Search in sources :

Example 26 with Diff

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());
        }
    }
}
Also used : Diff(org.javers.core.diff.Diff)

Example 27 with Diff

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;
}
Also used : Javers(org.javers.core.Javers) Diff(org.javers.core.diff.Diff)

Example 28 with Diff

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);
    });
}
Also used : Diff(org.javers.core.diff.Diff)

Example 29 with Diff

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")));
}
Also used : Javers(org.javers.core.Javers) Diff(org.javers.core.diff.Diff) List(java.util.List) Test(org.junit.Test)

Example 30 with Diff

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");
}
Also used : ValueChange(org.javers.core.diff.changetype.ValueChange) Javers(org.javers.core.Javers) Diff(org.javers.core.diff.Diff) Test(org.junit.Test)

Aggregations

Diff (org.javers.core.diff.Diff)57 Observation (org.hl7.fhir.r4.model.Observation)23 Javers (org.javers.core.Javers)10 Test (org.junit.Test)5 Bundle (org.hl7.fhir.r4.model.Bundle)4 DualProtocolSaajSoapMessageFactory (ca.bc.gov.open.pcss.civil.comparison.config.DualProtocolSaajSoapMessageFactory)2 List (java.util.List)2 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)2 VirologischerBefundCompositionConverter (org.ehrbase.fhirbridge.ehr.converter.specific.virologischerbefund.VirologischerBefundCompositionConverter)2 GECCOPersonendatenComposition (org.ehrbase.fhirbridge.ehr.opt.geccopersonendatencomposition.GECCOPersonendatenComposition)2 VirologischerBefundComposition (org.ehrbase.fhirbridge.ehr.opt.virologischerbefundcomposition.VirologischerBefundComposition)2 BefundObservation (org.ehrbase.fhirbridge.ehr.opt.virologischerbefundcomposition.definition.BefundObservation)2 VirologischerBefundConverter (org.ehrbase.fhirbridge.fhir.bundle.converter.VirologischerBefundConverter)2 Condition (org.hl7.fhir.r4.model.Condition)2 DiagnosticReport (org.hl7.fhir.r4.model.DiagnosticReport)2 ValueChange (org.javers.core.diff.changetype.ValueChange)2 WebServiceSenderWithAuth (ca.bc.gov.open.pcss.civil.comparison.config.WebServiceSenderWithAuth)1 ca.bc.gov.open.pcss.three (ca.bc.gov.open.pcss.three)1 YesNoType (ca.bc.gov.open.pcss.two.YesNoType)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1