Search in sources :

Example 1 with UpdatableLegacyOrderPositionDefaultView

use of com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.UpdatableLegacyOrderPositionDefaultView in project blaze-persistence by Blazebit.

the class EntityViewUpdateSubviewInverseEmbeddedComplexTest method testAddNewElementToCollectionAndUpdate.

@Test
public void testAddNewElementToCollectionAndUpdate() {
    // Given
    UpdatableLegacyOrderView newOrder = evm.create(UpdatableLegacyOrderView.class);
    CreatableLegacyOrderPositionView position = evm.create(CreatableLegacyOrderPositionView.class);
    position.setCreationDate(Calendar.getInstance());
    position.getId().setPositionId(0);
    position.setArticleNumber("123");
    newOrder.getPositions().add(position);
    UpdatableLegacyOrderPositionDefaultView positionDefault = evm.create(UpdatableLegacyOrderPositionDefaultView.class);
    positionDefault.getId().setSupplierId(1);
    position.getDefaults().add(positionDefault);
    update(newOrder);
    // Then 1
    Assert.assertNotNull(newOrder.getPositions().iterator().next().getDefaults().iterator().next().getId().getOrderId());
    // When
    newOrder.getPositions().iterator().next().getDefaults().iterator().next().setValue("NEW");
    position = evm.create(CreatableLegacyOrderPositionView.class);
    position.getId().setPositionId(1);
    position.setArticleNumber("123");
    newOrder.getPositions().add(position);
    positionDefault = evm.create(UpdatableLegacyOrderPositionDefaultView.class);
    positionDefault.getId().setSupplierId(2);
    position.getDefaults().add(positionDefault);
    update(newOrder);
    // Then 2
    em.clear();
    LegacyOrder legacyOrder = em.find(LegacyOrder.class, newOrder.getId());
    Assert.assertEquals(2, legacyOrder.getPositions().size());
    Iterator<LegacyOrderPosition> iterator = legacyOrder.getPositions().iterator();
    LegacyOrderPosition actualPosition = iterator.next();
    if (actualPosition.getId().getPositionId().equals(0)) {
        actualPosition = iterator.next();
    }
    Assert.assertEquals(new LegacyOrderPositionId(newOrder.getId(), 1), actualPosition.getId());
}
Also used : CreatableLegacyOrderPositionView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.CreatableLegacyOrderPositionView) LegacyOrderPosition(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPosition) UpdatableLegacyOrderPositionDefaultView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.UpdatableLegacyOrderPositionDefaultView) LegacyOrderPositionId(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionId) 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)1 LegacyOrderPosition (com.blazebit.persistence.view.testsuite.entity.LegacyOrderPosition)1 LegacyOrderPositionId (com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionId)1 AbstractEntityViewUpdateTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest)1 CreatableLegacyOrderPositionView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.CreatableLegacyOrderPositionView)1 UpdatableLegacyOrderPositionDefaultView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.UpdatableLegacyOrderPositionDefaultView)1 UpdatableLegacyOrderView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.UpdatableLegacyOrderView)1 Test (org.junit.Test)1