Reuse Constraint IDs and Property IDs (#2937)

* Revert "Revert "Reused Constraint IDs and Parameter PIDs (#2893)""

This reverts commit 4c739be843.

* Reuse Constraint IDs and Parameter PIDs

After the cleanup of MockConstraintFetcher, using constraint IDs and property IDs defined in the corresponding scrtinizer for the test files.
This commit is contained in:
Ekta Mishra 2020-07-15 00:21:18 +05:30 committed by GitHub
parent 4c739be843
commit c7a8dfb329
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 92 additions and 101 deletions

View File

@ -21,12 +21,16 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import static org.openrefine.wikidata.qa.Constraint.CONSTRAINT_EXCEPTIONS;
import static org.openrefine.wikidata.qa.Constraint.CONSTRAINT_STATUS;
import static org.openrefine.wikidata.qa.scrutinizers.SingleValueScrutinizer.SINGLE_VALUE_CONSTRAINT_QID;
public class ConstraintTest { public class ConstraintTest {
public static ItemIdValue itemIdValue = Datamodel.makeWikidataItemIdValue("Q19474404"); public static ItemIdValue itemIdValue = Datamodel.makeWikidataItemIdValue(SINGLE_VALUE_CONSTRAINT_QID);
public static PropertyIdValue constraintException = Datamodel.makeWikidataPropertyIdValue("P2303"); public static PropertyIdValue constraintException = Datamodel.makeWikidataPropertyIdValue(CONSTRAINT_EXCEPTIONS);
public static Value exceptionValue = Datamodel.makeWikidataItemIdValue("Q7409772"); public static Value exceptionValue = Datamodel.makeWikidataItemIdValue("Q7409772");
public static PropertyIdValue constraintStatus = Datamodel.makeWikidataPropertyIdValue("P2316"); public static PropertyIdValue constraintStatus = Datamodel.makeWikidataPropertyIdValue(CONSTRAINT_STATUS);
public static Value statusValue = Datamodel.makeWikidataItemIdValue("Q62026391"); public static Value statusValue = Datamodel.makeWikidataItemIdValue("Q62026391");
public static Constraint constraint; public static Constraint constraint;

View File

@ -23,6 +23,10 @@ import java.util.List;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.openrefine.wikidata.qa.scrutinizers.DifferenceWithinRangeScrutinizer.DIFFERENCE_WITHIN_RANGE_CONSTRAINT_PID;
import static org.openrefine.wikidata.qa.scrutinizers.DifferenceWithinRangeScrutinizer.DIFFERENCE_WITHIN_RANGE_CONSTRAINT_QID;
import static org.openrefine.wikidata.qa.scrutinizers.DifferenceWithinRangeScrutinizer.MAXIMUM_VALUE_PID;
import static org.openrefine.wikidata.qa.scrutinizers.DifferenceWithinRangeScrutinizer.MINIMUM_VALUE_PID;
public class DifferenceWithinScrutinizerTest extends ScrutinizerTest{ public class DifferenceWithinScrutinizerTest extends ScrutinizerTest{
@ -30,11 +34,11 @@ public class DifferenceWithinScrutinizerTest extends ScrutinizerTest{
public static PropertyIdValue lowerBoundPid = Datamodel.makeWikidataPropertyIdValue("P569"); public static PropertyIdValue lowerBoundPid = Datamodel.makeWikidataPropertyIdValue("P569");
public static QuantityValue minValue = Datamodel.makeQuantityValue(new BigDecimal(0)); public static QuantityValue minValue = Datamodel.makeQuantityValue(new BigDecimal(0));
public static QuantityValue maxValue = Datamodel.makeQuantityValue(new BigDecimal(150)); public static QuantityValue maxValue = Datamodel.makeQuantityValue(new BigDecimal(150));
public static ItemIdValue entityIdValue = Datamodel.makeWikidataItemIdValue("Q21510854"); public static ItemIdValue entityIdValue = Datamodel.makeWikidataItemIdValue(DIFFERENCE_WITHIN_RANGE_CONSTRAINT_QID);
public static PropertyIdValue propertyParameterPID = Datamodel.makeWikidataPropertyIdValue("P2306"); public static PropertyIdValue propertyParameterPID = Datamodel.makeWikidataPropertyIdValue(DIFFERENCE_WITHIN_RANGE_CONSTRAINT_PID);
public static PropertyIdValue minimumValuePID = Datamodel.makeWikidataPropertyIdValue("P2313"); public static PropertyIdValue minimumValuePID = Datamodel.makeWikidataPropertyIdValue(MINIMUM_VALUE_PID);
public static PropertyIdValue maximumValuePID = Datamodel.makeWikidataPropertyIdValue("P2312"); public static PropertyIdValue maximumValuePID = Datamodel.makeWikidataPropertyIdValue(MAXIMUM_VALUE_PID);
@Override @Override
public EditScrutinizer getScrutinizer() { public EditScrutinizer getScrutinizer() {
@ -59,10 +63,10 @@ public class DifferenceWithinScrutinizerTest extends ScrutinizerTest{
List<Statement> constraintDefinitions = constraintParameterStatementList(entityIdValue, constraintQualifiers); List<Statement> constraintDefinitions = constraintParameterStatementList(entityIdValue, constraintQualifiers);
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(upperBoundPid, "Q21510854")).thenReturn(constraintDefinitions); when(fetcher.getConstraintsByType(upperBoundPid, DIFFERENCE_WITHIN_RANGE_CONSTRAINT_QID)).thenReturn(constraintDefinitions);
when(fetcher.findValues(constraintQualifiers, "P2306")).thenReturn(Collections.singletonList(lowerBoundPid)); when(fetcher.findValues(constraintQualifiers, DIFFERENCE_WITHIN_RANGE_CONSTRAINT_PID)).thenReturn(Collections.singletonList(lowerBoundPid));
when(fetcher.findValues(constraintQualifiers, "P2313")).thenReturn(Collections.singletonList(minValue)); when(fetcher.findValues(constraintQualifiers, MINIMUM_VALUE_PID)).thenReturn(Collections.singletonList(minValue));
when(fetcher.findValues(constraintQualifiers, "P2312")).thenReturn(Collections.singletonList(maxValue)); when(fetcher.findValues(constraintQualifiers, MAXIMUM_VALUE_PID)).thenReturn(Collections.singletonList(maxValue));
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(updateA); scrutinize(updateA);
@ -87,10 +91,10 @@ public class DifferenceWithinScrutinizerTest extends ScrutinizerTest{
List<Statement> constraintDefinitions = constraintParameterStatementList(entityIdValue, constraintQualifiers); List<Statement> constraintDefinitions = constraintParameterStatementList(entityIdValue, constraintQualifiers);
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(upperBoundPid, "Q21510854")).thenReturn(constraintDefinitions); when(fetcher.getConstraintsByType(upperBoundPid, DIFFERENCE_WITHIN_RANGE_CONSTRAINT_QID)).thenReturn(constraintDefinitions);
when(fetcher.findValues(constraintQualifiers, "P2306")).thenReturn(Collections.singletonList(lowerBoundPid)); when(fetcher.findValues(constraintQualifiers, DIFFERENCE_WITHIN_RANGE_CONSTRAINT_PID)).thenReturn(Collections.singletonList(lowerBoundPid));
when(fetcher.findValues(constraintQualifiers, "P2313")).thenReturn(Collections.singletonList(minValue)); when(fetcher.findValues(constraintQualifiers, MINIMUM_VALUE_PID)).thenReturn(Collections.singletonList(minValue));
when(fetcher.findValues(constraintQualifiers, "P2312")).thenReturn(Collections.singletonList(maxValue)); when(fetcher.findValues(constraintQualifiers, MAXIMUM_VALUE_PID)).thenReturn(Collections.singletonList(maxValue));
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(updateA); scrutinize(updateA);

View File

@ -42,6 +42,7 @@ import java.util.List;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.openrefine.wikidata.qa.scrutinizers.DistinctValuesScrutinizer.DISTINCT_VALUES_CONSTRAINT_QID;
public class DistinctValuesScrutinizerTest extends StatementScrutinizerTest { public class DistinctValuesScrutinizerTest extends StatementScrutinizerTest {
@ -49,7 +50,7 @@ public class DistinctValuesScrutinizerTest extends StatementScrutinizerTest {
public static Value value1 = Datamodel.makeWikidataItemIdValue("Q41673"); public static Value value1 = Datamodel.makeWikidataItemIdValue("Q41673");
public static Value value2 = Datamodel.makeWikidataItemIdValue("Q43175"); public static Value value2 = Datamodel.makeWikidataItemIdValue("Q43175");
public static ItemIdValue entityIdValue = Datamodel.makeWikidataItemIdValue("Q19474404"); public static ItemIdValue entityIdValue = Datamodel.makeWikidataItemIdValue(DISTINCT_VALUES_CONSTRAINT_QID);
@Override @Override
public EditScrutinizer getScrutinizer() { public EditScrutinizer getScrutinizer() {
@ -69,7 +70,7 @@ public class DistinctValuesScrutinizerTest extends StatementScrutinizerTest {
List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList); List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList);
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(propertyIdValue, "Q21502410")).thenReturn(statementList); when(fetcher.getConstraintsByType(propertyIdValue, DISTINCT_VALUES_CONSTRAINT_QID)).thenReturn(statementList);
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(update); scrutinize(update);
@ -90,7 +91,7 @@ public class DistinctValuesScrutinizerTest extends StatementScrutinizerTest {
List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList); List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList);
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(propertyIdValue, "Q21502410")).thenReturn(statementList); when(fetcher.getConstraintsByType(propertyIdValue, DISTINCT_VALUES_CONSTRAINT_QID)).thenReturn(statementList);
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(update); scrutinize(update);

View File

@ -57,8 +57,8 @@ public class EntityTypeScrutinizerTest extends StatementScrutinizerTest {
List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList); List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList);
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(propertyIdValue,"Q52004125")).thenReturn(statementList); when(fetcher.getConstraintsByType(propertyIdValue,ALLOWED_ENTITY_TYPES_QID)).thenReturn(statementList);
when(fetcher.findValues(snakGroupList, "P2305")).thenReturn(Collections.singletonList(allowedValue)); when(fetcher.findValues(snakGroupList, ALLOWED_ENTITY_TYPES_PID)).thenReturn(Collections.singletonList(allowedValue));
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(update); scrutinize(update);
@ -81,8 +81,8 @@ public class EntityTypeScrutinizerTest extends StatementScrutinizerTest {
List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList); List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList);
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(propertyIdValue,"Q52004125")).thenReturn(statementList); when(fetcher.getConstraintsByType(propertyIdValue,ALLOWED_ENTITY_TYPES_QID)).thenReturn(statementList);
when(fetcher.findValues(snakGroupList, "P2305")).thenReturn(Collections.singletonList(itemValue)); when(fetcher.findValues(snakGroupList, ALLOWED_ENTITY_TYPES_PID)).thenReturn(Collections.singletonList(itemValue));
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(update); scrutinize(update);

View File

@ -43,6 +43,8 @@ import java.util.List;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.openrefine.wikidata.qa.scrutinizers.FormatScrutinizer.FORMAT_CONSTRAINT_QID;
import static org.openrefine.wikidata.qa.scrutinizers.FormatScrutinizer.FORMAT_REGEX_PID;
public class FormatScrutinizerTest extends ScrutinizerTest { public class FormatScrutinizerTest extends ScrutinizerTest {
@ -52,8 +54,8 @@ public class FormatScrutinizerTest extends ScrutinizerTest {
public static Value incompleteMatchValue = Datamodel.makeStringValue(".jpg"); public static Value incompleteMatchValue = Datamodel.makeStringValue(".jpg");
public static String regularExpression = "(?i).+\\.(jpg|jpeg|jpe|png|svg|tif|tiff|gif|xcf|pdf|djvu|webp)"; public static String regularExpression = "(?i).+\\.(jpg|jpeg|jpe|png|svg|tif|tiff|gif|xcf|pdf|djvu|webp)";
public static ItemIdValue entityIdValue = Datamodel.makeWikidataItemIdValue("Q21502404"); public static ItemIdValue entityIdValue = Datamodel.makeWikidataItemIdValue(FORMAT_CONSTRAINT_QID);
public static PropertyIdValue regularExpressionParameter = Datamodel.makeWikidataPropertyIdValue("P1793"); public static PropertyIdValue regularExpressionParameter = Datamodel.makeWikidataPropertyIdValue(FORMAT_REGEX_PID);
public static Value regularExpressionFormat = Datamodel.makeStringValue(regularExpression); public static Value regularExpressionFormat = Datamodel.makeStringValue(regularExpression);
@Override @Override
@ -76,8 +78,8 @@ public class FormatScrutinizerTest extends ScrutinizerTest {
List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList); List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList);
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(propertyIdValue, "Q21502404")).thenReturn(statementList); when(fetcher.getConstraintsByType(propertyIdValue, FORMAT_CONSTRAINT_QID)).thenReturn(statementList);
when(fetcher.findValues(snakGroupList, "P1793")).thenReturn(Collections.singletonList(regularExpressionFormat)); when(fetcher.findValues(snakGroupList, FORMAT_REGEX_PID)).thenReturn(Collections.singletonList(regularExpressionFormat));
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(updateA); scrutinize(updateA);
assertWarningsRaised(FormatScrutinizer.type); assertWarningsRaised(FormatScrutinizer.type);
@ -97,8 +99,8 @@ public class FormatScrutinizerTest extends ScrutinizerTest {
List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList); List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList);
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(propertyIdValue, "Q21502404")).thenReturn(statementList); when(fetcher.getConstraintsByType(propertyIdValue, FORMAT_CONSTRAINT_QID)).thenReturn(statementList);
when(fetcher.findValues(snakGroupList, "P1793")).thenReturn(Collections.singletonList(regularExpressionFormat)); when(fetcher.findValues(snakGroupList, FORMAT_REGEX_PID)).thenReturn(Collections.singletonList(regularExpressionFormat));
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(updateA); scrutinize(updateA);
assertNoWarningRaised(); assertNoWarningRaised();
@ -118,8 +120,8 @@ public class FormatScrutinizerTest extends ScrutinizerTest {
List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList); List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList);
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(propertyIdValue, "Q21502404")).thenReturn(statementList); when(fetcher.getConstraintsByType(propertyIdValue, FORMAT_CONSTRAINT_QID)).thenReturn(statementList);
when(fetcher.findValues(snakGroupList, "P1793")).thenReturn(Collections.singletonList(regularExpressionFormat)); when(fetcher.findValues(snakGroupList, FORMAT_REGEX_PID)).thenReturn(Collections.singletonList(regularExpressionFormat));
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(updateA); scrutinize(updateA);
assertWarningsRaised(FormatScrutinizer.type); assertWarningsRaised(FormatScrutinizer.type);

View File

@ -41,6 +41,9 @@ import java.util.List;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.openrefine.wikidata.qa.scrutinizers.InverseConstraintScrutinizer.INVERSE_CONSTRAINT_QID;
import static org.openrefine.wikidata.qa.scrutinizers.InverseConstraintScrutinizer.INVERSE_PROPERTY_PID;
import static org.openrefine.wikidata.qa.scrutinizers.InverseConstraintScrutinizer.SYMMETRIC_CONSTRAINT_QID;
public class InverseConstaintScrutinizerTest extends StatementScrutinizerTest { public class InverseConstaintScrutinizerTest extends StatementScrutinizerTest {
@ -50,9 +53,9 @@ public class InverseConstaintScrutinizerTest extends StatementScrutinizerTest {
public static PropertyIdValue symmetricPropertyID = Datamodel.makeWikidataPropertyIdValue("P3373"); public static PropertyIdValue symmetricPropertyID = Datamodel.makeWikidataPropertyIdValue("P3373");
public static ItemIdValue symmetricPropertyValue = Datamodel.makeWikidataItemIdValue("Q9545711"); public static ItemIdValue symmetricPropertyValue = Datamodel.makeWikidataItemIdValue("Q9545711");
public static ItemIdValue inverseEntityIdValue = Datamodel.makeWikidataItemIdValue("Q21510855"); public static ItemIdValue inverseEntityIdValue = Datamodel.makeWikidataItemIdValue(INVERSE_CONSTRAINT_QID);
public static ItemIdValue symmetricEntityIdValue = Datamodel.makeWikidataItemIdValue("Q21510862"); public static ItemIdValue symmetricEntityIdValue = Datamodel.makeWikidataItemIdValue(SYMMETRIC_CONSTRAINT_QID);
public static PropertyIdValue propertyParameter = Datamodel.makeWikidataPropertyIdValue("P2306"); public static PropertyIdValue propertyParameter = Datamodel.makeWikidataPropertyIdValue(INVERSE_PROPERTY_PID);
@Override @Override
public EditScrutinizer getScrutinizer() { public EditScrutinizer getScrutinizer() {
@ -73,8 +76,8 @@ public class InverseConstaintScrutinizerTest extends StatementScrutinizerTest {
List<Statement> statementList = constraintParameterStatementList(inverseEntityIdValue, snakGroupList); List<Statement> statementList = constraintParameterStatementList(inverseEntityIdValue, snakGroupList);
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(propertyId, "Q21510855")).thenReturn(statementList); when(fetcher.getConstraintsByType(propertyId, INVERSE_CONSTRAINT_QID)).thenReturn(statementList);
when(fetcher.findValues(snakGroupList, "P2306")).thenReturn(Collections.singletonList(inversePropertyID)); when(fetcher.findValues(snakGroupList, INVERSE_PROPERTY_PID)).thenReturn(Collections.singletonList(inversePropertyID));
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(update); scrutinize(update);
assertWarningsRaised(InverseConstraintScrutinizer.type); assertWarningsRaised(InverseConstraintScrutinizer.type);
@ -94,8 +97,8 @@ public class InverseConstaintScrutinizerTest extends StatementScrutinizerTest {
List<Statement> statementList = constraintParameterStatementList(symmetricEntityIdValue, snakGroupList); List<Statement> statementList = constraintParameterStatementList(symmetricEntityIdValue, snakGroupList);
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(symmetricPropertyID, "Q21510862")).thenReturn(statementList); when(fetcher.getConstraintsByType(symmetricPropertyID, SYMMETRIC_CONSTRAINT_QID)).thenReturn(statementList);
when(fetcher.findValues(snakGroupList, "P2306")).thenReturn(Collections.singletonList(symmetricPropertyID)); when(fetcher.findValues(snakGroupList, INVERSE_PROPERTY_PID)).thenReturn(Collections.singletonList(symmetricPropertyID));
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(update); scrutinize(update);
assertWarningsRaised(InverseConstraintScrutinizer.type); assertWarningsRaised(InverseConstraintScrutinizer.type);
@ -115,8 +118,8 @@ public class InverseConstaintScrutinizerTest extends StatementScrutinizerTest {
List<Statement> statementList = constraintParameterStatementList(inverseEntityIdValue, snakGroupList); List<Statement> statementList = constraintParameterStatementList(inverseEntityIdValue, snakGroupList);
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(propertyId, "Q21510855")).thenReturn(statementList); when(fetcher.getConstraintsByType(propertyId, INVERSE_CONSTRAINT_QID)).thenReturn(statementList);
when(fetcher.findValues(snakGroupList, "P2306")).thenReturn(Collections.singletonList(inversePropertyID)); when(fetcher.findValues(snakGroupList, INVERSE_PROPERTY_PID)).thenReturn(Collections.singletonList(inversePropertyID));
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(update); scrutinize(update);
assertNoWarningRaised(); assertNoWarningRaised();

View File

@ -10,24 +10,21 @@ import org.wikidata.wdtk.datamodel.implementation.StatementImpl;
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue; import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
import org.wikidata.wdtk.datamodel.interfaces.Snak; import org.wikidata.wdtk.datamodel.interfaces.Snak;
import org.wikidata.wdtk.datamodel.interfaces.SnakGroup;
import org.wikidata.wdtk.datamodel.interfaces.Statement; import org.wikidata.wdtk.datamodel.interfaces.Statement;
import org.wikidata.wdtk.datamodel.interfaces.Value; import org.wikidata.wdtk.datamodel.interfaces.Value;
import java.util.Collections; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.openrefine.wikidata.qa.scrutinizers.MultiValueScrutinizer.MULTI_VALUE_CONSTRAINT_QID;
public class MultiValueScrutinizerTest extends ScrutinizerTest { public class MultiValueScrutinizerTest extends ScrutinizerTest {
public static PropertyIdValue propertyIdValue = Datamodel.makeWikidataPropertyIdValue("P1963"); public static PropertyIdValue propertyIdValue = Datamodel.makeWikidataPropertyIdValue("P1963");
public static Value valueSnak1 = Datamodel.makeWikidataItemIdValue("Q5"); public static Value valueSnak = Datamodel.makeWikidataItemIdValue("Q5");
public static Value valueSnak2 = Datamodel.makeWikidataItemIdValue("Q4"); public static ItemIdValue entityIdValue = Datamodel.makeWikidataItemIdValue(MULTI_VALUE_CONSTRAINT_QID);
public static ItemIdValue entityIdValue = Datamodel.makeWikidataItemIdValue("Q21510857");
public static PropertyIdValue constraintParameter = Datamodel.makeWikidataPropertyIdValue("P2316");
public static Value constraintStatus = Datamodel.makeWikidataItemIdValue("Q62026391");
@Override @Override
public EditScrutinizer getScrutinizer() { public EditScrutinizer getScrutinizer() {
@ -45,13 +42,9 @@ public class MultiValueScrutinizerTest extends ScrutinizerTest {
ItemUpdate update = new ItemUpdateBuilder(idA).addStatement(TestingData.generateStatement(idA, idB)) ItemUpdate update = new ItemUpdateBuilder(idA).addStatement(TestingData.generateStatement(idA, idB))
.addStatement(TestingData.generateStatement(idA, idB)).addStatement(statement1).addStatement(statement2).build(); .addStatement(TestingData.generateStatement(idA, idB)).addStatement(statement1).addStatement(statement2).build();
Snak snak = Datamodel.makeValueSnak(constraintParameter, constraintStatus); List<Statement> statementList = constraintParameterStatementList(entityIdValue, new ArrayList<>());
List<Snak> snakList1 = Collections.singletonList(snak);
SnakGroup snakGroup = Datamodel.makeSnakGroup(snakList1);
List<SnakGroup> snakGroupList = Collections.singletonList(snakGroup);
List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList);
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(propertyIdValue, "Q21510857")).thenReturn(statementList); when(fetcher.getConstraintsByType(propertyIdValue, MULTI_VALUE_CONSTRAINT_QID)).thenReturn(statementList);
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(update); scrutinize(update);
@ -62,18 +55,14 @@ public class MultiValueScrutinizerTest extends ScrutinizerTest {
public void testNewItemTrigger() { public void testNewItemTrigger() {
ItemIdValue idA = TestingData.newIdA; ItemIdValue idA = TestingData.newIdA;
ItemIdValue idB = TestingData.newIdB; ItemIdValue idB = TestingData.newIdB;
Snak mainSnakValue = Datamodel.makeValueSnak(propertyIdValue, valueSnak1); Snak mainSnakValue = Datamodel.makeValueSnak(propertyIdValue, valueSnak);
Statement statement = new StatementImpl("P1963", mainSnakValue, idA); Statement statement = new StatementImpl("P1963", mainSnakValue, idA);
ItemUpdate updateA = new ItemUpdateBuilder(idA).addStatement(TestingData.generateStatement(idA, idB)).addStatement(statement).build(); ItemUpdate updateA = new ItemUpdateBuilder(idA).addStatement(TestingData.generateStatement(idA, idB)).addStatement(statement).build();
ItemUpdate updateB = new ItemUpdateBuilder(idB).addStatement(TestingData.generateStatement(idB, idB)).build(); ItemUpdate updateB = new ItemUpdateBuilder(idB).addStatement(TestingData.generateStatement(idB, idB)).build();
Snak snak = Datamodel.makeValueSnak(constraintParameter, constraintStatus); List<Statement> statementList = constraintParameterStatementList(entityIdValue, new ArrayList<>());
List<Snak> snakList1 = Collections.singletonList(snak);
SnakGroup snakGroup = Datamodel.makeSnakGroup(snakList1);
List<SnakGroup> snakGroupList = Collections.singletonList(snakGroup);
List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList);
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(propertyIdValue, "Q21510857")).thenReturn(statementList); when(fetcher.getConstraintsByType(propertyIdValue, MULTI_VALUE_CONSTRAINT_QID)).thenReturn(statementList);
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(updateA, updateB); scrutinize(updateA, updateB);
@ -84,18 +73,14 @@ public class MultiValueScrutinizerTest extends ScrutinizerTest {
public void testExistingItemTrigger() { public void testExistingItemTrigger() {
ItemIdValue idA = TestingData.existingId; ItemIdValue idA = TestingData.existingId;
ItemIdValue idB = TestingData.matchedId; ItemIdValue idB = TestingData.matchedId;
Snak mainSnakValue = Datamodel.makeValueSnak(propertyIdValue, valueSnak1); Snak mainSnakValue = Datamodel.makeValueSnak(propertyIdValue, valueSnak);
Statement statement = new StatementImpl("P1963", mainSnakValue, idA); Statement statement = new StatementImpl("P1963", mainSnakValue, idA);
ItemUpdate updateA = new ItemUpdateBuilder(idA).addStatement(TestingData.generateStatement(idA, idB)).addStatement(statement).build(); ItemUpdate updateA = new ItemUpdateBuilder(idA).addStatement(TestingData.generateStatement(idA, idB)).addStatement(statement).build();
ItemUpdate updateB = new ItemUpdateBuilder(idB).addStatement(TestingData.generateStatement(idB, idB)).build(); ItemUpdate updateB = new ItemUpdateBuilder(idB).addStatement(TestingData.generateStatement(idB, idB)).build();
Snak snak = Datamodel.makeValueSnak(constraintParameter, constraintStatus); List<Statement> statementList = constraintParameterStatementList(entityIdValue, new ArrayList<>());
List<Snak> snakList1 = Collections.singletonList(snak);
SnakGroup snakGroup = Datamodel.makeSnakGroup(snakList1);
List<SnakGroup> snakGroupList = Collections.singletonList(snakGroup);
List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList);
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(propertyIdValue, "Q21510857")).thenReturn(statementList); when(fetcher.getConstraintsByType(propertyIdValue, MULTI_VALUE_CONSTRAINT_QID)).thenReturn(statementList);
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(updateA, updateB); scrutinize(updateA, updateB);

View File

@ -44,12 +44,16 @@ import java.util.stream.Collectors;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.openrefine.wikidata.qa.scrutinizers.QualifierCompatibilityScrutinizer.ALLOWED_QUALIFIERS_CONSTRAINT_PID;
import static org.openrefine.wikidata.qa.scrutinizers.QualifierCompatibilityScrutinizer.ALLOWED_QUALIFIERS_CONSTRAINT_QID;
import static org.openrefine.wikidata.qa.scrutinizers.QualifierCompatibilityScrutinizer.MANDATORY_QUALIFIERS_CONSTRAINT_PID;
import static org.openrefine.wikidata.qa.scrutinizers.QualifierCompatibilityScrutinizer.MANDATORY_QUALIFIERS_CONSTRAINT_QID;
public class QualifierCompatibilityScrutinizerTest extends StatementScrutinizerTest { public class QualifierCompatibilityScrutinizerTest extends StatementScrutinizerTest {
public static ItemIdValue allowedQualifierEntity = Datamodel.makeWikidataItemIdValue("Q21510851"); public static ItemIdValue allowedQualifierEntity = Datamodel.makeWikidataItemIdValue(ALLOWED_QUALIFIERS_CONSTRAINT_QID);
public static ItemIdValue mandatoryQualifierEntity = Datamodel.makeWikidataItemIdValue("Q21510856"); public static ItemIdValue mandatoryQualifierEntity = Datamodel.makeWikidataItemIdValue(MANDATORY_QUALIFIERS_CONSTRAINT_QID);
public static PropertyIdValue propertyParameterPID = Datamodel.makeWikidataPropertyIdValue("P2306"); public static PropertyIdValue propertyParameterPID = Datamodel.makeWikidataPropertyIdValue(ALLOWED_QUALIFIERS_CONSTRAINT_PID);
public static PropertyIdValue propertyParameterValue = Datamodel.makeWikidataPropertyIdValue("P585"); public static PropertyIdValue propertyParameterValue = Datamodel.makeWikidataPropertyIdValue("P585");
public static PropertyIdValue allowedPropertyIdValue = Datamodel.makeWikidataPropertyIdValue("P2196"); public static PropertyIdValue allowedPropertyIdValue = Datamodel.makeWikidataPropertyIdValue("P2196");
@ -77,8 +81,8 @@ public class QualifierCompatibilityScrutinizerTest extends StatementScrutinizerT
List<Statement> statementList = constraintParameterStatementList(allowedQualifierEntity, snakGroupList); List<Statement> statementList = constraintParameterStatementList(allowedQualifierEntity, snakGroupList);
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(allowedPropertyIdValue, "Q21510851")).thenReturn(statementList); when(fetcher.getConstraintsByType(allowedPropertyIdValue, ALLOWED_QUALIFIERS_CONSTRAINT_QID)).thenReturn(statementList);
when(fetcher.findValues(snakGroupList, "P2306")).thenReturn(Collections.singletonList(qualifierProperty)); when(fetcher.findValues(snakGroupList, ALLOWED_QUALIFIERS_CONSTRAINT_PID)).thenReturn(Collections.singletonList(qualifierProperty));
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(update); scrutinize(update);
@ -99,8 +103,8 @@ public class QualifierCompatibilityScrutinizerTest extends StatementScrutinizerT
List<Statement> statementList = constraintParameterStatementList(mandatoryQualifierEntity, snakGroupList); List<Statement> statementList = constraintParameterStatementList(mandatoryQualifierEntity, snakGroupList);
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(mandatoryPropertyIdValue, "Q21510856")).thenReturn(statementList); when(fetcher.getConstraintsByType(mandatoryPropertyIdValue, MANDATORY_QUALIFIERS_CONSTRAINT_QID)).thenReturn(statementList);
when(fetcher.findValues(snakGroupList, "P2306")).thenReturn(Collections.singletonList(qualifierProperty)); when(fetcher.findValues(snakGroupList, MANDATORY_QUALIFIERS_CONSTRAINT_PID)).thenReturn(Collections.singletonList(qualifierProperty));
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(update); scrutinize(update);
@ -122,8 +126,8 @@ public class QualifierCompatibilityScrutinizerTest extends StatementScrutinizerT
List<Statement> statementList = constraintParameterStatementList(allowedQualifierEntity, snakGroupList); List<Statement> statementList = constraintParameterStatementList(allowedQualifierEntity, snakGroupList);
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(allowedPropertyIdValue, "Q21510851")).thenReturn(statementList); when(fetcher.getConstraintsByType(allowedPropertyIdValue, ALLOWED_QUALIFIERS_CONSTRAINT_QID)).thenReturn(statementList);
when(fetcher.findValues(snakGroupList, "P2306")).thenReturn(Collections.singletonList(qualifierProperty)); when(fetcher.findValues(snakGroupList, ALLOWED_QUALIFIERS_CONSTRAINT_PID)).thenReturn(Collections.singletonList(qualifierProperty));
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(update); scrutinize(update);

View File

@ -24,6 +24,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.openrefine.wikidata.qa.scrutinizers.QuantityScrutinizer.ALLOWED_UNITS_CONSTRAINT_PID;
import static org.openrefine.wikidata.qa.scrutinizers.QuantityScrutinizer.ALLOWED_UNITS_CONSTRAINT_QID; import static org.openrefine.wikidata.qa.scrutinizers.QuantityScrutinizer.ALLOWED_UNITS_CONSTRAINT_QID;
import static org.openrefine.wikidata.qa.scrutinizers.QuantityScrutinizer.INTEGER_VALUED_CONSTRAINT_QID; import static org.openrefine.wikidata.qa.scrutinizers.QuantityScrutinizer.INTEGER_VALUED_CONSTRAINT_QID;
import static org.openrefine.wikidata.qa.scrutinizers.QuantityScrutinizer.NO_BOUNDS_CONSTRAINT_QID; import static org.openrefine.wikidata.qa.scrutinizers.QuantityScrutinizer.NO_BOUNDS_CONSTRAINT_QID;
@ -55,7 +56,7 @@ public class QuantityScrutinizerTest extends ValueScrutinizerTest{
public static ItemIdValue noBoundsEntity = Datamodel.makeWikidataItemIdValue(NO_BOUNDS_CONSTRAINT_QID); public static ItemIdValue noBoundsEntity = Datamodel.makeWikidataItemIdValue(NO_BOUNDS_CONSTRAINT_QID);
public static ItemIdValue integerValueEntity = Datamodel.makeWikidataItemIdValue(INTEGER_VALUED_CONSTRAINT_QID); public static ItemIdValue integerValueEntity = Datamodel.makeWikidataItemIdValue(INTEGER_VALUED_CONSTRAINT_QID);
public static ItemIdValue allowedUnitEntity = Datamodel.makeWikidataItemIdValue(ALLOWED_UNITS_CONSTRAINT_QID); public static ItemIdValue allowedUnitEntity = Datamodel.makeWikidataItemIdValue(ALLOWED_UNITS_CONSTRAINT_QID);
public static PropertyIdValue itemParameterPID = Datamodel.makeWikidataPropertyIdValue("P2305"); public static PropertyIdValue itemParameterPID = Datamodel.makeWikidataPropertyIdValue(ALLOWED_UNITS_CONSTRAINT_PID);
public static Value allowedUnit = Datamodel.makeWikidataItemIdValue("Q5"); public static Value allowedUnit = Datamodel.makeWikidataItemIdValue("Q5");
@Override @Override
@ -211,7 +212,7 @@ public class QuantityScrutinizerTest extends ValueScrutinizerTest{
List<Statement> constraintDefinitions = constraintParameterStatementList(allowedUnitEntity, constraintQualifiers); List<Statement> constraintDefinitions = constraintParameterStatementList(allowedUnitEntity, constraintQualifiers);
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(propertyIdValue, ALLOWED_UNITS_CONSTRAINT_QID)).thenReturn(constraintDefinitions); when(fetcher.getConstraintsByType(propertyIdValue, ALLOWED_UNITS_CONSTRAINT_QID)).thenReturn(constraintDefinitions);
when(fetcher.findValues(constraintQualifiers, "P2305")).thenReturn(Collections.singletonList(allowedUnit)); when(fetcher.findValues(constraintQualifiers, ALLOWED_UNITS_CONSTRAINT_PID)).thenReturn(Collections.singletonList(allowedUnit));
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(update); scrutinize(update);
@ -228,7 +229,7 @@ public class QuantityScrutinizerTest extends ValueScrutinizerTest{
List<Statement> constraintDefinitions = constraintParameterStatementList(allowedUnitEntity, new ArrayList<>()); List<Statement> constraintDefinitions = constraintParameterStatementList(allowedUnitEntity, new ArrayList<>());
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(propertyIdValue, ALLOWED_UNITS_CONSTRAINT_QID)).thenReturn(constraintDefinitions); when(fetcher.getConstraintsByType(propertyIdValue, ALLOWED_UNITS_CONSTRAINT_QID)).thenReturn(constraintDefinitions);
when(fetcher.findValues(any(), eq("P2305"))).thenReturn(new ArrayList<>()); when(fetcher.findValues(any(), eq(ALLOWED_UNITS_CONSTRAINT_PID))).thenReturn(new ArrayList<>());
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(update); scrutinize(update);
@ -244,7 +245,7 @@ public class QuantityScrutinizerTest extends ValueScrutinizerTest{
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(propertyIdValue, ALLOWED_UNITS_CONSTRAINT_QID)).thenReturn(new ArrayList<>()); when(fetcher.getConstraintsByType(propertyIdValue, ALLOWED_UNITS_CONSTRAINT_QID)).thenReturn(new ArrayList<>());
when(fetcher.findValues(any(), eq("P2305"))).thenReturn(new ArrayList<>()); when(fetcher.findValues(any(), eq(ALLOWED_UNITS_CONSTRAINT_PID))).thenReturn(new ArrayList<>());
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(update); scrutinize(update);

View File

@ -46,18 +46,15 @@ import static org.mockito.Mockito.when;
import static org.openrefine.wikidata.qa.scrutinizers.RestrictedPositionScrutinizer.SCOPE_CONSTRAINT_PID; import static org.openrefine.wikidata.qa.scrutinizers.RestrictedPositionScrutinizer.SCOPE_CONSTRAINT_PID;
import static org.openrefine.wikidata.qa.scrutinizers.RestrictedPositionScrutinizer.SCOPE_CONSTRAINT_QID; import static org.openrefine.wikidata.qa.scrutinizers.RestrictedPositionScrutinizer.SCOPE_CONSTRAINT_QID;
import static org.openrefine.wikidata.qa.scrutinizers.RestrictedPositionScrutinizer.SCOPE_CONSTRAINT_QUALIFIER_QID; import static org.openrefine.wikidata.qa.scrutinizers.RestrictedPositionScrutinizer.SCOPE_CONSTRAINT_QUALIFIER_QID;
import static org.openrefine.wikidata.qa.scrutinizers.RestrictedPositionScrutinizer.SCOPE_CONSTRAINT_REFERENCE_QID;
import static org.openrefine.wikidata.qa.scrutinizers.RestrictedPositionScrutinizer.SCOPE_CONSTRAINT_VALUE_QID; import static org.openrefine.wikidata.qa.scrutinizers.RestrictedPositionScrutinizer.SCOPE_CONSTRAINT_VALUE_QID;
public class RestrictedPositionScrutinizerTest extends SnakScrutinizerTest { public class RestrictedPositionScrutinizerTest extends SnakScrutinizerTest {
public static PropertyIdValue propertyIdValue = Datamodel.makeWikidataPropertyIdValue("P22"); public static PropertyIdValue propertyIdValue = Datamodel.makeWikidataPropertyIdValue("P22");
public static PropertyIdValue mainSnakPid = Datamodel.makeWikidataPropertyIdValue("P1234"); public static PropertyIdValue propertyScopeParameter = Datamodel.makeWikidataPropertyIdValue(SCOPE_CONSTRAINT_PID);
public static PropertyIdValue propertyScopeParameter = Datamodel.makeWikidataPropertyIdValue("P5314");
public static ItemIdValue entityIdValue = Datamodel.makeWikidataItemIdValue(SCOPE_CONSTRAINT_QID); public static ItemIdValue entityIdValue = Datamodel.makeWikidataItemIdValue(SCOPE_CONSTRAINT_QID);
public static ItemIdValue asMainSnak = Datamodel.makeWikidataItemIdValue(SCOPE_CONSTRAINT_VALUE_QID); public static ItemIdValue asMainSnak = Datamodel.makeWikidataItemIdValue(SCOPE_CONSTRAINT_VALUE_QID);
public static ItemIdValue asQualifier = Datamodel.makeWikidataItemIdValue(SCOPE_CONSTRAINT_QUALIFIER_QID); public static ItemIdValue asQualifier = Datamodel.makeWikidataItemIdValue(SCOPE_CONSTRAINT_QUALIFIER_QID);
public static ItemIdValue asReference = Datamodel.makeWikidataItemIdValue(SCOPE_CONSTRAINT_REFERENCE_QID);
@Override @Override
public EditScrutinizer getScrutinizer() { public EditScrutinizer getScrutinizer() {

View File

@ -34,7 +34,7 @@ public class RestrictedValuesScrutinizerTest extends SnakScrutinizerTest {
public static ItemIdValue allowedValueEntity = Datamodel.makeWikidataItemIdValue(ALLOWED_VALUES_CONSTRAINT_QID); public static ItemIdValue allowedValueEntity = Datamodel.makeWikidataItemIdValue(ALLOWED_VALUES_CONSTRAINT_QID);
public static ItemIdValue disallowedValueEntity = Datamodel.makeWikidataItemIdValue(DISALLOWED_VALUES_CONSTRAINT_QID); public static ItemIdValue disallowedValueEntity = Datamodel.makeWikidataItemIdValue(DISALLOWED_VALUES_CONSTRAINT_QID);
public static PropertyIdValue itemParameterPID = Datamodel.makeWikidataPropertyIdValue("P2305"); public static PropertyIdValue itemParameterPID = Datamodel.makeWikidataPropertyIdValue(ALLOWED_VALUES_CONSTRAINT_PID);
@Override @Override
public EditScrutinizer getScrutinizer() { public EditScrutinizer getScrutinizer() {

View File

@ -33,15 +33,15 @@ import org.wikidata.wdtk.datamodel.implementation.StatementImpl;
import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue;
import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue; import org.wikidata.wdtk.datamodel.interfaces.PropertyIdValue;
import org.wikidata.wdtk.datamodel.interfaces.Snak; import org.wikidata.wdtk.datamodel.interfaces.Snak;
import org.wikidata.wdtk.datamodel.interfaces.SnakGroup;
import org.wikidata.wdtk.datamodel.interfaces.Statement; import org.wikidata.wdtk.datamodel.interfaces.Statement;
import org.wikidata.wdtk.datamodel.interfaces.Value; import org.wikidata.wdtk.datamodel.interfaces.Value;
import java.util.Collections; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.openrefine.wikidata.qa.scrutinizers.SingleValueScrutinizer.SINGLE_VALUE_CONSTRAINT_QID;
public class SingleValueScrutinizerTest extends ScrutinizerTest { public class SingleValueScrutinizerTest extends ScrutinizerTest {
@ -49,9 +49,7 @@ public class SingleValueScrutinizerTest extends ScrutinizerTest {
public static Value value1 = Datamodel.makeWikidataItemIdValue("Q6581072"); public static Value value1 = Datamodel.makeWikidataItemIdValue("Q6581072");
public static Value value2 = Datamodel.makeWikidataItemIdValue("Q6581097"); public static Value value2 = Datamodel.makeWikidataItemIdValue("Q6581097");
public static ItemIdValue entityIdValue = Datamodel.makeWikidataItemIdValue("Q19474404"); public static ItemIdValue entityIdValue = Datamodel.makeWikidataItemIdValue(SINGLE_VALUE_CONSTRAINT_QID);
public static PropertyIdValue constraintException = Datamodel.makeWikidataPropertyIdValue("P2303");
public static Value exceptionValue = Datamodel.makeWikidataItemIdValue("Q7409772");
@Override @Override
public EditScrutinizer getScrutinizer() { public EditScrutinizer getScrutinizer() {
@ -67,14 +65,10 @@ public class SingleValueScrutinizerTest extends ScrutinizerTest {
Statement statement2 = new StatementImpl("P21", snak2, idA); Statement statement2 = new StatementImpl("P21", snak2, idA);
ItemUpdate update = new ItemUpdateBuilder(idA).addStatement(statement1).addStatement(statement2).build(); ItemUpdate update = new ItemUpdateBuilder(idA).addStatement(statement1).addStatement(statement2).build();
Snak snak = Datamodel.makeValueSnak(constraintException, exceptionValue); List<Statement> statementList = constraintParameterStatementList(entityIdValue, new ArrayList<>());
List<Snak> snakList = Collections.singletonList(snak);
SnakGroup snakGroup = Datamodel.makeSnakGroup(snakList);
List<SnakGroup> snakGroupList = Collections.singletonList(snakGroup);
List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList);
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(propertyIdValue, "Q19474404")).thenReturn(statementList); when(fetcher.getConstraintsByType(propertyIdValue, SINGLE_VALUE_CONSTRAINT_QID)).thenReturn(statementList);
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(update); scrutinize(update);
assertWarningsRaised(SingleValueScrutinizer.type); assertWarningsRaised(SingleValueScrutinizer.type);
@ -87,14 +81,10 @@ public class SingleValueScrutinizerTest extends ScrutinizerTest {
Statement statement1 = new StatementImpl("P21", snak1, idA); Statement statement1 = new StatementImpl("P21", snak1, idA);
ItemUpdate updateA = new ItemUpdateBuilder(idA).addStatement(statement1).build(); ItemUpdate updateA = new ItemUpdateBuilder(idA).addStatement(statement1).build();
Snak snak = Datamodel.makeValueSnak(constraintException, exceptionValue); List<Statement> statementList = constraintParameterStatementList(entityIdValue, new ArrayList<>());
List<Snak> snakList = Collections.singletonList(snak);
SnakGroup snakGroup = Datamodel.makeSnakGroup(snakList);
List<SnakGroup> snakGroupList = Collections.singletonList(snakGroup);
List<Statement> statementList = constraintParameterStatementList(entityIdValue, snakGroupList);
ConstraintFetcher fetcher = mock(ConstraintFetcher.class); ConstraintFetcher fetcher = mock(ConstraintFetcher.class);
when(fetcher.getConstraintsByType(propertyIdValue, "Q19474404")).thenReturn(statementList); when(fetcher.getConstraintsByType(propertyIdValue, SINGLE_VALUE_CONSTRAINT_QID)).thenReturn(statementList);
setFetcher(fetcher); setFetcher(fetcher);
scrutinize(updateA); scrutinize(updateA);
assertNoWarningRaised(); assertNoWarningRaised();