Search in sources :

Example 6 with LegacyOrder

use of com.blazebit.persistence.view.testsuite.entity.LegacyOrder in project blaze-persistence by Blazebit.

the class EntityViewUpdateSubviewInverseEmbeddedSimpleTest method testPersistAndAddNewElementToCollection.

@Test
public void testPersistAndAddNewElementToCollection() {
    // When
    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);
    // Then
    // After update, the position is replaced with the declaration type
    assertFalse(newOrder.getPositions().iterator().next() instanceof UpdatableLegacyOrderPositionView);
    em.clear();
    LegacyOrder legacyOrder = em.find(LegacyOrder.class, newOrder.getId());
    Assert.assertEquals(1, legacyOrder.getPositions().size());
    Assert.assertEquals(new LegacyOrderPositionId(newOrder.getId(), 0), legacyOrder.getPositions().iterator().next().getId());
}
Also used : LegacyOrderPositionId(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionId) UpdatableLegacyOrderPositionView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionView) LegacyOrder(com.blazebit.persistence.view.testsuite.entity.LegacyOrder) UpdatableLegacyOrderView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderView) AbstractEntityViewUpdateTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest) Test(org.junit.Test)

Example 7 with LegacyOrder

use of com.blazebit.persistence.view.testsuite.entity.LegacyOrder in project blaze-persistence by Blazebit.

the class EntityViewUpdateSubviewInverseEmbeddedSimpleTest method testLoadMultipleUpdatableWithUpdatableFlatViewIds.

@Test
public void testLoadMultipleUpdatableWithUpdatableFlatViewIds() {
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            LegacyOrder o = new LegacyOrder();
            em.persist(o);
            LegacyOrderPosition p = new LegacyOrderPosition(new LegacyOrderPositionId(o.getId(), 0));
            p.setArticleNumber("123");
            p.setOrder(o);
            em.persist(p);
            o.getPositions().add(p);
            LegacyOrderPositionDefault d1 = new LegacyOrderPositionDefault(new LegacyOrderPositionDefaultId(p.getId(), 1));
            d1.setValue("1");
            em.persist(d1);
            LegacyOrderPositionDefault d2 = new LegacyOrderPositionDefault(new LegacyOrderPositionDefaultId(p.getId(), 2));
            d2.setValue("1");
            em.persist(d2);
            p.getDefaults().add(d1);
            p.getDefaults().add(d2);
        }
    });
    em.clear();
    List<UpdatableLegacyOrderPositionDefaultView> resultList = evm.applySetting(EntityViewSetting.create(UpdatableLegacyOrderPositionDefaultView.class), cbf.create(em, LegacyOrderPositionDefault.class)).getResultList();
    // Making the id view updatable at some point caused just a part of the id to be considered when de-duplicating updatable views
    assertEquals(2, resultList.size());
    assertNotEquals(resultList.get(0).getId(), resultList.get(1).getId());
}
Also used : LegacyOrderPosition(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPosition) EntityManager(javax.persistence.EntityManager) UpdatableLegacyOrderPositionDefaultView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionDefaultView) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) LegacyOrderPositionDefault(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionDefault) LegacyOrderPositionId(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionId) LegacyOrderPositionDefaultId(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionDefaultId) LegacyOrder(com.blazebit.persistence.view.testsuite.entity.LegacyOrder) AbstractEntityViewUpdateTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest) Test(org.junit.Test)

Example 8 with LegacyOrder

use of com.blazebit.persistence.view.testsuite.entity.LegacyOrder in project blaze-persistence by Blazebit.

the class EntityViewUpdateSubviewInverseEmbeddedSimpleTest 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.simple.model.UpdatableLegacyOrderPositionView) LegacyOrder(com.blazebit.persistence.view.testsuite.entity.LegacyOrder) UpdatableLegacyOrderView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderView) AbstractEntityViewUpdateTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest) Test(org.junit.Test)

Example 9 with LegacyOrder

use of com.blazebit.persistence.view.testsuite.entity.LegacyOrder in project blaze-persistence by Blazebit.

