X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=catalog-be%2Fsrc%2Ftest%2Fjava%2Forg%2Fopenecomp%2Fsdc%2Fbe%2Fcomponents%2Fimpl%2FServiceImportBusinessLogicTest.java;h=c6ba0ba9ac47cdddf13d8322cd95cd740ab401d8;hb=f4668df71072c8ecd4b9d05423006265b36a6ef7;hp=1d6a3ff6738c068f8670d88ad85366973bf53a58;hpb=c970dbd2d109f57af2adcaf6e641e19342a0f142;p=sdc.git diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java index 1d6a3ff673..c6ba0ba9ac 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java @@ -19,40 +19,53 @@ package org.openecomp.sdc.be.components.impl; import static org.assertj.core.api.Java6Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyBoolean; import static org.mockito.Mockito.anyList; import static org.mockito.Mockito.anyMap; -import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.contains; import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.isNull; +import static org.mockito.Mockito.matches; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.openecomp.sdc.be.components.impl.ServiceImportBusinessLogic.CREATE_RESOURCE; import fj.data.Either; +import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.net.URISyntaxException; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Collections; import java.util.EnumMap; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import org.apache.commons.codec.binary.Base64; import org.apache.commons.collections.map.HashedMap; import org.apache.commons.lang3.tuple.ImmutablePair; +import org.json.simple.JSONObject; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; -import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.openecomp.sdc.be.components.csar.CsarInfo; +import org.openecomp.sdc.be.components.csar.ServiceCsarInfo; import org.openecomp.sdc.be.components.impl.artifact.ArtifactOperationInfo; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.impl.utils.CreateServiceFromYamlParameter; @@ -63,12 +76,14 @@ import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; +import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType; import org.openecomp.sdc.be.externalapi.servlet.ArtifactExternalServlet; import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.info.NodeTypeInfoToUpdateArtifacts; import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.model.AttributeDefinition; import org.openecomp.sdc.be.model.CapabilityDefinition; +import org.openecomp.sdc.be.model.CapabilityTypeDefinition; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.ComponentInstance; import org.openecomp.sdc.be.model.ComponentInstanceInput; @@ -77,6 +92,7 @@ import org.openecomp.sdc.be.model.ComponentMetadataDefinition; import org.openecomp.sdc.be.model.ComponentParametersView; import org.openecomp.sdc.be.model.DataTypeDefinition; import org.openecomp.sdc.be.model.GroupDefinition; +import org.openecomp.sdc.be.model.GroupTypeDefinition; import org.openecomp.sdc.be.model.IPropertyInputCommon; import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; @@ -96,31 +112,44 @@ import org.openecomp.sdc.be.model.UploadPropInfo; import org.openecomp.sdc.be.model.UploadReqInfo; import org.openecomp.sdc.be.model.UploadResourceInfo; import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache; import org.openecomp.sdc.be.model.operations.api.ICapabilityTypeOperation; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; +import org.openecomp.sdc.be.model.operations.impl.ArtifactTypeOperation; +import org.openecomp.sdc.be.model.operations.impl.CapabilityTypeOperation; +import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation; +import org.openecomp.sdc.be.model.operations.impl.ModelOperation; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; import org.openecomp.sdc.be.servlets.AbstractValidationsServlet; import org.openecomp.sdc.be.tosca.CsarUtils; +import org.openecomp.sdc.be.tosca.ToscaExportHandler; import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; import org.openecomp.sdc.common.api.ArtifactTypeEnum; import org.openecomp.sdc.common.api.Constants; +import org.openecomp.sdc.common.zip.ZipUtils; +import org.openecomp.sdc.common.zip.exception.ZipException; import org.openecomp.sdc.exception.ResponseFormat; +import org.yaml.snakeyaml.Yaml; class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTestSetup { + private final ArtifactDefinition artifactDefinition = mock(ArtifactDefinition.class); + private final ResourceImportManager resourceImportManager = mock(ResourceImportManager.class); + private final ServletUtils servletUtils = mock(ServletUtils.class); + private final AbstractValidationsServlet servlet = new ArtifactExternalServlet( + componentInstanceBusinessLogic, componentsUtils, servletUtils, resourceImportManager, artifactsBusinessLogic); + private final ApplicationDataTypeCache applicationDataTypeCache = mock(ApplicationDataTypeCache.class); + private final ArtifactTypeOperation artifactTypeOperation = mock(ArtifactTypeOperation.class); + private final DataTypeBusinessLogic dataTypeBusinessLogic = mock(DataTypeBusinessLogic.class); + private final ArtifactTypeImportManager artifactTypeImportManager = mock(ArtifactTypeImportManager.class); + private final GroupTypeOperation groupTypeOperation = mock(GroupTypeOperation.class); + private final CapabilityTypeOperation capabilityTypeOperation = mock(CapabilityTypeOperation.class); + private final CapabilityTypeImportManager capabilityTypeImportManager = mock(CapabilityTypeImportManager.class); + private final InterfaceLifecycleTypeImportManager interfaceLifecycleTypeImportManager = mock(InterfaceLifecycleTypeImportManager.class); + @InjectMocks private ServiceImportBusinessLogic sIBL; - @Mock - private ArtifactDefinition artifactDefinition; - @Mock - private ServletUtils servletUtils; - @Mock - private ResourceImportManager resourceImportManager; - - private AbstractValidationsServlet servlet = new ArtifactExternalServlet(userBusinessLogic, - componentInstanceBusinessLogic, componentsUtils, servletUtils, resourceImportManager, artifactsBusinessLogic); - public static String loadFileNameToJsonString(String fileName) throws IOException { String sourceDir = "src/test/resources/normativeTypes"; return loadFileNameToJsonString(sourceDir, fileName); @@ -143,23 +172,53 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest @Test void testCreateService_OK() { Service oldService = createServiceObject(true); + oldService.setComponentInstances(creatComponentInstances()); + oldService.setComponentInstancesProperties( + Collections.singletonMap(COMPONENT_ID, Collections.singletonList(new ComponentInstanceProperty()))); String payloadName = "valid_vf"; Map payload = crateCsarFromPayload(); Service newService = createServiceObject(true); newService.setComponentInstances(creatComponentInstances()); + ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty(); + componentInstanceProperty.setName("propertiesName"); + final JSONObject jsonObject = new JSONObject(); + jsonObject.put(ToscaGetFunctionType.GET_INPUT.getFunctionName(), "zxjTestImportServiceAb_propertiesName"); + componentInstanceProperty.setValue(jsonObject.toJSONString()); + + Map toscaArtifacts = new HashMap<>(); + ArtifactDefinition artifactDef = new ArtifactDefinition(); + String artifactUniqueId = "test_extcp_resource.assettoscatemplate"; + artifactDef.setUniqueId(artifactUniqueId); + toscaArtifacts.put(ToscaExportHandler.ASSET_TOSCA_TEMPLATE, artifactDef); + Resource resource = new Resource(); + String resourceUniqueId = "extcp_resource"; + resource.setUniqueId(resourceUniqueId); + resource.setToscaArtifacts(toscaArtifacts); + resource.getComponentMetadataDefinition().getMetadataDataDefinition().setState(LifecycleStateEnum.CERTIFIED.name()); + resource.setResourceType(ResourceTypeEnum.VF); + + ImmutablePair resourceTemplate = getNodeType(); + String updatedNodeType = "org.openecomp.resource.cp.extCP"; + resource.setToscaResourceName(updatedNodeType); + + newService.setComponentInstancesProperties( + Collections.singletonMap(COMPONENT_ID + "." + "zxjTestImportServiceAb", Collections.singletonList(componentInstanceProperty))); + newService.setProperties(getProperties()); when(serviceBusinessLogic.validateServiceBeforeCreate(eq(newService), any(User.class), any(AuditingActionEnum.class))) .thenReturn(Either.left(newService)); when(toscaOperationFacade.validateCsarUuidUniqueness(anyString())).thenReturn(StorageOperationStatus.OK); - CsarInfo csarInfo = getCsarInfo(); - when(csarBusinessLogic.getCsarInfo(any(Service.class), any(), any(User.class), any(Map.class), anyString())).thenReturn(csarInfo); + ServiceCsarInfo csarInfo = getCsarInfo(); + when(csarBusinessLogic.getCsarInfo(any(Service.class), any(), any(User.class), any(Map.class), anyString(), any())).thenReturn(csarInfo); when(serviceImportParseLogic.findNodeTypesArtifactsToHandle(any(Map.class), any(CsarInfo.class), any(Service.class))) .thenReturn(Either.left(new HashMap>>())); - when(csarBusinessLogic.getParsedToscaYamlInfo(anyString(), anyString(), any(), any(CsarInfo.class), any(), any(Service.class))) - .thenReturn(getParsedToscaYamlInfo()); + doReturn(getParsedToscaYamlInfo()).when(csarBusinessLogic) + .getParsedToscaYamlInfo(anyString(), anyString(), any(), any(CsarInfo.class), any(), any(Service.class)); + doReturn(getParsedToscaYamlInfo()).when(csarBusinessLogic).getParsedToscaYamlInfo(any(ServiceCsarInfo.class), any(Service.class)); when(serviceBusinessLogic.lockComponentByName(newService.getSystemName(), oldService, CREATE_RESOURCE)).thenReturn(Either.left(true)); when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(createOldResource())); - when(serviceImportParseLogic.createServiceTransaction(oldService, csarInfo.getModifier(), false)).thenReturn(newService); + when(serviceImportParseLogic.createServiceTransaction(oldService, csarInfo.getModifier(), false, + AuditingActionEnum.CREATE_RESOURCE)).thenReturn(newService); when(serviceImportParseLogic.createInputsOnService(eq(oldService), anyMap())).thenReturn(newService); Assertions.assertDoesNotThrow(() -> { when(serviceImportParseLogic.createSubstitutionFilterOnService(eq(oldService), any())).thenReturn(newService); @@ -167,7 +226,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest when(serviceImportParseLogic.getNodeTypesFromTemplate(anyMap())).thenReturn(getNodeTypes()); when(serviceImportParseLogic.createNodeTypeResourceFromYaml(anyString(), any(Map.Entry.class), any(User.class), anyMap(), any(Service.class), anyBoolean(), any(), anyList(), anyBoolean(), any(CsarInfo.class), anyBoolean())).thenReturn( - new ImmutablePair<>(new Resource(), ActionStatus.OK)); + new ImmutablePair<>(resource, ActionStatus.OK)); when(serviceImportParseLogic.getComponentWithInstancesFilter()).thenReturn(new ComponentParametersView()); when(toscaOperationFacade.getToscaElement(anyString(), any(ComponentParametersView.class))).thenReturn(Either.left(newService)); when(serviceImportParseLogic.getComponentFilterAfterCreateRelations()).thenReturn(new ComponentParametersView()); @@ -185,6 +244,51 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest when(serviceImportParseLogic.getServiceWithGroups(anyString())).thenReturn(newService); when(mockJanusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK); when(graphLockOperation.unlockComponentByName(anyString(), anyString(), any(NodeTypeEnum.class))).thenReturn(StorageOperationStatus.OK); + when(serviceImportParseLogic.createOutputsOnService(any(Service.class), any(), anyString())).thenReturn(newService); + when(toscaOperationFacade.updateInputsToComponent(anyList(), eq(newService.getUniqueId()))).thenReturn(Either.left(new ArrayList<>())); + + when(applicationDataTypeCache.get(any(), contains("tosca.datatypes.test_"))).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); + DataTypeDefinition typeToBeUpdated = new DataTypeDefinition(); + List properties = new ArrayList<>(); + PropertyDefinition nameProperty = new PropertyDefinition(); + nameProperty.setName("name"); + nameProperty.setType("string"); + properties.add(nameProperty); + PropertyDefinition versionProperty = new PropertyDefinition(); + versionProperty.setName("version"); + versionProperty.setType("string"); + properties.add(versionProperty); + typeToBeUpdated.setProperties(properties); + when(applicationDataTypeCache.get(any(), eq("onap.datatypes.ToscaConceptIdentifier.datatype"))).thenReturn(Either.left(typeToBeUpdated)); + when(applicationDataTypeCache.get(any(), matches("^((?!(tosca.datatypes.test_|onap.datatypes.ToscaConceptIdentifier)).)*$"))).thenReturn( + Either.left(new DataTypeDefinition())); + + when(artifactTypeOperation.getArtifactTypeByUid(contains("tosca.testartifacts.Name"))).thenReturn( + Either.right(StorageOperationStatus.NOT_FOUND)); + when(artifactTypeOperation.getArtifactTypeByUid(contains("tosca.artifacts"))).thenReturn(Either.left(null)); + + when(interfaceLifecycleTypeOperation.getInterface(contains("tosca.interfaces"))).thenReturn(Either.left(new InterfaceDefinition())); + when(interfaceLifecycleTypeOperation.getInterface(contains("tosca.interfaces.test"))).thenReturn( + Either.right(StorageOperationStatus.NOT_FOUND)); + + when(capabilityTypeOperation.getCapabilityType(anyString())) + .thenReturn(Either.left(new CapabilityTypeDefinition())); + when(capabilityTypeOperation.getCapabilityType(contains("tosca.testcapabilitytypes.Name"))) + .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + + when(toscaOperationFacade.getLatestByToscaResourceName(contains("org.openecomp.resource"), isNull())) + .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + when(toscaOperationFacade.getLatestByToscaResourceName(contains("tosca.nodes."), isNull())) + .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + when(toscaOperationFacade.getLatestByToscaResourceName(updatedNodeType, null)).thenReturn(Either.left(resource)); + when(toscaOperationFacade.getLatestByToscaResourceName(contains("org.openecomp.service."), isNull())) + .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + when(artifactsBusinessLogic.handleDownloadRequestById(resourceUniqueId, artifactUniqueId, user.getUserId(), ComponentTypeEnum.RESOURCE, null, + null)) + .thenReturn(resourceTemplate); + when(toscaOperationFacade.updatePropertyOfComponent(eq(oldService), any(PropertyDefinition.class))).thenReturn(Either.left(null)); + when(toscaOperationFacade.updateComponentInstancePropsToComponent(anyMap(), anyString())).thenReturn(Either.left(null)); + when(groupTypeOperation.getGroupTypeByUid(anyString())).thenReturn(Either.left(new GroupTypeDefinition())); Service result = sIBL.createService(oldService, AuditingActionEnum.CREATE_RESOURCE, user, payload, payloadName); assertNotNull(result); @@ -197,6 +301,49 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest assertEquals(1, result.getComponentInstances().get(0).getRequirements().size()); assertNotNull(result.getCategories()); assertEquals(1, result.getCategories().size()); + + ArgumentCaptor yaml = ArgumentCaptor.forClass(String.class); + verify(dataTypeBusinessLogic).createDataTypeFromYaml(yaml.capture(), isNull(), anyBoolean()); + Map yamlMap = new Yaml().load(yaml.getValue()); + assertEquals(3, yamlMap.size()); + assertNotNull(yamlMap.get("tosca.datatypes.test_a")); + assertNotNull(yamlMap.get("tosca.datatypes.test_b")); + assertNotNull(yamlMap.get("onap.datatypes.ToscaConceptIdentifier")); + + ArgumentCaptor artifactTypes = ArgumentCaptor.forClass(String.class); + verify(artifactTypeImportManager).createArtifactTypes(artifactTypes.capture(), isNull(), anyBoolean()); + Map artifactTypesMap = new Yaml().load(artifactTypes.getValue()); + assertEquals(1, artifactTypesMap.size()); + assertNotNull(artifactTypesMap.get("tosca.testartifacts.Name")); + + ArgumentCaptor capabilityTypes = ArgumentCaptor.forClass(String.class); + verify(capabilityTypeImportManager).createCapabilityTypes( + capabilityTypes.capture(), + isNull(), + anyBoolean()); + Map capabilityTypesMap = new Yaml().load(capabilityTypes.getValue()); + assertEquals(1, capabilityTypesMap.size()); + assertNotNull(capabilityTypesMap.get("tosca.testcapabilitytypes.Name")); + + ArgumentCaptor> nodeTypes = ArgumentCaptor.forClass(Map.class); + verify(resourceImportManager).importAllNormativeResource(nodeTypes.capture(), any(), any(), any(), any(), + anyBoolean(), anyBoolean()); + Map nodeTypesMap = nodeTypes.getValue(); + Map newUpdatedNodeType = (Map) nodeTypesMap.get(updatedNodeType); + assertEquals(8, ((Map) newUpdatedNodeType.get("properties")).size()); + Assertions.assertNull(newUpdatedNodeType.get("attributes")); + assertEquals(3, ((List>) newUpdatedNodeType.get("requirements")).size()); + assertEquals(1, ((Map) newUpdatedNodeType.get("capabilities")).size()); + assertEquals(2, ((Map) newUpdatedNodeType.get("interfaces")).size()); + + ArgumentCaptor interfaceTypes = ArgumentCaptor.forClass(String.class); + verify(interfaceLifecycleTypeImportManager).createLifecycleTypes(interfaceTypes.capture(), any(), anyBoolean()); + Map yamlInterfaceMap = new Yaml().load(interfaceTypes.getValue()); + assertEquals(3, yamlInterfaceMap.size()); + assertNotNull(yamlInterfaceMap.get("tosca.interfaces.test.node.lifecycle.Attach")); + assertNotNull(yamlInterfaceMap.get("tosca.interfaces.test.node.lifecycle.Detach")); + assertNotNull(yamlInterfaceMap.get("tosca.interfaces.test.node.lifecycle.Reconfigure")); + } @Test @@ -209,7 +356,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest when(serviceBusinessLogic.validateServiceBeforeCreate(any(Service.class), any(User.class), any(AuditingActionEnum.class))) .thenReturn(Either.left(newService)); when(toscaOperationFacade.validateCsarUuidUniqueness(anyString())).thenReturn(StorageOperationStatus.OK); - when(csarBusinessLogic.getCsarInfo(any(Service.class), any(), any(User.class), any(Map.class), anyString())).thenReturn(getCsarInfo()); + when(csarBusinessLogic.getCsarInfo(any(Service.class), any(), any(User.class), any(Map.class), anyString(), any())).thenReturn(getCsarInfo()); when(serviceImportParseLogic.findNodeTypesArtifactsToHandle(any(Map.class), any(CsarInfo.class), any(Service.class))) .thenReturn(Either.right(ActionStatus.GENERAL_ERROR)); when(csarBusinessLogic.getParsedToscaYamlInfo(anyString(), anyString(), any(), any(CsarInfo.class), anyString(), @@ -224,16 +371,16 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest Service oldService = createServiceObject(true); String csarUUID = "valid_vf"; Map payload = crateCsarFromPayload(); - CsarInfo csarInfo = getCsarInfo(); + ServiceCsarInfo csarInfo = getCsarInfo(); Map>> map = new HashedMap(); when(csarBusinessLogic.getCsarInfo(any(Service.class), any(), any(User.class), - any(Map.class), anyString())).thenReturn(csarInfo); + any(Map.class), anyString(), any())).thenReturn(csarInfo); when(serviceImportParseLogic.findNodeTypesArtifactsToHandle(any(Map.class), any(CsarInfo.class), any(Service.class))).thenReturn(Either.left(map)); Assertions.assertThrows(ComponentException.class, () -> sIBL.createServiceFromCsar(oldService, - user, payload, csarUUID)); + user, payload, csarUUID, null)); } @Test @@ -242,7 +389,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest Resource resource = createOldResource(); String topologyTemplateYaml = getMainTemplateContent("service_import_template.yml"); String yamlName = "group.yml"; - CsarInfo csarInfo = getCsarInfo(); + ServiceCsarInfo csarInfo = getCsarInfo(); Map>> nodeTypesArtifactsToCreate = new HashMap<>(); String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; @@ -259,7 +406,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest Assertions.assertThrows(ComponentException.class, () -> sIBL.createServiceFromYaml(oldService, topologyTemplateYaml, yamlName, nodeTypesInfo, csarInfo, - nodeTypesArtifactsToCreate, false, true, nodeName)); + nodeTypesArtifactsToCreate, false, true, nodeName, user.getUserId(), null)); } @Test @@ -278,7 +425,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest csfyp.setParsedToscaYamlInfo(parsedToscaYamlInfo); when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(resource)); Assertions.assertThrows(ComponentException.class, () -> sIBL.createServiceAndRIsFromYaml(oldService, - false, nodeTypesArtifactsToCreate, false, true, csfyp)); + false, nodeTypesArtifactsToCreate, false, true, csfyp, user.getUserId(), null)); } @Test @@ -297,7 +444,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest csfyp.setParsedToscaYamlInfo(parsedToscaYamlInfo); when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(resource)); Assertions.assertThrows(ComponentException.class, () -> sIBL.createServiceAndRIsFromYaml(oldService, - false, nodeTypesArtifactsToCreate, false, true, csfyp)); + false, nodeTypesArtifactsToCreate, false, true, csfyp, user.getUserId(), null)); } @Test @@ -535,16 +682,13 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest artifactDefinition.setArtifactName("artifactDefinition"); deploymentArtifacts.put("deploymentArtifacts", artifactDefinition); preparedService.setDeploymentArtifacts(deploymentArtifacts); - String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; - Map>> nodeTypesArtifactsToHandle = new HashMap<>(); - NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts = new NodeTypeInfoToUpdateArtifacts(nodeName, nodeTypesArtifactsToHandle); when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(createServiceObject(true))); when(csarArtifactsAndGroupsBusinessLogic.updateResourceArtifactsFromCsar(any(CsarInfo.class), any(Service.class), anyString(), anyString(), anyList(), anyBoolean(), anyBoolean())).thenReturn(Either.left(preparedService)); Assertions.assertNotNull( sIBL.createOrUpdateArtifacts(operation, createdArtifacts, yamlFileName, csarInfo, - preparedService, nodeTypeInfoToUpdateArtifacts, true, true)); + preparedService, true, true)); } @Test @@ -749,21 +893,26 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest void testCreateGroupsOnResourceNull() { Service service = createServiceObject(true); Map groups = new HashMap<>(); - Assertions.assertNotNull(sIBL.createGroupsOnResource(service, groups)); + Assertions.assertNotNull( + sIBL.createGroupsOnResource(service, groups)); } @Test void testUpdateGroupsMembersUsingResource() { Service service = createServiceObject(true); Map groups = getGroups(); - Assertions.assertNotNull(sIBL.updateGroupsMembersUsingResource(groups, service)); + + Assertions.assertNotNull( + sIBL.updateGroupsMembersUsingResource(groups, service)); } @Test void testUpdateGroupsMembersUsingResource_left() { Service service = createServiceObject(true); Map groups = getGroups(); - Assertions.assertNotNull(sIBL.updateGroupsMembersUsingResource(groups, service)); + + Assertions.assertNotNull( + sIBL.updateGroupsMembersUsingResource(groups, service)); } @Test @@ -845,7 +994,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest Assertions.assertNotNull(yamlName); sIBL.processComponentInstance(yamlName, resource, componentInstancesList, allDataTypes.left().value(), instProperties, instCapabilties, instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, - originCompMap, instInputs, instNodeFilter, uploadComponentInstanceInfo); + originCompMap, instInputs, instNodeFilter, null, uploadComponentInstanceInfo); } @Test @@ -871,7 +1020,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest Assertions.assertThrows(ComponentException.class, () -> sIBL.processComponentInstance(yamlName, resource, componentInstancesList, null, instProperties, instCapabilties, instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, originCompMap, - instInputs, instNodeFilter, uploadComponentInstanceInfo)); + instInputs, instNodeFilter, null, uploadComponentInstanceInfo)); } @Test @@ -920,7 +1069,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest List propertyList = getPropertyList(); Assertions.assertNotNull(resource); Assertions.assertNotNull(currPropertiesMap); - sIBL.processProperty(resource, currentCompInstance, allDataTypes, currPropertiesMap, instPropList, propertyList); + sIBL.processProperty(resource, allDataTypes, currPropertiesMap, instPropList, propertyList); } @Test @@ -1134,7 +1283,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest any(ComponentInstance.class), any(UploadReqInfo.class))).thenReturn(capabilityDefinition); when(componentsUtils.getResponseFormat(any(ActionStatus.class), anyString())).thenReturn(responseFormat); when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(service)); - Assertions.assertNotNull(sIBL.createServiceInstancesRelations(user, yamlName, service, uploadResInstancesMap)); + Assertions.assertNotNull(sIBL.createServiceInstancesRelations(user, yamlName, service, uploadResInstancesMap, null)); } @Test @@ -1145,7 +1294,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest Map uploadResInstancesMap = new HashMap<>(); Assertions.assertThrows(ComponentException.class, - () -> sIBL.createServiceInstancesRelations(user, yamlName, service, uploadResInstancesMap)); + () -> sIBL.createServiceInstancesRelations(user, yamlName, service, uploadResInstancesMap, null)); } @Test @@ -1176,7 +1325,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest sIBL.processComponentInstance(yamlName, service, componentInstancesList, allDataTypes.left().value(), instProperties, instCapabilties, instRequirements, instDeploymentArtifacts, - instArtifacts, instAttributes, originCompMap, instInputs, instNodeFilter, + instArtifacts, instAttributes, originCompMap, instInputs, instNodeFilter, null, uploadComponentInstanceInfo); } @@ -1203,7 +1352,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest Assertions.assertThrows(ComponentException.class, () -> sIBL.processComponentInstance(yamlName, service, componentInstancesList, null, instProperties, instCapabilties, instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, originCompMap, - instInputs, instNodeFilter, uploadComponentInstanceInfo)); + instInputs, instNodeFilter, null, uploadComponentInstanceInfo)); } @Test @@ -1260,7 +1409,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest propertyList.add(propertyInfo); Assertions.assertNotNull(resource); - sIBL.processProperty(resource, currentCompInstance, allDataTypes, currPropertiesMap, instPropList, propertyList); + sIBL.processProperty(resource, allDataTypes, currPropertiesMap, instPropList, propertyList); } @Test @@ -1568,6 +1717,7 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest any(ComponentInstance.class), any(UploadReqInfo.class))).thenReturn(capabilityDefinition); when(componentsUtils.getResponseFormat(any(ActionStatus.class), anyString())).thenReturn(responseFormat); Assertions.assertNotNull(sIBL.addRelationToRI(yamlName, service, nodesInfoValue, relations)); + Assertions.assertNotNull(relations.get(0).getRelationships().get(0).getOperations()); } @Test @@ -1581,7 +1731,6 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest List relations = new ArrayList<>(); when(componentsUtils.getResponseFormat(any(ActionStatus.class), anyString())).thenReturn(responseFormat); Assertions.assertNotNull(sIBL.addRelationToRI(yamlName, service, nodesInfoValue, relations)); - } @Test @@ -1657,12 +1806,11 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest originResource.setComponentType(ComponentTypeEnum.RESOURCE); originResource.setToscaResourceName("toscaResourceName"); originResource.setResourceType(ResourceTypeEnum.VF); - originResource.setResourceType(ResourceTypeEnum.VF); Map nodeNamespaceMap = new HashMap<>(); nodeNamespaceMap.put("resources", originResource); - when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())).thenReturn(Either.left(originResource)); + when(toscaOperationFacade.getLatestByToscaResourceName(RESOURCE_TOSCA_NAME, null)).thenReturn(Either.left(originResource)); Assertions.assertNotNull( - sIBL.validateResourceInstanceBeforeCreate(yamlName, uploadComponentInstanceInfo, nodeNamespaceMap)); + sIBL.validateResourceInstanceBeforeCreate(yamlName, null, uploadComponentInstanceInfo, nodeNamespaceMap)); } @Test @@ -1881,7 +2029,9 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest groupDefinition.setUniqueId("groupDefinitionUniqueId"); groupDefinition.setName("groupDefinition"); groupDefinitionList.add(groupDefinition); - Assertions.assertNotNull(sIBL.createGroupsOnResource(resource, groups)); + + Assertions.assertNotNull( + sIBL.createGroupsOnResource(resource, groups)); } @Test @@ -1897,14 +2047,18 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest void testUpdateGroupsMembersUsingResource2() { Resource resource = createParseResourceObject(true); Map groups = getGroups(); - Assertions.assertNotNull(sIBL.updateGroupsMembersUsingResource(groups, resource)); + + Assertions.assertNotNull( + sIBL.updateGroupsMembersUsingResource(groups, resource)); } @Test void testUpdateGroupsMembersUsingResource_left2() { Resource resource = createParseResourceObject(true); Map groups = getGroups(); - Assertions.assertNotNull(sIBL.updateGroupsMembersUsingResource(groups, resource)); + + Assertions.assertNotNull( + sIBL.updateGroupsMembersUsingResource(groups, resource)); } @Test @@ -2287,6 +2441,8 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest componentInstance.setUniqueId("uniqueId"); componentInstance.setComponentUid("componentUid"); componentInstance.setName("zxjTestImportServiceAb"); + componentInstance.setNormalizedName("zxjTestImportServiceAb"); + componentInstance.setProperties(getProperties()); componentInstances.add(componentInstance); return componentInstances; } @@ -2333,14 +2489,41 @@ class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTest return mainTemplateContent; } - protected CsarInfo getCsarInfo() { + protected ServiceCsarInfo getCsarInfo() { String csarUuid = "0010"; User user = new User("jh0003"); - Map csar = crateCsarFromPayload(); - String vfReousrceName = "resouceName"; - String mainTemplateName = "mainTemplateName"; - String mainTemplateContent = getMainTemplateContent("service_import_template.yml"); - return new CsarInfo(user, csarUuid, csar, vfReousrceName, mainTemplateName, mainTemplateContent, false); + + try { + File csarFile = new File( + ServiceImportBusinessLogicTest.class.getClassLoader().getResource("csars/service-Ser09080002-csar.csar").toURI()); + Map csar = ZipUtils.readZip(csarFile, false); + + String vfReousrceName = "resouceName"; + String mainTemplateName = "Definitions/service_import_template.yml"; + + Optional keyOp = csar.keySet().stream().filter(k -> k.endsWith("service-Ser09080002-template.yml")).findAny(); + byte[] mainTemplateService = keyOp.map(csar::get).orElse(null); + assertNotNull(mainTemplateService); + final String mainTemplateContent = new String(mainTemplateService); + + return new ServiceCsarInfo(user, csarUuid, csar, vfReousrceName, null, mainTemplateName, mainTemplateContent, false, mock(ModelOperation.class)); + } catch (URISyntaxException | ZipException e) { + fail(e); + } + return null; + } + + private ImmutablePair getNodeType() { + try { + File resource = new File( + ServiceImportBusinessLogicTest.class.getClassLoader().getResource("node-types/resource-Extcp-template.yml").toURI()); + byte[] extcpResource = Files.readAllBytes(resource.toPath()); + + return new ImmutablePair<>("org.openecomp.resource.cp.extCP", extcpResource); + } catch (URISyntaxException | IOException e) { + fail(e); + } + return null; } protected CsarUtils.NonMetaArtifactInfo getNonMetaArtifactInfo() {