Search in sources :

Example 1 with TechnologyId

use of com.qcadoo.mes.technologies.domain.TechnologyId in project mes by qcadoo.

the class TechnologyCustomizerTest method shouldCreateCustomizedTechnologyWithMainProduct.

@Test
public final void shouldCreateCustomizedTechnologyWithMainProduct() {
    // given
    Entity technologyCopy = mockTechnology(2L, true, null);
    Entity technology = mockTechnology(1L, true, technologyCopy);
    stubIsValid(technology, true);
    Entity nodeProduct = mockProduct(ProductFamilyElementType.PRODUCTS_FAMILY);
    Entity node = mockNodeEntity(technology, TechnologyStructureNodeType.COMPONENT, null, nodeProduct);
    stubIsValid(node, true);
    stubNodeSearchResult(node);
    Entity mainOpoc = mockEntity();
    stubIsValid(mainOpoc, true);
    String generatedTechNumber = "generatedTechNumber";
    String generatedTechName = "generated tech name";
    stubTechNameAndNumberGenerator(mainProduct, generatedTechNumber, generatedTechName);
    // when
    Optional<Either<String, TechnologyId>> result = technologyCustomizer.customize(NODE_ID, mainProduct, generatorSettings, false);
    // then
    assertTrue(result.isPresent());
    assertTrue(result.get().isRight());
    assertEquals((long) result.get().getRight().get(), 2L);
    verify(technologyOperationProductsCustomizer).customize(new TechnologyId(technologyCopy.getId()), mainProduct, mainProduct, generatorSettings);
    verify(technologyOperationProductsCustomizer, never()).prepareMainTechnologyProduct(anyEntity(), anyEntity());
    verify(technologyNameAndNumberGenerator).generateName(mainProduct);
    verify(technologyNameAndNumberGenerator).generateNumber(mainProduct);
    verify(technologyCopy).setField(TechnologyFields.NUMBER, generatedTechNumber);
    verify(technologyCopy).setField(TechnologyFields.NAME, generatedTechName);
    verify(node).setField(GeneratorTreeNodeFields.PRODUCT_TECHNOLOGY, 2L);
    verify(productCustomizer, never()).findOrCreate(anyEntity(), anyEntity(), any(ProductSuffixes.class), any(GeneratorSettings.class));
}
Also used : QcadooModelMatchers.anyEntity(com.qcadoo.testing.model.QcadooModelMatchers.anyEntity) Entity(com.qcadoo.model.api.Entity) ProductSuffixes(com.qcadoo.mes.technologiesGenerator.customization.product.domain.ProductSuffixes) TechnologyId(com.qcadoo.mes.technologies.domain.TechnologyId) Either(com.qcadoo.commons.functional.Either) GeneratorSettings(com.qcadoo.mes.technologiesGenerator.GeneratorSettings) Test(org.junit.Test)

Example 2 with TechnologyId

use of com.qcadoo.mes.technologies.domain.TechnologyId in project mes by qcadoo.

the class TechnologyCustomizerTest method shouldCreateCustomizedTechnologyWithCopiedAndCustomizedProduct.

