Search in sources :

Example 21 with Diff

use of org.javers.core.diff.Diff in project molgenis-emx2 by molgenis.

the class CompareTools method reloadAndCompare.

public static void reloadAndCompare(Database database, Schema schema) {
    // remember
    String schemaName = schema.getMetadata().getName();
    Collection<String> tableNames = schema.getTableNames();
    // empty the cache
    database.clearCache();
    // check reload from drive
    Schema schemaLoadedFromDisk = database.getSchema(schemaName);
    for (String tableName : tableNames) {
        TableMetadata t1 = schema.getTable(tableName).getMetadata();
        TableMetadata t2 = schemaLoadedFromDisk.getTable(tableName).getMetadata();
        Diff diff = getJavers().compare(t1, t2);
        if (diff.hasChanges()) {
            fail("Roundtrip test failed: changes, " + diff.toString());
        }
    }
}
Also used : Diff(org.javers.core.diff.Diff)

Example 22 with Diff

use of org.javers.core.diff.Diff in project tutorials by eugenp.

the class JaversUnitTest method givenListOfPersons_whenCompare_ThenShouldDetectChanges.

@Test
public void givenListOfPersons_whenCompare_ThenShouldDetectChanges() {
    // given
    Javers javers = JaversBuilder.javers().build();
    Person personThatWillBeRemoved = new Person(2, "Thomas Link");
    List<Person> oldList = Lists.asList(new Person(1, "Michael Program"), personThatWillBeRemoved);
    List<Person> newList = Lists.asList(new Person(1, "Michael Not Program"));
    // when
    Diff diff = javers.compareCollections(oldList, newList, Person.class);
    // then
    assertThat(diff.getChanges()).hasSize(3);
    ValueChange valueChange = diff.getChangesByType(ValueChange.class).get(0);
    assertThat(valueChange.getPropertyName()).isEqualTo("name");
    assertThat(valueChange.getLeft()).isEqualTo("Michael Program");
    assertThat(valueChange.getRight()).isEqualTo("Michael Not Program");
    ObjectRemoved objectRemoved = diff.getChangesByType(ObjectRemoved.class).get(0);
    assertThat(objectRemoved.getAffectedObject().get().equals(personThatWillBeRemoved)).isTrue();
    ListChange listChange = diff.getChangesByType(ListChange.class).get(0);
    assertThat(listChange.getValueRemovedChanges().size()).isEqualTo(1);
}
Also used : ValueChange(org.javers.core.diff.changetype.ValueChange) Javers(org.javers.core.Javers) Diff(org.javers.core.diff.Diff) ObjectRemoved(org.javers.core.diff.changetype.ObjectRemoved) ListChange(org.javers.core.diff.changetype.container.ListChange) Test(org.junit.Test)

Example 23 with Diff

use of org.javers.core.diff.Diff in project tutorials by eugenp.

the class JaversUnitTest method givenListOfPerson_whenPersonRemovedAddress_thenDetectThatChange.

@Test
public void givenListOfPerson_whenPersonRemovedAddress_thenDetectThatChange() {
    // given
    Javers javers = JaversBuilder.javers().build();
    PersonWithAddress person = new PersonWithAddress(1, "Tom", Arrays.asList(new Address("England")));
    PersonWithAddress personWithNewAddress = new PersonWithAddress(1, "Tom", Collections.emptyList());
    // when
    Diff diff = javers.compare(person, personWithNewAddress);
    List objectsByChangeType = diff.getObjectsByChangeType(ObjectRemoved.class);
    // then
    assertThat(objectsByChangeType).hasSize(1);
    assertThat(objectsByChangeType.get(0).equals(new Address("England")));
}
Also used : Javers(org.javers.core.Javers) Diff(org.javers.core.diff.Diff) List(java.util.List) Test(org.junit.Test)

Example 24 with Diff

use of org.javers.core.diff.Diff in project workbench by all-of-us.

the class ProfileService method validateProfileForCorrectness.

private void validateProfileForCorrectness(@Nullable Profile previousProfile, @Nonnull Profile profile) throws BadRequestException {
    final Diff diff = javers.compare(previousProfile, profile);
    validateProfileForCorrectness(diff, profile);
}
Also used : Diff(org.javers.core.diff.Diff)

Example 25 with Diff

use of org.javers.core.diff.Diff in project workbench by all-of-us.

the class ProfileService method validateProfile.

/**
 * Validates a set of Profile changes by comparing the updated profile to the previous version.
 * Only fields that have changed are subject to validation.
 *
 * <p>If the previous version is null, the updated profile is presumed to be a new profile and all
 * validation rules are run. If both versions are non-null, only changed fields are validated.
 *
 * <p>This method should only be called after calling `cleanProfile` on the updated Profile
 * object.
 *
 * @param updatedProfile
 * @param previousProfile
 * @throws BadRequestException
 */
@VisibleForTesting
public void validateProfile(@Nonnull Profile updatedProfile, @Nullable Profile previousProfile) {
    final Diff diff = javers.compare(previousProfile, updatedProfile);
    validateProfileForCorrectness(diff, updatedProfile);
    if (userService.hasAuthority(userProvider.get().getUserId(), Authority.ACCESS_CONTROL_ADMIN)) {
        validateChangesAllowedByAdmin(diff);
    } else {
        validateChangesAllowedByUser(diff);
    }
}
Also used : Diff(org.javers.core.diff.Diff) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

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