Exemplo n.º 1
0
  private void updateTechnology(final Entity technology) {
    String number = technology.getStringField(TechnologyFields.NUMBER);
    Entity product = technology.getBelongsToField(TechnologyFields.PRODUCT);

    technology.setField(TechnologyFields.NAME, makeTechnologyName(number, product));
    technology.setField(TechnologyFields.TECHNOLOGY_PROTOTYPE, null);
    technology.setField(
        TechnologyFields.TECHNOLOGY_TYPE, TechnologyType.WITH_OWN_TECHNOLOGY.getStringValue());

    EntityTree operationComponents = technology.getTreeField(TechnologyFields.OPERATION_COMPONENTS);

    if ((operationComponents != null) && !operationComponents.isEmpty()) {
      EntityTreeNode root = operationComponents.getRoot();

      root.getDataDefinition().delete(root.getId());
    }

    technology.setField(TechnologyFields.OPERATION_COMPONENTS, Lists.newArrayList());

    technology.getDataDefinition().save(technology);

    if (TechnologyStateStringValues.CHECKED.equals(
        technology.getStringField(TechnologyFields.STATE))) {
      changeTechnologyState(technology, TechnologyStateStringValues.DRAFT);
    }
  }
  @Test
  public final void shouldReturnEmptyMapIfParentOpNotConsumeManyOutputsFromOneSubOp() {
    // given
    Entity product1 = mockProductComponent(1L);
    Entity product2 = mockProductComponent(2L);
    Entity product3 = mockProductComponent(3L);
    Entity product4 = mockProductComponent(4L);
    Entity product5 = mockProductComponent(5L);
    Entity product6 = mockProductComponent(6L);

    EntityTreeNode node2B =
        mockOperationComponent("2.B.", newArrayList(product6), newArrayList(product4));
    EntityTreeNode node2A =
        mockOperationComponent("2.A.", newArrayList(product5), newArrayList(product3));
    EntityTreeNode node2 =
        mockOperationComponent(
            "2.",
            newArrayList(product3, product4),
            newArrayList(product2),
            newArrayList(node2A, node2B));
    EntityTreeNode node1 =
        mockOperationComponent(
            "1.", newArrayList(product2), newArrayList(product1), newArrayList(node2));
    given(tree.getRoot()).willReturn(node1);

    // when
    resultMap = technologyTreeValidationService.checkConsumingManyProductsFromOneSubOp(tree);

    // then
    assertNotNull(resultMap);
    assertTrue(resultMap.isEmpty());
  }
  @Test
  public final void shouldReturnNotEmptyMapIfSubOpsProduceTheSameOutputsWhichAreConsumed() {
    // given
    Entity product1 = mockProductComponent(1L);
    Entity product2 = mockProductComponent(2L);
    Entity product3 = mockProductComponent(3L);
    Entity product4 = mockProductComponent(4L);
    Entity product5 = mockProductComponent(5L);
    Entity product6 = mockProductComponent(6L);

    EntityTreeNode node3 =
        mockOperationComponent(3L, "3.", newArrayList(product5), newArrayList(product2, product3));
    EntityTreeNode node2 =
        mockOperationComponent(2L, "2.", newArrayList(product6), newArrayList(product2, product4));
    EntityTreeNode node1 =
        mockOperationComponent(
            1L, "1.", newArrayList(product2), newArrayList(product1), newArrayList(node2, node3));
    given(tree.getRoot()).willReturn(node1);

    // when
    Map<String, Set<Entity>> returnedMap =
        technologyTreeValidationService.checkConsumingTheSameProductFromManySubOperations(tree);

    // then
    assertNotNull(returnedMap);
    assertFalse(returnedMap.isEmpty());
    assertEquals(1, returnedMap.size());
    assertTrue(returnedMap.containsKey("1."));
    assertTrue(returnedMap.get("1.").contains(product2));
  }
  @Test
  public final void shouldReturnNotEmptyMapIfParentOpConsumeManyOutputsFromOneSubOp() {
    // given
    Entity product1 = mockProductComponent(1L);
    Entity product2 = mockProductComponent(2L);
    Entity product3 = mockProductComponent(3L);
    Entity product4 = mockProductComponent(4L);
    Entity product5 = mockProductComponent(5L);
    Entity product6 = mockProductComponent(6L);

    EntityTreeNode node3 =
        mockOperationComponent(
            "3.", newArrayList(product6), newArrayList(product3, product4, product5));
    EntityTreeNode node2 =
        mockOperationComponent(
            "2.", newArrayList(product3, product4), newArrayList(product2), newArrayList(node3));
    EntityTreeNode node1 =
        mockOperationComponent(
            "1.", newArrayList(product2), newArrayList(product1), newArrayList(node2));
    given(tree.getRoot()).willReturn(node1);

    // when
    resultMap = technologyTreeValidationService.checkConsumingManyProductsFromOneSubOp(tree);

    // then
    assertNotNull(resultMap);
    assertFalse(resultMap.isEmpty());
    assertEquals(1, resultMap.size());
    hasNodeNumbersFor(node2, node3);
  }
  @Test
  public final void shouldReturnNotEmptyMapIfManyParentOpConsumesManyOutputsFromOneSubOp() {
    // given
    Entity product1 = mockProductComponent(1L);
    Entity product2 = mockProductComponent(2L);
    Entity product3 = mockProductComponent(3L);
    Entity product4 = mockProductComponent(4L);
    Entity product5 = mockProductComponent(5L);
    Entity product6 = mockProductComponent(6L);
    Entity product7 = mockProductComponent(7L);
    Entity product8 = mockProductComponent(8L);
    Entity product9 = mockProductComponent(9L);
    Entity product10 = mockProductComponent(10L);
    Entity product11 = mockProductComponent(11L);
    Entity product12 = mockProductComponent(12L);

    EntityTreeNode node1A3 =
        mockOperationComponent(
            "1.A.3.", newArrayList(product11, product12), newArrayList(product10));
    EntityTreeNode node1A2 =
        mockOperationComponent(
            "1.A.2.",
            newArrayList(product10),
            newArrayList(product7, product8, product9),
            newArrayList(node1A3));
    EntityTreeNode node1A1 =
        mockOperationComponent(
            "1.A.1.",
            newArrayList(product7, product8, product9),
            newArrayList(product2, product3),
            newArrayList(node1A2));
    EntityTreeNode node1B1 =
        mockOperationComponent("1.B.1.", newArrayList(product6), newArrayList(product4, product5));
    EntityTreeNode node1 =
        mockOperationComponent(
            "1.",
            newArrayList(product2, product3, product4, product5),
            newArrayList(product1),
            newArrayList(node1A1, node1B1));

    given(tree.getRoot()).willReturn(node1);

    // when
    resultMap = technologyTreeValidationService.checkConsumingManyProductsFromOneSubOp(tree);

    // then
    assertNotNull(resultMap);
    assertFalse(resultMap.isEmpty());
    assertEquals(2, resultMap.size());
    assertEquals(2, resultMap.get(node1.getStringField(NODE_NUMBER)).size());
    hasNodeNumbersFor(node1, node1A1);
    hasNodeNumbersFor(node1, node1B1);
    hasNodeNumbersFor(node1A1, node1A2);
  }