Make Service base type optional
[sdc.git] / catalog-model / src / test / java / org / openecomp / sdc / be / model / ServiceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.model;
22
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;
32
33 import static org.junit.Assert.assertEquals;
34
35 import java.util.HashMap;
36 import java.util.Map;
37
38 public class ServiceTest {
39
40     protected static ConfigurationManager configurationManager;
41     static Configuration.EnvironmentContext environmentContext = new Configuration.EnvironmentContext();
42
43     @BeforeClass
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);
49     }
50
51     private Service createTestSubject() {
52         return new Service();
53     }
54
55     @Test
56     public void testCtor() throws Exception {
57         new Service(new ComponentMetadataDefinition());
58     }
59
60     @Test
61     public void testGetServiceApiArtifacts() throws Exception {
62         Service testSubject;
63         Map<String, ArtifactDefinition> result;
64
65         // default test
66         testSubject = createTestSubject();
67         result = testSubject.getServiceApiArtifacts();
68     }
69
70     @Test
71     public void testSetServiceApiArtifacts() throws Exception {
72         Service testSubject;
73         Map<String, ArtifactDefinition> serviceApiArtifacts = null;
74
75         // default test
76         testSubject = createTestSubject();
77         testSubject.setServiceApiArtifacts(serviceApiArtifacts);
78     }
79
80     @Test
81     public void testGetProjectCode() throws Exception {
82         Service testSubject;
83         String result;
84
85         // default test
86         testSubject = createTestSubject();
87         result = testSubject.getProjectCode();
88     }
89
90     @Test
91     public void testGetForwardingPaths() throws Exception {
92         Service testSubject;
93         Map<String, ForwardingPathDataDefinition> result;
94
95         // default test
96         testSubject = createTestSubject();
97         result = testSubject.getForwardingPaths();
98     }
99
100     @Test
101     public void testSetForwardingPaths() throws Exception {
102         Service testSubject;
103         Map<String, ForwardingPathDataDefinition> forwardingPaths = null;
104
105         // default test
106         testSubject = createTestSubject();
107         testSubject.setForwardingPaths(forwardingPaths);
108     }
109
110     @Test
111     public void testAddForwardingPath() throws Exception {
112         Service testSubject;
113         ForwardingPathDataDefinition forwardingPathDataDefinition = new ForwardingPathDataDefinition();
114         ForwardingPathDataDefinition result;
115
116         // default test
117         testSubject = createTestSubject();
118         result = testSubject.addForwardingPath(forwardingPathDataDefinition);
119     }
120
121     @Test
122     public void testSetProjectCode() throws Exception {
123         Service testSubject;
124         String projectName = "";
125
126         // default test
127         testSubject = createTestSubject();
128         testSubject.setProjectCode(projectName);
129     }
130
131     @Test
132     public void testGetDistributionStatus() throws Exception {
133         Service testSubject;
134         DistributionStatusEnum result;
135
136         // default test
137         testSubject = createTestSubject();
138         result = testSubject.getDistributionStatus();
139     }
140
141     @Test
142     public void testSetDistributionStatus() throws Exception {
143         Service testSubject;
144         DistributionStatusEnum distributionStatus = null;
145
146         // test 1
147         testSubject = createTestSubject();
148         distributionStatus = null;
149         testSubject.setDistributionStatus(distributionStatus);
150         testSubject.setDistributionStatus(DistributionStatusEnum.DISTRIBUTED);
151     }
152
153     @Test
154     public void testSetEcompGeneratedNaming() throws Exception {
155         Service testSubject;
156         Boolean ecompGeneratedNaming = null;
157
158         // default test
159         testSubject = createTestSubject();
160         testSubject.setEcompGeneratedNaming(ecompGeneratedNaming);
161     }
162
163     @Test
164     public void testIsEcompGeneratedNaming() throws Exception {
165         Service testSubject;
166         Boolean result;
167
168         // default test
169         testSubject = createTestSubject();
170         result = testSubject.isEcompGeneratedNaming();
171     }
172
173     @Test
174     public void testSetNamingPolicy() throws Exception {
175         Service testSubject;
176         String namingPolicy = "";
177
178         // default test
179         testSubject = createTestSubject();
180         testSubject.setNamingPolicy(namingPolicy);
181     }
182
183     @Test
184     public void testGetNamingPolicy() throws Exception {
185         Service testSubject;
186         String result;
187
188         // default test
189         testSubject = createTestSubject();
190         result = testSubject.getNamingPolicy();
191     }
192
193     @Test
194     public void testGetEnvironmentContext() throws Exception {
195         Service testSubject;
196         String result;
197
198         // default test
199         testSubject = createTestSubject();
200         result = testSubject.getEnvironmentContext();
201     }
202
203     @Test
204     public void testSetEnvironmentContext() throws Exception {
205         Service testSubject;
206         String environmentContext = "";
207
208         // default test
209         testSubject = createTestSubject();
210         testSubject.setEnvironmentContext(environmentContext);
211     }
212
213     @Test
214     public void testSetServiceType() throws Exception {
215         Service testSubject;
216         String serviceType = "";
217
218         // default test
219         testSubject = createTestSubject();
220         testSubject.setServiceType(serviceType);
221     }
222
223     @Test
224     public void testGetServiceType() throws Exception {
225         Service testSubject;
226         String result;
227
228         // default test
229         testSubject = createTestSubject();
230         result = testSubject.getServiceType();
231     }
232
233     @Test
234     public void testSetServiceRole() throws Exception {
235         Service testSubject;
236         String serviceRole = "";
237
238         // default test
239         testSubject = createTestSubject();
240         testSubject.setServiceRole(serviceRole);
241     }
242
243     @Test
244     public void testGetServiceRole() throws Exception {
245         Service testSubject;
246         String result;
247
248         // default test
249         testSubject = createTestSubject();
250         result = testSubject.getServiceRole();
251     }
252
253     @Test
254     public void testToString() throws Exception {
255         Service testSubject;
256         String result;
257
258         // default test
259         testSubject = createTestSubject();
260         result = testSubject.toString();
261     }
262
263     @Test
264     public void testSetSpecificComponetTypeArtifacts() throws Exception {
265         Service testSubject;
266         Map<String, ArtifactDefinition> specificComponentTypeArtifacts = null;
267
268         // default test
269         testSubject = createTestSubject();
270         testSubject.setSpecificComponetTypeArtifacts(specificComponentTypeArtifacts);
271     }
272
273     @Test
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);
282
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);
290     }
291
292     @Test
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);
300     }
301
302     @Test
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);
310
311         Configuration configuration = new Configuration();
312
313         configuration.setServiceBaseNodeTypes(null);
314         configurationManager.setConfiguration(configuration);
315     }
316 }