Add regression test for serialization of statement groups
This commit is contained in:
parent
8ae4c8fe94
commit
214efc73b4
111
extensions/wikidata/tests/data/updates/statement_groups.json
Normal file
111
extensions/wikidata/tests/data/updates/statement_groups.json
Normal file
@ -0,0 +1,111 @@
|
||||
{
|
||||
"addedAliases": [],
|
||||
"addedStatementGroups": [
|
||||
{
|
||||
"property": {
|
||||
"type": "wikibase-entityid",
|
||||
"value": {
|
||||
"entity-type": "property",
|
||||
"id": "P348",
|
||||
"numeric-id": 348
|
||||
}
|
||||
},
|
||||
"statements": [
|
||||
{
|
||||
"mainsnak": {
|
||||
"property": "P348",
|
||||
"snaktype": "novalue"
|
||||
},
|
||||
"rank": "normal",
|
||||
"type": "statement"
|
||||
}
|
||||
],
|
||||
"subject": {
|
||||
"type": "wikibase-entityid",
|
||||
"value": {
|
||||
"entity-type": "item",
|
||||
"id": "Q34",
|
||||
"numeric-id": 34
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"property": {
|
||||
"type": "wikibase-entityid",
|
||||
"value": {
|
||||
"entity-type": "property",
|
||||
"id": "P52",
|
||||
"numeric-id": 52
|
||||
}
|
||||
},
|
||||
"statements": [
|
||||
{
|
||||
"mainsnak": {
|
||||
"datatype": "wikibase-item",
|
||||
"datavalue": {
|
||||
"entityType": "http://www.wikidata.org/ontology#Item",
|
||||
"id": "Q1234",
|
||||
"iri": "http://localhost/entity/Q1234",
|
||||
"label": "new item",
|
||||
"reconInternalId": 1234,
|
||||
"siteIri": "http://localhost/entity/",
|
||||
"types": []
|
||||
},
|
||||
"property": "P52",
|
||||
"snaktype": "value"
|
||||
},
|
||||
"rank": "normal",
|
||||
"type": "statement"
|
||||
}
|
||||
],
|
||||
"subject": {
|
||||
"type": "wikibase-entityid",
|
||||
"value": {
|
||||
"entity-type": "item",
|
||||
"id": "Q34",
|
||||
"numeric-id": 34
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"addedStatements": [
|
||||
{
|
||||
"mainsnak": {
|
||||
"property": "P348",
|
||||
"snaktype": "novalue"
|
||||
},
|
||||
"rank": "normal",
|
||||
"type": "statement"
|
||||
},
|
||||
{
|
||||
"mainsnak": {
|
||||
"datatype": "wikibase-item",
|
||||
"datavalue": {
|
||||
"entityType": "http://www.wikidata.org/ontology#Item",
|
||||
"id": "Q1234",
|
||||
"iri": "http://localhost/entity/Q1234",
|
||||
"label": "new item",
|
||||
"reconInternalId": 1234,
|
||||
"siteIri": "http://localhost/entity/",
|
||||
"types": []
|
||||
},
|
||||
"property": "P52",
|
||||
"snaktype": "value"
|
||||
},
|
||||
"rank": "normal",
|
||||
"type": "statement"
|
||||
}
|
||||
],
|
||||
"deletedStatements": [],
|
||||
"descriptions": [],
|
||||
"labels": [],
|
||||
"new": false,
|
||||
"subject": {
|
||||
"type": "wikibase-entityid",
|
||||
"value": {
|
||||
"entity-type": "item",
|
||||
"id": "Q34",
|
||||
"numeric-id": 34
|
||||
}
|
||||
}
|
||||
}
|
@ -28,6 +28,7 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@ -48,6 +49,8 @@ import org.wikidata.wdtk.datamodel.interfaces.Statement;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.StatementGroup;
|
||||
import org.wikidata.wdtk.datamodel.interfaces.StatementRank;
|
||||
|
||||
import com.google.refine.tests.util.TestUtils;
|
||||
|
||||
public class ItemUpdateTest {
|
||||
|
||||
private ItemIdValue existingSubject = Datamodel.makeWikidataItemIdValue("Q34");
|
||||
@ -110,6 +113,13 @@ public class ItemUpdateTest {
|
||||
assertEquals(Arrays.asList(statement1, statement2), update.getAddedStatements());
|
||||
assertEquals(statementGroups, update.getAddedStatementGroups().stream().collect(Collectors.toSet()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializeStatements() throws IOException {
|
||||
ItemUpdate update = new ItemUpdateBuilder(existingSubject).addStatement(statement1).addStatement(statement2)
|
||||
.build();
|
||||
TestUtils.isSerializedTo(update, TestingData.jsonFromFile("updates/statement_groups.json"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteStatements() {
|
||||
|
Loading…
Reference in New Issue
Block a user