use of com.blazebit.persistence.view.change.PluralChangeModel in project blaze-persistence by Blazebit.
the class EntityViewUpdateSubviewInverseEmbeddedEntityIdTest method testRemoveReadOnlyElementFromCollection.
@Test
public void testRemoveReadOnlyElementFromCollection() {
// Given
UpdatableLegacyOrderView newOrder = evm.create(UpdatableLegacyOrderView.class);
UpdatableLegacyOrderPositionView position = evm.create(UpdatableLegacyOrderPositionView.class);
position.getId().setPositionId(0);
position.setArticleNumber("123");
newOrder.getPositions().add(position);
update(newOrder);
// When
em.clear();
newOrder = evm.applySetting(EntityViewSetting.create(UpdatableLegacyOrderView.class), cbf.create(em, LegacyOrder.class)).getSingleResult();
newOrder.getPositions().remove(newOrder.getPositions().iterator().next());
PluralChangeModel<Object, Object> positionsChangeModel = (PluralChangeModel<Object, Object>) evm.getChangeModel(newOrder).get("positions");
Assert.assertEquals(1, positionsChangeModel.getRemovedElements().size());
update(newOrder);
// Then
em.clear();
LegacyOrder legacyOrder = em.find(LegacyOrder.class, newOrder.getId());
Assert.assertEquals(0, legacyOrder.getPositions().size());
}
use of com.blazebit.persistence.view.change.PluralChangeModel in project blaze-persistence by Blazebit.
the class EntityViewUpdateMutableEmbeddableCollectionsTest method assertMutableChangeModel.
private void assertMutableChangeModel(UpdatableDocumentEmbeddableWithCollectionsView docView) {
if (!isFullMode()) {
SingularChangeModel<UpdatableDocumentEmbeddableWithCollectionsView> changeModel = evm.getChangeModel(docView);
PluralChangeModel<?, ?> namesChange = (PluralChangeModel<?, ?>) changeModel.get("names");
if (registerType) {
assertFalse(changeModel.isDirty());
assertEquals(ChangeModel.ChangeKind.NONE, changeModel.getKind());
assertFalse(namesChange.isDirty());
assertEquals(ChangeModel.ChangeKind.NONE, namesChange.getKind());
assertEquals(0, namesChange.getAddedElements().size());
assertEquals(0, namesChange.getRemovedElements().size());
assertEquals(0, namesChange.getMutatedElements().size());
assertEquals(0, namesChange.getElementChanges().size());
assertEquals(0, changeModel.getDirtyChanges().size());
} else {
assertTrue(changeModel.isDirty());
assertEquals(ChangeModel.ChangeKind.MUTATED, changeModel.getKind());
assertTrue(namesChange.isDirty());
assertEquals(ChangeModel.ChangeKind.MUTATED, namesChange.getKind());
assertEquals(1, namesChange.getAddedElements().size());
assertEquals(1, namesChange.getRemovedElements().size());
assertEquals(0, namesChange.getMutatedElements().size());
assertEquals(ChangeModel.ChangeKind.UPDATED, namesChange.getAddedElements().get(0).getKind());
assertEquals(ChangeModel.ChangeKind.UPDATED, namesChange.getRemovedElements().get(0).getKind());
assertUnorderedEquals(Arrays.asList(namesChange.getAddedElements().get(0), namesChange.getRemovedElements().get(0)), namesChange.getElementChanges());
assertEquals(new NameObject("doc1", "doc1"), namesChange.getAddedElements().get(0).getCurrentState());
assertEquals(new NameObject("doc1", "doc1"), namesChange.getRemovedElements().get(0).getInitialState());
assertEquals(Arrays.asList(namesChange), changeModel.getDirtyChanges());
}
}
}
Aggregations