Search in sources :

Example 26 with EntityList

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

the class ProductQuantitiesServiceImplTest method init.

@Before
public void init() {
    MockitoAnnotations.initMocks(this);
    productQuantitiesService = new ProductQuantitiesServiceImpl();
    ReflectionTestUtils.setField(productQuantitiesService, "numberService", numberService);
    when(order.getBelongsToField("technology")).thenReturn(technology);
    tree = mockEntityTreeIterator(asList((Entity) operationComponent1, (Entity) operationComponent2));
    EntityList opComp1InComp = mockEntityListIterator(asList(productInComponent1));
    EntityList opComp1InComp1 = mockEntityListIterator(asList(productInComponent1));
    EntityList opComp1InComp2 = mockEntityListIterator(asList(productInComponent1));
    EntityList opComp2InComp = mockEntityListIterator(asList(productInComponent2, productInComponent3));
    EntityList opComp2InComp1 = mockEntityListIterator(asList(productInComponent2, productInComponent3));
    EntityList opComp2InComp2 = mockEntityListIterator(asList(productInComponent2, productInComponent3));
    EntityList opComp1OutComp = mockEntityListIterator(asList(productOutComponent2));
    EntityList opComp1OutComp1 = mockEntityListIterator(asList(productOutComponent2));
    EntityList opComp1OutComp2 = mockEntityListIterator(asList(productOutComponent2));
    EntityList opComp2OutComp = mockEntityListIterator(asList(productOutComponent4));
    EntityList opComp2OutComp1 = mockEntityListIterator(asList(productOutComponent4));
    EntityList opComp2OutComp2 = mockEntityListIterator(asList(productOutComponent4));
    when(operationComponent1.getHasManyField("operationProductInComponents")).thenReturn(opComp1InComp, opComp1InComp1, opComp1InComp2);
    when(operationComponent1.getHasManyField("operationProductOutComponents")).thenReturn(opComp1OutComp, opComp1OutComp1, opComp1OutComp2);
    when(operationComponent2.getHasManyField("operationProductInComponents")).thenReturn(opComp2InComp, opComp2InComp1, opComp2InComp2);
    when(operationComponent2.getHasManyField("operationProductOutComponents")).thenReturn(opComp2OutComp, opComp2OutComp1, opComp2OutComp2);
    plannedQty = new BigDecimal(4.5f);
    when(order.getField("plannedQuantity")).thenReturn(plannedQty);
    when(productInComponent1.getField("quantity")).thenReturn(new BigDecimal(5));
    when(productInComponent2.getField("quantity")).thenReturn(new BigDecimal(2));
    when(productInComponent3.getField("quantity")).thenReturn(new BigDecimal(1));
    when(productOutComponent2.getField("quantity")).thenReturn(new BigDecimal(1));
    when(productOutComponent4.getField("quantity")).thenReturn(new BigDecimal(1));
    productInComponents = new HashMap<Entity, List<Entity>>();
    productOutComponents = new HashMap<Entity, List<Entity>>();
    productInComponents.put(operationComponent1, asList(productInComponent1));
    productInComponents.put(operationComponent2, asList(productInComponent2, productInComponent3));
    productOutComponents.put(operationComponent1, asList(productOutComponent2));
    productOutComponents.put(operationComponent2, asList(productOutComponent4));
    when(product1.getId()).thenReturn(1L);
    when(product2.getId()).thenReturn(2L);
    when(product3.getId()).thenReturn(3L);
    when(product4.getId()).thenReturn(4L);
    when(technology.getBelongsToField("product")).thenReturn(product4);
    when(productInComponent1.getBelongsToField("product")).thenReturn(product1);
    when(productInComponent2.getBelongsToField("product")).thenReturn(product2);
    when(productInComponent3.getBelongsToField("product")).thenReturn(product3);
    when(productOutComponent2.getBelongsToField("product")).thenReturn(product2);
    when(productOutComponent4.getBelongsToField("product")).thenReturn(product4);
    when(tree.getRoot()).thenReturn(operationComponent2);
    EntityList operationComponent1children = mockEntityListIterator(new LinkedList<Entity>());
    EntityList operationComponent2children = mockEntityListIterator(asList((Entity) operationComponent1));
    when(operationComponent1.getHasManyField("children")).thenReturn(operationComponent1children);
    when(operationComponent2.getHasManyField("children")).thenReturn(operationComponent2children);
    when(technology.getTreeField("operationComponents")).thenReturn(tree);
    when(ddIn.getName()).thenReturn("operationProductInComponent");
    when(ddOut.getName()).thenReturn("operationProductOutComponent");
    when(productInComponent1.getDataDefinition()).thenReturn(ddIn);
    when(productInComponent2.getDataDefinition()).thenReturn(ddIn);
    when(productInComponent3.getDataDefinition()).thenReturn(ddIn);
    when(productOutComponent2.getDataDefinition()).thenReturn(ddOut);
    when(productOutComponent4.getDataDefinition()).thenReturn(ddOut);
    mathContext = MathContext.DECIMAL64;
    when(numberService.getMathContext()).thenReturn(mathContext);
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityList(com.qcadoo.model.api.EntityList) Arrays.asList(java.util.Arrays.asList) LinkedList(java.util.LinkedList) EntityList(com.qcadoo.model.api.EntityList) List(java.util.List) BigDecimal(java.math.BigDecimal) Before(org.junit.Before)

Example 27 with EntityList

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

the class ProductionLinesServiceImplTest method mockEntityListIterator.

private static EntityList mockEntityListIterator(final List<Entity> list) {
    EntityList entityList = mock(EntityList.class);
    when(entityList.iterator()).thenReturn(list.iterator());
    return entityList;
}
Also used : EntityList(com.qcadoo.model.api.EntityList)

Example 28 with EntityList

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

the class TechnologyServiceTest method init.

@Before
public void init() {
    technologyService = new TechnologyService();
    MockitoAnnotations.initMocks(this);
    when(product1.getId()).thenReturn(1L);
    when(product2.getId()).thenReturn(2L);
    when(opComp1.getBelongsToField("parent")).thenReturn(null);
    when(opComp2.getBelongsToField("parent")).thenReturn(opComp1);
    EntityList opComp1Children = mockEntityIterator(asList((Entity) opComp2));
    when(opComp1.getHasManyField("children")).thenReturn(opComp1Children);
    when(prodOutComp1.getBelongsToField("product")).thenReturn(product1);
    when(prodOutComp2.getBelongsToField("product")).thenReturn(product2);
    when(prodInComp1.getBelongsToField("product")).thenReturn(product1);
    when(prodOutComp1.getDecimalField("quantity")).thenReturn(new BigDecimal(10));
    when(prodOutComp2.getDecimalField("quantity")).thenReturn(new BigDecimal(10));
    EntityList opComp1prodIns = mockEntityIterator(asList(prodInComp1));
    when(opComp1.getHasManyField("operationProductInComponents")).thenReturn(opComp1prodIns);
    EntityList opComp2prodOuts = mockEntityIterator(asList(prodOutComp1, prodOutComp2));
    when(opComp2.getHasManyField("operationProductOutComponents")).thenReturn(opComp2prodOuts);
    when(dataDefinition.getName()).thenReturn("technologyOperationComponent");
    when(opComp2.getDataDefinition()).thenReturn(dataDefinition);
    when(opComp1.getDataDefinition()).thenReturn(dataDefinition);
    when(opComp1.getBelongsToField("technology")).thenReturn(technology);
    when(opComp2.getBelongsToField("technology")).thenReturn(technology);
}
Also used : Entity(com.qcadoo.model.api.Entity) EntityList(com.qcadoo.model.api.EntityList) BigDecimal(java.math.BigDecimal) Before(org.junit.Before)

Example 29 with EntityList

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

the class WorkPlansColumnFillerTest method mockEntityList.

private EntityList mockEntityList(List<Entity> list) {
    EntityList entityList = mock(EntityList.class);
    when(entityList.iterator()).thenReturn(list.iterator());
    return entityList;
}
Also used : EntityList(com.qcadoo.model.api.EntityList)

Example 30 with EntityList

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

the class WorkPlansColumnFillerTest method shouldReturnCorrectColumnValuesForProducts.

@Test
public void shouldReturnCorrectColumnValuesForProducts() {
    // given
    EntityTree operComps = mockEntityTree(asList(operationComponent));
    EntityTree operComps2 = mockEntityTree(asList(operationComponent));
    given(technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS)).willReturn(operComps, operComps2);
    given(operationComponent.getId()).willReturn(1L);
    EntityList prodInComps = mockEntityList(asList(operationProductComponent));
    EntityList prodInComps2 = mockEntityList(asList(operationProductComponent));
    given(operationProductComponent.getBelongsToField("operationComponent")).willReturn(operationComponent);
    given(operationProductComponent.getBelongsToField(L_PRODUCT)).willReturn(product);
    given(operationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_IN_COMPONENTS)).willReturn(prodInComps, prodInComps2);
    EntityList prodOutComps = mockEntityList(new ArrayList<Entity>());
    given(operationComponent.getHasManyField(TechnologyOperationComponentFields.OPERATION_PRODUCT_OUT_COMPONENTS)).willReturn(prodOutComps);
    given(operationProductComponent.getDataDefinition()).willReturn(operationProductComponentDD);
    given(operationProductComponentDD.getName()).willReturn(TechnologiesConstants.MODEL_OPERATION_PRODUCT_IN_COMPONENT);
    OperationProductComponentWithQuantityContainer quantities = new OperationProductComponentWithQuantityContainer();
    quantities.put(operationProductComponent, new BigDecimal(11));
    given(productQuantitiesService.getProductComponentQuantities(order)).willReturn(quantities);
    // when
    Map<Entity, Map<String, String>> columnValues = workPlansColumnFiller.getValues(asList(order));
    // then
    assertEquals(1, columnValues.size());
    assertEquals("product (123)", columnValues.get(operationProductComponent).get(L_PRODUCT_NAME));
    assertEquals("11.00000 abc", columnValues.get(operationProductComponent).get(L_PLANNED_QUANTITY));
}
Also used : Entity(com.qcadoo.model.api.Entity) OperationProductComponentWithQuantityContainer(com.qcadoo.mes.technologies.dto.OperationProductComponentWithQuantityContainer) EntityList(com.qcadoo.model.api.EntityList) EntityTree(com.qcadoo.model.api.EntityTree) Map(java.util.Map) BigDecimal(java.math.BigDecimal) 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