Add regression test for serialization of statement groups

This commit is contained in:
Antonin Delpeuch 2019-06-14 14:14:38 +01:00
parent 8ae4c8fe94
commit 214efc73b4
2 changed files with 121 additions and 0 deletions

View 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
}
}
}

View File

@ -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");
@ -111,6 +114,13 @@ public class ItemUpdateTest {
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() {
ItemUpdate update = new ItemUpdateBuilder(existingSubject).deleteStatement(statement1)