diff options
author | priyanshu <pagarwal@amdocs.com> | 2018-09-05 18:05:36 +0530 |
---|---|---|
committer | Avi Gaffa <avi.gaffa@amdocs.com> | 2018-09-13 13:00:27 +0000 |
commit | b65c8eeb334a2c579a2dc0241f480d81e9309f9c (patch) | |
tree | b3b3ed06b53703f771da51bec4b40e71b9e1bd1d /catalog-be/src/test/java | |
parent | f1e032cf4ae3505eb8acbce56ac978649d6f63d4 (diff) |
Interface operation support for service - BE
1. Interface operation support for service
2. Refactored common code of operationspa
3. ONAP Bug fixes VF operations
Change-Id: If1c4fd5f17626dbe568ee66ad997eb8ffb772e29
Issue-ID: SDC-1739
Signed-off-by: priyanshu <pagarwal@amdocs.com>
Diffstat (limited to 'catalog-be/src/test/java')
5 files changed, 300 insertions, 135 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java index eb17d56154..e8a698fec1 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java @@ -40,7 +40,6 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.openecomp.sdc.ElementOperationMock; import org.openecomp.sdc.be.auditing.impl.AuditingManager; -import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic; import org.openecomp.sdc.be.components.validation.InterfaceOperationValidation; import org.openecomp.sdc.be.components.validation.UserValidations; import org.openecomp.sdc.be.config.ConfigurationManager; @@ -56,7 +55,6 @@ import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.impl.WebAppContextWrapper; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.DataTypeDefinition; -import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.LifecycleStateEnum; import org.openecomp.sdc.be.model.Operation; import org.openecomp.sdc.be.model.Resource; @@ -83,42 +81,37 @@ import org.springframework.web.context.WebApplicationContext; public class InterfaceOperationBusinessLogicTest { - public static final String RESOURCE_CATEGORY1 = "Network Layer 2-3"; - public static final String RESOURCE_SUBCATEGORY = "Router"; - - private String resourceId = "resourceId1"; - private String operationId = "uniqueId1"; - Resource resourceUpdate; - Operation operation; - - public static final String RESOURCE_NAME = "My-Resource_Name with space"; - - final ServletContext servletContext = Mockito.mock(ServletContext.class); - IElementOperation mockElementDao; - TitanDao mockTitanDao = Mockito.mock(TitanDao.class); - UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class); - ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class); - NodeTypeOperation nodeTypeOperation = Mockito.mock(NodeTypeOperation.class); - NodeTemplateOperation nodeTemplateOperation = Mockito.mock(NodeTemplateOperation.class); - TopologyTemplateOperation topologyTemplateOperation = Mockito.mock(TopologyTemplateOperation.class); - final IPropertyOperation propertyOperation = Mockito.mock(IPropertyOperation.class); - final ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class); - WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class); - UserValidations userValidations = Mockito.mock(UserValidations.class); - WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class); - ArtifactCassandraDao artifactCassandraDao = Mockito.mock(ArtifactCassandraDao.class); - InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class); - InterfaceOperationValidation operationValidator = Mockito.mock(InterfaceOperationValidation.class); - - ResponseFormatManager responseManager = null; - GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class); - User user = null; - Resource resourceResponse = null; - ComponentsUtils componentsUtils; - ArtifactsBusinessLogic artifactManager = new ArtifactsBusinessLogic(); - private GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class); + private static final String RESOURCE_CATEGORY1 = "Network Layer 2-3"; + private static final String RESOURCE_SUBCATEGORY = "Router"; + + private final String resourceId = "resourceId1"; + private final String operationId = "uniqueId1"; + private Operation operation; + + private static final String RESOURCE_NAME = "My-Resource_Name with space"; + + private final ServletContext servletContext = Mockito.mock(ServletContext.class); + private final TitanDao mockTitanDao = Mockito.mock(TitanDao.class); + private final UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class); + private final ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class); + private final NodeTypeOperation nodeTypeOperation = Mockito.mock(NodeTypeOperation.class); + private final NodeTemplateOperation nodeTemplateOperation = Mockito.mock(NodeTemplateOperation.class); + private final TopologyTemplateOperation topologyTemplateOperation = Mockito.mock(TopologyTemplateOperation.class); + private final IPropertyOperation propertyOperation = Mockito.mock(IPropertyOperation.class); + private final ApplicationDataTypeCache applicationDataTypeCache = Mockito.mock(ApplicationDataTypeCache.class); + private final WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class); + private final UserValidations userValidations = Mockito.mock(UserValidations.class); + private final WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class); + private final ArtifactCassandraDao artifactCassandraDao = Mockito.mock(ArtifactCassandraDao.class); + private final InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class); + private final InterfaceOperationValidation operationValidator = Mockito.mock(InterfaceOperationValidation.class); + + private final GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class); + private User user = null; + private final ArtifactsBusinessLogic artifactManager = new ArtifactsBusinessLogic(); @InjectMocks + private InterfaceOperationBusinessLogic bl = new InterfaceOperationBusinessLogic(); @Before @@ -132,10 +125,10 @@ public class InterfaceOperationBusinessLogicTest { String appConfigDir = "src/test/resources/config/catalog-be"; ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir); ConfigurationManager configurationManager = new ConfigurationManager(configurationSource); - componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class)); + ComponentsUtils componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class)); // Elements - mockElementDao = new ElementOperationMock(); + IElementOperation mockElementDao = new ElementOperationMock(); // User data and management user = new User(); @@ -172,23 +165,22 @@ public class InterfaceOperationBusinessLogicTest { when(graphLockOperation.lockComponentByName(Mockito.anyString(), eq(NodeTypeEnum.Resource))).thenReturn(StorageOperationStatus.OK); // createResource - resourceResponse = createResourceObject(true); + Resource resourceResponse = createResourceObject(true); Either<Resource, StorageOperationStatus> eitherCreate = Either.left(resourceResponse); - Either<Integer, StorageOperationStatus> eitherValidate = Either.left(null); when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(eitherCreate); //TODO Remove if passes /*when(toscaOperationFacade.validateCsarUuidUniqueness(Mockito.anyString())).thenReturn(eitherValidate);*/ - Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<String, DataTypeDefinition>(); + Map<String, DataTypeDefinition> emptyDataTypes = new HashMap<>(); when(applicationDataTypeCache.getAll()).thenReturn(Either.left(emptyDataTypes)); //InterfaceOperation when(operationValidator.validateInterfaceOperations(anyCollection(), anyObject(), anyBoolean())).thenReturn(Either.left(true)); when(interfaceOperation.addInterface(anyString(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME))); when(interfaceOperation.updateInterface(anyString(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME))); - when(interfaceOperation.addInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME))); - when(interfaceOperation.updateInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME))); - when(interfaceOperation.deleteInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME))); - when(interfaceOperation.deleteInterfaceOperation(any(),any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn(RESOURCE_NAME))); + when(interfaceOperation.addInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn())); + when(interfaceOperation.updateInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn())); + when(interfaceOperation.deleteInterfaceOperation(anyObject(), anyObject(), anyObject())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn())); + when(interfaceOperation.deleteInterfaceOperation(any(),any(), any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockOperationToReturn())); when(interfaceOperation.updateInterface(any(),any())).thenReturn(Either.left(InterfaceOperationTestUtils.mockInterfaceDefinitionToReturn(RESOURCE_NAME))); when(mockTitanDao.commit()).thenReturn(TitanOperationStatus.OK); @@ -210,7 +202,6 @@ public class InterfaceOperationBusinessLogicTest { setCanWorkOnResource(resourceCsar); Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resourceCsar); when(toscaOperationFacade.getToscaFullElement(resourceCsar.getUniqueId())).thenReturn(oldResourceRes); - responseManager = ResponseFormatManager.getInstance(); } @Test @@ -260,37 +251,13 @@ public class InterfaceOperationBusinessLogicTest { private void validateUserRoles(Role... roles) { List<Role> listOfRoles = Stream.of(roles).collect(Collectors.toList()); - } + } - private Resource setCanWorkOnResource(Resource resource) { + private void setCanWorkOnResource(Resource resource) { resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); resource.setLastUpdaterUserId(user.getUserId()); - return resource; - } - - private Resource setUpResourceMock(){ - Resource resource = new Resource(); - resource.setUniqueId(resourceId); - resource.setName(RESOURCE_NAME); - resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY); - resource.setDescription("My short description"); - resource.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinition(RESOURCE_NAME)); - - List<InputDefinition> inputDefinitionList = new ArrayList<>(); - inputDefinitionList.add(createInputDefinition("uniqueId1")); - resource.setInputs(inputDefinitionList); - - return resource; } - private InputDefinition createInputDefinition(String inputId) { - InputDefinition inputDefinition = new InputDefinition(); - inputDefinition.setInputId(inputId); - inputDefinition.setDescription("Input Description"); - - return inputDefinition; - - } private Resource createResourceForInterfaceOperation() { Resource resource = new Resource(); resource.setUniqueId(resourceId); @@ -306,11 +273,11 @@ public class InterfaceOperationBusinessLogicTest { resource.setName(RESOURCE_NAME); resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY); resource.setDescription("My short description"); - List<String> tgs = new ArrayList<String>(); + List<String> tgs = new ArrayList<>(); tgs.add("test"); tgs.add(resource.getName()); resource.setTags(tgs); - List<String> template = new ArrayList<String>(); + List<String> template = new ArrayList<>(); template.add("Root"); resource.setDerivedFrom(template); resource.setVendorName("Motorola"); @@ -324,7 +291,6 @@ public class InterfaceOperationBusinessLogicTest { if (afterCreate) { resource.setName(resource.getName()); resource.setVersion("0.1"); - resource.setUniqueId(resource.getName().toLowerCase() + ":" + resource.getVersion()); resource.setCreatorUserId(user.getUserId()); resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName()); @@ -338,11 +304,11 @@ public class InterfaceOperationBusinessLogicTest { resource.setName(RESOURCE_NAME); resource.addCategory(RESOURCE_CATEGORY1, RESOURCE_SUBCATEGORY); resource.setDescription("My short description"); - List<String> tgs = new ArrayList<String>(); + List<String> tgs = new ArrayList<>(); tgs.add("test"); tgs.add(resource.getName()); resource.setTags(tgs); - List<String> template = new ArrayList<String>(); + List<String> template = new ArrayList<>(); template.add("Root"); resource.setDerivedFrom(template); resource.setVendorName("Motorola"); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java index d41294b4c2..6fe2f1308c 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidationTest.java @@ -21,8 +21,11 @@ import static org.mockito.Mockito.when; import com.google.common.collect.Sets; import fj.data.Either; + +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; import org.junit.Assert; @@ -35,20 +38,23 @@ import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition; import org.openecomp.sdc.be.model.ArtifactDefinition; +import org.openecomp.sdc.be.model.ComponentInstanceInput; +import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Operation; +import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.exception.ResponseFormat; import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils; public class InterfaceOperationValidationTest { - private Resource resource = setUpResourceMock(); - ResponseFormatManager responseFormatManagerMock; + private final Component component = setUpComponentMock(); + private ResponseFormatManager responseFormatManagerMock; - InterfaceOperationValidationUtilTest interfaceOperationValidationUtilTest = new InterfaceOperationValidationUtilTest(); - ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>(); - ListDataDefinition<OperationOutputDefinition> operationOutputDefinitionList = new ListDataDefinition<>(); + private final InterfaceOperationValidationUtilTest interfaceOperationValidationUtilTest = new InterfaceOperationValidationUtilTest(); + private final ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>(); + private final ListDataDefinition<OperationOutputDefinition> operationOutputDefinitionList = new ListDataDefinition<>(); @Before public void init() { @@ -67,7 +73,7 @@ public class InterfaceOperationValidationTest { "interface operation2",new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"upgrade"); Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest - .validateInterfaceOperations(operations, resource, false); + .validateInterfaceOperations(operations, component, false); Assert.assertTrue(booleanResponseFormatEither.isLeft()); } @@ -78,10 +84,10 @@ public class InterfaceOperationValidationTest { Collection<Operation> operations = createInterfaceOperationData("op2", "interface operation2 - The Spring Initializer provides a project generator to make you " + "productive with the certain technology stack from the beginning. You can create a skeleton project" + - "with web, data access (relational and NoSQL datastores), cloud, or messaging support", + "with web, data access (relational and NoSQL data stores), cloud, or messaging support", new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"update"); Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest - .validateInterfaceOperations(operations, resource, false); + .validateInterfaceOperations(operations, component, false); Assert.assertTrue(booleanResponseFormatEither.isRight()); } @@ -95,7 +101,7 @@ public class InterfaceOperationValidationTest { "interface operation2",new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList, ""); Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest - .validateInterfaceOperations(operations, resource, false); + .validateInterfaceOperations(operations, component, false); Assert.assertTrue(booleanResponseFormatEither.isRight()); } @@ -107,7 +113,7 @@ public class InterfaceOperationValidationTest { "interface operation2",new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"input2"); Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest - .validateInterfaceOperations(operations, resource, false); + .validateInterfaceOperations(operations, component, false); Assert.assertTrue(booleanResponseFormatEither.isRight()); } @@ -119,7 +125,7 @@ public class InterfaceOperationValidationTest { "interface operation2",new ArtifactDefinition(), operationInputDefinitionList, operationOutputDefinitionList,"CREATE"); Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest - .validateInterfaceOperations(operations, resource, false); + .validateInterfaceOperations(operations, component, false); Assert.assertTrue(booleanResponseFormatEither.isRight()); } @@ -132,9 +138,9 @@ public class InterfaceOperationValidationTest { operationOutputDefinitionList, "interface operation2 - The Spring Initializer provides a project generator to make you " + "productive with the certain technology stack from the beginning. You can create a skeleton project" + - "with web, data access (relational and NoSQL datastores), cloud, or messaging support"); + "with web, data access (relational and NoSQL data stores), cloud, or messaging support"); Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest - .validateInterfaceOperations(operations, resource, false); + .validateInterfaceOperations(operations, component, false); Assert.assertTrue(booleanResponseFormatEither.isRight()); } @@ -151,7 +157,7 @@ public class InterfaceOperationValidationTest { operationOutputDefinitionList,"create"); Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest - .validateInterfaceOperations(operations, resource, false); + .validateInterfaceOperations(operations, component, false); Assert.assertTrue(booleanResponseFormatEither.isRight()); } @@ -166,12 +172,12 @@ public class InterfaceOperationValidationTest { Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest - .validateInterfaceOperations(operations, resource, false); + .validateInterfaceOperations(operations, component, false); Assert.assertTrue(booleanResponseFormatEither.isLeft()); } @Test - public void testInterfaceOperationeInputParamNameEmpty() { + public void testInterfaceOperationInputParamNameEmpty() { operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition(" ")); operationInputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationInputDefinition("label1")); operationOutputDefinitionList.add(InterfaceOperationTestUtils.createMockOperationOutputDefinition("label1")); @@ -181,7 +187,7 @@ public class InterfaceOperationValidationTest { Either<Boolean, ResponseFormat> booleanResponseFormatEither = interfaceOperationValidationUtilTest - .validateInterfaceOperations(operations, resource, false); + .validateInterfaceOperations(operations, component, false); Assert.assertTrue(booleanResponseFormatEither.isRight()); } @@ -191,10 +197,33 @@ public class InterfaceOperationValidationTest { return Sets.newHashSet(InterfaceOperationTestUtils.createInterfaceOperation(uniqueID, description, artifactDefinition, inputs, outputs, name)); } - private Resource setUpResourceMock(){ - Resource resource = new Resource(); - resource.setInterfaces(createMockInterfaceDefinition()); - return resource; + private Component setUpComponentMock(){ + Component component = new Resource(); + + List<InputDefinition> inputs = new ArrayList<>(); + InputDefinition inputDefinition = new InputDefinition(); + InputDefinition inputDefinition1 = new InputDefinition(); + + List<ComponentInstanceInput> componentInstanceInputs = new ArrayList<>(); + ComponentInstanceInput componentInstanceInput1 = new ComponentInstanceInput(); + componentInstanceInput1.setComponentInstanceName("componentInstance1"); + componentInstanceInput1.setUniqueId("inputId1"); + ComponentInstanceInput componentInstanceInput2 = new ComponentInstanceInput(); + componentInstanceInput2.setComponentInstanceName("componentInstance2"); + componentInstanceInput2.setUniqueId("inputId2"); + + componentInstanceInputs.add(componentInstanceInput1); + componentInstanceInputs.add(componentInstanceInput2); + + inputDefinition.setUniqueId("inputId1"); + inputDefinition.setInputs(componentInstanceInputs); + inputDefinition1.setUniqueId("uniqueId3"); + + inputs.add(inputDefinition); + inputs.add(inputDefinition1); + component.setInputs(inputs); + component.setInterfaces(createMockInterfaceDefinition()); + return component; } private Map<String, InterfaceDefinition> createMockInterfaceDefinition() { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java index b158ddf5da..0c02e71bd2 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverterTest.java @@ -1,38 +1,104 @@ package org.openecomp.sdc.be.datamodel.utils; -import static org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields.IO_INPUT_PARAMETERS; - -import java.util.LinkedList; - +import org.junit.Assert; import org.junit.Test; import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationParamDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition; import org.openecomp.sdc.be.model.Operation; +import static org.openecomp.sdc.test.utils.InterfaceOperationTestUtils.createMockOperationInputDefinition; +import static org.openecomp.sdc.test.utils.InterfaceOperationTestUtils.createMockOperationOutputDefinition; + public class InterfaceUIDataConverterTest { @Test - public void testConvertInterfaceDataToOperationData() throws Exception { - InterfaceOperationDataDefinition interfaceOperation = new InterfaceOperationDataDefinition(); + public void testConvertInterfaceDataToOperationData() { + InterfaceOperationDataDefinition interfaceOperation = createIODD("test", + "test description", + createParamDataList("inpName", "property", true, "String"), + createParamDataList("OutName", null, true, "String"), + "workflowId", + "workflowVersionId"); + Operation result; + result = InterfaceUIDataConverter.convertInterfaceDataToOperationData(interfaceOperation); + Assert.assertNotNull(result); + } + + @Test + public void testConvertInterfaceDataToOperationDataWithoutMandatory() { + ListDataDefinition<InterfaceOperationParamDataDefinition> iopd = new ListDataDefinition<>(); + iopd.add(createParamData("test", "property", "String")); + InterfaceOperationDataDefinition interfaceOperation = createIODD("test", + "test description", iopd, iopd, + "workflowId", + "workflowVersionId"); Operation result; + result = InterfaceUIDataConverter.convertInterfaceDataToOperationData(interfaceOperation); + Assert.assertNotNull(result); + } - // default test + @Test + public void testConvertInterfaceDataToOperationDataWithoutOptionalFields() { + InterfaceOperationDataDefinition interfaceOperation = new InterfaceOperationDataDefinition(); + interfaceOperation.setOperationType("operationType"); + Operation result; result = InterfaceUIDataConverter.convertInterfaceDataToOperationData(interfaceOperation); + Assert.assertNotNull(result); } @Test - public void testConvertOperationDataToInterfaceData() throws Exception { + public void testConvertOperationDataToInterfaceData() { Operation operationData = new Operation(); InterfaceOperationDataDefinition result; ListDataDefinition<OperationInputDefinition> inputs = new ListDataDefinition<>(); + inputs.add(createMockOperationInputDefinition("Inp1")); ListDataDefinition<OperationOutputDefinition> outputs = new ListDataDefinition<>(); + outputs.add(createMockOperationOutputDefinition("out1")); operationData.setInputs(inputs); operationData.setOutputs(outputs); operationData.setImplementation(new ArtifactDataDefinition()); - // default test result = InterfaceUIDataConverter.convertOperationDataToInterfaceData(operationData); + Assert.assertNotNull(result); + } + + private InterfaceOperationDataDefinition createIODD(String operationType, String description, + ListDataDefinition<InterfaceOperationParamDataDefinition> inputParams, + ListDataDefinition<InterfaceOperationParamDataDefinition> outputParams, + String workflowId, + String workflowVersionId) { + InterfaceOperationDataDefinition interfaceOperation = new InterfaceOperationDataDefinition(); + interfaceOperation.setOperationType(operationType); + interfaceOperation.setDescription(description); + interfaceOperation.setInputParams(inputParams); + interfaceOperation.setOutputParams(outputParams); + interfaceOperation.setWorkflowId(workflowId); + interfaceOperation.setWorkflowVersionId(workflowVersionId); + return interfaceOperation; + } + + private InterfaceOperationParamDataDefinition createParamData(String name, String property, boolean mandatory, String type) { + InterfaceOperationParamDataDefinition definition = createParamData(name, property, type); + definition.setMandatory(mandatory); + return definition; + } + + private InterfaceOperationParamDataDefinition createParamData(String name, String property, String type) { + InterfaceOperationParamDataDefinition definition = new InterfaceOperationParamDataDefinition(); + definition.setName(name); + definition.setProperty(property); + definition.setType(type); + return definition; } + + private ListDataDefinition<InterfaceOperationParamDataDefinition> createParamDataList(String name, + String property, boolean mandatory, String type) { + ListDataDefinition<InterfaceOperationParamDataDefinition> list = new ListDataDefinition<>(); + list.add(createParamData(name, property, mandatory, type)); + return list; + } + }
\ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java index bebfbd19d8..7a88d0a9d3 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtilTest.java @@ -16,6 +16,12 @@ package org.openecomp.sdc.be.tosca.utils; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.util.HashMap; +import java.util.Map; + import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -27,31 +33,41 @@ import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.model.Service; import org.openecomp.sdc.be.tosca.ToscaExportHandler; import org.openecomp.sdc.be.tosca.ToscaRepresentation; +import org.openecomp.sdc.be.tosca.model.ToscaLifecycleOperationDefinition; import org.openecomp.sdc.be.tosca.model.ToscaNodeType; +import org.openecomp.sdc.be.tosca.model.ToscaProperty; import org.openecomp.sdc.be.tosca.model.ToscaTemplate; - -import java.util.HashMap; -import java.util.Map; +import org.openecomp.sdc.common.util.YamlToObjectConverter; public class InterfacesOperationsToscaUtilTest { + private static final String MAPPED_PROPERTY_NAME = "mapped_property"; + private static final String INPUT_NAME_PREFIX = "input_"; + private static final String NODE_TYPE_NAME = "test"; + private String[] inputTypes = {"string", "integer", "float", "boolean"}; + private static ObjectMapper mapper; + @BeforeClass public static void setUp() { new DummyConfigurationManager(); + mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); } - @Test() - public void addInterfaceTypeElement() { + + @Test + public void addInterfaceTypeElementToResource() { Component component = new Resource(); component.setNormalizedName("normalizedComponentName"); InterfaceDefinition addedInterface = new InterfaceDefinition(); addedInterface.setToscaResourceName("interface.types.test_resource_name"); addOperationsToInterface(addedInterface, 5, 3, true); final String interfaceType = "normalizedComponentName-interface"; - ((Resource) component).setInterfaces(new HashMap<>()); - ((Resource) component).getInterfaces().put(interfaceType, addedInterface); + component.setInterfaces(new HashMap<>()); + component.getInterfaces().put(interfaceType, addedInterface); final Map<String, Object> interfaceTypeElement = InterfacesOperationsToscaUtil.addInterfaceTypeElement(component); @@ -65,7 +81,29 @@ public class InterfacesOperationsToscaUtilTest { } @Test - public void addInterfaceDefinitionElement() { + public void addInterfaceTypeElementToService() { + Component component = new Service(); + component.setNormalizedName("normalizedServiceComponentName"); + InterfaceDefinition addedInterface = new InterfaceDefinition(); + addedInterface.setToscaResourceName("interface.types.test_service_name"); + addOperationsToInterface(addedInterface, 5, 3, true); + final String interfaceType = "normalizedServiceComponentName-interface"; + component.setInterfaces(new HashMap<>()); + component.getInterfaces().put(interfaceType, addedInterface); + final Map<String, Object> interfaceTypeElement = + InterfacesOperationsToscaUtil.addInterfaceTypeElement(component); + + ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null); + ToscaTemplate template = new ToscaTemplate("testService"); + template.setInterface_types(interfaceTypeElement); + final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template); + + Assert.assertFalse(toscaRepresentation.getMainYaml().contains("operations")); + Assert.assertTrue(toscaRepresentation.getMainYaml().contains("interface.types.test_service_name")); + } + + @Test + public void addInterfaceDefinitionElementToResource() { Component component = new Resource(); component.setNormalizedName("normalizedComponentName"); InterfaceDefinition addedInterface = new InterfaceDefinition(); @@ -73,25 +111,58 @@ public class InterfacesOperationsToscaUtilTest { addOperationsToInterface(addedInterface, 3, 2, true); final String interfaceType = "normalizedComponentName-interface"; - ((Resource) component).setInterfaces(new HashMap<>()); - ((Resource) component).getInterfaces().put(interfaceType, addedInterface); + component.setInterfaces(new HashMap<>()); + component.getInterfaces().put(interfaceType, addedInterface); ToscaNodeType nodeType = new ToscaNodeType(); InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType); ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null); - ToscaTemplate template = new ToscaTemplate("test"); + ToscaTemplate template = new ToscaTemplate(NODE_TYPE_NAME); Map<String, ToscaNodeType> nodeTypes = new HashMap<>(); - nodeTypes.put("test", nodeType); + nodeTypes.put(NODE_TYPE_NAME, nodeType); template.setNode_types(nodeTypes); final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template); - Assert.assertFalse(toscaRepresentation.getMainYaml().contains("operations")); - Assert.assertTrue(toscaRepresentation.getMainYaml().contains("resourceName:")); - Assert.assertTrue(toscaRepresentation.getMainYaml().contains("inputs:")); - Assert.assertFalse(toscaRepresentation.getMainYaml().contains("defaultp")); - Assert.assertTrue(toscaRepresentation.getMainYaml().contains("has description")); - Assert.assertTrue(toscaRepresentation.getMainYaml().contains("naming_function_")); - Assert.assertTrue(toscaRepresentation.getMainYaml().contains("com.some.resource.or.other.resourceName")); + String mainYaml = toscaRepresentation.getMainYaml(); + Assert.assertFalse(mainYaml.contains("operations")); + Assert.assertTrue(mainYaml.contains("resourceName:")); + Assert.assertTrue(mainYaml.contains("inputs:")); + validateOperationInputs(mainYaml); + Assert.assertFalse(mainYaml.contains("defaultp")); + Assert.assertTrue(mainYaml.contains("has description")); + Assert.assertTrue(mainYaml.contains(MAPPED_PROPERTY_NAME)); + Assert.assertTrue(mainYaml.contains("com.some.resource.or.other.resourceName")); + } + + @Test + public void addInterfaceDefinitionElementToService() { + Component component = new Service(); + component.setNormalizedName("normalizedServiceComponentName"); + InterfaceDefinition addedInterface = new InterfaceDefinition(); + addedInterface.setToscaResourceName("com.some.service.or.other.serviceName"); + + addOperationsToInterface(addedInterface, 3, 2, true); + final String interfaceType = "normalizedServiceComponentName-interface"; + component.setInterfaces(new HashMap<>()); + component.getInterfaces().put(interfaceType, addedInterface); + ToscaNodeType nodeType = new ToscaNodeType(); + InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType); + + ToscaExportHandler handler = new ToscaExportHandler(null,null,null,null,null,null); + ToscaTemplate template = new ToscaTemplate("testService"); + Map<String, ToscaNodeType> nodeTypes = new HashMap<>(); + nodeTypes.put(NODE_TYPE_NAME, nodeType); + template.setNode_types(nodeTypes); + final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template); + String mainYaml = toscaRepresentation.getMainYaml(); + Assert.assertFalse(mainYaml.contains("operations")); + Assert.assertTrue(mainYaml.contains("serviceName:")); + Assert.assertTrue(mainYaml.contains("inputs:")); + validateOperationInputs(mainYaml); + Assert.assertFalse(mainYaml.contains("defaultp")); + Assert.assertTrue(mainYaml.contains("has description")); + Assert.assertTrue(mainYaml.contains(MAPPED_PROPERTY_NAME)); + Assert.assertTrue(mainYaml.contains("com.some.service.or.other.serviceName")); } @Test @@ -103,8 +174,8 @@ public class InterfacesOperationsToscaUtilTest { addOperationsToInterface(addedInterface, 3, 3, false); final String interfaceType = "normalizedComponentName-interface"; - ((Resource) component).setInterfaces(new HashMap<>()); - ((Resource) component).getInterfaces().put(interfaceType, addedInterface); + component.setInterfaces(new HashMap<>()); + component.getInterfaces().put(interfaceType, addedInterface); ToscaNodeType nodeType = new ToscaNodeType(); InterfacesOperationsToscaUtil.addInterfaceDefinitionElement(component, nodeType); @@ -116,7 +187,7 @@ public class InterfacesOperationsToscaUtilTest { final ToscaRepresentation toscaRepresentation = handler.createToscaRepresentation(template); Assert.assertFalse(toscaRepresentation.getMainYaml().contains("operations")); - Assert.assertFalse(toscaRepresentation.getMainYaml().contains("input_")); + Assert.assertFalse(toscaRepresentation.getMainYaml().contains(INPUT_NAME_PREFIX)); Assert.assertFalse(toscaRepresentation.getMainYaml().contains("defaultp")); Assert.assertTrue(toscaRepresentation.getMainYaml().contains("resourceNameNoInputs:")); Assert.assertTrue(toscaRepresentation.getMainYaml().contains("has description")); @@ -146,17 +217,48 @@ public class InterfacesOperationsToscaUtilTest { private ListDataDefinition<OperationInputDefinition> createInputs(int numOfInputs) { ListDataDefinition<OperationInputDefinition> operationInputDefinitionList = new ListDataDefinition<>(); for (int i = 0; i < numOfInputs; i++) { - operationInputDefinitionList.add(createMockOperationInputDefinition("input_" + i, - java.util.UUID.randomUUID().toString() + "." + "naming_function_" + i)); + operationInputDefinitionList.add(createMockOperationInputDefinition( + INPUT_NAME_PREFIX + inputTypes[i] + "_" + i, + java.util.UUID.randomUUID().toString() + "." + MAPPED_PROPERTY_NAME, i)); } return operationInputDefinitionList; } - private OperationInputDefinition createMockOperationInputDefinition(String name, String id) { + private OperationInputDefinition createMockOperationInputDefinition(String name, String id, int index) { OperationInputDefinition operationInputDefinition = new OperationInputDefinition(); operationInputDefinition.setName(name); operationInputDefinition.setInputId(id); + operationInputDefinition.setType(inputTypes[index]); + operationInputDefinition.setRequired(index % 2 == 0); return operationInputDefinition; } + + private void validateOperationInputs(String mainYaml) { + String nodeTypeKey = NODE_TYPE_NAME + ":"; + String nodeTypesRepresentation = mainYaml.substring(mainYaml.indexOf(nodeTypeKey) + nodeTypeKey.length(), + mainYaml.lastIndexOf(MAPPED_PROPERTY_NAME) + MAPPED_PROPERTY_NAME.length()); + YamlToObjectConverter objectConverter = new YamlToObjectConverter(); + ToscaNodeType toscaNodeType = objectConverter.convert(nodeTypesRepresentation.getBytes(), ToscaNodeType.class); + Map<String, Object> interfaces = toscaNodeType.getInterfaces(); + for (Object interfaceVal : interfaces.values()) { + Map<String, Object> interfaceDefinition = mapper.convertValue(interfaceVal, Map.class); + for (Object operationVal : interfaceDefinition.values()) { + if (operationVal instanceof Map) { + validateOperationInputDefinition(operationVal); + } + } + } + } + + private void validateOperationInputDefinition(Object operationVal) { + ToscaLifecycleOperationDefinition operation = + mapper.convertValue(operationVal, ToscaLifecycleOperationDefinition.class); + Map<String, ToscaProperty> inputs = operation.getInputs(); + for (Map.Entry<String, ToscaProperty> inputEntry : inputs.entrySet()) { + Assert.assertEquals(inputEntry.getKey().split("_")[1], inputEntry.getValue().getType()); + Boolean expectedIsRequired = Integer.parseInt(inputEntry.getKey().split("_")[2]) % 2 == 0; + Assert.assertEquals(expectedIsRequired, inputEntry.getValue().getRequired()); + } + } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java b/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java index 76e73bab75..10acd69a79 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/test/utils/InterfaceOperationTestUtils.java @@ -51,13 +51,13 @@ public class InterfaceOperationTestUtils { return operation; } - public static InterfaceDefinition mockInterfaceDefinitionToReturn(String resourceNamme) { + public static InterfaceDefinition mockInterfaceDefinitionToReturn(String resourceName) { Map<String, Operation> operationMap = createMockOperationMap(); return createInterface("int1", "Interface 1", - "lifecycle", "org.openecomp.interfaces.node.lifecycle." + resourceNamme, operationMap); + "lifecycle", "org.openecomp.interfaces.node.lifecycle." + resourceName, operationMap); } - public static Operation mockOperationToReturn(String resourceNamme) { + public static Operation mockOperationToReturn() { return createMockOperation(); } @@ -93,6 +93,7 @@ public class InterfaceOperationTestUtils { OperationInputDefinition operationInputDefinition = new OperationInputDefinition(); operationInputDefinition.setName(name); operationInputDefinition.setUniqueId("uniqueId1"); + operationInputDefinition.setInputId("inputId1"); return operationInputDefinition; } @@ -100,6 +101,7 @@ public class InterfaceOperationTestUtils { OperationOutputDefinition operationOutputDefinition = new OperationOutputDefinition(); operationOutputDefinition.setName(name); operationOutputDefinition.setUniqueId("uniqueId1"); + operationOutputDefinition.setInputId("inputId1"); return operationOutputDefinition; } |