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());
}
}
}
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);
}
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")));
}
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);
}
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);
}
}
Aggregations