use of de.tblsoft.solr.pipeline.bean.DocumentDiff in project solr-cmd-utils by tblsoft.
the class DocumentDifferTest method testCreateField.
@Test
public void testCreateField() {
Document document1 = DocumentBuilder.document().field("foo", "bar").create();
Document document2 = DocumentBuilder.document().field("foo", "bar").field("change", "new").create();
DocumentDiff diff = DocumentDiffer.compare(document1, document2);
Assert.assertEquals(1, diff.getFieldDiffs().size());
Assert.assertEquals(FieldDiff.DiffType.CREATE, diff.getFieldDiffs().get(0).getDiffType());
}
use of de.tblsoft.solr.pipeline.bean.DocumentDiff in project solr-cmd-utils by tblsoft.
the class DocumentDifferTest method testDeleteField.
@Test
public void testDeleteField() {
Document document1 = DocumentBuilder.document().field("foo", "bar").field("change", "old").create();
Document document2 = DocumentBuilder.document().field("foo", "bar").create();
DocumentDiff diff = DocumentDiffer.compare(document1, document2);
Assert.assertEquals(1, diff.getFieldDiffs().size());
Assert.assertEquals(FieldDiff.DiffType.DELETE, diff.getFieldDiffs().get(0).getDiffType());
}
use of de.tblsoft.solr.pipeline.bean.DocumentDiff in project solr-cmd-utils by tblsoft.
the class DocumentDiffer method compare.
public static DocumentDiff compare(Document d1, Document d2) {
DocumentDiff diff = new DocumentDiff();
for (Field field : d1.getFields()) {
List<String> values1 = field.getValues();
List<String> values2 = d2.getFieldValues(field.getName());
d2.deleteField(field.getName());
FieldDiff.DiffType changeType = getChangeType(values1, values2);
FieldDiff fieldDiff = new FieldDiff();
fieldDiff.setDiffType(changeType);
if (!changeType.equals(FieldDiff.DiffType.EQUAL)) {
fieldDiff.setOldValues(values1);
fieldDiff.setNewValue(values2);
diff.getFieldDiffs().add(fieldDiff);
}
}
for (Field field : d2.getFields()) {
FieldDiff fieldDiff = new FieldDiff();
fieldDiff.setDiffType(FieldDiff.DiffType.CREATE);
fieldDiff.setNewValue(field.getValues());
diff.getFieldDiffs().add(fieldDiff);
}
return diff;
}
use of de.tblsoft.solr.pipeline.bean.DocumentDiff in project solr-cmd-utils by tblsoft.
the class DocumentDifferTest method testDiffDocuments.
@Test
public void testDiffDocuments() {
Document document1 = DocumentBuilder.document().field("foo", "bar").field("change", "old").create();
Document document2 = DocumentBuilder.document().field("foo", "bar").field("change", "new").create();
DocumentDiff diff = DocumentDiffer.compare(document1, document2);
Assert.assertEquals(1, diff.getFieldDiffs().size());
Assert.assertEquals(FieldDiff.DiffType.DIFF, diff.getFieldDiffs().get(0).getDiffType());
}
use of de.tblsoft.solr.pipeline.bean.DocumentDiff in project solr-cmd-utils by tblsoft.
the class DocumentDifferTest method testEqualDocuments.
@Test
public void testEqualDocuments() {
Document document1 = DocumentBuilder.document().field("foo", "bar").create();
Document document2 = DocumentBuilder.document().field("foo", "bar").create();
DocumentDiff diff = DocumentDiffer.compare(document1, document2);
Assert.assertEquals(0, diff.getFieldDiffs().size());
}
Aggregations