@Test
public final void shouldCreateCustomizedTechnologyWithCopiedAndCustomizedProduct() {
    // given
    Entity technologyCopy = mockTechnology(2L, true, null);
    Entity technology = mockTechnology(1L, true, technologyCopy);
    stubIsValid(technology, true);
    Entity nodeProduct = mockProduct(ProductFamilyElementType.PRODUCTS_FAMILY);
    Entity node = mockNodeEntity(technology, TechnologyStructureNodeType.COMPONENT, mockEntity(), nodeProduct);
    stubIsValid(node, true);
    stubNodeSearchResult(node);
    Entity mainOpoc = mockEntity();
    stubIsValid(mainOpoc, true);
    Entity customizedProduct = mockEntity();
    stubIsValid(customizedProduct, true);
    stubProductCustomizer(customizedProduct);
    String generatedTechNumber = "generatedTechNumber";
    String generatedTechName = "generated tech name";
    stubTechNameAndNumberGenerator(customizedProduct, generatedTechNumber, generatedTechName);
    // when
    Optional<Either<String, TechnologyId>> result = technologyCustomizer.customize(NODE_ID, mainProduct, generatorSettings, false);
    // then
    assertTrue(result.isPresent());
    assertTrue(result.get().isRight());
    assertEquals((long) result.get().getRight().get(), 2L);
    verify(technologyOperationProductsCustomizer).customize(new TechnologyId(technologyCopy.getId()), mainProduct, customizedProduct, generatorSettings);
    verify(technologyOperationProductsCustomizer, never()).prepareMainTechnologyProduct(anyEntity(), anyEntity());
    verify(technologyNameAndNumberGenerator).generateName(customizedProduct);
    verify(technologyNameAndNumberGenerator).generateNumber(customizedProduct);
    verify(technologyCopy).setField(TechnologyFields.NUMBER, generatedTechNumber);
    verify(technologyCopy).setField(TechnologyFields.NAME, generatedTechName);
    verify(node).setField(GeneratorTreeNodeFields.PRODUCT_TECHNOLOGY, 2L);
    verify(productCustomizer).findOrCreate(anyEntity(), anyEntity(), eq(new ProductSuffixes(new ProductNumberSuffix(MAIN_PROD_NUMBER), new ProductNameSuffix(MAIN_PROD_NAME))), any(GeneratorSettings.class));
}
Also used : QcadooModelMatchers.anyEntity(com.qcadoo.testing.model.QcadooModelMatchers.anyEntity) Entity(com.qcadoo.model.api.Entity) ProductSuffixes(com.qcadoo.mes.technologiesGenerator.customization.product.domain.ProductSuffixes) TechnologyId(com.qcadoo.mes.technologies.domain.TechnologyId) ProductNameSuffix(com.qcadoo.mes.technologiesGenerator.customization.product.domain.ProductNameSuffix) Either(com.qcadoo.commons.functional.Either) ProductNumberSuffix(com.qcadoo.mes.technologiesGenerator.customization.product.domain.ProductNumberSuffix) GeneratorSettings(com.qcadoo.mes.technologiesGenerator.GeneratorSettings) Test(org.junit.Test)

Example 3 with TechnologyId

use of com.qcadoo.mes.technologies.domain.TechnologyId in project mes by qcadoo.

the class TechnologyCustomizerTest method shouldCreateCustomizedTechnologyWithMainProductEvenIfTechnologyOutputProductIsNotAProductsFamily.

@Test
public final void shouldCreateCustomizedTechnologyWithMainProductEvenIfTechnologyOutputProductIsNotAProductsFamily() {
    // given
    Entity technologyCopy = mockTechnology(2L, true, null);
    Entity technology = mockTechnology(1L, true, technologyCopy);
    stubIsValid(technology, true);
    Entity nodeProduct = mockProduct(ProductFamilyElementType.PARTICULAR_PRODUCT);
    Entity node = mockNodeEntity(technology, TechnologyStructureNodeType.COMPONENT, null, nodeProduct);
    stubIsValid(node, true);
    stubNodeSearchResult(node);
    Entity mainOpoc = mockEntity();
    stubIsValid(mainOpoc, true);
    String generatedTechNumber = "generatedTechNumber";
    String generatedTechName = "generated tech name";
    stubTechNameAndNumberGenerator(mainProduct, generatedTechNumber, generatedTechName);
    // when
    Optional<Either<String, TechnologyId>> result = technologyCustomizer.customize(NODE_ID, mainProduct, generatorSettings, false);
    // then
    assertTrue(result.isPresent());
    assertTrue(result.get().isRight());
    assertEquals((long) result.get().getRight().get(), 2L);
    verify(technologyOperationProductsCustomizer).customize(new TechnologyId(technologyCopy.getId()), mainProduct, mainProduct, generatorSettings);
    verify(technologyOperationProductsCustomizer, never()).prepareMainTechnologyProduct(anyEntity(), anyEntity());
    verify(technologyNameAndNumberGenerator).generateName(mainProduct);
    verify(technologyNameAndNumberGenerator).generateNumber(mainProduct);
    verify(technologyCopy).setField(TechnologyFields.NUMBER, generatedTechNumber);
    verify(technologyCopy).setField(TechnologyFields.NAME, generatedTechName);
    verify(node).setField(GeneratorTreeNodeFields.PRODUCT_TECHNOLOGY, 2L);
    verify(productCustomizer, never()).findOrCreate(anyEntity(), anyEntity(), any(ProductSuffixes.class), any(GeneratorSettings.class));
}
Also used : QcadooModelMatchers.anyEntity(com.qcadoo.testing.model.QcadooModelMatchers.anyEntity) Entity(com.qcadoo.model.api.Entity) ProductSuffixes(com.qcadoo.mes.technologiesGenerator.customization.product.domain.ProductSuffixes) TechnologyId(com.qcadoo.mes.technologies.domain.TechnologyId) Either(com.qcadoo.commons.functional.Either) GeneratorSettings(com.qcadoo.mes.technologiesGenerator.GeneratorSettings) Test(org.junit.Test)

