use of com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionId in project blaze-persistence by Blazebit.
the class EntityViewUpdateSubviewInverseEmbeddedEntityIdTest 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.LegacyOrderPositionId in project blaze-persistence by Blazebit.
the class EntityViewUpdateSubviewInverseEmbeddedSimpleTest 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.LegacyOrderPositionId in project blaze-persistence by Blazebit.
the class EntityViewUpdateSubviewInverseEmbeddedSimpleTest method testPersistAndAddNewElementToNewCollection.
@Test
public void testPersistAndAddNewElementToNewCollection() {
// When
UpdatableLegacyOrderView newOrder = evm.create(UpdatableLegacyOrderView.class);
UpdatableLegacyOrderPositionView position = evm.create(UpdatableLegacyOrderPositionView.class);
position.getId().setPositionId(0);
position.setArticleNumber("123");
newOrder.setPositions(new HashSet<>(Arrays.<LegacyOrderPositionIdView>asList(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.LegacyOrderPositionId 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.LegacyOrderPositionId in project blaze-persistence by Blazebit.
the class EntityViewUpdateSubviewInverseEmbeddedEntityIdTest method testFixConstraintViolationErrorOnInverseCollectionElement.
@Test
public void testFixConstraintViolationErrorOnInverseCollectionElement() {
// Given
UpdatableLegacyOrderView newOrder = evm.create(UpdatableLegacyOrderView.class);
UpdatableLegacyOrderPositionView position = evm.create(UpdatableLegacyOrderPositionView.class);
position.setId(new LegacyOrderPositionId());
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