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