StatementUpdate { @JsonIgnore public boolean isEmptyEdit() { return getUpdatedStatements().isEmpty(); } StatementUpdate(StatementDocument currentDocument,
			List<Statement> addStatements, List<Statement> deleteStatements); @JsonIgnore String getJsonUpdateString(); StatementDocument performEdit(WbEditingAction action, boolean editAsBot, String summary, List<String> tags); @JsonProperty("claims") @JsonInclude(Include.NON_EMPTY) List<Statement> getUpdatedStatements(); @JsonIgnore boolean isEmptyEdit(); void setGuidGenerator(GuidGenerator generator);  }
@Test public void testDeleteAndAdd() { Reference r1 = ReferenceBuilder.newInstance().withPropertyValue(P1, Q1) .build(); Reference r2 = ReferenceBuilder.newInstance().withPropertyValue(P2, Q2) .build(); Statement s3 = StatementBuilder.forSubjectAndProperty(Q1, P2) .withReference(r1).withValue(Q1).withId("ID-s3").build(); Statement s4 = StatementBuilder.forSubjectAndProperty(Q1, P2) .withReference(r2).withValue(Q1).withId("ID-s4").build(); ItemDocument currentDocument = ItemDocumentBuilder.forItemId(Q1) .withStatement(s4).build(); List<Statement> addStatements = Collections.singletonList(s3); List<Statement> deleteStatements = Collections.singletonList(s4); StatementUpdate su = new StatementUpdate(currentDocument, addStatements, deleteStatements); assertTrue(su.toDelete.contains("ID-s4")); assertTrue(su.toKeep.containsKey(P2)); assertEquals(1, su.toKeep.get(P2).size()); assertEquals(s3, su.toKeep.get(P2).get(0).statement); assertFalse(su.isEmptyEdit()); }
@Test public void testMergeExisting() { Statement s1 = StatementBuilder.forSubjectAndProperty(Q1, P1) .withValue(Q1).withId("ID-s1").build(); Statement s2 = StatementBuilder.forSubjectAndProperty(Q1, P1) .withValue(Q1).withId("ID-s2").build(); Statement s3 = StatementBuilder.forSubjectAndProperty(Q1, P1) .withValue(Q2).build(); ItemDocument currentDocument = ItemDocumentBuilder.forItemId(Q1) .withStatement(s1).withStatement(s2).build(); StatementUpdate su = new StatementUpdate(currentDocument, Collections.singletonList(s3), Collections.emptyList()); assertEquals(su.toDelete, Collections.singletonList("ID-s1")); assertEquals(1, su.toKeep.size()); assertTrue(su.toKeep.containsKey(P1)); assertEquals(2, su.toKeep.get(P1).size()); assertEquals(s3, su.toKeep.get(P1).get(0).statement); assertTrue(su.toKeep.get(P1).get(0).write); assertEquals(s2, su.toKeep.get(P1).get(1).statement); assertFalse(su.toKeep.get(P1).get(1).write); assertFalse(su.isEmptyEdit()); }
@Test public void testNullEdit() { Statement s1 = StatementBuilder.forSubjectAndProperty(Q1, P1) .withValue(Q1).withId("ID-s1").build(); Statement s1dup = StatementBuilder.forSubjectAndProperty(Q1, P1) .withValue(Q1).build(); Statement s2 = StatementBuilder.forSubjectAndProperty(Q1, P1) .withValue(Q1).withId("ID-s2").build(); ItemDocument currentDocument = ItemDocumentBuilder.forItemId(Q1) .withStatement(s1).build(); StatementUpdate su = new StatementUpdate(currentDocument, Collections.singletonList(s1dup), Collections.singletonList(s2)); assertTrue(su.isEmptyEdit()); }
@Test public void testMergeNew() { Statement s1 = StatementBuilder.forSubjectAndProperty(Q1, P3) .withValue(Q1).build(); Statement s2 = StatementBuilder.forSubjectAndProperty(Q1, P3) .withValue(Q1).build(); ItemDocument currentDocument = ItemDocumentBuilder.forItemId(Q1) .build(); StatementUpdate su = new StatementUpdate(currentDocument, Arrays.asList(s1, s2), Collections.emptyList()); assertEquals(0, su.toDelete.size()); assertEquals(1, su.toKeep.size()); assertTrue(su.toKeep.containsKey(P3)); assertEquals(1, su.toKeep.get(P3).size()); assertEquals(s1, su.toKeep.get(P3).get(0).statement); assertTrue(su.toKeep.get(P3).get(0).write); assertFalse(su.isEmptyEdit()); }