the class EntityViewUpdateSubviewInverseEmbeddedComplexTest method testAddElementCreateViewToCollection.

@Test
public void testAddElementCreateViewToCollection() {
    // Given
    UpdatableLegacyOrderView newOrder = evm.create(UpdatableLegacyOrderView.class);
    CreatableLegacyOrderPositionView position = evm.create(CreatableLegacyOrderPositionView.class);
    position.getId().setPositionId(0);
    position.setArticleNumber("123");
    newOrder.getPositions().add(position);
    update(newOrder);
    // When
    CreatableLegacyOrderPositionElementView elementView = evm.create(CreatableLegacyOrderPositionElementView.class);
    elementView.setText("test");
    newOrder.getPositions().iterator().next().getElems().add(elementView);
    update(newOrder);
    // Then
    em.clear();
    LegacyOrder legacyOrder = em.find(LegacyOrder.class, newOrder.getId());
    Assert.assertEquals(1, legacyOrder.getPositions().size());
    LegacyOrderPosition orderPosition = legacyOrder.getPositions().iterator().next();
    Assert.assertEquals(new LegacyOrderPositionId(newOrder.getId(), 0), orderPosition.getId());
    Assert.assertEquals(1, orderPosition.getElems().size());
    Assert.assertEquals("test", orderPosition.getElems().iterator().next().getText());
}
Also used : CreatableLegacyOrderPositionView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.CreatableLegacyOrderPositionView) LegacyOrderPosition(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPosition) LegacyOrderPositionId(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionId) CreatableLegacyOrderPositionElementView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.CreatableLegacyOrderPositionElementView) LegacyOrder(com.blazebit.persistence.view.testsuite.entity.LegacyOrder) UpdatableLegacyOrderView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.UpdatableLegacyOrderView) AbstractEntityViewUpdateTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest) Test(org.junit.Test)

Example 10 with LegacyOrder

use of com.blazebit.persistence.view.testsuite.entity.LegacyOrder in project blaze-persistence by Blazebit.

the class EntityViewUpdateSubviewInverseEmbeddedComplexTest 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.complex.model.UpdatableLegacyOrderPositionView) LegacyOrder(com.blazebit.persistence.view.testsuite.entity.LegacyOrder) UpdatableLegacyOrderView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.UpdatableLegacyOrderView) AbstractEntityViewUpdateTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest) Test(org.junit.Test)

Aggregations

LegacyOrder (com.blazebit.persistence.view.testsuite.entity.LegacyOrder)18 AbstractEntityViewUpdateTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest)18 Test (org.junit.Test)18 LegacyOrderPositionId (com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionId)12 UpdatableLegacyOrderPositionView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionView)7 UpdatableLegacyOrderView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderView)7 UpdatableLegacyOrderView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.UpdatableLegacyOrderView)6 LegacyOrderPosition (com.blazebit.persistence.view.testsuite.entity.LegacyOrderPosition)4 CreatableLegacyOrderPositionView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.CreatableLegacyOrderPositionView)4 UpdatableLegacyOrderPositionView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.entityid.model.UpdatableLegacyOrderPositionView)4 UpdatableLegacyOrderView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.entityid.model.UpdatableLegacyOrderView)4 PluralChangeModel (com.blazebit.persistence.view.change.PluralChangeModel)3 UpdatableLegacyOrderPositionView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.UpdatableLegacyOrderPositionView)2 TxVoidWork (com.blazebit.persistence.testsuite.tx.TxVoidWork)1 LegacyOrderPositionDefault (com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionDefault)1 LegacyOrderPositionDefaultId (com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionDefaultId)1 CreatableLegacyOrderPositionElementView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.CreatableLegacyOrderPositionElementView)1 UpdatableLegacyOrderPositionDefaultView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.UpdatableLegacyOrderPositionDefaultView)1 LegacyOrderPositionIdView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.LegacyOrderPositionIdView)1 UpdatableLegacyOrderPositionDefaultView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionDefaultView)1