Search in sources :

Example 1 with EntityList

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

the class EntityTestUtils method stubHasManyField.

public static void stubHasManyField(final Entity entity, final String fieldName, final Iterable<Entity> fieldValue) {
    EntityList entityListMock = EntityListMock.create(Lists.newArrayList(fieldValue));
    stubHasManyField(entity, fieldName, entityListMock);
}
Also used : EntityList(com.qcadoo.model.api.EntityList)

Example 2 with EntityList

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

the class DataAccessServiceGetTest method shouldGetHasManyField.

@Test
public void shouldGetHasManyField() throws Exception {
    // given
    SampleParentDatabaseObject parentDatabaseObject = new SampleParentDatabaseObject();
    parentDatabaseObject.setId(1L);
    parentDatabaseObject.setName("Mr T");
    given(session.get(any(Class.class), Matchers.anyInt())).willReturn(parentDatabaseObject);
    // when
    Entity entity = parentDataDefinition.get(1L);
    // then
    assertEquals(1L, entity.getId().longValue());
    assertEquals("Mr T", entity.getField("name"));
    assertThat(entity.getField("entities"), CoreMatchers.instanceOf(EntityListImpl.class));
    EntityList entities = entity.getHasManyField("entities");
    assertEquals(1L, getField(entities, "parentId"));
    assertEquals("belongsTo", ((FieldDefinition) getField(entities, "joinFieldDefinition")).getName());
    assertEquals("simple.entity", ((DataDefinition) getField(entities, "dataDefinition")).getName());
}
Also used : Entity(com.qcadoo.model.api.Entity) SampleParentDatabaseObject(com.qcadoo.model.beans.sample.SampleParentDatabaseObject) EntityList(com.qcadoo.model.api.EntityList) Test(org.junit.Test)

Example 3 with EntityList

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

the class DefaultEntityTest method shouldReturnDetachedEntityListImpl.

@Test
public final void shouldReturnDetachedEntityListImpl() throws Exception {
    // given
    final String hasManyFieldName = "hasManyDetachedField";
    List<Entity> listOfMockEntities = getListOfMockEntities();
    defaultEntity.setField(hasManyFieldName, listOfMockEntities);
    // when
    EntityList resultList = defaultEntity.getHasManyField(hasManyFieldName);
    // then
    Assert.assertTrue(resultList instanceof DetachedEntityListImpl);
    Assert.assertEquals(listOfMockEntities.size(), resultList.size());
    Assert.assertArrayEquals(listOfMockEntities.toArray(), resultList.toArray());
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityList(com.qcadoo.model.api.EntityList) Test(org.junit.Test)

Example 4 with EntityList

use of com.qcadoo.model.api.EntityList 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 5 with EntityList

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

the class HasManyIntegrationTest method checkHasManyField.

private void checkHasManyField(final Entity entity, final String fieldName, final Entity... expectedEntities) {
    EntityList entities = entity.getHasManyField(fieldName);
    Set<Long> ids = Sets.newHashSet(Collections2.transform(entity.getHasManyField(fieldName), EXTRACT_ID));
    assertEquals(expectedEntities.length, entities.size());
    for (Entity expectedEntity : expectedEntities) {
        assertTrue("missing " + expectedEntity, ids.contains(expectedEntity.getId()));
    }
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityList(com.qcadoo.model.api.EntityList)

Aggregations

EntityList (com.qcadoo.model.api.EntityList)103 Entity (com.qcadoo.model.api.Entity)52 Test (org.junit.Test)27 DataDefinition (com.qcadoo.model.api.DataDefinition)16 SearchCriteriaBuilder (com.qcadoo.model.api.search.SearchCriteriaBuilder)16 Before (org.junit.Before)11 UserFieldsMF (com.qcadoo.mes.materialFlow.constants.UserFieldsMF)10 UserLocationFields (com.qcadoo.mes.materialFlow.constants.UserLocationFields)10 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)10 SearchRestrictions (com.qcadoo.model.api.search.SearchRestrictions)10 SecurityService (com.qcadoo.security.api.SecurityService)10 QcadooSecurityConstants (com.qcadoo.security.constants.QcadooSecurityConstants)10 Objects (java.util.Objects)10 Set (java.util.Set)10 Collectors (java.util.stream.Collectors)10 Autowired (org.springframework.beans.factory.annotation.Autowired)10 Service (org.springframework.stereotype.Service)10 FilterValueHolder (com.qcadoo.view.api.components.lookup.FilterValueHolder)9 BigDecimal (java.math.BigDecimal)9 StateChangeTest (com.qcadoo.mes.states.StateChangeTest)5