Search in sources :

Example 6 with Javers

use of org.javers.core.Javers 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)

Example 7 with Javers

use of org.javers.core.Javers in project backend by CatalogueOfLife.

the class TaxonResourceTest method create.

@Test
public void create() throws Exception {
    RULE.startNamesIndex();
    Taxon t = createTaxon();
    t.setId(adminCreds(base).post(json(t), String.class));
    Taxon t2 = userCreds(base.path(t.getId())).get(Taxon.class);
    assertNotNull(t2);
    // manually created taxa will always be of origin USER
    assertEquals(t.getId(), t2.getId());
    TestEntityGenerator.nullifyUserDate(t2);
    prepareEquals(t);
    prepareEquals(t2);
    t2.getName().setId(null);
    Javers javers = JaversBuilder.javers().build();
    Diff diff = javers.compare(t, t2);
    System.out.println(diff);
    assertEquals(t, t2);
}
Also used : Javers(org.javers.core.Javers) Diff(org.javers.core.diff.Diff) Taxon(life.catalogue.api.model.Taxon) Test(org.junit.Test)

Example 8 with Javers

use of org.javers.core.Javers in project backend by CatalogueOfLife.

the class DuplicateMapperTest method printDiff.

void printDiff(Object o1, Object o2) {
    Javers javers = JaversBuilder.javers().build();
    Diff diff = javers.compare(o1, o2);
    System.out.println(diff);
}
Also used : Javers(org.javers.core.Javers) Diff(org.javers.core.diff.Diff)

Example 9 with Javers

use of org.javers.core.Javers in project backend by CatalogueOfLife.

the class MapperTestBase method printDiff.

protected void printDiff(Object o1, Object o2) {
    Javers javers = JaversBuilder.javers().build();
    Diff diff = javers.compare(o1, o2);
    System.out.println(diff);
}
Also used : Javers(org.javers.core.Javers) Diff(org.javers.core.diff.Diff)

Aggregations

Javers (org.javers.core.Javers)9 Diff (org.javers.core.diff.Diff)9 Test (org.junit.Test)5 List (java.util.List)2 ValueChange (org.javers.core.diff.changetype.ValueChange)2 Taxon (life.catalogue.api.model.Taxon)1 ObjectRemoved (org.javers.core.diff.changetype.ObjectRemoved)1 ListChange (org.javers.core.diff.changetype.container.ListChange)1