use of com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderView 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());
}
use of com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderView 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());
}
use of com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderView 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());
}
use of com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderView 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());
}
use of com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderView 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());
}
Aggregations