use of com.blazebit.persistence.view.testsuite.entity.LegacyOrderPosition 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.entity.LegacyOrderPosition 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.LegacyOrderPosition 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.LegacyOrderPosition 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.entity.LegacyOrderPosition in project blaze-persistence by Blazebit.
the class EntityViewUpdateSubviewInverseEmbeddedSimpleTest method testConvertEmbeddedIdEntityViewToEntityReference.
@Test
public void testConvertEmbeddedIdEntityViewToEntityReference() {
// 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
LegacyOrderPosition legacyOrderPosition = evm.getEntityReference(em, position);
// Then
Assert.assertEquals(new LegacyOrderPositionId(newOrder.getId(), 0), legacyOrderPosition.getId());
}
Aggregations