Search in sources :

Example 51 with FieldDefinition

use of com.qcadoo.model.api.FieldDefinition in project qcadoo by qcadoo.

the class EntityServiceImplTest method shouldLazyLoadEntitiesUsingProxy.

@Test
public void shouldLazyLoadEntitiesUsingProxy() throws Exception {
    // given
    InternalDataDefinition dataDefinition = mock(InternalDataDefinition.class, RETURNS_DEEP_STUBS);
    FieldDefinition fieldDefinition = mock(FieldDefinition.class);
    BelongsToType fieldType = mock(BelongsToType.class);
    Entity entity1 = new DefaultEntity(dataDefinition, 1L);
    Entity entity2 = new DefaultEntity(dataDefinition, 2L);
    given(fieldDefinition.getName()).willReturn("joinField");
    given(fieldDefinition.getType()).willReturn(fieldType);
    given(fieldType.getDataDefinition()).willReturn(dataDefinition);
    given(dataDefinition.isEnabled()).willReturn(true);
    given(dataDefinition.getField("joinField")).willReturn(fieldDefinition);
    given(dataDefinition.find().createAlias(fieldDefinition.getName(), fieldDefinition.getName()).add(SearchRestrictions.eq(fieldDefinition.getName() + ".id", 5L)).list().getEntities()).willReturn(Lists.newArrayList(entity1, entity2));
    List<Entity> entityList = new EntityListImpl(dataDefinition, "joinField", 5L);
    // then
    assertNotNull(entityList);
    assertEquals(2, entityList.size());
    assertThat(entityList, JUnitMatchers.hasItems(entity1, entity2));
}
Also used : Entity(com.qcadoo.model.api.Entity) BelongsToType(com.qcadoo.model.api.types.BelongsToType) FieldDefinition(com.qcadoo.model.api.FieldDefinition) InternalDataDefinition(com.qcadoo.model.internal.api.InternalDataDefinition) Test(org.junit.Test)

Example 52 with FieldDefinition

use of com.qcadoo.model.api.FieldDefinition in project qcadoo by qcadoo.

the class EntityServiceImplTest method shouldThrownAnExceptionWhileGettingNotExistingField.

@Test(expected = IllegalStateException.class)
public void shouldThrownAnExceptionWhileGettingNotExistingField() throws Exception {
    // given
    SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject(1L);
    FieldDefinition fieldDefinition = new FieldDefinitionImpl(new DataDefinitionImpl("", "", null), "unknown");
    // when
    entityService.getField(databaseEntity, fieldDefinition);
}
Also used : FieldDefinition(com.qcadoo.model.api.FieldDefinition) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) Test(org.junit.Test)

Example 53 with FieldDefinition

use of com.qcadoo.model.api.FieldDefinition in project qcadoo by qcadoo.

the class EntityServiceImplTest method shouldThrownAnExceptionWhileSettingNotExistingField.

@Test(expected = IllegalStateException.class)
public void shouldThrownAnExceptionWhileSettingNotExistingField() throws Exception {
    // given
    SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject(1L);
    FieldDefinition fieldDefinition = new FieldDefinitionImpl(new DataDefinitionImpl("", "", null), "unknown").withType(new StringType());
    // when
    entityService.setField(databaseEntity, fieldDefinition, "XXX");
}
Also used : StringType(com.qcadoo.model.internal.types.StringType) FieldDefinition(com.qcadoo.model.api.FieldDefinition) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) Test(org.junit.Test)

Example 54 with FieldDefinition

use of com.qcadoo.model.api.FieldDefinition in project qcadoo by qcadoo.

the class EntityServiceImplTest method shouldNotThrownAnExceptionWhileGettingFieldWithInvalidType.

