Search in sources :

Example 6 with BelongsToType

use of com.qcadoo.model.api.types.BelongsToType in project qcadoo by qcadoo.

the class EntityListImplTest method shouldLoadEntities.

@Test
public void shouldLoadEntities() throws Exception {
    // given
    Entity entity = mock(Entity.class);
    List<Entity> entities = Collections.singletonList(entity);
    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.getName()).willReturn("field");
    given(fieldDefinition.getType()).willReturn(fieldType);
    given(dataDefinition.getField("hasMany")).willReturn(fieldDefinition);
    given(dataDefinition.find().createAlias(fieldDefinition.getName(), fieldDefinition.getName()).add(SearchRestrictions.eq(fieldDefinition.getName() + ".id", 1L)).list().getEntities()).willReturn(entities);
    given(dataAccessService.get(dataDefinition, 1L)).willReturn(entity);
    EntityListImpl list = new EntityListImpl(dataDefinition, "hasMany", 1L);
    // then
    assertEquals(1, list.size());
    assertEquals(entity, list.get(0));
}
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 7 with BelongsToType

use of com.qcadoo.model.api.types.BelongsToType in project qcadoo by qcadoo.

the class EntityListImplTest method shouldReturnCriteriaBuilder.

@Test
public void shouldReturnCriteriaBuilder() throws Exception {
    // given
    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("hasMany")).willReturn(fieldDefinition);
    SearchCriteriaBuilder searchCriteriaBuilder = mock(SearchCriteriaBuilder.class);
    given(dataDefinition.find().createAlias(fieldDefinition.getName(), fieldDefinition.getName()).add(SearchRestrictions.eq(fieldDefinition.getName() + ".id", 1L))).willReturn(searchCriteriaBuilder);
    EntityList list = new EntityListImpl(dataDefinition, "hasMany", 1L);
    // then
    assertEquals(searchCriteriaBuilder, list.find());
}
Also used : SearchCriteriaBuilder(com.qcadoo.model.api.search.SearchCriteriaBuilder) BelongsToType(com.qcadoo.model.api.types.BelongsToType) FieldDefinition(com.qcadoo.model.api.FieldDefinition) EntityList(com.qcadoo.model.api.EntityList) InternalDataDefinition(com.qcadoo.model.internal.api.InternalDataDefinition) Test(org.junit.Test)

Example 8 with BelongsToType

use of com.qcadoo.model.api.types.BelongsToType 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 9 with BelongsToType

use of com.qcadoo.model.api.types.BelongsToType 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)

Example 10 with BelongsToType

use of com.qcadoo.model.api.types.BelongsToType in project qcadoo by qcadoo.

the class EntityTreeImplTest method shouldFailIfThereAreMultipleRoots.

@Test(expected = IllegalStateException.class)
public void shouldFailIfThereAreMultipleRoots() throws Exception {
    // given
    Entity entity1 = mock(Entity.class);
    given(entity1.getId()).willReturn(1L);
    Entity entity2 = mock(Entity.class);
    given(entity2.getId()).willReturn(2L);
    List<Entity> entities = Arrays.asList(new Entity[] { entity1, entity2 });
    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
    tree.size();
}
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

BelongsToType (com.qcadoo.model.api.types.BelongsToType)26 FieldDefinition (com.qcadoo.model.api.FieldDefinition)19 Test (org.junit.Test)14 DataDefinition (com.qcadoo.model.api.DataDefinition)13 Entity (com.qcadoo.model.api.Entity)12 InternalDataDefinition (com.qcadoo.model.internal.api.InternalDataDefinition)10 HasManyType (com.qcadoo.model.api.types.HasManyType)5 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)5 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)5 Before (org.junit.Before)4 EntityList (com.qcadoo.model.api.EntityList)2 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)2 FieldType (com.qcadoo.model.api.types.FieldType)2 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)2 ComponentOption (com.qcadoo.view.internal.ComponentOption)2 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)2 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)2 AbstractComponentPattern (com.qcadoo.view.internal.patterns.AbstractComponentPattern)2 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)2 Map (java.util.Map)2