Search in sources :

Example 16 with LegacyOrder

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

the class EntityViewUpdateSubviewInverseEmbeddedEntityIdTest method testAddNewElementToCollection.

@Test
public void testAddNewElementToCollection() {
    // Given
    UpdatableLegacyOrderView newOrder = evm.create(UpdatableLegacyOrderView.class);
    update(newOrder);
    // When
    UpdatableLegacyOrderPositionView position = evm.create(UpdatableLegacyOrderPositionView.class);
    position.getId().setPositionId(0);
    position.setArticleNumber("123");
    newOrder.getPositions().add(position);
    update(newOrder);
    // Then
    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.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 17 with LegacyOrder

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

the class EntityViewUpdateSubviewInverseEmbeddedSimpleTest method testReplaceInverseCollectionElementWithNewElement.

@Test
public void testReplaceInverseCollectionElementWithNewElement() {
    // 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);
    em.clear();
    // When
    position = evm.create(UpdatableLegacyOrderPositionView.class);
    position.getId().setOrderId(newOrder.getId());
    position.getId().setPositionId(0);
    position.setArticleNumber("456");
    newOrder.getPositions().clear();
    newOrder.getPositions().add(position);
    update(newOrder);
    em.clear();
    // Then
    LegacyOrder legacyOrder = em.find(LegacyOrder.class, newOrder.getId());
    Assert.assertEquals(1, legacyOrder.getPositions().size());
    Assert.assertEquals("456", legacyOrder.getPositions().iterator().next().getArticleNumber());
}
Also used : 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 18 with LegacyOrder

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

the class EntityViewUpdateSubviewInverseEmbeddedSimpleTest method testFixConstraintViolationErrorOnInverseCollectionElement.

@Test
public void testFixConstraintViolationErrorOnInverseCollectionElement() {
    // Given
    UpdatableLegacyOrderView newOrder = evm.create(UpdatableLegacyOrderView.class);
    UpdatableLegacyOrderPositionView position = evm.create(UpdatableLegacyOrderPositionView.class);
    position.getId().setPositionId(0);
    newOrder.getPositions().add(position);
    try {
        update(newOrder);
        Assert.fail("Expected the transaction to fail!");
    } catch (Exception ex) {
        // When
        em.clear();
        position.setArticleNumber("123");
        update(newOrder);
    }
    // Then
    em.clear();
    LegacyOrder legacyOrder = em.find(LegacyOrder.class, newOrder.getId());
    Assert.assertEquals("123", legacyOrder.getPositions().iterator().next().getArticleNumber());
}
Also used : 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)

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