From f8bc4f94da584d5861827df7ee2107c33f514a55 Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Mon, 6 Apr 2020 15:44:56 +0100 Subject: Support configuring of tosca type for categories Signed-off-by: MichaelMorris Issue-ID: SDC-2877 Change-Id: I3160c5089979757628f31a44b01836236563b770 --- .../java/org/openecomp/sdc/be/model/Component.java | 86 ++-- .../java/org/openecomp/sdc/be/model/Resource.java | 78 +-- .../java/org/openecomp/sdc/be/model/Service.java | 21 +- .../org/openecomp/sdc/be/model/ResourceTest.java | 39 +- .../org/openecomp/sdc/be/model/ServiceTest.java | 543 +++++++++++---------- .../config/catalog-model/configuration.yaml | 5 + .../src/test/resources/config/configuration.yaml | 5 + 7 files changed, 424 insertions(+), 353 deletions(-) (limited to 'catalog-model') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java index bf1dfef243..63194752fc 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java @@ -311,20 +311,18 @@ public abstract class Component implements PropertiesOwner { public Map safeGetComponentInstanceDeploymentArtifacts(String componentInstanceId) { return getComponentInstanceById(componentInstanceId).map(ComponentInstance::safeGetDeploymentArtifacts) - .orElse(emptyMap()); + .orElse(emptyMap()); } public Map safeGetComponentInstanceInformationalArtifacts(String componentInstanceId) { return getComponentInstanceById(componentInstanceId).map(ComponentInstance::safeGetInformationalArtifacts) - .orElse(emptyMap()); + .orElse(emptyMap()); } public List safeGetComponentInstanceHeatArtifacts(String componentInstanceId) { - return safeGetComponentInstanceDeploymentArtifacts(componentInstanceId) - .values() - .stream() - .filter(artifact -> ArtifactTypeEnum.HEAT_ENV.getType().equals(artifact.getArtifactType())) - .collect(Collectors.toList()); + return safeGetComponentInstanceDeploymentArtifacts(componentInstanceId).values().stream() + .filter(artifact -> ArtifactTypeEnum.HEAT_ENV.getType().equals(artifact.getArtifactType())) + .collect(Collectors.toList()); } public Map> safeGetComponentInstancesProperties() { @@ -336,13 +334,10 @@ public abstract class Component implements PropertiesOwner { } private Map> findUiComponentInstancesProperties() { - List instancesFromUi = componentInstances.stream() - .filter(i -> !i.isCreatedFromCsar()) - .map(ComponentInstance::getUniqueId) - .collect(Collectors.toList()); - return componentInstancesProperties.entrySet().stream() - .filter(e -> instancesFromUi.contains(e.getKey())) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + List instancesFromUi = componentInstances.stream().filter(i -> !i.isCreatedFromCsar()) + .map(ComponentInstance::getUniqueId).collect(Collectors.toList()); + return componentInstancesProperties.entrySet().stream().filter(e -> instancesFromUi.contains(e.getKey())) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } public Map> safeGetComponentInstancesInputs() { @@ -354,13 +349,10 @@ public abstract class Component implements PropertiesOwner { } private Map> findUiComponentInstancesInputs() { - List instancesFromUi = componentInstances.stream() - .filter(i -> !i.isCreatedFromCsar()) - .map(ComponentInstance::getUniqueId) - .collect(Collectors.toList()); - return componentInstancesInputs.entrySet().stream() - .filter(e -> instancesFromUi.contains(e.getKey())) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + List instancesFromUi = componentInstances.stream().filter(i -> !i.isCreatedFromCsar()) + .map(ComponentInstance::getUniqueId).collect(Collectors.toList()); + return componentInstancesInputs.entrySet().stream().filter(e -> instancesFromUi.contains(e.getKey())) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } public List safeGetComponentInstanceProperties(String cmptInstacneId) { @@ -458,9 +450,7 @@ public abstract class Component implements PropertiesOwner { if (groups == null) { return Optional.empty(); } - return groups.stream() - .filter(predicate) - .findAny(); + return groups.stream().filter(predicate).findAny(); } public void addGroups(List groupsToAdd) { @@ -483,8 +473,7 @@ public abstract class Component implements PropertiesOwner { this.properties = new ArrayList<>(); } - this.properties.add(propertyDefinition); - ; + this.properties.add(propertyDefinition);; } public void addCategory(String category, String subCategory) { @@ -565,21 +554,16 @@ public abstract class Component implements PropertiesOwner { if (isEmpty(groups)) { return emptyMap(); } - return groups.stream() - .filter(gr -> Objects.nonNull(gr.getProperties())) - .collect(toMap(GroupDataDefinition::getUniqueId, - GroupDataDefinition::getProperties)); + return groups.stream().filter(gr -> Objects.nonNull(gr.getProperties())) + .collect(toMap(GroupDataDefinition::getUniqueId, GroupDataDefinition::getProperties)); } public Map> safeGetPolicyProperties() { if (isEmpty(policies)) { return emptyMap(); } - return policies.values() - .stream() - .filter(policy -> Objects.nonNull(policy.getProperties())) - .collect(toMap(PolicyDataDefinition::getUniqueId, - PolicyDataDefinition::getProperties)); + return policies.values().stream().filter(policy -> Objects.nonNull(policy.getProperties())) + .collect(toMap(PolicyDataDefinition::getUniqueId, PolicyDataDefinition::getProperties)); } public List safeGetComponentInstanceInputsByName(String cmptInstanceName) { @@ -587,12 +571,10 @@ public abstract class Component implements PropertiesOwner { if (this.componentInstancesInputs == null) { return emptyPropsList; } - return this.componentInstances.stream() - .filter(ci -> ci.getName().equals(cmptInstanceName)) - .map(ComponentInstance::getUniqueId) - .map(instanceId -> safeGetComponentInstanceEntity(instanceId, this.componentInstancesInputs)) - .findAny() - .orElse(emptyPropsList); + return this.componentInstances.stream().filter(ci -> ci.getName().equals(cmptInstanceName)) + .map(ComponentInstance::getUniqueId) + .map(instanceId -> safeGetComponentInstanceEntity(instanceId, this.componentInstancesInputs)).findAny() + .orElse(emptyPropsList); } private List safeGetComponentInstanceEntity(String cmptInstanceId, Map> instanceEntities) { @@ -604,17 +586,17 @@ public abstract class Component implements PropertiesOwner { return cmptInstanceProps == null ? emptyPropsList : cmptInstanceProps; } - public void setSpecificComponetTypeArtifacts(Map specificComponentTypeArtifacts) { // Implement where needed } public String fetchGenericTypeToscaNameFromConfig() { - // Implement where needed - return ConfigurationManager.getConfigurationManager() - .getConfiguration() - .getGenericAssetNodeTypes() - .get(this.assetType()); + return ConfigurationManager.getConfigurationManager().getConfiguration().getGenericAssetNodeTypes() + .get(this.assetType()); + } + + protected Optional getHeadOption(List list) { + return list == null || list.isEmpty() ? Optional.empty() : Optional.ofNullable(list.get(0)); } public String assetType() { @@ -661,18 +643,14 @@ public abstract class Component implements PropertiesOwner { if (policies == null) { return emptyList(); } - return policies.values().stream() - .filter(policyPredicate) - .collect(Collectors.toList()); + return policies.values().stream().filter(policyPredicate).collect(Collectors.toList()); } public List resolveGroupsByMember(String instanceId) { if (groups == null) { return emptyList(); } - return groups.stream() - .filter(group -> group.containsInstanceAsMember(instanceId)) - .collect(Collectors.toList()); + return groups.stream().filter(group -> group.containsInstanceAsMember(instanceId)).collect(Collectors.toList()); } public String getActualComponentType() { @@ -703,7 +681,7 @@ public abstract class Component implements PropertiesOwner { componentMetadataDefinition.getMetadataDataDefinition().setVspArchived(vspArchived); } - //supportability log method return map of component metadata teddy.h + // supportability log method return map of component metadata teddy.h public Map getComponentMetadataForSupportLog() { Map componentMetadata = new HashMap<>(); componentMetadata.put(ILogConfiguration.MDC_SUPPORTABLITY_COMPONENT_NAME, this.getName()); diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java index 2c7dc57a52..44d6eff4fb 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java @@ -28,11 +28,14 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; import lombok.ToString; + import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.utils.MapUtil; import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; +import org.openecomp.sdc.be.model.category.CategoryDefinition; +import org.openecomp.sdc.be.model.category.SubCategoryDefinition; @Getter @Setter @@ -60,32 +63,31 @@ public class Resource extends Component { public Resource() { super(new ResourceMetadataDefinition()); - this.getComponentMetadataDefinition().getMetadataDataDefinition() - .setComponentType(ComponentTypeEnum.RESOURCE); + this.getComponentMetadataDefinition().getMetadataDataDefinition().setComponentType(ComponentTypeEnum.RESOURCE); } public Resource(ComponentMetadataDefinition componentMetadataDefinition) { super(componentMetadataDefinition); if (this.getComponentMetadataDefinition().getMetadataDataDefinition() == null) { - this.getComponentMetadataDefinition().componentMetadataDataDefinition = new ResourceMetadataDataDefinition(); + this.getComponentMetadataDefinition().componentMetadataDataDefinition = + new ResourceMetadataDataDefinition(); } this.getComponentMetadataDefinition().getMetadataDataDefinition().setComponentType(ComponentTypeEnum.RESOURCE); } public Boolean isAbstract() { - return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition() - .getMetadataDataDefinition()) - .isAbstract(); + return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) + .isAbstract(); } public void setAbstract(Boolean isAbstract) { ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) - .setAbstract(isAbstract); + .setAbstract(isAbstract); } public String getCost() { return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) - .getCost(); + .getCost(); } public void setCost(String cost) { @@ -94,74 +96,91 @@ public class Resource extends Component { public String getLicenseType() { return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) - .getLicenseType(); + .getLicenseType(); } public void setLicenseType(String licenseType) { ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) - .setLicenseType(licenseType); + .setLicenseType(licenseType); } public String getToscaResourceName() { return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) - .getToscaResourceName(); + .getToscaResourceName(); } public void setToscaResourceName(String toscaResourceName) { ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) - .setToscaResourceName(toscaResourceName); + .setToscaResourceName(toscaResourceName); } public ResourceTypeEnum getResourceType() { return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) - .getResourceType(); + .getResourceType(); } public void setResourceType(ResourceTypeEnum resourceType) { ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) - .setResourceType(resourceType); + .setResourceType(resourceType); } public String getVendorName() { return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) - .getVendorName(); + .getVendorName(); } public void setVendorName(String vendorName) { ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) - .setVendorName(vendorName); + .setVendorName(vendorName); } public String getVendorRelease() { return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) - .getVendorRelease(); + .getVendorRelease(); } public void setVendorRelease(String vendorRelease) { ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) - .setVendorRelease(vendorRelease); + .setVendorRelease(vendorRelease); } public String getResourceVendorModelNumber() { return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) - .getResourceVendorModelNumber(); + .getResourceVendorModelNumber(); } public void setResourceVendorModelNumber(String resourceVendorModelNumber) { - ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()). - setResourceVendorModelNumber(resourceVendorModelNumber); + ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) + .setResourceVendorModelNumber(resourceVendorModelNumber); } @Override public String fetchGenericTypeToscaNameFromConfig() { + return fetchToscaNameFromConfigBasedOnCategory().orElse(fetchToscaNameFromConfigBasedOnAssetType()); + } + + public String fetchToscaNameFromConfigBasedOnAssetType() { String result = super.fetchGenericTypeToscaNameFromConfig(); if (null == result) { result = ConfigurationManager.getConfigurationManager().getConfiguration().getGenericAssetNodeTypes() - .get(ResourceTypeEnum.VFC.getValue()); + .get(ResourceTypeEnum.VFC.getValue()); } return result; } + private Optional fetchToscaNameFromConfigBasedOnCategory() { + return getHeadOption(this.getCategories()).flatMap(category -> getHeadOption(category.getSubcategories()).map( + subCategory -> fetchToscaNameFromConfigBasedOnCategory(category.getName(), subCategory.getName()))); + } + + private String fetchToscaNameFromConfigBasedOnCategory(final String resourceCategory, + final String resourceSubCategory) { + return Optional + .ofNullable(ConfigurationManager.getConfigurationManager().getConfiguration().getResourceNodeTypes()) + .map(categoryNames -> categoryNames.get(resourceCategory)) + .map(subCategoryNames -> subCategoryNames.get(resourceSubCategory)).orElse(null); + } + @Override public String assetType() { return this.getResourceType().name(); @@ -174,21 +193,22 @@ public class Resource extends Component { @Override public boolean deriveFromGeneric() { - return this.shouldGenerateInputs() || (derivedFrom != null && derivedFrom - .contains(fetchGenericTypeToscaNameFromConfig())); + return this.shouldGenerateInputs() + || (derivedFrom != null && derivedFrom.contains(fetchGenericTypeToscaNameFromConfig())); } public Map> groupRelationsFromCsarByInstanceName(Resource resource) { List componentInstanceRelationsFromCsar = resource.getComponentInstancesRelations() - .stream().filter(r -> !r.isOriginUI()).collect(Collectors.toList()); - Map> relationsByInstanceId = MapUtil - .groupListBy(componentInstanceRelationsFromCsar, RequirementCapabilityRelDef::getFromNode); - return MapUtil - .convertMapKeys(relationsByInstanceId, instId -> getInstanceInvariantNameFromInstanceId(resource, instId)); + .stream().filter(r -> !r.isOriginUI()).collect(Collectors.toList()); + Map> relationsByInstanceId = + MapUtil.groupListBy(componentInstanceRelationsFromCsar, RequirementCapabilityRelDef::getFromNode); + return MapUtil.convertMapKeys(relationsByInstanceId, + instId -> getInstanceInvariantNameFromInstanceId(resource, instId)); } private String getInstanceInvariantNameFromInstanceId(Resource resource, String instId) { Optional componentInstanceById = resource.getComponentInstanceById(instId); return componentInstanceById.isPresent() ? componentInstanceById.get().getInvariantName() : null; } + } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java index 3040f6bb6c..3e33fd490c 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java @@ -22,16 +22,20 @@ package org.openecomp.sdc.be.model; import java.util.HashMap; import java.util.Map; +import java.util.Optional; + import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; import lombok.ToString; import org.apache.commons.lang.StringUtils; +import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition; import org.openecomp.sdc.be.datatypes.components.ServiceMetadataDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.InstantiationTypes; +import org.openecomp.sdc.be.model.category.CategoryDefinition; import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElementTypeEnum; @Getter @@ -51,8 +55,8 @@ public class Service extends Component { public Service(ComponentMetadataDefinition serviceMetadataDefinition) { super(serviceMetadataDefinition); - ComponentMetadataDataDefinition metadataDataDefinition = this.getComponentMetadataDefinition() - .getMetadataDataDefinition(); + ComponentMetadataDataDefinition metadataDataDefinition = + this.getComponentMetadataDefinition().getMetadataDataDefinition(); if (metadataDataDefinition != null) { metadataDataDefinition.setComponentType(ComponentTypeEnum.SERVICE); } @@ -157,6 +161,19 @@ public class Service extends Component { } } + @Override + public String fetchGenericTypeToscaNameFromConfig() { + return getHeadOption(this.getCategories()) + .map(category -> fetchToscaNameFromConfigBasedOnService(category.getName())) + .orElse(super.fetchGenericTypeToscaNameFromConfig()); + } + + private String fetchToscaNameFromConfigBasedOnService(final String serviceCategory) { + return Optional + .ofNullable(ConfigurationManager.getConfigurationManager().getConfiguration().getServiceNodeTypes()) + .map(serviceNames -> serviceNames.get(serviceCategory)).orElse(null); + } + @Override public void setSpecificComponetTypeArtifacts(Map specificComponentTypeArtifacts) { setServiceApiArtifacts(specificComponentTypeArtifacts); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java index bb72c53033..cb50c9601c 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ResourceTest.java @@ -20,11 +20,15 @@ package org.openecomp.sdc.be.model; +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import org.junit.Assert; import org.junit.Test; +import org.openecomp.sdc.be.config.Configuration; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.be.unittests.utils.ModelConfDependentTest; @@ -302,13 +306,38 @@ public class ResourceTest extends ModelConfDependentTest { } @Test - public void testFetchGenericTypeToscaNameFromConfig() throws Exception { - Resource testSubject; - String result; + public void testFetchGenericTypeToscaNameFromConfigNoToscaTypesDefinedForCategories() throws Exception { + Resource testSubject = createTestSubject(); + testSubject.addCategory("CategoryA", "SubCategoryB"); + + Configuration existingConfiguration = configurationManager.getConfiguration(); + Configuration newConfiguration = new Configuration(); + newConfiguration.setServiceNodeTypes(null); + Map genericAssetNodeTypes = new HashMap<>(); + genericAssetNodeTypes.put("VFC", "org.openecomp.resource.abstract.nodes.VFC"); + newConfiguration.setGenericAssetNodeTypes(genericAssetNodeTypes); + configurationManager.setConfiguration(newConfiguration); + + String result = testSubject.fetchGenericTypeToscaNameFromConfig(); + assertEquals("org.openecomp.resource.abstract.nodes.VFC", result); + configurationManager.setConfiguration(existingConfiguration); + } + @Test + public void testFetchGenericTypeToscaNameFromConfigNoToscaTypeDefinedForRelevantCategory() throws Exception { // default test - testSubject = createTestSubject(); - result = testSubject.fetchGenericTypeToscaNameFromConfig(); + Resource testSubject = createTestSubject(); + testSubject.addCategory("CategoryA", "SubCategoryC"); + String result = testSubject.fetchGenericTypeToscaNameFromConfig(); + assertEquals("org.openecomp.resource.abstract.nodes.VFC", result); + } + + @Test + public void testFetchGenericTypeToscaNameFromConfigToscaTypeDefinedForCategory() throws Exception { + Resource testSubject = createTestSubject(); + testSubject.addCategory("CategoryA", "SubCategoryB"); + String result = testSubject.fetchGenericTypeToscaNameFromConfig(); + assertEquals("org.openecomp.resource.abstract.nodes.B", result); } @Test diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ServiceTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ServiceTest.java index b677548773..d84d97b547 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/ServiceTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/ServiceTest.java @@ -25,275 +25,292 @@ import org.junit.Test; import org.openecomp.sdc.be.config.Configuration; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition; +import org.openecomp.sdc.be.model.category.CategoryDefinition; import org.openecomp.sdc.common.api.ConfigurationSource; import org.openecomp.sdc.common.impl.ExternalConfiguration; import org.openecomp.sdc.common.impl.FSConfigurationSource; +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; import java.util.Map; public class ServiceTest { - protected static ConfigurationManager configurationManager; - static Configuration.EnvironmentContext environmentContext = new Configuration.EnvironmentContext(); - - @BeforeClass - public static void init() { - String appConfigDir = "src/test/resources/config"; - ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), - appConfigDir); - configurationManager = new ConfigurationManager(configurationSource); - - Configuration configuration = new Configuration(); - - configuration.setJanusGraphInMemoryGraph(true); - environmentContext.setDefaultValue("General_Revenue-Bearing"); - configuration.setEnvironmentContext(environmentContext); - - configurationManager.setConfiguration(configuration); - } - - private Service createTestSubject() { - return new Service(); - } - - @Test - public void testCtor() throws Exception { - new Service(new ComponentMetadataDefinition()); - } - - @Test - public void testGetServiceApiArtifacts() throws Exception { - Service testSubject; - Map result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getServiceApiArtifacts(); - } - - - @Test - public void testSetServiceApiArtifacts() throws Exception { - Service testSubject; - Map serviceApiArtifacts = null; - - // default test - testSubject = createTestSubject(); - testSubject.setServiceApiArtifacts(serviceApiArtifacts); - } - - - @Test - public void testGetProjectCode() throws Exception { - Service testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getProjectCode(); - } - - - @Test - public void testGetForwardingPaths() throws Exception { - Service testSubject; - Map result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getForwardingPaths(); - } - - - @Test - public void testSetForwardingPaths() throws Exception { - Service testSubject; - Map forwardingPaths = null; - - // default test - testSubject = createTestSubject(); - testSubject.setForwardingPaths(forwardingPaths); - } - - - @Test - public void testAddForwardingPath() throws Exception { - Service testSubject; - ForwardingPathDataDefinition forwardingPathDataDefinition = new ForwardingPathDataDefinition(); - ForwardingPathDataDefinition result; - - // default test - testSubject = createTestSubject(); - result = testSubject.addForwardingPath(forwardingPathDataDefinition); - } - - - @Test - public void testSetProjectCode() throws Exception { - Service testSubject; - String projectName = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setProjectCode(projectName); - } - - - @Test - public void testGetDistributionStatus() throws Exception { - Service testSubject; - DistributionStatusEnum result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getDistributionStatus(); - } - - - @Test - public void testSetDistributionStatus() throws Exception { - Service testSubject; - DistributionStatusEnum distributionStatus = null; - - // test 1 - testSubject = createTestSubject(); - distributionStatus = null; - testSubject.setDistributionStatus(distributionStatus); - testSubject.setDistributionStatus(DistributionStatusEnum.DISTRIBUTED); - } - - - @Test - public void testSetEcompGeneratedNaming() throws Exception { - Service testSubject; - Boolean ecompGeneratedNaming = null; - - // default test - testSubject = createTestSubject(); - testSubject.setEcompGeneratedNaming(ecompGeneratedNaming); - } - - - @Test - public void testIsEcompGeneratedNaming() throws Exception { - Service testSubject; - Boolean result; - - // default test - testSubject = createTestSubject(); - result = testSubject.isEcompGeneratedNaming(); - } - - - @Test - public void testSetNamingPolicy() throws Exception { - Service testSubject; - String namingPolicy = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setNamingPolicy(namingPolicy); - } - - - @Test - public void testGetNamingPolicy() throws Exception { - Service testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getNamingPolicy(); - } - - - @Test - public void testGetEnvironmentContext() throws Exception { - Service testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getEnvironmentContext(); - } - - - @Test - public void testSetEnvironmentContext() throws Exception { - Service testSubject; - String environmentContext = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setEnvironmentContext(environmentContext); - } - - - @Test - public void testSetServiceType() throws Exception { - Service testSubject; - String serviceType = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setServiceType(serviceType); - } - - - @Test - public void testGetServiceType() throws Exception { - Service testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getServiceType(); - } - - - @Test - public void testSetServiceRole() throws Exception { - Service testSubject; - String serviceRole = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setServiceRole(serviceRole); - } - - - @Test - public void testGetServiceRole() throws Exception { - Service testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getServiceRole(); - } - - - - - - @Test - public void testToString() throws Exception { - Service testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.toString(); - } - - - @Test - public void testSetSpecificComponetTypeArtifacts() throws Exception { - Service testSubject; - Map specificComponentTypeArtifacts = null; - - // default test - testSubject = createTestSubject(); - testSubject.setSpecificComponetTypeArtifacts(specificComponentTypeArtifacts); - } + protected static ConfigurationManager configurationManager; + static Configuration.EnvironmentContext environmentContext = new Configuration.EnvironmentContext(); + + @BeforeClass + public static void init() { + String appConfigDir = "src/test/resources/config"; + ConfigurationSource configurationSource = + new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir); + configurationManager = new ConfigurationManager(configurationSource); + } + + private Service createTestSubject() { + return new Service(); + } + + @Test + public void testCtor() throws Exception { + new Service(new ComponentMetadataDefinition()); + } + + @Test + public void testGetServiceApiArtifacts() throws Exception { + Service testSubject; + Map result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getServiceApiArtifacts(); + } + + @Test + public void testSetServiceApiArtifacts() throws Exception { + Service testSubject; + Map serviceApiArtifacts = null; + + // default test + testSubject = createTestSubject(); + testSubject.setServiceApiArtifacts(serviceApiArtifacts); + } + + @Test + public void testGetProjectCode() throws Exception { + Service testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getProjectCode(); + } + + @Test + public void testGetForwardingPaths() throws Exception { + Service testSubject; + Map result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getForwardingPaths(); + } + + @Test + public void testSetForwardingPaths() throws Exception { + Service testSubject; + Map forwardingPaths = null; + + // default test + testSubject = createTestSubject(); + testSubject.setForwardingPaths(forwardingPaths); + } + + @Test + public void testAddForwardingPath() throws Exception { + Service testSubject; + ForwardingPathDataDefinition forwardingPathDataDefinition = new ForwardingPathDataDefinition(); + ForwardingPathDataDefinition result; + + // default test + testSubject = createTestSubject(); + result = testSubject.addForwardingPath(forwardingPathDataDefinition); + } + + @Test + public void testSetProjectCode() throws Exception { + Service testSubject; + String projectName = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setProjectCode(projectName); + } + + @Test + public void testGetDistributionStatus() throws Exception { + Service testSubject; + DistributionStatusEnum result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getDistributionStatus(); + } + + @Test + public void testSetDistributionStatus() throws Exception { + Service testSubject; + DistributionStatusEnum distributionStatus = null; + + // test 1 + testSubject = createTestSubject(); + distributionStatus = null; + testSubject.setDistributionStatus(distributionStatus); + testSubject.setDistributionStatus(DistributionStatusEnum.DISTRIBUTED); + } + + @Test + public void testSetEcompGeneratedNaming() throws Exception { + Service testSubject; + Boolean ecompGeneratedNaming = null; + + // default test + testSubject = createTestSubject(); + testSubject.setEcompGeneratedNaming(ecompGeneratedNaming); + } + + @Test + public void testIsEcompGeneratedNaming() throws Exception { + Service testSubject; + Boolean result; + + // default test + testSubject = createTestSubject(); + result = testSubject.isEcompGeneratedNaming(); + } + + @Test + public void testSetNamingPolicy() throws Exception { + Service testSubject; + String namingPolicy = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setNamingPolicy(namingPolicy); + } + + @Test + public void testGetNamingPolicy() throws Exception { + Service testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getNamingPolicy(); + } + + @Test + public void testGetEnvironmentContext() throws Exception { + Service testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getEnvironmentContext(); + } + + @Test + public void testSetEnvironmentContext() throws Exception { + Service testSubject; + String environmentContext = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setEnvironmentContext(environmentContext); + } + + @Test + public void testSetServiceType() throws Exception { + Service testSubject; + String serviceType = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setServiceType(serviceType); + } + + @Test + public void testGetServiceType() throws Exception { + Service testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getServiceType(); + } + + @Test + public void testSetServiceRole() throws Exception { + Service testSubject; + String serviceRole = ""; + + // default test + testSubject = createTestSubject(); + testSubject.setServiceRole(serviceRole); + } + + @Test + public void testGetServiceRole() throws Exception { + Service testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getServiceRole(); + } + + @Test + public void testToString() throws Exception { + Service testSubject; + String result; + + // default test + testSubject = createTestSubject(); + result = testSubject.toString(); + } + + @Test + public void testSetSpecificComponetTypeArtifacts() throws Exception { + Service testSubject; + Map specificComponentTypeArtifacts = null; + + // default test + testSubject = createTestSubject(); + testSubject.setSpecificComponetTypeArtifacts(specificComponentTypeArtifacts); + } + + @Test + public void testFetchGenericTypeToscaNameFromConfigNoToscaTypesForCategories() throws Exception { + Configuration existingConfiguration = configurationManager.getConfiguration(); + Configuration newConfiguration = new Configuration(); + newConfiguration.setServiceNodeTypes(null); + Map genericAssetNodeTypes = new HashMap<>(); + genericAssetNodeTypes.put("Service", "org.openecomp.resource.abstract.nodes.service"); + newConfiguration.setGenericAssetNodeTypes(genericAssetNodeTypes); + configurationManager.setConfiguration(newConfiguration); + + Service testSubject = createTestSubject(); + CategoryDefinition category = new CategoryDefinition(); + category.setName("CategoryB"); + testSubject.addCategory(category); + String result = testSubject.fetchGenericTypeToscaNameFromConfig(); + assertEquals("org.openecomp.resource.abstract.nodes.service", result); + configurationManager.setConfiguration(existingConfiguration); + } + + @Test + public void testFetchGenericTypeToscaNameFromConfigNoToscaTypeForRelevantCategory() throws Exception { + Service testSubject = createTestSubject(); + CategoryDefinition category = new CategoryDefinition(); + category.setName("CategoryD"); + testSubject.addCategory(category); + String result = testSubject.fetchGenericTypeToscaNameFromConfig(); + assertEquals("org.openecomp.resource.abstract.nodes.service", result); + } + + @Test + public void testFetchGenericTypeToscaNameFromConfigToscaTypeDefinedForCategory() throws Exception { + Service testSubject = createTestSubject(); + CategoryDefinition category = new CategoryDefinition(); + category.setName("CategoryB"); + testSubject.addCategory(category); + String result = testSubject.fetchGenericTypeToscaNameFromConfig(); + assertEquals("org.openecomp.resource.abstract.nodes.B", result); + + Configuration configuration = new Configuration(); + + configuration.setServiceNodeTypes(null); + configurationManager.setConfiguration(configuration); + } } diff --git a/catalog-model/src/test/resources/config/catalog-model/configuration.yaml b/catalog-model/src/test/resources/config/catalog-model/configuration.yaml index 8f7f0f8cf8..5055198a2d 100644 --- a/catalog-model/src/test/resources/config/catalog-model/configuration.yaml +++ b/catalog-model/src/test/resources/config/catalog-model/configuration.yaml @@ -337,6 +337,11 @@ genericAssetNodeTypes: VF : org.openecomp.resource.abstract.nodes.VF PNF: org.openecomp.resource.abstract.nodes.PNF Service: org.openecomp.resource.abstract.nodes.service + +resourceNodeTypes: + CategoryA: + SubCategoryA: org.openecomp.resource.abstract.nodes.A + SubCategoryB: org.openecomp.resource.abstract.nodes.B workloadContext: Production environmentContext: diff --git a/catalog-model/src/test/resources/config/configuration.yaml b/catalog-model/src/test/resources/config/configuration.yaml index 8f7f0f8cf8..4e8bc0a7dc 100644 --- a/catalog-model/src/test/resources/config/configuration.yaml +++ b/catalog-model/src/test/resources/config/configuration.yaml @@ -337,6 +337,11 @@ genericAssetNodeTypes: VF : org.openecomp.resource.abstract.nodes.VF PNF: org.openecomp.resource.abstract.nodes.PNF Service: org.openecomp.resource.abstract.nodes.service + +serviceNodeTypes: + CategoryA: org.openecomp.resource.abstract.nodes.A + CategoryB: org.openecomp.resource.abstract.nodes.B + CategoryC: org.openecomp.resource.abstract.nodes.C workloadContext: Production environmentContext: -- cgit 1.2.3-korg