use of com.qcadoo.model.api.EntityOpResult in project qcadoo by qcadoo.
the class CyclesPreventionTest method shouldNotFallIntoInfiniteCycleDuringCascadeManyToManyDeletion2entities.
@Test
public final void shouldNotFallIntoInfiniteCycleDuringCascadeManyToManyDeletion2entities() {
// given
Entity modelA = buildEntity(aDataDefinition);
Entity modelB = buildEntity(bDataDefinition);
modelA.setField(FIELD_MTM_B, Lists.newArrayList(modelB));
modelB.setField(FIELD_MTM_A, Lists.newArrayList(modelA));
modelA = fromDb(save(modelA));
modelB = fromDb(save(modelB));
// when
EntityOpResult result = aDataDefinition.delete(modelA.getId());
// then
Assert.assertTrue(result.isSuccessfull());
Assert.assertNull(fromDb(modelA));
Assert.assertNull(fromDb(modelB));
}
use of com.qcadoo.model.api.EntityOpResult in project qcadoo by qcadoo.
the class HasManyIntegrationTest method shouldOnDeleteHookRejectCascadeNullification.
@Test
public final void shouldOnDeleteHookRejectCascadeNullification() {
// given
Entity component = createComponent("component", null, null);
component.setField("deletionIsAllowed", false);
component = componentDataDefinition.save(component);
Entity part1 = partDataDefinition.save(createComponentPart("part1", component));
Entity part2 = partDataDefinition.save(createComponentPart("part2", component));
Entity part3 = partDataDefinition.save(createComponentPart("part3", null));
component = fromDb(component);
// when
EntityOpResult result = componentDataDefinition.delete(component.getId());
// then
assertFalse(result.isSuccessfull());
Entity componentFromDb = fromDb(component);
assertNotNull(componentFromDb);
checkParts(componentFromDb, part1, part2);
Entity part1fromDb = fromDb(part1);
assertNotNull(part1fromDb);
assertNotNull(part1fromDb.getField("component"));
Entity part2fromDb = fromDb(part2);
assertNotNull(part2fromDb);
assertNotNull(part2fromDb.getField("component"));
Entity part3fromDb = fromDb(part3);
assertNotNull(part3fromDb);
assertNull(part3fromDb.getField("component"));
}
use of com.qcadoo.model.api.EntityOpResult in project qcadoo by qcadoo.
the class HasManyIntegrationTest method shouldPerformCascadeNullification.
@Test
public final void shouldPerformCascadeNullification() {
// given
Entity component = createComponent("component", null, null);
component.setField("deletionIsAllowed", true);
component = componentDataDefinition.save(component);
Entity part1 = partDataDefinition.save(createComponentPart("part1", component));
Entity part2 = partDataDefinition.save(createComponentPart("part2", component));
Entity part3 = partDataDefinition.save(createComponentPart("part3", null));
component = fromDb(component);
// when
EntityOpResult result = componentDataDefinition.delete(component.getId());
// then
assertTrue(result.isSuccessfull());
assertNull(fromDb(component));
Entity part1fromDb = fromDb(part1);
assertNotNull(part1fromDb);
assertNull(part1fromDb.getField("component"));
Entity part2fromDb = fromDb(part2);
assertNotNull(part2fromDb);
assertNull(part2fromDb.getField("component"));
Entity part3fromDb = fromDb(part3);
assertNotNull(part3fromDb);
assertNull(part3fromDb.getField("component"));
}
use of com.qcadoo.model.api.EntityOpResult in project qcadoo by qcadoo.
the class HasManyIntegrationTest method shouldPerformCascadeDeletion.
@Test
public final void shouldPerformCascadeDeletion() {
// given
Entity product = productDataDefinition.save(createProduct("someName", "someNumber"));
Entity part1 = partDataDefinition.save(createPart("part1", product));
Entity part2 = partDataDefinition.save(createPart("part2", product));
Entity part3 = partDataDefinition.save(createPart("part3", null));
product = fromDb(product);
// when
EntityOpResult result = productDataDefinition.delete(product.getId());
// then
assertTrue(result.isSuccessfull());
assertNull(fromDb(product));
assertNull(fromDb(part1));
assertNull(fromDb(part2));
assertNotNull(fromDb(part3));
}
use of com.qcadoo.model.api.EntityOpResult in project qcadoo by qcadoo.
the class ManyToManyIntegrationTest method shouldOnDeleteHookRejectCascadeDeletion.
@Test
public final void shouldOnDeleteHookRejectCascadeDeletion() {
// given
Entity firstProduct = save(createProduct("asd", "00001"));
Entity secondProduct = save(createProduct("fgh", "00002"));
Entity thirdProduct = save(createProduct("jkl", "00003"));
Entity anotherProduct = save(createProduct("qwertyuiop", "00004"));
Entity firstPart = save(createPart("qwe", anotherProduct, Lists.newArrayList(firstProduct, secondProduct)));
Entity secondPart = save(createPart("rty", anotherProduct, Lists.newArrayList(firstProduct, thirdProduct)));
Entity thirdPart = save(createPart("uiop", anotherProduct, Lists.newArrayList(firstProduct, secondProduct, thirdProduct)));
thirdPart.setField("deletionIsProhibited", true);
thirdPart = save(thirdPart);
// when
EntityOpResult result = delete(secondProduct);
// then
Assert.assertFalse(result.isSuccessfull());
Assert.assertNotNull(fromDb(firstPart));
Assert.assertNotNull(fromDb(secondPart));
Assert.assertNotNull(fromDb(thirdPart));
Assert.assertNotNull(fromDb(firstProduct));
Assert.assertNotNull(fromDb(secondProduct));
Assert.assertNotNull(fromDb(thirdProduct));
}
Aggregations