Search in sources :

Example 16 with EntityOpResult

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

Example 17 with EntityOpResult

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

Example 18 with EntityOpResult

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

Example 19 with EntityOpResult

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

Example 20 with EntityOpResult

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));
}
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