Skip to content

Commit

Permalink
added simple diff test to try out new strategy, some javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Apr 17, 2024
1 parent 0db1f86 commit 788bf1f
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.evolveum.midpoint.prism.delta.*;

import org.testng.AssertJUnit;
import org.testng.annotations.Test;

import com.evolveum.midpoint.prism.*;
Expand Down Expand Up @@ -542,4 +543,39 @@ private void assertHashAndEquals(PrismObject<UserType> user1, PrismObject<UserTy
}
assertEquals("Hash codes are not equal (strategy=" + strategy + ")", hash1, hash2);
}

@Test
public void testNaturalKeysDiff() {
GuiObjectDetailsPageType details1 = new GuiObjectDetailsPageType();
VirtualContainersSpecificationType c3 = createContainer(3L, "id1", "description1");
details1.getContainer().add(c3);
details1.getContainer().add(createContainer(4L, "id2", "description2"));

GuiObjectDetailsPageType details2 = new GuiObjectDetailsPageType();
details2.getContainer().add(createContainer(5L, "id1", "description11111111"));

PrismContainer item1 = details1.asPrismContainerValue().findContainer(GuiObjectDetailsPageType.F_CONTAINER);
PrismContainer item2 = details2.asPrismContainerValue().findContainer(GuiObjectDetailsPageType.F_CONTAINER);

ContainerDelta<?> delta = item1.diff(item2);
AssertJUnit.assertNotNull(delta);

// PCV ID and natural key exists
// delta will contain only two item deltas, replace description and delete one container value
List<ItemDelta> deltas = item1.diffModifications(item2, ParameterizedEquivalenceStrategy.REAL_VALUE_CONSIDER_DIFFERENT_IDS_NATURAL_KEYS);
AssertJUnit.assertEquals(2, deltas.size());

// no PCV ID, natural key will not be used
// delta will contain only one container delta with add/delete of whole values
c3.setId(null);
deltas = item1.diffModifications(item2, ParameterizedEquivalenceStrategy.REAL_VALUE_CONSIDER_DIFFERENT_IDS_NATURAL_KEYS);
AssertJUnit.assertEquals(1, deltas.size());
}

private VirtualContainersSpecificationType createContainer(Long id, String identifier, String description) {
return new VirtualContainersSpecificationType()
.id(id)
.identifier(identifier)
.description(description);
}
}

0 comments on commit 788bf1f

Please sign in to comment.