Exemplo n.º 1
0
  @Before
  public final void init() {
    workPlanService = new WorkPlansServiceImpl();

    dataDefinitionService = mock(DataDefinitionService.class);
    TranslationService translationService = mock(TranslationService.class);
    workPlan = mock(Entity.class);
    workPlanDD = mock(DataDefinition.class);

    when(dataDefinitionService.get(
            WorkPlansConstants.PLUGIN_IDENTIFIER, WorkPlansConstants.MODEL_WORK_PLAN))
        .thenReturn(workPlanDD);

    when(translationService.translate(
            Mockito.anyString(), Mockito.any(Locale.class), Mockito.anyString()))
        .thenReturn(TRANSLATED_STRING);

    when(workPlanDD.getName()).thenReturn(WorkPlansConstants.MODEL_WORK_PLAN);
    when(workPlanDD.getPluginIdentifier()).thenReturn(WorkPlansConstants.PLUGIN_IDENTIFIER);
    when(workPlanDD.get(Mockito.anyLong())).thenReturn(workPlan);

    when(workPlan.getDataDefinition()).thenReturn(workPlanDD);
    when(workPlan.getId()).thenReturn(1L);

    ReflectionTestUtils.setField(workPlanService, "dataDefinitionService", dataDefinitionService);
    ReflectionTestUtils.setField(workPlanService, "translationService", translationService);
  }
Exemplo n.º 2
0
  private Entity generateFormEntity(final ViewDefinitionState view) {
    DataDefinition dd =
        dataDefinitionService.get(BasicConstants.PLUGIN_IDENTIFIER, BasicConstants.MODEL_PRODUCT);

    FormComponent form = getForm(view);
    Entity formEntity = form.getEntity();
    GridComponent parentsGrid = (GridComponent) view.getComponentByReference("parents");
    if (parentsGrid.getSelectedEntities().isEmpty()) {
      return null;
    }
    Long productId = parentsGrid.getSelectedEntities().get(0).getId();

    if (productId == null) {
      throw new FormValidationException("basic.productFamiliesTree.noProductSelected");
    }

    Entity product = dd.get(productId);

    List<Entity> tree = productsFamiliesTreeService.getHierarchyProductsTree(product);
    EntityTree entityTree = EntityTreeUtilsService.getDetachedEntityTree(tree);
    formEntity.setId(productId);
    formEntity.setField(PRODUCT_FAMILY_CHILDREN_TREE, entityTree);

    return formEntity;
  }
 public void setProductAsConverted(final ImportedProduct product) {
   DataDefinition importedProductDataDefinition =
       dataDefinitionService.get(
           SfcSimpleConstants.PLUGIN_IDENTIFIER, SfcSimpleConstants.MODEL_IMPORTED_PRODUCT);
   Entity importedProduct = importedProductDataDefinition.get(product.getOriginalEntityId());
   importedProduct.setField(FIELD_CONVERTED, "1");
   importedProductDataDefinition.save(importedProduct);
 }
 public void setOrderAsConverted(final ImportedOrder order) {
   DataDefinition importedOrderDataDefinition =
       dataDefinitionService.get(
           SfcSimpleConstants.PLUGIN_IDENTIFIER, SfcSimpleConstants.MODEL_IMPORTED_ORDER);
   Entity importedOrder = importedOrderDataDefinition.get(order.getOriginalEntityId());
   importedOrder.setField(FIELD_CONVERTED, "1");
   importedOrderDataDefinition.save(importedOrder);
 }
 private Entity mockProductComponent(final Long productId) {
   Entity productComponent = mock(Entity.class);
   Entity product = mock(Entity.class);
   given(product.getField("id")).willReturn(productId);
   given(product.getId()).willReturn(productId);
   given(productComponent.getField("product")).willReturn(product);
   given(productComponent.getBelongsToField("product")).willReturn(product);
   given(dataDefinition.get(productId)).willReturn(productComponent);
   return productComponent;
 }
