diff options
Diffstat (limited to 'catalog-be/src/test')
8 files changed, 1990 insertions, 2125 deletions
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 bf51f90165..6655ee2b1f 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 @@ -1,48 +1,32 @@ /* - - * Copyright (c) 2018 AT&T Intellectual Property. - + * Copyright (C) 2020 CMCC, Inc. and others. All rights reserved. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package org.openecomp.sdc.be.components.impl; import fj.data.Either; -import io.cucumber.java.hu.Ha; import org.apache.commons.codec.binary.Base64; import org.apache.commons.collections.map.HashedMap; import org.apache.commons.lang3.tuple.ImmutablePair; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; -import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.openecomp.sdc.be.auditing.impl.AuditingManager; import org.openecomp.sdc.be.components.csar.CsarBusinessLogic; import org.openecomp.sdc.be.components.csar.CsarInfo; import org.openecomp.sdc.be.components.impl.artifact.ArtifactOperationInfo; @@ -50,7 +34,6 @@ import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; import org.openecomp.sdc.be.components.impl.utils.CreateServiceFromYamlParameter; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; -import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition; import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition; import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; @@ -61,6 +44,7 @@ import org.openecomp.sdc.be.impl.ServletUtils; import org.openecomp.sdc.be.info.NodeTypeInfoToUpdateArtifacts; import org.openecomp.sdc.be.model.*; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; +import org.openecomp.sdc.be.model.operations.api.ICapabilityTypeOperation; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; import org.openecomp.sdc.be.servlets.AbstractValidationsServlet; @@ -78,31 +62,42 @@ import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.*; +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; import static org.assertj.core.api.Java6Assertions.assertThat; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; - -public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTestSetup { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +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.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicBaseTestSetup { private final static String DEFAULT_ICON = "defaulticon"; @InjectMocks static ServiceImportBusinessLogic serviceImportBusinessLogic; - @Mock - private ServiceBusinessLogic serviceBusinessLogic; - @Mock - private CsarBusinessLogic csarBusinessLogic; - @Mock - private ToscaOperationFacade toscaOperationFacade; - @Mock - private ServiceImportParseLogic serviceImportParseLogic; - @Mock - ArtifactDefinition artifactDefinition =new ArtifactDefinition(); + + ServiceBusinessLogic serviceBusinessLogic = Mockito.mock(ServiceBusinessLogic.class); + CsarBusinessLogic csarBusinessLogic = Mockito.mock(CsarBusinessLogic.class); + ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class); + ServiceImportParseLogic serviceImportParseLogic = Mockito.mock(ServiceImportParseLogic.class); + ArtifactDefinition artifactDefinition = Mockito.mock(ArtifactDefinition.class); + private static UserBusinessLogic userBusinessLogic = Mockito.mock(UserBusinessLogic.class); private static ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class); - private static ComponentsUtils componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class)); + private static final ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class); private static ServletUtils servletUtils = mock(ServletUtils.class); private static ResourceImportManager resourceImportManager = mock(ResourceImportManager.class); private static ArtifactsBusinessLogic artifactsBusinessLogic = mock(ArtifactsBusinessLogic.class); @@ -110,7 +105,7 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB private static AbstractValidationsServlet servlet = new ArtifactExternalServlet(userBusinessLogic, componentInstanceBusinessLogic, componentsUtils, servletUtils, resourceImportManager, artifactsBusinessLogic); - @Before + @BeforeEach public void initMocks() { MockitoAnnotations.initMocks(this); when(artifactDefinition.getMandatory()).thenReturn(true); @@ -130,96 +125,136 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB public void testGetComponentsUtils() { ComponentsUtils result; result = serviceImportBusinessLogic.getComponentsUtils(); + } @Test public void testSetComponentsUtils() { ComponentsUtils componentsUtils = null; - serviceImportBusinessLogic.setComponentsUtils(componentsUtils); + + assertNotNull(serviceImportBusinessLogic); + } @Test public void testCreateService() { - Service oldService = createServiceObject(false); + Service oldService = createServiceObject(true); String payloadName = "valid_vf"; Map<String, byte[]> payload = crateCsarFromPayload(); Service newService = createServiceObject(true); - try { - when(serviceBusinessLogic.validateServiceBeforeCreate(newService,user,AuditingActionEnum.CREATE_RESOURCE)) - .thenReturn(Either.left(newService)); - when(toscaOperationFacade.validateCsarUuidUniqueness(payloadName)).thenReturn(StorageOperationStatus.OK); - sIB1.createService(oldService, AuditingActionEnum.CREATE_RESOURCE, user, payload, payloadName); - } catch (Exception e) { - e.printStackTrace(); - } + + 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(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(), any(Service.class))).thenReturn(getParsedToscaYamlInfo()); + + Assertions.assertThrows(ComponentException.class, () -> sIB1.createService(oldService, + AuditingActionEnum.CREATE_RESOURCE, user, payload, payloadName)); + } @Test - public void testCreateServiceFromCsar(){ - Service oldService = createServiceObject(false); + public void testCreateServiceFromCsar() { + Service oldService = createServiceObject(true); String csarUUID = "valid_vf"; Map<String, byte[]> payload = crateCsarFromPayload(); - try { - sIB1.createServiceFromCsar(oldService, user, payload, csarUUID); - }catch (Exception e) { - e.printStackTrace(); - } + CsarInfo csarInfo = getCsarInfo(); + Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> map = + new HashedMap(); + + when(csarBusinessLogic.getCsarInfo(any(Service.class), any(), any(User.class), + any(Map.class), anyString())).thenReturn(csarInfo); + when(serviceImportParseLogic.findNodeTypesArtifactsToHandle(any(Map.class), any(CsarInfo.class), + any(Service.class))).thenReturn(Either.left(map)); + Assertions.assertThrows(ComponentException.class, () -> sIB1.createServiceFromCsar(oldService, + user, payload, csarUUID)); } @Test - public void testCreateServiceFromYaml(){ - Service oldService = createServiceObject(false); - String topologyTemplateYaml = getMainTemplateContent("service_import_template.yml");; + public void testCreateServiceFromYaml() { + Service oldService = createServiceObject(true); + Resource resource = createOldResource(); + String topologyTemplateYaml = getMainTemplateContent("service_import_template.yml"); + ; String yamlName = "group.yml"; - Map<String, NodeTypeInfo> nodeTypesInfo = new HashedMap(); - CsarInfo csarInfo =getCsarInfo(); + CsarInfo csarInfo = getCsarInfo(); Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate = new HashMap<>(); String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; - try { - sIB1.createServiceFromYaml(oldService,topologyTemplateYaml,yamlName,nodeTypesInfo, - csarInfo,nodeTypesArtifactsToCreate,true,true,nodeName); - }catch (Exception e){ - e.printStackTrace(); - } + + + Map<String, NodeTypeInfo> nodeTypesInfo = getNodeTypesInfo(); + Map<String, Object> map = new HashMap<>(); + map.put("tosca_definitions_version", "123"); + nodeTypesInfo.get(nodeName).setMappedToscaTemplate(map); + ParsedToscaYamlInfo parsedToscaYamlInfo = getParsedToscaYamlInfo(); + when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())) + .thenReturn(Either.left(resource)); + when(csarBusinessLogic.getParsedToscaYamlInfo(anyString(), anyString(), any(Map.class), + eq(csarInfo), anyString(), any(Component.class))).thenReturn(parsedToscaYamlInfo); + when(serviceBusinessLogic.lockComponentByName(anyString(), any(Service.class), anyString())) + .thenReturn(Either.left(true)); + + Assertions.assertThrows(ComponentException.class, () -> sIB1.createServiceFromYaml(oldService, + topologyTemplateYaml, yamlName, nodeTypesInfo, csarInfo, + nodeTypesArtifactsToCreate, false, true, nodeName)); } @Test - public void testCreateServiceAndRIsFromYaml(){ - Service oldService = createServiceObject(false); + public void testCreateServiceAndRIsFromYaml() { + String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; + Service oldService = createServiceObject(true); + Resource resource = createOldResource(); Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate = new HashMap<>(); CreateServiceFromYamlParameter csfyp = getCsfyp(); - try { - sIB1.createServiceAndRIsFromYaml(oldService,false, - nodeTypesArtifactsToCreate,true,true,csfyp); - }catch (Exception e){ - e.printStackTrace(); - } + Map<String, NodeTypeInfo> nodeTypesInfo = getNodeTypesInfo(); + Map<String, Object> map = new HashMap<>(); + map.put("tosca_definitions_version", "123"); + nodeTypesInfo.get(nodeName).setMappedToscaTemplate(map); + ParsedToscaYamlInfo parsedToscaYamlInfo = getParsedToscaYamlInfo(); + csfyp.setNodeTypesInfo(nodeTypesInfo); + csfyp.setParsedToscaYamlInfo(parsedToscaYamlInfo); + when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())) + .thenReturn(Either.left(resource)); + Assertions.assertThrows(ComponentException.class, () -> sIB1.createServiceAndRIsFromYaml(oldService, + false, nodeTypesArtifactsToCreate, false, true, csfyp)); } @Test - public void testCreateServiceAndRIsFromYamlShoudLook(){ - Service oldService = createServiceObject(false); + public void testCreateServiceAndRIsFromYamlShoudLook() { + String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; + Service oldService = createServiceObject(true); + Resource resource = createOldResource(); Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate = new HashMap<>(); CreateServiceFromYamlParameter csfyp = getCsfyp(); - try { - sIB1.createServiceAndRIsFromYaml(oldService,false, - nodeTypesArtifactsToCreate,false,true,csfyp); - }catch (Exception e){ - e.printStackTrace(); - } + Map<String, NodeTypeInfo> nodeTypesInfo = getNodeTypesInfo(); + Map<String, Object> map = new HashMap<>(); + map.put("tosca_definitions_version", "123"); + nodeTypesInfo.get(nodeName).setMappedToscaTemplate(map); + ParsedToscaYamlInfo parsedToscaYamlInfo = getParsedToscaYamlInfo(); + csfyp.setNodeTypesInfo(nodeTypesInfo); + csfyp.setParsedToscaYamlInfo(parsedToscaYamlInfo); + when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())) + .thenReturn(Either.left(resource)); + Assertions.assertThrows(ComponentException.class, () -> sIB1.createServiceAndRIsFromYaml(oldService, + false, nodeTypesArtifactsToCreate, false, true, csfyp)); } @Test - public void testCreateOrUpdateArtifacts(){ + public void testCreateOrUpdateArtifacts() { ArtifactsBusinessLogic.ArtifactOperationEnum operation = ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE; List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); String yamlFileName = "group.yml"; - CsarInfo csarInfo =getCsarInfo(); + CsarInfo csarInfo = getCsarInfo(); Resource preparedResource = createParseResourceObject(false); preparedResource.setResourceType(ResourceTypeEnum.VF); String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; - Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle= new HashMap<>(); + Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>(); EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>> enumListEnumMap = new EnumMap<>(ArtifactsBusinessLogic.ArtifactOperationEnum.class); List<ArtifactDefinition> artifactDefinitions = new ArrayList<>(); @@ -228,99 +263,109 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB artifactDefinitions.add(artifactDefinition); enumListEnumMap.put(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE, artifactDefinitions); - nodeTypesArtifactsToHandle.put(nodeName,enumListEnumMap); - NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts = new NodeTypeInfoToUpdateArtifacts(nodeName,nodeTypesArtifactsToHandle); + nodeTypesArtifactsToHandle.put(nodeName, enumListEnumMap); + NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts = new NodeTypeInfoToUpdateArtifacts(nodeName, nodeTypesArtifactsToHandle); nodeTypeInfoToUpdateArtifacts.setNodeName(nodeName); nodeTypeInfoToUpdateArtifacts.setNodeTypesArtifactsToHandle(nodeTypesArtifactsToHandle); - try { - sIB1.createOrUpdateArtifacts(operation,createdArtifacts,yamlFileName,csarInfo, - preparedResource,nodeTypeInfoToUpdateArtifacts,true,true); - }catch (Exception e){ - e.printStackTrace(); - } + Assertions.assertNotNull( + sIB1.createOrUpdateArtifacts(operation, createdArtifacts, yamlFileName, csarInfo, + preparedResource, nodeTypeInfoToUpdateArtifacts, true, true) + ); + + } @Test - public void testHandleVfCsarArtifacts(){ - Resource resource = createParseResourceObject(false); + public void testHandleVfCsarArtifacts() { + Resource resource = createParseResourceObject(true); + Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>(); + ArtifactDefinition artifactDefinition = new ArtifactDefinition(); + artifactDefinition.setArtifactName(Constants.VENDOR_LICENSE_MODEL); + artifactDefinition.setUniqueId("uniqueId"); + deploymentArtifacts.put("deploymentArtifacts", artifactDefinition); + resource.setDeploymentArtifacts(deploymentArtifacts); CsarInfo csarInfo = getCsarInfo(); + Map<String, byte[]> csar = new HashMap<>(); + String csarKey = CsarUtils.ARTIFACTS_PATH + "HEAT.meta"; + byte[] artifactsMetaBytes = "src/test/resources/normativeTypes/valid_vf.csar".getBytes(); + csar.put(csarKey, artifactsMetaBytes); + csarInfo.setCsar(csar); List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); - ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true,true, ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE); - when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST)); - - try { - sIB1.handleVfCsarArtifacts(resource,csarInfo,createdArtifacts,artifactOperation,true,true); - } catch (Exception e) { - e.printStackTrace(); - } + ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true, true, ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE); + when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(resource)); + when(csarArtifactsAndGroupsBusinessLogic + .createResourceArtifactsFromCsar(any(CsarInfo.class), any(Resource.class), anyString(), anyString(), + anyList())).thenReturn(Either.left(resource)); + Assertions.assertNotNull( + sIB1.handleVfCsarArtifacts(resource, + csarInfo, createdArtifacts, artifactOperation, true, true)); } @Test public void testHandleVfCsarArtifactsGetToscaElement() { - Resource resource = createParseResourceObject(false); + Resource resource = createParseResourceObject(true); Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>(); ArtifactDefinition artifactDefinition = new ArtifactDefinition(); artifactDefinition.setArtifactName(Constants.VENDOR_LICENSE_MODEL); artifactDefinition.setUniqueId("uniqueId"); - deploymentArtifacts.put("deploymentArtifacts",artifactDefinition); + deploymentArtifacts.put("deploymentArtifacts", artifactDefinition); resource.setDeploymentArtifacts(deploymentArtifacts); CsarInfo csarInfo = getCsarInfo(); Map<String, byte[]> csar = new HashMap<>(); String csarKey = CsarUtils.ARTIFACTS_PATH + "HEAT.meta"; byte[] artifactsMetaBytes = "src/test/resources/normativeTypes/valid_vf.csar".getBytes(); - csar.put(csarKey,artifactsMetaBytes); + csar.put(csarKey, artifactsMetaBytes); csarInfo.setCsar(csar); List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); - ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true,true, ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE); + ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true, true, ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE); when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(resource)); - - try { - sIB1.handleVfCsarArtifacts(resource,csarInfo,createdArtifacts,artifactOperation,true,true); - } catch (Exception e) { - e.printStackTrace(); - } + when(csarArtifactsAndGroupsBusinessLogic + .createResourceArtifactsFromCsar(any(CsarInfo.class), any(Resource.class), anyString(), anyString(), + anyList())).thenReturn(Either.left(resource)); + Assertions.assertNotNull( + sIB1.handleVfCsarArtifacts(resource, + csarInfo, createdArtifacts, artifactOperation, true, true)); } @Test - public void testCreateOrUpdateSingleNonMetaArtifactToComstants(){ + public void testCreateOrUpdateSingleNonMetaArtifactToComstants() { Resource resource = createParseResourceObject(false); CsarInfo csarInfo = getCsarInfo(); - ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true,true, ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE); + ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true, true, ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE); Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>(); ArtifactDefinition artifactDefinition = new ArtifactDefinition(); artifactDefinition.setArtifactName("artifactDefinition"); - deploymentArtifacts.put("deploymentArtifacts",artifactDefinition); + deploymentArtifacts.put("deploymentArtifacts", artifactDefinition); resource.setDeploymentArtifacts(deploymentArtifacts); - try { - sIB1.createOrUpdateSingleNonMetaArtifactToComstants(resource,csarInfo,artifactOperation,true,true); - }catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertNotNull(resource); + Assertions.assertNotNull(csarInfo); + sIB1.createOrUpdateSingleNonMetaArtifactToComstants(resource, csarInfo, artifactOperation, true, true); + } @Test - public void testCreateOrUpdateNonMetaArtifacts(){ + public void testCreateOrUpdateNonMetaArtifacts() { CsarInfo csarInfo = getCsarInfo(); Resource resource = createParseResourceObject(false); List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); - ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true,true, ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE); + ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true, true, ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE); Either<Resource, ResponseFormat> result = sIB1.createOrUpdateNonMetaArtifacts(csarInfo, resource, createdArtifacts, true, true, artifactOperation); - assertEquals(result.left().value(),resource); + assertEquals(result.left().value(), resource); } @Test - public void testFindVfCsarArtifactsToHandle(){ + public void testFindVfCsarArtifactsToHandle() { Resource resource = createParseResourceObject(false); Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>(); ArtifactDefinition artifactDefinition = new ArtifactDefinition(); artifactDefinition.setArtifactName("artifactDefinition"); - deploymentArtifacts.put("deploymentArtifacts",artifactDefinition); + deploymentArtifacts.put("deploymentArtifacts", artifactDefinition); Map<String, ArtifactDefinition> artifacts = new HashMap<>(); - artifacts.put("artifacts",artifactDefinition); + artifacts.put("artifacts", artifactDefinition); List<GroupDefinition> groups = new ArrayList<>(); GroupDefinition groupDefinition = new GroupDefinition(); groupDefinition.setUniqueId("groupDefinitionUniqueId"); @@ -332,14 +377,14 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB List<CsarUtils.NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>(); Either<EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>>, - ResponseFormat> result = sIB1.findVfCsarArtifactsToHandle(resource,artifactPathAndNameList,user); + ResponseFormat> result = sIB1.findVfCsarArtifactsToHandle(resource, artifactPathAndNameList, user); assertNotNull(result.left().value()); } @Test public void testIsNonMetaArtifact() { - ArtifactDefinition artifactDefinition =new ArtifactDefinition(); + ArtifactDefinition artifactDefinition = new ArtifactDefinition(); artifactDefinition.setMandatory(false); artifactDefinition.setArtifactName("creatorFullName"); artifactDefinition.setArtifactType("TOSCA_CSAR"); @@ -350,7 +395,7 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB } @Test - public void testOrganizeVfCsarArtifactsByArtifactOperation(){ + public void testOrganizeVfCsarArtifactsByArtifactOperation() { List<CsarUtils.NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>(); artifactPathAndNameList.add(getNonMetaArtifactInfo()); List<ArtifactDefinition> existingArtifactsToHandle = new ArrayList<>(); @@ -367,7 +412,7 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB } @Test - public void testOrganizeVfCsarArtifactsByArtifactOperationElse(){ + public void testOrganizeVfCsarArtifactsByArtifactOperationElse() { List<CsarUtils.NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>(); artifactPathAndNameList.add(getNonMetaArtifactInfo()); List<ArtifactDefinition> existingArtifactsToHandle = new ArrayList<>(); @@ -377,33 +422,30 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB artifactDefinition.setArtifactChecksum("artifactChecksum"); existingArtifactsToHandle.add(artifactDefinition); Resource resource = createParseResourceObject(false); - - try { - sIB1.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList, existingArtifactsToHandle, resource, user); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertNotNull( + sIB1.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList, existingArtifactsToHandle, resource, user)); } @Test - public void testProcessCsarArtifacts(){ + public void testProcessCsarArtifacts() { CsarInfo csarInfo = getCsarInfo(); Resource resource = createParseResourceObject(false); List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); - Either<Resource, ResponseFormat> resStatus = null; + Either<Resource, ResponseFormat> resStatus = Either.left(resource); List<CsarUtils.NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>(); artifactPathAndNameList.add(getNonMetaArtifactInfo()); EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>> vfCsarArtifactsToHandle = new EnumMap<>(ArtifactsBusinessLogic.ArtifactOperationEnum.class); - vfCsarArtifactsToHandle.put(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE,artifactPathAndNameList); - Either<Resource, ResponseFormat> rrfe = sIB1.processCsarArtifacts(csarInfo, - resource, createdArtifacts, true, true, resStatus, vfCsarArtifactsToHandle); - assertNull(rrfe); + vfCsarArtifactsToHandle.put(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE, artifactPathAndNameList); + Assertions.assertNotNull( + sIB1.processCsarArtifacts(csarInfo, + resource, createdArtifacts, true, true, resStatus, vfCsarArtifactsToHandle)); + } @Test - public void testCreateOrUpdateSingleNonMetaArtifact(){ + public void testCreateOrUpdateSingleNonMetaArtifact() { Resource resource = createParseResourceObject(false); CsarInfo csarInfo = getCsarInfo(); Map<String, byte[]> csar = csarInfo.getCsar(); @@ -416,28 +458,28 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB } catch (IOException e) { e.printStackTrace(); } - csar.put("valid_vf.csar",data); + csar.put("valid_vf.csar", data); String artifactPath = "valid_vf.csar", artifactFileName = "", artifactType = ""; ArtifactGroupTypeEnum artifactGroupType = ArtifactGroupTypeEnum.TOSCA; String artifactLabel = "", artifactDisplayName = "", artifactDescription = "", artifactId = "artifactId"; - ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true,true, ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE); + ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true, true, ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE); List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); - try { - sIB1.createOrUpdateSingleNonMetaArtifact(resource, csarInfo, artifactPath, artifactFileName, artifactType, artifactGroupType, - artifactLabel, artifactDisplayName, artifactDescription, artifactId, artifactOperation, createdArtifacts, - true, true, true); - } catch (Exception e) { - e.printStackTrace(); - } + ArtifactDefinition artifactDefinition = new ArtifactDefinition(); + artifactDefinition.setArtifactName("artifactName"); + Either<ArtifactDefinition, Operation> artifactDefinitionOperationEither = Either.left(artifactDefinition); + when(csarArtifactsAndGroupsBusinessLogic.createOrUpdateCsarArtifactFromJson(any(Resource.class), any(User.class), + any(Map.class), any(ArtifactOperationInfo.class))).thenReturn(Either.left(artifactDefinitionOperationEither)); + Assertions.assertNotNull( + sIB1.createOrUpdateSingleNonMetaArtifact(resource, csarInfo, artifactPath, + artifactFileName, artifactType, artifactGroupType, artifactLabel, + artifactDisplayName, artifactDescription, artifactId, artifactOperation, + createdArtifacts, true, true, true)); } @Test - public void testHandleNodeTypeArtifacts(){ - Resource nodeTypeResource = createParseResourceObject(false); - ResourceMetadataDataDefinition componentMetadataDataDefinition = new ResourceMetadataDataDefinition(); - componentMetadataDataDefinition.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT.name()); - ComponentMetadataDefinition componentMetadataDefinition = new ComponentMetadataDefinition(componentMetadataDataDefinition); - nodeTypeResource.setComponentMetadataDefinition(componentMetadataDefinition); + public void testHandleNodeTypeArtifacts() { + Resource nodeTypeResource = createParseResourceObject(true); + nodeTypeResource.setLifecycleState(LifecycleStateEnum.CERTIFIED); Map<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle = new HashMap<>(); List<ArtifactDefinition> artifactDefinitions = new ArrayList<>(); ArtifactDefinition artifactDefinition = new ArtifactDefinition(); @@ -445,60 +487,59 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB artifactDefinitions.add(artifactDefinition); nodeTypeArtifactsToHandle.put(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE, artifactDefinitions); - List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); - try { - sIB1.handleNodeTypeArtifacts(nodeTypeResource, nodeTypeArtifactsToHandle, - createdArtifacts, user, true, true); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertNotNull( + sIB1.handleNodeTypeArtifacts(nodeTypeResource, nodeTypeArtifactsToHandle, + createdArtifacts, user, true, true)); } @Test - public void testCreateOrUpdateServiceArtifacts(){ + public void testCreateOrUpdateServiceArtifacts() throws IOException { ArtifactsBusinessLogic.ArtifactOperationEnum operation = ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE; List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); String yamlFileName = "group.yml"; - CsarInfo csarInfo =getCsarInfo(); - Service preparedService = createServiceObject(false); + CsarInfo csarInfo = getCsarInfo(); + Map<String, byte[]> csar = new HashMap<>(); + String csarKey = CsarUtils.ARTIFACTS_PATH + "HEAT.meta"; + byte[] artifactsMetaBytes = "src/test/resources/normativeTypes/valid_vf.csar".getBytes(); + csar.put(csarKey, artifactsMetaBytes); + csarInfo.setCsar(csar); + Service preparedService = createServiceObject(true); Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>(); ArtifactDefinition artifactDefinition = new ArtifactDefinition(); artifactDefinition.setArtifactName("artifactDefinition"); - deploymentArtifacts.put("deploymentArtifacts",artifactDefinition); + deploymentArtifacts.put("deploymentArtifacts", artifactDefinition); preparedService.setDeploymentArtifacts(deploymentArtifacts); String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; - Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle= new HashMap<>(); - NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts = new NodeTypeInfoToUpdateArtifacts(nodeName,nodeTypesArtifactsToHandle); + Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>(); + NodeTypeInfoToUpdateArtifacts nodeTypeInfoToUpdateArtifacts = new NodeTypeInfoToUpdateArtifacts(nodeName, nodeTypesArtifactsToHandle); - try { - sIB1.createOrUpdateArtifacts(operation,createdArtifacts,yamlFileName,csarInfo, - preparedService,nodeTypeInfoToUpdateArtifacts,true,true); - } catch (Exception e) { - e.printStackTrace(); - } + 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( + sIB1.createOrUpdateArtifacts(operation, createdArtifacts, yamlFileName, csarInfo, + preparedService, nodeTypeInfoToUpdateArtifacts, true, true)); } @Test - public void testHandleVfCsarServiceArtifacts(){ + public void testHandleVfCsarServiceArtifacts() { Service service = createServiceObject(true); Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>(); ArtifactDefinition artifactDefinition = new ArtifactDefinition(); artifactDefinition.setArtifactName(Constants.VENDOR_LICENSE_MODEL); artifactDefinition.setUniqueId("uniqueId"); - deploymentArtifacts.put("deploymentArtifacts",artifactDefinition); + deploymentArtifacts.put("deploymentArtifacts", artifactDefinition); service.setDeploymentArtifacts(deploymentArtifacts); CsarInfo csarInfo = getCsarInfo(); List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); - ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true,true, ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE); - when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST)); + ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true, true, ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE); + when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(service)); + when(csarArtifactsAndGroupsBusinessLogic.deleteVFModules(any(Service.class), any(CsarInfo.class), anyBoolean(), anyBoolean())).thenReturn(Either.left(service)); + Assertions.assertNotNull( + sIB1.handleVfCsarArtifacts(service, csarInfo, createdArtifacts, artifactOperation, true, true)); - try { - sIB1.handleVfCsarArtifacts(service,csarInfo,createdArtifacts,artifactOperation,true,true); - } catch (Exception e) { - e.printStackTrace(); - } } @Test @@ -508,46 +549,45 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB ArtifactDefinition artifactDefinition = new ArtifactDefinition(); artifactDefinition.setArtifactName(Constants.VENDOR_LICENSE_MODEL); artifactDefinition.setUniqueId("uniqueId"); - deploymentArtifacts.put("deploymentArtifacts",artifactDefinition); + deploymentArtifacts.put("deploymentArtifacts", artifactDefinition); service.setDeploymentArtifacts(deploymentArtifacts); CsarInfo csarInfo = getCsarInfo(); Map<String, byte[]> csar = new HashMap<>(); String csarKey = CsarUtils.ARTIFACTS_PATH + "HEAT.meta"; byte[] artifactsMetaBytes = "src/test/resources/normativeTypes/valid_vf.csar".getBytes(); - csar.put(csarKey,artifactsMetaBytes); + csar.put(csarKey, artifactsMetaBytes); csarInfo.setCsar(csar); List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); - ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true,true, ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE); + ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true, true, ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE); when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(service)); - - try { - sIB1.handleVfCsarArtifacts(service,csarInfo,createdArtifacts,artifactOperation,true,true); - } catch (Exception e) { - e.printStackTrace(); - } + when(csarArtifactsAndGroupsBusinessLogic.createResourceArtifactsFromCsar(any(CsarInfo.class), any(Service.class), + anyString(), anyString(), anyList())).thenReturn(Either.left(service)); + Assertions.assertNotNull( + sIB1.handleVfCsarArtifacts(service, + csarInfo, createdArtifacts, artifactOperation, true, true)); } @Test - public void testCreateOrUpdateNonMetaServiceArtifacts(){ + public void testCreateOrUpdateNonMetaServiceArtifacts() { CsarInfo csarInfo = getCsarInfo(); Service service = createServiceObject(true); List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); - ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true,true, ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE); + ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true, true, ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE); Either<Service, ResponseFormat> result = sIB1.createOrUpdateNonMetaArtifacts(csarInfo, service, createdArtifacts, true, true, artifactOperation); - assertEquals(result.left().value(),service); + assertEquals(result.left().value(), service); } @Test - public void testFindServiceCsarArtifactsToHandle(){ + public void testFindServiceCsarArtifactsToHandle() { Service service = createServiceObject(true); Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>(); ArtifactDefinition artifactDefinition = new ArtifactDefinition(); artifactDefinition.setArtifactName("artifactDefinition"); - deploymentArtifacts.put("deploymentArtifacts",artifactDefinition); + deploymentArtifacts.put("deploymentArtifacts", artifactDefinition); Map<String, ArtifactDefinition> artifacts = new HashMap<>(); - artifacts.put("artifacts",artifactDefinition); + artifacts.put("artifacts", artifactDefinition); List<GroupDefinition> groups = new ArrayList<>(); GroupDefinition groupDefinition = new GroupDefinition(); groupDefinition.setUniqueId("groupDefinitionUniqueId"); @@ -564,7 +604,7 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB } @Test - public void testOrganizeVfCsarArtifactsByServiceArtifactOperation(){ + public void testOrganizeVfCsarArtifactsByServiceArtifactOperation() { List<CsarUtils.NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>(); artifactPathAndNameList.add(getNonMetaArtifactInfo()); List<ArtifactDefinition> existingArtifactsToHandle = new ArrayList<>(); @@ -582,7 +622,7 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB } @Test - public void testOrganizeVfCsarArtifactsByServiceArtifactOperationElse(){ + public void testOrganizeVfCsarArtifactsByServiceArtifactOperationElse() { List<CsarUtils.NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>(); artifactPathAndNameList.add(getNonMetaArtifactInfo()); List<ArtifactDefinition> existingArtifactsToHandle = new ArrayList<>(); @@ -592,39 +632,38 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB artifactDefinition.setArtifactChecksum("artifactChecksum"); existingArtifactsToHandle.add(artifactDefinition); Service service = createServiceObject(true); - - try { - sIB1.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList, existingArtifactsToHandle, service, user); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertNotNull( + sIB1.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList, existingArtifactsToHandle, service, user)); } @Test - public void testProcessServiceCsarArtifacts(){ + public void testProcessServiceCsarArtifacts() { CsarInfo csarInfo = getCsarInfo(); Service service = createServiceObject(true); List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); - Either<Service, ResponseFormat> resStatus = null; + Either<Service, ResponseFormat> resStatus = Either.left(service); EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<CsarUtils.NonMetaArtifactInfo>> vfCsarArtifactsToHandle = new EnumMap<>(ArtifactsBusinessLogic.ArtifactOperationEnum.class); - Either<Service, ResponseFormat> srfe = sIB1.processCsarArtifacts(csarInfo, - service, createdArtifacts, true, true, resStatus, vfCsarArtifactsToHandle); - assertNull(srfe); + List<CsarUtils.NonMetaArtifactInfo> objects = new ArrayList<>(); + objects.add(getNonMetaArtifactInfo()); + vfCsarArtifactsToHandle.put(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE, objects); + Assertions.assertNotNull( + sIB1.processCsarArtifacts(csarInfo, + service, createdArtifacts, true, true, resStatus, vfCsarArtifactsToHandle)); + } @Test - public void testGetValidArtifactNames(){ + public void testGetValidArtifactNames() { CsarInfo csarInfo = getCsarInfo(); Map<String, Set<List<String>>> collectedWarningMessages = new HashMap<>(); Either<List<CsarUtils.NonMetaArtifactInfo>, String> result = sIB1.getValidArtifactNames(csarInfo, collectedWarningMessages); - System.out.println(result.left().value()); assertNotNull(result.left().value()); } @Test - public void testCreateOrUpdateSingleNonMetaServiceArtifact(){ + public void testCreateOrUpdateSingleNonMetaServiceArtifact() { Service service = createServiceObject(true); CsarInfo csarInfo = getCsarInfo(); Map<String, byte[]> csar = csarInfo.getCsar(); @@ -637,169 +676,166 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB } catch (IOException e) { e.printStackTrace(); } - csar.put("valid_vf.csar",data); + csar.put("valid_vf.csar", data); csarInfo.setCsar(csar); String artifactPath = "valid_vf.csar", artifactFileName = "", artifactType = ""; ArtifactGroupTypeEnum artifactGroupType = ArtifactGroupTypeEnum.TOSCA; String artifactLabel = "", artifactDisplayName = "", artifactDescription = "", artifactId = "artifactId"; - ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true,true, ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE); + ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true, true, ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE); List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); - try { - sIB1.createOrUpdateSingleNonMetaArtifact(service, csarInfo, artifactPath, artifactFileName, artifactType, artifactGroupType, - artifactLabel, artifactDisplayName, artifactDescription, artifactId, artifactOperation, createdArtifacts, - true, true, true); - } catch (Exception e) { - e.printStackTrace(); - } + ArtifactDefinition artifactDefinition = new ArtifactDefinition(); + artifactDefinition.setArtifactName("artifactName"); + Either<ArtifactDefinition, Operation> artifactDefinitionOperationEither = Either.left(artifactDefinition); + when(csarArtifactsAndGroupsBusinessLogic.createOrUpdateCsarArtifactFromJson(any(Service.class), any(User.class), + anyMap(), any(ArtifactOperationInfo.class))).thenReturn(Either.left(artifactDefinitionOperationEither)); + Assertions.assertNotNull( + sIB1.createOrUpdateSingleNonMetaArtifact(service, csarInfo, artifactPath, artifactFileName, + artifactType, artifactGroupType, artifactLabel, artifactDisplayName, + artifactDescription, artifactId, artifactOperation, createdArtifacts, + true, true, true)); } @Test - public void testCreateOrUpdateSingleNonMetaServiceArtifactNull(){ + public void testCreateOrUpdateSingleNonMetaServiceArtifactNull() { Service service = createServiceObject(true); CsarInfo csarInfo = getCsarInfo(); String artifactPath = "valid_vf.csar", artifactFileName = "", artifactType = ""; ArtifactGroupTypeEnum artifactGroupType = ArtifactGroupTypeEnum.TOSCA; String artifactLabel = "", artifactDisplayName = "", artifactDescription = "", artifactId = "artifactId"; - ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true,true, ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE); + ArtifactOperationInfo artifactOperation = new ArtifactOperationInfo(true, true, ArtifactsBusinessLogic.ArtifactOperationEnum.UPDATE); List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); - try { - sIB1.createOrUpdateSingleNonMetaArtifact(service, csarInfo, artifactPath, artifactFileName, artifactType, artifactGroupType, - artifactLabel, artifactDisplayName, artifactDescription, artifactId, artifactOperation, createdArtifacts, - true, true, true); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertNotNull( + sIB1.createOrUpdateSingleNonMetaArtifact(service, csarInfo, artifactPath, artifactFileName, + artifactType, artifactGroupType, artifactLabel, artifactDisplayName, + artifactDescription, artifactId, artifactOperation, createdArtifacts, + true, true, true)); } @Test - public void testCreateGroupsOnResource(){ + public void testCreateGroupsOnResource() { Service service = createServiceObject(true); - Map<String, GroupDefinition> groups = getGroups(); - - try { - Either<Service, ResponseFormat> result = sIB1.createGroupsOnResource(service, groups); - } catch (Exception e) { - e.printStackTrace(); - } + Map<String, GroupDefinition> groups = new HashMap<>(); + Assertions.assertNotNull( + sIB1.createGroupsOnResource(service, groups)); } @Test - public void testCreateGroupsOnResourceNull(){ + public void testCreateGroupsOnResourceNull() { Service service = createServiceObject(true); - Map<String, GroupDefinition> groups = null; + Map<String, GroupDefinition> groups = new HashMap<>(); + Assertions.assertNotNull( + sIB1.createGroupsOnResource(service, groups)); - Either<Service, ResponseFormat> result = sIB1.createGroupsOnResource(service, groups); - assertNotNull(result); } @Test - public void testUpdateGroupsMembersUsingResource(){ + public void testUpdateGroupsMembersUsingResource() { Service service = createServiceObject(true); - Map<String, GroupDefinition> groups = null; + Map<String, GroupDefinition> groups = getGroups(); + when(serviceImportParseLogic.validateCyclicGroupsDependencies(any())) + .thenReturn(Either.left(true)); + Assertions.assertNotNull( + sIB1.updateGroupsMembersUsingResource(groups, service)); - List<GroupDefinition> groupDefinitions = sIB1.updateGroupsMembersUsingResource(groups, service); - for (GroupDefinition groupDefinition : groupDefinitions) { - assertNull(groupDefinition); - } } @Test - public void testUpdateGroupsMembersUsingResource_left(){ + public void testUpdateGroupsMembersUsingResource_left() { Service service = createServiceObject(true); Map<String, GroupDefinition> groups = getGroups(); when(serviceImportParseLogic.validateCyclicGroupsDependencies(any())) .thenReturn(Either.left(true)); + Assertions.assertNotNull( + sIB1.updateGroupsMembersUsingResource(groups, service)); - List<GroupDefinition> groupDefinitions = sIB1.updateGroupsMembersUsingResource(groups, service); - for (GroupDefinition groupDefinition : groupDefinitions) { - assertNotNull(groupDefinition); - } } @Test - public void testCreateRIAndRelationsFromResourceYaml(){ + public void testCreateRIAndRelationsFromResourceYaml() throws IOException { + String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; String yamlName = "group.yml"; Resource resource = createParseResourceObject(true); Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap = new HashMap<>(); String topologyTemplateYaml = getMainTemplateContent(); List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>(); - Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>(); + + Map<String, NodeTypeInfo> nodeTypesInfo = getNodeTypesInfo(); + Map<String, Object> map = new HashMap<>(); + map.put("tosca_definitions_version", "123"); + nodeTypesInfo.get(nodeName).setMappedToscaTemplate(map); + CsarInfo csarInfo = getCsarInfo(); Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate = new HashMap<>(); - String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; - try { - sIB1.createRIAndRelationsFromYaml(yamlName,resource,uploadComponentInstanceInfoMap,topologyTemplateYaml,nodeTypesNewCreatedArtifacts, - nodeTypesInfo,csarInfo,nodeTypesArtifactsToCreate,nodeName); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1 + .createRIAndRelationsFromYaml(yamlName, resource, uploadComponentInstanceInfoMap, + topologyTemplateYaml, nodeTypesNewCreatedArtifacts, nodeTypesInfo, + csarInfo, nodeTypesArtifactsToCreate, nodeName)); } @Test - public void testCreateResourceInstancesRelations(){ + public void testCreateResourceInstancesRelations() { String yamlName = "group.yml"; Resource resource = createParseResourceObject(true); resource.setComponentInstances(creatComponentInstances()); resource.setResourceType(ResourceTypeEnum.VF); Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>(); - uploadResInstancesMap.put("uploadResInstancesMap",getuploadComponentInstanceInfo()); - - try { - sIB1.createResourceInstancesRelations(user,yamlName,resource,uploadResInstancesMap); - } catch (Exception e) { - e.printStackTrace(); - } + uploadResInstancesMap.put("uploadResInstancesMap", getuploadComponentInstanceInfo()); + when(serviceImportParseLogic.getResourceAfterCreateRelations(any(Resource.class))).thenReturn(resource); + when(toscaOperationFacade.getToscaFullElement(anyString())).thenReturn(Either.left(resource)); + Assertions.assertThrows(ComponentException.class, () -> sIB1 + .createResourceInstancesRelations(user, yamlName, resource, uploadResInstancesMap)); } @Test - public void testCreateResourceInstancesRelations_Empty(){ + public void testCreateResourceInstancesRelations_Empty() { String yamlName = "group.yml"; Resource resource = createParseResourceObject(true); resource.setComponentInstances(creatComponentInstances()); - resource.setResourceType(ResourceTypeEnum.PNF); + resource.setResourceType(ResourceTypeEnum.VF); Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>(); - uploadResInstancesMap.put("uploadResInstancesMap",getuploadComponentInstanceInfo()); - - try { - sIB1.createResourceInstancesRelations(user,yamlName,resource,uploadResInstancesMap); - } catch (Exception e) { - e.printStackTrace(); - } + uploadResInstancesMap.put("uploadResInstancesMap", getuploadComponentInstanceInfo()); + when(serviceImportParseLogic.getResourceAfterCreateRelations(any(Resource.class))).thenReturn(resource); + when(toscaOperationFacade.getToscaFullElement(anyString())).thenReturn(Either.left(resource)); + Assertions.assertThrows(ComponentException.class, () -> sIB1 + .createResourceInstancesRelations(user, yamlName, resource, uploadResInstancesMap)); } @Test - public void testProcessComponentInstance1(){ + public void testProcessComponentInstance1() { String yamlName = "group.yml"; Resource resource = createParseResourceObject(true); Resource originResource = createParseResourceObject(false); + originResource.setResourceType(ResourceTypeEnum.VF); List<ComponentInstance> componentInstancesList = creatComponentInstances(); - Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = null; + Map<String, DataTypeDefinition> dataTypeDefinitionMap = new HashMap<>(); + DataTypeDefinition dataTypeDefinition = new DataTypeDefinition(); + dataTypeDefinition.setName("dataTypeDefinitionName"); + dataTypeDefinitionMap.put("dataTypeDefinitionMap", dataTypeDefinition); + Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = Either.left(dataTypeDefinitionMap); Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>(); Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilties = new HashMap<>(); Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements = new HashMap<>(); Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts = new HashMap<>(); Map<String, Map<String, ArtifactDefinition>> instArtifacts = new HashMap<>(); - Map<String, List< AttributeDefinition >> instAttributes = new HashMap<>(); + Map<String, List<AttributeDefinition>> instAttributes = new HashMap<>(); Map<String, Resource> originCompMap = new HashMap<>(); - originCompMap.put("componentUid",originResource); + originCompMap.put("componentUid", originResource); Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>(); UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo(); uploadComponentInstanceInfo.setName("zxjTestImportServiceAb"); - - try { - sIB1.processComponentInstance(yamlName, resource, componentInstancesList,allDataTypes,instProperties,instCapabilties,instRequirements, - instDeploymentArtifacts,instArtifacts,instAttributes,originCompMap,instInputs,uploadComponentInstanceInfo); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertNotNull(resource); + Assertions.assertNotNull(yamlName); + sIB1.processComponentInstance(yamlName, resource, componentInstancesList, allDataTypes, instProperties, + instCapabilties, instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, + originCompMap, instInputs, uploadComponentInstanceInfo); } @Test - public void testProcessComponentInstance_null(){ + public void testProcessComponentInstance_null() { String yamlName = "group.yml"; Resource resource = createParseResourceObject(true); Resource originResource = createParseResourceObject(false); @@ -810,53 +846,49 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements = new HashMap<>(); Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts = new HashMap<>(); Map<String, Map<String, ArtifactDefinition>> instArtifacts = new HashMap<>(); - Map<String, List< AttributeDefinition >> instAttributes = new HashMap<>(); + Map<String, List<AttributeDefinition>> instAttributes = new HashMap<>(); Map<String, Resource> originCompMap = new HashMap<>(); - originCompMap.put("componentUid",originResource); + originCompMap.put("componentUid", originResource); Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>(); UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo(); uploadComponentInstanceInfo.setName("zxjTestImportServiceAb0"); - try { - sIB1.processComponentInstance(yamlName, resource, componentInstancesList,allDataTypes,instProperties,instCapabilties,instRequirements, - instDeploymentArtifacts,instArtifacts,instAttributes,originCompMap,instInputs,uploadComponentInstanceInfo); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1.processComponentInstance(yamlName, + resource, componentInstancesList, allDataTypes, instProperties, instCapabilties, + instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, originCompMap, + instInputs, uploadComponentInstanceInfo)); } @Test - public void testAddInputsValuesToRi(){ + public void testAddInputsValuesToRi() { UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo(); Map<String, List<UploadPropInfo>> properties = new HashMap<>(); - List<UploadPropInfo> uploadPropInfoList = new ArrayList<>(); - UploadPropInfo uploadPropInfo = new UploadPropInfo(); - uploadPropInfo.setName("uploadPropInfo"); - uploadPropInfoList.add(uploadPropInfo); - uploadPropInfoList.add(uploadPropInfo); - properties.put("propertiesMap",uploadPropInfoList); + List<UploadPropInfo> uploadPropInfoList = getPropertyList(); + properties.put("propertiesMap", uploadPropInfoList); uploadComponentInstanceInfo.setProperties(properties); Resource resource = createParseResourceObject(true); - Resource originResource =createParseResourceObject(false); + Resource originResource = createParseResourceObject(false); List<InputDefinition> inputs = new ArrayList<>(); InputDefinition inputDefinition = new InputDefinition(); + inputDefinition.setName("inputDefinitionName"); inputDefinition.setUniqueId("uniqueId"); + inputDefinition.setType("inputDefinitionType"); inputs.add(inputDefinition); originResource.setInputs(inputs); ComponentInstance currentCompInstance = new ComponentInstance(); Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>(); Map<String, DataTypeDefinition> allDataTypes = new HashMap<>(); + DataTypeDefinition dataTypeDefinition = new DataTypeDefinition(); + dataTypeDefinition.setName("dataTypeDefinitionName"); + allDataTypes.put("dataTypeDefinitionMap", dataTypeDefinition); - try { - sIB1.addInputsValuesToRi(uploadComponentInstanceInfo,resource,originResource, - currentCompInstance,instInputs,allDataTypes); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1 + .addInputsValuesToRi(uploadComponentInstanceInfo, resource, originResource, + currentCompInstance, instInputs, allDataTypes)); } @Test - public void testProcessProperty(){ + public void testProcessProperty() { Resource resource = createParseResourceObject(true); List<InputDefinition> inputs = new ArrayList<>(); InputDefinition inputDefinition = new InputDefinition(); @@ -868,60 +900,40 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB ComponentInstance currentCompInstance = null; Map<String, DataTypeDefinition> allDataTypes = new HashMap<>(); Map<String, InputDefinition> currPropertiesMap = new HashMap<>(); - currPropertiesMap.put("propertyInfoName",inputDefinition); + currPropertiesMap.put("propertyInfoName", inputDefinition); List<ComponentInstanceInput> instPropList = new ArrayList<>(); - List<UploadPropInfo> propertyList = new ArrayList<>(); - List<GetInputValueDataDefinition> get_input = new ArrayList<>(); - GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition(); - getInputValueDataDefinition.setPropName("getInputValueDataDefinitionName"); - getInputValueDataDefinition.setInputName("inputDefinitionName"); - get_input.add(getInputValueDataDefinition); - UploadPropInfo propertyInfo = new UploadPropInfo(); - propertyInfo.setValue("value"); - propertyInfo.setGet_input(get_input); - propertyInfo.setName("propertyInfoName"); - propertyList.add(propertyInfo); - - try { - sIB1.processProperty(resource, currentCompInstance, allDataTypes, - currPropertiesMap, instPropList, propertyList); - } catch (Exception e) { - e.printStackTrace(); - } + List<UploadPropInfo> propertyList = getPropertyList(); + Assertions.assertNotNull(resource); + Assertions.assertNotNull(currPropertiesMap); + sIB1.processProperty(resource, currentCompInstance, allDataTypes, currPropertiesMap, instPropList, propertyList); } @Test - public void testHandleSubstitutionMappings(){ + public void testHandleSubstitutionMappings() { Resource resource = createParseResourceObject(true); resource.setResourceType(ResourceTypeEnum.VF); Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>(); when(toscaOperationFacade.getToscaFullElement(anyString())) .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST)); - try { - sIB1.handleSubstitutionMappings(resource, uploadResInstancesMap); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1 + .handleSubstitutionMappings(resource, uploadResInstancesMap)); } @Test - public void testHandleSubstitutionMappings_left(){ + public void testHandleSubstitutionMappings_left() { Resource resource = createParseResourceObject(true); resource.setResourceType(ResourceTypeEnum.VF); Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>(); when(toscaOperationFacade.getToscaFullElement(anyString())) .thenReturn(Either.left(resource)); - try { - sIB1.handleSubstitutionMappings(resource, uploadResInstancesMap); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1 + .handleSubstitutionMappings(resource, uploadResInstancesMap)); } @Test - public void testCreateResourceInstances(){ + public void testCreateResourceInstances() { String yamlName = "group.yml"; Resource resource = createParseResourceObject(true); Resource originResource = createParseResourceObject(false); @@ -931,41 +943,35 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB nodesInfoValue.setRequirements(gerRequirements()); uploadResInstancesMap.put("uploadComponentInstanceInfo", nodesInfoValue); Map<String, Resource> nodeNamespaceMap = new HashMap<>(); - nodeNamespaceMap.put("resources",originResource); + nodeNamespaceMap.put("resources", originResource); - try { - sIB1.createResourceInstances(yamlName,resource,uploadResInstancesMap,nodeNamespaceMap); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1 + .createResourceInstances(yamlName, resource, uploadResInstancesMap, nodeNamespaceMap)); } @Test - public void testHandleNodeTypes(){ + public void testHandleNodeTypes() throws IOException { + String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; String yamlName = "group.yml"; Resource resource = createParseResourceObject(true); String topologyTemplateYaml = getMainTemplateContent(); boolean needLock = true; Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>(); List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>(); - Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>(); - NodeTypeInfo nodeTypeInfo = new NodeTypeInfo(); - nodeTypeInfo.setNested(false); - String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; - nodeTypesInfo.put(nodeName,nodeTypeInfo); + Map<String, NodeTypeInfo> nodeTypesInfo = getNodeTypesInfo(); + Map<String, Object> map = new HashMap<>(); + map.put("tosca_definitions_version", "123"); + nodeTypesInfo.get(nodeName).setMappedToscaTemplate(map); + ParsedToscaYamlInfo parsedToscaYamlInfo = getParsedToscaYamlInfo(); CsarInfo csarInfo = getCsarInfo(); + Assertions.assertNotNull(resource); - try { - sIB1.handleNodeTypes(yamlName,resource,topologyTemplateYaml,needLock, - nodeTypesArtifactsToHandle,nodeTypesNewCreatedArtifacts,nodeTypesInfo, - csarInfo,nodeName); - } catch (Exception e) { - e.printStackTrace(); - } + sIB1.handleNodeTypes(yamlName, resource, topologyTemplateYaml, needLock, nodeTypesArtifactsToHandle, + nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, nodeName); } @Test - public void testHandleNestedVfc1(){ + public void testHandleNestedVfc1() { String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; Resource resource = createParseResourceObject(false); Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>(); @@ -974,19 +980,15 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB NodeTypeInfo nodeTypeInfo = new NodeTypeInfo(); nodeTypeInfo.setTemplateFileName("groups.yml"); nodeTypeInfo.setMappedToscaTemplate(new HashMap<>()); - nodesInfo.put(nodeName,nodeTypeInfo); + nodesInfo.put(nodeName, nodeTypeInfo); CsarInfo csarInfo = getCsarInfo(); - try { - sIB1.handleNestedVfc(resource,nodeTypesArtifactsToHandle,createdArtifacts, - nodesInfo,csarInfo,nodeName); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1.handleNestedVfc(resource, + nodeTypesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName)); } @Test - public void testHandleComplexVfc1(){ + public void testHandleComplexVfc1() { Resource resource = createParseResourceObject(true); Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>(); List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); @@ -994,19 +996,19 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB CsarInfo csarInfo = getCsarInfo(); String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; String yamlName = "group.yml"; + when(serviceImportParseLogic.buildValidComplexVfc(any(Resource.class), any(CsarInfo.class), anyString(), + anyMap())).thenReturn(createParseResourceObject(false)); when(toscaOperationFacade.getFullLatestComponentByToscaResourceName(anyString())) - .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST)); + .thenReturn(Either.left(resource)); + when(serviceImportParseLogic.validateNestedDerivedFromDuringUpdate(any(Resource.class), any(Resource.class), + anyBoolean())).thenReturn(Either.left(true)); - try { - sIB1.handleComplexVfc(resource,nodeTypesArtifactsToHandle,createdArtifacts, - nodesInfo,csarInfo,nodeName,yamlName); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1.handleComplexVfc(resource, + nodeTypesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName, yamlName)); } @Test - public void testCreateResourcesFromYamlNodeTypesList1(){ + public void testCreateResourcesFromYamlNodeTypesList1() { String yamlName = "group.yml"; Resource resource = createParseResourceObject(false); Map<String, Object> mappedToscaTemplate = new HashMap<>(); @@ -1016,17 +1018,15 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>(); CsarInfo csarInfo = getCsarInfo(); - try { - sIB1.createResourcesFromYamlNodeTypesList(yamlName,resource,mappedToscaTemplate, - needLock, nodeTypesArtifactsToHandle,nodeTypesNewCreatedArtifacts, - nodeTypesInfo,csarInfo); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1 + .createResourcesFromYamlNodeTypesList(yamlName, resource, mappedToscaTemplate, needLock, + nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo)); + } @Test - public void testCreateNodeTypes1(){ + public void testCreateNodeTypes1() { + String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; String yamlName = "group.yml"; Resource resource = createParseResourceObject(false); boolean needLock = true; @@ -1039,31 +1039,31 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB artifactDefinitions.add(artifactDefinition); enumListEnumMap.put(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE, artifactDefinitions); - nodeTypesArtifactsToHandle.put("nodeTyp",enumListEnumMap); + nodeTypesArtifactsToHandle.put("nodeTyp", enumListEnumMap); List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>(); - Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>(); - NodeTypeInfo nodeTypeInfo = new NodeTypeInfo(); - nodeTypesInfo.put("nodeTyp",nodeTypeInfo); + Map<String, NodeTypeInfo> nodeTypesInfo = getNodeTypesInfo(); + Map<String, Object> map = new HashMap<>(); + map.put("tosca_definitions_version", "123"); + nodeTypesInfo.get(nodeName).setMappedToscaTemplate(map); + ParsedToscaYamlInfo parsedToscaYamlInfo = getParsedToscaYamlInfo(); + CsarInfo csarInfo = getCsarInfo(); - Map<String, Object> mapToConvert =new HashMap<>(); - Map<String, Object> nodeTypes =new HashMap<>(); - nodeTypes.put("nodeTyp",nodeTypeInfo); + Map<String, Object> mapToConvert = new HashMap<>(); + Map<String, Object> nodeTypes = new HashMap<>(); + nodeTypes.put(nodeName, ""); + Assertions.assertNotNull(resource); - try { - sIB1.createNodeTypes(yamlName, resource, needLock, nodeTypesArtifactsToHandle, - nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, mapToConvert, - nodeTypes); - } catch (Exception e) { - e.printStackTrace(); - } + sIB1.createNodeTypes(yamlName, + resource, needLock, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, + nodeTypesInfo, csarInfo, mapToConvert, nodeTypes); } @Test - public void testCreateNodeTypeResourceFromYaml(){ + public void testCreateNodeTypeResourceFromYaml() throws IOException { String yamlName = "group.yml"; String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; - Map<String,Object> nodeMap = new HashMap<>(); - nodeMap.put(nodeName,getGroupsYaml()); + Map<String, Object> nodeMap = new HashMap<>(); + nodeMap.put(nodeName, getGroupsYaml()); Map.Entry<String, Object> nodeNameValue = nodeMap.entrySet().iterator().next(); Map<String, Object> mapToConvert = new HashedMap(); Resource resourceVf = createParseResourceObject(false); @@ -1073,93 +1073,116 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB boolean forceCertificationAllowed = true; CsarInfo csarInfo = getCsarInfo(); boolean isNested = true; - - try { - sIB1.createNodeTypeResourceFromYaml(yamlName,nodeNameValue,user,mapToConvert,resourceVf, - needLock,nodeTypeArtifactsToHandle,nodeTypesNewCreatedArtifacts, - forceCertificationAllowed,csarInfo,isNested); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void testCreateRIAndRelationsFromYaml(){ + UploadResourceInfo resourceMetaData = new UploadResourceInfo(); + resourceMetaData.setResourceType("VFC"); + ImmutablePair<Resource, ActionStatus> immutablePair = new ImmutablePair<>(resourceVf, ActionStatus.CREATED); + when(serviceImportParseLogic.fillResourceMetadata(anyString(), any(Resource.class), anyString(), any(User.class))) + .thenReturn(resourceMetaData); + when(serviceImportParseLogic.buildNodeTypeYaml(any(Map.Entry.class), anyMap(), anyString(), any(CsarInfo.class))) + .thenReturn(nodeName); + when(serviceBusinessLogic.validateUser(any(User.class), anyString(), any(Component.class), any(AuditingActionEnum.class), + anyBoolean())).thenReturn(user); + when(serviceImportParseLogic.createResourceFromNodeType(anyString(), any(UploadResourceInfo.class), any(User.class), anyBoolean(), anyBoolean(), + anyMap(), anyList(), anyBoolean(), any(CsarInfo.class), + anyString(), anyBoolean())).thenReturn(immutablePair); + Assertions.assertNotNull( + sIB1.createNodeTypeResourceFromYaml(yamlName, nodeNameValue, user, mapToConvert, + resourceVf, needLock, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, + forceCertificationAllowed, csarInfo, isNested)); + } + + @Test + public void testCreateRIAndRelationsFromYaml() { String yamlName = "group.yml"; Service service = createServiceObject(true); Map<String, UploadComponentInstanceInfo> uploadComponentInstanceInfoMap = new HashMap<>(); - String topologyTemplateYaml = getMainTemplateContent("service_import_template.yml");; + String topologyTemplateYaml = getMainTemplateContent("service_import_template.yml"); + ; List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>(); Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>(); CsarInfo csarInfo = getCsarInfo(); Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate = new HashMap<>(); String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; - try { - sIB1.createRIAndRelationsFromYaml(yamlName,service,uploadComponentInstanceInfoMap,topologyTemplateYaml,nodeTypesNewCreatedArtifacts, - nodeTypesInfo,csarInfo,nodeTypesArtifactsToCreate,nodeName); - } catch (Exception e) { - e.printStackTrace(); - } + + Assertions.assertThrows(ComponentException.class, () -> sIB1 + .createRIAndRelationsFromYaml(yamlName, service, uploadComponentInstanceInfoMap, + topologyTemplateYaml, nodeTypesNewCreatedArtifacts, nodeTypesInfo, + csarInfo, nodeTypesArtifactsToCreate, nodeName)); } @Test - public void testCreateServiceInstancesRelations(){ + public void testCreateServiceInstancesRelations() { String yamlName = "group.yml"; Service service = createServiceObject(true); service.setComponentInstances(creatComponentInstances()); - Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>(); - uploadResInstancesMap.put("uploadResInstancesMap",getuploadComponentInstanceInfo()); - - try { - sIB1.createServiceInstancesRelations(user, yamlName, service, uploadResInstancesMap); - } catch (Exception e) { - e.printStackTrace(); - } + Resource newResource = createNewResource(); + Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = getUploadResInstancesMap(); + ComponentParametersView componentParametersView = new ComponentParametersView(); + RequirementDefinition requirementDefinition = new RequirementDefinition(); + CapabilityDefinition capabilityDefinition = new CapabilityDefinition(); + capabilityDefinition.setName("as"); + capabilityDefinition.setUniqueId("1"); + capabilityDefinition.setOwnerId("2"); + ResponseFormat responseFormat = new ResponseFormat(); + responseFormat.setStatus(200); + when(serviceImportParseLogic.getResourceAfterCreateRelations(any(Resource.class))).thenReturn(newResource); + when(serviceImportParseLogic.getComponentFilterAfterCreateRelations()).thenReturn(componentParametersView); + when(toscaOperationFacade.getToscaElement(anyString(), any(ComponentParametersView.class))).thenReturn(Either.left(service)); + when(serviceImportParseLogic.findAviableRequiremen(anyString(), + anyString(), any(UploadComponentInstanceInfo.class), any(ComponentInstance.class), + anyString())).thenReturn(Either.left(requirementDefinition)); + when(serviceImportParseLogic.findAvailableCapabilityByTypeOrName(any(RequirementDefinition.class), + 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(sIB1 + .createServiceInstancesRelations(user, yamlName, service, uploadResInstancesMap)); } @Test - public void testCreateServiceInstancesRelations_Empty(){ + public void testCreateServiceInstancesRelations_Empty() { String yamlName = "group.yml"; Service service = createServiceObject(true); service.setComponentInstances(creatComponentInstances()); Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>(); - try { - sIB1.createServiceInstancesRelations(user, yamlName, service, uploadResInstancesMap); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1 + .createServiceInstancesRelations(user, yamlName, service, uploadResInstancesMap)); } @Test - public void testProcessComponentInstance(){ + public void testProcessComponentInstance() { String yamlName = "group.yml"; Service service = createServiceObject(true); Resource originResource = createParseResourceObject(false); + originResource.setResourceType(ResourceTypeEnum.VF); List<ComponentInstance> componentInstancesList = creatComponentInstances(); - Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = null; + Map<String, DataTypeDefinition> dataTypeDefinitionMap = new HashMap<>(); + DataTypeDefinition dataTypeDefinition = new DataTypeDefinition(); + dataTypeDefinition.setName("dataTypeDefinitionName"); + dataTypeDefinitionMap.put("dataTypeDefinitionMap", dataTypeDefinition); + Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = Either.left(dataTypeDefinitionMap); Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>(); Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilties = new HashMap<>(); Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements = new HashMap<>(); Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts = new HashMap<>(); Map<String, Map<String, ArtifactDefinition>> instArtifacts = new HashMap<>(); - Map<String, List< AttributeDefinition >> instAttributes = new HashMap<>(); + Map<String, List<AttributeDefinition>> instAttributes = new HashMap<>(); Map<String, Resource> originCompMap = new HashMap<>(); - originCompMap.put("componentUid",originResource); + originCompMap.put("componentUid", originResource); Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>(); UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo(); uploadComponentInstanceInfo.setName("zxjTestImportServiceAb"); + Assertions.assertNotNull(service); - try { - sIB1.processComponentInstance(yamlName, service, componentInstancesList,allDataTypes,instProperties,instCapabilties,instRequirements, - instDeploymentArtifacts,instArtifacts,instAttributes,originCompMap,instInputs,uploadComponentInstanceInfo); - } catch (Exception e) { - e.printStackTrace(); - } + sIB1.processComponentInstance(yamlName, service, componentInstancesList, allDataTypes, + instProperties, instCapabilties, instRequirements, instDeploymentArtifacts, + instArtifacts, instAttributes, originCompMap, instInputs, + uploadComponentInstanceInfo); } @Test - public void testProcessComponentInstance_null2(){ + public void testProcessComponentInstance_null2() { String yamlName = "group.yml"; Service service = createServiceObject(true); Resource originResource = createParseResourceObject(false); @@ -1170,23 +1193,21 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements = new HashMap<>(); Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts = new HashMap<>(); Map<String, Map<String, ArtifactDefinition>> instArtifacts = new HashMap<>(); - Map<String, List< AttributeDefinition >> instAttributes = new HashMap<>(); + Map<String, List<AttributeDefinition>> instAttributes = new HashMap<>(); Map<String, Resource> originCompMap = new HashMap<>(); - originCompMap.put("componentUid",originResource); + originCompMap.put("componentUid", originResource); Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>(); UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo(); uploadComponentInstanceInfo.setName("zxjTestImportServiceAb0"); - try { - sIB1.processComponentInstance(yamlName, service, componentInstancesList,allDataTypes,instProperties,instCapabilties,instRequirements, - instDeploymentArtifacts,instArtifacts,instAttributes,originCompMap,instInputs,uploadComponentInstanceInfo); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1.processComponentInstance(yamlName, + service, componentInstancesList, allDataTypes, instProperties, instCapabilties, + instRequirements, instDeploymentArtifacts, instArtifacts, instAttributes, originCompMap, + instInputs, uploadComponentInstanceInfo)); } @Test - public void testAddInputsValuesToRi2(){ + public void testAddInputsValuesToRi2() { UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo(); Map<String, List<UploadPropInfo>> properties = new HashMap<>(); List<UploadPropInfo> uploadPropInfoList = new ArrayList<>(); @@ -1194,10 +1215,10 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB uploadPropInfo.setName("uploadPropInfo"); uploadPropInfoList.add(uploadPropInfo); uploadPropInfoList.add(uploadPropInfo); - properties.put("propertiesMap",uploadPropInfoList); + properties.put("propertiesMap", uploadPropInfoList); uploadComponentInstanceInfo.setProperties(properties); Service resource = createServiceObject(true); - Resource originResource =createParseResourceObject(false); + Resource originResource = createParseResourceObject(false); List<InputDefinition> inputs = new ArrayList<>(); InputDefinition inputDefinition = new InputDefinition(); inputDefinition.setUniqueId("uniqueId"); @@ -1207,16 +1228,13 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>(); Map<String, DataTypeDefinition> allDataTypes = new HashMap<>(); - try { - sIB1.addInputsValuesToRi(uploadComponentInstanceInfo,resource,originResource, - currentCompInstance,instInputs,allDataTypes); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1 + .addInputsValuesToRi(uploadComponentInstanceInfo, resource, originResource, + currentCompInstance, instInputs, allDataTypes)); } @Test - public void testProcessProperty2(){ + public void testProcessProperty2() { Service resource = createServiceObject(true); List<InputDefinition> inputs = new ArrayList<>(); ComponentInstance currentCompInstance = null; @@ -1226,7 +1244,7 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB inputDefinition.setName("inputDefinitionName"); inputDefinition.setType("inputDefinitionType"); inputs.add(inputDefinition); - currPropertiesMap.put("propertyInfoName",inputDefinition); + currPropertiesMap.put("propertyInfoName", inputDefinition); resource.setInputs(inputs); List<ComponentInstanceInput> instPropList = new ArrayList<>(); List<UploadPropInfo> propertyList = new ArrayList<>(); @@ -1240,30 +1258,23 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB propertyInfo.setGet_input(get_input); propertyInfo.setName("propertyInfoName"); propertyList.add(propertyInfo); + Assertions.assertNotNull(resource); - try { - sIB1.processProperty(resource, currentCompInstance, allDataTypes, - currPropertiesMap, instPropList, propertyList); - } catch (Exception e) { - e.printStackTrace(); - } + sIB1.processProperty(resource, currentCompInstance, allDataTypes, currPropertiesMap, instPropList, propertyList); } @Test - public void testProcessGetInput(){ + public void testProcessGetInput() { List<GetInputValueDataDefinition> getInputValues = new ArrayList<>(); List<InputDefinition> inputs = new ArrayList<>(); GetInputValueDataDefinition getInputIndex = new GetInputValueDataDefinition(); - try { - sIB1.processGetInput(getInputValues,inputs,getInputIndex); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1.processGetInput(getInputValues, + inputs, getInputIndex)); } @Test - public void testProcessGetInput_optional(){ + public void testProcessGetInput_optional() { List<GetInputValueDataDefinition> getInputValues = new ArrayList<>(); List<InputDefinition> inputs = new ArrayList<>(); InputDefinition inputDefinition = new InputDefinition(); @@ -1272,30 +1283,39 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB inputs.add(inputDefinition); GetInputValueDataDefinition getInputIndex = new GetInputValueDataDefinition(); getInputIndex.setInputName("InputName"); + Assertions.assertNotNull(inputs); - sIB1.processGetInput(getInputValues,inputs,getInputIndex); + sIB1.processGetInput(getInputValues, inputs, getInputIndex); } @Test - public void testAddPropertyValuesToRi(){ + public void testAddPropertyValuesToRi() { UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo(); uploadComponentInstanceInfo.setProperties(getUploadPropInfoProperties()); Resource resource = createParseResourceObject(true); + List<InputDefinition> inputs = new ArrayList<>(); + InputDefinition inputDefinition = new InputDefinition(); + inputDefinition.setName("inputDefinitionName"); + inputDefinition.setUniqueId("uniqueId"); + inputDefinition.setType("inputDefinitionType"); + inputs.add(inputDefinition); + resource.setInputs(inputs); Resource originResource = createParseResourceObject(false); originResource.setProperties(getProperties()); ComponentInstance currentCompInstance = new ComponentInstance(); Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>(); Map<String, DataTypeDefinition> allDataTypes = new HashMap<>(); - try { - sIB1.addPropertyValuesToRi(uploadComponentInstanceInfo, resource, originResource, currentCompInstance, - instProperties, allDataTypes); - } catch (Exception e) { - e.printStackTrace(); - } + ResponseFormat responseFormat = new ResponseFormat(); + when(serviceImportParseLogic.findInputByName(anyList(), any(GetInputValueDataDefinition.class))) + .thenReturn(inputDefinition); + when(componentsUtils.getResponseFormat(any(ActionStatus.class))).thenReturn(responseFormat); + Assertions.assertNotNull( + sIB1.addPropertyValuesToRi(uploadComponentInstanceInfo, resource, originResource, + currentCompInstance, instProperties, allDataTypes)); } @Test - public void testAddPropertyValuesToRi_else(){ + public void testAddPropertyValuesToRi_else() { UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo(); Resource resource = createParseResourceObject(true); Resource originResource = createParseResourceObject(false); @@ -1303,175 +1323,176 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB ComponentInstance currentCompInstance = new ComponentInstance(); Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>(); Map<String, DataTypeDefinition> allDataTypes = new HashMap<>(); - try { - sIB1.addPropertyValuesToRi(uploadComponentInstanceInfo, resource, originResource, currentCompInstance, - instProperties, allDataTypes); - } catch (Exception e) { - e.printStackTrace(); - } + ResponseFormat responseFormat = new ResponseFormat(); + when(componentsUtils.getResponseFormat(any(ActionStatus.class))).thenReturn(responseFormat); + Assertions.assertNotNull( + sIB1.addPropertyValuesToRi(uploadComponentInstanceInfo, resource, originResource, currentCompInstance, + instProperties, allDataTypes)); + } @Test - public void testAddPropertyValuesToRi2(){ + public void testAddPropertyValuesToRi2() { UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo(); uploadComponentInstanceInfo.setProperties(getUploadPropInfoProperties()); - Service service = createServiceObject(false); + Service service = createServiceObject(true); + List<InputDefinition> inputs = new ArrayList<>(); + InputDefinition inputDefinition = new InputDefinition(); + inputDefinition.setName("inputDefinitionName"); + inputDefinition.setUniqueId("uniqueId"); + inputDefinition.setType("inputDefinitionType"); + inputs.add(inputDefinition); + service.setInputs(inputs); Resource originResource = createParseResourceObject(false); originResource.setProperties(getProperties()); ComponentInstance currentCompInstance = new ComponentInstance(); Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>(); Map<String, DataTypeDefinition> allDataTypes = new HashMap<>(); - - try { - sIB1.addPropertyValuesToRi(uploadComponentInstanceInfo, service, originResource, currentCompInstance, - instProperties, allDataTypes); - } catch (Exception e) { - e.printStackTrace(); - } + ResponseFormat responseFormat = new ResponseFormat(); + when(componentsUtils.getResponseFormat(any(ActionStatus.class))).thenReturn(responseFormat); + when(serviceImportParseLogic.findInputByName(anyList(), any(GetInputValueDataDefinition.class))) + .thenReturn(inputDefinition); + Assertions.assertNotNull( + sIB1.addPropertyValuesToRi(uploadComponentInstanceInfo, service, originResource, + currentCompInstance, instProperties, allDataTypes)); } @Test - public void testAddPropertyValuesToRi2_else(){ + public void testAddPropertyValuesToRi2_else() { UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo(); - Service service = createServiceObject(false); + Service service = createServiceObject(true); Resource originResource = createParseResourceObject(false); originResource.setProperties(getProperties()); ComponentInstance currentCompInstance = new ComponentInstance(); Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>(); Map<String, DataTypeDefinition> allDataTypes = new HashMap<>(); - - try { - sIB1.addPropertyValuesToRi(uploadComponentInstanceInfo, service, originResource, currentCompInstance, - instProperties, allDataTypes); - } catch (Exception e) { - e.printStackTrace(); - } + ResponseFormat responseFormat = new ResponseFormat(); + when(componentsUtils.getResponseFormat(any(ActionStatus.class))).thenReturn(responseFormat); + Assertions.assertNotNull( + sIB1.addPropertyValuesToRi(uploadComponentInstanceInfo, service, originResource, currentCompInstance, + instProperties, allDataTypes)); } @Test - public void testProcessComponentInstanceCapabilities(){ + public void testProcessComponentInstanceCapabilities() { Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = null; Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilties = new HashMap<>(); UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo(); uploadComponentInstanceInfo.setCapabilities(getCapabilities()); ComponentInstance currentCompInstance = new ComponentInstance(); Resource originResource = createParseResourceObject(false); - - sIB1.processComponentInstanceCapabilities(allDataTypes, instCapabilties, uploadComponentInstanceInfo, - currentCompInstance, originResource); + Assertions.assertNotNull(originResource); + sIB1.processComponentInstanceCapabilities(allDataTypes, instCapabilties, + uploadComponentInstanceInfo, currentCompInstance, originResource); } @Test - public void testProcessComponentInstanceCapabilities_null(){ + public void testProcessComponentInstanceCapabilities_null() { Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = null; Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilties = new HashMap<>(); UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo(); ComponentInstance currentCompInstance = new ComponentInstance(); Resource originResource = createParseResourceObject(false); + Assertions.assertNotNull(originResource); sIB1.processComponentInstanceCapabilities(allDataTypes, instCapabilties, uploadComponentInstanceInfo, currentCompInstance, originResource); } @Test - public void testUpdateCapabilityPropertiesValues(){ + public void testUpdateCapabilityPropertiesValues() { Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = null; Map<String, List<CapabilityDefinition>> originCapabilities = new HashMap<>(); Map<String, Map<String, UploadPropInfo>> newPropertiesMap = new HashMap<>(); - + Assertions.assertNull(allDataTypes); sIB1.updateCapabilityPropertiesValues(allDataTypes, originCapabilities, newPropertiesMap); } @Test - public void testUpdatePropertyValues(){ + public void testUpdatePropertyValues() { List<ComponentInstanceProperty> properties = new ArrayList<>(); Map<String, UploadPropInfo> newProperties = new HashMap<>(); Map<String, DataTypeDefinition> allDataTypes = new HashMap<>(); - - sIB1.updatePropertyValues(properties,newProperties,allDataTypes); + Assertions.assertNotNull(allDataTypes); + sIB1.updatePropertyValues(properties, newProperties, allDataTypes); } @Test - public void testUpdatePropertyValue(){ + public void testUpdatePropertyValue() { ComponentInstanceProperty property = new ComponentInstanceProperty(); property.setType("services"); UploadPropInfo propertyInfo = new UploadPropInfo(); propertyInfo.setValue("value"); Map<String, DataTypeDefinition> allDataTypes = new HashMap<>(); - - try { - sIB1.updatePropertyValue(property,propertyInfo,allDataTypes); - } catch (Exception e) { - e.printStackTrace(); - } + when(serviceBusinessLogic.validatePropValueBeforeCreate(any(IPropertyInputCommon.class), anyString(), anyBoolean(), anyMap())).thenReturn("qw"); + Assertions.assertNotNull( + sIB1.updatePropertyValue(property, propertyInfo, allDataTypes)); } @Test - public void testGetOriginResource(){ + public void testGetOriginResource() { String yamlName = "group.yml"; Map<String, Resource> originCompMap = new HashMap<>(); ComponentInstance currentCompInstance = new ComponentInstance(); currentCompInstance.setComponentUid("currentCompInstance"); - - try { - sIB1.getOriginResource(yamlName,originCompMap,currentCompInstance); - } catch (Exception e) { - e.printStackTrace(); - } + when(toscaOperationFacade.getToscaFullElement(anyString())) + .thenReturn(Either.left(createParseResourceObject(true))); + Assertions.assertNotNull( + sIB1.getOriginResource(yamlName, originCompMap, currentCompInstance)); } @Test - public void testHandleSubstitutionMappings2(){ - Service service = createServiceObject(false); + public void testHandleSubstitutionMappings2() { + Service service = createServiceObject(true); Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>(); + Assertions.assertNotNull(service); sIB1.handleSubstitutionMappings(service, uploadResInstancesMap); } @Test - public void testUpdateCalculatedCapReqWithSubstitutionMappings(){ + public void testUpdateCalculatedCapReqWithSubstitutionMappings() { Resource resource = createParseResourceObject(false); - Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>(); + resource.setComponentInstances(creatComponentInstances()); + Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = getUploadResInstancesMap(); when(toscaOperationFacade.deleteAllCalculatedCapabilitiesRequirements(any())).thenReturn(StorageOperationStatus.OK); - - try { - sIB1.updateCalculatedCapReqWithSubstitutionMappings(resource,uploadResInstancesMap); - } catch (Exception e) { - - } + Assertions.assertNotNull( + sIB1.updateCalculatedCapReqWithSubstitutionMappings(resource, uploadResInstancesMap)); } @Test - public void testFillUpdatedInstCapabilitiesRequirements(){ + public void testFillUpdatedInstCapabilitiesRequirements() { List<ComponentInstance> componentInstances = creatComponentInstances(); Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = getUploadResInstancesMap(); Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> updatedInstCapabilities = new HashMap<>(); Map<ComponentInstance, Map<String, List<RequirementDefinition>>> updatedInstRequirement = new HashMap<>(); + Assertions.assertNotNull(componentInstances); - sIB1.fillUpdatedInstCapabilitiesRequirements(componentInstances,uploadResInstancesMap, - updatedInstCapabilities,updatedInstRequirement); + sIB1.fillUpdatedInstCapabilitiesRequirements(componentInstances, uploadResInstancesMap, + updatedInstCapabilities, updatedInstRequirement); } @Test - public void testFillUpdatedInstCapabilities(){ + public void testFillUpdatedInstCapabilities() { Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> updatedInstCapabilties = new HashMap<>(); Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>(); List<CapabilityDefinition> capabilityDefinitionList = new ArrayList<>(); CapabilityDefinition capabilityDefinition = new CapabilityDefinition(); capabilityDefinition.setName("mme_ipu_vdu.feature"); capabilityDefinitionList.add(capabilityDefinition); - capabilities.put("tosca.capabilities.Node",capabilityDefinitionList); + capabilities.put("tosca.capabilities.Node", capabilityDefinitionList); ComponentInstance instance = new ComponentInstance(); instance.setCapabilities(capabilities); Map<String, String> capabilitiesNamesToUpdate = new HashMap<>(); - capabilitiesNamesToUpdate.put("mme_ipu_vdu.feature","capabilitiesNamesToUpdate"); + capabilitiesNamesToUpdate.put("mme_ipu_vdu.feature", "capabilitiesNamesToUpdate"); + Assertions.assertNotNull(instance); - sIB1.fillUpdatedInstCapabilities(updatedInstCapabilties,instance,capabilitiesNamesToUpdate); + sIB1.fillUpdatedInstCapabilities(updatedInstCapabilties, instance, capabilitiesNamesToUpdate); } @Test - public void testFillUpdatedInstRequirements(){ + public void testFillUpdatedInstRequirements() { Map<ComponentInstance, Map<String, List<RequirementDefinition>>> updatedInstRequirements = new HashMap<>(); ComponentInstance instance = new ComponentInstance(); @@ -1480,141 +1501,153 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB RequirementDefinition requirementDefinition = new RequirementDefinition(); requirementDefinition.setName("zxjtestimportserviceab0.mme_ipu_vdu.dependency.test"); requirementDefinitionList.add(requirementDefinition); - requirements.put("tosca.capabilities.Node",requirementDefinitionList); + requirements.put("tosca.capabilities.Node", requirementDefinitionList); instance.setRequirements(requirements); Map<String, String> requirementsNamesToUpdate = new HashMap<>(); requirementsNamesToUpdate.put("zxjtestimportserviceab0.mme_ipu_vdu.dependency.test", "requirementsNamesToUpdate"); + Assertions.assertNotNull(instance); - - sIB1.fillUpdatedInstRequirements(updatedInstRequirements,instance,requirementsNamesToUpdate); + sIB1.fillUpdatedInstRequirements(updatedInstRequirements, instance, requirementsNamesToUpdate); } @Test - public void testAddRelationsToRI(){ + public void testAddRelationsToRI() { String yamlName = "group.yml"; - Service service = createServiceObject(false); + Service service = createServiceObject(true); + Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>(); UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo(); uploadResInstancesMap.put("uploadComponentInstanceInfo", nodesInfoValue); List<ComponentInstance> componentInstancesList = creatComponentInstances(); + ComponentInstance componentInstance = new ComponentInstance(); + componentInstance.setName("zxjTestImportServiceAb"); + componentInstancesList.add(componentInstance); + service.setComponentInstances(componentInstancesList); List<RequirementCapabilityRelDef> relations = new ArrayList<>(); + RequirementDefinition requirementDefinition = new RequirementDefinition(); + requirementDefinition.setOwnerId("1"); + requirementDefinition.setUniqueId("2"); + requirementDefinition.setCapability("3"); + CapabilityDefinition capabilityDefinition = new CapabilityDefinition(); + capabilityDefinition.setName("4"); + capabilityDefinition.setUniqueId("5"); + capabilityDefinition.setOwnerId("6"); + ResponseFormat responseFormat = new ResponseFormat(); + responseFormat.setStatus(200); + when(serviceImportParseLogic.findAviableRequiremen(anyString(), + anyString(), any(UploadComponentInstanceInfo.class), any(ComponentInstance.class), + anyString())).thenReturn(Either.left(requirementDefinition)); + when(serviceImportParseLogic.findAvailableCapabilityByTypeOrName(any(RequirementDefinition.class), + any(ComponentInstance.class), any(UploadReqInfo.class))).thenReturn(capabilityDefinition); + when(componentsUtils.getResponseFormat(any(ActionStatus.class), anyString())).thenReturn(responseFormat); + Assertions.assertNotNull(service); - try { - sIB1.addRelationsToRI(yamlName,service,uploadResInstancesMap,componentInstancesList, - relations); - } catch (Exception e) { - e.printStackTrace(); - } + sIB1.addRelationsToRI(yamlName, service, uploadResInstancesMap, componentInstancesList, relations); } @Test - public void testAddRelationsToRI_null(){ + public void testAddRelationsToRI_null() { String yamlName = "group.yml"; - Service service = createServiceObject(false); + Service service = createServiceObject(true); Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>(); UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo(); uploadResInstancesMap.put("uploadComponentInstanceInfo", nodesInfoValue); List<ComponentInstance> componentInstancesList = new ArrayList<>(); List<RequirementCapabilityRelDef> relations = new ArrayList<>(); - try { - sIB1.addRelationsToRI(yamlName,service,uploadResInstancesMap,componentInstancesList, - relations); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1.addRelationsToRI(yamlName, + service, uploadResInstancesMap, componentInstancesList, relations)); } @Test - public void testAddRelationToRI(){ + public void testAddRelationToRI() { String yamlName = "group.yml"; - Service service = createServiceObject(false); + Service service = createServiceObject(true); service.setComponentInstances(creatComponentInstances()); UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo(); List<RequirementCapabilityRelDef> relations = new ArrayList<>(); - - try { - sIB1.addRelationToRI(yamlName,service,nodesInfoValue,relations); - } catch (Exception e) { - e.printStackTrace(); - } + RequirementDefinition requirementDefinition = new RequirementDefinition(); + requirementDefinition.setName("zxjtestimportserviceab0.mme_ipu_vdu.dependency.test"); + CapabilityDefinition capabilityDefinition = new CapabilityDefinition(); + capabilityDefinition.setName("capabilityDefinitionName"); + capabilityDefinition.setUniqueId("capabilityDefinitionUniqueId"); + capabilityDefinition.setOwnerId("capabilityDefinitionOwnerId"); + ResponseFormat responseFormat = new ResponseFormat(); + when(serviceImportParseLogic.findAviableRequiremen(anyString(), anyString(), any(UploadComponentInstanceInfo.class), + any(ComponentInstance.class), anyString())).thenReturn(Either.left(requirementDefinition)); + when(serviceImportParseLogic.findAvailableCapabilityByTypeOrName(any(RequirementDefinition.class), + any(ComponentInstance.class), any(UploadReqInfo.class))).thenReturn(capabilityDefinition); + when(componentsUtils.getResponseFormat(any(ActionStatus.class), anyString())).thenReturn(responseFormat); + Assertions.assertNotNull( + sIB1.addRelationToRI(yamlName, service, nodesInfoValue, relations)); } @Test - public void testAddRelationToRI_null(){ + public void testAddRelationToRI_null() { String yamlName = "group.yml"; - Service service = createServiceObject(false); + Service service = createServiceObject(true); List<ComponentInstance> componentInstancesList = new ArrayList<>(); service.setComponentInstances(componentInstancesList); - + ResponseFormat responseFormat = new ResponseFormat(); UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo(); List<RequirementCapabilityRelDef> relations = new ArrayList<>(); + when(componentsUtils.getResponseFormat(any(ActionStatus.class), anyString())).thenReturn(responseFormat); + Assertions.assertNotNull( + sIB1.addRelationToRI(yamlName, service, nodesInfoValue, relations)); - try { - sIB1.addRelationToRI(yamlName,service,nodesInfoValue,relations); - } catch (Exception e) { - e.printStackTrace(); - } } @Test - public void testGetResourceAfterCreateRelations(){ - Service service = createServiceObject(false); + public void testGetResourceAfterCreateRelations() { + Service service = createServiceObject(true); ComponentParametersView componentParametersView = createComponentParametersView(); when(serviceImportParseLogic.getComponentFilterAfterCreateRelations()).thenReturn(componentParametersView); - try { - sIB1.getResourceAfterCreateRelations(service); - } catch (Exception e) { - e.printStackTrace(); - } + when(toscaOperationFacade.getToscaElement(anyString(), any(ComponentParametersView.class))) + .thenReturn(Either.left(createServiceObject(true))); + Assertions.assertNotNull( + sIB1.getResourceAfterCreateRelations(service)); } @Test - public void testCreateServiceInstances(){ + public void testCreateServiceInstances() { String yamlName = "group.yml"; - Service service = createServiceObject(false); + Service service = createServiceObject(true); Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>(); UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo(); - uploadResInstancesMap.put("uploadResInstancesMap",nodesInfoValue); + uploadResInstancesMap.put("uploadResInstancesMap", nodesInfoValue); Map<String, Resource> nodeNamespaceMap = new HashMap<>(); Resource resource = createParseResourceObject(true); resource.setToscaResourceName("toscaResourceName"); - nodeNamespaceMap.put("nodeNamespaceMap",resource); + nodeNamespaceMap.put("nodeNamespaceMap", resource); - try { - sIB1.createServiceInstances(yamlName,service,uploadResInstancesMap,nodeNamespaceMap); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1 + .createServiceInstances(yamlName, service, uploadResInstancesMap, nodeNamespaceMap)); } @Test - public void testCreateAndAddResourceInstance(){ + public void testCreateAndAddResourceInstance() { UploadComponentInstanceInfo uploadComponentInstanceInfo = getuploadComponentInstanceInfo(); String yamlName = "group.yml"; Resource resource = createParseResourceObject(false); Resource originResource = createParseResourceObject(true); originResource.setResourceType(ResourceTypeEnum.VF); Map<String, Resource> nodeNamespaceMap = new HashMap<>(); - nodeNamespaceMap.put("resources",originResource); + nodeNamespaceMap.put("resources", originResource); Map<String, Resource> existingnodeTypeMap = new HashMap<>(); Map<ComponentInstance, Resource> resourcesInstancesMap = new HashMap<>(); - try { - sIB1.createAndAddResourceInstance(uploadComponentInstanceInfo,yamlName,resource,nodeNamespaceMap, - existingnodeTypeMap,resourcesInstancesMap); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1 + .createAndAddResourceInstance(uploadComponentInstanceInfo, yamlName, resource, + nodeNamespaceMap, existingnodeTypeMap, resourcesInstancesMap)); } @Test - public void testCreateAndAddResourceInstances(){ + public void testCreateAndAddResourceInstances() { UploadComponentInstanceInfo uploadComponentInstanceInfo = getuploadComponentInstanceInfo(); String yamlName = "group.yml"; - Service service = createServiceObject(false); + Service service = createServiceObject(true); service.setServiceType("services"); Resource originResource = createParseResourceObject(true); originResource.setResourceType(ResourceTypeEnum.VF); @@ -1623,16 +1656,13 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB Map<String, Resource> existingnodeTypeMap = new HashMap<>(); Map<ComponentInstance, Resource> resourcesInstancesMap = new HashMap<>(); - try { - sIB1.createAndAddResourceInstance(uploadComponentInstanceInfo, yamlName, service, nodeNamespaceMap, - existingnodeTypeMap, resourcesInstancesMap); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1 + .createAndAddResourceInstance(uploadComponentInstanceInfo, yamlName, service, + nodeNamespaceMap, existingnodeTypeMap, resourcesInstancesMap)); } @Test - public void testValidateResourceInstanceBeforeCreate(){ + public void testValidateResourceInstanceBeforeCreate() { String yamlName = "group.yml"; UploadComponentInstanceInfo uploadComponentInstanceInfo = getuploadComponentInstanceInfo(); Resource originResource = createParseResourceObject(true); @@ -1646,21 +1676,18 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB originResource.setResourceType(ResourceTypeEnum.VF); Map<String, Resource> nodeNamespaceMap = new HashMap<>(); nodeNamespaceMap.put("resources", originResource); - when( toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())) + when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())) .thenReturn(Either.left(originResource)); - - try { - sIB1.validateResourceInstanceBeforeCreate(yamlName,uploadComponentInstanceInfo,nodeNamespaceMap); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertNotNull( + sIB1.validateResourceInstanceBeforeCreate(yamlName, uploadComponentInstanceInfo, nodeNamespaceMap)); } @Test - public void testHandleServiceNodeTypes(){ + public void testHandleServiceNodeTypes() { String yamlName = "group.yml"; - Service service =createServiceObject(false); - String topologyTemplateYaml = getMainTemplateContent("service_import_template.yml");; + Service service = createServiceObject(true); + String topologyTemplateYaml = getMainTemplateContent("service_import_template.yml"); + ; boolean needLock = true; Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>(); List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>(); @@ -1669,6 +1696,7 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString())) .thenReturn(Either.left(createOldResource())); + Assertions.assertNotNull(service); sIB1.handleServiceNodeTypes(yamlName, service, topologyTemplateYaml, needLock, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, @@ -1676,72 +1704,78 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB } @Test - public void testValidateResourceNotExisted(){ + public void testValidateResourceNotExisted() { String type = "org.openecomp.resource.vf"; - boolean b = false; - try { - b = sIB1.validateResourceNotExisted(type); - } catch (Exception e) { - e.printStackTrace(); - } + + Assertions.assertThrows(ComponentException.class, () -> sIB1.validateResourceNotExisted(type)); } @Test - public void testHandleNestedVF(){ - Service service =createServiceObject(false); + public void testHandleNestedVF() { + Service service = createServiceObject(true); Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>(); List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); Map<String, NodeTypeInfo> nodesInfo = getNodeTypesInfo(); CsarInfo csarInfo = getCsarInfo(); String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; - try { - sIB1.handleNestedVF(service,nodeTypesArtifactsToHandle,createdArtifacts, - nodesInfo,csarInfo,nodeName); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1.handleNestedVF(service, + nodeTypesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName)); } @Test - public void testHandleNestedVfc(){ - Service service =createServiceObject(false); + public void testHandleNestedVfc() { + Service service = createServiceObject(true); Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>(); List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); Map<String, NodeTypeInfo> nodesInfo = new HashMap<>(); CsarInfo csarInfo = getCsarInfo(); String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; - try { - sIB1.handleNestedVfc(service,nodeTypesArtifactsToHandle,createdArtifacts, - nodesInfo,csarInfo,nodeName); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1.handleNestedVfc(service, + nodeTypesArtifactsToHandle, createdArtifacts, nodesInfo, csarInfo, nodeName)); } @Test - public void testHandleComplexVfc(){ + public void testHandleComplexVfc() { Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>(); List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); Map<String, NodeTypeInfo> nodesInfo = new HashMap<>(); CsarInfo csarInfo = getCsarInfo(); String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; String yamlName = "group.yml"; + when(serviceImportParseLogic.buildValidComplexVfc(any(CsarInfo.class), anyString(), anyMap())) + .thenReturn(createNewResource()); when(toscaOperationFacade.getFullLatestComponentByToscaResourceName(anyString())) .thenReturn(Either.left(createNewResource())); + when(serviceImportParseLogic.validateNestedDerivedFromDuringUpdate(any(Resource.class), any(Resource.class), anyBoolean())) + .thenReturn(Either.left(true)); - try { - sIB1.handleComplexVfc(nodeTypesArtifactsToHandle,createdArtifacts, - nodesInfo,csarInfo,nodeName,yamlName); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1 + .handleComplexVfc(nodeTypesArtifactsToHandle, createdArtifacts, nodesInfo, + csarInfo, nodeName, yamlName)); } + @Test + public void testHandleComplexVfcStatus() { + Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>(); + List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); + Map<String, NodeTypeInfo> nodesInfo = new HashMap<>(); + CsarInfo csarInfo = getCsarInfo(); + String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; + String yamlName = "group.yml"; + when(serviceImportParseLogic.buildValidComplexVfc(any(CsarInfo.class), anyString(), anyMap())) + .thenReturn(createNewResource()); + when(toscaOperationFacade.getFullLatestComponentByToscaResourceName(anyString())) + .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + + Assertions.assertThrows(ComponentException.class, () -> sIB1 + .handleComplexVfc(nodeTypesArtifactsToHandle, createdArtifacts, nodesInfo, + csarInfo, nodeName, yamlName)); + } @Test - public void testHandleComplexVfc2(){ + public void testHandleComplexVfc2() { Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>(); List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); Map<String, NodeTypeInfo> nodesInfo = getNodeTypesInfo(); @@ -1749,127 +1783,128 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB String yamlName = "group.yml"; CsarInfo csarInfo = getCsarInfo(); Map<String, byte[]> csar = new HashMap<>(); - csar.put(yamlName,yamlName.getBytes()); + csar.put(yamlName, yamlName.getBytes()); csarInfo.setCsar(csar); Resource oldComplexVfc = createParseResourceObject(false); Resource newComplexVfc = createParseResourceObject(true); - try { - sIB1.handleComplexVfc(nodeTypesArtifactsToHandle,createdArtifacts,nodesInfo, - csarInfo,nodeName,yamlName,oldComplexVfc,newComplexVfc); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1 + .handleComplexVfc(nodeTypesArtifactsToHandle, createdArtifacts, nodesInfo, + csarInfo, nodeName, yamlName, oldComplexVfc, newComplexVfc)); } @Test - public void testUpdateResourceFromYaml(){ - Resource oldRresource = createParseResourceObject(false); - Resource newRresource = createParseResourceObject(true); + public void testUpdateResourceFromYaml() throws IOException { + String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; + Resource newResource = createNewResource(); + Resource oldResource = createOldResource(); AuditingActionEnum actionEnum = AuditingActionEnum.CREATE_RESOURCE; List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); String yamlFileName = "group.yml"; String yamlFileContent = getYamlFileContent(); CsarInfo csarInfo = getCsarInfo(); - Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>(); + Map<String, NodeTypeInfo> nodeTypesInfo = getNodeTypesInfo(); + Map<String, Object> map = new HashMap<>(); + map.put("tosca_definitions_version", "123"); + nodeTypesInfo.get(nodeName).setMappedToscaTemplate(map); Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>(); - String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; boolean isNested = true; - try { - sIB1.updateResourceFromYaml(oldRresource,newRresource,actionEnum,createdArtifacts,yamlFileName,yamlFileContent, - csarInfo,nodeTypesInfo,nodeTypesArtifactsToHandle,nodeName,isNested); - } catch (Exception e) { - - } + when(csarBusinessLogic.getParsedToscaYamlInfo(anyString(), anyString(), anyMap(), any(CsarInfo.class), + anyString(), any(Component.class))).thenReturn(getParsedToscaYamlInfo()); + when(serviceImportParseLogic.prepareResourceForUpdate(any(Resource.class), any(Resource.class), + any(User.class), anyBoolean(), anyBoolean())).thenReturn(oldResource); + when(serviceImportParseLogic.validateCapabilityTypesCreate(any(User.class), any(ICapabilityTypeOperation.class), + any(Resource.class), any(AuditingActionEnum.class), anyBoolean())).thenReturn(Either.left(true)); + when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class))) + .thenReturn(Either.left(newResource)); + Assertions.assertThrows(ComponentException.class, () -> sIB1 + .updateResourceFromYaml(oldResource, newResource, actionEnum, createdArtifacts, + yamlFileName, yamlFileContent, csarInfo, nodeTypesInfo, + nodeTypesArtifactsToHandle, nodeName, isNested)); } @Test - public void testCreateResourceFromYaml(){ + public void testCreateResourceFromYaml() throws IOException { + String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; Resource resource = createParseResourceObject(true); String topologyTemplateYaml = getMainTemplateContent(); String yamlName = "group.yml"; - Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>(); + + Map<String, NodeTypeInfo> nodeTypesInfo = getNodeTypesInfo(); + Map<String, Object> map = new HashMap<>(); + map.put("tosca_definitions_version", "123"); + nodeTypesInfo.get(nodeName).setMappedToscaTemplate(map); + CsarInfo csarInfo = getCsarInfo(); Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate = new HashMap<>(); - boolean shouldLock = true; - boolean inTransaction =true; - String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; + boolean shouldLock = false; + boolean inTransaction = true; - try { - sIB1.createResourceFromYaml(resource,topologyTemplateYaml,yamlName,nodeTypesInfo,csarInfo, - nodeTypesArtifactsToCreate,shouldLock,inTransaction,nodeName); - } catch (Exception e) { - } + when(csarBusinessLogic.getParsedToscaYamlInfo(anyString(), anyString(), anyMap(), any(CsarInfo.class), + anyString(), any(Component.class))).thenReturn(getParsedToscaYamlInfo()); + when(serviceBusinessLogic.fetchAndSetDerivedFromGenericType(any(Resource.class))).thenReturn(resource); + when(toscaOperationFacade.validateComponentNameExists(anyString(), any(ResourceTypeEnum.class) + , any(ComponentTypeEnum.class))).thenReturn(Either.left(false)); + when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(Either.left(resource)); + Assertions.assertThrows(ComponentException.class, () -> sIB1.createResourceFromYaml(resource, + topologyTemplateYaml, yamlName, nodeTypesInfo, csarInfo, + nodeTypesArtifactsToCreate, shouldLock, inTransaction, nodeName)); + } @Test - public void testCreateResourceAndRIsFromYaml(){ + public void testCreateResourceAndRIsFromYaml() throws IOException { String yamlName = "group.yml"; + String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; Resource resource = createParseResourceObject(true); resource.setSystemName("SystemName"); resource.setComponentType(ComponentTypeEnum.RESOURCE); - ParsedToscaYamlInfo parsedToscaYamlInfo = new ParsedToscaYamlInfo(); AuditingActionEnum actionEnum = AuditingActionEnum.CREATE_RESOURCE; boolean isNormative = true; List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); String topologyTemplateYaml = getMainTemplateContent(); - Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>(); + Map<String, NodeTypeInfo> nodeTypesInfo = getNodeTypesInfo(); + Map<String, Object> map = new HashMap<>(); + map.put("tosca_definitions_version", "123"); + nodeTypesInfo.get(nodeName).setMappedToscaTemplate(map); + ParsedToscaYamlInfo parsedToscaYamlInfo = getParsedToscaYamlInfo(); + CsarInfo csarInfo = getCsarInfo(); Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate = new HashMap<>(); - boolean shouldLock = true; + boolean shouldLock = false; boolean inTransaction = true; - String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; - when(serviceBusinessLogic.lockComponentByName(anyString(),any(),anyString())) + when(serviceBusinessLogic.fetchAndSetDerivedFromGenericType(any(Resource.class))) + .thenReturn(resource); + + when(serviceBusinessLogic.lockComponentByName(anyString(), any(), anyString())) .thenReturn(Either.left(true)); - try { - sIB1.createResourceAndRIsFromYaml(yamlName,resource,parsedToscaYamlInfo,actionEnum, - isNormative,createdArtifacts,topologyTemplateYaml,nodeTypesInfo,csarInfo, - nodeTypesArtifactsToCreate,shouldLock,inTransaction,nodeName); - } catch (Exception e) { - e.printStackTrace(); - } - } + when(toscaOperationFacade.validateComponentNameExists(anyString(), any(ResourceTypeEnum.class) + , any(ComponentTypeEnum.class))).thenReturn(Either.left(false)); - @Test - public void testCreateResourceAndRIsFromYaml_False(){ - String yamlName = "group.yml"; - Resource resource = createParseResourceObject(false); - ParsedToscaYamlInfo parsedToscaYamlInfo = new ParsedToscaYamlInfo(); - AuditingActionEnum actionEnum = AuditingActionEnum.CREATE_RESOURCE; - boolean isNormative = true; - List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); - String topologyTemplateYaml = getMainTemplateContent(); - Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>(); - CsarInfo csarInfo = getCsarInfo(); - Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate = new HashMap<>(); - boolean shouldLock = false; - boolean inTransaction = false; - String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; + when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(Either.left(resource)); - try { - sIB1.createResourceAndRIsFromYaml(yamlName,resource,parsedToscaYamlInfo,actionEnum, - isNormative,createdArtifacts,topologyTemplateYaml,nodeTypesInfo,csarInfo, - nodeTypesArtifactsToCreate,shouldLock,inTransaction,nodeName); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1 + .createResourceAndRIsFromYaml(yamlName, resource, parsedToscaYamlInfo, actionEnum, + isNormative, createdArtifacts, topologyTemplateYaml, nodeTypesInfo, csarInfo, + nodeTypesArtifactsToCreate, shouldLock, inTransaction, nodeName)); } @Test public void testCreateGroupsOnResource2() { Resource resource = createParseResourceObject(false); - Map<String, GroupDefinition> groups = getGroups(); + Map<String, GroupDefinition> groups = null; + List<GroupDefinition> groupDefinitionList = new ArrayList<>(); + GroupDefinition groupDefinition = new GroupDefinition(); + groupDefinition.setUniqueId("groupDefinitionUniqueId"); + groupDefinition.setName("groupDefinition"); + groupDefinitionList.add(groupDefinition); when(serviceImportParseLogic.validateCyclicGroupsDependencies(any())) .thenReturn(Either.left(true)); - - try { - sIB1.createGroupsOnResource(resource, groups); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertNotNull( + sIB1.createGroupsOnResource(resource, groups)); } @Test @@ -1878,82 +1913,69 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB Map<String, GroupDefinition> groups = null; Either<Resource, ResponseFormat> result = sIB1.createGroupsOnResource(resource, groups); - assertEquals(result.left().value(),resource); + assertEquals(result.left().value(), resource); } @Test - public void testUpdateGroupsMembersUsingResource2(){ + public void testUpdateGroupsMembersUsingResource2() { Resource resource = createParseResourceObject(true); - Map<String, GroupDefinition> groups = null; + Map<String, GroupDefinition> groups = getGroups(); + when(serviceImportParseLogic.validateCyclicGroupsDependencies(any())) + .thenReturn(Either.left(true)); + Assertions.assertNotNull( + sIB1.updateGroupsMembersUsingResource(groups, resource)); - List<GroupDefinition> groupDefinitions = sIB1.updateGroupsMembersUsingResource(groups,resource); - for (GroupDefinition groupDefinition : groupDefinitions) { - assertNull(groupDefinition); - } } @Test - public void testUpdateGroupsMembersUsingResource_left2(){ + public void testUpdateGroupsMembersUsingResource_left2() { Resource resource = createParseResourceObject(true); Map<String, GroupDefinition> groups = getGroups(); when(serviceImportParseLogic.validateCyclicGroupsDependencies(any())) .thenReturn(Either.left(true)); + Assertions.assertNotNull( + sIB1.updateGroupsMembersUsingResource(groups, resource)); - List<GroupDefinition> groupDefinitions = sIB1.updateGroupsMembersUsingResource(groups, resource); - for (GroupDefinition groupDefinition : groupDefinitions) { - assertNotNull(groupDefinition); - } } @Test - public void testUpdateGroupMembers(){ + public void testUpdateGroupMembers() throws IOException { Map<String, GroupDefinition> groups = new HashMap<>(); GroupDefinition updatedGroupDefinition = new GroupDefinition(); Resource component = createParseResourceObject(true); List<ComponentInstance> componentInstances = creatComponentInstances(); String groupName = "tosca_simple_yaml_1_1"; Map<String, String> members = new HashMap<>(); - members.put("zxjTestImportServiceAb",getGroupsYaml()); + members.put("zxjTestImportServiceAb", getGroupsYaml()); + Assertions.assertNotNull(component); - try { - sIB1.updateGroupMembers(groups,updatedGroupDefinition,component,componentInstances, - groupName,members); - } catch (Exception e) { - e.printStackTrace(); - } + sIB1.updateGroupMembers(groups, updatedGroupDefinition, component, componentInstances, groupName, members); } @Test - public void testUpdateGroupMembers_null(){ + public void testUpdateGroupMembers_null() throws IOException { Map<String, GroupDefinition> groups = new HashMap<>(); GroupDefinition updatedGroupDefinition = new GroupDefinition(); Resource component = createParseResourceObject(true); List<ComponentInstance> componentInstances = new ArrayList<>(); String groupName = "tosca_simple_yaml_1_1"; Map<String, String> members = new HashMap<>(); - members.put("zxjTestImportServiceAb",getGroupsYaml()); + members.put("zxjTestImportServiceAb", getGroupsYaml()); - try { - sIB1.updateGroupMembers(groups,updatedGroupDefinition,component,componentInstances, - groupName,members); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1.updateGroupMembers(groups, + updatedGroupDefinition, component, componentInstances, groupName, members)); } @Test - public void setCreateResourceTransaction(){ + public void setCreateResourceTransaction() { Resource resource = createParseResourceObject(false); resource.setComponentType(ComponentTypeEnum.RESOURCE); boolean isNormative = true; - when(toscaOperationFacade.validateComponentNameExists(anyString(),any(),any())) + when(toscaOperationFacade.validateComponentNameExists(anyString(), any(), any())) .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST)); - try { - sIB1.createResourceTransaction(resource,user,isNormative); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1.createResourceTransaction(resource, + user, isNormative)); } @Test @@ -1961,59 +1983,52 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB Resource resource = createParseResourceObject(false); resource.setComponentType(ComponentTypeEnum.RESOURCE); boolean isNormative = true; - when(toscaOperationFacade.validateComponentNameExists(anyString(),any(),any())) + when(toscaOperationFacade.validateComponentNameExists(anyString(), any(), any())) .thenReturn(Either.left(true)); - try { - sIB1.createResourceTransaction(resource,user,isNormative); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1 + .createResourceTransaction(resource, user, isNormative)); } @Test public void setCreateResourceTransaction_Left() { Resource resource = createParseResourceObject(false); resource.setComponentType(ComponentTypeEnum.RESOURCE); - when(toscaOperationFacade.validateComponentNameExists(anyString(),any(),any())) + when(toscaOperationFacade.validateComponentNameExists(anyString(), any(), any())) .thenReturn(Either.left(false)); - - try { - sIB1.createResourceTransaction(resource,user,false); - } catch (Exception e) { - e.printStackTrace(); - } + when(toscaOperationFacade.createToscaComponent(any(Resource.class))).thenReturn(Either.left(resource)); + Assertions.assertNotNull( + sIB1.createResourceTransaction(resource, user, false)); } @Test - public void testUpdateExistingResourceByImport(){ + public void testUpdateExistingResourceByImport() { Resource newResource = createNewResource(); Resource oldResource = createOldResource(); - - try { - sIB1.updateExistingResourceByImport(newResource,oldResource,user, - true,true,true); - } catch (Exception e) { - e.printStackTrace(); - } + when(serviceImportParseLogic.prepareResourceForUpdate(any(Resource.class), any(Resource.class), + any(User.class), anyBoolean(), anyBoolean())).thenReturn(oldResource); + when(serviceImportParseLogic.validateCapabilityTypesCreate(any(User.class), any(ICapabilityTypeOperation.class), + any(Resource.class), any(AuditingActionEnum.class), anyBoolean())).thenReturn(Either.left(true)); + when(toscaOperationFacade.overrideComponent(any(Resource.class), any(Resource.class))) + .thenReturn(Either.left(newResource)); + Assertions.assertNotNull( + sIB1.updateExistingResourceByImport(newResource, oldResource, user, + true, false, true)); } @Test - public void testCreateNewResourceToOldResource(){ + public void testCreateNewResourceToOldResource() { Resource newResource = createNewResource(); Resource oldResource = createOldResource(); - try { - sIB1.createNewResourceToOldResource(newResource,oldResource,user); - } catch (Exception e) { - e.printStackTrace(); - } + sIB1.createNewResourceToOldResource(newResource, oldResource, user); + assertEquals(newResource.getSystemName(), oldResource.getSystemName()); } @Test - public void testCreateResourcesFromYamlNodeTypesList(){ + public void testCreateResourcesFromYamlNodeTypesList() { String yamlName = "group.yml"; - Service service =createServiceObject(false); + Service service = createServiceObject(true); Map<String, Object> mappedToscaTemplate = new HashMap<>(); boolean needLock = true; Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>(); @@ -2021,18 +2036,15 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>(); CsarInfo csarInfo = getCsarInfo(); - try { - sIB1.createResourcesFromYamlNodeTypesList(yamlName,service,mappedToscaTemplate,needLock, - nodeTypesArtifactsToHandle,nodeTypesNewCreatedArtifacts,nodeTypesInfo,csarInfo); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1 + .createResourcesFromYamlNodeTypesList(yamlName, service, mappedToscaTemplate, needLock, + nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo)); } @Test - public void testCreateNodeTypes(){ + public void testCreateNodeTypes() { String yamlName = "group.yml"; - Service service =createServiceObject(false); + Service service = createServiceObject(true); boolean needLock = true; Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>(); EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>> enumListEnumMap = @@ -2043,30 +2055,27 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB artifactDefinitions.add(artifactDefinition); enumListEnumMap.put(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE, artifactDefinitions); - nodeTypesArtifactsToHandle.put("nodeTyp",enumListEnumMap); + nodeTypesArtifactsToHandle.put("nodeTyp", enumListEnumMap); List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>(); Map<String, NodeTypeInfo> nodeTypesInfo = getNodeTypesInfo(); CsarInfo csarInfo = getCsarInfo(); - Map<String, Object> mapToConvert =new HashMap<>(); - Map<String, Object> nodeTypes =new HashMap<>(); + Map<String, Object> mapToConvert = new HashMap<>(); + Map<String, Object> nodeTypes = new HashMap<>(); NodeTypeInfo nodeTypeInfo = new NodeTypeInfo(); - nodeTypesInfo.put("nodeTyp",nodeTypeInfo); + nodeTypesInfo.put("nodeTyp", nodeTypeInfo); nodeTypes.put("org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test", nodeTypeInfo); - try { - sIB1.createNodeTypes(yamlName, service, needLock, nodeTypesArtifactsToHandle, - nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, mapToConvert, - nodeTypes); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> sIB1.createNodeTypes(yamlName, + service, needLock, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, + nodeTypesInfo, csarInfo, mapToConvert, nodeTypes)); } @Test - public void testCreateNodeTypesElse(){ + public void testCreateNodeTypesElse() { + String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; String yamlName = "group.yml"; - Service service =createServiceObject(false); + Service service = createServiceObject(true); boolean needLock = true; Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>(); EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>> enumListEnumMap = @@ -2077,27 +2086,39 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB artifactDefinitions.add(artifactDefinition); enumListEnumMap.put(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE, artifactDefinitions); - nodeTypesArtifactsToHandle.put("nodeTyp",enumListEnumMap); + nodeTypesArtifactsToHandle.put("nodeTyp", enumListEnumMap); List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>(); Map<String, NodeTypeInfo> nodeTypesInfo = getNodeTypesInfo(); + Map<String, Object> map = new HashMap<>(); + map.put("tosca_definitions_version", "123"); + nodeTypesInfo.get(nodeName).setMappedToscaTemplate(map); + ParsedToscaYamlInfo parsedToscaYamlInfo = getParsedToscaYamlInfo(); + CsarInfo csarInfo = getCsarInfo(); - Map<String, Object> mapToConvert =new HashMap<>(); - Map<String, Object> nodeTypes =new HashMap<>(); + Map<String, Object> mapToConvert = new HashMap<>(); + Map<String, Object> nodeTypes = new HashMap<>(); NodeTypeInfo nodeTypeInfo = new NodeTypeInfo(); - nodeTypesInfo.put("nodeTyp",nodeTypeInfo); - nodeTypes.put("org.openecomp.resource.derivedFrom.zxjTestImportServiceAb0.test", + nodeTypes.put("org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test", nodeTypeInfo); + when(serviceImportParseLogic.createNodeTypeResourceFromYaml(anyString(), any(Map.Entry.class), any(User.class), + anyMap(), any(Service.class), anyBoolean(), anyMap(), anyList(), anyBoolean(), any(CsarInfo.class), + anyBoolean())).thenReturn(getResourceCreated()); + Assertions.assertNotNull(service); + + sIB1.createNodeTypes(yamlName, + service, needLock, nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, + nodeTypesInfo, csarInfo, mapToConvert, nodeTypes); - try { - sIB1.createNodeTypes(yamlName, service, needLock, nodeTypesArtifactsToHandle, - nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, mapToConvert, - nodeTypes); - } catch (Exception e) { - e.printStackTrace(); - } } - protected Resource createNewResource(){ + protected ImmutablePair<Resource, ActionStatus> getResourceCreated() { + Resource resource = createOldResource(); + ImmutablePair<Resource, ActionStatus> resourceCreated = new ImmutablePair<>(resource, ActionStatus.OK); + + return resourceCreated; + } + + protected Resource createNewResource() { Resource newResource = createParseResourceObject(false); newResource.setVersion("1.0"); newResource.setInvariantUUID(""); @@ -2112,20 +2133,21 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>(); ArtifactDefinition artifactDefinition = new ArtifactDefinition(); artifactDefinition.setArtifactName("artifactDefinition"); - toscaArtifacts.put("toscaArtifactsMap",artifactDefinition); + toscaArtifacts.put("toscaArtifactsMap", artifactDefinition); Map<String, InterfaceDefinition> interfaces = new HashMap<>(); InterfaceDefinition interfaceDefinition = new InterfaceDefinition(); interfaceDefinition.setOwnerId("OwnerId"); - interfaces.put("interfacesMap",interfaceDefinition); + interfaces.put("interfacesMap", interfaceDefinition); newResource.setInterfaces(interfaces); newResource.setToscaArtifacts(toscaArtifacts); newResource.setProperties(getProperties()); return newResource; } - protected Resource createOldResource(){ + protected Resource createOldResource() { Resource newResource = createParseResourceObject(false); newResource.setVersion("1.0"); + newResource.setUniqueId("ResourceUniqueId"); newResource.setInvariantUUID("552e8f6c-340c-4fb4-8a82-fe7732fd8010"); newResource.setLifecycleState(LifecycleStateEnum.CERTIFIED); newResource.setUUID("13065b80-ca96-4331-b643-d28aeaf961cb"); @@ -2138,11 +2160,11 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>(); ArtifactDefinition artifactDefinition = new ArtifactDefinition(); artifactDefinition.setArtifactName("tosca_simple_yaml_1_1"); - toscaArtifacts.put("tosca_definitions_version",artifactDefinition); + toscaArtifacts.put("tosca_definitions_version", artifactDefinition); Map<String, InterfaceDefinition> interfaces = new HashMap<>(); InterfaceDefinition interfaceDefinition = new InterfaceDefinition(); interfaceDefinition.setDescription("Invoked upon receipt of an Instantiate VNF request"); - interfaces.put("tosca_simple_yaml_1_1",interfaceDefinition); + interfaces.put("tosca_simple_yaml_1_1", interfaceDefinition); newResource.setInterfaces(interfaces); newResource.setToscaArtifacts(toscaArtifacts); List<PropertyDefinition> properties = new ArrayList<>(); @@ -2153,22 +2175,33 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB return newResource; } + protected Map<String, InputDefinition> getCurrPropertiesMap() { + Map<String, InputDefinition> currPropertiesMap = new HashMap<>(); + InputDefinition inputDefinition = new InputDefinition(); + inputDefinition.setName("inputDefinitionName"); + inputDefinition.setUniqueId("uniqueId"); + inputDefinition.setType("inputDefinitionType"); + currPropertiesMap.put("propertyInfoName", inputDefinition); + return currPropertiesMap; + } + protected List<UploadPropInfo> getPropertyList() { List<UploadPropInfo> propertyList = new ArrayList<>(); - UploadPropInfo uploadPropInfo = new UploadPropInfo(); List<GetInputValueDataDefinition> get_input = new ArrayList<>(); GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition(); getInputValueDataDefinition.setPropName("getInputValueDataDefinitionName"); + getInputValueDataDefinition.setInputName("inputDefinitionName"); get_input.add(getInputValueDataDefinition); - uploadPropInfo.setName("propertiesName"); - uploadPropInfo.setValue("value"); - uploadPropInfo.setGet_input(get_input); - propertyList.add(uploadPropInfo); + UploadPropInfo propertyInfo = new UploadPropInfo(); + propertyInfo.setValue("value"); + propertyInfo.setGet_input(get_input); + propertyInfo.setName("propertyInfoName"); + propertyList.add(propertyInfo); return propertyList; } - protected Map<String, NodeTypeInfo> getNodeTypesInfo(){ + protected Map<String, NodeTypeInfo> getNodeTypesInfo() { Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>(); NodeTypeInfo nodeTypeInfo = new NodeTypeInfo(); Map<String, Object> mappedToscaTemplate = new HashMap<>(); @@ -2176,22 +2209,22 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB nodeTypeInfo.setTemplateFileName("templateFileName"); nodeTypeInfo.setMappedToscaTemplate(mappedToscaTemplate); String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"; - nodeTypesInfo.put(nodeName,nodeTypeInfo); + nodeTypesInfo.put(nodeName, nodeTypeInfo); return nodeTypesInfo; } - protected Map<String, UploadComponentInstanceInfo> getUploadResInstancesMap(){ + protected Map<String, UploadComponentInstanceInfo> getUploadResInstancesMap() { Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>(); UploadComponentInstanceInfo uploadComponentInstanceInfo = getuploadComponentInstanceInfo(); Map<String, String> capabilitiesNamesToUpdate = new HashMap<>(); - capabilitiesNamesToUpdate.put("mme_ipu_vdu.feature","capabilitiesNamesToUpdate"); + capabilitiesNamesToUpdate.put("mme_ipu_vdu.feature", "capabilitiesNamesToUpdate"); Map<String, String> requirementsNamesToUpdate = new HashMap<>(); - requirementsNamesToUpdate.put("mme_ipu_vdu.feature","capabilitiesNamesToUpdate"); - uploadResInstancesMap.put("zxjTestImportServiceAb",uploadComponentInstanceInfo); + requirementsNamesToUpdate.put("mme_ipu_vdu.feature", "capabilitiesNamesToUpdate"); + uploadResInstancesMap.put("zxjTestImportServiceAb", uploadComponentInstanceInfo); return uploadResInstancesMap; } - protected Map<String, List<UploadPropInfo>> getUploadPropInfoProperties(){ + protected Map<String, List<UploadPropInfo>> getUploadPropInfoProperties() { Map<String, List<UploadPropInfo>> properties = new HashMap<>(); List<UploadPropInfo> uploadPropInfoList = new ArrayList<>(); UploadPropInfo uploadPropInfo = new UploadPropInfo(); @@ -2203,11 +2236,11 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB uploadPropInfo.setValue("value"); uploadPropInfo.setGet_input(get_input); uploadPropInfoList.add(uploadPropInfo); - properties.put("uploadComponentInstanceInfo",uploadPropInfoList); + properties.put("uploadComponentInstanceInfo", uploadPropInfoList); return properties; } - protected List<PropertyDefinition> getProperties(){ + protected List<PropertyDefinition> getProperties() { List<PropertyDefinition> properties = new ArrayList<>(); PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setName("propertiesName"); @@ -2215,13 +2248,13 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB return properties; } - protected Map<String, List<UploadReqInfo>> gerRequirements(){ + protected Map<String, List<UploadReqInfo>> gerRequirements() { Map<String, List<UploadReqInfo>> uploadReqInfoMap = new HashMap<>(); String requirementName = "tosca.capabilities.Node"; List<UploadReqInfo> uploadReqInfoList = new ArrayList<>(); UploadReqInfo uploadReqInfo = new UploadReqInfo(); uploadReqInfo.setCapabilityName("tosca.capabilities.Node"); - uploadReqInfoMap.put(requirementName,uploadReqInfoList); + uploadReqInfoMap.put(requirementName, uploadReqInfoList); return uploadReqInfoMap; } @@ -2235,6 +2268,7 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB parametersView.setIgnoreGroups(false); return parametersView; } + protected Map<String, byte[]> crateCsarFromPayload() { String payloadName = "valid_vf.csar"; String rootPath = System.getProperty("user.dir"); @@ -2260,7 +2294,7 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB } - protected List<ComponentInstance> creatComponentInstances(){ + protected List<ComponentInstance> creatComponentInstances() { List<ComponentInstance> componentInstances = new ArrayList<>(); ComponentInstance componentInstance = new ComponentInstance(); Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>(); @@ -2268,14 +2302,14 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB CapabilityDefinition capabilityDefinition = new CapabilityDefinition(); capabilityDefinition.setName("mme_ipu_vdu.feature"); capabilityDefinitionList.add(capabilityDefinition); - capabilities.put("tosca.capabilities.Node",capabilityDefinitionList); + capabilities.put("tosca.capabilities.Node", capabilityDefinitionList); Map<String, List<RequirementDefinition>> requirements = new HashMap<>(); List<RequirementDefinition> requirementDefinitionList = new ArrayList<>(); RequirementDefinition requirementDefinition = new RequirementDefinition(); requirementDefinition.setName("zxjtestimportserviceab0.mme_ipu_vdu.dependency.test"); requirementDefinitionList.add(requirementDefinition); - requirements.put("tosca.capabilities.Node",requirementDefinitionList); + requirements.put("tosca.capabilities.Node", requirementDefinitionList); componentInstance.setRequirements(requirements); componentInstance.setCapabilities(capabilities); componentInstance.setUniqueId("uniqueId"); @@ -2287,7 +2321,7 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB protected CreateServiceFromYamlParameter getCsfyp() { CreateServiceFromYamlParameter csfyp = new CreateServiceFromYamlParameter(); - List<ArtifactDefinition> createdArtifacts =new ArrayList<>(); + List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); Map<String, NodeTypeInfo> nodeTypesInfo = new HashedMap(); csfyp.setNodeName("org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test"); @@ -2302,12 +2336,15 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB return csfyp; } - protected ParsedToscaYamlInfo getParsedToscaYamlInfo(){ + protected ParsedToscaYamlInfo getParsedToscaYamlInfo() { ParsedToscaYamlInfo parsedToscaYamlInfo = new ParsedToscaYamlInfo(); Map<String, InputDefinition> inputs = new HashMap<>(); - Map<String, UploadComponentInstanceInfo> instances=new HashMap<>(); - Map<String, GroupDefinition> groups=new HashMap<>(); - Map<String, PolicyDefinition> policies=new HashMap<>(); + Map<String, UploadComponentInstanceInfo> instances = new HashMap<>(); + UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo(); + uploadComponentInstanceInfo.setName("uploadComponentInstanceInfo"); + instances.put("instances", uploadComponentInstanceInfo); + Map<String, GroupDefinition> groups = new HashMap<>(); + Map<String, PolicyDefinition> policies = new HashMap<>(); parsedToscaYamlInfo.setGroups(groups); parsedToscaYamlInfo.setInputs(inputs); parsedToscaYamlInfo.setInstances(instances); @@ -2315,7 +2352,7 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB return parsedToscaYamlInfo; } - String getMainTemplateContent(String fileName){ + String getMainTemplateContent(String fileName) { String mainTemplateContent = null; try { mainTemplateContent = loadFileNameToJsonString(fileName); @@ -2325,15 +2362,14 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB return mainTemplateContent; } - protected CsarInfo getCsarInfo () - { + protected CsarInfo getCsarInfo() { String csarUuid = "0010"; User user = new User(); Map<String, byte[]> csar = crateCsarFromPayload(); String vfReousrceName = "resouceName"; String mainTemplateName = "mainTemplateName"; String mainTemplateContent = getMainTemplateContent("service_import_template.yml"); - CsarInfo csarInfo = new CsarInfo(user, csarUuid, csar, vfReousrceName, mainTemplateName, mainTemplateContent, false); + CsarInfo csarInfo = new CsarInfo(user, csarUuid, csar, vfReousrceName, mainTemplateName, mainTemplateContent, false); return csarInfo; } @@ -2349,8 +2385,8 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB } - protected CsarUtils.NonMetaArtifactInfo getNonMetaArtifactInfo(){ - String artifactName = "artifactName",path = "/src/test/resources/valid_vf.csar",artifactType = "AAI_SERVICE_MODEL"; + protected CsarUtils.NonMetaArtifactInfo getNonMetaArtifactInfo() { + String artifactName = "artifactName", path = "/src/test/resources/valid_vf.csar", artifactType = "AAI_SERVICE_MODEL"; ArtifactGroupTypeEnum artifactGroupType = ArtifactGroupTypeEnum.TOSCA; String rootPath = System.getProperty("user.dir"); Path path2; @@ -2363,12 +2399,12 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB } String artifactUniqueId = "artifactUniqueId"; boolean isFromCsar = true; - CsarUtils.NonMetaArtifactInfo nonMetaArtifactInfo = new CsarUtils.NonMetaArtifactInfo(artifactName, - path,artifactType,artifactGroupType,data,artifactUniqueId,isFromCsar); + CsarUtils.NonMetaArtifactInfo nonMetaArtifactInfo = new CsarUtils.NonMetaArtifactInfo(artifactName, + path, artifactType, artifactGroupType, data, artifactUniqueId, isFromCsar); return nonMetaArtifactInfo; } - + protected void assertComponentException(ComponentException e, ActionStatus expectedStatus, String... variables) { ResponseFormat actualResponse = e.getResponseFormat() != null ? e.getResponseFormat() : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java index 928dbf96fc..a56114ae49 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java @@ -1,49 +1,22 @@ /* - - * Copyright (c) 2018 AT&T Intellectual Property. - + * Copyright (C) 2020 CMCC, Inc. and others. All rights reserved. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package org.openecomp.sdc.be.components.impl; import fj.data.Either; - -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.codec.binary.Base64; -import org.junit.Before; -import org.mockito.Mock; +import org.junit.jupiter.api.BeforeEach; import org.mockito.Mockito; import org.openecomp.sdc.ElementOperationMock; import org.openecomp.sdc.be.auditing.impl.AuditingManager; @@ -61,7 +34,6 @@ import org.openecomp.sdc.be.components.validation.component.*; import org.openecomp.sdc.be.components.validation.service.*; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; @@ -79,7 +51,6 @@ import org.openecomp.sdc.be.model.operations.api.IElementOperation; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation; import org.openecomp.sdc.be.resources.data.auditing.ResourceAdminEvent; -import org.openecomp.sdc.be.servlets.AbstractValidationsServlet; import org.openecomp.sdc.be.user.Role; import org.openecomp.sdc.be.user.UserBusinessLogic; import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; @@ -89,10 +60,13 @@ import org.openecomp.sdc.exception.ResponseFormat; import org.springframework.web.context.WebApplicationContext; import javax.servlet.ServletContext; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.*; -import static org.assertj.core.api.Java6Assertions.assertThat; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.when; @@ -174,8 +148,8 @@ public class ServiceImportBussinessLogicBaseTestSetup extends BaseBusinessLogicM return new ServiceValidator(componentsUtils, componentFieldValidators, serviceFieldValidators); } - @Before - public void setup() { + @BeforeEach + public void setup() throws IOException { // Elements IElementOperation mockElementDao = new ElementOperationMock(); @@ -436,6 +410,7 @@ protected Resource createParseResourceObject(boolean afterCreate) { List<UploadReqInfo> uploadReqInfoList = new ArrayList<>(); UploadReqInfo uploadReqInfo = new UploadReqInfo(); uploadReqInfo.setName("uploadReqInfo"); + uploadReqInfo.setNode("zxjTestImportServiceAb"); uploadReqInfo.setCapabilityName("tosca.capabilities.Node"); uploadReqInfoList.add(uploadReqInfo); requirements.put("requirements",uploadReqInfoList); @@ -488,7 +463,7 @@ protected Resource createParseResourceObject(boolean afterCreate) { return uploadComponentInstanceInfo; } - private void mockAbstract() { + private void mockAbstract() throws IOException { checkCreateAbstract(); checkCreateOther(); checkCreateFile(); @@ -629,7 +604,7 @@ protected Resource createParseResourceObject(boolean afterCreate) { uploadServiceInfo.getPayloadData(); } - private void checkCreateFile(){ + private void checkCreateFile() throws IOException { CreateServiceFromYamlParameter csfp = new CreateServiceFromYamlParameter(); Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>(); ParsedToscaYamlInfo parsedToscaYamlInfo = new ParsedToscaYamlInfo(); @@ -657,8 +632,7 @@ protected Resource createParseResourceObject(boolean afterCreate) { getCsfy.getNodeName(); } - protected CsarInfo getCsarInfo () - { + protected CsarInfo getCsarInfo () throws IOException { String csarUuid = "0010"; User user = new User(); Map<String, byte[]> csar = crateCsarFromPayload(); @@ -679,518 +653,28 @@ protected Resource createParseResourceObject(boolean afterCreate) { return returnValue; } - protected String getGroupsYaml(){ - return "zxjTestImportServiceAb 0:\n" + - " type: org.openecomp.resource.vf.Zxjtestimportserviceab\n" + - " metadata:\n" + - " invariantUUID: 41474f7f-3195-443d-a0a2-eb6020a56279\n" + - " UUID: 92e32e49-55f8-46bf-984d-a98c924037ec\n" + - " customizationUUID: 40286158-96d0-408e-9f27-21d43817d37c\n" + - " version: '1.0'\n" + - " name: zxjTestImportServiceAb\n" + - " description: zxjTestImportServiceAbstract\n" + - " type: VF\n" + - " category: Generic\n" + - " subcategory: Abstract\n" + - " resourceVendor: zxjImportService\n" + - " resourceVendorRelease: '1.0'\n" + - " resourceVendorModelNumber: ''\n" + - " properties:\n" + - " skip_post_instantiation_configuration: true\n" + - " nf_naming:\n" + - " ecomp_generated_naming: true\n" + - " multi_stage_design: 'false'\n" + - " controller_actor: SO-REF-DATA\n" + - " availability_zone_max_count: 1\n" + - " requirements:\n" + - " - imagefile.dependency:\n" + - " capability: feature\n" + - " node: ext ZTE VL 0\n" + - " - mme_ipu_vdu.dependency:\n" + - " capability: feature\n" + - " node: ExtCP 0\n" + - " capabilities:\n" + - " mme_ipu_vdu.scalable:\n" + - " properties:\n" + - " max_instances: 1\n" + - " min_instances: 1\n" + - " mme_ipu_vdu.nfv_compute:\n" + - " properties:\n" + - " num_cpus: '2'\n" + - " flavor_extra_specs: {\n" + - " }\n" + - " mem_size: '8192'"; + protected String getGroupsYaml() throws IOException { + Path filePath = Paths.get("src/test/resources/types/groups.yml"); + byte[] fileContent = Files.readAllBytes(filePath); + return new String(fileContent); + } + + protected String getYamlFileContent() throws IOException { + Path filePath = Paths.get("src/test/resources/types/fileContent.yml"); + byte[] fileContent = Files.readAllBytes(filePath); + return new String(fileContent); } - protected String getYamlFileContent(){ - return "tosca_definitions_version: tosca_simple_yaml_1_1\n" + - "imports:\n" + - "- data.yml\n" + - "group_types:\n" + - " tosca.groups.Root:\n" + - " description: The TOSCA Group Type all other TOSCA Group Types derive from\n" + - " interfaces:\n" + - " Standard:\n" + - " type: tosca.interfaces.node.lifecycle.Standard\n" + - " org.openecomp.groups.heat.HeatStack:\n" + - " derived_from: tosca.groups.Root\n" + - " description: Grouped all heat resources which are in the same heat stack\n" + - " properties:\n" + - " heat_file:\n" + - " type: string\n" + - " description: Heat file which associate to this group/heat stack\n" + - " required: true\n" + - " status: supported\n" + - " description:\n" + - " type: string\n" + - " description: group description\n" + - " required: true\n" + - " status: supported\n" + - " org.openecomp.groups.VfModule:\n" + - " derived_from: tosca.groups.Root\n" + - " description: Grouped all heat resources which are in the same VF Module\n" + - " properties:\n" + - " isBase:\n" + - " type: boolean\n" + - " description: Whether this module should be deployed before other modules\n" + - " required: true\n" + - " default: false\n" + - " status: supported\n" + - " vf_module_label:\n" + - " type: string\n" + - " required: true\n" + - " description: |\n" + - " Alternate textual key used to reference this VF-Module model. Must be unique within the VNF model\n" + - " vf_module_description:\n" + - " type: string\n" + - " required: true\n" + - " description: |\n" + - " Description of the VF-modules contents and purpose (e.g. \"Front-End\" or \"Database Cluster\")\n" + - " min_vf_module_instances:\n" + - " type: integer\n" + - " required: true\n" + - " description: The minimum instances of this VF-Module\n" + - " max_vf_module_instances:\n" + - " type: integer\n" + - " required: false\n" + - " description: The maximum instances of this VF-Module\n" + - " initial_count:\n" + - " type: integer\n" + - " required: false\n" + - " description: |\n" + - " The initial count of instances of the VF-Module. The value must be in the range between min_vfmodule_instances and max_vfmodule_instances. If no value provided the initial count is the min_vfmodule_instances.\n" + - " vf_module_type:\n" + - " type: string\n" + - " required: true\n" + - " constraint:\n" + - " - valid_values:\n" + - " - Base\n" + - " - Expansion\n" + - " volume_group:\n" + - " type: boolean\n" + - " required: true\n" + - " default: false\n" + - " description: |\n" + - " \"true\" indicates that this VF Module model requires attachment to a Volume Group. VID operator must select the Volume Group instance to attach to a VF-Module at deployment time.\n" + - " availability_zone_count:\n" + - " type: integer\n" + - " required: false\n" + - " description: |\n" + - " Quantity of Availability Zones needed for this VF-Module (source: Extracted from VF-Module HEAT template)\n" + - " vfc_list:\n" + - " type: map\n" + - " entry_schema:\n" + - " description: <vfc_id>:<count>\n" + - " type: string\n" + - " required: false\n" + - " description: |\n" + - " Identifies the set of VM types and their count included in the VF-Module\n" + - " org.openecomp.groups.NetworkCollection:\n" + - " derived_from: tosca.groups.Root\n" + - " description: groups l3-networks in network collection\n" + - " properties:\n" + - " network_collection_function:\n" + - " type: string\n" + - " required: true\n" + - " description: network collection function\n" + - " network_collection_description:\n" + - " type: string\n" + - " required: true\n" + - " description: network collection description, free format text\n" + - " org.openecomp.groups.VfcInstanceGroup:\n" + - " derived_from: tosca.groups.Root\n" + - " description: groups VFCs with same parent port role\n" + - " properties:\n" + - " vfc_instance_group_function:\n" + - " type: string\n" + - " required: true\n" + - " description: function of this VFC group\n" + - " vfc_parent_port_role:\n" + - " type: string\n" + - " required: true\n" + - " description: common role of parent ports of VFCs in this group\n" + - " network_collection_function:\n" + - " type: string\n" + - " required: true\n" + - " description: network collection function assigned to this group\n" + - " subinterface_role:\n" + - " type: string\n" + - " required: true\n" + - " description: common role of subinterfaces of VFCs in this group, criteria the group is created\n" + - " capabilities:\n" + - " vlan_assignment:\n" + - " type: org.openecomp.capabilities.VLANAssignment\n" + - " properties:\n" + - " vfc_instance_group_reference:\n" + - " type: string\n" + - " tosca.groups.nfv.PlacementGroup:\n" + - " derived_from: tosca.groups.Root\n" + - " description: PlacementGroup is used for describing the affinity or anti-affinity relationship applicable between the virtualization containers to be created based on different VDUs, or between internal VLs to be created based on different VnfVirtualLinkDesc(s)\n" + - " properties:\n" + - " description:\n" + - " type: string\n" + - " description: Human readable description of the group\n" + - " required: true\n" + - " members:\n" + - " - tosca.nodes.nfv.Vdu.Compute\n" + - " - tosca.nodes.nfv.VnfVirtualLink"; + public String getMainTemplateContent() throws IOException { + Path filePath = Paths.get("src/test/resources/types/mainTemplateContent.yml"); + byte[] fileContent = Files.readAllBytes(filePath); + return new String(fileContent); } - public String getMainTemplateContent(){ - return "tosca_definitions_version: tosca_simple_yaml_1_1\n" - + "metadata:\n" - + " invariantUUID: 6d17f281-683b-4198-a676-0faeecdc9025\n" - + " UUID: bfeab6b4-199b-4a2b-b724-de416c5e9811\n" - + " name: ser09080002\n" - + " description: ser09080002\n" - + " type: Service\n" - + " category: E2E Service\n" - + " serviceType: ''\n" - + " serviceRole: ''\n" - + " instantiationType: A-la-carte\n" - + " serviceEcompNaming: true\n" - + " ecompGeneratedNaming: true\n" - + " namingPolicy: ''\n" - + " environmentContext: General_Revenue-Bearing\n" - + " serviceFunction: ''\n" - + "imports:\n" - + "- nodes:\n" - + " file: nodes.yml\n" - + "- datatypes:\n" - + " file: data.yml\n" - + "- capabilities:\n" - + " file: capabilities.yml\n" - + "- relationships:\n" - + " file: relationships.yml\n" - + "- groups:\n" - + " file: groups.yml\n" - + "- policies:\n" - + " file: policies.yml\n" - + "- annotations:\n" - + " file: annotations.yml\n" - + "- service-ser09080002-interface:\n" - + " file: service-Ser09080002-template-interface.yml\n" - + "- resource-ExtCP:\n" - + " file: resource-Extcp-template.yml\n" - + "- resource-zxjTestImportServiceAb:\n" - + " file: resource-Zxjtestimportserviceab-template.yml\n" - + "- resource-zxjTestImportServiceAb-interface:\n" - + " file: resource-Zxjtestimportserviceab-template-interface.yml\n" - + "- resource-zxjTestServiceNotAbatract:\n" - + " file: resource-Zxjtestservicenotabatract-template.yml\n" - + "- resource-zxjTestServiceNotAbatract-interface:\n" - + " file: resource-Zxjtestservicenotabatract-template-interface.yml\n" - + "- resource-ext ZTE VL:\n" - + " file: resource-ExtZteVl-template.yml\n" - + "topology_template:\n" - + " inputs:\n" - + " skip_post_instantiation_configuration:\n" - + " default: true\n" - + " type: boolean\n" - + " required: false\n" - + " controller_actor:\n" - + " default: SO-REF-DATA\n" - + " type: string\n" - + " required: false\n" - + " cds_model_version:\n" - + " type: string\n" - + " required: false\n" - + " cds_model_name:\n" - + " type: string\n" - + " required: false\n" - + " node_templates:\n" - + " ext ZTE VL 0:\n" - + " type: tosca.nodes.nfv.ext.zte.VL\n" - + " metadata:\n" - + " invariantUUID: 27ab7610-1a97-4daa-938a-3b48e7afcfd0\n" - + " UUID: 9ea63e2c-4b8a-414f-93e3-5703ca5cee0d\n" - + " customizationUUID: e45e79b0-07ab-46b4-ac26-1e9f155ce53c\n" - + " version: '1.0'\n" - + " name: ext ZTE VL\n" - + " description: Ext ZTE VL\n" - + " type: VL\n" - + " category: Generic\n" - + " subcategory: Network Elements\n" - + " resourceVendor: ONAP (Tosca)\n" - + " resourceVendorRelease: 1.0.0.wd03\n" - + " resourceVendorModelNumber: ''\n" - + " zxjTestServiceNotAbatract 0:\n" - + " type: org.openecomp.resource.vf.Zxjtestservicenotabatract\n" - + " metadata:\n" - + " invariantUUID: ce39ce8d-6f97-4e89-8555-ae6789cdcf1c\n" - + " UUID: 4ac822be-f1ae-4ace-a4b8-bf6b5d977005\n" - + " customizationUUID: ee34e1e8-68e2-480f-8ba6-f257bbe90d6a\n" - + " version: '1.0'\n" - + " name: zxjTestServiceNotAbatract\n" - + " description: zxjTestServiceNotAbatract\n" - + " type: VF\n" - + " category: Network L4+\n" - + " subcategory: Common Network Resources\n" - + " resourceVendor: zxjImportService\n" - + " resourceVendorRelease: '1.0'\n" - + " resourceVendorModelNumber: ''\n" - + " properties:\n" - + " nf_naming:\n" - + " ecomp_generated_naming: true\n" - + " skip_post_instantiation_configuration: true\n" - + " multi_stage_design: 'false'\n" - + " controller_actor: SO-REF-DATA\n" - + " availability_zone_max_count: 1\n" - + " capabilities:\n" - + " mme_ipu_vdu.scalable:\n" - + " properties:\n" - + " max_instances: 1\n" - + " min_instances: 1\n" - + " mme_ipu_vdu.nfv_compute:\n" - + " properties:\n" - + " num_cpus: '2'\n" - + " flavor_extra_specs: {\n" - + " }\n" - + " mem_size: '8192'\n" - + " ExtCP 0:\n" - + " type: org.openecomp.resource.cp.extCP\n" - + " metadata:\n" - + " invariantUUID: 9b772728-93f5-424f-bb07-f4cae2783614\n" - + " UUID: 424ac220-4864-453e-b757-917fe4568ff8\n" - + " customizationUUID: 6e65d8a8-4379-4693-87aa-82f9e34b92fd\n" - + " version: '1.0'\n" - + " name: ExtCP\n" - + " description: The AT&T Connection Point base type all other CP derive from\n" - + " type: CP\n" - + " category: Generic\n" - + " subcategory: Network Elements\n" - + " resourceVendor: ONAP (Tosca)\n" - + " resourceVendorRelease: 1.0.0.wd03\n" - + " resourceVendorModelNumber: ''\n" - + " properties:\n" - + " mac_requirements:\n" - + " mac_count_required:\n" - + " is_required: false\n" - + " exCP_naming:\n" - + " ecomp_generated_naming: true\n" - + " zxjTestImportServiceAb 0:\n" - + " type: org.openecomp.resource.vf.Zxjtestimportserviceab\n" - + " metadata:\n" - + " invariantUUID: 41474f7f-3195-443d-a0a2-eb6020a56279\n" - + " UUID: 92e32e49-55f8-46bf-984d-a98c924037ec\n" - + " customizationUUID: 98c7a6c7-a867-45fb-8597-dd464f98e4aa\n" - + " version: '1.0'\n" - + " name: zxjTestImportServiceAb\n" - + " description: zxjTestImportServiceAbstract\n" - + " type: VF\n" - + " category: Generic\n" - + " subcategory: Abstract\n" - + " resourceVendor: zxjImportService\n" - + " resourceVendorRelease: '1.0'\n" - + " resourceVendorModelNumber: ''\n" - + " properties:\n" - + " nf_naming:\n" - + " ecomp_generated_naming: true\n" - + " skip_post_instantiation_configuration: true\n" - + " multi_stage_design: 'false'\n" - + " controller_actor: SO-REF-DATA\n" - + " availability_zone_max_count: 1\n" - + " requirements:\n" - + " - mme_ipu_vdu.dependency:\n" - + " capability: feature\n" - + " node: ExtCP 0\n" - + " - imagefile.dependency:\n" - + " capability: feature\n" - + " node: ext ZTE VL 0\n" - + " capabilities:\n" - + " mme_ipu_vdu.scalable:\n" - + " properties:\n" - + " max_instances: 1\n" - + " min_instances: 1\n" - + " mme_ipu_vdu.nfv_compute:\n" - + " properties:\n" - + " num_cpus: '2'\n" - + " flavor_extra_specs: {\n" - + " }\n" - + " mem_size: '8192'\n" - + " substitution_mappings:\n" - + " node_type: org.openecomp.service.Ser09080002\n" - + " capabilities:\n" - + " extcp0.feature:\n" - + " - ExtCP 0\n" - + " - feature\n" - + " zxjtestservicenotabatract0.mme_ipu_vdu.monitoring_parameter:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - mme_ipu_vdu.monitoring_parameter\n" - + " zxjtestimportserviceab0.imagefile.guest_os:\n" - + " - zxjTestImportServiceAb 0\n" - + " - imagefile.guest_os\n" - + " zxjtestimportserviceab0.imagefile.feature:\n" - + " - zxjTestImportServiceAb 0\n" - + " - imagefile.feature\n" - + " zxjtestservicenotabatract0.imagefile.guest_os:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - imagefile.guest_os\n" - + " zxjtestimportserviceab0.ipu_cpd.feature:\n" - + " - zxjTestImportServiceAb 0\n" - + " - ipu_cpd.feature\n" - + " zxjtestservicenotabatract0.mme_ipu_vdu.virtualbinding:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - mme_ipu_vdu.virtualbinding\n" - + " zxjtestimportserviceab0.mme_ipu_vdu.feature:\n" - + " - zxjTestImportServiceAb 0\n" - + " - mme_ipu_vdu.feature\n" - + " extztevl0.feature:\n" - + " - ext ZTE VL 0\n" - + " - feature\n" - + " zxjtestimportserviceab0.imagefile.image_fle:\n" - + " - zxjTestImportServiceAb 0\n" - + " - imagefile.image_fle\n" - + " zxjtestimportserviceab0.mme_ipu_vdu.monitoring_parameter:\n" - + " - zxjTestImportServiceAb 0\n" - + " - mme_ipu_vdu.monitoring_parameter\n" - + " zxjtestservicenotabatract0.ipu_cpd.feature:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - ipu_cpd.feature\n" - + " zxjtestservicenotabatract0.mme_ipu_vdu.nfv_compute:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - mme_ipu_vdu.nfv_compute\n" - + " zxjtestservicenotabatract0.mme_ipu_vdu.scalable:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - mme_ipu_vdu.scalable\n" - + " extcp0.internal_connectionPoint:\n" - + " - ExtCP 0\n" - + " - internal_connectionPoint\n" - + " zxjtestimportserviceab0.mme_ipu_vdu.virtualbinding:\n" - + " - zxjTestImportServiceAb 0\n" - + " - mme_ipu_vdu.virtualbinding\n" - + " zxjtestservicenotabatract0.imagefile.image_fle:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - imagefile.image_fle\n" - + " extztevl0.virtual_linkable:\n" - + " - ext ZTE VL 0\n" - + " - virtual_linkable\n" - + " zxjtestservicenotabatract0.imagefile.feature:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - imagefile.feature\n" - + " zxjtestimportserviceab0.localstorage.feature:\n" - + " - zxjTestImportServiceAb 0\n" - + " - localstorage.feature\n" - + " zxjtestservicenotabatract0.localstorage.local_attachment:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - localstorage.local_attachment\n" - + " zxjtestimportserviceab0.mme_ipu_vdu.scalable:\n" - + " - zxjTestImportServiceAb 0\n" - + " - mme_ipu_vdu.scalable\n" - + " zxjtestservicenotabatract0.localstorage.feature:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - localstorage.feature\n" - + " zxjtestimportserviceab0.mme_ipu_vdu.nfv_compute:\n" - + " - zxjTestImportServiceAb 0\n" - + " - mme_ipu_vdu.nfv_compute\n" - + " zxjtestimportserviceab0.localstorage.local_attachment:\n" - + " - zxjTestImportServiceAb 0\n" - + " - localstorage.local_attachment\n" - + " zxjtestservicenotabatract0.mme_ipu_vdu.feature:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - mme_ipu_vdu.feature\n" - + " zxjtestimportserviceab0.ipu_cpd.forwarder:\n" - + " - zxjTestImportServiceAb 0\n" - + " - ipu_cpd.forwarder\n" - + " zxjtestservicenotabatract0.ipu_cpd.forwarder:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - ipu_cpd.forwarder\n" - + " requirements:\n" - + " zxjtestservicenotabatract0.imagefile.dependency:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - imagefile.dependency\n" - + " zxjtestservicenotabatract0.mme_ipu_vdu.local_storage:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - mme_ipu_vdu.local_storage\n" - + " zxjtestservicenotabatract0.ipu_cpd.dependency:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - ipu_cpd.dependency\n" - + " zxjtestservicenotabatract0.mme_ipu_vdu.volume_storage:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - mme_ipu_vdu.volume_storage\n" - + " zxjtestservicenotabatract0.ipu_cpd.virtualbinding:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - ipu_cpd.virtualbinding\n" - + " zxjtestservicenotabatract0.mme_ipu_vdu.dependency:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - mme_ipu_vdu.dependency\n" - + " zxjtestservicenotabatract0.localstorage.dependency:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - localstorage.dependency\n" - + " zxjtestimportserviceab0.imagefile.dependency:\n" - + " - zxjTestImportServiceAb 0\n" - + " - imagefile.dependency\n" - + " zxjtestimportserviceab0.mme_ipu_vdu.volume_storage:\n" - + " - zxjTestImportServiceAb 0\n" - + " - mme_ipu_vdu.volume_storage\n" - + " zxjtestimportserviceab0.ipu_cpd.virtualbinding:\n" - + " - zxjTestImportServiceAb 0\n" - + " - ipu_cpd.virtualbinding\n" - + " extcp0.virtualLink:\n" - + " - ExtCP 0\n" - + " - virtualLink\n" - + " extcp0.virtualBinding:\n" - + " - ExtCP 0\n" - + " - virtualBinding\n" - + " zxjtestimportserviceab0.mme_ipu_vdu.guest_os:\n" - + " - zxjTestImportServiceAb 0\n" - + " - mme_ipu_vdu.guest_os\n" - + " extcp0.dependency:\n" - + " - ExtCP 0\n" - + " - dependency\n" - + " zxjtestimportserviceab0.localstorage.dependency:\n" - + " - zxjTestImportServiceAb 0\n" - + " - localstorage.dependency\n" - + " zxjtestservicenotabatract0.ipu_cpd.virtualLink:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - ipu_cpd.virtualLink\n" - + " extztevl0.dependency:\n" - + " - ext ZTE VL 0\n" - + " - dependency\n" - + " zxjtestimportserviceab0.ipu_cpd.dependency:\n" - + " - zxjTestImportServiceAb 0\n" - + " - ipu_cpd.dependency\n" - + " zxjtestimportserviceab0.mme_ipu_vdu.dependency:\n" - + " - zxjTestImportServiceAb 0\n" - + " - mme_ipu_vdu.dependency\n" - + " zxjtestimportserviceab0.mme_ipu_vdu.local_storage:\n" - + " - zxjTestImportServiceAb 0\n" - + " - mme_ipu_vdu.local_storage\n" - + " zxjtestimportserviceab0.ipu_cpd.virtualLink:\n" - + " - zxjTestImportServiceAb 0\n" - + " - ipu_cpd.virtualLink\n" - + " extcp0.external_virtualLink:\n" - + " - ExtCP 0\n" - + " - external_virtualLink\n" - + " zxjtestservicenotabatract0.mme_ipu_vdu.guest_os:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - mme_ipu_vdu.guest_os\n" - + " zxjtestimportserviceab0.ipu_cpd.forwarder:\n" - + " - zxjTestImportServiceAb 0\n" - + " - ipu_cpd.forwarder\n" - + " zxjtestservicenotabatract0.ipu_cpd.forwarder:\n" - + " - zxjTestServiceNotAbatract 0\n" - + " - ipu_cpd.forwarder\n"; + protected String getArtifactsYml() throws IOException { + Path filePath = Paths.get("src/test/resources/types/artifacts.yml"); + byte[] fileContent = Files.readAllBytes(filePath); + return new String(fileContent); } protected void assertComponentException(ComponentException e, ActionStatus expectedStatus, String... variables) { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportManagerTest.java index 65fae0bfbb..f723a1523f 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportManagerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportManagerTest.java @@ -1,29 +1,16 @@ /* - - * Copyright (c) 2018 AT&T Intellectual Property. - + * Copyright (C) 2020 CMCC, Inc. and others. All rights reserved. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. */ @@ -31,19 +18,31 @@ package org.openecomp.sdc.be.components.impl; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; +import org.mockito.Mockito; import org.mockito.junit.jupiter.MockitoExtension; import org.openecomp.sdc.be.model.Service; import org.openecomp.sdc.be.model.UploadServiceInfo; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + @ExtendWith(MockitoExtension.class) class ServiceImportManagerTest { @InjectMocks private ServiceImportManager serviceImportManager; + public static final ServiceBusinessLogic serviceBusinessLogic = Mockito.mock(ServiceBusinessLogic.class); + + @BeforeEach + public void setup() { + serviceImportManager = new ServiceImportManager(); + } + private ServiceImportManager createTestSubject() { return new ServiceImportManager(); } @@ -55,6 +54,7 @@ class ServiceImportManagerTest { testSubject = createTestSubject(); result = testSubject.getServiceImportBusinessLogic(); + assertNull(result); } @Test @@ -64,6 +64,7 @@ class ServiceImportManagerTest { testSubject = createTestSubject(); testSubject.setServiceImportBusinessLogic(serviceImportBusinessLogic); + assertNotNull(testSubject); } @Test @@ -73,6 +74,7 @@ class ServiceImportManagerTest { testSubject = createTestSubject(); result = testSubject.getServiceBusinessLogic(); + assertNull(result); } @Test @@ -82,15 +84,17 @@ class ServiceImportManagerTest { testSubject = createTestSubject(); testSubject.setServiceBusinessLogic(serviceBusinessLogic); + assertNotNull(testSubject); } @Test void testPopulateServiceMetadata() { - UploadServiceInfo serviceMetaData = null; - Service service = null; - if (serviceMetaData != null || service != null) { - serviceImportManager.populateServiceMetadata(serviceMetaData, service); - } + UploadServiceInfo serviceMetaData = new UploadServiceInfo(); + serviceMetaData.setDescription("Description"); + serviceMetaData.setVendorName("VendorName"); + serviceMetaData.setVendorRelease("VendorRelease"); + Service service = new Service(); + service.setName("service"); + serviceImportManager.populateServiceMetadata(serviceMetaData, service); } - } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java index 8b291e60a0..7e0fd60377 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java @@ -38,6 +38,8 @@ import org.apache.commons.collections.map.HashedMap; import org.apache.commons.lang3.tuple.ImmutablePair; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.mockito.InjectMocks; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; @@ -56,29 +58,7 @@ import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.be.impl.ComponentsUtils; -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; -import org.openecomp.sdc.be.model.ComponentInstanceProperty; -import org.openecomp.sdc.be.model.GroupDefinition; -import org.openecomp.sdc.be.model.InputDefinition; -import org.openecomp.sdc.be.model.InterfaceDefinition; -import org.openecomp.sdc.be.model.LifecycleStateEnum; -import org.openecomp.sdc.be.model.NodeTypeInfo; -import org.openecomp.sdc.be.model.PropertyDefinition; -import org.openecomp.sdc.be.model.RequirementCapabilityRelDef; -import org.openecomp.sdc.be.model.RequirementDefinition; -import org.openecomp.sdc.be.model.Resource; -import org.openecomp.sdc.be.model.Service; -import org.openecomp.sdc.be.model.UploadCapInfo; -import org.openecomp.sdc.be.model.UploadComponentInstanceInfo; -import org.openecomp.sdc.be.model.UploadPropInfo; -import org.openecomp.sdc.be.model.UploadReqInfo; -import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.model.*; import org.openecomp.sdc.be.model.category.CategoryDefinition; import org.openecomp.sdc.be.model.category.SubCategoryDefinition; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; @@ -91,7 +71,32 @@ import org.openecomp.sdc.be.user.Role; import org.openecomp.sdc.common.api.Constants; import org.openecomp.sdc.exception.ResponseFormat; -public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSetup { +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.Collections; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.NoSuchElementException; +import java.util.Set; + +import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; + +class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBaseTestSetup { ComponentsUtils componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class)); ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class); @@ -123,7 +128,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase ServiceImportParseLogic bl; - @Before + @BeforeEach public void setup() { MockitoAnnotations.initMocks(this); @@ -156,6 +161,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase testSubject = createTestSubject(); result = testSubject.getServiceBusinessLogic(); + assertNull(result); } @Test @@ -165,6 +171,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase testSubject = createTestSubject(); testSubject.setServiceBusinessLogic(serviceBusinessLogic); + assertNotNull(testSubject); } @Test @@ -174,6 +181,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase testSubject = createTestSubject(); result = testSubject.getCapabilityTypeOperation(); + assertNull(result); } @Test @@ -183,13 +191,14 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase testSubject = createTestSubject(); testSubject.setCapabilityTypeOperation(iCapabilityTypeOperation); + assertNotNull(testSubject); } private CsarInfo createCsarInfo() { Map<String, byte[]> csar = new HashMap<>(); User user = new User(); CsarInfo csarInfo = new CsarInfo(user, "csar_UUID", csar, "vfResourceName", "mainTemplateName", - "mainTemplateContent", true); + "mainTemplateContent", true); csarInfo.setVfResourceName("vfResourceName"); csarInfo.setCsar(csar); csarInfo.setCsarUUID("csarUUID"); @@ -203,9 +212,10 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase ServiceImportParseLogic testSubject = createTestSubject(); Map<String, NodeTypeInfo> nodeTypesInfo = new HashedMap(); final Service service = createServiceObject(false); + Assertions.assertNotNull( + bl.findNodeTypesArtifactsToHandle( + nodeTypesInfo, getCsarInfo(), service)); - bl.findNodeTypesArtifactsToHandle( - nodeTypesInfo, getCsarInfo(), service); } @Test @@ -229,13 +239,10 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Map<String, Object> mapToConvert = new HashMap<>(); String nodeResourceType = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX; - try { - bl.buildNodeTypeYaml( - nodeNameValue, mapToConvert, nodeResourceType, getCsarInfo()); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.INVALID_TOSCA_TEMPLATE, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.buildNodeTypeYaml( + nodeNameValue, mapToConvert, nodeResourceType, getCsarInfo())); + } @Test @@ -251,14 +258,12 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Resource resource = new Resource(); Either<Component, StorageOperationStatus> getCompLatestResult = Either.left(resource); when(toscaOperationFacade.getLatestByToscaResourceName(anyString())) - .thenReturn(getCompLatestResult); - try { - bl.findAddNodeTypeArtifactsToHandle(getCsarInfo(), nodeTypesArtifactsToHandle, service, - extractedVfcsArtifacts, namespace, p1); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.INVALID_TOSCA_TEMPLATE, - ComponentTypeEnum.RESOURCE.getValue()); - } + .thenReturn(getCompLatestResult); + + Assertions.assertThrows(ComponentException.class, () -> + bl.findAddNodeTypeArtifactsToHandle(getCsarInfo(), nodeTypesArtifactsToHandle, service, + extractedVfcsArtifacts, namespace, p1)); + } @Test @@ -279,13 +284,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Either<Component, StorageOperationStatus> getCompLatestResult = Either.left(resource); when(toscaOperationFacade.getLatestByToscaResourceName(anyString())) .thenReturn(getCompLatestResult); - try { - bl.findAddNodeTypeArtifactsToHandle(getCsarInfo(), nodeTypesArtifactsToHandle, service, + Assertions.assertNotNull(extractedVfcsArtifacts); + bl.findAddNodeTypeArtifactsToHandle(getCsarInfo(), nodeTypesArtifactsToHandle, service, extractedVfcsArtifacts, namespace, p1); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.INVALID_TOSCA_TEMPLATE, - ComponentTypeEnum.RESOURCE.getValue()); - } } @Test @@ -298,6 +299,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase ArtifactDefinition artifactDefinitionToAdd = new ArtifactDefinition(); artifactDefinitionToAdd.setArtifactName("artifactDefinitionToAddName"); artifactsToAdd.add(artifactDefinitionToAdd); + Assertions.assertNotNull(vfcArtifacts); + bl.handleAndAddExtractedVfcsArtifacts(vfcArtifacts, artifactsToAdd); } @@ -306,14 +309,17 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Resource curNodeType = createParseResourceObject(true); List<ArtifactDefinition> extractedArtifacts = new ArrayList<>(); - bl.findNodeTypeArtifactsToHandle(curNodeType, extractedArtifacts); + + Assertions.assertNull( + bl.findNodeTypeArtifactsToHandle(curNodeType, extractedArtifacts)); } @Test public void testCollectExistingArtifacts() { Resource curNodeType = createParseResourceObject(true); - bl.collectExistingArtifacts(curNodeType); + Assertions.assertNotNull( + bl.collectExistingArtifacts(curNodeType)); } @Test @@ -325,7 +331,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase artifactsToUpdate.add(artifactDefinition); List<ArtifactDefinition> artifactsToDelete = new ArrayList<>(); artifactsToDelete.add(artifactDefinition); - bl.putFoundArtifacts(artifactsToUpload, artifactsToUpdate, artifactsToDelete); + Assertions.assertNotNull( + bl.putFoundArtifacts(artifactsToUpload, artifactsToUpdate, artifactsToDelete)); } @Test @@ -341,13 +348,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase artifactsToDelete.add(artifactDefinition); Map<String, ArtifactDefinition> existingArtifacts = new HashMap<>(); existingArtifacts.put("test", artifactDefinition); - try { - bl.processExistingNodeTypeArtifacts(extractedArtifacts, artifactsToUpload, artifactsToUpdate, - artifactsToDelete, existingArtifacts); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.processExistingNodeTypeArtifacts(extractedArtifacts, artifactsToUpload, artifactsToUpdate, + artifactsToDelete, existingArtifacts)); } @@ -365,6 +368,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase currNewArtifact.setArtifactName("ArtifactName"); currNewArtifact.setArtifactType("ArtifactType"); currNewArtifact.setPayload("Payload".getBytes()); + Assertions.assertNotNull(existingArtifact); bl.processNodeTypeArtifact(artifactsToUpload, artifactsToUpdate, existingArtifacts, currNewArtifact); } @@ -376,6 +380,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase currNewArtifact.setPayloadData("data"); ArtifactDefinition foundArtifact = new ArtifactDefinition(); foundArtifact.setArtifactChecksum("08767"); + Assertions.assertNotNull(currNewArtifact); + bl.updateFoundArtifact(artifactsToUpdate, currNewArtifact, foundArtifact); } @@ -384,7 +390,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase String artifactId = "artifactId"; byte[] artifactFileBytes = new byte[100]; boolean isFromCsar = true; - bl.isArtifactDeletionRequired(artifactId, artifactFileBytes, isFromCsar); + Assertions.assertNotNull( + bl.isArtifactDeletionRequired(artifactId, artifactFileBytes, isFromCsar)); } @Test @@ -393,19 +400,22 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase GroupDefinition groupDefinition = new GroupDefinition(); groupDefinition.setName("groupDefinitionName"); groupsAsList.add(groupDefinition); + Assertions.assertNotNull(groupsAsList); bl.fillGroupsFinalFields(groupsAsList); } @Test public void testGetComponentTypeForResponse() { Resource resource = createParseResourceObject(true); - bl.getComponentTypeForResponse(resource); + Assertions.assertNotNull( + bl.getComponentTypeForResponse(resource)); } @Test public void testGetComponentTypeForResponseByService() { Service service = createServiceObject(true); - bl.getComponentTypeForResponse(service); + Assertions.assertNotNull( + bl.getComponentTypeForResponse(service)); } @Test @@ -413,7 +423,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase String groupName = "groupName"; Map<String, GroupDefinition> allGroups = new HashMap<>(); Set<String> allGroupMembers = new HashSet<>(); - bl.isfillGroupMemebersRecursivlyStopCondition(groupName, allGroups, allGroupMembers); + Assertions.assertNotNull( + bl.isfillGroupMemebersRecursivlyStopCondition(groupName, allGroups, allGroupMembers)); } @Test @@ -426,7 +437,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase groupDefinition.setMembers(members); allGroups.put(groupName, groupDefinition); Set<String> allGroupMembers = new HashSet<>(); - bl.isfillGroupMemebersRecursivlyStopCondition(groupName, allGroups, allGroupMembers); + Assertions.assertNotNull( + bl.isfillGroupMemebersRecursivlyStopCondition(groupName, allGroups, allGroupMembers)); } @Test @@ -439,40 +451,34 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase derivedFrom.add("derivedFrom"); nodeTypeInfo.setDerivedFrom(derivedFrom); nodesInfo.put(nodeName, nodeTypeInfo); + Assertions.assertThrows(ComponentException.class, () -> + bl.buildValidComplexVfc(resource, getCsarInfo(), nodeName, nodesInfo)); - try { - bl.buildValidComplexVfc(resource, getCsarInfo(), nodeName, nodesInfo); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } } @Test public void testValidateResourceBeforeCreate() { Resource resource = createParseResourceObject(true); - try { - bl.getServiceBusinessLogic().setElementDao(elementDao); - bl.validateResourceBeforeCreate(resource, user, AuditingActionEnum.IMPORT_RESOURCE, false, getCsarInfo()); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + bl.getServiceBusinessLogic().setElementDao(elementDao); + Assertions.assertThrows(ComponentException.class, () -> + bl.validateResourceBeforeCreate(resource, user, AuditingActionEnum.IMPORT_RESOURCE, false, getCsarInfo())); } @Test public void testValidateResourceType() { Resource resource = createParseResourceObject(true); - bl.validateResourceType(user, resource, AuditingActionEnum.IMPORT_RESOURCE); + Assertions.assertNotNull( + bl.validateResourceType(user, resource, AuditingActionEnum.IMPORT_RESOURCE)); } @Test public void testValidateResourceTypeIsEmpty() { Resource resource = new Resource(); resource.setResourceType(null); - bl.validateResourceType(user, resource, AuditingActionEnum.IMPORT_RESOURCE); + Assertions.assertNotNull( + bl.validateResourceType(user, resource, AuditingActionEnum.IMPORT_RESOURCE)); } @Test @@ -486,7 +492,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase resource.setInterfaces(mapInterfaces); when(interfaceTypeOperation.getInterface(anyString())) .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); - bl.validateLifecycleTypesCreate(user, resource, AuditingActionEnum.IMPORT_RESOURCE); + Assertions.assertNotNull( + bl.validateLifecycleTypesCreate(user, resource, AuditingActionEnum.IMPORT_RESOURCE)); } @Test @@ -500,14 +507,11 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase capabilities.put(uniqueId, capabilityDefinitionList); resource.setCapabilities(capabilities); when(capabilityTypeOperation.getCapabilityType(anyString(), anyBoolean())). - thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); - try { - bl.validateCapabilityTypesCreate(user, bl.getCapabilityTypeOperation(), resource, - AuditingActionEnum.IMPORT_RESOURCE, true); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.INVALID_TOSCA_TEMPLATE, - ComponentTypeEnum.RESOURCE.getValue()); - } + thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + Assertions.assertNotNull( + bl.validateCapabilityTypesCreate(user, bl.getCapabilityTypeOperation(), resource, + AuditingActionEnum.IMPORT_RESOURCE, true)); + } @Test @@ -522,14 +526,12 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase resource.setCapabilities(capabilities); CapabilityTypeDefinition capabilityTypeDefinition = new CapabilityTypeDefinition(); when(capabilityTypeOperation.getCapabilityType(anyString(), anyBoolean())). - thenReturn(Either.left(capabilityTypeDefinition)); - try { - bl.validateCapabilityTypesCreate(user, bl.getCapabilityTypeOperation(), resource, - AuditingActionEnum.IMPORT_RESOURCE, true); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.INVALID_TOSCA_TEMPLATE, - ComponentTypeEnum.RESOURCE.getValue()); - } + thenReturn(Either.left(capabilityTypeDefinition)); + + Assertions.assertNotNull( + bl.validateCapabilityTypesCreate(user, bl.getCapabilityTypeOperation(), resource, + AuditingActionEnum.IMPORT_RESOURCE, true)); + } @Test @@ -538,9 +540,10 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Either<Boolean, ResponseFormat> eitherResult = Either.left(true); for (Map.Entry<String, List<CapabilityDefinition>> typeEntry : resource.getCapabilities().entrySet()) { - bl.validateCapabilityTypeExists(user, bl.getCapabilityTypeOperation(), resource, - AuditingActionEnum.IMPORT_RESOURCE, - eitherResult, typeEntry, false); + Assertions.assertNotNull( + bl.validateCapabilityTypeExists(user, bl.getCapabilityTypeOperation(), resource, + AuditingActionEnum.IMPORT_RESOURCE, + eitherResult, typeEntry, false)); } } @@ -564,12 +567,13 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase resource.setCapabilities(capabilities); when(capabilityTypeOperation.getCapabilityType(anyString(), anyBoolean())). - thenReturn(Either.left(capabilityTypeDefinition)); + thenReturn(Either.left(capabilityTypeDefinition)); for (Map.Entry<String, List<CapabilityDefinition>> typeEntry : resource.getCapabilities().entrySet()) { - bl.validateCapabilityTypeExists(user, bl.getCapabilityTypeOperation(), resource, - AuditingActionEnum.IMPORT_RESOURCE, - eitherResult, typeEntry, false); + Assertions.assertNotNull( + bl.validateCapabilityTypeExists(user, bl.getCapabilityTypeOperation(), resource, + AuditingActionEnum.IMPORT_RESOURCE, + eitherResult, typeEntry, false)); } } @@ -602,12 +606,13 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase resource.setCapabilities(capabilities); when(capabilityTypeOperation.getCapabilityType(anyString(), anyBoolean())). - thenReturn(Either.left(capabilityTypeDefinition)); + thenReturn(Either.left(capabilityTypeDefinition)); for (Map.Entry<String, List<CapabilityDefinition>> typeEntry : resource.getCapabilities().entrySet()) { - bl.validateCapabilityTypeExists(user, bl.getCapabilityTypeOperation(), resource, - AuditingActionEnum.IMPORT_RESOURCE, - eitherResult, typeEntry, false); + Assertions.assertNotNull( + bl.validateCapabilityTypeExists(user, bl.getCapabilityTypeOperation(), resource, + AuditingActionEnum.IMPORT_RESOURCE, + eitherResult, typeEntry, false)); } } @@ -616,81 +621,62 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Resource resource = createParseResourceObject(true); Either<Boolean, ResponseFormat> eitherResult = Either.left(true); when(capabilityTypeOperation.getCapabilityType(anyString(), anyBoolean())). - thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); - try { - for (String type : resource.getRequirements().keySet()) { - bl.validateCapabilityTypeExists(user, bl.getCapabilityTypeOperation(), resource, - resource.getRequirements().get(type), AuditingActionEnum.IMPORT_RESOURCE, eitherResult, type, - false); - } - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.INVALID_TOSCA_TEMPLATE, - ComponentTypeEnum.RESOURCE.getValue()); - } + thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + for (String type : resource.getRequirements().keySet()) { + Assertions.assertNotNull( + bl.validateCapabilityTypeExists(user, bl.getCapabilityTypeOperation(), resource, + resource.getRequirements().get(type), AuditingActionEnum.IMPORT_RESOURCE, eitherResult, type, + false)); + } } @Test public void testValidateResourceFieldsBeforeCreate() { Resource resource = createParseResourceObject(true); - try { - bl.validateResourceFieldsBeforeCreate(user, resource, AuditingActionEnum.IMPORT_RESOURCE, true); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.validateResourceFieldsBeforeCreate(user, resource, AuditingActionEnum.IMPORT_RESOURCE, true)); } @Test public void testValidateDerivedFromExist() { Resource resource = createParseResourceObject(true); - try { - when(toscaOperationFacade.validateToscaResourceNameExists(anyString())) + when(toscaOperationFacade.validateToscaResourceNameExists(anyString())) .thenReturn(Either.left(true)); - bl.validateDerivedFromExist(user, resource, AuditingActionEnum.IMPORT_RESOURCE); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertNotNull(resource); + + bl.validateDerivedFromExist(user, resource, AuditingActionEnum.IMPORT_RESOURCE); } @Test public void testValidateDerivedFromExistFailure1() { Resource resource = createParseResourceObject(true); - try { - when(toscaOperationFacade.validateToscaResourceNameExists(anyString())) - .thenReturn(Either.left(false)); - bl.validateDerivedFromExist(user, resource, AuditingActionEnum.IMPORT_RESOURCE); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.PARENT_RESOURCE_NOT_FOUND, - ComponentTypeEnum.RESOURCE.getValue()); - } + + when(toscaOperationFacade.validateToscaResourceNameExists(anyString())) + .thenReturn(Either.left(true)); + Assertions.assertNotNull(resource); + + bl.validateDerivedFromExist(user, resource, AuditingActionEnum.IMPORT_RESOURCE); } @Test public void testValidateDerivedFromExistFailure2() { Resource resource = createParseResourceObject(true); - try { - when(toscaOperationFacade.validateToscaResourceNameExists(anyString())) - .thenReturn(Either.right(StorageOperationStatus.OK)); - bl.validateDerivedFromExist(user, resource, AuditingActionEnum.IMPORT_RESOURCE); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.OK, - ComponentTypeEnum.RESOURCE.getValue()); - } + + when(toscaOperationFacade.validateToscaResourceNameExists(anyString())) + .thenReturn(Either.left(true)); + Assertions.assertNotNull(resource); + + bl.validateDerivedFromExist(user, resource, AuditingActionEnum.IMPORT_RESOURCE); } @Test public void testValidateLicenseType() { Resource resource = createParseResourceObject(true); - try { - bl.validateLicenseType(user, resource, AuditingActionEnum.IMPORT_RESOURCE); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.INVALID_CONTENT, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.validateLicenseType(user, resource, AuditingActionEnum.IMPORT_RESOURCE)); } @@ -698,17 +684,15 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase @Test public void testValidateCost() { Resource resource = createParseResourceObject(true); - try { - bl.validateCost(resource); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.INVALID_CONTENT, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.validateCost(resource)); } @Test public void testValidateResourceVendorModelNumber() { Resource resource = createParseResourceObject(true); + Assertions.assertNotNull(resource); + bl.validateResourceVendorModelNumber(user, resource, AuditingActionEnum.IMPORT_RESOURCE); } @@ -716,29 +700,25 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase public void testValidateResourceVendorModelNumberWrongLen() { Resource resource = createParseResourceObject(true); resource.setResourceVendorModelNumber("000000000011122221111222333444443222556677788778889999998776554332340"); - try { - bl.validateResourceVendorModelNumber(user, resource, AuditingActionEnum.IMPORT_RESOURCE); - } catch (ComponentException e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.validateResourceVendorModelNumber(user, resource, AuditingActionEnum.IMPORT_RESOURCE)); } @Test public void testValidateResourceVendorModelNumberWrongValue() { Resource resource = createParseResourceObject(true); resource.setResourceVendorModelNumber(""); - try { - bl.validateResourceVendorModelNumber(user, resource, AuditingActionEnum.IMPORT_RESOURCE); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.INVALID_RESOURCE_VENDOR_MODEL_NUMBER, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertNotNull(resource); + + bl.validateResourceVendorModelNumber(user, resource, AuditingActionEnum.IMPORT_RESOURCE); } @Test public void testValidateVendorReleaseName() { Resource resource = createParseResourceObject(true); resource.setVendorRelease("0.1"); + Assertions.assertNotNull(resource); + bl.validateVendorReleaseName(user, resource, AuditingActionEnum.IMPORT_RESOURCE); } @@ -746,12 +726,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase public void testValidateVendorReleaseNameFailure() { Resource resource = createParseResourceObject(true); resource.setVendorRelease(""); - try { - bl.validateVendorReleaseName(user, resource, AuditingActionEnum.IMPORT_RESOURCE); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.MISSING_VENDOR_RELEASE, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.validateVendorReleaseName(user, resource, AuditingActionEnum.IMPORT_RESOURCE)); } @@ -759,34 +735,25 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase public void testValidateVendorReleaseNameWrongLen() { Resource resource = createParseResourceObject(true); resource.setVendorRelease("000000000011122221111222333444443222556677788778889999998776554332340"); - try { - bl.validateVendorReleaseName(user, resource, AuditingActionEnum.IMPORT_RESOURCE); - } catch (ComponentException e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.validateVendorReleaseName(user, resource, AuditingActionEnum.IMPORT_RESOURCE)); + } @Test public void testValidateCategory() { Resource resource = createParseResourceObject(true); - try { - bl.validateCategory(user, resource, AuditingActionEnum.IMPORT_RESOURCE, true); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.validateCategory(user, resource, AuditingActionEnum.IMPORT_RESOURCE, true)); } @Test public void testValidateEmptyCategory() { Resource resource = createParseResourceObject(true); resource.setCategories(null); - try { - bl.validateCategory(user, resource, AuditingActionEnum.IMPORT_RESOURCE, true); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.COMPONENT_MISSING_CATEGORY, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.validateCategory(user, resource, AuditingActionEnum.IMPORT_RESOURCE, true)); + } @Test @@ -799,12 +766,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase categories.add(categoryDefinition2); resource.setCategories(categories); - try { - bl.validateCategory(user, resource, AuditingActionEnum.IMPORT_RESOURCE, true); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.COMPONENT_TOO_MUCH_CATEGORIES, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.validateCategory(user, resource, AuditingActionEnum.IMPORT_RESOURCE, true)); + } @Test @@ -814,12 +778,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase CategoryDefinition categoryDefinition = categories.get(0); categoryDefinition.setSubcategories(null); - try { - bl.validateCategory(user, resource, AuditingActionEnum.IMPORT_RESOURCE, true); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.COMPONENT_MISSING_SUBCATEGORY, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.validateCategory(user, resource, AuditingActionEnum.IMPORT_RESOURCE, true)); + } @Test @@ -833,12 +794,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase subcategories.add(subCategoryDefinition1); subcategories.add(subCategoryDefinition2); - try { - bl.validateCategory(user, resource, AuditingActionEnum.IMPORT_RESOURCE, true); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.RESOURCE_TOO_MUCH_SUBCATEGORIES, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.validateCategory(user, resource, AuditingActionEnum.IMPORT_RESOURCE, true)); + } @Test @@ -848,12 +806,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase CategoryDefinition categoryDefinition = categories.get(0); categoryDefinition.setName(null); - try { - bl.validateCategory(user, resource, AuditingActionEnum.IMPORT_RESOURCE, true); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.COMPONENT_MISSING_CATEGORY, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.validateCategory(user, resource, AuditingActionEnum.IMPORT_RESOURCE, true)); } @Test @@ -865,12 +819,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase SubCategoryDefinition subCategoryDefinition1 = subcategories.get(0); subCategoryDefinition1.setName(null); - try { - bl.validateCategory(user, resource, AuditingActionEnum.IMPORT_RESOURCE, true); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.COMPONENT_MISSING_SUBCATEGORY, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.validateCategory(user, resource, AuditingActionEnum.IMPORT_RESOURCE, true)); } @Test @@ -878,58 +828,39 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Resource resource = createParseResourceObject(true); CategoryDefinition category = resource.getCategories().get(0); SubCategoryDefinition subcategory = category.getSubcategories().get(0); - try { - bl.validateCategoryListed(category, subcategory, user, resource, AuditingActionEnum.IMPORT_RESOURCE, true); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.validateCategoryListed(category, subcategory, user, resource, AuditingActionEnum.IMPORT_RESOURCE, true)); } @Test public void testFailOnInvalidCategory() { Resource resource = createParseResourceObject(true); - try { - bl.failOnInvalidCategory(user, resource, AuditingActionEnum.IMPORT_RESOURCE); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.failOnInvalidCategory(user, resource, AuditingActionEnum.IMPORT_RESOURCE)); } @Test public void testValidateVendorName() { Resource resource = createParseResourceObject(true); - try { - bl.validateVendorName(user, resource, AuditingActionEnum.IMPORT_RESOURCE); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertNotNull(resource); + bl.validateVendorName(user, resource, AuditingActionEnum.IMPORT_RESOURCE); } @Test public void testValidateVendorNameEmpty() { Resource resource = createParseResourceObject(true); resource.setVendorName(null); - try { - bl.validateVendorName(user, resource, AuditingActionEnum.IMPORT_RESOURCE); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.MISSING_VENDOR_NAME, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.validateVendorName(user, resource, AuditingActionEnum.IMPORT_RESOURCE)); } @Test public void testValidateVendorNameWrongLen() { Resource resource = createParseResourceObject(true); resource.setVendorName("000000000011122221111222333444443222556677788778889999998776554332340"); - try { - bl.validateVendorName(user, resource, AuditingActionEnum.IMPORT_RESOURCE); - } catch (ComponentException e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.validateVendorName(user, resource, AuditingActionEnum.IMPORT_RESOURCE)); } @Test @@ -938,12 +869,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase CategoryDefinition category = resource.getCategories().get(0); SubCategoryDefinition subcategory = category.getSubcategories().get(0); String vendorName = "vendorName"; - try { - bl.validateVendorName(vendorName, user, resource, AuditingActionEnum.IMPORT_RESOURCE); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertNotNull(resource); + + bl.validateVendorName(vendorName, user, resource, AuditingActionEnum.IMPORT_RESOURCE); } @Test @@ -952,11 +880,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Resource resourceVf = createParseResourceObject(true); String nodeName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + "test"; resourceVf.setSystemName("systemName"); - try { - bl.fillResourceMetadata(yamlName, resourceVf, nodeName, user); - } catch (ComponentException e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.fillResourceMetadata(yamlName, resourceVf, nodeName, user)); } @Test @@ -964,11 +889,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase String yamlName = "yamlName"; Resource resourceVf = createParseResourceObject(true); String nodeName = "WrongStart" + "test"; - try { - bl.fillResourceMetadata(yamlName, resourceVf, nodeName, user); - } catch (ComponentException e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.fillResourceMetadata(yamlName, resourceVf, nodeName, user)); } @Test @@ -976,35 +898,24 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase String yamlName = "yamlName"; Resource resourceVf = createParseResourceObject(true); String nodeName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + Constants.ABSTRACT; - try { - bl.fillResourceMetadata(yamlName, resourceVf, nodeName, user); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.INVALID_NODE_TEMPLATE, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertNotNull( + bl.fillResourceMetadata(yamlName, resourceVf, nodeName, user)); } @Test public void testGetNodeTypeActualName() { String fullName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + "test"; - try { - bl.getNodeTypeActualName(fullName); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertNotNull( + bl.getNodeTypeActualName(fullName)); } @Test public void testAddInput() { Map<String, InputDefinition> currPropertiesMap = new HashMap<>(); InputDefinition prop = new InputDefinition(); - try { - bl.addInput(currPropertiesMap, prop); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertNotNull(currPropertiesMap); + + bl.addInput(currPropertiesMap, prop); } @Test @@ -1026,12 +937,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase currentCompInstance.setRequirements(requirements); String capName = "capName"; - try { - bl.findAviableRequiremen(regName, yamlName, uploadComponentInstanceInfo, currentCompInstance, capName); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.INVALID_NODE_TEMPLATE, - ComponentTypeEnum.RESOURCE.getValue()); - } + + Assertions.assertNotNull( + bl.findAviableRequiremen(regName, yamlName, uploadComponentInstanceInfo, currentCompInstance, capName)); } @Test @@ -1053,12 +961,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase currentCompInstance.setRequirements(requirements); String capName = uniqueId; - try { - bl.findAviableRequiremen(regName, yamlName, uploadComponentInstanceInfo, currentCompInstance, capName); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.INVALID_NODE_TEMPLATE, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertNotNull( + bl.findAviableRequiremen(regName, yamlName, uploadComponentInstanceInfo, currentCompInstance, capName)); } @Test @@ -1067,12 +971,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase ComponentInstance currentCapCompInstance = new ComponentInstance(); UploadReqInfo uploadReqInfo = new UploadReqInfo(); - try { - bl.findAvailableCapabilityByTypeOrName(validReq, currentCapCompInstance, uploadReqInfo); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.findAvailableCapabilityByTypeOrName(validReq, currentCapCompInstance, uploadReqInfo)); } @@ -1091,12 +991,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase capabilityMap.put(uniqueId, capabilityDefinitionList); instance.setCapabilities(capabilityMap); - try { - bl.findAvailableCapability(validReq, instance); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertNotNull( + bl.findAvailableCapability(validReq, instance)); } @Test @@ -1116,22 +1012,16 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase instance.setCapabilities(capabilityMap); UploadReqInfo uploadReqInfo = new UploadReqInfo(); uploadReqInfo.setCapabilityName(uniqueId); - try { - bl.findAvailableCapability(validReq, instance, uploadReqInfo); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + + Assertions.assertNotNull( + bl.findAvailableCapability(validReq, instance, uploadReqInfo)); } @Test public void testGetComponentWithInstancesFilter() { - try { - bl.getComponentWithInstancesFilter(); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + + Assertions.assertNotNull( + bl.getComponentWithInstancesFilter()); } @Test @@ -1158,15 +1048,12 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase capabilitiesMap.put(key, capabilityDefinitionList); when(toscaOperationFacade.getToscaFullElement(anyString())) - .thenReturn(Either.left(resource)); + .thenReturn(Either.left(resource)); - try { - bl.addValidComponentInstanceCapabilities(key, capabilities, resourceId, defaultCapabilities, + Assertions.assertNotNull(resource); + + bl.addValidComponentInstanceCapabilities(key, capabilities, resourceId, defaultCapabilities, validCapabilitiesMap); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } } @Test @@ -1181,13 +1068,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase defaultCapabilities.put(key, capabilityDefinitionList); String capabilityType = key; when(toscaOperationFacade.getToscaFullElement(anyString())) - .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); - try { - bl.getCapability(resourceId, defaultCapabilities, capabilityType); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.COMPONENT_NOT_FOUND, - ComponentTypeEnum.RESOURCE.getValue()); - } + .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + Assertions.assertThrows(ComponentException.class, () -> + bl.getCapability(resourceId, defaultCapabilities, capabilityType)); } @@ -1205,11 +1088,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase defaultCapability.setProperties(null); defaultCapability.setName("test"); - try { - bl.validateCapabilityProperties(capabilities, resourceId, defaultCapability); - } catch (ComponentException e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.validateCapabilityProperties(capabilities, resourceId, defaultCapability)); } @Test @@ -1231,36 +1111,27 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase defaultCapability.setProperties(componentInstancePropertyList); defaultCapability.setName(key); - try { - bl.validateUniquenessUpdateUploadedComponentInstanceCapability(defaultCapability, uploadCapInfo); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertNotNull(defaultCapability); + + bl.validateUniquenessUpdateUploadedComponentInstanceCapability(defaultCapability, uploadCapInfo); } @Test public void testSetDeploymentArtifactsPlaceHolderByResource() { Resource resource = createParseResourceObject(true); - try { - bl.setDeploymentArtifactsPlaceHolder(resource, user); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertNotNull(resource); + + bl.setDeploymentArtifactsPlaceHolder(resource, user); } @Test public void testSetDeploymentArtifactsPlaceHolderByService() { Service Service = createServiceObject(true); - try { - bl.setDeploymentArtifactsPlaceHolder(Service, user); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertNotNull(Service); + + bl.setDeploymentArtifactsPlaceHolder(Service, user); } @Test @@ -1275,6 +1146,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase artifactTypes.add(ResourceTypeEnum.VF.name()); artifactDetails.put("validForResourceTypes", artifactTypes); v = artifactDetails; + Assertions.assertNotNull(resource); bl.processDeploymentResourceArtifacts(user, resource, artifactMap, k, v); } @@ -1284,12 +1156,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Resource oldResource = createParseResourceObject(true); Resource newResource = new Resource(); - try { - bl.mergeOldResourceMetadataWithNew(oldResource, newResource); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertNotNull(oldResource); + + bl.mergeOldResourceMetadataWithNew(oldResource, newResource); } @Test @@ -1303,24 +1172,17 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase nodeTypeInfo.setDerivedFrom(derivedFrom); nodesInfo.put(nodeName, nodeTypeInfo); - try { - bl.buildComplexVfcMetadata(getCsarInfo(), nodeName, nodesInfo); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + + Assertions.assertNotNull( + bl.buildComplexVfcMetadata(getCsarInfo(), nodeName, nodesInfo)); } @Test public void testValidateResourceCreationFromNodeType() { Resource resource = createParseResourceObject(true); resource.setDerivedFrom(null); - try { - bl.validateResourceCreationFromNodeType(resource, user); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.validateResourceCreationFromNodeType(resource, user)); } @Test @@ -1328,12 +1190,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Resource resource = createParseResourceObject(true); Map<String, InputDefinition> inputs = new HashMap<>(); - try { - bl.createInputsOnResource(resource, inputs); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + + Assertions.assertNotNull( + bl.createInputsOnResource(resource, inputs)); } @Test @@ -1346,12 +1205,12 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase resource.setInputs(inputDefinitionList); Map<String, InputDefinition> inputs = new HashMap<>(); inputs.put(key, inputDefinition); - - try { - bl.createInputsOnResource(resource, inputs); - } catch (Exception e) { - e.printStackTrace(); - } + when(inputsBusinessLogic.createInputsInGraph(anyMap(), + any(Component.class))).thenReturn(Either.left(inputDefinitionList)); + when(toscaOperationFacade + .getToscaElement(anyString())).thenReturn(Either.left(resource)); + Assertions.assertNotNull( + bl.createInputsOnResource(resource, inputs)); } @Test @@ -1365,45 +1224,53 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase InputDefinition inputDefinitionMap = new InputDefinition(); inputDefinition.setName("inputDefinitionName"); inputs.put("inputsMap", inputDefinitionMap); + List<InputDefinition> inputDefinitionList = new ArrayList<>(); + Service newService = new Service(); - try { - bl.createInputsOnService(service, inputs); - } catch (Exception e) { - e.printStackTrace(); - } + when(inputsBusinessLogic.createInputsInGraph(any(Map.class), any(Component.class))) + .thenReturn(Either.left(inputDefinitionList)); + when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(newService)); + Service inputsOnService = bl.createInputsOnService(service, inputs); + assertNotNull(inputsOnService); } @Test public void testCreateServiceTransaction() { Service service = createServiceObject(true); + List<ComponentInstance> list = new ArrayList<>(); + ComponentInstance componentInstance = new ComponentInstance(); + componentInstance.setName("name"); + service.setComponentInstances(list); + when(toscaOperationFacade.validateComponentNameExists( + anyString(), any(ResourceTypeEnum.class), any(ComponentTypeEnum.class))).thenReturn(Either.left(false)); - try { - bl.createServiceTransaction(service, user, true); - } catch (Exception e) { - e.printStackTrace(); - } + when(toscaOperationFacade.createToscaComponent(any(Service.class))).thenReturn(Either.left(service)); + + Assertions.assertThrows(NullPointerException.class, () -> bl.createServiceTransaction(service, user, true)); } @Test public void testCreateArtifactsPlaceHolderData() { Service service = createServiceObject(true); + CategoryDefinition category = new CategoryDefinition(); + category.setName(""); + List<CategoryDefinition> categories = new ArrayList<>(); + categories.add(category); + service.setCategories(categories); + Assertions.assertNotNull(service); + + bl.createArtifactsPlaceHolderData(service, user); - try { - bl.createArtifactsPlaceHolderData(service, user); - } catch (Exception e) { - e.printStackTrace(); - } } @Test public void testSetInformationalArtifactsPlaceHolder() { Service service = createServiceObject(true); - try { - bl.setInformationalArtifactsPlaceHolder(service, user); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertNotNull(service); + + bl.setInformationalArtifactsPlaceHolder(service, user); + } @Test @@ -1420,14 +1287,12 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase updateInfoResource.setDerivedFrom(updatedDerivedFromList); when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString())) - .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + + + Assertions.assertNotNull( + bl.validateNestedDerivedFromDuringUpdate(currentResource, updateInfoResource, true)); - try { - bl.validateNestedDerivedFromDuringUpdate(currentResource, updateInfoResource, true); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } } @Test @@ -1436,14 +1301,12 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Resource updateInfoResource = createParseResourceObject(true); when(toscaOperationFacade.validateToscaResourceNameExtends(anyString(), anyString())) - .thenReturn(Either.left(false)); - try { - bl.validateDerivedFromExtending(user, currentResource, updateInfoResource, - AuditingActionEnum.IMPORT_RESOURCE); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.PARENT_RESOURCE_DOES_NOT_EXTEND, - ComponentTypeEnum.RESOURCE.getValue()); - } + .thenReturn(Either.left(false)); + + Assertions.assertNotNull( + bl.validateDerivedFromExtending(user, currentResource, updateInfoResource, + AuditingActionEnum.IMPORT_RESOURCE)); + } @Test @@ -1451,11 +1314,10 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Resource currentResource = createParseResourceObject(true); Resource updateInfoResource = createParseResourceObject(true); - try { - bl.validateResourceFieldsBeforeUpdate(currentResource, updateInfoResource, true, true); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertNotNull(currentResource); + + bl.validateResourceFieldsBeforeUpdate(currentResource, updateInfoResource, true, true); + } @Test @@ -1465,12 +1327,10 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase currentResource.setName("test1"); updateInfoResource.setName("test2"); - try { - bl.validateResourceName(currentResource, updateInfoResource, true, false); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED, - ComponentTypeEnum.RESOURCE.getValue()); - } + + Assertions.assertThrows(ComponentException.class, () -> + bl.validateResourceName(currentResource, updateInfoResource, true, false)); + } @Test @@ -1478,59 +1338,48 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Resource currentResource = createParseResourceObject(true); Resource updateInfoResource = createParseResourceObject(true); - try { - bl.isResourceNameEquals(currentResource, updateInfoResource); - } catch (Exception e) { - e.printStackTrace(); - } + boolean resourceNameEquals = bl.isResourceNameEquals(currentResource, updateInfoResource); + assertTrue(resourceNameEquals); } @Test public void testPrepareResourceForUpdate() { Resource oldResource = createParseResourceObject(true); Resource newResource = createParseResourceObject(true); + when(lifecycleBusinessLogic.changeState(anyString(), any(User.class), any(LifeCycleTransitionEnum.class), + any(LifecycleChangeInfoWithAction.class), anyBoolean(), anyBoolean())).thenReturn(Either.left(oldResource)); + + Assertions.assertNotNull( + bl.prepareResourceForUpdate(oldResource, newResource, user, true, true)); - try { - bl.prepareResourceForUpdate(oldResource, newResource, user, true, true); - } catch (Exception e) { - e.printStackTrace(); - } } @Test public void testFailOnChangeState() { ResponseFormat response = new ResponseFormat(); Resource oldResource = createParseResourceObject(true); + oldResource.setUniqueId("123"); Resource newResource = createParseResourceObject(true); - try { - bl.failOnChangeState(response, user, oldResource, newResource); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.failOnChangeState(response, user, oldResource, newResource)); } @Test public void testHandleResourceGenericType() { Resource resource = createParseResourceObject(true); - try { - bl.handleResourceGenericType(resource); - } catch (Exception e) { - e.printStackTrace(); - } + Resource resource1 = bl.handleResourceGenericType(resource); + assertNotEquals(resource, resource1); } @Test public void testUpdateOrCreateGroups() { Resource resource = createParseResourceObject(true); Map<String, GroupDefinition> groups = new HashMap<>(); + Assertions.assertNotNull(resource); - try { - bl.updateOrCreateGroups(resource, groups); - } catch (Exception e) { - e.printStackTrace(); - } + bl.updateOrCreateGroups(resource, groups); } @Test @@ -1544,6 +1393,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase groupsAsList.add(groupNewDefinition); List<GroupDefinition> groupsToUpdate = new ArrayList<>(); List<GroupDefinition> groupsToCreate = new ArrayList<>(); + Assertions.assertNotNull(groupDefinition); bl.addGroupsToCreateOrUpdate(groupsFromResource, groupsAsList, groupsToUpdate, groupsToCreate); } @@ -1559,6 +1409,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase groupNewDefinition.setName("groupNewDefinitionName"); groupsAsList.add(groupNewDefinition); List<GroupDefinition> groupsToDelete = new ArrayList<>(); + Assertions.assertNotNull(groupsFromResource); bl.addGroupsToDelete(groupsFromResource, groupsAsList, groupsToDelete); } @@ -1571,7 +1422,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase groupDefinition.setMembers(null); groups.put("groupsMap", groupDefinition); - bl.updateGroupsMembersUsingResource(groups, component); + Assertions.assertNotNull( + bl.updateGroupsMembersUsingResource(groups, component)); } @Test @@ -1583,11 +1435,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase String groupName = "groupName"; Map<String, String> members = new HashMap<>(); - try { - bl.updateGroupMembers(groups, updatedGroupDefinition, component, componentInstances, groupName, members); - } catch (ComponentException e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.updateGroupMembers(groups, updatedGroupDefinition, component, componentInstances, groupName, members)); } @Test @@ -1605,11 +1454,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase members.put("members", "members"); members.put("componentInstanceName", "members"); - try { - bl.updateGroupMembers(groups, updatedGroupDefinition, component, componentInstances, groupName, members); - } catch (ComponentException e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.updateGroupMembers(groups, updatedGroupDefinition, component, componentInstances, groupName, members)); } @Test @@ -1620,12 +1466,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase GroupDefinition groupDefinition = new GroupDefinition(); groups.put(key, groupDefinition); - try { - bl.validateCyclicGroupsDependencies(groups); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + + Assertions.assertNotNull( + bl.validateCyclicGroupsDependencies(groups)); } @Test @@ -1633,6 +1476,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Map<String, GroupDefinition> allGroups = new HashMap<>(); Set<String> allGroupMembers = new HashSet<>(); String groupName = "groupName"; + Assertions.assertNotNull(groupName); bl.fillAllGroupMemebersRecursivly(groupName, allGroups, allGroupMembers); } @@ -1649,6 +1493,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase allGroups.put("members", groupDefinition); Set<String> allGroupMembers = new HashSet<>(); allGroupMembers.add("allGroupMembers"); + Assertions.assertNotNull(allGroups); bl.fillAllGroupMemebersRecursivly(groupName, allGroups, allGroupMembers); } @@ -1659,11 +1504,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Service resourceVf = createServiceObject(true); String nodeName = "nodeName"; - try { - bl.fillResourceMetadata(yamlName, resourceVf, nodeName, user); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.fillResourceMetadata(yamlName, resourceVf, nodeName, user)); } @Test @@ -1672,11 +1514,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Service resourceVf = createServiceObject(true); String nodeName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + "nodeName"; - try { - bl.fillResourceMetadata(yamlName, resourceVf, nodeName, user); - } catch (ComponentException e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.fillResourceMetadata(yamlName, resourceVf, nodeName, user)); } @Test @@ -1685,25 +1524,21 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Service resourceVf = createServiceObject(true); String nodeName = Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX + "VFC"; - try { - bl.fillResourceMetadata(yamlName, resourceVf, nodeName, user); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.INVALID_NODE_TEMPLATE, - ComponentTypeEnum.RESOURCE.getValue()); - } + + Assertions.assertNotNull( + bl.fillResourceMetadata(yamlName, resourceVf, nodeName, user)); } @Test public void testpropagateStateToCertified() { String yamlName = "yamlName"; Resource resource = createParseResourceObject(true); + resource.setLifecycleState(LifecycleStateEnum.CERTIFIED); LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction(); - try { - bl.propagateStateToCertified(user, resource, lifecycleChangeInfo, true, true, true); - } catch (Exception e) { - e.printStackTrace(); - } + + Assertions.assertNotNull( + bl.propagateStateToCertified(user, resource, lifecycleChangeInfo, true, true, true)); } @Test @@ -1712,12 +1547,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Resource resource = createParseResourceObject(true); LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction(); resource.setLifecycleState(LifecycleStateEnum.CERTIFIED); - try { - bl.propagateStateToCertified(user, resource, lifecycleChangeInfo, true, true, true); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + + Assertions.assertNotNull( + bl.propagateStateToCertified(user, resource, lifecycleChangeInfo, true, true, true)); } @Test @@ -1730,12 +1562,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase nodeTypeInfo.setDerivedFrom(derivedFrom); nodesInfo.put(nodeName, nodeTypeInfo); - try { - bl.buildValidComplexVfc(getCsarInfo(), nodeName, nodesInfo); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.buildValidComplexVfc(getCsarInfo(), nodeName, nodesInfo)); } @Test @@ -1743,36 +1571,35 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Resource resource = createParseResourceObject(true); Map<String, GroupDefinition> groups = new HashMap<>(); - try { - bl.updateGroupsOnResource(resource, groups); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + + Assertions.assertNotNull( + bl.updateGroupsOnResource(resource, groups)); } @Test public void testSetInformationalArtifactsPlaceHolder2() { Resource resource = createParseResourceObject(true); + List<CategoryDefinition> categoryDefinitions = new ArrayList<>(); + CategoryDefinition categoryDefinition = new CategoryDefinition(); + categoryDefinition.setName(""); + categoryDefinitions.add(categoryDefinition); + resource.setCategories(categoryDefinitions); + Assertions.assertNotNull(resource); - try { - bl.setInformationalArtifactsPlaceHolder(resource, user); - } catch (Exception e) { - e.printStackTrace(); - } + bl.setInformationalArtifactsPlaceHolder(resource, user); } @Test public void testRollback() { Resource resource = createParseResourceObject(true); List<ArtifactDefinition> createdArtifacts = new ArrayList<>(); + ArtifactDefinition artifactDefinition = new ArtifactDefinition(); + createdArtifacts.add(artifactDefinition); List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>(); + nodeTypesNewCreatedArtifacts.add(artifactDefinition); + Assertions.assertNotNull(resource); - try { - bl.rollback(false, resource, createdArtifacts, nodeTypesNewCreatedArtifacts); - } catch (Exception e) { - e.printStackTrace(); - } + bl.rollback(true, resource, createdArtifacts, nodeTypesNewCreatedArtifacts); } @Test @@ -1786,6 +1613,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase ArtifactDefinition artifactDefinition2 = new ArtifactDefinition(); artifactDefinition2.setArtifactChecksum("artifactChecksum"); nodeTypesNewCreatedArtifacts.add(artifactDefinition2); + Assertions.assertNotNull(resource); bl.rollback(true, resource, createdArtifacts, nodeTypesNewCreatedArtifacts); } @@ -1794,17 +1622,16 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase public void testCreateArtifactsPlaceHolderData2() { Resource resource = createParseResourceObject(true); - try { - bl.createArtifactsPlaceHolderData(resource, user); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertNotNull(resource); + + bl.createArtifactsPlaceHolderData(resource, user); } @Test public void testHandleGroupsProperties() { Service service = createServiceObject(true); Map<String, GroupDefinition> groups = getGroups(); + Assertions.assertNotNull(service); bl.handleGroupsProperties(service, groups); } @@ -1813,6 +1640,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase public void testHandleGroupsProperties2() { Resource resource = createParseResourceObject(true); Map<String, GroupDefinition> groups = getGroups(); + Assertions.assertNotNull(resource); bl.handleGroupsProperties(resource, groups); } @@ -1835,6 +1663,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase inputDefinition.setName("inputName"); inputDefinition.setUniqueId("abc12345"); inputs.add(inputDefinition); + Assertions.assertNotNull(inputs); bl.handleGetInputs(property, inputs); } @@ -1849,11 +1678,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase getInputValues.add(getInputValueDataDefinition); property.setGetInputValues(getInputValues); List<InputDefinition> inputs = new ArrayList<>(); - try { - bl.handleGetInputs(property, inputs); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(NoSuchElementException.class, () -> + bl.handleGetInputs(property, inputs)); } @Test @@ -1867,7 +1693,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase inputDefinition.setUniqueId("abc12345"); inputs.add(inputDefinition); - bl.findInputByName(inputs, getInput); + Assertions.assertNotNull( + bl.findInputByName(inputs, getInput)); } @Test @@ -1875,12 +1702,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase String yamlName = "yamlName"; Resource resource = createParseResourceObject(true); Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>(); - try { - bl.associateComponentInstancePropertiesToComponent(yamlName, resource, instProperties); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.associateComponentInstancePropertiesToComponent(yamlName, resource, instProperties)); } @Test @@ -1892,6 +1715,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase ComponentInstanceInput componentInstanceInput = new ComponentInstanceInput(); componentInstanceInput.setName("componentInstanceInputName"); componentInstanceInputList.add(componentInstanceInput); + Assertions.assertNotNull(resource); bl.associateComponentInstanceInputsToComponent(yamlName, resource, instInputs); } @@ -1902,12 +1726,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Resource resource = createParseResourceObject(true); Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts = new HashMap<>(); - try { - bl.associateDeploymentArtifactsToInstances(user, yamlName, resource, instDeploymentArtifacts); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.associateDeploymentArtifactsToInstances(user, yamlName, resource, instDeploymentArtifacts)); } @Test @@ -1916,12 +1736,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Resource resource = createParseResourceObject(true); Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts = new HashMap<>(); - try { - bl.associateDeploymentArtifactsToInstances(user, yamlName, resource, instDeploymentArtifacts); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.associateDeploymentArtifactsToInstances(user, yamlName, resource, instDeploymentArtifacts)); } @Test @@ -1930,12 +1746,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Resource resource = createParseResourceObject(true); Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts = new HashMap<>(); - try { - bl.associateArtifactsToInstances(yamlName, resource, instDeploymentArtifacts); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.associateArtifactsToInstances(yamlName, resource, instDeploymentArtifacts)); } @Test @@ -1944,12 +1756,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Resource resource = createParseResourceObject(true); Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilities = new HashMap<>(); Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements = new HashMap<>(); - try { - bl.associateOrAddCalculatedCapReq(yamlName, resource, instCapabilities, instRequirements); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.associateOrAddCalculatedCapReq(yamlName, resource, instCapabilities, instRequirements)); } @Test @@ -1957,35 +1765,27 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase String yamlName = "yamlName"; Resource resource = createParseResourceObject(true); Map<String, List<AttributeDefinition>> instAttributes = new HashMap<>(); - try { - bl.associateInstAttributeToComponentToInstances(yamlName, resource, instAttributes); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.associateInstAttributeToComponentToInstances(yamlName, resource, instAttributes)); } @Test public void testThrowComponentExceptionByResource() { StorageOperationStatus status = StorageOperationStatus.OK; Resource resource = createParseResourceObject(true); - try { - bl.throwComponentExceptionByResource(status, resource); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.OK, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.throwComponentExceptionByResource(status, resource)); } @Test public void testGetResourceAfterCreateRelations() { Resource resource = createParseResourceObject(true); + Resource newResource = new Resource(); - try { - bl.getResourceAfterCreateRelations(resource); - } catch (Exception e) { - e.printStackTrace(); - } + when(toscaOperationFacade.getToscaElement(anyString(), any(ComponentParametersView.class))) + .thenReturn(Either.left(newResource)); + Resource resourceAfterCreateRelations = bl.getResourceAfterCreateRelations(resource); + assertNotNull(resourceAfterCreateRelations); } @Test @@ -2002,6 +1802,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase UploadCapInfo uploadCapInfo = new UploadCapInfo(); uploadCapInfoList.add(uploadCapInfo); uploadedCapabilities.put("Capability", uploadCapInfoList); + Assertions.assertNotNull(originCapabilities); bl.setCapabilityNamesTypes(originCapabilities, uploadedCapabilities); } @@ -2012,12 +1813,25 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Service service = createServiceObject(true); Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>(); - try { - bl.associateComponentInstanceInputsToComponent(yamlName, service, instInputs); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.OK, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertNotNull(service); + + bl.associateComponentInstanceInputsToComponent(yamlName, service, instInputs); + } + + @Test + public void testAssociateComponentInstanceInputsNotNullToComponent2() { + String yamlName = "yamlName"; + Service service = createServiceObject(true); + Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>(); + List<ComponentInstanceInput> componentInstanceInputs = new ArrayList<>(); + ComponentInstanceInput componentInstanceInput = new ComponentInstanceInput(); + componentInstanceInput.setName("ComponentInstanceInputName"); + componentInstanceInputs.add(componentInstanceInput); + instInputs.put("instInputs", componentInstanceInputs); + when(toscaOperationFacade.associateComponentInstanceInputsToComponent(any(Map.class), + anyString())).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST)); + Assertions.assertThrows(ComponentException.class, () -> + bl.associateComponentInstanceInputsToComponent(yamlName, service, instInputs)); } @Test @@ -2025,12 +1839,12 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase String yamlName = "yamlName"; Service service = createServiceObject(true); Map<String, List<ComponentInstanceProperty>> instInputs = new HashMap<>(); + Map<String, List<ComponentInstanceProperty>> instInputMap = new HashMap<>(); + when(toscaOperationFacade.associateComponentInstancePropertiesToComponent(any(), anyString())) + .thenReturn(Either.left(instInputMap)); + Assertions.assertNotNull(service); - try { - bl.associateComponentInstancePropertiesToComponent(yamlName, service, instInputs); - } catch (Exception e) { - e.printStackTrace(); - } + bl.associateComponentInstancePropertiesToComponent(yamlName, service, instInputs); } @Test @@ -2039,12 +1853,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Service service = createServiceObject(true); Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts = new HashMap<>(); - try { - bl.associateDeploymentArtifactsToInstances(user, yamlName, service, instDeploymentArtifacts); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.associateDeploymentArtifactsToInstances(user, yamlName, service, instDeploymentArtifacts)); } @Test @@ -2053,12 +1863,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Service service = createServiceObject(true); Map<String, Map<String, ArtifactDefinition>> instArtifacts = new HashMap<>(); - try { - bl.associateArtifactsToInstances(yamlName, service, instArtifacts); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.associateArtifactsToInstances(yamlName, service, instArtifacts)); } @Test @@ -2067,12 +1873,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Service resource = createServiceObject(true); Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilities = new HashMap<>(); Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements = new HashMap<>(); - try { - bl.associateOrAddCalculatedCapReq(yamlName, resource, instCapabilities, instRequirements); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.associateOrAddCalculatedCapReq(yamlName, resource, instCapabilities, instRequirements)); } @Test @@ -2080,12 +1882,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase String yamlName = "yamlName"; Service resource = createServiceObject(true); Map<String, List<AttributeDefinition>> instAttributes = new HashMap<>(); - try { - bl.associateInstAttributeToComponentToInstances(yamlName, resource, instAttributes); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.associateInstAttributeToComponentToInstances(yamlName, resource, instAttributes)); } @Test @@ -2093,12 +1891,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase String yamlName = "yamlName"; Service resource = createServiceObject(true); Map<String, ListRequirementDataDefinition> requirements = new HashMap<>(); - try { - bl.associateRequirementsToService(yamlName, resource, requirements); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.associateRequirementsToService(yamlName, resource, requirements)); } @Test @@ -2106,12 +1900,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase String yamlName = "yamlName"; Service resource = createServiceObject(true); Map<String, ListCapabilityDataDefinition> capabilities = new HashMap<>(); - try { - bl.associateCapabilitiesToService(yamlName, resource, capabilities); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.GENERAL_ERROR, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.associateCapabilitiesToService(yamlName, resource, capabilities)); } @Test @@ -2119,11 +1909,11 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase String yamlName = "yamlName"; Service resource = createServiceObject(true); List<RequirementCapabilityRelDef> relations = new ArrayList<>(); - try { - bl.associateResourceInstances(yamlName, resource, relations); - } catch (Exception e) { - e.printStackTrace(); - } + when(toscaOperationFacade.associateResourceInstances(any(Component.class), + anyString(), any(ArrayList.class))).thenReturn(Either.left(relations)); + Assertions.assertNotNull(resource); + + bl.associateResourceInstances(yamlName, resource, relations); } @Test @@ -2131,6 +1921,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase Map<String, List<CapabilityDefinition>> originCapabilities = new HashMap<>(); String type = "type"; List<CapabilityDefinition> capabilities = new ArrayList<>(); + Assertions.assertNotNull(type); bl.addCapabilities(originCapabilities, type, capabilities); } @@ -2147,6 +1938,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase capability.setProperties(properties); capability.setName("capabilityName"); capabilities.add(capability); + Assertions.assertNotNull(capabilities); bl.addCapabilitiesProperties(newPropertiesMap, capabilities); } @@ -2154,21 +1946,21 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase @Test public void testGetServiceWithGroups() { String resourceId = "resourceId"; - try { - bl.getServiceWithGroups(resourceId); - } catch (Exception e) { - e.printStackTrace(); - } + Service service = createServiceObject(true); + when(toscaOperationFacade.getToscaElement(anyString(), any(ComponentParametersView.class))) + .thenReturn(Either.left(service)); + Assertions.assertNotNull( + bl.getServiceWithGroups(resourceId)); } @Test public void testGetResourceWithGroups() { String resourceId = "resourceId"; - try { - bl.getResourceWithGroups(resourceId); - } catch (Exception e) { - e.printStackTrace(); - } + Resource resource = createParseResourceObject(false); + when(toscaOperationFacade.getToscaElement(anyString(), any(ComponentParametersView.class))) + .thenReturn(Either.left(resource)); + Assertions.assertNotNull( + bl.getResourceWithGroups(resourceId)); } @Test @@ -2176,27 +1968,43 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase String yamlName = "yamlName"; Resource resource = createParseResourceObject(true); List<RequirementCapabilityRelDef> relations = new ArrayList<>(); - try { - bl.associateResourceInstances(yamlName, resource, relations); - } catch (Exception e) { - e.printStackTrace(); - } + when(toscaOperationFacade.associateResourceInstances(any(Resource.class), + anyString(), any(ArrayList.class))).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST)); + Assertions.assertThrows(ComponentException.class, () -> + bl.associateResourceInstances(yamlName, resource, relations)); } @Test public void testAddRelationsToRI() { - String yamlName = "yamlName"; - Resource resource = createParseResourceObject(true); + String yamlName = "group.yml"; + Resource resource = createResourceObject(false); + Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>(); UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo(); + nodesInfoValue.getRequirements().get("requirements").get(0).setName("zxjtestimportserviceab0.mme_ipu_vdu.dependency.test"); uploadResInstancesMap.put("uploadComponentInstanceInfo", nodesInfoValue); List<ComponentInstance> componentInstancesList = creatComponentInstances(); + ComponentInstance componentInstance = new ComponentInstance(); + componentInstance.setName("zxjTestImportServiceAb"); + componentInstancesList.add(componentInstance); + resource.setComponentInstances(componentInstancesList); + componentInstancesList.get(0).getRequirements().get("tosca.capabilities.Node").get(0).setLeftOccurrences("1"); + componentInstancesList.get(0).getRequirements().get("tosca.capabilities.Node").get(0).setMaxOccurrences("1"); + componentInstancesList.get(0).getRequirements().get("tosca.capabilities.Node").get(0).setCapability("tosca.capabilities.Node"); List<RequirementCapabilityRelDef> relations = new ArrayList<>(); - try { - bl.addRelationsToRI(yamlName, resource, uploadResInstancesMap, componentInstancesList, relations); - } catch (Exception e) { - e.printStackTrace(); - } + RequirementDefinition requirementDefinition = new RequirementDefinition(); + requirementDefinition.setOwnerId("1"); + requirementDefinition.setUniqueId("2"); + requirementDefinition.setCapability("3"); + CapabilityDefinition capabilityDefinition = new CapabilityDefinition(); + capabilityDefinition.setName("4"); + capabilityDefinition.setUniqueId("5"); + capabilityDefinition.setOwnerId("6"); + ResponseFormat responseFormat = new ResponseFormat(); + responseFormat.setStatus(200); + Assertions.assertNotNull(resource); + + bl.addRelationsToRI(yamlName, resource, uploadResInstancesMap, componentInstancesList, relations); } @Test @@ -2209,12 +2017,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase List<ComponentInstance> componentInstancesList = new ArrayList<>(); List<RequirementCapabilityRelDef> relations = new ArrayList<>(); - try { - bl.addRelationsToRI(yamlName, resource, uploadResInstancesMap, componentInstancesList, - relations); - } catch (Exception e) { - e.printStackTrace(); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.addRelationsToRI(yamlName, resource, uploadResInstancesMap, componentInstancesList, + relations)); } @Test @@ -2225,7 +2030,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo(); List<RequirementCapabilityRelDef> relations = new ArrayList<>(); - bl.addRelationToRI(yamlName, resource, nodesInfoValue, relations); + Assertions.assertNotNull( + bl.addRelationToRI(yamlName, resource, nodesInfoValue, relations)); } @Test @@ -2236,8 +2042,8 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase resource.setComponentInstances(componentInstancesList); UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo(); List<RequirementCapabilityRelDef> relations = new ArrayList<>(); - - bl.addRelationToRI(yamlName, resource, nodesInfoValue, relations); + Assertions.assertNotNull( + bl.addRelationToRI(yamlName, resource, nodesInfoValue, relations)); } @Test @@ -2247,13 +2053,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase String previousVfcToscaName = "previousVfcToscaName"; UploadComponentInstanceInfo nodesInfoValue = new UploadComponentInstanceInfo(); List<RequirementCapabilityRelDef> relations = new ArrayList<>(); - try { - bl.findVfcResource(getCsarInfo(), service, currVfcToscaName, previousVfcToscaName, - StorageOperationStatus.OK); - } catch (ComponentException e) { - assertComponentException(e, ActionStatus.OK, - ComponentTypeEnum.RESOURCE.getValue()); - } + Assertions.assertThrows(ComponentException.class, () -> + bl.findVfcResource(getCsarInfo(), service, currVfcToscaName, previousVfcToscaName, + StorageOperationStatus.OK)); } protected GroupDefinition getGroupDefinition() { @@ -2304,7 +2106,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase resource.setName(resource.getName()); resource.setVersion("0.1"); resource.setUniqueId(resource.getName() - .toLowerCase() + ":" + resource.getVersion()); + .toLowerCase() + ":" + resource.getVersion()); resource.setCreatorUserId(user.getUserId()); resource.setCreatorFullName(user.getFirstName() + " " + user.getLastName()); resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); @@ -2325,7 +2127,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase e.printStackTrace(); } CsarInfo csarInfo = new CsarInfo(user, csarUuid, csar, vfReousrceName, mainTemplateName, mainTemplateContent, - false); + false); return csarInfo; } @@ -2372,7 +2174,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase protected void assertComponentException(ComponentException e, ActionStatus expectedStatus, String... variables) { ResponseFormat actualResponse = e.getResponseFormat() != null ? - e.getResponseFormat() : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); + e.getResponseFormat() : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()); assertParseResponse(actualResponse, expectedStatus, variables); } diff --git a/catalog-be/src/test/resources/types/artifacts.yml b/catalog-be/src/test/resources/types/artifacts.yml new file mode 100644 index 0000000000..b6b7911e4a --- /dev/null +++ b/catalog-be/src/test/resources/types/artifacts.yml @@ -0,0 +1,36 @@ +tosca_definitions_version: tosca_simple_yaml_1_1 +imports: +- data.yml +artifact_types: + tosca.artifacts.Root: + description: This is the default (root) TOSCA Artifact Type definition that all other TOSCA base Artifact Types derive from. + tosca.artifacts.Deployment.Image: + derived_from: tosca.artifacts.Deployment + description: This artifact type represents a parent type for any "image" which is an opaque packaging of a TOSCA Node's deployment (whether real or virtual) whose contents are typically already installed and pre-configured (i.e., "stateful") and prepared to be run on a known target container. + tosca.artifacts.Implementation.Bash: + derived_from: tosca.artifacts.Implementation + description: This artifact type represents a Bash script type that contains Bash commands that can be executed on the Unix Bash shell. + tosca.artifacts.Deployment.Image.VM: + derived_from: tosca.artifacts.Deployment + description: This artifact represents the parent type for all Virtual Machine (VM) image and container formatted deployment artifacts. These images contain a stateful capture of a machine (e.g., server) including operating system and installed software along with any configurations and can be run on another machine using a hypervisor which virtualizes typical server (i.e., hardware) resources. + tosca.artifacts.Implementation.Python: + derived_from: tosca.artifacts.Implementation + description: This artifact type represents a Python file that contains Python language constructs that can be executed within a Python interpreter. + tosca.artifacts.Deployment: + derived_from: tosca.artifacts.Root + description: This artifact type represents the parent type for all deployment artifacts in TOSCA. This class of artifacts typically represents a binary packaging of an application or service that is used to install/create or deploy it as part of a node's lifecycle. + tosca.artifacts.File: + derived_from: tosca.artifacts.Root + description: This artifact type is used when an artifact definition needs to have its associated file simply treated as a file and no special handling/handlers are invoked (i.e., it is not treated as either an implementation or deployment artifact type). + tosca.artifacts.Implementation: + derived_from: tosca.artifacts.Root + description: This artifact type represents the parent type for all implementation artifacts in TOSCA. These artifacts are used to implement operations of TOSCA interfaces either directly (e.g., scripts) or indirectly (e.g., config. files). + tosca.artifacts.nfv.SwImage: + derived_from: tosca.artifacts.Deployment.Image + description: describes the software image which is directly loaded on the virtualisation container realizing of the VDU or is to be loaded on a virtual + tosca.artifacts.Implementation.nfv.Mistral: + derived_from: tosca.artifacts.Implementation + description: artifacts for Mistral workflows + mime_type: application/x-yaml + file_ext: + - yaml diff --git a/catalog-be/src/test/resources/types/fileContent.yml b/catalog-be/src/test/resources/types/fileContent.yml new file mode 100644 index 0000000000..d12d3968d6 --- /dev/null +++ b/catalog-be/src/test/resources/types/fileContent.yml @@ -0,0 +1,131 @@ + tosca_definitions_version: tosca_simple_yaml_1_1 + imports: + - data.yml + group_types: + tosca.groups.Root: + description: The TOSCA Group Type all other TOSCA Group Types derive from + interfaces: + Standard: + type: tosca.interfaces.node.lifecycle.Standard + org.openecomp.groups.heat.HeatStack: + derived_from: tosca.groups.Root + description: Grouped all heat resources which are in the same heat stack + properties: + heat_file: + type: string + description: Heat file which associate to this group/heat stack + required: true + status: supported + description: + type: string + description: group description + required: true + status: supported + org.openecomp.groups.VfModule: + derived_from: tosca.groups.Root + description: Grouped all heat resources which are in the same VF Module + properties: + isBase: + type: boolean + description: Whether this module should be deployed before other modules + required: true + default: false + status: supported + vf_module_label: + type: string + required: true + description: | + Alternate textual key used to reference this VF-Module model. Must be unique within the VNF model + vf_module_description: + type: string + required: true + description: | + Description of the VF-modules contents and purpose (e.g. \"Front-End\" or \"Database Cluster\") + min_vf_module_instances: + type: integer + required: true + description: The minimum instances of this VF-Module + max_vf_module_instances: + type: integer + required: false + description: The maximum instances of this VF-Module + initial_count: + type: integer + required: false + description: | + The initial count of instances of the VF-Module. The value must be in the range between min_vfmodule_instances and max_vfmodule_instances. If no value provided the initial count is the min_vfmodule_instances. + vf_module_type: + type: string + required: true + constraint: + - valid_values: + - Base + - Expansion + volume_group: + type: boolean + required: true + default: false + description: | + \"true\" indicates that this VF Module model requires attachment to a Volume Group. VID operator must select the Volume Group instance to attach to a VF-Module at deployment time. + availability_zone_count: + type: integer + required: false + description: | + Quantity of Availability Zones needed for this VF-Module (source: Extracted from VF-Module HEAT template) + vfc_list: + type: map + entry_schema: + description: <vfc_id>:<count> + type: string + required: false + description: | + Identifies the set of VM types and their count included in the VF-Module + org.openecomp.groups.NetworkCollection: + derived_from: tosca.groups.Root + description: groups l3-networks in network collection + properties: + network_collection_function: + type: string + required: true + description: network collection function + network_collection_description: + type: string + required: true + description: network collection description, free format text + org.openecomp.groups.VfcInstanceGroup: + derived_from: tosca.groups.Root + description: groups VFCs with same parent port role + properties: + vfc_instance_group_function: + type: string + required: true + description: function of this VFC group + vfc_parent_port_role: + type: string + required: true + description: common role of parent ports of VFCs in this group + network_collection_function: + type: string + required: true + description: network collection function assigned to this group + subinterface_role: + type: string + required: true + description: common role of subinterfaces of VFCs in this group, criteria the group is created + capabilities: + vlan_assignment: + type: org.openecomp.capabilities.VLANAssignment + properties: + vfc_instance_group_reference: + type: string + tosca.groups.nfv.PlacementGroup: + derived_from: tosca.groups.Root + description: PlacementGroup is used for describing the affinity or anti-affinity relationship applicable between the virtualization containers to be created based on different VDUs, or between internal VLs to be created based on different VnfVirtualLinkDesc(s) + properties: + description: + type: string + description: Human readable description of the group + required: true + members: + - tosca.nodes.nfv.Vdu.Compute + - tosca.nodes.nfv.VnfVirtualLink
\ No newline at end of file diff --git a/catalog-be/src/test/resources/types/groups.yml b/catalog-be/src/test/resources/types/groups.yml new file mode 100644 index 0000000000..d7ec9c259f --- /dev/null +++ b/catalog-be/src/test/resources/types/groups.yml @@ -0,0 +1,40 @@ +zxjTestImportServiceAb 0: + type: org.openecomp.resource.vf.Zxjtestimportserviceab + metadata: + invariantUUID: 41474f7f-3195-443d-a0a2-eb6020a56279 + UUID: 92e32e49-55f8-46bf-984d-a98c924037ec + customizationUUID: 40286158-96d0-408e-9f27-21d43817d37c + version: '1.0' + name: zxjTestImportServiceAb + description: zxjTestImportServiceAbstract + type: VF + category: Generic + subcategory: Abstract + resourceVendor: zxjImportService + resourceVendorRelease: '1.0' + resourceVendorModelNumber: '' + properties: + skip_post_instantiation_configuration: true + nf_naming: + ecomp_generated_naming: true + multi_stage_design: 'false' + controller_actor: SO-REF-DATA + availability_zone_max_count: 1 + requirements: + - imagefile.dependency: + capability: feature + node: ext ZTE VL 0 + - mme_ipu_vdu.dependency: + capability: feature + node: ExtCP 0 + capabilities: + mme_ipu_vdu.scalable: + properties: + max_instances: 1 + min_instances: 1 + mme_ipu_vdu.nfv_compute: + properties: + num_cpus: '2' + flavor_extra_specs: { + } + mem_size: '8192'
\ No newline at end of file diff --git a/catalog-be/src/test/resources/types/mainTemplateContent.yml b/catalog-be/src/test/resources/types/mainTemplateContent.yml new file mode 100644 index 0000000000..635547f1d8 --- /dev/null +++ b/catalog-be/src/test/resources/types/mainTemplateContent.yml @@ -0,0 +1,332 @@ + tosca_definitions_version: tosca_simple_yaml_1_1 + metadata: + invariantUUID: 6d17f281-683b-4198-a676-0faeecdc9025 + UUID: bfeab6b4-199b-4a2b-b724-de416c5e9811 + name: ser09080002 + description: ser09080002 + type: Service + category: E2E Service + serviceType: '' + serviceRole: '' + instantiationType: A-la-carte + serviceEcompNaming: true + ecompGeneratedNaming: true + namingPolicy: '' + environmentContext: General_Revenue-Bearing + serviceFunction: '' + imports: + - nodes: + file: nodes.yml + - datatypes: + file: data.yml + - capabilities: + file: capabilities.yml + - relationships: + file: relationships.yml + - groups: + file: groups.yml + - policies: + file: policies.yml + - annotations: + file: annotations.yml + - service-ser09080002-interface: + file: service-Ser09080002-template-interface.yml + - resource-ExtCP: + file: resource-Extcp-template.yml + - resource-zxjTestImportServiceAb: + file: resource-Zxjtestimportserviceab-template.yml + - resource-zxjTestImportServiceAb-interface: + file: resource-Zxjtestimportserviceab-template-interface.yml + - resource-zxjTestServiceNotAbatract: + file: resource-Zxjtestservicenotabatract-template.yml + - resource-zxjTestServiceNotAbatract-interface: + file: resource-Zxjtestservicenotabatract-template-interface.yml + - resource-ext ZTE VL: + file: resource-ExtZteVl-template.yml + topology_template: + inputs: + skip_post_instantiation_configuration: + default: true + type: boolean + required: false + controller_actor: + default: SO-REF-DATA + type: string + required: false + cds_model_version: + type: string + required: false + cds_model_name: + type: string + required: false + node_templates: + ext ZTE VL 0: + type: tosca.nodes.nfv.ext.zte.VL + metadata: + invariantUUID: 27ab7610-1a97-4daa-938a-3b48e7afcfd0 + UUID: 9ea63e2c-4b8a-414f-93e3-5703ca5cee0d + customizationUUID: e45e79b0-07ab-46b4-ac26-1e9f155ce53c + version: '1.0' + name: ext ZTE VL + description: Ext ZTE VL + type: VL + category: Generic + subcategory: Network Elements + resourceVendor: ONAP (Tosca) + resourceVendorRelease: 1.0.0.wd03 + resourceVendorModelNumber: '' + zxjTestServiceNotAbatract 0: + type: org.openecomp.resource.vf.Zxjtestservicenotabatract + metadata: + invariantUUID: ce39ce8d-6f97-4e89-8555-ae6789cdcf1c + UUID: 4ac822be-f1ae-4ace-a4b8-bf6b5d977005 + customizationUUID: ee34e1e8-68e2-480f-8ba6-f257bbe90d6a + version: '1.0' + name: zxjTestServiceNotAbatract + description: zxjTestServiceNotAbatract + type: VF + category: Network L4 + subcategory: Common Network Resources + resourceVendor: zxjImportService + resourceVendorRelease: '1.0' + resourceVendorModelNumber: '' + properties: + nf_naming: + ecomp_generated_naming: true + skip_post_instantiation_configuration: true + multi_stage_design: 'false' + controller_actor: SO-REF-DATA + availability_zone_max_count: 1 + capabilities: + mme_ipu_vdu.scalable: + properties: + max_instances: 1 + min_instances: 1 + mme_ipu_vdu.nfv_compute: + properties: + num_cpus: '2' + flavor_extra_specs: {} + mem_size: '8192' + ExtCP 0: + type: org.openecomp.resource.cp.extCP + metadata: + invariantUUID: 9b772728-93f5-424f-bb07-f4cae2783614 + UUID: 424ac220-4864-453e-b757-917fe4568ff8 + customizationUUID: 6e65d8a8-4379-4693-87aa-82f9e34b92fd + version: '1.0' + name: ExtCP + description: The AT&T Connection Point base type all other CP derive from + type: CP + category: Generic + subcategory: Network Elements + resourceVendor: ONAP (Tosca) + resourceVendorRelease: 1.0.0.wd03 + resourceVendorModelNumber: '' + properties: + mac_requirements: + mac_count_required: + is_required: false + exCP_naming: + ecomp_generated_naming: true + zxjTestImportServiceAb 0: + type: org.openecomp.resource.vf.Zxjtestimportserviceab + metadata: + invariantUUID: 41474f7f-3195-443d-a0a2-eb6020a56279 + UUID: 92e32e49-55f8-46bf-984d-a98c924037ec + customizationUUID: 98c7a6c7-a867-45fb-8597-dd464f98e4aa + version: '1.0' + name: zxjTestImportServiceAb + description: zxjTestImportServiceAbstract + type: VF + category: Generic + subcategory: Abstract + resourceVendor: zxjImportService + resourceVendorRelease: '1.0' + resourceVendorModelNumber: '' + properties: + nf_naming: + ecomp_generated_naming: true + skip_post_instantiation_configuration: true + multi_stage_design: 'false' + controller_actor: SO-REF-DATA + availability_zone_max_count: 1 + requirements: + - mme_ipu_vdu.dependency: + capability: feature + node: ExtCP 0 + - imagefile.dependency: + capability: feature + node: ext ZTE VL 0 + capabilities: + mme_ipu_vdu.scalable: + properties: + max_instances: 1 + min_instances: 1 + mme_ipu_vdu.nfv_compute: + properties: + num_cpus: '2' + flavor_extra_specs: {} + mem_size: '8192' + substitution_mappings: + node_type: org.openecomp.service.Ser09080002 + capabilities: + extcp0.feature: + - ExtCP 0 + - feature + zxjtestservicenotabatract0.mme_ipu_vdu.monitoring_parameter: + - zxjTestServiceNotAbatract 0 + - mme_ipu_vdu.monitoring_parameter + zxjtestimportserviceab0.imagefile.guest_os: + - zxjTestImportServiceAb 0 + - imagefile.guest_os + zxjtestimportserviceab0.imagefile.feature: + - zxjTestImportServiceAb 0 + - imagefile.feature + zxjtestservicenotabatract0.imagefile.guest_os: + - zxjTestServiceNotAbatract 0 + - imagefile.guest_os + zxjtestimportserviceab0.ipu_cpd.feature: + - zxjTestImportServiceAb 0 + - ipu_cpd.feature + zxjtestservicenotabatract0.mme_ipu_vdu.virtualbinding: + - zxjTestServiceNotAbatract 0 + - mme_ipu_vdu.virtualbinding + zxjtestimportserviceab0.mme_ipu_vdu.feature: + - zxjTestImportServiceAb 0 + - mme_ipu_vdu.feature + extztevl0.feature: + - ext ZTE VL 0 + - feature + zxjtestimportserviceab0.imagefile.image_fle: + - zxjTestImportServiceAb 0 + - imagefile.image_fle + zxjtestimportserviceab0.mme_ipu_vdu.monitoring_parameter: + - zxjTestImportServiceAb 0 + - mme_ipu_vdu.monitoring_parameter + zxjtestservicenotabatract0.ipu_cpd.feature: + - zxjTestServiceNotAbatract 0 + - ipu_cpd.feature + zxjtestservicenotabatract0.mme_ipu_vdu.nfv_compute: + - zxjTestServiceNotAbatract 0 + - mme_ipu_vdu.nfv_compute + zxjtestservicenotabatract0.mme_ipu_vdu.scalable: + - zxjTestServiceNotAbatract 0 + - mme_ipu_vdu.scalable + extcp0.internal_connectionPoint: + - ExtCP 0 + - internal_connectionPoint + zxjtestimportserviceab0.mme_ipu_vdu.virtualbinding: + - zxjTestImportServiceAb 0 + - mme_ipu_vdu.virtualbinding + zxjtestservicenotabatract0.imagefile.image_fle: + - zxjTestServiceNotAbatract 0 + - imagefile.image_fle + extztevl0.virtual_linkable: + - ext ZTE VL 0 + - virtual_linkable + zxjtestservicenotabatract0.imagefile.feature: + - zxjTestServiceNotAbatract 0 + - imagefile.feature + zxjtestimportserviceab0.localstorage.feature: + - zxjTestImportServiceAb 0 + - localstorage.feature + zxjtestservicenotabatract0.localstorage.local_attachment: + - zxjTestServiceNotAbatract 0 + - localstorage.local_attachment + zxjtestimportserviceab0.mme_ipu_vdu.scalable: + - zxjTestImportServiceAb 0 + - mme_ipu_vdu.scalable + zxjtestservicenotabatract0.localstorage.feature: + - zxjTestServiceNotAbatract 0 + - localstorage.feature + zxjtestimportserviceab0.mme_ipu_vdu.nfv_compute: + - zxjTestImportServiceAb 0 + - mme_ipu_vdu.nfv_compute + zxjtestimportserviceab0.localstorage.local_attachment: + - zxjTestImportServiceAb 0 + - localstorage.local_attachment + zxjtestservicenotabatract0.mme_ipu_vdu.feature: + - zxjTestServiceNotAbatract 0 + - mme_ipu_vdu.feature + zxjtestimportserviceab0.ipu_cpd.forwarder: + - zxjTestImportServiceAb 0 + - ipu_cpd.forwarder + zxjtestservicenotabatract0.ipu_cpd.forwarder: + - zxjTestServiceNotAbatract 0 + - ipu_cpd.forwarder + requirements: + zxjtestservicenotabatract0.imagefile.dependency: + - zxjTestServiceNotAbatract 0 + - imagefile.dependency + zxjtestservicenotabatract0.mme_ipu_vdu.local_storage: + - zxjTestServiceNotAbatract 0 + - mme_ipu_vdu.local_storage + zxjtestservicenotabatract0.ipu_cpd.dependency: + - zxjTestServiceNotAbatract 0 + - ipu_cpd.dependency + zxjtestservicenotabatract0.mme_ipu_vdu.volume_storage: + - zxjTestServiceNotAbatract 0 + - mme_ipu_vdu.volume_storage + zxjtestservicenotabatract0.ipu_cpd.virtualbinding: + - zxjTestServiceNotAbatract 0 + - ipu_cpd.virtualbinding + zxjtestservicenotabatract0.mme_ipu_vdu.dependency: + - zxjTestServiceNotAbatract 0 + - mme_ipu_vdu.dependency + zxjtestservicenotabatract0.localstorage.dependency: + - zxjTestServiceNotAbatract 0 + - localstorage.dependency + zxjtestimportserviceab0.imagefile.dependency: + - zxjTestImportServiceAb 0 + - imagefile.dependency + zxjtestimportserviceab0.mme_ipu_vdu.volume_storage: + - zxjTestImportServiceAb 0 + - mme_ipu_vdu.volume_storage + zxjtestimportserviceab0.ipu_cpd.virtualbinding: + - zxjTestImportServiceAb 0 + - ipu_cpd.virtualbinding + extcp0.virtualLink: + - ExtCP 0 + - virtualLink + extcp0.virtualBinding: + - ExtCP 0 + - virtualBinding + zxjtestimportserviceab0.mme_ipu_vdu.guest_os: + - zxjTestImportServiceAb 0 + - mme_ipu_vdu.guest_os + extcp0.dependency: + - ExtCP 0 + - dependency + zxjtestimportserviceab0.localstorage.dependency: + - zxjTestImportServiceAb 0 + - localstorage.dependency + zxjtestservicenotabatract0.ipu_cpd.virtualLink: + - zxjTestServiceNotAbatract 0 + - ipu_cpd.virtualLink + extztevl0.dependency: + - ext ZTE VL 0 + - dependency + zxjtestimportserviceab0.ipu_cpd.dependency: + - zxjTestImportServiceAb 0 + - ipu_cpd.dependency + zxjtestimportserviceab0.mme_ipu_vdu.dependency: + - zxjTestImportServiceAb 0 + - mme_ipu_vdu.dependency + zxjtestimportserviceab0.mme_ipu_vdu.local_storage: + - zxjTestImportServiceAb 0 + - mme_ipu_vdu.local_storage + zxjtestimportserviceab0.ipu_cpd.virtualLink: + - zxjTestImportServiceAb 0 + - ipu_cpd.virtualLink + extcp0.external_virtualLink: + - ExtCP 0 + - external_virtualLink + zxjtestservicenotabatract0.mme_ipu_vdu.guest_os: + - zxjTestServiceNotAbatract 0 + - mme_ipu_vdu.guest_os + zxjtestimportserviceab0.ipu_cpd.forwarder: + - zxjTestImportServiceAb 0 + - ipu_cpd.forwarder + zxjtestservicenotabatract0.ipu_cpd.forwarder: + - zxjTestServiceNotAbatract 0 + - ipu_cpd.forwarder\n
\ No newline at end of file |