use of org.javers.core.diff.Diff in project molgenis-emx2 by molgenis.
the class CompareTools method assertEquals.
public static void assertEquals(SchemaMetadata schema1, SchemaMetadata schema2) {
Collection<String> tableNames1 = schema1.getTableNames();
Collection<String> tableNames2 = schema2.getTableNames();
for (Object tableName : tableNames1) if (!tableNames2.contains(tableName))
fail("Schema's have different tables: schema2 doesn't contain '" + tableName + "'");
for (Object tableName : tableNames2) if (!tableNames1.contains(tableName))
fail("Schema's have different tables: schema1 doesn't contain '" + tableName + "'");
for (String tableName : tableNames1) {
Diff diff = getJavers().compare(schema1.getTableMetadata(tableName), schema2.getTableMetadata(tableName));
if (diff.hasChanges()) {
fail("Roundtrip test failed: changes for table " + tableName + ": " + diff.toString());
}
}
}
use of org.javers.core.diff.Diff in project concord by walmartlabs.
the class DiffUtils method compare.
public static Map<String, Object> compare(Object left, Object right) {
Javers javers = JaversBuilder.javers().build();
Diff diff = javers.compare(left, right);
CustomChangeProcessor changeProcessor = new CustomChangeProcessor();
javers.processChangeList(diff.getChanges(), changeProcessor);
Map<String, Object> m = changeProcessor.result();
removeIfEmpty(m, KEY_PREVIOUS);
removeIfEmpty(m, KEY_NEW);
return m;
}
use of org.javers.core.diff.Diff in project hermes by allegro.
the class EventAuditor method objectUpdated.
@Override
public void objectUpdated(String username, Object oldObject, Object newObject) {
ignoringExceptions(() -> {
Diff diff = javers.compare(oldObject, newObject);
AuditEvent event = new AuditEvent(AuditEventType.UPDATED, diff.toString(), oldObject.getClass().getSimpleName(), oldObject.toString(), username);
restTemplate.postForObject(eventDestination, event, Void.class);
});
}
use of org.javers.core.diff.Diff in project tutorials by eugenp.
the class JaversUnitTest method givenListOfPerson_whenPersonHasNewAddress_thenDetectThatChange.
@Test
public void givenListOfPerson_whenPersonHasNewAddress_thenDetectThatChange() {
// given
Javers javers = JaversBuilder.javers().build();
PersonWithAddress person = new PersonWithAddress(1, "Tom", Arrays.asList(new Address("England")));
PersonWithAddress personWithNewAddress = new PersonWithAddress(1, "Tom", Arrays.asList(new Address("England"), new Address("USA")));
// when
Diff diff = javers.compare(person, personWithNewAddress);
List objectsByChangeType = diff.getObjectsByChangeType(NewObject.class);
// then
assertThat(objectsByChangeType).hasSize(1);
assertThat(objectsByChangeType.get(0).equals(new Address("USA")));
}
use of org.javers.core.diff.Diff in project tutorials by eugenp.
the class JaversUnitTest method givenPersonObject_whenApplyModificationOnIt_thenShouldDetectChange.
@Test
public void givenPersonObject_whenApplyModificationOnIt_thenShouldDetectChange() {
// given
Javers javers = JaversBuilder.javers().build();
Person person = new Person(1, "Michael Program");
Person personAfterModification = new Person(1, "Michael Java");
// when
Diff diff = javers.compare(person, personAfterModification);
// then
ValueChange change = diff.getChangesByType(ValueChange.class).get(0);
assertThat(diff.getChanges()).hasSize(1);
assertThat(change.getPropertyName()).isEqualTo("name");
assertThat(change.getLeft()).isEqualTo("Michael Program");
assertThat(change.getRight()).isEqualTo("Michael Java");
}
Aggregations