Exemplo n.º 6
0
 @Test
 public void shouldReturnWhenProductQuantitiesFromTechnologyIsnotEmpty() throws Exception {
   // given
   Long orderId = 1L;
   Long technologyId = 2L;
   when(order.getBelongsToField("technology")).thenReturn(technology);
   when(order.getId()).thenReturn(orderId);
   when(orderDD.get(orderId)).thenReturn(order);
   when(technology.getId()).thenReturn(technologyId);
   // when
   orderHooksCNFM.fillOrderOperationProductsInComponents(orderDD, order);
 }
  @Test
  public void shouldReturnNullWhenGetCompanyProductsFamily() {
    // given
    Long companyProductsFamilyId = null;

    given(companyProductsFamilyDD.get(companyProductsFamilyId)).willReturn(null);

    // when
    Entity result = deliveriesService.getDeliveredProduct(companyProductsFamilyId);

    // then
    assertEquals(null, result);
  }
  @Test
  public void shouldReturnCompanyProductsFamilyWhenGetCompanyProductsFamily() {
    // given
    Long companyProductsFamilyId = 1L;

    given(companyProductsFamilyDD.get(companyProductsFamilyId)).willReturn(companyProductsFamily);

    // when
    Entity result = deliveriesService.getCompanyProductsFamily(companyProductsFamilyId);

    // then
    assertEquals(companyProductsFamily, result);
  }
  @Test
  public void shouldReturnDeliveredProductWhenGetDeliveredProduct() {
    // given
    Long deliveredProductId = 1L;

    given(deliveredProductDD.get(deliveredProductId)).willReturn(deliveredProduct);

    // when
    Entity result = deliveriesService.getDeliveredProduct(deliveredProductId);

    // then
    assertEquals(deliveredProduct, result);
  }
Exemplo n.º 10
0
  @Test
  public void shouldReturnNullWhenGetOrderedProduct() {
    // given
    Long orderedProductId = null;

    given(orderedProductDD.get(orderedProductId)).willReturn(null);

    // when
    Entity result = deliveriesService.getOrderedProduct(orderedProductId);

    // then
    assertEquals(null, result);
  }
Exemplo n.º 11
0
  @Test
  public void shouldReturnDeliveryWhenGetDelivery() {
    // given
    Long deliveryId = 1L;

    given(deliveryDD.get(deliveryId)).willReturn(delivery);

    // when
    Entity result = deliveriesService.getDelivery(deliveryId);

    // then
    assertEquals(delivery, result);
  }
Exemplo n.º 12
0
  @Test
  public void shouldReturnWhenProductionLineIsThisSame() throws Exception {
    // given
    Long orderId = 1L;
    when(entity.getId()).thenReturn(orderId);
    when(dataDefinition.get(orderId)).thenReturn(order);
    when(order.getBelongsToField(OrderFields.PRODUCTION_LINE)).thenReturn(orderProdLine);
    when(entity.getBelongsToField(OrderFields.PRODUCTION_LINE)).thenReturn(orderProdLine);

    // when
    hooksOTFO.changedProductionLine(dataDefinition, entity);
    // then
  }
  @Before
  public void init() {
    hooks = new TechnologyOperationComponentInOrderListHooks();
    MockitoAnnotations.initMocks(this);
    ReflectionTestUtils.setField(hooks, "dataDefinitionService", dataDefinitionService);

    Long orderId = 1L;
    when(dataDefinitionService.get(PLUGIN_IDENTIFIER, OrdersConstants.MODEL_ORDER))
        .thenReturn(dataDefinition);
    when(view.getComponentByReference("form")).thenReturn(form);
    when(form.getEntityId()).thenReturn(orderId);
    when(dataDefinition.get(orderId)).thenReturn(order);
    when(view.getComponentByReference("technology")).thenReturn(technologyField);
  }
