Search in sources :

Example 1 with UpdatableLegacyOrderPositionView

use of com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionView 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 2 with UpdatableLegacyOrderPositionView

use of com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionView 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 3 with UpdatableLegacyOrderPositionView

use of com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionView 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 4 with UpdatableLegacyOrderPositionView

use of com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionView 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 5 with UpdatableLegacyOrderPositionView

use of com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionView 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)

Aggregations

AbstractEntityViewUpdateTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest)8 UpdatableLegacyOrderPositionView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionView)8 UpdatableLegacyOrderView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderView)8 Test (org.junit.Test)8 LegacyOrder (com.blazebit.persistence.view.testsuite.entity.LegacyOrder)7 LegacyOrderPositionId (com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionId)5 LegacyOrderPosition (com.blazebit.persistence.view.testsuite.entity.LegacyOrderPosition)2 PluralChangeModel (com.blazebit.persistence.view.change.PluralChangeModel)1 LegacyOrderPositionIdView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.LegacyOrderPositionIdView)1 UpdatableLegacyOrderPositionEmbeddableView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionEmbeddableView)1