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