Search in sources :

Example 6 with PluralChangeModel

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());
}
Also used : PluralChangeModel(com.blazebit.persistence.view.change.PluralChangeModel) UpdatableLegacyOrderPositionView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.entityid.model.UpdatableLegacyOrderPositionView) LegacyOrder(com.blazebit.persistence.view.testsuite.entity.LegacyOrder) UpdatableLegacyOrderView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.entityid.model.UpdatableLegacyOrderView) AbstractEntityViewUpdateTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest) Test(org.junit.Test)

Example 7 with PluralChangeModel

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());
        }
    }
}
Also used : UpdatableDocumentEmbeddableWithCollectionsView(com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithCollectionsView) NameObject(com.blazebit.persistence.testsuite.entity.NameObject) PluralChangeModel(com.blazebit.persistence.view.change.PluralChangeModel)

Aggregations

PluralChangeModel (com.blazebit.persistence.view.change.PluralChangeModel)7 Test (org.junit.Test)5 AbstractEntityViewUpdateTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest)4 LegacyOrder (com.blazebit.persistence.view.testsuite.entity.LegacyOrder)3 NameObject (com.blazebit.persistence.testsuite.entity.NameObject)2 UpdatableDocumentEmbeddableWithCollectionsView (com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithCollectionsView)2 Document (com.blazebit.persistence.testsuite.entity.Document)1 AbstractEntityViewUpdateDocumentTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateDocumentTest)1 UpdatableDocumentWithCollectionsView (com.blazebit.persistence.view.testsuite.update.listener.model.UpdatableDocumentWithCollectionsView)1 UpdatablePersonView (com.blazebit.persistence.view.testsuite.update.listener.model.UpdatablePersonView)1 UpdatableLegacyOrderPositionView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.UpdatableLegacyOrderPositionView)1 UpdatableLegacyOrderView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.UpdatableLegacyOrderView)1 UpdatableLegacyOrderPositionView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.entityid.model.UpdatableLegacyOrderPositionView)1 UpdatableLegacyOrderView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.entityid.model.UpdatableLegacyOrderView)1 UpdatableLegacyOrderPositionView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionView)1 UpdatableLegacyOrderView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderView)1 UpdatableDocumentView (com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatableDocumentView)1 UpdatablePersonView (com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatablePersonView)1 UpdatableVersionView (com.blazebit.persistence.view.testsuite.update.subview.inverse.unmapped.model.UpdatableVersionView)1