Search in sources :

Example 6 with StatementUpdate

use of org.wikidata.wdtk.datamodel.interfaces.StatementUpdate in project OpenRefine by OpenRefine.

the class StatementGroupEditTest method testAddOrMergeStatementsMatching.

@Test
public void testAddOrMergeStatementsMatching() {
    when(merger.match(statement1, statement)).thenReturn(true);
    when(merger.match(statement2, statement)).thenReturn(false);
    when(merger.merge(statement1, statement)).thenReturn(statement1);
    StatementEdit statementEdit = new StatementEdit(statement, merger, StatementEditingMode.ADD_OR_MERGE);
    StatementGroupEdit SUT = new StatementGroupEdit(Collections.singletonList(statementEdit));
    SUT.contributeToStatementUpdate(builder, statementGroup);
    StatementUpdate statementUpdate = builder.build();
    assertEquals(statementUpdate.getAdded(), Collections.emptyList());
    assertEquals(statementUpdate.getReplaced(), Collections.singletonMap(statementId1, statement1));
    assertEquals(statementUpdate.getRemoved(), Collections.emptySet());
}
Also used : StatementUpdate(org.wikidata.wdtk.datamodel.interfaces.StatementUpdate) Test(org.testng.annotations.Test)

Example 7 with StatementUpdate

use of org.wikidata.wdtk.datamodel.interfaces.StatementUpdate in project OpenRefine by OpenRefine.

the class StatementGroupEditTest method testAddStatementsNoMatching.

@Test
public void testAddStatementsNoMatching() {
    when(merger.match(statement1, statement)).thenReturn(false);
    when(merger.match(statement2, statement)).thenReturn(false);
    StatementEdit statementEdit = new StatementEdit(statement, merger, StatementEditingMode.ADD);
    StatementGroupEdit SUT = new StatementGroupEdit(Collections.singletonList(statementEdit));
    SUT.contributeToStatementUpdate(builder, statementGroup);
    StatementUpdate statementUpdate = builder.build();
    assertEquals(statementUpdate.getAdded(), Collections.singletonList(statement));
    assertEquals(statementUpdate.getReplaced(), Collections.emptyMap());
    assertEquals(statementUpdate.getRemoved(), Collections.emptySet());
}
Also used : StatementUpdate(org.wikidata.wdtk.datamodel.interfaces.StatementUpdate) Test(org.testng.annotations.Test)

Example 8 with StatementUpdate

use of org.wikidata.wdtk.datamodel.interfaces.StatementUpdate in project OpenRefine by OpenRefine.

the class StatementGroupEditTest method testDeleteStatements.

@Test
public void testDeleteStatements() {
    when(merger.match(statement1, statement)).thenReturn(false);
    when(merger.match(statement2, statement)).thenReturn(true);
    StatementEdit statementEdit = new StatementEdit(statement, merger, StatementEditingMode.DELETE);
    StatementGroupEdit SUT = new StatementGroupEdit(Collections.singletonList(statementEdit));
    SUT.contributeToStatementUpdate(builder, statementGroup);
    StatementUpdate statementUpdate = builder.build();
    assertEquals(statementUpdate.getAdded(), Collections.emptyList());
    assertEquals(statementUpdate.getReplaced(), Collections.emptyMap());
    assertEquals(statementUpdate.getRemoved(), Collections.singleton(statementId2));
}
Also used : StatementUpdate(org.wikidata.wdtk.datamodel.interfaces.StatementUpdate) Test(org.testng.annotations.Test)

Aggregations

StatementUpdate (org.wikidata.wdtk.datamodel.interfaces.StatementUpdate)8 Test (org.testng.annotations.Test)7 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Datamodel (org.wikidata.wdtk.datamodel.helpers.Datamodel)2 EntityDocument (org.wikidata.wdtk.datamodel.interfaces.EntityDocument)2 ItemDocument (org.wikidata.wdtk.datamodel.interfaces.ItemDocument)2 ItemIdValue (org.wikidata.wdtk.datamodel.interfaces.ItemIdValue)2 MediaInfoDocument (org.wikidata.wdtk.datamodel.interfaces.MediaInfoDocument)2 MediaInfoIdValue (org.wikidata.wdtk.datamodel.interfaces.MediaInfoIdValue)2 MonolingualTextValue (org.wikidata.wdtk.datamodel.interfaces.MonolingualTextValue)2 TermUpdate (org.wikidata.wdtk.datamodel.interfaces.TermUpdate)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1