diff options
author | andre.schmid <andre.schmid@est.tech> | 2020-03-04 16:28:05 +0000 |
---|---|---|
committer | Julien Bertozzi <julien.bertozzi@intl.att.com> | 2020-07-29 11:39:50 +0000 |
commit | 5e8464585f07210ad4b20ddfee2c23b1cf2d8b2a (patch) | |
tree | d0e9b828f0b374f504115443814537deb35d49c1 /catalog-model/src/test/java | |
parent | 18a43d537bc91d752377159fb0d5b3e9f5bdd6e5 (diff) |
Config. allowed instances in component composition
During the creation of Resource and Services components,
the allowed types to add in its composition are hard-coded.
This change allows those types to be configurable using the
configuration.yaml backend file.
Change-Id: If48849b57fe5124468db3d55f2f06391348935fb
Issue-ID: SDC-3177
Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-model/src/test/java')
2 files changed, 196 insertions, 0 deletions
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/config/ModelOperationsSpringConfig.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/config/ModelOperationsSpringConfig.java index a473e31c58..929441cf01 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/config/ModelOperationsSpringConfig.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/config/ModelOperationsSpringConfig.java @@ -28,6 +28,7 @@ import org.springframework.context.annotation.PropertySource; @ComponentScan({"org.openecomp.sdc.be.dao.cassandra", "org.openecomp.sdc.be.model.cache", "org.openecomp.sdc.be.model.jsonjanusgraph.operations", "org.openecomp.sdc.be.model.jsonjanusgraph.utils", + "org.openecomp.sdc.be.model.jsonjanusgraph.config", "org.openecomp.sdc.be.model.operations.impl"}) @PropertySource("classpath:dao.properties") public class ModelOperationsSpringConfig { } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/config/ContainerInstanceTypesDataTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/config/ContainerInstanceTypesDataTest.java new file mode 100644 index 0000000000..5df79146c4 --- /dev/null +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/config/ContainerInstanceTypesDataTest.java @@ -0,0 +1,195 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.be.model.jsonjanusgraph.config; + +import static java.util.Collections.emptyList; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.is; + +import java.util.EnumMap; +import java.util.EnumSet; +import java.util.List; +import org.apache.commons.collections4.CollectionUtils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.openecomp.sdc.be.config.ConfigurationManager; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; +import org.openecomp.sdc.common.impl.ExternalConfiguration; +import org.openecomp.sdc.common.impl.FSConfigurationSource; + +public class ContainerInstanceTypesDataTest { + + private ContainerInstanceTypesData containerInstanceTypesData; + private EnumSet<ResourceTypeEnum> serviceAllowedTypes; + private EnumMap<ResourceTypeEnum, EnumSet<ResourceTypeEnum>> resourceAllowedTypeConfig; + private EnumSet<ResourceTypeEnum> allResourceTypes; + + @BeforeAll + public static void beforeClass() { + new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), + "src/test/resources/config")); + } + + @BeforeEach + public void setUp() { + containerInstanceTypesData = new ContainerInstanceTypesData(); + + allResourceTypes = EnumSet.allOf(ResourceTypeEnum.class); + + serviceAllowedTypes = EnumSet.of(ResourceTypeEnum.VF, + ResourceTypeEnum.CR, + ResourceTypeEnum.CP, + ResourceTypeEnum.PNF, + ResourceTypeEnum.CVFC, + ResourceTypeEnum.VL, + ResourceTypeEnum.Configuration, + ResourceTypeEnum.ServiceProxy, + ResourceTypeEnum.ABSTRACT + ); + + resourceAllowedTypeConfig = + new EnumMap<>(ResourceTypeEnum.class); + + resourceAllowedTypeConfig.put(ResourceTypeEnum.VF, + EnumSet.of(ResourceTypeEnum.VFC, + ResourceTypeEnum.VF, + ResourceTypeEnum.CR, + ResourceTypeEnum.CP, + ResourceTypeEnum.PNF, + ResourceTypeEnum.CVFC, + ResourceTypeEnum.VL, + ResourceTypeEnum.Configuration, + ResourceTypeEnum.ServiceProxy, + ResourceTypeEnum.ABSTRACT)); + + resourceAllowedTypeConfig.put(ResourceTypeEnum.CVFC, + EnumSet.of(ResourceTypeEnum.VFC, + ResourceTypeEnum.VF, + ResourceTypeEnum.CR, + ResourceTypeEnum.CP, + ResourceTypeEnum.PNF, + ResourceTypeEnum.CVFC, + ResourceTypeEnum.VL, + ResourceTypeEnum.ServiceProxy, + ResourceTypeEnum.ABSTRACT)); + + resourceAllowedTypeConfig.put(ResourceTypeEnum.PNF, + EnumSet.of(ResourceTypeEnum.VF, + ResourceTypeEnum.CR, + ResourceTypeEnum.CP, + ResourceTypeEnum.PNF, + ResourceTypeEnum.CVFC, + ResourceTypeEnum.VL, + ResourceTypeEnum.Configuration, + ResourceTypeEnum.ServiceProxy, + ResourceTypeEnum.ABSTRACT)); + + resourceAllowedTypeConfig.put(ResourceTypeEnum.CR, + EnumSet.of(ResourceTypeEnum.VF, + ResourceTypeEnum.CR, + ResourceTypeEnum.CP, + ResourceTypeEnum.PNF, + ResourceTypeEnum.CVFC, + ResourceTypeEnum.VL, + ResourceTypeEnum.Configuration, + ResourceTypeEnum.ServiceProxy, + ResourceTypeEnum.ABSTRACT)); + + resourceAllowedTypeConfig.put(ResourceTypeEnum.VL, + EnumSet.of(ResourceTypeEnum.VL)); + } + + @Test + public void isAllowedForServiceComponent() { + for (final ResourceTypeEnum allowedType : serviceAllowedTypes) { + assertThat(String.format("%s should be allowed", allowedType.getValue()), + containerInstanceTypesData.isAllowedForServiceComponent(allowedType), is(true)); + } + } + + @Test + public void isAllowedForResourceComponent() { + for (final ResourceTypeEnum componentResourceType : allResourceTypes) { + final EnumSet<ResourceTypeEnum> allowedResourceType = resourceAllowedTypeConfig.get(componentResourceType); + for (final ResourceTypeEnum resourceType : allResourceTypes) { + if (allowedResourceType == null) { + final String msg = String + .format("'%s' resource type should not be allowed", resourceType.getValue()); + assertThat(msg, containerInstanceTypesData + .isAllowedForResourceComponent(componentResourceType, resourceType), is(false)); + continue; + } + final boolean isAllowed = allowedResourceType.contains(resourceType); + final String msg = String + .format("'%s' resource type should %s be allowed", resourceType.getValue(), isAllowed ? "" : "not"); + assertThat(msg, containerInstanceTypesData + .isAllowedForResourceComponent(componentResourceType, resourceType), is( + isAllowed)); + } + } + } + + @Test + public void getComponentAllowedListTest() { + List<String> actualAllowedList = containerInstanceTypesData + .getComponentAllowedList(ComponentTypeEnum.SERVICE, null); + assertThat("Allowed Instance Resource Type List should be as expected", + actualAllowedList, containsInAnyOrder(actualAllowedList.toArray())); + + for (final ResourceTypeEnum resourceType : allResourceTypes) { + actualAllowedList = containerInstanceTypesData + .getComponentAllowedList(ComponentTypeEnum.RESOURCE, resourceType); + final EnumSet<ResourceTypeEnum> expectedAllowedSet = resourceAllowedTypeConfig.get(resourceType); + if (CollectionUtils.isEmpty(expectedAllowedSet)) { + assertThat("Allowed Instance Resource Type List should be as expected", + actualAllowedList, is(empty())); + continue; + } + assertThat("Allowed Instance Resource Type List should be as expected", + actualAllowedList, + containsInAnyOrder(expectedAllowedSet.stream().map(ResourceTypeEnum::getValue).toArray())); + } + } + + @Test + public void getComponentAllowedListTestEmptyList() { + List<String> actualAllowedList = containerInstanceTypesData + .getComponentAllowedList(ComponentTypeEnum.PRODUCT, null); + final String msg = "Allowed Instance Resource Type List should be empty"; + assertThat(msg, actualAllowedList, is(emptyList())); + + actualAllowedList = containerInstanceTypesData + .getComponentAllowedList(ComponentTypeEnum.SERVICE, ResourceTypeEnum.VF); + assertThat(msg, actualAllowedList, is(emptyList())); + + actualAllowedList = containerInstanceTypesData + .getComponentAllowedList(ComponentTypeEnum.SERVICE, ResourceTypeEnum.ServiceProxy); + assertThat(msg, actualAllowedList, is(emptyList())); + + actualAllowedList = containerInstanceTypesData + .getComponentAllowedList(ComponentTypeEnum.RESOURCE, null); + assertThat(msg, actualAllowedList, is(emptyList())); + } + +}
\ No newline at end of file |