Example 4 with TechnologyId

use of com.qcadoo.mes.technologies.domain.TechnologyId in project mes by qcadoo.

the class TechnologyCustomizerTest method shouldCreateCustomizedTechnologyWithAlteredMainOutputProduct2.

@Test
public final void shouldCreateCustomizedTechnologyWithAlteredMainOutputProduct2() {
    // given
    given(generatorSettings.shouldCreateAndSwitchProducts()).willReturn(false);
    Entity technologyCopy = mockTechnology(2L, true, null);
    Entity technology = mockTechnology(1L, true, technologyCopy);
    stubIsValid(technology, true);
    Entity nodeProduct = mockProduct(ProductFamilyElementType.PARTICULAR_PRODUCT);
    stubIsValid(nodeProduct, true);
    Entity node = mockNodeEntity(technology, TechnologyStructureNodeType.COMPONENT, null, nodeProduct);
    stubIsValid(node, true);
    stubNodeSearchResult(node);
    String generatedTechNumber = "generatedTechNumber";
    String generatedTechName = "generated tech name";
    stubTechNameAndNumberGenerator(mainProduct, generatedTechNumber, generatedTechName);
    // when
    Optional<Either<String, TechnologyId>> result = technologyCustomizer.customize(NODE_ID, mainProduct, generatorSettings, false);
    // then
    assertTrue(result.isPresent());
    assertTrue(result.get().isRight());
    assertEquals((long) result.get().getRight().get(), 2L);
    verify(technologyOperationProductsCustomizer, never()).customize(any(TechnologyId.class), anyEntity(), anyEntity(), any(GeneratorSettings.class));
    verify(technologyOperationProductsCustomizer).prepareMainTechnologyProduct(technologyCopy, mainProduct);
    verify(technologyNameAndNumberGenerator).generateName(mainProduct);
    verify(technologyNameAndNumberGenerator).generateNumber(mainProduct);
    verify(technologyCopy).setField(TechnologyFields.NUMBER, generatedTechNumber);
    verify(technologyCopy).setField(TechnologyFields.NAME, generatedTechName);
    verify(node).setField(GeneratorTreeNodeFields.PRODUCT_TECHNOLOGY, 2L);
    verify(productCustomizer, never()).findOrCreate(anyEntity(), anyEntity(), any(ProductSuffixes.class), any(GeneratorSettings.class));
}
Also used : QcadooModelMatchers.anyEntity(com.qcadoo.testing.model.QcadooModelMatchers.anyEntity) Entity(com.qcadoo.model.api.Entity) ProductSuffixes(com.qcadoo.mes.technologiesGenerator.customization.product.domain.ProductSuffixes) TechnologyId(com.qcadoo.mes.technologies.domain.TechnologyId) Either(com.qcadoo.commons.functional.Either) GeneratorSettings(com.qcadoo.mes.technologiesGenerator.GeneratorSettings) Test(org.junit.Test)

Example 5 with TechnologyId

use of com.qcadoo.mes.technologies.domain.TechnologyId in project mes by qcadoo.

the class TechnologyCustomizerTest method shouldCreateCustomizedTechnologyWithoutAlteringMainOutputProduct.

