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 shouldReturnEmptyMapForEmptyTree() {
    // given
    given(tree.isEmpty()).willReturn(true);

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

    // then
    assertNotNull(resultMap);
    assertTrue(resultMap.isEmpty());
  }
  @Before
  public final void init() {
    MockitoAnnotations.initMocks(this);
    technologyTreeValidationService = new TechnologyTreeValidationServiceImpl();
    given(tree.isEmpty()).willReturn(false);
    resultMap = null;

    ReflectionTestUtils.setField(
        technologyTreeValidationService, "dataDefinitionService", dataDefinitionService);

    given(dataDefinitionService.get("basic", "product")).willReturn(dataDefinition);
  }