use of com.blazebit.persistence.view.testsuite.entity.LegacyOrder 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.entity.LegacyOrder in project blaze-persistence by Blazebit.
the class EntityViewUpdateSubviewInverseEmbeddedSimpleTest method testLoadMultipleUpdatableWithUpdatableFlatViewIds.
@Test
public void testLoadMultipleUpdatableWithUpdatableFlatViewIds() {
transactional(new TxVoidWork() {
@Override
public void work(EntityManager em) {
LegacyOrder o = new LegacyOrder();
em.persist(o);
LegacyOrderPosition p = new LegacyOrderPosition(new LegacyOrderPositionId(o.getId(), 0));
p.setArticleNumber("123");
p.setOrder(o);
em.persist(p);
o.getPositions().add(p);
LegacyOrderPositionDefault d1 = new LegacyOrderPositionDefault(new LegacyOrderPositionDefaultId(p.getId(), 1));
d1.setValue("1");
em.persist(d1);
LegacyOrderPositionDefault d2 = new LegacyOrderPositionDefault(new LegacyOrderPositionDefaultId(p.getId(), 2));
d2.setValue("1");
em.persist(d2);
p.getDefaults().add(d1);
p.getDefaults().add(d2);
}
});
em.clear();
List<UpdatableLegacyOrderPositionDefaultView> resultList = evm.applySetting(EntityViewSetting.create(UpdatableLegacyOrderPositionDefaultView.class), cbf.create(em, LegacyOrderPositionDefault.class)).getResultList();
// Making the id view updatable at some point caused just a part of the id to be considered when de-duplicating updatable views
assertEquals(2, resultList.size());
assertNotEquals(resultList.get(0).getId(), resultList.get(1).getId());
}
use of com.blazebit.persistence.view.testsuite.entity.LegacyOrder 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());
}
use of com.blazebit.persistence.view.testsuite.entity.LegacyOrder 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.entity.LegacyOrder 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());
}
Aggregations