aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
authorzhaoxiangjun666 <xjzhaop@isoftstone.com>2020-09-27 20:15:36 +0800
committerChristophe Closset <christophe.closset@intl.att.com>2020-10-12 11:40:43 +0000
commit78712174a6f275fc722482ee7783dd705497baf6 (patch)
tree8d223d0b2252e1bdf19217ed60ea833c7a81194a /catalog-be/src
parent969d2d7c2caed78d297ccf8e0ebc9120831c18b0 (diff)
Add test code for Test Topology Auto Design- Service Import
Issue-ID: SDC-3297 Change-Id: Ia8e1f53b96a559d606356cd3072e1dac98c694e0 Signed-off-by: zhaoxiangjun666 <xjzhaop@isoftstone.com>
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java73
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java19
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogicTest.java738
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportBussinessLogicBaseTestSetup.java130
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogicTest.java484
5 files changed, 1163 insertions, 281 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
index 857c5e32b7..b47c3928e8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
@@ -522,8 +522,7 @@ public class ServiceImportBusinessLogic{
return Either.right(createArtifactsFromCsar.right().value());
}
return Either.left(createArtifactsFromCsar.left().value());
- }catch(Exception e)
- {
+ }catch(Exception e) {
log.debug("Exception occured in getResourceResponseFormatEither, message:{}", e.getMessage(), e);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
}
@@ -3026,39 +3025,7 @@ public class ServiceImportBusinessLogic{
serviceImportParseLogic.validateResourceFieldsBeforeUpdate(oldResource, newResource, inTransaction, isNested);
serviceImportParseLogic
.validateCapabilityTypesCreate(user, serviceImportParseLogic.getCapabilityTypeOperation(), newResource, AuditingActionEnum.IMPORT_RESOURCE, inTransaction);
- newResource.setContactId(newResource.getContactId().toLowerCase());
- newResource.setCreatorUserId(user.getUserId());
- newResource.setCreatorFullName(user.getFullName());
- newResource.setLastUpdaterUserId(user.getUserId());
- newResource.setLastUpdaterFullName(user.getFullName());
- newResource.setUniqueId(oldResource.getUniqueId());
- newResource.setVersion(oldResource.getVersion());
- newResource.setInvariantUUID(oldResource.getInvariantUUID());
- newResource.setLifecycleState(oldResource.getLifecycleState());
- newResource.setUUID(oldResource.getUUID());
- newResource.setNormalizedName(oldResource.getNormalizedName());
- newResource.setSystemName(oldResource.getSystemName());
- if (oldResource.getCsarUUID() != null) {
- newResource.setCsarUUID(oldResource.getCsarUUID());
- }
- if (oldResource.getImportedToscaChecksum() != null) {
- newResource.setImportedToscaChecksum(oldResource.getImportedToscaChecksum());
- }
- if (newResource.getDerivedFromGenericType() == null || newResource.getDerivedFromGenericType().isEmpty()) {
- newResource.setDerivedFromGenericType(oldResource.getDerivedFromGenericType());
- }
- if (newResource.getDerivedFromGenericVersion() == null || newResource.getDerivedFromGenericVersion().isEmpty()) {
- newResource.setDerivedFromGenericVersion(oldResource.getDerivedFromGenericVersion());
- }
- if (newResource.getToscaArtifacts() == null || newResource.getToscaArtifacts().isEmpty()) {
- serviceBusinessLogic.setToscaArtifactsPlaceHolders(newResource, user);
- }
- if (newResource.getInterfaces() == null || newResource.getInterfaces().isEmpty()) {
- newResource.setInterfaces(oldResource.getInterfaces());
- }
- if (CollectionUtils.isEmpty(newResource.getProperties())) {
- newResource.setProperties(oldResource.getProperties());
- }
+ createNewResourceToOldResource(newResource, oldResource, user);
Either<Resource, StorageOperationStatus> overrideResource = toscaOperationFacade
.overrideComponent(newResource, oldResource);
@@ -3084,6 +3051,42 @@ public class ServiceImportBusinessLogic{
}
}
+ protected void createNewResourceToOldResource(Resource newResource, Resource oldResource, User user) {
+ newResource.setContactId(newResource.getContactId().toLowerCase());
+ newResource.setCreatorUserId(user.getUserId());
+ newResource.setCreatorFullName(user.getFullName());
+ newResource.setLastUpdaterUserId(user.getUserId());
+ newResource.setLastUpdaterFullName(user.getFullName());
+ newResource.setUniqueId(oldResource.getUniqueId());
+ newResource.setVersion(oldResource.getVersion());
+ newResource.setInvariantUUID(oldResource.getInvariantUUID());
+ newResource.setLifecycleState(oldResource.getLifecycleState());
+ newResource.setUUID(oldResource.getUUID());
+ newResource.setNormalizedName(oldResource.getNormalizedName());
+ newResource.setSystemName(oldResource.getSystemName());
+ if (oldResource.getCsarUUID() != null) {
+ newResource.setCsarUUID(oldResource.getCsarUUID());
+ }
+ if (oldResource.getImportedToscaChecksum() != null) {
+ newResource.setImportedToscaChecksum(oldResource.getImportedToscaChecksum());
+ }
+ if (newResource.getDerivedFromGenericType() == null || newResource.getDerivedFromGenericType().isEmpty()) {
+ newResource.setDerivedFromGenericType(oldResource.getDerivedFromGenericType());
+ }
+ if (newResource.getDerivedFromGenericVersion() == null || newResource.getDerivedFromGenericVersion().isEmpty()) {
+ newResource.setDerivedFromGenericVersion(oldResource.getDerivedFromGenericVersion());
+ }
+ if (newResource.getToscaArtifacts() == null || newResource.getToscaArtifacts().isEmpty()) {
+ serviceBusinessLogic.setToscaArtifactsPlaceHolders(newResource, user);
+ }
+ if (newResource.getInterfaces() == null || newResource.getInterfaces().isEmpty()) {
+ newResource.setInterfaces(oldResource.getInterfaces());
+ }
+ if (CollectionUtils.isEmpty(newResource.getProperties())) {
+ newResource.setProperties(oldResource.getProperties());
+ }
+ }
+
protected Map<String, Resource> createResourcesFromYamlNodeTypesList(String yamlName, Service service, Map<String, Object> mappedToscaTemplate, boolean needLock,
Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle,
List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, Map<String, NodeTypeInfo> nodeTypesInfo,
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java
index 65576d1567..935a5d6796 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportParseLogic.java
@@ -2198,13 +2198,18 @@ public class ServiceImportParseLogic {
}
public void associateComponentInstancePropertiesToComponent(String yamlName, Resource resource, Map<String, List<ComponentInstanceProperty>> instProperties) {
- Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus> addPropToInst = toscaOperationFacade
- .associateComponentInstancePropertiesToComponent(instProperties, resource.getUniqueId());
- if (addPropToInst.isRight()) {
- log.debug("failed to associate properties of resource {} status is {}", resource.getUniqueId(),
- addPropToInst.right().value());
- throw new ComponentException(componentsUtils.getResponseFormat(
- componentsUtils.convertFromStorageResponse(addPropToInst.right().value()), yamlName));
+ try {
+ Either<Map<String, List<ComponentInstanceProperty>>, StorageOperationStatus> addPropToInst = toscaOperationFacade
+ .associateComponentInstancePropertiesToComponent(instProperties, resource.getUniqueId());
+ if (addPropToInst.isRight()) {
+ log.debug("failed to associate properties of resource {} status is {}", resource.getUniqueId(),
+ addPropToInst.right().value());
+ throw new ComponentException(componentsUtils.getResponseFormat(
+ componentsUtils.convertFromStorageResponse(addPropToInst.right().value()), yamlName));
+ }
+ } catch (Exception e) {
+ log.debug("Exception occured when findNodeTypeArtifactsToHandle, error is:{}", e.getMessage());
+ throw new ComponentException(ActionStatus.GENERAL_ERROR);
}
}
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 02e145ec65..c176137193 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
@@ -122,6 +122,8 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
sIB1.setCsarBusinessLogic(csarBusinessLogic);
sIB1.setServiceImportParseLogic(serviceImportParseLogic);
sIB1.setToscaOperationFacade(toscaOperationFacade);
+ sIB1.setComponentsUtils(componentsUtils);
+ sIB1.setCsarArtifactsAndGroupsBusinessLogic(csarArtifactsAndGroupsBusinessLogic);
}
@@ -189,7 +191,21 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
Map<String, EnumMap<ArtifactsBusinessLogic.ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToCreate = new HashMap<>();
CreateServiceFromYamlParameter csfyp = getCsfyp();
try {
- sIB1.createServiceAndRIsFromYaml(oldService,false,nodeTypesArtifactsToCreate,true,true,csfyp);
+ sIB1.createServiceAndRIsFromYaml(oldService,false,
+ nodeTypesArtifactsToCreate,true,true,csfyp);
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testCreateServiceAndRIsFromYamlShoudLook(){
+ Service oldService = createServiceObject(false);
+ 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();
}
@@ -232,6 +248,34 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
CsarInfo csarInfo = getCsarInfo();
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();
+ }
+ }
+
+ @Test
+ public void testHandleVfCsarArtifactsGetToscaElement() {
+ Resource resource = createParseResourceObject(false);
+ 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.CREATE);
+ when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(resource));
+
try {
sIB1.handleVfCsarArtifacts(resource,csarInfo,createdArtifacts,artifactOperation,true,true);
} catch (Exception e) {
@@ -324,6 +368,26 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
}
@Test
+ public void testOrganizeVfCsarArtifactsByArtifactOperationElse(){
+ List<CsarUtils.NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>();
+ artifactPathAndNameList.add(getNonMetaArtifactInfo());
+ List<ArtifactDefinition> existingArtifactsToHandle = new ArrayList<>();
+ ArtifactDefinition artifactDefinition = new ArtifactDefinition();
+ artifactDefinition.setArtifactName("artifactName");
+ artifactDefinition.setArtifactType(ArtifactTypeEnum.AAI_VF_MODEL.name());
+ artifactDefinition.setArtifactChecksum("artifactChecksum");
+ existingArtifactsToHandle.add(artifactDefinition);
+ Resource resource = createParseResourceObject(false);
+
+ try {
+ sIB1.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList, existingArtifactsToHandle, resource, user);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ @Test
public void testProcessCsarArtifacts(){
CsarInfo csarInfo = getCsarInfo();
Resource resource = createParseResourceObject(false);
@@ -429,6 +493,34 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
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));
+
+ try {
+ sIB1.handleVfCsarArtifacts(service,csarInfo,createdArtifacts,artifactOperation,true,true);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testHandleVfCsarServiceArtifactsGetToscaElement() throws IOException {
+ 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);
+ 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);
+ csarInfo.setCsar(csar);
+ List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
+ 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) {
@@ -491,6 +583,26 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
}
@Test
+ public void testOrganizeVfCsarArtifactsByServiceArtifactOperationElse(){
+ List<CsarUtils.NonMetaArtifactInfo> artifactPathAndNameList = new ArrayList<>();
+ artifactPathAndNameList.add(getNonMetaArtifactInfo());
+ List<ArtifactDefinition> existingArtifactsToHandle = new ArrayList<>();
+ ArtifactDefinition artifactDefinition = new ArtifactDefinition();
+ artifactDefinition.setArtifactName("artifactName");
+ artifactDefinition.setArtifactType(ArtifactTypeEnum.AAI_VF_MODEL.name());
+ artifactDefinition.setArtifactChecksum("artifactChecksum");
+ existingArtifactsToHandle.add(artifactDefinition);
+ Service service = createServiceObject(true);
+
+ try {
+ sIB1.organizeVfCsarArtifactsByArtifactOperation(artifactPathAndNameList, existingArtifactsToHandle, service, user);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ @Test
public void testProcessServiceCsarArtifacts(){
CsarInfo csarInfo = getCsarInfo();
Service service = createServiceObject(true);
@@ -516,9 +628,37 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
public void testCreateOrUpdateSingleNonMetaServiceArtifact(){
Service service = createServiceObject(true);
CsarInfo csarInfo = getCsarInfo();
+ Map<String, byte[]> csar = csarInfo.getCsar();
String rootPath = System.getProperty("user.dir");
- Path path = Paths.get(rootPath + "/src/test/resources/valid_vf.csar");
- String artifactPath = path.toString(), artifactFileName = "", artifactType = "";
+ Path path;
+ byte[] data = new byte[0];
+ path = Paths.get(rootPath + "/src/test/resources/valid_vf.csar");
+ try {
+ data = Files.readAllBytes(path);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ 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);
+ 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();
+ }
+ }
+
+ @Test
+ 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);
@@ -545,6 +685,16 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
}
@Test
+ public void testCreateGroupsOnResourceNull(){
+ Service service = createServiceObject(true);
+ Map<String, GroupDefinition> groups = null;
+
+ Either<Service, ResponseFormat> result = sIB1.createGroupsOnResource(service, groups);
+ assertNotNull(result);
+
+ }
+
+ @Test
public void testUpdateGroupsMembersUsingResource(){
Service service = createServiceObject(true);
Map<String, GroupDefinition> groups = null;
@@ -556,6 +706,19 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
}
@Test
+ public void testUpdateGroupsMembersUsingResource_left(){
+ Service service = createServiceObject(true);
+ Map<String, GroupDefinition> groups = getGroups();
+ when(serviceImportParseLogic.validateCyclicGroupsDependencies(any()))
+ .thenReturn(Either.left(true));
+
+ List<GroupDefinition> groupDefinitions = sIB1.updateGroupsMembersUsingResource(groups, service);
+ for (GroupDefinition groupDefinition : groupDefinitions) {
+ assertNotNull(groupDefinition);
+ }
+ }
+
+ @Test
public void testCreateRIAndRelationsFromResourceYaml(){
String yamlName = "group.yml";
Resource resource = createParseResourceObject(true);
@@ -593,6 +756,23 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
}
@Test
+ public void testCreateResourceInstancesRelations_Empty(){
+ String yamlName = "group.yml";
+ Resource resource = createParseResourceObject(true);
+ resource.setComponentInstances(creatComponentInstances());
+ resource.setResourceType(ResourceTypeEnum.PNF);
+ Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
+ uploadResInstancesMap.put("uploadResInstancesMap",getuploadComponentInstanceInfo());
+
+ try {
+ sIB1.createResourceInstancesRelations(user,yamlName,resource,uploadResInstancesMap);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ @Test
public void testProcessComponentInstance1(){
String yamlName = "group.yml";
Resource resource = createParseResourceObject(true);
@@ -620,6 +800,33 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
}
@Test
+ public void testProcessComponentInstance_null(){
+ String yamlName = "group.yml";
+ Resource resource = createParseResourceObject(true);
+ Resource originResource = createParseResourceObject(false);
+ List<ComponentInstance> componentInstancesList = creatComponentInstances();
+ Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = null;
+ 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< AttributeDataDefinition >> instAttributes = new HashMap<>();
+ Map<String, Resource> originCompMap = new HashMap<>();
+ 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();
+ }
+ }
+
+ @Test
public void testAddInputsValuesToRi(){
UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
Map<String, List<UploadPropInfo>> properties = new HashMap<>();
@@ -654,16 +861,27 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
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);
ComponentInstance currentCompInstance = null;
Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
Map<String, InputDefinition> currPropertiesMap = new HashMap<>();
- inputDefinition.setType("inputDefinitionType");
currPropertiesMap.put("propertyInfoName",inputDefinition);
List<ComponentInstanceInput> instPropList = new ArrayList<>();
- List<UploadPropInfo> propertyList = getPropertyList();
+ 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,
@@ -678,6 +896,23 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
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();
+ }
+ }
+
+ @Test
+ 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);
@@ -760,6 +995,8 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
CsarInfo csarInfo = getCsarInfo();
String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test";
String yamlName = "group.yml";
+ when(toscaOperationFacade.getFullLatestComponentByToscaResourceName(anyString()))
+ .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
try {
sIB1.handleComplexVfc(resource,nodeTypesArtifactsToHandle,createdArtifacts,
@@ -882,6 +1119,20 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
}
@Test
+ 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();
+ }
+ }
+
+ @Test
public void testProcessComponentInstance(){
String yamlName = "group.yml";
Service service = createServiceObject(true);
@@ -909,6 +1160,33 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
}
@Test
+ public void testProcessComponentInstance_null2(){
+ String yamlName = "group.yml";
+ Service service = createServiceObject(true);
+ Resource originResource = createParseResourceObject(false);
+ List<ComponentInstance> componentInstancesList = creatComponentInstances();
+ Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = null;
+ 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< AttributeDataDefinition >> instAttributes = new HashMap<>();
+ Map<String, Resource> originCompMap = new HashMap<>();
+ 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();
+ }
+ }
+
+ @Test
public void testAddInputsValuesToRi2(){
UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
Map<String, List<UploadPropInfo>> properties = new HashMap<>();
@@ -941,17 +1219,22 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
@Test
public void testProcessProperty2(){
Service resource = createServiceObject(true);
+ List<InputDefinition> inputs = new ArrayList<>();
ComponentInstance currentCompInstance = null;
Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
Map<String, InputDefinition> currPropertiesMap = new HashMap<>();
InputDefinition inputDefinition = new InputDefinition();
+ inputDefinition.setName("inputDefinitionName");
inputDefinition.setType("inputDefinitionType");
+ inputs.add(inputDefinition);
currPropertiesMap.put("propertyInfoName",inputDefinition);
+ resource.setInputs(inputs);
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");
@@ -981,6 +1264,20 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
}
@Test
+ public void testProcessGetInput_optional(){
+ List<GetInputValueDataDefinition> getInputValues = new ArrayList<>();
+ List<InputDefinition> inputs = new ArrayList<>();
+ InputDefinition inputDefinition = new InputDefinition();
+ inputDefinition.setUniqueId("uniqueId");
+ inputDefinition.setName("InputName");
+ inputs.add(inputDefinition);
+ GetInputValueDataDefinition getInputIndex = new GetInputValueDataDefinition();
+ getInputIndex.setInputName("InputName");
+
+ sIB1.processGetInput(getInputValues,inputs,getInputIndex);
+ }
+
+ @Test
public void testAddPropertyValuesToRi(){
UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
uploadComponentInstanceInfo.setProperties(getUploadPropInfoProperties());
@@ -999,6 +1296,23 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
}
@Test
+ public void testAddPropertyValuesToRi_else(){
+ UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
+ Resource resource = createParseResourceObject(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, resource, originResource, currentCompInstance,
+ instProperties, allDataTypes);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
public void testAddPropertyValuesToRi2(){
UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
uploadComponentInstanceInfo.setProperties(getUploadPropInfoProperties());
@@ -1018,12 +1332,41 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
}
@Test
+ public void testAddPropertyValuesToRi2_else(){
+ UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
+ Service service = createServiceObject(false);
+ 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();
+ }
+ }
+
+ @Test
public void testProcessComponentInstanceCapabilities(){
Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = null;
Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilties = new HashMap<>();
UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
- uploadComponentInstanceInfo.setProperties(getUploadPropInfoProperties()); Map<String, List<UploadPropInfo>> properties = new HashMap<>();
- uploadComponentInstanceInfo.setProperties(properties);
+ uploadComponentInstanceInfo.setCapabilities(getCapabilities());
+ ComponentInstance currentCompInstance = new ComponentInstance();
+ Resource originResource = createParseResourceObject(false);
+
+ sIB1.processComponentInstanceCapabilities(allDataTypes, instCapabilties, uploadComponentInstanceInfo,
+ currentCompInstance, originResource);
+ }
+
+ @Test
+ 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);
@@ -1167,6 +1510,24 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
}
@Test
+ public void testAddRelationsToRI_null(){
+ String yamlName = "group.yml";
+ Service service = createServiceObject(false);
+ 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();
+ }
+ }
+
+ @Test
public void testAddRelationToRI(){
String yamlName = "group.yml";
Service service = createServiceObject(false);
@@ -1183,6 +1544,23 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
}
@Test
+ public void testAddRelationToRI_null(){
+ String yamlName = "group.yml";
+ Service service = createServiceObject(false);
+ List<ComponentInstance> componentInstancesList = new ArrayList<>();
+ service.setComponentInstances(componentInstancesList);
+
+ UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ List<RequirementCapabilityRelDef> relations = new ArrayList<>();
+
+ try {
+ sIB1.addRelationToRI(yamlName,service,nodesInfoValue,relations);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
public void testGetResourceAfterCreateRelations(){
Service service = createServiceObject(false);
ComponentParametersView componentParametersView = createComponentParametersView();
@@ -1259,9 +1637,18 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
String yamlName = "group.yml";
UploadComponentInstanceInfo uploadComponentInstanceInfo = getuploadComponentInstanceInfo();
Resource originResource = createParseResourceObject(true);
+ ResourceMetadataDataDefinition componentMetadataDataDefinition = new ResourceMetadataDataDefinition();
+ componentMetadataDataDefinition.setState(LifecycleStateEnum.CERTIFIED.name());
+ ComponentMetadataDefinition componentMetadataDefinition = new ComponentMetadataDefinition(componentMetadataDataDefinition);
+ originResource.setComponentMetadataDefinition(componentMetadataDefinition);
+ originResource.setComponentType(ComponentTypeEnum.RESOURCE);
+ originResource.setToscaResourceName("toscaResourceName");
+ originResource.setResourceType(ResourceTypeEnum.VF);
originResource.setResourceType(ResourceTypeEnum.VF);
Map<String, Resource> nodeNamespaceMap = new HashMap<>();
nodeNamespaceMap.put("resources", originResource);
+ when( toscaOperationFacade.getLatestResourceByToscaResourceName(anyString()))
+ .thenReturn(Either.left(originResource));
try {
sIB1.validateResourceInstanceBeforeCreate(yamlName,uploadComponentInstanceInfo,nodeNamespaceMap);
@@ -1281,14 +1668,12 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
Map<String, NodeTypeInfo> nodeTypesInfo = getNodeTypesInfo();
CsarInfo csarInfo = getCsarInfo();
String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test";
+ when(toscaOperationFacade.getLatestResourceByToscaResourceName(anyString()))
+ .thenReturn(Either.left(createOldResource()));
- try {
- sIB1.handleServiceNodeTypes(yamlName,service,topologyTemplateYaml,needLock,
- nodeTypesArtifactsToHandle,nodeTypesNewCreatedArtifacts,nodeTypesInfo,
- csarInfo,nodeName);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ sIB1.handleServiceNodeTypes(yamlName, service, topologyTemplateYaml, needLock,
+ nodeTypesArtifactsToHandle, nodeTypesNewCreatedArtifacts, nodeTypesInfo,
+ csarInfo, nodeName);
}
@Test
@@ -1344,6 +1729,8 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
CsarInfo csarInfo = getCsarInfo();
String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test";
String yamlName = "group.yml";
+ when(toscaOperationFacade.getFullLatestComponentByToscaResourceName(anyString()))
+ .thenReturn(Either.left(createNewResource()));
try {
sIB1.handleComplexVfc(nodeTypesArtifactsToHandle,createdArtifacts,
@@ -1421,7 +1808,9 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
@Test
public void testCreateResourceAndRIsFromYaml(){
String yamlName = "group.yml";
- Resource resource = createParseResourceObject(false);
+ Resource resource = createParseResourceObject(true);
+ resource.setSystemName("SystemName");
+ resource.setComponentType(ComponentTypeEnum.RESOURCE);
ParsedToscaYamlInfo parsedToscaYamlInfo = new ParsedToscaYamlInfo();
AuditingActionEnum actionEnum = AuditingActionEnum.CREATE_RESOURCE;
boolean isNormative = true;
@@ -1433,20 +1822,61 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
boolean shouldLock = true;
boolean inTransaction = true;
String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test";
+ 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();
+ }
+ }
+
+ @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";
+ try {
+ sIB1.createResourceAndRIsFromYaml(yamlName,resource,parsedToscaYamlInfo,actionEnum,
+ isNormative,createdArtifacts,topologyTemplateYaml,nodeTypesInfo,csarInfo,
+ nodeTypesArtifactsToCreate,shouldLock,inTransaction,nodeName);
+ } catch (Exception e) {
+ e.printStackTrace();
}
}
@Test
- public void testCreateGroupsOnResource2(){
+ public void testCreateGroupsOnResource2() {
Resource resource = createParseResourceObject(false);
- Map<String, GroupDefinition> groups = new HashMap<>();
+ Map<String, GroupDefinition> groups = getGroups();
+ when(serviceImportParseLogic.validateCyclicGroupsDependencies(any()))
+ .thenReturn(Either.left(true));
+
+ try {
+ sIB1.createGroupsOnResource(resource, groups);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testCreateGroupsOnResource2_null() {
+ Resource resource = createParseResourceObject(false);
+ Map<String, GroupDefinition> groups = null;
Either<Resource, ResponseFormat> result = sIB1.createGroupsOnResource(resource, groups);
assertEquals(result.left().value(),resource);
@@ -1464,6 +1894,19 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
}
@Test
+ public void testUpdateGroupsMembersUsingResource_left2(){
+ Resource resource = createParseResourceObject(true);
+ Map<String, GroupDefinition> groups = getGroups();
+ when(serviceImportParseLogic.validateCyclicGroupsDependencies(any()))
+ .thenReturn(Either.left(true));
+
+ List<GroupDefinition> groupDefinitions = sIB1.updateGroupsMembersUsingResource(groups, resource);
+ for (GroupDefinition groupDefinition : groupDefinitions) {
+ assertNotNull(groupDefinition);
+ }
+ }
+
+ @Test
public void testUpdateGroupMembers(){
Map<String, GroupDefinition> groups = new HashMap<>();
GroupDefinition updatedGroupDefinition = new GroupDefinition();
@@ -1482,10 +1925,45 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
}
@Test
+ public void testUpdateGroupMembers_null(){
+ 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());
+
+ try {
+ sIB1.updateGroupMembers(groups,updatedGroupDefinition,component,componentInstances,
+ groupName,members);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
public void setCreateResourceTransaction(){
Resource resource = createParseResourceObject(false);
resource.setComponentType(ComponentTypeEnum.RESOURCE);
boolean isNormative = true;
+ when(toscaOperationFacade.validateComponentNameExists(anyString(),any(),any()))
+ .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
+
+ try {
+ sIB1.createResourceTransaction(resource,user,isNormative);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void setCreateResourceTransaction_leftTrue() {
+ Resource resource = createParseResourceObject(false);
+ resource.setComponentType(ComponentTypeEnum.RESOURCE);
+ boolean isNormative = true;
+ when(toscaOperationFacade.validateComponentNameExists(anyString(),any(),any()))
+ .thenReturn(Either.left(true));
try {
sIB1.createResourceTransaction(resource,user,isNormative);
@@ -1495,9 +1973,23 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
}
@Test
+ public void setCreateResourceTransaction_Left() {
+ Resource resource = createParseResourceObject(false);
+ resource.setComponentType(ComponentTypeEnum.RESOURCE);
+ when(toscaOperationFacade.validateComponentNameExists(anyString(),any(),any()))
+ .thenReturn(Either.left(false));
+
+ try {
+ sIB1.createResourceTransaction(resource,user,false);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
public void testUpdateExistingResourceByImport(){
- Resource newResource = createParseResourceObject(false);
- Resource oldResource = createParseResourceObject(true);
+ Resource newResource = createNewResource();
+ Resource oldResource = createOldResource();
try {
sIB1.updateExistingResourceByImport(newResource,oldResource,user,
@@ -1508,6 +2000,18 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
}
@Test
+ public void testCreateNewResourceToOldResource(){
+ Resource newResource = createNewResource();
+ Resource oldResource = createOldResource();
+
+ try {
+ sIB1.createNewResourceToOldResource(newResource,oldResource,user);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
public void testCreateResourcesFromYamlNodeTypesList(){
String yamlName = "group.yml";
Service service =createServiceObject(false);
@@ -1540,7 +2044,8 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
artifactDefinitions.add(artifactDefinition);
enumListEnumMap.put(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE,
artifactDefinitions);
- nodeTypesArtifactsToHandle.put("nodeTyp",enumListEnumMap); List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>();
+ nodeTypesArtifactsToHandle.put("nodeTyp",enumListEnumMap);
+ List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>();
Map<String, NodeTypeInfo> nodeTypesInfo = getNodeTypesInfo();
CsarInfo csarInfo = getCsarInfo();
Map<String, Object> mapToConvert =new HashMap<>();
@@ -1559,6 +2064,96 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
}
}
+ @Test
+ public void testCreateNodeTypesElse(){
+ String yamlName = "group.yml";
+ Service service =createServiceObject(false);
+ boolean needLock = true;
+ 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<>();
+ ArtifactDefinition artifactDefinition = new ArtifactDefinition();
+ artifactDefinition.setArtifactName("artifactName");
+ artifactDefinitions.add(artifactDefinition);
+ enumListEnumMap.put(ArtifactsBusinessLogic.ArtifactOperationEnum.CREATE,
+ artifactDefinitions);
+ 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<>();
+ NodeTypeInfo nodeTypeInfo = new NodeTypeInfo();
+ nodeTypesInfo.put("nodeTyp",nodeTypeInfo);
+ nodeTypes.put("org.openecomp.resource.derivedFrom.zxjTestImportServiceAb0.test",
+ nodeTypeInfo);
+
+ try {
+ sIB1.createNodeTypes(yamlName, service, needLock, nodeTypesArtifactsToHandle,
+ nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo, mapToConvert,
+ nodeTypes);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ protected Resource createNewResource(){
+ Resource newResource = createParseResourceObject(false);
+ newResource.setVersion("1.0");
+ newResource.setInvariantUUID("");
+ newResource.setLifecycleState(null);
+ newResource.setUUID("");
+ newResource.setNormalizedName("");
+ newResource.setSystemName("");
+ newResource.setCsarUUID("");
+ newResource.setImportedToscaChecksum("");
+ newResource.setDerivedFromGenericType("");
+ newResource.setDerivedFromGenericVersion("");
+ Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
+ ArtifactDefinition artifactDefinition = new ArtifactDefinition();
+ artifactDefinition.setArtifactName("artifactDefinition");
+ toscaArtifacts.put("toscaArtifactsMap",artifactDefinition);
+ Map<String, InterfaceDefinition> interfaces = new HashMap<>();
+ InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setOwnerId("OwnerId");
+ interfaces.put("interfacesMap",interfaceDefinition);
+ newResource.setInterfaces(interfaces);
+ newResource.setToscaArtifacts(toscaArtifacts);
+ newResource.setProperties(getProperties());
+ return newResource;
+ }
+
+ protected Resource createOldResource(){
+ Resource newResource = createParseResourceObject(false);
+ newResource.setVersion("1.0");
+ newResource.setInvariantUUID("552e8f6c-340c-4fb4-8a82-fe7732fd8010");
+ newResource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
+ newResource.setUUID("13065b80-ca96-4331-b643-d28aeaf961cb");
+ newResource.setNormalizedName("NormalizedName");
+ newResource.setSystemName("default");
+ newResource.setCsarUUID("CsarUUID");
+ newResource.setImportedToscaChecksum("ImportedToscaChecksum");
+ newResource.setDerivedFromGenericType("DerivedFromGenericType");
+ newResource.setDerivedFromGenericVersion("0.1");
+ Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
+ ArtifactDefinition artifactDefinition = new ArtifactDefinition();
+ artifactDefinition.setArtifactName("tosca_simple_yaml_1_1");
+ 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);
+ newResource.setInterfaces(interfaces);
+ newResource.setToscaArtifacts(toscaArtifacts);
+ List<PropertyDefinition> properties = new ArrayList<>();
+ PropertyDefinition propertyDefinition = new PropertyDefinition();
+ propertyDefinition.setName("tosca_simple_yaml_1_1");
+ properties.add(propertyDefinition);
+ newResource.setProperties(properties);
+ return newResource;
+ }
+
protected List<UploadPropInfo> getPropertyList() {
List<UploadPropInfo> propertyList = new ArrayList<>();
UploadPropInfo uploadPropInfo = new UploadPropInfo();
@@ -1573,18 +2168,12 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
return propertyList;
}
- protected Map<String, GroupDefinition> getGroups() {
- Map<String, GroupDefinition> groups = new HashMap<>();
- GroupDefinition groupDefinition = new GroupDefinition();
- groupDefinition.setName("groupDefinitionName");
- groups.put("groupsMap",groupDefinition);
- return groups;
- }
protected Map<String, NodeTypeInfo> getNodeTypesInfo(){
Map<String, NodeTypeInfo> nodeTypesInfo = new HashMap<>();
NodeTypeInfo nodeTypeInfo = new NodeTypeInfo();
Map<String, Object> mappedToscaTemplate = new HashMap<>();
+ nodeTypeInfo.setNested(true);
nodeTypeInfo.setTemplateFileName("templateFileName");
nodeTypeInfo.setMappedToscaTemplate(mappedToscaTemplate);
String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test";
@@ -1627,101 +2216,6 @@ public class ServiceImportBusinessLogicTest extends ServiceImportBussinessLogicB
return properties;
}
- protected UploadComponentInstanceInfo getuploadComponentInstanceInfo(){
- UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
- uploadComponentInstanceInfo.setType("resources");
- Collection<String> directives = new Collection<String>() {
- @Override
- public int size() {
- return 0;
- }
-
- @Override
- public boolean isEmpty() {
- return false;
- }
-
- @Override
- public boolean contains(Object o) {
- return false;
- }
-
- @Override
- public Iterator<String> iterator() {
- return null;
- }
-
- @Override
- public Object[] toArray() {
- return new Object[0];
- }
-
- @Override
- public <T> T[] toArray(T[] ts) {
- return null;
- }
-
- @Override
- public boolean add(String s) {
- return false;
- }
-
- @Override
- public boolean remove(Object o) {
- return false;
- }
-
- @Override
- public boolean containsAll(Collection<?> collection) {
- return false;
- }
-
- @Override
- public boolean addAll(Collection<? extends String> collection) {
- return false;
- }
-
- @Override
- public boolean removeAll(Collection<?> collection) {
- return false;
- }
-
- @Override
- public boolean retainAll(Collection<?> collection) {
- return false;
- }
-
- @Override
- public void clear() {
-
- }
- };
- uploadComponentInstanceInfo.setDirectives(directives);
- UploadNodeFilterInfo uploadNodeFilterInfo = new UploadNodeFilterInfo();
- Map<String, List<UploadReqInfo>> requirements = new HashMap<>();
- List<UploadReqInfo> uploadReqInfoList = new ArrayList<>();
- UploadReqInfo uploadReqInfo = new UploadReqInfo();
- uploadReqInfo.setName("uploadReqInfo");
- uploadReqInfo.setCapabilityName("tosca.capabilities.Node");
- uploadReqInfoList.add(uploadReqInfo);
- requirements.put("requirements",uploadReqInfoList);
- uploadNodeFilterInfo.setName("mme_ipu_vdu.virtualbinding");
- uploadComponentInstanceInfo.setCapabilities(getCapabilities());
- uploadComponentInstanceInfo.setRequirements(requirements);
- return uploadComponentInstanceInfo;
- }
-
- protected Map<String, List<UploadCapInfo>> getCapabilities(){
- List<UploadCapInfo> uploadCapInfoList = new ArrayList<>();
- UploadCapInfo uploadCapInfo = new UploadCapInfo();
- uploadCapInfo.setNode("tosca.nodes.Root");
- uploadCapInfo.setName("mme_ipu_vdu.dependency");
- uploadCapInfoList.add(uploadCapInfo);
- Map<String, List<UploadCapInfo>> uploadCapInfoMap = new HashMap<>();
- uploadCapInfoMap.put("tosca.capabilities.Node",uploadCapInfoList);
- return uploadCapInfoMap;
- }
-
protected Map<String, List<UploadReqInfo>> gerRequirements(){
Map<String, List<UploadReqInfo>> uploadReqInfoMap = new HashMap<>();
String requirementName = "tosca.capabilities.Node";
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 15487d7ea0..928dbf96fc 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
@@ -352,6 +352,136 @@ protected Resource createParseResourceObject(boolean afterCreate) {
return genericService;
}
+
+ protected Map<String, GroupDefinition> getGroups() {
+ Map<String, GroupDefinition> groups = new HashMap<>();
+ GroupDefinition groupDefinition = new GroupDefinition();
+ groupDefinition.setName("groupDefinitionName");
+ groups.put("groupsMap",groupDefinition);
+ return groups;
+ }
+
+ protected UploadComponentInstanceInfo getuploadComponentInstanceInfo(){
+ UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
+ uploadComponentInstanceInfo.setType("resources");
+ Collection<String> directives = new Collection<String>() {
+ @Override
+ public int size() {
+ return 0;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return false;
+ }
+
+ @Override
+ public boolean contains(Object o) {
+ return false;
+ }
+
+ @Override
+ public Iterator<String> iterator() {
+ return null;
+ }
+
+ @Override
+ public Object[] toArray() {
+ return new Object[0];
+ }
+
+ @Override
+ public <T> T[] toArray(T[] ts) {
+ return null;
+ }
+
+ @Override
+ public boolean add(String s) {
+ return false;
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ return false;
+ }
+
+ @Override
+ public boolean containsAll(Collection<?> collection) {
+ return false;
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends String> collection) {
+ return false;
+ }
+
+ @Override
+ public boolean removeAll(Collection<?> collection) {
+ return false;
+ }
+
+ @Override
+ public boolean retainAll(Collection<?> collection) {
+ return false;
+ }
+
+ @Override
+ public void clear() {
+
+ }
+ };
+ uploadComponentInstanceInfo.setDirectives(directives);
+ UploadNodeFilterInfo uploadNodeFilterInfo = new UploadNodeFilterInfo();
+ Map<String, List<UploadReqInfo>> requirements = new HashMap<>();
+ List<UploadReqInfo> uploadReqInfoList = new ArrayList<>();
+ UploadReqInfo uploadReqInfo = new UploadReqInfo();
+ uploadReqInfo.setName("uploadReqInfo");
+ uploadReqInfo.setCapabilityName("tosca.capabilities.Node");
+ uploadReqInfoList.add(uploadReqInfo);
+ requirements.put("requirements",uploadReqInfoList);
+ uploadNodeFilterInfo.setName("mme_ipu_vdu.virtualbinding");
+ uploadComponentInstanceInfo.setCapabilities(getCapabilities());
+ uploadComponentInstanceInfo.setRequirements(requirements);
+ uploadComponentInstanceInfo.setName("zxjTestImportServiceAb");
+ return uploadComponentInstanceInfo;
+ }
+
+ protected Map<String, List<UploadCapInfo>> getCapabilities(){
+ List<UploadCapInfo> uploadCapInfoList = new ArrayList<>();
+ UploadCapInfo uploadCapInfo = new UploadCapInfo();
+ uploadCapInfo.setNode("tosca.nodes.Root");
+ uploadCapInfo.setName("mme_ipu_vdu.dependency");
+ uploadCapInfoList.add(uploadCapInfo);
+ Map<String, List<UploadCapInfo>> uploadCapInfoMap = new HashMap<>();
+ uploadCapInfoMap.put("tosca.capabilities.Node",uploadCapInfoList);
+ return uploadCapInfoMap;
+ }
+
+ protected List<ComponentInstance> creatComponentInstances(){
+ List<ComponentInstance> componentInstances = new ArrayList<>();
+ ComponentInstance componentInstance = new ComponentInstance();
+ 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);
+
+ 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);
+ componentInstance.setRequirements(requirements);
+ componentInstance.setCapabilities(capabilities);
+ componentInstance.setUniqueId("uniqueId");
+ componentInstance.setComponentUid("componentUid");
+ componentInstance.setName("zxjTestImportServiceAb");
+ componentInstances.add(componentInstance);
+ return componentInstances;
+ }
+
protected UploadComponentInstanceInfo createUploadComponentInstanceInfo(){
UploadComponentInstanceInfo uploadComponentInstanceInfo = new UploadComponentInstanceInfo();
uploadComponentInstanceInfo.setName("UploadComponentInstanceInfo");
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 18408dc913..ce57ff103a 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
@@ -51,6 +51,7 @@ import org.openecomp.sdc.be.components.csar.CsarInfo;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
import org.openecomp.sdc.be.components.impl.artifact.ArtifactOperationInfo;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
@@ -97,6 +98,8 @@ import org.openecomp.sdc.be.model.User;
import java.util.HashMap;
import java.util.Map;
+
+
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
@@ -115,6 +118,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
IElementOperation elementDao = Mockito.mock(IElementOperation.class);
IInterfaceLifecycleOperation interfaceTypeOperation = Mockito.mock(IInterfaceLifecycleOperation.class);
InputsBusinessLogic inputsBusinessLogic = Mockito.mock(InputsBusinessLogic.class);
+ LifecycleBusinessLogic lifecycleBusinessLogic = Mockito.mock(LifecycleBusinessLogic.class);
private static final String RESOURCE_NAME = "My-Resource_Name with space";
private static final String RESOURCE_TOSCA_NAME = "My-Resource_Tosca_Name";
@@ -160,7 +164,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
bl.setCapabilityTypeOperation(capabilityTypeOperation);
bl.setInterfaceTypeOperation(interfaceTypeOperation);
bl.setInputsBusinessLogic(inputsBusinessLogic);
-
+ bl.setLifecycleBusinessLogic(lifecycleBusinessLogic);
}
@Test
@@ -276,10 +280,42 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
}
@Test
- public void testHandleAndAddExtractedVfcsArtifacts() {
+ public void testFindAddNodeTypeArtifactsToHandleNotNull() {
+ Map<String, List<ArtifactDefinition>> extractedVfcsArtifacts = new HashMap<>();
+ Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = new HashMap<>();
+ String namespace = "namespace";
List<ArtifactDefinition> vfcArtifacts = new ArrayList<>();
+ ArtifactDefinition artifactDefinition = new ArtifactDefinition();
+ artifactDefinition.setArtifactName("artifactDefinitionName");
+ vfcArtifacts.add(artifactDefinition);
+ extractedVfcsArtifacts.put(namespace,vfcArtifacts);
+ ImmutablePair p1 = ImmutablePair.<String, String>of("s", "sd");
+ Map<String, NodeTypeInfo> nodeTypesInfo = new HashedMap();
+ final Service service = createServiceObject(false);
+ 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());
+ }
+ }
+
+ @Test
+ public void testHandleAndAddExtractedVfcsArtifacts() {
+ List<ArtifactDefinition> vfcArtifacts = new ArrayList<>();
+ ArtifactDefinition artifactDefinition = new ArtifactDefinition();
+ artifactDefinition.setArtifactName("artifactDefinitionName");
+ vfcArtifacts.add(artifactDefinition);
List<ArtifactDefinition> artifactsToAdd = new ArrayList<>();
+ ArtifactDefinition artifactDefinitionToAdd = new ArtifactDefinition();
+ artifactDefinitionToAdd.setArtifactName("artifactDefinitionToAddName");
+ artifactsToAdd.add(artifactDefinitionToAdd);
bl.handleAndAddExtractedVfcsArtifacts(vfcArtifacts, artifactsToAdd);
}
@@ -338,7 +374,15 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
List<ArtifactDefinition> artifactsToUpload = new ArrayList<>();
List<ArtifactDefinition> artifactsToUpdate = new ArrayList<>();
Map<String, ArtifactDefinition> existingArtifacts = new HashMap<>();
+ ArtifactDefinition existingArtifact = new ArtifactDefinition();
+ existingArtifact.setArtifactName("ArtifactName");
+ existingArtifact.setArtifactType("ArtifactType");
+ existingArtifact.setArtifactChecksum("ArtifactChecksum");
+ existingArtifacts.put("existingArtifactMap",existingArtifact);
ArtifactDefinition currNewArtifact = new ArtifactDefinition();
+ currNewArtifact.setArtifactName("ArtifactName");
+ currNewArtifact.setArtifactType("ArtifactType");
+ currNewArtifact.setPayload("Payload".getBytes());
bl.processNodeTypeArtifact(artifactsToUpload, artifactsToUpdate, existingArtifacts, currNewArtifact);
}
@@ -364,6 +408,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
@Test
public void testFillGroupsFinalFields() {
List<GroupDefinition> groupsAsList = new ArrayList<>();
+ GroupDefinition groupDefinition = new GroupDefinition();
+ groupDefinition.setName("groupDefinitionName");
+ groupsAsList.add(groupDefinition);
bl.fillGroupsFinalFields(groupsAsList);
}
@@ -1237,14 +1284,17 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
@Test
public void testProcessDeploymentResourceArtifacts() {
Resource resource = createParseResourceObject(true);
+ resource.setResourceType(ResourceTypeEnum.VF);
Map<String, ArtifactDefinition> artifactMap = new HashMap<>();
String k = "key";
Object v = new Object();
- try {
- bl.processDeploymentResourceArtifacts(user, resource, artifactMap, k, v);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ Map<String,List<String>> artifactDetails = new HashMap<>();
+ List<String> artifactTypes = new ArrayList<>();
+ artifactTypes.add(ResourceTypeEnum.VF.name());
+ artifactDetails.put("validForResourceTypes",artifactTypes);
+ v = artifactDetails;
+
+ bl.processDeploymentResourceArtifacts(user, resource, artifactMap, k, v);
}
@Test
@@ -1325,7 +1375,14 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
@Test
public void testCreateInputsOnService() {
Service service = createServiceObject(true);
+ List<InputDefinition> resourceProperties = new ArrayList<>();
+ InputDefinition inputDefinition = new InputDefinition();
+ inputDefinition.setName("inputDefinitionName");
+ service.setInputs(resourceProperties);
Map<String, InputDefinition> inputs = new HashMap<>();
+ InputDefinition inputDefinitionMap = new InputDefinition();
+ inputDefinition.setName("inputDefinitionName");
+ inputs.put("inputsMap",inputDefinitionMap);
try {
bl.createInputsOnService(service, inputs);
@@ -1496,56 +1553,75 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
@Test
public void testAddGroupsToCreateOrUpdate() {
- Resource resource = createParseResourceObject(true);
- Map<String, GroupDefinition> groups = new HashMap<>();
-
List<GroupDefinition> groupsFromResource = new ArrayList<>();
+ GroupDefinition groupDefinition = new GroupDefinition();
+ groupDefinition.setInvariantName("groupDefinitionName");
+ groupsFromResource.add(groupDefinition);
List<GroupDefinition> groupsAsList = new ArrayList<>();
+ GroupDefinition groupNewDefinition =getGroupDefinition();
+ groupsAsList.add(groupNewDefinition);
List<GroupDefinition> groupsToUpdate = new ArrayList<>();
List<GroupDefinition> groupsToCreate = new ArrayList<>();
- try {
- bl.addGroupsToCreateOrUpdate(groupsFromResource, groupsAsList, groupsToUpdate, groupsToCreate);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ bl.addGroupsToCreateOrUpdate(groupsFromResource, groupsAsList, groupsToUpdate, groupsToCreate);
}
@Test
public void testAddGroupsToDelete() {
- Map<String, GroupDefinition> groups = new HashMap<>();
-
List<GroupDefinition> groupsFromResource = new ArrayList<>();
+ GroupDefinition groupDefinition = new GroupDefinition();
+ groupDefinition.setName("groupDefinitionName");
+ groupsFromResource.add(groupDefinition);
List<GroupDefinition> groupsAsList = new ArrayList<>();
+ GroupDefinition groupNewDefinition = new GroupDefinition();
+ groupNewDefinition.setName("groupNewDefinitionName");
+ groupsAsList.add(groupNewDefinition);
List<GroupDefinition> groupsToDelete = new ArrayList<>();
- try {
- bl.addGroupsToDelete(groupsFromResource, groupsAsList, groupsToDelete);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ bl.addGroupsToDelete(groupsFromResource, groupsAsList, groupsToDelete);
}
@Test
public void testUpdateGroupsMembersUsingResource() {
Service component = createServiceObject(true);
Map<String, GroupDefinition> groups = new HashMap<>();
+ GroupDefinition groupDefinition = getGroupDefinition();
+ groupDefinition.setMembers(null);
+ groups.put("groupsMap",groupDefinition);
+
+ bl.updateGroupsMembersUsingResource(groups, component);
+ }
+
+ @Test
+ public void testupdateGroupMembers() {
+ Service component = createServiceObject(true);
+ Map<String, GroupDefinition> groups = new HashMap<>();
+ GroupDefinition updatedGroupDefinition = new GroupDefinition();
+ List<ComponentInstance> componentInstances = new ArrayList<>();
+ String groupName = "groupName";
+ Map<String, String> members = new HashMap<>();
try {
- bl.updateGroupsMembersUsingResource(groups, component);
- } catch (Exception e) {
+ bl.updateGroupMembers(groups, updatedGroupDefinition, component, componentInstances, groupName, members);
+ } catch (ComponentException e) {
e.printStackTrace();
}
}
@Test
- public void testupdateGroupMembers() {
+ public void testupdateGroupMembersNotNull() {
Service component = createServiceObject(true);
- Map<String, GroupDefinition> groups = new HashMap<>();
+ Map<String, GroupDefinition> groups = getGroups();
GroupDefinition updatedGroupDefinition = new GroupDefinition();
List<ComponentInstance> componentInstances = new ArrayList<>();
+ ComponentInstance componentInstance = new ComponentInstance();
+ componentInstance.setName("componentInstanceName");
+ componentInstance.setUniqueId("componentInstanceUniqueId");
+ componentInstances.add(componentInstance);
String groupName = "groupName";
Map<String, String> members = new HashMap<>();
+ members.put("members", "members");
+ members.put("componentInstanceName", "members");
try {
bl.updateGroupMembers(groups, updatedGroupDefinition, component, componentInstances, groupName, members);
@@ -1576,15 +1652,27 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
Set<String> allGroupMembers = new HashSet<>();
String groupName = "groupName";
- try {
- bl.fillAllGroupMemebersRecursivly(groupName, allGroups, allGroupMembers);
- } catch (Exception e) {
+ bl.fillAllGroupMemebersRecursivly(groupName, allGroups, allGroupMembers);
+ }
- }
+ @Test
+ public void testFillAllGroupMemebersRecursivlyAllGroups() {
+ String groupName = "groupName";
+ Map<String, GroupDefinition> allGroups = new HashMap<>();
+ GroupDefinition groupDefinition = new GroupDefinition();
+ Map<String, String> members = new HashMap<>();
+ members.put("members", "members");
+ groupDefinition.setMembers(members);
+ allGroups.put(groupName, groupDefinition);
+ allGroups.put("members", groupDefinition);
+ Set<String> allGroupMembers = new HashSet<>();
+ allGroupMembers.add("allGroupMembers");
+
+ bl.fillAllGroupMemebersRecursivly(groupName, allGroups, allGroupMembers);
}
@Test
- public void testFillResourceMetadataForService() {
+ public void testFillResourceMetadataForServiceFailure() {
String yamlName = "yamlName";
Service resourceVf = createServiceObject(true);
String nodeName = "nodeName";
@@ -1592,7 +1680,34 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
try {
bl.fillResourceMetadata(yamlName, resourceVf, nodeName, user);
} catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ @Test
+ public void testFillResourceMetadataForServiceWrongType() {
+ String yamlName = "yamlName";
+ 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();
+ }
+ }
+
+ @Test
+ public void testFillResourceMetadataForServiceSuccess() {
+ String yamlName = "yamlName";
+ 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());
}
}
@@ -1605,32 +1720,52 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
try {
bl.propagateStateToCertified(user, resource, lifecycleChangeInfo, true, true, true);
} catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ @Test
+ public void testpropagateStateToCertifiedIsTrue() {
+ String yamlName = "yamlName";
+ 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());
}
}
@Test
public void testBuildValidComplexVfc2() {
- String nodeName = "nodeName";
- Resource resource = createParseResourceObject(true);
+ String nodeName = "org.openecomp.resource.derivedFrom.zxjTestImportServiceAb.test";
Map<String, NodeTypeInfo> nodesInfo = new HashMap<>();
+ NodeTypeInfo nodeTypeInfo = new NodeTypeInfo();
+ List<String> derivedFrom = new ArrayList<>();
+ derivedFrom.add("derivedFrom");
+ nodeTypeInfo.setDerivedFrom(derivedFrom);
+ nodesInfo.put(nodeName, nodeTypeInfo);
try {
bl.buildValidComplexVfc(getCsarInfo(), nodeName, nodesInfo);
- } catch (Exception e) {
-
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.GENERAL_ERROR,
+ ComponentTypeEnum.RESOURCE.getValue());
}
}
@Test
- public void testUpdateGroupsOnResource() {
+ public void testUpdateGroupsOnResourceEmptyGroups() {
Resource resource = createParseResourceObject(true);
Map<String, GroupDefinition> groups = new HashMap<>();
try {
bl.updateGroupsOnResource(resource, groups);
- } catch (Exception e) {
-
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.GENERAL_ERROR,
+ ComponentTypeEnum.RESOURCE.getValue());
}
}
@@ -1641,63 +1776,116 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
try {
bl.setInformationalArtifactsPlaceHolder(resource, user);
} catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testRollback() {
+ Resource resource = createParseResourceObject(true);
+ List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
+ List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>();
+ try {
+ bl.rollback(false,resource, createdArtifacts,nodeTypesNewCreatedArtifacts);
+ } catch (Exception e) {
+ e.printStackTrace();
}
}
@Test
+ public void testRollback_NotNull() {
+ Resource resource = createParseResourceObject(true);
+ List<ArtifactDefinition> createdArtifacts = new ArrayList<>();
+ ArtifactDefinition artifactDefinition = new ArtifactDefinition();
+ artifactDefinition.setArtifactName("artifactName");
+ createdArtifacts.add(artifactDefinition);
+ List<ArtifactDefinition> nodeTypesNewCreatedArtifacts = new ArrayList<>();
+ ArtifactDefinition artifactDefinition2 = new ArtifactDefinition();
+ artifactDefinition2.setArtifactChecksum("artifactChecksum");
+ nodeTypesNewCreatedArtifacts.add(artifactDefinition2);
+
+ bl.rollback(true, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
+ }
+
+ @Test
public void testCreateArtifactsPlaceHolderData2() {
Resource resource = createParseResourceObject(true);
try {
bl.createArtifactsPlaceHolderData(resource, user);
} catch (Exception e) {
-
+ e.printStackTrace();
}
}
@Test
public void testHandleGroupsProperties() {
Service service = createServiceObject(true);
- Map<String, GroupDefinition> groups = new HashMap<>();
- try {
- bl.handleGroupsProperties(service, groups);
- } catch (Exception e) {
+ Map<String, GroupDefinition> groups = getGroups();
- }
+ bl.handleGroupsProperties(service, groups);
}
@Test
public void testHandleGroupsProperties2() {
Resource resource = createParseResourceObject(true);
- Map<String, GroupDefinition> groups = new HashMap<>();
- try {
- bl.handleGroupsProperties(resource, groups);
- } catch (Exception e) {
+ Map<String, GroupDefinition> groups = getGroups();
- }
+ bl.handleGroupsProperties(resource, groups);
}
@Test
public void testHandleGetInputs() {
PropertyDataDefinition property = new PropertyDataDefinition();
+ List<GetInputValueDataDefinition> getInputValues = new ArrayList<>();
+ GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition();
+ GetInputValueDataDefinition getInput = new GetInputValueDataDefinition();
+ getInput.setInputId("inputId");
+ getInput.setInputName("inputName");
+ getInputValueDataDefinition.setInputName("inputName");
+ getInputValueDataDefinition.setPropName("getInputValueDataDefinitionName");
+ getInputValueDataDefinition.setGetInputIndex(getInputValueDataDefinition);
+ getInputValues.add(getInputValueDataDefinition);
+ property.setGetInputValues(getInputValues);
+ List<InputDefinition> inputs = new ArrayList<>();
+ InputDefinition inputDefinition = new InputDefinition();
+ inputDefinition.setName("inputName");
+ inputDefinition.setUniqueId("abc12345");
+ inputs.add(inputDefinition);
+
+ bl.handleGetInputs(property, inputs);
+ }
+
+ @Test
+ public void testHandleGetInputs_null() {
+ PropertyDataDefinition property = new PropertyDataDefinition();
+ List<GetInputValueDataDefinition> getInputValues = new ArrayList<>();
+ GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition();
+ getInputValueDataDefinition.setInputName("inputName");
+ getInputValueDataDefinition.setPropName("getInputValueDataDefinitionName");
+ getInputValues.add(getInputValueDataDefinition);
+ property.setGetInputValues(getInputValues);
List<InputDefinition> inputs = new ArrayList<>();
try {
bl.handleGetInputs(property, inputs);
} catch (Exception e) {
-
+ e.printStackTrace();
}
}
@Test
public void testFindInputByName() {
GetInputValueDataDefinition getInput = new GetInputValueDataDefinition();
+ getInput.setInputId("inputId");
+ getInput.setInputName("inputName");
List<InputDefinition> inputs = new ArrayList<>();
- try {
- bl.findInputByName(inputs, getInput);
- } catch (Exception e) {
+ InputDefinition inputDefinition = new InputDefinition();
+ inputDefinition.setName("inputName");
+ inputDefinition.setUniqueId("abc12345");
+ inputs.add(inputDefinition);
- }
+ bl.findInputByName(inputs, getInput);
}
@Test
@@ -1705,11 +1893,11 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
String yamlName = "yamlName";
Resource resource = createParseResourceObject(true);
Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>();
- List<InputDefinition> inputs = new ArrayList<>();
try {
bl.associateComponentInstancePropertiesToComponent(yamlName, resource, instProperties);
- } catch (Exception e) {
-
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.GENERAL_ERROR,
+ ComponentTypeEnum.RESOURCE.getValue());
}
}
@@ -1718,12 +1906,12 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
String yamlName = "yamlName";
Resource resource = createParseResourceObject(true);
Map<String, List<ComponentInstanceInput>> instInputs = new HashMap<>();
+ List<ComponentInstanceInput> componentInstanceInputList = new ArrayList<>();
+ ComponentInstanceInput componentInstanceInput = new ComponentInstanceInput();
+ componentInstanceInput.setName("componentInstanceInputName");
+ componentInstanceInputList.add(componentInstanceInput);
- try {
- bl.associateComponentInstanceInputsToComponent(yamlName, resource, instInputs);
- } catch (Exception e) {
-
- }
+ bl.associateComponentInstanceInputsToComponent(yamlName, resource, instInputs);
}
@Test
@@ -1734,8 +1922,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
try {
bl.associateDeploymentArtifactsToInstances(user, yamlName, resource, instDeploymentArtifacts);
- } catch (Exception e) {
-
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.GENERAL_ERROR,
+ ComponentTypeEnum.RESOURCE.getValue());
}
}
@@ -1747,8 +1936,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
try {
bl.associateDeploymentArtifactsToInstances(user, yamlName, resource, instDeploymentArtifacts);
- } catch (Exception e) {
-
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.GENERAL_ERROR,
+ ComponentTypeEnum.RESOURCE.getValue());
}
}
@@ -1760,8 +1950,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
try {
bl.associateArtifactsToInstances(yamlName, resource, instDeploymentArtifacts);
- } catch (Exception e) {
-
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.GENERAL_ERROR,
+ ComponentTypeEnum.RESOURCE.getValue());
}
}
@@ -1773,8 +1964,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements = new HashMap<>();
try {
bl.associateOrAddCalculatedCapReq(yamlName, resource, instCapabilities, instRequirements);
- } catch (Exception e) {
-
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.GENERAL_ERROR,
+ ComponentTypeEnum.RESOURCE.getValue());
}
}
@@ -1785,8 +1977,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
Map<String, List<AttributeDataDefinition>> instAttributes = new HashMap<>();
try {
bl.associateInstAttributeToComponentToInstances(yamlName, resource, instAttributes);
- } catch (Exception e) {
-
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.GENERAL_ERROR,
+ ComponentTypeEnum.RESOURCE.getValue());
}
}
@@ -1796,34 +1989,39 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
Resource resource = createParseResourceObject(true);
try {
bl.throwComponentExceptionByResource(status, resource);
- } catch (Exception e) {
-
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.OK,
+ ComponentTypeEnum.RESOURCE.getValue());
}
}
@Test
public void testGetResourceAfterCreateRelations() {
-
Resource resource = createParseResourceObject(true);
try {
bl.getResourceAfterCreateRelations(resource);
- } catch (Exception e) {
-
+ } catch (Exception e) {
+ e.printStackTrace();
}
}
@Test
public void testSetCapabilityNamesTypes() {
-
Map<String, List<CapabilityDefinition>> originCapabilities = new HashMap<>();
+ List<CapabilityDefinition> capabilityDefinitionList = new ArrayList<>();
+ CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
+ capabilityDefinition.setName("Capability");
+ capabilityDefinition.setType("Resource");
+ capabilityDefinitionList.add(capabilityDefinition);
+ originCapabilities.put("Capability",capabilityDefinitionList);
Map<String, List<UploadCapInfo>> uploadedCapabilities = new HashMap<>();
+ List<UploadCapInfo> uploadCapInfoList = new ArrayList<>();
+ UploadCapInfo uploadCapInfo = new UploadCapInfo();
+ uploadCapInfoList.add(uploadCapInfo);
+ uploadedCapabilities.put("Capability",uploadCapInfoList);
- try {
- bl.setCapabilityNamesTypes(originCapabilities, uploadedCapabilities);
- } catch (Exception e) {
-
- }
+ bl.setCapabilityNamesTypes(originCapabilities, uploadedCapabilities);
}
@Test
@@ -1834,8 +2032,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
try {
bl.associateComponentInstanceInputsToComponent(yamlName, service, instInputs);
- } catch (Exception e) {
-
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.OK,
+ ComponentTypeEnum.RESOURCE.getValue());
}
}
@@ -1848,7 +2047,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
try {
bl.associateComponentInstancePropertiesToComponent(yamlName, service, instInputs);
} catch (Exception e) {
-
+ e.printStackTrace();
}
}
@@ -1860,8 +2059,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
try {
bl.associateDeploymentArtifactsToInstances(user, yamlName, service, instDeploymentArtifacts);
- } catch (Exception e) {
-
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.GENERAL_ERROR,
+ ComponentTypeEnum.RESOURCE.getValue());
}
}
@@ -1873,8 +2073,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
try {
bl.associateArtifactsToInstances(yamlName, service, instArtifacts);
- } catch (Exception e) {
-
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.GENERAL_ERROR,
+ ComponentTypeEnum.RESOURCE.getValue());
}
}
@Test
@@ -1885,8 +2086,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
Map<ComponentInstance, Map<String, List<RequirementDefinition>>> instRequirements = new HashMap<>();
try {
bl.associateOrAddCalculatedCapReq(yamlName, resource, instCapabilities, instRequirements);
- } catch (Exception e) {
-
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.GENERAL_ERROR,
+ ComponentTypeEnum.RESOURCE.getValue());
}
}
@@ -1897,8 +2099,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
Map<String, List<AttributeDataDefinition>> instAttributes = new HashMap<>();
try {
bl.associateInstAttributeToComponentToInstances(yamlName, resource, instAttributes);
- } catch (Exception e) {
-
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.GENERAL_ERROR,
+ ComponentTypeEnum.RESOURCE.getValue());
}
}
@@ -1909,8 +2112,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
Map<String, ListRequirementDataDefinition> requirements = new HashMap<>();
try {
bl.associateRequirementsToService(yamlName, resource, requirements);
- } catch (Exception e) {
-
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.GENERAL_ERROR,
+ ComponentTypeEnum.RESOURCE.getValue());
}
}
@@ -1921,8 +2125,9 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
Map<String, ListCapabilityDataDefinition> capabilities = new HashMap<>();
try {
bl.associateCapabilitiesToService(yamlName, resource, capabilities);
- } catch (Exception e) {
-
+ } catch (ComponentException e) {
+ assertComponentException(e, ActionStatus.GENERAL_ERROR,
+ ComponentTypeEnum.RESOURCE.getValue());
}
}
@@ -1934,7 +2139,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
try {
bl.associateResourceInstances(yamlName, resource, relations);
} catch (Exception e) {
-
+ e.printStackTrace();
}
}
@@ -1943,22 +2148,24 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
Map<String, List<CapabilityDefinition>> originCapabilities = new HashMap<>();
String type = "type";
List<CapabilityDefinition> capabilities = new ArrayList<>();
- try {
- bl.addCapabilities(originCapabilities, type, capabilities);
- } catch (Exception e) {
- }
+ bl.addCapabilities(originCapabilities, type, capabilities);
}
@Test
public void testAddCapabilitiesProperties() {
Map<String, Map<String, UploadPropInfo>> newPropertiesMap = new HashMap<>();
List<UploadCapInfo> capabilities = new ArrayList<>();
- try {
- bl.addCapabilitiesProperties(newPropertiesMap, capabilities);
- } catch (Exception e) {
+ UploadCapInfo capability = new UploadCapInfo();
+ List<UploadPropInfo> properties = new ArrayList<>();
+ UploadPropInfo uploadPropInfo = new UploadPropInfo();
+ uploadPropInfo.setName("uploadPropInfoName");
+ properties.add(uploadPropInfo);
+ capability.setProperties(properties);
+ capability.setName("capabilityName");
+ capabilities.add(capability);
- }
+ bl.addCapabilitiesProperties(newPropertiesMap, capabilities);
}
@Test
@@ -1967,7 +2174,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
try {
bl.getServiceWithGroups(resourceId);
} catch (Exception e) {
-
+ e.printStackTrace();
}
}
@@ -1977,7 +2184,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
try {
bl.getResourceWithGroups(resourceId);
} catch (Exception e) {
-
+ e.printStackTrace();
}
}
@@ -1989,7 +2196,7 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
try {
bl.associateResourceInstances(yamlName, resource, relations);
} catch (Exception e) {
-
+ e.printStackTrace();
}
}
@@ -1998,29 +2205,59 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
String yamlName = "yamlName";
Resource resource = createParseResourceObject(true);
Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
- List<ComponentInstance> componentInstancesList = new ArrayList<>();
+ UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ uploadResInstancesMap.put("uploadComponentInstanceInfo", nodesInfoValue);
+ List<ComponentInstance> componentInstancesList = creatComponentInstances();
List<RequirementCapabilityRelDef> relations = new ArrayList<>();
try {
bl.addRelationsToRI(yamlName, resource, uploadResInstancesMap, componentInstancesList, relations);
} catch (Exception e) {
-
+ e.printStackTrace();
}
}
@Test
- public void testAddRelationsToRI2() {
- String yamlName = "yamlName";
+ public void testAddRelationsToRI_null(){
+ String yamlName = "group.yml";
Resource resource = createParseResourceObject(true);
- UploadComponentInstanceInfo nodesInfoValue = new UploadComponentInstanceInfo();
+ Map<String, UploadComponentInstanceInfo> uploadResInstancesMap = new HashMap<>();
+ UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ uploadResInstancesMap.put("uploadComponentInstanceInfo", nodesInfoValue);
+ List<ComponentInstance> componentInstancesList = new ArrayList<>();
List<RequirementCapabilityRelDef> relations = new ArrayList<>();
+
try {
- bl.addRelationToRI(yamlName, resource, nodesInfoValue, relations);
+ bl.addRelationsToRI(yamlName,resource,uploadResInstancesMap,componentInstancesList,
+ relations);
} catch (Exception e) {
-
+ e.printStackTrace();
}
}
@Test
+ public void testAddRelationToRI() {
+ String yamlName = "yamlName";
+ Resource resource = createParseResourceObject(true);
+ resource.setComponentInstances(creatComponentInstances());
+ UploadComponentInstanceInfo nodesInfoValue =getuploadComponentInstanceInfo();
+ List<RequirementCapabilityRelDef> relations = new ArrayList<>();
+
+ bl.addRelationToRI(yamlName, resource, nodesInfoValue, relations);
+ }
+
+ @Test
+ public void testAddRelationToRI_null(){
+ String yamlName = "yamlName.yml";
+ Resource resource = createParseResourceObject(false);
+ List<ComponentInstance> componentInstancesList = new ArrayList<>();
+ resource.setComponentInstances(componentInstancesList);
+ UploadComponentInstanceInfo nodesInfoValue = getuploadComponentInstanceInfo();
+ List<RequirementCapabilityRelDef> relations = new ArrayList<>();
+
+ bl.addRelationToRI(yamlName, resource, nodesInfoValue, relations);
+ }
+
+ @Test
public void testFindVfcResource() {
Service service = createServiceObject(true);
String currVfcToscaName = "currVfcToscaName";
@@ -2036,6 +2273,19 @@ public class ServiceImportParseLogicTest extends ServiceImportBussinessLogicBase
}
}
+ protected GroupDefinition getGroupDefinition(){
+ GroupDefinition groupDefinition = new GroupDefinition();
+ Map<String, String> members = new HashMap<>();
+ members.put("members", "members");
+ Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>();
+ List<PropertyDataDefinition> properties = new ArrayList<>();
+ groupDefinition.setInvariantName("groupDefinitionName");
+ groupDefinition.setMembers(members);
+ groupDefinition.setProperties(properties);
+ groupDefinition.setCapabilities(capabilities);
+ return groupDefinition;
+ }
+
protected Resource createParseResourceObject(boolean afterCreate) {
Resource resource = new Resource();
resource.setName(RESOURCE_NAME);