use of com.qcadoo.model.api.EntityOpResult in project qcadoo by qcadoo.
the class CyclesPreventionTest method shouldNotFallIntoInfiniteCycleDuringCascadeHasManyNullification3entities.
@Test
public final void shouldNotFallIntoInfiniteCycleDuringCascadeHasManyNullification3entities() {
// given
Entity modelA = buildEntity(aDataDefinition);
Entity modelB = buildEntity(bDataDefinition);
Entity modelC = buildEntity(cDataDefinition);
modelA.setField(FIELD_BT_C_NULLIFY, modelC.getId());
// modelC.setField("nullifyHasManyA", Lists.newArrayList(modelA));
modelB.setField(FIELD_BT_A_NULLIFY, modelA.getId());
// modelA.setField("nullifyHasManyB", Lists.newArrayList(modelB));
modelC.setField(FIELD_BT_B_NULLIFY, modelB.getId());
// modelB.setField("nullifyHasManyC", Lists.newArrayList(modelC));
modelC = fromDb(save(modelC));
modelB = fromDb(save(modelB));
modelA = fromDb(save(modelA));
// when
EntityOpResult result = aDataDefinition.delete(modelA.getId());
// then
Assert.assertTrue(result.isSuccessfull());
Assert.assertNull(fromDb(modelA));
Assert.assertNotNull(fromDb(modelB));
Assert.assertNull(fromDb(modelB).getField(FIELD_BT_A_NULLIFY));
Assert.assertNotNull(fromDb(modelC));
Assert.assertNotNull(fromDb(modelC).getField(FIELD_BT_B_NULLIFY));
}
use of com.qcadoo.model.api.EntityOpResult in project qcadoo by qcadoo.
the class CyclesPreventionTest method shouldNotFallIntoInfiniteCycleDuringCascadeHasManyNullification2entities.
@Test
public final void shouldNotFallIntoInfiniteCycleDuringCascadeHasManyNullification2entities() {
// given
Entity modelA = buildEntity(aDataDefinition);
Entity modelB = buildEntity(bDataDefinition);
modelA.setField(FIELD_BT_B_NULLIFY, modelB.getId());
modelB.setField(FIELD_BT_A_NULLIFY, modelA.getId());
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.assertNotNull(fromDb(modelB));
Assert.assertNull(fromDb(modelB).getField(FIELD_BT_A_NULLIFY));
}
use of com.qcadoo.model.api.EntityOpResult in project qcadoo by qcadoo.
the class CyclesPreventionTest method shouldNotFallIntoInfiniteCycleDuringCascadeHasManyDeletion3entities.
@Test
public final void shouldNotFallIntoInfiniteCycleDuringCascadeHasManyDeletion3entities() {
// given
Entity modelA = buildEntity(aDataDefinition);
Entity modelB = buildEntity(bDataDefinition);
Entity modelC = buildEntity(cDataDefinition);
modelA.setField(FIELD_BT_C, modelC.getId());
modelB.setField(FIELD_BT_A, modelA.getId());
modelC.setField(FIELD_BT_B, modelB.getId());
modelA = fromDb(save(modelA));
modelB = fromDb(save(modelB));
modelC = fromDb(save(modelC));
// when
EntityOpResult result = aDataDefinition.delete(modelA.getId());
// then
Assert.assertTrue(result.isSuccessfull());
Assert.assertNull(fromDb(modelA));
Assert.assertNull(fromDb(modelB));
Assert.assertNull(fromDb(modelC));
}
use of com.qcadoo.model.api.EntityOpResult in project qcadoo by qcadoo.
the class ManyToManyIntegrationTest method shouldPerformCascadeDeletionDeeplyVariant.
@Test
public final void shouldPerformCascadeDeletionDeeplyVariant() {
// 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)));
Entity factory1 = createFactory("factory1");
factory1.setField("parentPart", firstPart);
factory1.setField("deletionIsProhibited", false);
factory1 = save(factory1);
firstPart = fromDb(firstPart);
// when
EntityOpResult result = delete(secondProduct);
// then
Assert.assertTrue(result.isSuccessfull());
Assert.assertNull(fromDb(firstPart));
Assert.assertNotNull(fromDb(secondPart));
Assert.assertNull(fromDb(thirdPart));
Assert.assertNull(fromDb(factory1));
Assert.assertNotNull(fromDb(firstProduct));
Assert.assertNull(fromDb(secondProduct));
Assert.assertNotNull(fromDb(thirdProduct));
}
use of com.qcadoo.model.api.EntityOpResult in project qcadoo by qcadoo.
the class ManyToManyIntegrationTest method shouldOnDeleteHookRejectCascadeDeletionDeeplyVariant.
@Test
public final void shouldOnDeleteHookRejectCascadeDeletionDeeplyVariant() {
// 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)));
Entity factory1 = createFactory("factory1");
factory1.setField("parentPart", firstPart);
factory1.setField("deletionIsProhibited", true);
factory1 = save(factory1);
firstPart = fromDb(firstPart);
// 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(factory1));
Assert.assertNotNull(fromDb(firstProduct));
Assert.assertNotNull(fromDb(secondProduct));
Assert.assertNotNull(fromDb(thirdProduct));
}
Aggregations