From e7e5c134ded0814e590222264594beb1f2339ca2 Mon Sep 17 00:00:00 2001 From: Kanika Saini Date: Thu, 28 May 2020 22:18:22 +0530 Subject: [PATCH 1/2] validateStatementID() added that validates if the statement ID is of the right format --- .../implementation/DataObjectFactoryImpl.java | 2 +- .../implementation/StatementImpl.java | 32 +++++++++++++++++++ .../wdtk/datamodel/helpers/DatamodelTest.java | 6 ++-- .../datamodel/helpers/JsonSerializerTest.java | 6 ++-- .../helpers/StatementBuilderTest.java | 12 +++---- 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/DataObjectFactoryImpl.java b/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/DataObjectFactoryImpl.java index 268bf1bcc..889d6d04f 100644 --- a/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/DataObjectFactoryImpl.java +++ b/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/DataObjectFactoryImpl.java @@ -170,7 +170,7 @@ public Claim getClaim(EntityIdValue subject, Snak mainSnak, return getStatement( subject, mainSnak, qualifiers, Collections. emptyList(), StatementRank.NORMAL, - "empty id 12345").getClaim(); + "Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d").getClaim(); } @Override diff --git a/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/StatementImpl.java b/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/StatementImpl.java index fbb9c267f..387cfae69 100644 --- a/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/StatementImpl.java +++ b/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/StatementImpl.java @@ -74,6 +74,36 @@ public class StatementImpl implements Statement { private List qualifiersGroups; + /** + * Checks if the statement ID consists of a first part + * with the entity id of the item the statement belongs to, the separator $, plus + * a random hash of the form + * /^\{?[A-Z\d]{8}-[A-Z\d]{4}-[A-Z\d]{4}-[A-Z\d]{4}-[A-Z\d]{12}\}?\z/ + * + * @param statementID + * @return true if the statement ID is of the valid format + */ + public static boolean validateStatementID(String statementID) + { + if(statementID.equals("")) + return true; + + String separator = "\\$"; + String statementFormat ="^\\{?[A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}\\}?$"; + + String[] statementParts = statementID.split(separator); + if(statementParts.length != 2) + throw new IllegalArgumentException("Statement ID does not have the correct number of parts"); + + if(statementParts[0].charAt(0) != 'Q' && statementParts[0].charAt(0) != 'P' && statementParts[0].charAt(0) != 'L') + throw new TypeNotPresentException("Query,Property or Lexeme", null); + + if(!statementParts[1].matches(statementFormat)) + throw new IllegalStateException("Statement part does not have a correct format"); + + return true; + } + /** * Constructor. *

@@ -102,6 +132,7 @@ public StatementImpl( List references, EntityIdValue subjectId) { this.statementId = (statementId == null) ? "" : statementId; + boolean check = validateStatementID(statementId); Validate.notNull(rank, "No rank provided to create a statement."); this.rank = rank; @@ -131,6 +162,7 @@ public StatementImpl( List references, EntityIdValue subjectId) { this.statementId = (statementId == null) ? "" : statementId; + boolean check = validateStatementID(statementId); Validate.notNull(rank, "No rank provided to create a statement."); this.rank = rank; Validate.notNull(mainSnak, "No main snak provided to create a statement."); diff --git a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/DatamodelTest.java b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/DatamodelTest.java index 76ff7d326..9937905c0 100644 --- a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/DatamodelTest.java +++ b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/DatamodelTest.java @@ -341,12 +341,12 @@ public final void testGetStatement() { factory.getItemIdValue("Q42", "foo"), factory.getNoValueSnak(factory.getPropertyIdValue("P42", "foo")), Collections.emptyList(), Collections.emptyList(), - StatementRank.NORMAL, "MyId"); + StatementRank.NORMAL, "Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d"); Statement o2 = factory.getStatement( factory.getItemIdValue("Q42", "foo"), factory.getNoValueSnak(factory.getPropertyIdValue("P42", "foo")), Collections.emptyList(), Collections.emptyList(), - StatementRank.NORMAL, "MyId"); + StatementRank.NORMAL, "Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d"); assertEquals(o1, o2); } @@ -356,7 +356,7 @@ public final void testGetStatementGroup() { factory.getItemIdValue("Q42", "foo"), factory.getNoValueSnak(factory.getPropertyIdValue("P42", "foo")), Collections.emptyList(), Collections.emptyList(), - StatementRank.NORMAL, "MyId"); + StatementRank.NORMAL, "Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d"); StatementGroup o1 = Datamodel.makeStatementGroup(Collections.singletonList(s)); StatementGroup o2 = factory.getStatementGroup(Collections.singletonList(s)); assertEquals(o1, o2); diff --git a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/JsonSerializerTest.java b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/JsonSerializerTest.java index 100d15e72..b37cc22d1 100644 --- a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/JsonSerializerTest.java +++ b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/JsonSerializerTest.java @@ -55,7 +55,7 @@ public void testSerializer() throws IOException { Datamodel.makeStatement(qid1, Datamodel.makeNoValueSnak(Datamodel.makeWikidataPropertyIdValue("P42")), Collections.emptyList(), Collections.emptyList(), - StatementRank.NORMAL, "MyId" + StatementRank.NORMAL, "Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d" )))), Collections.emptyMap(), 1234); ItemDocument id2 = Datamodel.makeItemDocument( Datamodel.makeWikidataItemIdValue("Q2"), @@ -121,8 +121,8 @@ public void testStatementToJson() { Statement s = Datamodel.makeStatement(ItemIdValue.NULL, Datamodel.makeNoValueSnak(Datamodel.makeWikidataPropertyIdValue("P1")), Collections.emptyList(), Collections.emptyList(), - StatementRank.NORMAL, "MyId"); - String json = "{\"rank\":\"normal\",\"id\":\"MyId\",\"mainsnak\":{\"property\":\"P1\",\"snaktype\":\"novalue\"},\"type\":\"statement\"}"; + StatementRank.NORMAL, "Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d"); + String json = "{\"rank\":\"normal\",\"id\":\"Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d\",\"mainsnak\":{\"property\":\"P1\",\"snaktype\":\"novalue\"},\"type\":\"statement\"}"; JsonComparator.compareJsonStrings(json, JsonSerializer.getJsonString(s)); } diff --git a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/StatementBuilderTest.java b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/StatementBuilderTest.java index 25d4f330d..912826581 100644 --- a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/StatementBuilderTest.java +++ b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/StatementBuilderTest.java @@ -64,11 +64,11 @@ public void testComplexStatement() { Statement stmt1 = Datamodel.makeStatement(i, Datamodel.makeValueSnak(p, i), Collections.singletonList(sg), - Collections.singletonList(r), StatementRank.PREFERRED, "id"); + Collections.singletonList(r), StatementRank.PREFERRED, "Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d"); Statement stmt2 = StatementBuilder.forSubjectAndProperty(i, p) .withRank(StatementRank.PREFERRED).withValue(i) .withQualifierSomeValue(p).withQualifierNoValue(p) - .withQualifierValue(p, i).withId("id").withReference(r).build(); + .withQualifierValue(p, i).withId("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d").withReference(r).build(); assertEquals(stmt1, stmt2); } @@ -87,10 +87,10 @@ public void testQualifierList() { Statement stmt1 = Datamodel.makeStatement(i, Datamodel.makeValueSnak(p, i), Collections.singletonList(sg), - Collections.singletonList(r), StatementRank.PREFERRED, "id"); + Collections.singletonList(r), StatementRank.PREFERRED, "Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d"); Statement stmt2 = StatementBuilder.forSubjectAndProperty(i, p) .withRank(StatementRank.PREFERRED).withValue(i) - .withQualifiers(stmt1.getQualifiers()).withId("id") + .withQualifiers(stmt1.getQualifiers()).withId("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d") .withReference(r).build(); assertEquals(stmt1, stmt2); @@ -112,11 +112,11 @@ public void testReferenceList() { Statement stmt1 = Datamodel.makeStatement(i, Datamodel.makeValueSnak(p, i), Collections.singletonList(sg), - Arrays.asList(r1, r2), StatementRank.PREFERRED, "id"); + Arrays.asList(r1, r2), StatementRank.PREFERRED, "Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d"); Statement stmt2 = StatementBuilder.forSubjectAndProperty(i, p) .withRank(StatementRank.PREFERRED).withValue(i) .withQualifierSomeValue(p).withQualifierNoValue(p) - .withQualifierValue(p, i).withId("id") + .withQualifierValue(p, i).withId("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d") .withReferences(Arrays.asList(r1, r2)).build(); assertEquals(stmt1, stmt2); From 2f3daa9269312291771f58b4580fb253a5cf1d9d Mon Sep 17 00:00:00 2001 From: Kanika Saini Date: Fri, 29 May 2020 17:15:31 +0530 Subject: [PATCH 2/2] All test cases fixed --- .../implementation/StatementImpl.java | 4 +-- .../helpers/DatamodelConverterTest.java | 2 +- .../helpers/DatamodelFilterTest.java | 2 +- .../datamodel/helpers/FilterCopyTest.java | 6 ++-- .../DataObjectFactoryImplTest.java | 2 +- .../implementation/FormDocumentImplTest.java | 8 ++--- .../implementation/ItemDocumentImplTest.java | 6 ++-- .../LexemeDocumentImplTest.java | 8 ++--- .../MediaInfoDocumentImplTest.java | 10 +++---- .../PropertyDocumentImplTest.java | 6 ++-- .../implementation/SenseDocumentImplTest.java | 8 ++--- .../implementation/StatementGroupTest.java | 10 +++---- .../implementation/StatementImplTest.java | 30 +++++++++---------- .../TermedStatementDocumentImplTest.java | 4 +-- 14 files changed, 53 insertions(+), 53 deletions(-) diff --git a/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/StatementImpl.java b/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/StatementImpl.java index 387cfae69..bdcafde1c 100644 --- a/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/StatementImpl.java +++ b/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/StatementImpl.java @@ -95,7 +95,7 @@ public static boolean validateStatementID(String statementID) if(statementParts.length != 2) throw new IllegalArgumentException("Statement ID does not have the correct number of parts"); - if(statementParts[0].charAt(0) != 'Q' && statementParts[0].charAt(0) != 'P' && statementParts[0].charAt(0) != 'L') + if(statementParts[0].charAt(0) != 'Q' && statementParts[0].charAt(0) != 'P' && statementParts[0].charAt(0) != 'L' && statementParts[0].charAt(0) != 'M') throw new TypeNotPresentException("Query,Property or Lexeme", null); if(!statementParts[1].matches(statementFormat)) @@ -132,7 +132,7 @@ public StatementImpl( List references, EntityIdValue subjectId) { this.statementId = (statementId == null) ? "" : statementId; - boolean check = validateStatementID(statementId); + boolean check = validateStatementID(this.statementId); Validate.notNull(rank, "No rank provided to create a statement."); this.rank = rank; diff --git a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/DatamodelConverterTest.java b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/DatamodelConverterTest.java index 18ef7db37..ef6350547 100644 --- a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/DatamodelConverterTest.java +++ b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/DatamodelConverterTest.java @@ -76,7 +76,7 @@ private Statement getBrokenStatement() { return Datamodel.makeStatement( getTestItemIdValue(2), brokenSnak, Collections.emptyList(), Collections.emptyList(), - StatementRank.NORMAL, "id"); + StatementRank.NORMAL, "Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d"); } /** diff --git a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/DatamodelFilterTest.java b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/DatamodelFilterTest.java index 5289b21a0..97f7dacc5 100644 --- a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/DatamodelFilterTest.java +++ b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/DatamodelFilterTest.java @@ -207,7 +207,7 @@ private StatementGroup makeTestStatementGroup( subjectIdValue, Datamodel.makeSomeValueSnak(propertyIdValue), Collections.emptyList(), Collections.emptyList(), - StatementRank.NORMAL, "statement-id-" + propertyIdValue.getId()); + StatementRank.NORMAL, propertyIdValue.getId() + "$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d"); return Datamodel.makeStatementGroup(Collections.singletonList(statement)); } diff --git a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/FilterCopyTest.java b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/FilterCopyTest.java index bc39c3198..0215c93fb 100644 --- a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/FilterCopyTest.java +++ b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/helpers/FilterCopyTest.java @@ -167,7 +167,7 @@ private StatementGroup makeTestStatementGroup( Datamodel.makeWikidataItemIdValue("Q42"), Datamodel.makeSomeValueSnak(propertyIdValue), Collections.emptyList(), Collections.emptyList(), - StatementRank.NORMAL,"statement-id-" + propertyIdValue.getId()); + StatementRank.NORMAL,propertyIdValue.getId() + "$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d"); return Datamodel.makeStatementGroup(Collections .singletonList(statement)); } @@ -367,7 +367,7 @@ public void testDeepCopyReferencesFilter() { Statement statement = Datamodel.makeStatement( Datamodel.makeWikidataItemIdValue("Q42"), snak, Collections.emptyList(), Collections.singletonList(reference), - StatementRank.NORMAL,"statement-id-" + propertyIdValue.getId()); + StatementRank.NORMAL,propertyIdValue.getId() + "$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d"); StatementGroup statementGroup = Datamodel .makeStatementGroup(Collections.singletonList(statement)); ItemDocument itemDocument = Datamodel.makeItemDocument( @@ -381,7 +381,7 @@ public void testDeepCopyReferencesFilter() { Statement statementFiltered = Datamodel.makeStatement( Datamodel.makeWikidataItemIdValue("Q42"), snak, Collections.emptyList(), Collections.emptyList(), - StatementRank.NORMAL,"statement-id-" + propertyIdValue.getId()); + StatementRank.NORMAL,propertyIdValue.getId() + "$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d"); StatementGroup statementGroupFiltered = Datamodel .makeStatementGroup(Collections .singletonList(statementFiltered)); diff --git a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/DataObjectFactoryImplTest.java b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/DataObjectFactoryImplTest.java index 0816fcf18..f22a94d75 100644 --- a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/DataObjectFactoryImplTest.java +++ b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/DataObjectFactoryImplTest.java @@ -219,7 +219,7 @@ public final void testGetStatementGroup() { factory.getItemIdValue("Q42", "foo"), factory.getNoValueSnak(factory.getPropertyIdValue("P42", "foo")), Collections.emptyList(), Collections.emptyList(), - StatementRank.NORMAL, "MyId"); + StatementRank.NORMAL, "Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d"); StatementGroup o1 = new StatementGroupImpl(Collections.singletonList(s)); StatementGroup o2 = factory.getStatementGroup(Collections.singletonList(s)); assertEquals(o1, o2); diff --git a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/FormDocumentImplTest.java b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/FormDocumentImplTest.java index 71c57fc0f..41781673c 100644 --- a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/FormDocumentImplTest.java +++ b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/FormDocumentImplTest.java @@ -40,7 +40,7 @@ public class FormDocumentImplTest { new ItemIdValueImpl("Q2", "http://example.com/entity/"), new ItemIdValueImpl("Q1", "http://example.com/entity/") ); - private final Statement s = new StatementImpl("MyId", StatementRank.NORMAL, + private final Statement s = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, new SomeValueSnakImpl(new PropertyIdValueImpl("P42", "http://example.com/entity/")), Collections.emptyList(), Collections.emptyList(), fid); private final List statementGroups = Collections.singletonList( @@ -52,7 +52,7 @@ public class FormDocumentImplTest { private final FormDocument fd1 = new FormDocumentImpl(fid, repList, gramFeatures, statementGroups, 1234); private final FormDocument fd2 = new FormDocumentImpl(fid, repList, gramFeatures, statementGroups, 1234); - private final String JSON_FORM = "{\"type\":\"form\",\"id\":\"L42-F1\",\"grammaticalFeatures\":[\"Q1\",\"Q2\"],\"representations\":{\"en\":{\"language\":\"en\",\"value\":\"rep\"}},\"claims\":{\"P42\":[{\"rank\":\"normal\",\"id\":\"MyId\",\"mainsnak\":{\"property\":\"P42\",\"snaktype\":\"somevalue\"},\"type\":\"statement\"}]},\"lastrevid\":1234}"; + private final String JSON_FORM = "{\"type\":\"form\",\"id\":\"L42-F1\",\"grammaticalFeatures\":[\"Q1\",\"Q2\"],\"representations\":{\"en\":{\"language\":\"en\",\"value\":\"rep\"}},\"claims\":{\"P42\":[{\"rank\":\"normal\",\"id\":\"Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d\",\"mainsnak\":{\"property\":\"P42\",\"snaktype\":\"somevalue\"},\"type\":\"statement\"}]},\"lastrevid\":1234}"; @Test public void fieldsAreCorrect() { @@ -124,7 +124,7 @@ public void statementGroupsCanBeNull() { @Test(expected = IllegalArgumentException.class) public void statementGroupsUseSameSubject() { FormIdValue iid2 = new FormIdValueImpl("Q23", "http://example.org/"); - Statement s2 = new StatementImpl("MyId", StatementRank.NORMAL, + Statement s2 = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, new SomeValueSnakImpl(new PropertyIdValueImpl("P42", "http://wikibase.org/entity/")), Collections.emptyList(), Collections.emptyList(), iid2); StatementGroup sg2 = new StatementGroupImpl(Collections.singletonList(s2)); @@ -175,7 +175,7 @@ public void testWithExistingGrammaticalFeatures() { @Test public void testAddStatement() { - Statement fresh = new StatementImpl("MyFreshId", StatementRank.NORMAL, + Statement fresh = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, new SomeValueSnakImpl(new PropertyIdValueImpl("P29", "http://example.com/entity/")), Collections.emptyList(), Collections.emptyList(), fid); Claim claim = fresh.getClaim(); diff --git a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/ItemDocumentImplTest.java b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/ItemDocumentImplTest.java index a47e27b80..84d0f4d45 100644 --- a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/ItemDocumentImplTest.java +++ b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/ItemDocumentImplTest.java @@ -40,7 +40,7 @@ public class ItemDocumentImplTest { private final ObjectMapper mapper = new DatamodelMapper("http://example.com/entity/"); private final ItemIdValue iid = new ItemIdValueImpl("Q42", "http://example.com/entity/"); - private final Statement s = new StatementImpl("MyId", StatementRank.NORMAL, + private final Statement s = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, new SomeValueSnakImpl(new PropertyIdValueImpl("P42", "http://example.com/entity/")), Collections.emptyList(), Collections.emptyList(), iid); private final List statementGroups = Collections.singletonList( @@ -66,7 +66,7 @@ public class ItemDocumentImplTest { private final String JSON_ITEM_LABEL = "{\"type\":\"item\",\"id\":\"Q42\",\"labels\":{\"en\":{\"language\":\"en\",\"value\":\"label\"}},\"descriptions\":{},\"aliases\":{},\"claims\":{},\"sitelinks\":{}}"; private final String JSON_ITEM_DESCRIPTION = "{\"type\":\"item\",\"id\":\"Q42\",\"labels\":{},\"descriptions\":{\"fr\":{\"language\":\"fr\",\"value\":\"des\"}},\"aliases\":{},\"claims\":{},\"sitelinks\":{}}"; private final String JSON_ITEM_ALIASES = "{\"type\":\"item\",\"id\":\"Q42\",\"labels\":{},\"descriptions\":{},\"aliases\":{\"de\":[{\"language\":\"de\",\"value\":\"alias\"}]},\"claims\":{},\"sitelinks\":{}}"; - private final String JSON_ITEM_STATEMENTS = "{\"type\":\"item\",\"id\":\"Q42\",\"labels\":{},\"descriptions\":{},\"aliases\":{},\"claims\":{\"P42\":[{\"rank\":\"normal\",\"id\":\"MyId\",\"mainsnak\":{\"property\":\"P42\",\"snaktype\":\"somevalue\"},\"type\":\"statement\"}]},\"sitelinks\":{}}"; + private final String JSON_ITEM_STATEMENTS = "{\"type\":\"item\",\"id\":\"Q42\",\"labels\":{},\"descriptions\":{},\"aliases\":{},\"claims\":{\"P42\":[{\"rank\":\"normal\",\"id\":\"Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d\",\"mainsnak\":{\"property\":\"P42\",\"snaktype\":\"somevalue\"},\"type\":\"statement\"}]},\"sitelinks\":{}}"; private final String JSON_ITEM_SITELINKS = "{\"type\":\"item\",\"id\":\"Q42\",\"labels\":{},\"descriptions\":{},\"aliases\":{},\"claims\":{},\"sitelinks\":{\"enwiki\":{\"title\":\"Douglas Adams\",\"site\":\"enwiki\",\"badges\":[]}}}"; private final String JSON_ITEM_EMPTY_ARRAYS = "{\"type\":\"item\",\"id\":\"Q42\",\"labels\":[],\"descriptions\":[],\"aliases\":[],\"claims\":[],\"sitelinks\":[]}"; @@ -278,7 +278,7 @@ public void testWithOverridenAliases() { @Test public void testAddStatement() { - Statement fresh = new StatementImpl("MyFreshId", StatementRank.NORMAL, + Statement fresh = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, new SomeValueSnakImpl(new PropertyIdValueImpl("P29", "http://example.com/entity/")), Collections.emptyList(), Collections.emptyList(), iid); Claim claim = fresh.getClaim(); diff --git a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/LexemeDocumentImplTest.java b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/LexemeDocumentImplTest.java index f1c215859..884b669de 100644 --- a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/LexemeDocumentImplTest.java +++ b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/LexemeDocumentImplTest.java @@ -42,7 +42,7 @@ public class LexemeDocumentImplTest { private final LexemeIdValue lid = new LexemeIdValueImpl("L42", "http://example.com/entity/"); private final ItemIdValue lexCat = new ItemIdValueImpl("Q1", "http://example.com/entity/"); private final ItemIdValue language = new ItemIdValueImpl("Q2", "http://example.com/entity/"); - private final Statement s = new StatementImpl("MyId", StatementRank.NORMAL, + private final Statement s = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, new SomeValueSnakImpl(new PropertyIdValueImpl("P42", "http://example.com/entity/")), Collections.emptyList(), Collections.emptyList(), lid); private final List statementGroups = Collections.singletonList( @@ -69,7 +69,7 @@ public class LexemeDocumentImplTest { private final LexemeDocument ld1 = new LexemeDocumentImpl(lid, lexCat, language, lemmaList, statementGroups, forms, senses, 1234); private final LexemeDocument ld2 = new LexemeDocumentImpl(lid, lexCat, language, lemmaList, statementGroups, forms, senses, 1234); - private final String JSON_LEXEME = "{\"type\":\"lexeme\",\"id\":\"L42\",\"lexicalCategory\":\"Q1\",\"language\":\"Q2\",\"lemmas\":{\"en\":{\"language\":\"en\",\"value\":\"lemma\"}},\"claims\":{\"P42\":[{\"rank\":\"normal\",\"id\":\"MyId\",\"mainsnak\":{\"property\":\"P42\",\"snaktype\":\"somevalue\"},\"type\":\"statement\"}]},\"forms\":[{\"type\":\"form\",\"id\":\"L42-F1\",\"representations\":{\"en\":{\"language\":\"en\",\"value\":\"foo\"}},\"grammaticalFeatures\":[],\"claims\":{}}],\"senses\":[{\"type\":\"sense\",\"id\":\"L42-S1\",\"glosses\":{\"en\":{\"language\":\"en\",\"value\":\"foo meaning\"}},\"claims\":{}}],\"lastrevid\":1234}"; + private final String JSON_LEXEME = "{\"type\":\"lexeme\",\"id\":\"L42\",\"lexicalCategory\":\"Q1\",\"language\":\"Q2\",\"lemmas\":{\"en\":{\"language\":\"en\",\"value\":\"lemma\"}},\"claims\":{\"P42\":[{\"rank\":\"normal\",\"id\":\"Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d\",\"mainsnak\":{\"property\":\"P42\",\"snaktype\":\"somevalue\"},\"type\":\"statement\"}]},\"forms\":[{\"type\":\"form\",\"id\":\"L42-F1\",\"representations\":{\"en\":{\"language\":\"en\",\"value\":\"foo\"}},\"grammaticalFeatures\":[],\"claims\":{}}],\"senses\":[{\"type\":\"sense\",\"id\":\"L42-S1\",\"glosses\":{\"en\":{\"language\":\"en\",\"value\":\"foo meaning\"}},\"claims\":{}}],\"lastrevid\":1234}"; @Test public void fieldsAreCorrect() { @@ -173,7 +173,7 @@ public void statementGroupsCanBeNull() { @Test(expected = IllegalArgumentException.class) public void statementGroupsUseSameSubject() { LexemeIdValue iid2 = new LexemeIdValueImpl("Q23", "http://example.org/"); - Statement s2 = new StatementImpl("MyId", StatementRank.NORMAL, + Statement s2 = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, new SomeValueSnakImpl(new PropertyIdValueImpl("P42", "http://wikibase.org/entity/")), Collections.emptyList(), Collections.emptyList(), iid2); StatementGroup sg2 = new StatementGroupImpl(Collections.singletonList(s2)); @@ -235,7 +235,7 @@ public void testWithLemmaInNewLanguage() { @Test public void testAddStatement() { - Statement fresh = new StatementImpl("MyFreshId", StatementRank.NORMAL, + Statement fresh = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, new SomeValueSnakImpl(new PropertyIdValueImpl("P29", "http://example.com/entity/")), Collections.emptyList(), Collections.emptyList(), lid); Claim claim = fresh.getClaim(); diff --git a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/MediaInfoDocumentImplTest.java b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/MediaInfoDocumentImplTest.java index d5d3ae8d2..b93c6ce76 100644 --- a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/MediaInfoDocumentImplTest.java +++ b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/MediaInfoDocumentImplTest.java @@ -40,7 +40,7 @@ public class MediaInfoDocumentImplTest { private final ObjectMapper mapper = new DatamodelMapper("http://example.com/entity/"); private final MediaInfoIdValue mid = new MediaInfoIdValueImpl("M42", "http://example.com/entity/"); - private final Statement s = new StatementImpl("MyId", StatementRank.NORMAL, + private final Statement s = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, new SomeValueSnakImpl(new PropertyIdValueImpl("P42", "http://example.com/entity/")), Collections.emptyList(), Collections.emptyList(), mid); private final List statementGroups = Collections.singletonList( @@ -54,8 +54,8 @@ public class MediaInfoDocumentImplTest { private final String JSON_MEDIA_INFO_LABEL = "{\"type\":\"mediainfo\",\"id\":\"M42\",\"labels\":{\"en\":{\"language\":\"en\",\"value\":\"label\"}},\"claims\":{}}"; private final String JSON_MEDIA_INFO_DESCRIPTION = "{\"type\":\"mediainfo\",\"id\":\"M42\",\"labels\":{},\"descriptions\":{},\"statements\":{}}"; - private final String JSON_MEDIA_INFO_STATEMENTS = "{\"type\":\"mediainfo\",\"id\":\"M42\",\"labels\":{},\"statements\":{\"P42\":[{\"rank\":\"normal\",\"id\":\"MyId\",\"mainsnak\":{\"property\":\"P42\",\"snaktype\":\"somevalue\"},\"type\":\"statement\"}]}}"; - private final String JSON_MEDIA_INFO_CLAIMS = "{\"type\":\"mediainfo\",\"id\":\"M42\",\"labels\":{},\"claims\":{\"P42\":[{\"rank\":\"normal\",\"id\":\"MyId\",\"mainsnak\":{\"property\":\"P42\",\"snaktype\":\"somevalue\"},\"type\":\"statement\"}]}}"; + private final String JSON_MEDIA_INFO_STATEMENTS = "{\"type\":\"mediainfo\",\"id\":\"M42\",\"labels\":{},\"statements\":{\"P42\":[{\"rank\":\"normal\",\"id\":\"Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d\",\"mainsnak\":{\"property\":\"P42\",\"snaktype\":\"somevalue\"},\"type\":\"statement\"}]}}"; + private final String JSON_MEDIA_INFO_CLAIMS = "{\"type\":\"mediainfo\",\"id\":\"M42\",\"labels\":{},\"claims\":{\"P42\":[{\"rank\":\"normal\",\"id\":\"Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d\",\"mainsnak\":{\"property\":\"P42\",\"snaktype\":\"somevalue\"},\"type\":\"statement\"}]}}"; private final String JSON_MEDIA_INFO_EMPTY_ARRAYS = "{\"type\":\"mediainfo\",\"id\":\"M42\",\"labels\":[],\"descriptions\":[],\"statements\":[],\"sitelinks\":[]}"; @Test @@ -130,7 +130,7 @@ public void statementGroupsCanBeNull() { @Test(expected = IllegalArgumentException.class) public void statementGroupsUseSameSubject() { MediaInfoIdValue mid2 = new MediaInfoIdValueImpl("Q23", "http://example.org/"); - Statement s2 = new StatementImpl("MyId", StatementRank.NORMAL, + Statement s2 = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, new SomeValueSnakImpl(new PropertyIdValueImpl("P42", "http://wikibase.org/entity/")), Collections.emptyList(), Collections.emptyList(), mid2); StatementGroup sg2 = new StatementGroupImpl(Collections.singletonList(s2)); @@ -167,7 +167,7 @@ public void testWithLabelInNewLanguage() { @Test public void testAddStatement() { - Statement fresh = new StatementImpl("MyFreshId", StatementRank.NORMAL, + Statement fresh = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, new SomeValueSnakImpl(new PropertyIdValueImpl("P29", "http://example.com/entity/")), Collections.emptyList(), Collections.emptyList(), mid); Claim claim = fresh.getClaim(); diff --git a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/PropertyDocumentImplTest.java b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/PropertyDocumentImplTest.java index 3facfc3c8..20a359f52 100644 --- a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/PropertyDocumentImplTest.java +++ b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/PropertyDocumentImplTest.java @@ -41,7 +41,7 @@ public class PropertyDocumentImplTest { private final ObjectMapper mapper = new DatamodelMapper("http://example.com/entity/"); private PropertyIdValue pid = new PropertyIdValueImpl("P2", "http://example.com/entity/"); - private final Statement s = new StatementImpl("MyId", StatementRank.NORMAL, + private final Statement s = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, new SomeValueSnakImpl(new PropertyIdValueImpl("P42", "http://example.com/entity/")), Collections.emptyList(), Collections.emptyList(), pid); private final List statementGroups = Collections.singletonList( @@ -60,7 +60,7 @@ public class PropertyDocumentImplTest { private final PropertyDocument pd2 = new PropertyDocumentImpl(pid, labelList, descList, aliasList, statementGroups, datatypeId, 1234); - private final String JSON_PROPERTY = "{\"type\":\"property\",\"id\":\"P2\",\"labels\":{\"en\":{\"language\":\"en\",\"value\":\"label\"}},\"descriptions\":{\"fr\":{\"language\":\"fr\",\"value\":\"des\"}},\"aliases\":{\"de\":[{\"language\":\"de\",\"value\":\"alias\"}]},\"claims\":{\"P42\":[{\"rank\":\"normal\",\"id\":\"MyId\",\"mainsnak\":{\"property\":\"P42\",\"snaktype\":\"somevalue\"},\"type\":\"statement\"}]},\"datatype\":\"wikibase-item\",\"lastrevid\":1234}"; + private final String JSON_PROPERTY = "{\"type\":\"property\",\"id\":\"P2\",\"labels\":{\"en\":{\"language\":\"en\",\"value\":\"label\"}},\"descriptions\":{\"fr\":{\"language\":\"fr\",\"value\":\"des\"}},\"aliases\":{\"de\":[{\"language\":\"de\",\"value\":\"alias\"}]},\"claims\":{\"P42\":[{\"rank\":\"normal\",\"id\":\"Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d\",\"mainsnak\":{\"property\":\"P42\",\"snaktype\":\"somevalue\"},\"type\":\"statement\"}]},\"datatype\":\"wikibase-item\",\"lastrevid\":1234}"; @Test public void fieldsAreCorrect() { @@ -277,7 +277,7 @@ public void testWithOverridenAliases() { @Test public void testAddStatement() { - Statement fresh = new StatementImpl("MyFreshId", StatementRank.NORMAL, + Statement fresh = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, new SomeValueSnakImpl(new PropertyIdValueImpl("P29", "http://example.com/entity/")), Collections.emptyList(), Collections.emptyList(), pid); Claim claim = fresh.getClaim(); diff --git a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/SenseDocumentImplTest.java b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/SenseDocumentImplTest.java index b92a96d23..a8a3db91f 100644 --- a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/SenseDocumentImplTest.java +++ b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/SenseDocumentImplTest.java @@ -36,7 +36,7 @@ public class SenseDocumentImplTest { private final ObjectMapper mapper = new DatamodelMapper("http://example.com/entity/"); private final SenseIdValue sid = new SenseIdValueImpl("L42-S1", "http://example.com/entity/"); - private final Statement s = new StatementImpl("MyId", StatementRank.NORMAL, + private final Statement s = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, new SomeValueSnakImpl(new PropertyIdValueImpl("P42", "http://example.com/entity/")), Collections.emptyList(), Collections.emptyList(), sid); private final List statementGroups = Collections.singletonList( @@ -48,7 +48,7 @@ public class SenseDocumentImplTest { private final SenseDocument sd1 = new SenseDocumentImpl(sid, repList, statementGroups, 1234); private final SenseDocument sd2 = new SenseDocumentImpl(sid, repList, statementGroups, 1234); - private final String JSON_SENSE = "{\"type\":\"sense\",\"id\":\"L42-S1\",\"glosses\":{\"en\":{\"language\":\"en\",\"value\":\"rep\"}},\"claims\":{\"P42\":[{\"rank\":\"normal\",\"id\":\"MyId\",\"mainsnak\":{\"property\":\"P42\",\"snaktype\":\"somevalue\"},\"type\":\"statement\"}]},\"lastrevid\":1234}"; + private final String JSON_SENSE = "{\"type\":\"sense\",\"id\":\"L42-S1\",\"glosses\":{\"en\":{\"language\":\"en\",\"value\":\"rep\"}},\"claims\":{\"P42\":[{\"rank\":\"normal\",\"id\":\"Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d\",\"mainsnak\":{\"property\":\"P42\",\"snaktype\":\"somevalue\"},\"type\":\"statement\"}]},\"lastrevid\":1234}"; @Test public void fieldsAreCorrect() { @@ -111,7 +111,7 @@ public void statementGroupsCanBeNull() { @Test(expected = IllegalArgumentException.class) public void statementGroupsUseSameSubject() { SenseIdValue iid2 = new SenseIdValueImpl("Q23", "http://example.org/"); - Statement s2 = new StatementImpl("MyId", StatementRank.NORMAL, + Statement s2 = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, new SomeValueSnakImpl(new PropertyIdValueImpl("P42", "http://wikibase.org/entity/")), Collections.emptyList(), Collections.emptyList(), iid2); StatementGroup sg2 = new StatementGroupImpl(Collections.singletonList(s2)); @@ -147,7 +147,7 @@ public void testWithGlossInNewLanguage() { @Test public void testAddStatement() { - Statement fresh = new StatementImpl("MyFreshId", StatementRank.NORMAL, + Statement fresh = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, new SomeValueSnakImpl(new PropertyIdValueImpl("P29", "http://example.com/entity/")), Collections.emptyList(), Collections.emptyList(), sid); Claim claim = fresh.getClaim(); diff --git a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/StatementGroupTest.java b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/StatementGroupTest.java index c2b09a73d..f6e4c8e24 100644 --- a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/StatementGroupTest.java +++ b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/StatementGroupTest.java @@ -38,13 +38,13 @@ public class StatementGroupTest { private EntityIdValue subject = new ItemIdValueImpl("Q42", "http://wikidata.org/entity/"); private PropertyIdValue property = new PropertyIdValueImpl("P42", "http://wikidata.org/entity/"); private Snak mainSnak = new ValueSnakImpl(property, subject); - private Statement statement1 = new StatementImpl("MyId", StatementRank.NORMAL, mainSnak, + private Statement statement1 = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, mainSnak, Collections.emptyList(), Collections.emptyList(), subject); - private Statement statement2 = new StatementImpl("MyId", StatementRank.PREFERRED, mainSnak, + private Statement statement2 = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.PREFERRED, mainSnak, Collections.emptyList(), Collections.emptyList(), subject); private Statement statementEmptyId = new StatementImpl("", StatementRank.NORMAL, mainSnak, Collections.emptyList(), Collections.emptyList(), subject); - private Statement statementDeprecrated = new StatementImpl("DepId", StatementRank.DEPRECATED, mainSnak, + private Statement statementDeprecrated = new StatementImpl("Q1221$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.DEPRECATED, mainSnak, Collections.emptyList(), Collections.emptyList(), subject); private StatementGroup sg1 = new StatementGroupImpl(Collections.singletonList(statement1)); private StatementGroup sg2 = new StatementGroupImpl(Collections.singletonList(statement1)); @@ -137,7 +137,7 @@ public void statementListRequiresSameSubject() { EntityIdValue subject2 = new ItemIdValueImpl("Q23", "http://wikidata.org/entity/"); Snak mainSnak = new NoValueSnakImpl(property); - Statement s2 = new StatementImpl("MyId", StatementRank.NORMAL, mainSnak, + Statement s2 = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, mainSnak, Collections.emptyList(), Collections.emptyList(), subject2); statements.add(s2); @@ -152,7 +152,7 @@ public void statementListRequiresSameProperty() { PropertyIdValue property2 = new PropertyIdValueImpl("P23", "http://wikidata.org/entity/"); Snak mainSnak = new NoValueSnakImpl(property2); - Statement s2 = new StatementImpl("MyId", StatementRank.NORMAL, mainSnak, + Statement s2 = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, mainSnak, Collections.emptyList(), Collections.emptyList(), subject); statements.add(s2); diff --git a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/StatementImplTest.java b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/StatementImplTest.java index 0c86fc7b9..0a5e7d7be 100644 --- a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/StatementImplTest.java +++ b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/StatementImplTest.java @@ -44,15 +44,15 @@ public class StatementImplTest { private final List references = Collections.singletonList(new ReferenceImpl(qualifiers)); private final Claim claim = new ClaimImpl(subjet, mainSnak, qualifiers); - private final Statement s1 = new StatementImpl("MyId", StatementRank.PREFERRED, mainSnak, + private final Statement s1 = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.PREFERRED, mainSnak, qualifiers, references, subjet); - private final Statement s2 = new StatementImpl("MyId", StatementRank.PREFERRED, mainSnak, + private final Statement s2 = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.PREFERRED, mainSnak, qualifiers, references, subjet); - private final String JSON_STATEMENT = "{\"rank\":\"preferred\",\"references\":[{\"snaks\":{\"P42\":[{\"property\":\"P42\",\"datatype\":\"wikibase-item\",\"datavalue\":{\"value\":{\"id\":\"Q42\",\"numeric-id\":42,\"entity-type\":\"item\"},\"type\":\"wikibase-entityid\"},\"snaktype\":\"value\"}]},\"snaks-order\":[\"P42\"]}],\"id\":\"MyId\",\"mainsnak\":{\"property\":\"P42\",\"datatype\":\"wikibase-item\",\"datavalue\":{\"value\":{\"id\":\"Q42\",\"numeric-id\":42,\"entity-type\":\"item\"},\"type\":\"wikibase-entityid\"},\"snaktype\":\"value\"},\"qualifiers-order\":[\"P42\"],\"type\":\"statement\",\"qualifiers\":{\"P42\":[{\"property\":\"P42\",\"datatype\":\"wikibase-item\",\"datavalue\":{\"value\":{\"id\":\"Q42\",\"numeric-id\":42,\"entity-type\":\"item\"},\"type\":\"wikibase-entityid\"},\"snaktype\":\"value\"}]}}"; + private final String JSON_STATEMENT = "{\"rank\":\"preferred\",\"references\":[{\"snaks\":{\"P42\":[{\"property\":\"P42\",\"datatype\":\"wikibase-item\",\"datavalue\":{\"value\":{\"id\":\"Q42\",\"numeric-id\":42,\"entity-type\":\"item\"},\"type\":\"wikibase-entityid\"},\"snaktype\":\"value\"}]},\"snaks-order\":[\"P42\"]}],\"id\":\"Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d\",\"mainsnak\":{\"property\":\"P42\",\"datatype\":\"wikibase-item\",\"datavalue\":{\"value\":{\"id\":\"Q42\",\"numeric-id\":42,\"entity-type\":\"item\"},\"type\":\"wikibase-entityid\"},\"snaktype\":\"value\"},\"qualifiers-order\":[\"P42\"],\"type\":\"statement\",\"qualifiers\":{\"P42\":[{\"property\":\"P42\",\"datatype\":\"wikibase-item\",\"datavalue\":{\"value\":{\"id\":\"Q42\",\"numeric-id\":42,\"entity-type\":\"item\"},\"type\":\"wikibase-entityid\"},\"snaktype\":\"value\"}]}}"; - private final Statement smallStatement = new StatementImpl("MyId", StatementRank.PREFERRED, mainSnak, + private final Statement smallStatement = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.PREFERRED, mainSnak, Collections.emptyList(), Collections.emptyList(), subjet); - private final String JSON_SMALL_STATEMENT = "{\"rank\":\"preferred\",\"id\":\"MyId\",\"mainsnak\":{\"property\":\"P42\",\"datatype\":\"wikibase-item\",\"datavalue\":{\"value\":{\"id\":\"Q42\",\"numeric-id\":42,\"entity-type\":\"item\"},\"type\":\"wikibase-entityid\"},\"snaktype\":\"value\"},\"type\":\"statement\"}"; + private final String JSON_SMALL_STATEMENT = "{\"rank\":\"preferred\",\"id\":\"Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d\",\"mainsnak\":{\"property\":\"P42\",\"datatype\":\"wikibase-item\",\"datavalue\":{\"value\":{\"id\":\"Q42\",\"numeric-id\":42,\"entity-type\":\"item\"},\"type\":\"wikibase-entityid\"},\"snaktype\":\"value\"},\"type\":\"statement\"}"; @Test public void gettersWorking() { @@ -61,26 +61,26 @@ public void gettersWorking() { assertEquals(s1.getQualifiers(), qualifiers); assertEquals(s1.getReferences(), references); assertEquals(s1.getRank(), StatementRank.PREFERRED); - assertEquals(s1.getStatementId(), "MyId"); + assertEquals(s1.getStatementId(), "Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d"); assertEquals(s1.getValue(), value); assertEquals(s1.getSubject(), subjet); } @Test(expected = NullPointerException.class) public void mainSnakNotNull() { - new StatementImpl("MyId", StatementRank.NORMAL, null, + new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, null, Collections.emptyList(), Collections.emptyList(), value); } @Test public void referencesCanBeNull() { - Statement statement = new StatementImpl("MyId", StatementRank.NORMAL, mainSnak, Collections.emptyList(), null, value); + Statement statement = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, mainSnak, Collections.emptyList(), null, value); assertTrue(statement.getReferences().isEmpty()); } @Test(expected = NullPointerException.class) public void rankNotNull() { - new StatementImpl("MyId", null, mainSnak, + new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", null, mainSnak, Collections.emptyList(), Collections.emptyList(), value); } @@ -94,8 +94,8 @@ public void idCanBeNull() { @Test public void withId() { Statement statement = new StatementImpl(null, StatementRank.NORMAL, claim.getMainSnak(), claim.getQualifiers(), Collections.emptyList(), claim.getSubject()); - Statement withId = statement.withStatementId("some id"); - assertEquals("some id", withId.getStatementId()); + Statement withId = statement.withStatementId("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d"); + assertEquals("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", withId.getStatementId()); } @Test @@ -105,16 +105,16 @@ public void hashBasedOnContent() { @Test public void equalityBasedOnContent() { - Statement sDiffClaim = new StatementImpl("MyId", StatementRank.NORMAL, mainSnak, + Statement sDiffClaim = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, mainSnak, Collections.emptyList(), Collections.emptyList(), new ItemIdValueImpl("Q43", "http://wikidata.org/entity/")); - Statement sDiffReferences = new StatementImpl("MyId", StatementRank.NORMAL, mainSnak, + Statement sDiffReferences = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, mainSnak, Collections.emptyList(), Collections.singletonList(new ReferenceImpl( Collections.singletonList(new SnakGroupImpl(Collections.singletonList(mainSnak))) )), value); - Statement sDiffRank = new StatementImpl("MyId", StatementRank.PREFERRED, mainSnak, + Statement sDiffRank = new StatementImpl("Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.PREFERRED, mainSnak, Collections.emptyList(), Collections.emptyList(), value); - Statement sDiffId = new StatementImpl("MyOtherId", StatementRank.NORMAL, mainSnak, + Statement sDiffId = new StatementImpl("Q1209$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d", StatementRank.NORMAL, mainSnak, Collections.emptyList(), Collections.emptyList(), value); assertEquals(s1, s1); diff --git a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/TermedStatementDocumentImplTest.java b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/TermedStatementDocumentImplTest.java index 3f8859044..85f15c178 100644 --- a/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/TermedStatementDocumentImplTest.java +++ b/wdtk-datamodel/src/test/java/org/wikidata/wdtk/datamodel/implementation/TermedStatementDocumentImplTest.java @@ -33,8 +33,8 @@ public class TermedStatementDocumentImplTest { private Map> initialStatements = null; private Statement statementA = null; private Statement statementEmptyId = null; - private String statementIdA = "myIdA"; - private String statementIdB = "myIdB"; + private String statementIdA = "Q5721$a763ede3-42b3-5ecb-ec0e-4bb85d4d348d"; + private String statementIdB = "Q5721$b763ede3-42b3-5ecb-ec0e-4bb85d4d348d"; @Before public void setUp() {