Search in sources :

Example 6 with EntityOpResult

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));
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityOpResult(com.qcadoo.model.api.EntityOpResult) Test(org.junit.Test)

Example 7 with EntityOpResult

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));
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityOpResult(com.qcadoo.model.api.EntityOpResult) Test(org.junit.Test)

Example 8 with EntityOpResult

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));
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityOpResult(com.qcadoo.model.api.EntityOpResult) Test(org.junit.Test)

Example 9 with EntityOpResult

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));
}
Also used : Entity(com.qcadoo.model.api.Entity) ProxyEntity(com.qcadoo.model.internal.ProxyEntity) EntityOpResult(com.qcadoo.model.api.EntityOpResult) Test(org.junit.Test)

Example 10 with EntityOpResult

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));
}
Also used : Entity(com.qcadoo.model.api.Entity) ProxyEntity(com.qcadoo.model.internal.ProxyEntity) EntityOpResult(com.qcadoo.model.api.EntityOpResult) Test(org.junit.Test)

Aggregations

EntityOpResult (com.qcadoo.model.api.EntityOpResult)21 Entity (com.qcadoo.model.api.Entity)19 Test (org.junit.Test)15 ProxyEntity (com.qcadoo.model.internal.ProxyEntity)4 FieldDefinition (com.qcadoo.model.api.FieldDefinition)2 ErrorMessage (com.qcadoo.model.api.validators.ErrorMessage)2 InternalDataDefinition (com.qcadoo.model.internal.api.InternalDataDefinition)2 InternalFieldDefinition (com.qcadoo.model.internal.api.InternalFieldDefinition)2 ArrayList (java.util.ArrayList)2 EntityList (com.qcadoo.model.api.EntityList)1 EntityMessagesHolder (com.qcadoo.model.api.EntityMessagesHolder)1 Monitorable (com.qcadoo.model.api.aop.Monitorable)1 CollectionFieldType (com.qcadoo.model.api.types.CollectionFieldType)1 HasManyType (com.qcadoo.model.api.types.HasManyType)1 TreeType (com.qcadoo.model.api.types.TreeType)1 EntitySignature (com.qcadoo.model.internal.utils.EntitySignature)1 GridComponent (com.qcadoo.view.api.components.GridComponent)1 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)1 Collection (java.util.Collection)1 List (java.util.List)1