use of com.blazebit.persistence.view.testsuite.entity.LegacyOrder in project blaze-persistence by Blazebit.
the class EntityViewUpdateSubviewInverseEmbeddedEntityIdTest 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.entity.LegacyOrder in project blaze-persistence by Blazebit.
the class EntityViewUpdateSubviewInverseEmbeddedSimpleTest method testReplaceInverseCollectionElementWithNewElement.
@Test
public void testReplaceInverseCollectionElementWithNewElement() {
// 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);
em.clear();
// When
position = evm.create(UpdatableLegacyOrderPositionView.class);
position.getId().setOrderId(newOrder.getId());
position.getId().setPositionId(0);
position.setArticleNumber("456");
newOrder.getPositions().clear();
newOrder.getPositions().add(position);
update(newOrder);
em.clear();
// Then
LegacyOrder legacyOrder = em.find(LegacyOrder.class, newOrder.getId());
Assert.assertEquals(1, legacyOrder.getPositions().size());
Assert.assertEquals("456", legacyOrder.getPositions().iterator().next().getArticleNumber());
}
use of com.blazebit.persistence.view.testsuite.entity.LegacyOrder in project blaze-persistence by Blazebit.
the class EntityViewUpdateSubviewInverseEmbeddedSimpleTest method testFixConstraintViolationErrorOnInverseCollectionElement.
@Test
public void testFixConstraintViolationErrorOnInverseCollectionElement() {
// Given
UpdatableLegacyOrderView newOrder = evm.create(UpdatableLegacyOrderView.class);
UpdatableLegacyOrderPositionView position = evm.create(UpdatableLegacyOrderPositionView.class);
position.getId().setPositionId(0);
newOrder.getPositions().add(position);
try {
update(newOrder);
Assert.fail("Expected the transaction to fail!");
} catch (Exception ex) {
// When
em.clear();
position.setArticleNumber("123");
update(newOrder);
}
// Then
em.clear();
LegacyOrder legacyOrder = em.find(LegacyOrder.class, newOrder.getId());
Assert.assertEquals("123", legacyOrder.getPositions().iterator().next().getArticleNumber());
}
Aggregations