diff options
author | MichaelMorris <michael.morris@est.tech> | 2020-04-06 15:44:56 +0100 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2020-05-07 08:14:26 +0000 |
commit | f8bc4f94da584d5861827df7ee2107c33f514a55 (patch) | |
tree | 4f16ccc40d1ecfce5b6d1e85ce731f9f1eb3d45d /catalog-model/src | |
parent | a36531c38fe1a9234b8dbeaed5505cf3ca48de26 (diff) |
Support configuring of tosca type for categories
Signed-off-by: MichaelMorris <michael.morris@est.tech>
Issue-ID: SDC-2877
Change-Id: I3160c5089979757628f31a44b01836236563b770
Diffstat (limited to 'catalog-model/src')
7 files changed, 424 insertions, 353 deletions
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<String, ArtifactDefinition> safeGetComponentInstanceDeploymentArtifacts(String componentInstanceId) { return getComponentInstanceById(componentInstanceId).map(ComponentInstance::safeGetDeploymentArtifacts) - .orElse(emptyMap()); + .orElse(emptyMap()); } public Map<String, ArtifactDefinition> safeGetComponentInstanceInformationalArtifacts(String componentInstanceId) { return getComponentInstanceById(componentInstanceId).map(ComponentInstance::safeGetInformationalArtifacts) - .orElse(emptyMap()); + .orElse(emptyMap()); } public List<ArtifactDefinition> 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<String, List<ComponentInstanceProperty>> safeGetComponentInstancesProperties() { @@ -336,13 +334,10 @@ public abstract class Component implements PropertiesOwner { } private Map<String, List<ComponentInstanceProperty>> findUiComponentInstancesProperties() { - List<String> 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<String> 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<String, List<ComponentInstanceInput>> safeGetComponentInstancesInputs() { @@ -354,13 +349,10 @@ public abstract class Component implements PropertiesOwner { } private Map<String, List<ComponentInstanceInput>> findUiComponentInstancesInputs() { - List<String> 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<String> 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<ComponentInstanceProperty> 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<GroupDefinition> 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<String, List<PropertyDataDefinition>> 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<ComponentInstanceInput> 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 <T> List<T> safeGetComponentInstanceEntity(String cmptInstanceId, Map<String, List<T>> instanceEntities) { @@ -604,17 +586,17 @@ public abstract class Component implements PropertiesOwner { return cmptInstanceProps == null ? emptyPropsList : cmptInstanceProps; } - public void setSpecificComponetTypeArtifacts(Map<String, ArtifactDefinition> 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 <A> Optional<A> getHeadOption(List<A> 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<GroupDefinition> 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<String, String> getComponentMetadataForSupportLog() { Map<String, String> 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<String> 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<String, List<RequirementCapabilityRelDef>> groupRelationsFromCsarByInstanceName(Resource resource) { List<RequirementCapabilityRelDef> componentInstanceRelationsFromCsar = resource.getComponentInstancesRelations() - .stream().filter(r -> !r.isOriginUI()).collect(Collectors.toList()); - Map<String, List<RequirementCapabilityRelDef>> relationsByInstanceId = MapUtil - .groupListBy(componentInstanceRelationsFromCsar, RequirementCapabilityRelDef::getFromNode); - return MapUtil - .convertMapKeys(relationsByInstanceId, instId -> getInstanceInvariantNameFromInstanceId(resource, instId)); + .stream().filter(r -> !r.isOriginUI()).collect(Collectors.toList()); + Map<String, List<RequirementCapabilityRelDef>> relationsByInstanceId = + MapUtil.groupListBy(componentInstanceRelationsFromCsar, RequirementCapabilityRelDef::getFromNode); + return MapUtil.convertMapKeys(relationsByInstanceId, + instId -> getInstanceInvariantNameFromInstanceId(resource, instId)); } private String getInstanceInvariantNameFromInstanceId(Resource resource, String instId) { Optional<ComponentInstance> 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); } @@ -158,6 +162,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<String, ArtifactDefinition> 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<String, String> 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<String, ArtifactDefinition> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getServiceApiArtifacts(); - } - - - @Test - public void testSetServiceApiArtifacts() throws Exception { - Service testSubject; - Map<String, ArtifactDefinition> 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<String, ForwardingPathDataDefinition> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getForwardingPaths(); - } - - - @Test - public void testSetForwardingPaths() throws Exception { - Service testSubject; - Map<String, ForwardingPathDataDefinition> 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<String, ArtifactDefinition> 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<String, ArtifactDefinition> result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getServiceApiArtifacts(); + } + + @Test + public void testSetServiceApiArtifacts() throws Exception { + Service testSubject; + Map<String, ArtifactDefinition> 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<String, ForwardingPathDataDefinition> result; + + // default test + testSubject = createTestSubject(); + result = testSubject.getForwardingPaths(); + } + + @Test + public void testSetForwardingPaths() throws Exception { + Service testSubject; + Map<String, ForwardingPathDataDefinition> 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<String, ArtifactDefinition> 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<String, String> 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: |