@Test
public final void shouldCreateCustomizedTechnologyWithoutAlteringMainOutputProduct() {
    // given
    given(generatorSettings.shouldCreateAndSwitchProducts()).willReturn(true);
    Entity technologyCopy = mockTechnology(2L, true, null);
    Entity technology = mockTechnology(1L, true, technologyCopy);
    stubIsValid(technology, true);
    Entity nodeProduct = mockProduct(ProductFamilyElementType.PARTICULAR_PRODUCT);
    stubIsValid(nodeProduct, true);
    Entity node = mockNodeEntity(technology, TechnologyStructureNodeType.COMPONENT, mockEntity(), nodeProduct);
    stubBelongsToField(node, GeneratorTreeNodeFields.PRODUCT, nodeProduct);
    stubIsValid(node, true);
    stubNodeSearchResult(node);
    String generatedTechNumber = "generatedTechNumber";
    String generatedTechName = "generated tech name";
    stubTechNameAndNumberGenerator(nodeProduct, generatedTechNumber, generatedTechName);
    // when
    Optional<Either<String, TechnologyId>> result = technologyCustomizer.customize(NODE_ID, mainProduct, generatorSettings, false);
    // then
    assertTrue(result.isPresent());
    assertTrue(result.get().isRight());
    assertEquals((long) result.get().getRight().get(), 2L);
    verify(technologyOperationProductsCustomizer).customize(new TechnologyId(technologyCopy.getId()), mainProduct, nodeProduct, generatorSettings);
    verify(technologyOperationProductsCustomizer, never()).prepareMainTechnologyProduct(anyEntity(), anyEntity());
    verify(technologyNameAndNumberGenerator).generateName(nodeProduct);
    verify(technologyNameAndNumberGenerator).generateNumber(nodeProduct);
    verify(technologyCopy).setField(TechnologyFields.NUMBER, generatedTechNumber);
    verify(technologyCopy).setField(TechnologyFields.NAME, generatedTechName);
    verify(node).setField(GeneratorTreeNodeFields.PRODUCT_TECHNOLOGY, 2L);
    verify(productCustomizer, never()).findOrCreate(anyEntity(), anyEntity(), any(ProductSuffixes.class), any(GeneratorSettings.class));
}
Also used : QcadooModelMatchers.anyEntity(com.qcadoo.testing.model.QcadooModelMatchers.anyEntity) Entity(com.qcadoo.model.api.Entity) ProductSuffixes(com.qcadoo.mes.technologiesGenerator.customization.product.domain.ProductSuffixes) TechnologyId(com.qcadoo.mes.technologies.domain.TechnologyId) Either(com.qcadoo.commons.functional.Either) GeneratorSettings(com.qcadoo.mes.technologiesGenerator.GeneratorSettings) Test(org.junit.Test)

Aggregations

TechnologyId (com.qcadoo.mes.technologies.domain.TechnologyId)19 Entity (com.qcadoo.model.api.Entity)18 QcadooModelMatchers.anyEntity (com.qcadoo.testing.model.QcadooModelMatchers.anyEntity)12 Test (org.junit.Test)12 Either (com.qcadoo.commons.functional.Either)10 GeneratorSettings (com.qcadoo.mes.technologiesGenerator.GeneratorSettings)9 ProductSuffixes (com.qcadoo.mes.technologiesGenerator.customization.product.domain.ProductSuffixes)8 Optional (java.util.Optional)4 OperationId (com.qcadoo.mes.technologies.domain.OperationId)3 SizeGroupId (com.qcadoo.mes.technologies.domain.SizeGroupId)3 TechnologyInputProductTypeId (com.qcadoo.mes.technologies.domain.TechnologyInputProductTypeId)3 TechnologyOperationId (com.qcadoo.mes.technologies.tree.domain.TechnologyOperationId)3 GeneratorContextFields (com.qcadoo.mes.technologiesGenerator.constants.GeneratorContextFields)3 GeneratorTreeNodeFields (com.qcadoo.mes.technologiesGenerator.constants.GeneratorTreeNodeFields)3 TechnologiesGeneratorConstants (com.qcadoo.mes.technologiesGenerator.constants.TechnologiesGeneratorConstants)3 ContextId (com.qcadoo.mes.technologiesGenerator.domain.ContextId)3 DataDefinition (com.qcadoo.model.api.DataDefinition)3 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)3 List (java.util.List)3 Logger (org.slf4j.Logger)3