use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class TechnologyServiceTest method mockEntityIterator.
private static EntityList mockEntityIterator(List<Entity> entities) {
EntityList entityList = mock(EntityList.class);
when(entityList.iterator()).thenReturn(entities.iterator());
return entityList;
}
use of com.qcadoo.model.api.EntityList in project mes by qcadoo.
the class TechnologyServiceTest method shouldThrowAnExceptionIfThereAreNoProductsOrIntermediates.
@Test
public void shouldThrowAnExceptionIfThereAreNoProductsOrIntermediates() {
// given
EntityList opComp2prodOuts = mockEntityIterator(asList(prodOutComp2));
when(opComp2.getHasManyField("operationProductOutComponents")).thenReturn(opComp2prodOuts);
// when
try {
technologyService.getProductCountForOperationComponent(opComp2);
fail();
} catch (IllegalStateException e) {
}
}
use of com.qcadoo.model.api.EntityList in project qcadoo by qcadoo.
the class DataAccessServiceSaveTest method shouldNotSaveEntityListField.
@Test
public void shouldNotSaveEntityListField() throws Exception {
// given
EntityList entities = new EntityListImpl(dataDefinition, "", 1L);
Entity parent = new DefaultEntity(parentDataDefinition, 1L);
parent.setField("entities", entities);
SampleParentDatabaseObject existingParent = new SampleParentDatabaseObject(1L);
given(session.get(any(Class.class), Matchers.anyInt())).willReturn(existingParent);
given(session.load(any(Class.class), Matchers.eq(1L))).willReturn(existingParent);
given(criteria.uniqueResult()).willReturn(1L);
// when
Entity entity = parentDataDefinition.save(parent);
// then
assertTrue(entity.isValid());
assertEquals(entities, entity.getField("entities"));
verify(session, times(1)).save(Mockito.any());
}
use of com.qcadoo.model.api.EntityList in project qcadoo by qcadoo.
the class DefaultEntityTest method shouldReturnEmptyDetachedEntityListIfFieldIsNull.
@Test
public final void shouldReturnEmptyDetachedEntityListIfFieldIsNull() throws Exception {
// given
final String hasManyFieldName = "hasManyDetachedField";
defaultEntity.setField(hasManyFieldName, null);
// when
EntityList resultList = defaultEntity.getHasManyField(hasManyFieldName);
// then
Assert.assertNotNull(resultList);
Assert.assertTrue(resultList instanceof DetachedEntityListImpl);
Assert.assertTrue(resultList.isEmpty());
}
use of com.qcadoo.model.api.EntityList in project qcadoo by qcadoo.
the class DefaultEntityTest method shouldReturnExistingEntityList.
@Test
public final void shouldReturnExistingEntityList() throws Exception {
// given
final String hasManyFieldName = "hasManyDetachedField";
EntityList entityList = mock(EntityList.class);
defaultEntity.setField(hasManyFieldName, entityList);
// when
EntityList resultList = defaultEntity.getHasManyField(hasManyFieldName);
// then
Assert.assertTrue(resultList instanceof EntityList);
Assert.assertEquals(entityList, resultList);
}
Aggregations