Exemplo n.º 14
0
  @Test
  public void shouldChangedProdLineWhenProdLineIsNullify() throws Exception {
    // given
    Long orderId = 1L;
    when(entity.getId()).thenReturn(orderId);
    when(dataDefinition.get(orderId)).thenReturn(order);
    when(order.getBelongsToField(OrderFields.PRODUCTION_LINE)).thenReturn(orderProdLine);
    when(entity.getBelongsToField(OrderFields.PRODUCTION_LINE)).thenReturn(null);
    EntityList tasks = mockEntityList(Lists.newArrayList(task1));

    when(result.getEntities()).thenReturn(tasks);
    // when
    hooksOTFO.changedProductionLine(dataDefinition, entity);
    // then

    Mockito.verify(task1).setField(OrderFields.PRODUCTION_LINE, null);
  }
  private List<String> getPluginIdentifiersFromView(final ViewDefinitionState viewDefinitionState) {

    List<String> pluginIdentifiers = new LinkedList<String>();
    GridComponent grid = (GridComponent) viewDefinitionState.getComponentByReference("grid");

    Preconditions.checkState(grid.getSelectedEntitiesIds().size() > 0, "No record selected");

    DataDefinition pluginDataDefinition =
        dataDefinitionService.get(
            QcadooPluginConstants.PLUGIN_IDENTIFIER, QcadooPluginConstants.MODEL_PLUGIN);
    for (Long entityId : grid.getSelectedEntitiesIds()) {
      Entity pluginEntity = pluginDataDefinition.get(entityId);

      pluginIdentifiers.add(pluginEntity.getStringField("identifier"));
    }

    return pluginIdentifiers;
  }
Exemplo n.º 16
0
  @Test
  public void shouldCreatetTechnologyInstOperProductInComp() throws Exception {
    // given
    Long orderId = 1L;
    Long technologyId = 2L;
    BigDecimal nominalCost1 = BigDecimal.TEN;
    BigDecimal nominalCost2 = BigDecimal.TEN;

    when(productQuantities.entrySet()).thenReturn(entrySet);
    when(entrySet.iterator()).thenReturn(iterator);
    when(iterator.hasNext()).thenReturn(true, true, false);
    when(iterator.next()).thenReturn(entry1, entry2);

    when(entry1.getKey()).thenReturn(prod1);
    when(entry2.getKey()).thenReturn(prod2);

    when(prod1.getDecimalField("nominalCost")).thenReturn(nominalCost1);
    when(prod2.getDecimalField("nominalCost")).thenReturn(nominalCost2);

    when(order.getBelongsToField("technology")).thenReturn(technology);
    when(order.getId()).thenReturn(orderId);
    when(orderDD.get(orderId)).thenReturn(orderFromDB);
    when(technology.getId()).thenReturn(technologyId);

    when(costNormsForMaterialsService.getProductQuantitiesFromTechnology(technologyId))
        .thenReturn(productQuantities);
    when(techInsOperCompProdInDD.create())
        .thenReturn(techInsOperCompProdIn1, techInsOperCompProdIn2);
    when(techInsOperCompProdIn1.getDataDefinition()).thenReturn(techInsOperCompProdInDD);
    when(techInsOperCompProdIn2.getDataDefinition()).thenReturn(techInsOperCompProdInDD);
    when(techInsOperCompProdInDD.save(techInsOperCompProdIn1))
        .thenReturn(techInsOperCompProdIn1, techInsOperCompProdIn2);
    // when
    orderHooksCNFM.fillOrderOperationProductsInComponents(orderDD, order);

    // then
    Mockito.verify(techInsOperCompProdIn1).setField("order", order);
    Mockito.verify(techInsOperCompProdIn1).setField("product", prod1);
    Mockito.verify(techInsOperCompProdIn1).setField("nominalCost", nominalCost1);
    Mockito.verify(techInsOperCompProdIn2).setField("order", order);
    Mockito.verify(techInsOperCompProdIn2).setField("product", prod2);
    Mockito.verify(techInsOperCompProdIn2).setField("nominalCost", nominalCost2);
  }