Search in sources :

Example 96 with EntityList

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;
}
Also used : EntityList(com.qcadoo.model.api.EntityList)

Example 97 with 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) {
    }
}
Also used : EntityList(com.qcadoo.model.api.EntityList) Test(org.junit.Test)

Example 98 with EntityList

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());
}
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 99 with EntityList

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());
}
Also used : EntityList(com.qcadoo.model.api.EntityList) Test(org.junit.Test)

Example 100 with EntityList

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);
}
Also used : EntityList(com.qcadoo.model.api.EntityList) Test(org.junit.Test)

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