use of com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.UpdatableLegacyOrderView in project blaze-persistence by Blazebit.
the class EntityViewUpdateSubviewInverseEmbeddedComplexTest method testAddElementCreateViewToCollection.
@Test
public void testAddElementCreateViewToCollection() {
// Given
UpdatableLegacyOrderView newOrder = evm.create(UpdatableLegacyOrderView.class);
CreatableLegacyOrderPositionView position = evm.create(CreatableLegacyOrderPositionView.class);
position.getId().setPositionId(0);
position.setArticleNumber("123");
newOrder.getPositions().add(position);
update(newOrder);
// When
CreatableLegacyOrderPositionElementView elementView = evm.create(CreatableLegacyOrderPositionElementView.class);
elementView.setText("test");
newOrder.getPositions().iterator().next().getElems().add(elementView);
update(newOrder);
// Then
em.clear();
LegacyOrder legacyOrder = em.find(LegacyOrder.class, newOrder.getId());
Assert.assertEquals(1, legacyOrder.getPositions().size());
LegacyOrderPosition orderPosition = legacyOrder.getPositions().iterator().next();
Assert.assertEquals(new LegacyOrderPositionId(newOrder.getId(), 0), orderPosition.getId());
Assert.assertEquals(1, orderPosition.getElems().size());
Assert.assertEquals("test", orderPosition.getElems().iterator().next().getText());
}
use of com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.UpdatableLegacyOrderView in project blaze-persistence by Blazebit.
the class EntityViewUpdateSubviewInverseEmbeddedComplexTest 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());
}
use of com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.UpdatableLegacyOrderView in project blaze-persistence by Blazebit.
the class EntityViewUpdateSubviewInverseEmbeddedComplexTest method testUpdateRemoveFromInverseSet.
@Test
public void testUpdateRemoveFromInverseSet() {
// Given
UpdatableLegacyOrderView newOrder = evm.create(UpdatableLegacyOrderView.class);
CreatableLegacyOrderPositionView position1 = evm.create(CreatableLegacyOrderPositionView.class);
position1.getId().setPositionId(0);
position1.setArticleNumber("123");
newOrder.getPositions().add(position1);
CreatableLegacyOrderPositionView position2 = evm.create(CreatableLegacyOrderPositionView.class);
position2.getId().setPositionId(1);
position2.setArticleNumber("456");
newOrder.getPositions().add(position2);
update(newOrder);
// When
newOrder.setPositions(new HashSet<>(newOrder.getPositions()));
newOrder.getPositions().remove(position2);
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.complex.model.UpdatableLegacyOrderView 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());
}
use of com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.UpdatableLegacyOrderView in project blaze-persistence by Blazebit.
the class EntityViewUpdateSubviewInverseEmbeddedComplexTest method testAddNewElementToCollection.
@Test
public void testAddNewElementToCollection() {
// Given
UpdatableLegacyOrderView newOrder = evm.create(UpdatableLegacyOrderView.class);
update(newOrder);
// When
CreatableLegacyOrderPositionView position = evm.create(CreatableLegacyOrderPositionView.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());
}
Aggregations