2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.model;
23 import org.junit.BeforeClass;
24 import org.junit.Test;
25 import org.openecomp.sdc.be.config.Configuration;
26 import org.openecomp.sdc.be.config.ConfigurationManager;
27 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
28 import org.openecomp.sdc.be.model.category.CategoryDefinition;
29 import org.openecomp.sdc.common.api.ConfigurationSource;
30 import org.openecomp.sdc.common.impl.ExternalConfiguration;
31 import org.openecomp.sdc.common.impl.FSConfigurationSource;
33 import static org.junit.Assert.assertEquals;
35 import java.util.HashMap;
38 public class ServiceTest {
40 protected static ConfigurationManager configurationManager;
41 static Configuration.EnvironmentContext environmentContext = new Configuration.EnvironmentContext();
44 public static void init() {
45 String appConfigDir = "src/test/resources/config";
46 ConfigurationSource configurationSource =
47 new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
48 configurationManager = new ConfigurationManager(configurationSource);
51 private Service createTestSubject() {
56 public void testCtor() throws Exception {
57 new Service(new ComponentMetadataDefinition());
61 public void testGetServiceApiArtifacts() throws Exception {
63 Map<String, ArtifactDefinition> result;
66 testSubject = createTestSubject();
67 result = testSubject.getServiceApiArtifacts();
71 public void testSetServiceApiArtifacts() throws Exception {
73 Map<String, ArtifactDefinition> serviceApiArtifacts = null;
76 testSubject = createTestSubject();
77 testSubject.setServiceApiArtifacts(serviceApiArtifacts);
81 public void testGetProjectCode() throws Exception {
86 testSubject = createTestSubject();
87 result = testSubject.getProjectCode();
91 public void testGetForwardingPaths() throws Exception {
93 Map<String, ForwardingPathDataDefinition> result;
96 testSubject = createTestSubject();
97 result = testSubject.getForwardingPaths();
101 public void testSetForwardingPaths() throws Exception {
103 Map<String, ForwardingPathDataDefinition> forwardingPaths = null;
106 testSubject = createTestSubject();
107 testSubject.setForwardingPaths(forwardingPaths);
111 public void testAddForwardingPath() throws Exception {
113 ForwardingPathDataDefinition forwardingPathDataDefinition = new ForwardingPathDataDefinition();
114 ForwardingPathDataDefinition result;
117 testSubject = createTestSubject();
118 result = testSubject.addForwardingPath(forwardingPathDataDefinition);
122 public void testSetProjectCode() throws Exception {
124 String projectName = "";
127 testSubject = createTestSubject();
128 testSubject.setProjectCode(projectName);
132 public void testGetDistributionStatus() throws Exception {
134 DistributionStatusEnum result;
137 testSubject = createTestSubject();
138 result = testSubject.getDistributionStatus();
142 public void testSetDistributionStatus() throws Exception {
144 DistributionStatusEnum distributionStatus = null;
147 testSubject = createTestSubject();
148 distributionStatus = null;
149 testSubject.setDistributionStatus(distributionStatus);
150 testSubject.setDistributionStatus(DistributionStatusEnum.DISTRIBUTED);
154 public void testSetEcompGeneratedNaming() throws Exception {
156 Boolean ecompGeneratedNaming = null;
159 testSubject = createTestSubject();
160 testSubject.setEcompGeneratedNaming(ecompGeneratedNaming);
164 public void testIsEcompGeneratedNaming() throws Exception {
169 testSubject = createTestSubject();
170 result = testSubject.isEcompGeneratedNaming();
174 public void testSetNamingPolicy() throws Exception {
176 String namingPolicy = "";
179 testSubject = createTestSubject();
180 testSubject.setNamingPolicy(namingPolicy);
184 public void testGetNamingPolicy() throws Exception {
189 testSubject = createTestSubject();
190 result = testSubject.getNamingPolicy();
194 public void testGetEnvironmentContext() throws Exception {
199 testSubject = createTestSubject();
200 result = testSubject.getEnvironmentContext();
204 public void testSetEnvironmentContext() throws Exception {
206 String environmentContext = "";
209 testSubject = createTestSubject();
210 testSubject.setEnvironmentContext(environmentContext);
214 public void testSetServiceType() throws Exception {
216 String serviceType = "";
219 testSubject = createTestSubject();
220 testSubject.setServiceType(serviceType);
224 public void testGetServiceType() throws Exception {
229 testSubject = createTestSubject();
230 result = testSubject.getServiceType();
234 public void testSetServiceRole() throws Exception {
236 String serviceRole = "";
239 testSubject = createTestSubject();
240 testSubject.setServiceRole(serviceRole);
244 public void testGetServiceRole() throws Exception {
249 testSubject = createTestSubject();
250 result = testSubject.getServiceRole();
254 public void testToString() throws Exception {
259 testSubject = createTestSubject();
260 result = testSubject.toString();
264 public void testSetSpecificComponetTypeArtifacts() throws Exception {
266 Map<String, ArtifactDefinition> specificComponentTypeArtifacts = null;
269 testSubject = createTestSubject();
270 testSubject.setSpecificComponetTypeArtifacts(specificComponentTypeArtifacts);
274 public void testFetchGenericTypeToscaNameFromConfigNoToscaTypesForCategories() {
275 Configuration existingConfiguration = configurationManager.getConfiguration();
276 Configuration newConfiguration = new Configuration();
277 newConfiguration.setServiceBaseNodeTypes(null);
278 Map<String, String> genericAssetNodeTypes = new HashMap<>();
279 genericAssetNodeTypes.put("Service", "org.openecomp.resource.abstract.nodes.service");
280 newConfiguration.setGenericAssetNodeTypes(genericAssetNodeTypes);
281 configurationManager.setConfiguration(newConfiguration);
283 Service testSubject = createTestSubject();
284 CategoryDefinition category = new CategoryDefinition();
285 category.setName("CategoryB");
286 testSubject.addCategory(category);
287 String result = testSubject.fetchGenericTypeToscaNameFromConfig();
288 assertEquals("org.openecomp.resource.abstract.nodes.service", result);
289 configurationManager.setConfiguration(existingConfiguration);
293 public void testFetchGenericTypeToscaNameFromConfigNoToscaTypeForRelevantCategory() {
294 Service testSubject = createTestSubject();
295 CategoryDefinition category = new CategoryDefinition();
296 category.setName("CategoryD");
297 testSubject.addCategory(category);
298 String result = testSubject.fetchGenericTypeToscaNameFromConfig();
299 assertEquals("org.openecomp.resource.abstract.nodes.service", result);
303 public void testFetchGenericTypeToscaNameFromConfigToscaTypeDefinedForCategory() {
304 Service testSubject = createTestSubject();
305 CategoryDefinition category = new CategoryDefinition();
306 category.setName("CategoryA");
307 testSubject.addCategory(category);
308 String result = testSubject.fetchGenericTypeToscaNameFromConfig();
309 assertEquals("org.openecomp.resource.abstract.nodes.A", result);
311 Configuration configuration = new Configuration();
313 configuration.setServiceBaseNodeTypes(null);
314 configurationManager.setConfiguration(configuration);