@Test
public void shouldNotThrownAnExceptionWhileGettingFieldWithInvalidType() throws Exception {
    // given
    SampleSimpleDatabaseObject databaseEntity = new SampleSimpleDatabaseObject(1L);
    databaseEntity.setName("Mr T");
    FieldDefinition fieldDefinition = new FieldDefinitionImpl(new DataDefinitionImpl("", "", null), "name").withType(new IntegerType());
    // when
    entityService.getField(databaseEntity, fieldDefinition);
}
Also used : IntegerType(com.qcadoo.model.internal.types.IntegerType) FieldDefinition(com.qcadoo.model.api.FieldDefinition) SampleSimpleDatabaseObject(com.qcadoo.model.beans.sample.SampleSimpleDatabaseObject) Test(org.junit.Test)

Example 55 with FieldDefinition

use of com.qcadoo.model.api.FieldDefinition in project qcadoo by qcadoo.

the class EntityTreeImplTest method shouldBuildTree.

@Test
public void shouldBuildTree() throws Exception {
    // given
    Entity entity1 = mock(Entity.class);
    given(entity1.getId()).willReturn(1L);
    Entity entity2 = mock(Entity.class);
    given(entity2.getId()).willReturn(2L);
    given(entity2.getBelongsToField("parent")).willReturn(entity1);
    Entity entity3 = mock(Entity.class);
    given(entity3.getId()).willReturn(3L);
    given(entity3.getBelongsToField("parent")).willReturn(entity1);
    Entity entity4 = mock(Entity.class);
    given(entity4.getId()).willReturn(4L);
    given(entity4.getBelongsToField("parent")).willReturn(entity2);
    List<Entity> entities = Arrays.asList(new Entity[] { entity1, entity2, entity3, entity4 });
    BelongsToType fieldType = mock(BelongsToType.class);
    InternalDataDefinition dataDefinition = mock(InternalDataDefinition.class, RETURNS_DEEP_STUBS);
    given(fieldType.getDataDefinition()).willReturn(dataDefinition);
    FieldDefinition fieldDefinition = mock(FieldDefinition.class);
    given(fieldDefinition.getType()).willReturn(fieldType);
    given(fieldDefinition.getName()).willReturn("field");
    given(dataDefinition.getField("tree")).willReturn(fieldDefinition);
    given(dataDefinition.find().add(SearchRestrictions.belongsTo("field", dataDefinition, 1L)).addOrder(SearchOrders.asc("priority")).list().getEntities()).willReturn(entities);
    EntityTreeImpl tree = new EntityTreeImpl(dataDefinition, "tree", 1L);
    // when
    EntityTreeNodeImpl root = tree.getRoot();
    // then
    assertEquals(4, tree.size());
    assertEquals(Long.valueOf(1L), root.getId());
    assertEquals(Long.valueOf(2L), root.getChildren().get(0).getId());
    assertEquals(Long.valueOf(3L), root.getChildren().get(1).getId());
    assertEquals(Long.valueOf(4L), root.getChildren().get(0).getChildren().get(0).getId());
}
Also used : Entity(com.qcadoo.model.api.Entity) BelongsToType(com.qcadoo.model.api.types.BelongsToType) FieldDefinition(com.qcadoo.model.api.FieldDefinition) InternalDataDefinition(com.qcadoo.model.internal.api.InternalDataDefinition) Test(org.junit.Test)

Aggregations

FieldDefinition (com.qcadoo.model.api.FieldDefinition)142 Test (org.junit.Test)92 DataDefinition (com.qcadoo.model.api.DataDefinition)49 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)48 Entity (com.qcadoo.model.api.Entity)32 BelongsToType (com.qcadoo.model.api.types.BelongsToType)19 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)15 InternalDataDefinition (com.qcadoo.model.internal.api.InternalDataDefinition)13 InternalFieldDefinition (com.qcadoo.model.internal.api.InternalFieldDefinition)12 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)11 HasManyType (com.qcadoo.model.api.types.HasManyType)9 StringType (com.qcadoo.model.internal.types.StringType)9 JSONObject (org.json.JSONObject)8 Map (java.util.Map)7 Matchers.anyString (org.mockito.Matchers.anyString)7 SearchCriterion (com.qcadoo.model.api.search.SearchCriterion)6 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)6 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)6 Before (org.junit.Before)6 EntityList (com.qcadoo.model.api.EntityList)5