From dd17d7a2b694c755d565c2348a7471a14f0b48f2 Mon Sep 17 00:00:00 2001 From: Ekta Mishra Date: Thu, 16 Jul 2020 22:04:26 +0530 Subject: [PATCH] Add test-cases for methods defined in WikidataConstraintFetcher (#2943) * Add test-cases for methods defined in WikidataConstraintFetcher tests for getConstraintsByTpe & getConstraintStatements methods. * Tests updated --- .../qa/WikidataConstraintFetcher.java | 27 ------------------- .../qa/WikidataConstraintFetcherTests.java | 26 ++++++++++++++++++ 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/extensions/wikidata/src/org/openrefine/wikidata/qa/WikidataConstraintFetcher.java b/extensions/wikidata/src/org/openrefine/wikidata/qa/WikidataConstraintFetcher.java index 1ac27f862..042cb34e1 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/qa/WikidataConstraintFetcher.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/qa/WikidataConstraintFetcher.java @@ -27,7 +27,6 @@ import org.openrefine.wikidata.utils.EntityCache; import org.wikidata.wdtk.datamodel.interfaces.EntityIdValue; import org.wikidata.wdtk.datamodel.interfaces.PropertyDocument; import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue; -import org.wikidata.wdtk.datamodel.interfaces.SnakGroup; import org.wikidata.wdtk.datamodel.interfaces.Statement; import org.wikidata.wdtk.datamodel.interfaces.StatementGroup; import org.wikidata.wdtk.datamodel.interfaces.StatementRank; @@ -48,38 +47,12 @@ public class WikidataConstraintFetcher implements ConstraintFetcher { public static String WIKIDATA_CONSTRAINT_PID = "P2302"; - // The following constraints still need to be implemented: - - public static String TYPE_CONSTRAINT_QID = "Q21503250"; - protected EntityCache entityCache; public WikidataConstraintFetcher(EntityCache cache) { entityCache = cache; } - /** - * Returns a single constraint for a particular type and a property, or null if - * there is no such constraint - * - * @param pid - * the property to retrieve the constraints for - * @param qid - * the type of the constraints - * @return the list of qualifiers for the constraint, or null if it does not - * exist - */ - protected List getSingleConstraint(PropertyIdValue pid, String qid) { - List statementList = getConstraintsByType(pid, qid); - if (!statementList.isEmpty()) { - Statement statement = statementList.get(0); - if (statement != null) { - return statement.getClaim().getQualifiers(); - } - } - return null; - } - /** * Gets the list of constraints of a particular type for a property * diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/qa/WikidataConstraintFetcherTests.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/qa/WikidataConstraintFetcherTests.java index 5b74306dc..ad2986533 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/qa/WikidataConstraintFetcherTests.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/qa/WikidataConstraintFetcherTests.java @@ -23,14 +23,40 @@ ******************************************************************************/ package org.openrefine.wikidata.qa; +import org.openrefine.wikidata.qa.scrutinizers.ConflictsWithScrutinizer; +import org.openrefine.wikidata.qa.scrutinizers.RestrictedValuesScrutinizer; import org.openrefine.wikidata.utils.EntityCacheStub; +import org.testng.Assert; +import org.testng.annotations.Test; +import org.wikidata.wdtk.datamodel.helpers.Datamodel; +import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue; + +import java.util.ArrayList; public class WikidataConstraintFetcherTests { private ConstraintFetcher fetcher; + public static PropertyIdValue instanceOf; public WikidataConstraintFetcherTests() { fetcher = new WikidataConstraintFetcher(new EntityCacheStub()); + instanceOf = Datamodel.makeWikidataPropertyIdValue("P31"); } + @Test + public void testGetConstraintsByType() { + Assert.assertEquals(fetcher.getConstraintsByType(instanceOf, ConflictsWithScrutinizer.CONFLICTS_WITH_CONSTRAINT_QID), new ArrayList<>()); + String constraintDefinitions = "[[ID P31$43E28495-355E-451E-A881-2EE14DFBE99D] http://www.wikidata.org/entity/P31 (property): http://www.wikidata.org/entity/P2302 :: http://www.wikidata.org/entity/Q52558054 (item)\n" + + " http://www.wikidata.org/entity/P2305 :: http://www.wikidata.org/entity/Q467 (item)\n" + + " http://www.wikidata.org/entity/P2305 :: http://www.wikidata.org/entity/Q6581072 (item)\n" + + " http://www.wikidata.org/entity/P2305 :: http://www.wikidata.org/entity/Q6581097 (item)\n" + + " http://www.wikidata.org/entity/P2305 :: http://www.wikidata.org/entity/Q8441 (item)\n" + + " http://www.wikidata.org/entity/P2305 :: http://www.wikidata.org/entity/Q171283 (item)\n" + + " http://www.wikidata.org/entity/P2305 :: http://www.wikidata.org/entity/Q11629 (item)\n" + + " http://www.wikidata.org/entity/P2305 :: http://www.wikidata.org/entity/Q11634 (item)\n" + + " http://www.wikidata.org/entity/P2305 :: http://www.wikidata.org/entity/Q131123 (item)\n" + + " http://www.wikidata.org/entity/P2316 :: http://www.wikidata.org/entity/Q21502408 (item)\n" + + "]"; + Assert.assertEquals(fetcher.getConstraintsByType(instanceOf, RestrictedValuesScrutinizer.DISALLOWED_VALUES_CONSTRAINT_QID).toString(), constraintDefinitions); + } }