Search in sources :

Example 1 with LegacyOrderPositionId

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

the class EntityViewUpdateSubviewInverseEmbeddedEntityIdTest 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.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 2 with LegacyOrderPositionId

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

the class EntityViewUpdateSubviewInverseEmbeddedSimpleTest 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.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 3 with LegacyOrderPositionId

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

the class EntityViewUpdateSubviewInverseEmbeddedSimpleTest method testPersistAndAddNewElementToNewCollection.

@Test
public void testPersistAndAddNewElementToNewCollection() {
    // When
    UpdatableLegacyOrderView newOrder = evm.create(UpdatableLegacyOrderView.class);
    UpdatableLegacyOrderPositionView position = evm.create(UpdatableLegacyOrderPositionView.class);
    position.getId().setPositionId(0);
    position.setArticleNumber("123");
    newOrder.setPositions(new HashSet<>(Arrays.<LegacyOrderPositionIdView>asList(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 : LegacyOrderPositionIdView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.LegacyOrderPositionIdView) 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 4 with LegacyOrderPositionId

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

the class EntityViewUpdateSubviewInverseEmbeddedSimpleTest method testUpdateReferenceEmbeddable.

@Test
public void testUpdateReferenceEmbeddable() {
    Assume.assumeFalse("Partial reference updates don't work in full mode", isFullMode());
    // Given
    UpdatableLegacyOrderView order1 = evm.create(UpdatableLegacyOrderView.class);
    UpdatableLegacyOrderPositionView position = evm.create(UpdatableLegacyOrderPositionView.class);
    position.getId().setPositionId(0);
    position.setArticleNumber("123");
    position.getEmbeddable().setName("123");
    order1.getPositions().add(position);
    update(order1);
    UpdatableLegacyOrderView order2 = evm.create(UpdatableLegacyOrderView.class);
    UpdatableLegacyOrderPositionView position1 = evm.create(UpdatableLegacyOrderPositionView.class);
    position1.getId().setPositionId(0);
    position1.setArticleNumber("123");
    position1.getEmbeddable().setName("123");
    order2.getPositions().add(position1);
    UpdatableLegacyOrderPositionView position2 = evm.create(UpdatableLegacyOrderPositionView.class);
    position2.getId().setPositionId(1);
    position2.setArticleNumber("456");
    position2.getEmbeddable().setName("456");
    order2.getPositions().add(position2);
    update(order2);
    // When
    UpdatableLegacyOrderView order = evm.getReference(UpdatableLegacyOrderView.class, order2.getId());
    position = evm.getReference(UpdatableLegacyOrderPositionView.class, position2.getId());
    position.setEmbeddable(evm.create(UpdatableLegacyOrderPositionEmbeddableView.class));
    position.getEmbeddable().setName("test");
    order.getPositions().add(position);
    update(order);
    // Then
    LegacyOrder legacyOrder = em.find(LegacyOrder.class, order2.getId());
    Assert.assertEquals(1, legacyOrder.getPositions().size());
    LegacyOrderPosition orderPosition = legacyOrder.getPositions().iterator().next();
    Assert.assertEquals(new LegacyOrderPositionId(order2.getId(), position2.getId().getPositionId()), orderPosition.getId());
    assertEquals("456", orderPosition.getArticleNumber());
    assertEquals("test", orderPosition.getEmbeddable().getName());
}
Also used : LegacyOrderPosition(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPosition) LegacyOrderPositionId(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionId) UpdatableLegacyOrderPositionView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionView) UpdatableLegacyOrderPositionEmbeddableView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionEmbeddableView) 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 5 with LegacyOrderPositionId

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

the class EntityViewUpdateSubviewInverseEmbeddedEntityIdTest method testFixConstraintViolationErrorOnInverseCollectionElement.

@Test
public void testFixConstraintViolationErrorOnInverseCollectionElement() {
    // Given
    UpdatableLegacyOrderView newOrder = evm.create(UpdatableLegacyOrderView.class);
    UpdatableLegacyOrderPositionView position = evm.create(UpdatableLegacyOrderPositionView.class);
    position.setId(new LegacyOrderPositionId());
    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 : 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)

Aggregations

LegacyOrderPositionId (com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionId)13 AbstractEntityViewUpdateTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest)13 Test (org.junit.Test)13 LegacyOrder (com.blazebit.persistence.view.testsuite.entity.LegacyOrder)12 LegacyOrderPosition (com.blazebit.persistence.view.testsuite.entity.LegacyOrderPosition)5 UpdatableLegacyOrderPositionView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionView)5 UpdatableLegacyOrderView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderView)5 CreatableLegacyOrderPositionView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.CreatableLegacyOrderPositionView)4 UpdatableLegacyOrderView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.UpdatableLegacyOrderView)4 UpdatableLegacyOrderPositionView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.entityid.model.UpdatableLegacyOrderPositionView)3 UpdatableLegacyOrderView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.entityid.model.UpdatableLegacyOrderView)3 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 UpdatableLegacyOrderPositionEmbeddableView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionEmbeddableView)1 EntityManager (javax.persistence.EntityManager)1