2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.openecomp.sdc.be.model.jsonjanusgraph.config;
22 import static java.util.Collections.emptyList;
23 import static org.hamcrest.MatcherAssert.assertThat;
24 import static org.hamcrest.Matchers.containsInAnyOrder;
25 import static org.hamcrest.Matchers.empty;
26 import static org.hamcrest.Matchers.is;
28 import java.util.EnumMap;
29 import java.util.EnumSet;
30 import java.util.List;
31 import org.apache.commons.collections4.CollectionUtils;
32 import org.junit.jupiter.api.BeforeAll;
33 import org.junit.jupiter.api.BeforeEach;
34 import org.junit.jupiter.api.Test;
35 import org.openecomp.sdc.be.config.ConfigurationManager;
36 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
37 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
38 import org.openecomp.sdc.common.impl.ExternalConfiguration;
39 import org.openecomp.sdc.common.impl.FSConfigurationSource;
41 public class ContainerInstanceTypesDataTest {
43 private ContainerInstanceTypesData containerInstanceTypesData;
44 private EnumSet<ResourceTypeEnum> serviceAllowedTypes;
45 private EnumMap<ResourceTypeEnum, EnumSet<ResourceTypeEnum>> resourceAllowedTypeConfig;
46 private EnumSet<ResourceTypeEnum> allResourceTypes;
49 public static void beforeClass() {
50 new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
51 "src/test/resources/config"));
56 containerInstanceTypesData = new ContainerInstanceTypesData();
58 allResourceTypes = EnumSet.allOf(ResourceTypeEnum.class);
60 serviceAllowedTypes = EnumSet.of(ResourceTypeEnum.VF,
64 ResourceTypeEnum.CVFC,
66 ResourceTypeEnum.Configuration,
67 ResourceTypeEnum.ServiceProxy,
68 ResourceTypeEnum.ABSTRACT
71 resourceAllowedTypeConfig =
72 new EnumMap<>(ResourceTypeEnum.class);
74 resourceAllowedTypeConfig.put(ResourceTypeEnum.VF,
75 EnumSet.of(ResourceTypeEnum.VFC,
80 ResourceTypeEnum.CVFC,
82 ResourceTypeEnum.Configuration,
83 ResourceTypeEnum.ServiceProxy,
84 ResourceTypeEnum.ABSTRACT));
86 resourceAllowedTypeConfig.put(ResourceTypeEnum.CVFC,
87 EnumSet.of(ResourceTypeEnum.VFC,
92 ResourceTypeEnum.CVFC,
94 ResourceTypeEnum.ServiceProxy,
95 ResourceTypeEnum.ABSTRACT));
97 resourceAllowedTypeConfig.put(ResourceTypeEnum.PNF,
98 EnumSet.of(ResourceTypeEnum.VF,
101 ResourceTypeEnum.PNF,
102 ResourceTypeEnum.CVFC,
104 ResourceTypeEnum.Configuration,
105 ResourceTypeEnum.ServiceProxy,
106 ResourceTypeEnum.ABSTRACT));
108 resourceAllowedTypeConfig.put(ResourceTypeEnum.CR,
109 EnumSet.of(ResourceTypeEnum.VF,
112 ResourceTypeEnum.PNF,
113 ResourceTypeEnum.CVFC,
115 ResourceTypeEnum.Configuration,
116 ResourceTypeEnum.ServiceProxy,
117 ResourceTypeEnum.ABSTRACT));
119 resourceAllowedTypeConfig.put(ResourceTypeEnum.VL,
120 EnumSet.of(ResourceTypeEnum.VL));
124 public void isAllowedForServiceComponent() {
125 for (final ResourceTypeEnum allowedType : serviceAllowedTypes) {
126 assertThat(String.format("%s should be allowed", allowedType.getValue()),
127 containerInstanceTypesData.isAllowedForServiceComponent(allowedType), is(true));
132 public void isAllowedForResourceComponent() {
133 for (final ResourceTypeEnum componentResourceType : allResourceTypes) {
134 final EnumSet<ResourceTypeEnum> allowedResourceType = resourceAllowedTypeConfig.get(componentResourceType);
135 for (final ResourceTypeEnum resourceType : allResourceTypes) {
136 if (allowedResourceType == null) {
137 final String msg = String
138 .format("'%s' resource type should not be allowed", resourceType.getValue());
139 assertThat(msg, containerInstanceTypesData
140 .isAllowedForResourceComponent(componentResourceType, resourceType), is(false));
143 final boolean isAllowed = allowedResourceType.contains(resourceType);
144 final String msg = String
145 .format("'%s' resource type should %s be allowed", resourceType.getValue(), isAllowed ? "" : "not");
146 assertThat(msg, containerInstanceTypesData
147 .isAllowedForResourceComponent(componentResourceType, resourceType), is(
154 public void getComponentAllowedListTest() {
155 List<String> actualAllowedList = containerInstanceTypesData
156 .getComponentAllowedList(ComponentTypeEnum.SERVICE, null);
157 assertThat("Allowed Instance Resource Type List should be as expected",
158 actualAllowedList, containsInAnyOrder(actualAllowedList.toArray()));
160 for (final ResourceTypeEnum resourceType : allResourceTypes) {
161 actualAllowedList = containerInstanceTypesData
162 .getComponentAllowedList(ComponentTypeEnum.RESOURCE, resourceType);
163 final EnumSet<ResourceTypeEnum> expectedAllowedSet = resourceAllowedTypeConfig.get(resourceType);
164 if (CollectionUtils.isEmpty(expectedAllowedSet)) {
165 assertThat("Allowed Instance Resource Type List should be as expected",
166 actualAllowedList, is(empty()));
169 assertThat("Allowed Instance Resource Type List should be as expected",
171 containsInAnyOrder(expectedAllowedSet.stream().map(ResourceTypeEnum::getValue).toArray()));
176 public void getComponentAllowedListTestEmptyList() {
177 List<String> actualAllowedList = containerInstanceTypesData
178 .getComponentAllowedList(ComponentTypeEnum.PRODUCT, null);
179 final String msg = "Allowed Instance Resource Type List should be empty";
180 assertThat(msg, actualAllowedList, is(emptyList()));
182 actualAllowedList = containerInstanceTypesData
183 .getComponentAllowedList(ComponentTypeEnum.SERVICE, ResourceTypeEnum.VF);
184 assertThat(msg, actualAllowedList, is(emptyList()));
186 actualAllowedList = containerInstanceTypesData
187 .getComponentAllowedList(ComponentTypeEnum.SERVICE, ResourceTypeEnum.ServiceProxy);
188 assertThat(msg, actualAllowedList, is(emptyList()));
190 actualAllowedList = containerInstanceTypesData
191 .getComponentAllowedList(ComponentTypeEnum.RESOURCE, null);
192 assertThat(msg, actualAllowedList, is(emptyList()));