cb50c9601c3bd3a344ea746edcfcf66790b80ed6
[sdc.git] / catalog-model / src / test / java / org / openecomp / sdc / be / model / ResourceTest.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 static org.junit.Assert.assertEquals;
24
25 import java.util.HashMap;
26 import java.util.LinkedList;
27 import java.util.List;
28 import java.util.Map;
29 import org.junit.Assert;
30 import org.junit.Test;
31 import org.openecomp.sdc.be.config.Configuration;
32 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
33 import org.openecomp.sdc.be.unittests.utils.ModelConfDependentTest;
34
35 public class ResourceTest extends ModelConfDependentTest {
36
37     private Resource createTestSubject() {
38         return new Resource();
39     }
40
41     @Test
42     public void testCtor() throws Exception {
43         ComponentMetadataDefinition componentMetadataDefinition = new ResourceMetadataDefinition();
44         new Resource(componentMetadataDefinition);
45     }
46
47     @Test
48     public void testGetProperties() throws Exception {
49         Resource testSubject;
50         List<PropertyDefinition> result;
51
52         // default test
53         testSubject = createTestSubject();
54         result = testSubject.getProperties();
55     }
56
57     @Test
58     public void testSetProperties() throws Exception {
59         Resource testSubject;
60         List<PropertyDefinition> properties = null;
61
62         // default test
63         testSubject = createTestSubject();
64         testSubject.setProperties(properties);
65     }
66
67     @Test
68     public void testGetAttributes() throws Exception {
69         Resource testSubject;
70         List<PropertyDefinition> result;
71
72         // default test
73         testSubject = createTestSubject();
74         result = testSubject.getAttributes();
75     }
76
77     @Test
78     public void testSetAttributes() throws Exception {
79         Resource testSubject;
80         List<PropertyDefinition> attributes = null;
81
82         // default test
83         testSubject = createTestSubject();
84         testSubject.setAttributes(attributes);
85     }
86
87     @Test
88     public void testGetInterfaces() throws Exception {
89         Resource testSubject;
90         Map<String, InterfaceDefinition> result;
91
92         // default test
93         testSubject = createTestSubject();
94         result = testSubject.getInterfaces();
95     }
96
97     @Test
98     public void testSetInterfaces() throws Exception {
99         Resource testSubject;
100         Map<String, InterfaceDefinition> interfaces = null;
101
102         // default test
103         testSubject = createTestSubject();
104         testSubject.setInterfaces(interfaces);
105     }
106
107     @Test
108     public void testIsAbstract() throws Exception {
109         Resource testSubject;
110         Boolean result;
111
112         // default test
113         testSubject = createTestSubject();
114         result = testSubject.isAbstract();
115     }
116
117     @Test
118     public void testSetAbstract() throws Exception {
119         Resource testSubject;
120         Boolean isAbstract = null;
121
122         // default test
123         testSubject = createTestSubject();
124         testSubject.setAbstract(isAbstract);
125     }
126
127     @Test
128     public void testGetCost() throws Exception {
129         Resource testSubject;
130         String result;
131
132         // default test
133         testSubject = createTestSubject();
134         result = testSubject.getCost();
135     }
136
137     @Test
138     public void testSetCost() throws Exception {
139         Resource testSubject;
140         String cost = "";
141
142         // default test
143         testSubject = createTestSubject();
144         testSubject.setCost(cost);
145     }
146
147     @Test
148     public void testGetLicenseType() throws Exception {
149         Resource testSubject;
150         String result;
151
152         // default test
153         testSubject = createTestSubject();
154         result = testSubject.getLicenseType();
155     }
156
157     @Test
158     public void testSetLicenseType() throws Exception {
159         Resource testSubject;
160         String licenseType = "";
161
162         // default test
163         testSubject = createTestSubject();
164         testSubject.setLicenseType(licenseType);
165     }
166
167     @Test
168     public void testHashCode() throws Exception {
169         Resource testSubject;
170         int result;
171
172         // default test
173         testSubject = createTestSubject();
174         result = testSubject.hashCode();
175     }
176
177     @Test
178     public void testEquals() throws Exception {
179         Resource testSubject;
180         Object obj = null;
181         boolean result;
182
183         // test 1
184         testSubject = createTestSubject();
185         result = testSubject.equals(obj);
186         Assert.assertEquals(false, result);
187         obj = new Object();
188         result = testSubject.equals(obj);
189         Assert.assertEquals(false, result);
190         result = testSubject.equals(testSubject);
191         Assert.assertEquals(true, result);
192
193         Resource testSubject2 = createTestSubject();
194         result = testSubject.equals(testSubject2);
195         Assert.assertEquals(true, result);
196     }
197
198     @Test
199     public void testToString() throws Exception {
200         Resource testSubject;
201         String result;
202
203         // default test
204         testSubject = createTestSubject();
205         result = testSubject.toString();
206     }
207
208     @Test
209     public void testGetToscaResourceName() throws Exception {
210         Resource testSubject;
211         String result;
212
213         // default test
214         testSubject = createTestSubject();
215         result = testSubject.getToscaResourceName();
216     }
217
218     @Test
219     public void testSetToscaResourceName() throws Exception {
220         Resource testSubject;
221         String toscaResourceName = "";
222
223         // default test
224         testSubject = createTestSubject();
225         testSubject.setToscaResourceName(toscaResourceName);
226     }
227
228     @Test
229     public void testGetResourceType() throws Exception {
230         Resource testSubject;
231         ResourceTypeEnum result;
232
233         // default test
234         testSubject = createTestSubject();
235         result = testSubject.getResourceType();
236     }
237
238     @Test
239     public void testSetResourceType() throws Exception {
240         Resource testSubject;
241         ResourceTypeEnum resourceType = null;
242
243         // default test
244         testSubject = createTestSubject();
245         testSubject.setResourceType(resourceType);
246     }
247
248     @Test
249     public void testSetVendorName() throws Exception {
250         Resource testSubject;
251         String vendorName = "";
252
253         // default test
254         testSubject = createTestSubject();
255         testSubject.setVendorName(vendorName);
256     }
257
258     @Test
259     public void testSetVendorRelease() throws Exception {
260         Resource testSubject;
261         String vendorRelease = "";
262
263         // default test
264         testSubject = createTestSubject();
265         testSubject.setVendorRelease(vendorRelease);
266     }
267
268     @Test
269     public void testSetResourceVendorModelNumber() throws Exception {
270         Resource testSubject;
271         String resourceVendorModelNumber = "";
272
273         // default test
274         testSubject = createTestSubject();
275         testSubject.setResourceVendorModelNumber(resourceVendorModelNumber);
276     }
277
278     @Test
279     public void testGetVendorName() throws Exception {
280         Resource testSubject;
281         String result;
282
283         // default test
284         testSubject = createTestSubject();
285         result = testSubject.getVendorName();
286     }
287
288     @Test
289     public void testGetVendorRelease() throws Exception {
290         Resource testSubject;
291         String result;
292
293         // default test
294         testSubject = createTestSubject();
295         result = testSubject.getVendorRelease();
296     }
297
298     @Test
299     public void testGetResourceVendorModelNumber() throws Exception {
300         Resource testSubject;
301         String result;
302
303         // default test
304         testSubject = createTestSubject();
305         result = testSubject.getResourceVendorModelNumber();
306     }
307
308     @Test
309     public void testFetchGenericTypeToscaNameFromConfigNoToscaTypesDefinedForCategories() throws Exception {
310         Resource testSubject = createTestSubject();
311         testSubject.addCategory("CategoryA", "SubCategoryB");
312
313         Configuration existingConfiguration = configurationManager.getConfiguration();
314         Configuration newConfiguration = new Configuration();
315         newConfiguration.setServiceNodeTypes(null);
316         Map<String, String> genericAssetNodeTypes = new HashMap<>();
317         genericAssetNodeTypes.put("VFC", "org.openecomp.resource.abstract.nodes.VFC");
318         newConfiguration.setGenericAssetNodeTypes(genericAssetNodeTypes);
319         configurationManager.setConfiguration(newConfiguration);
320
321         String result = testSubject.fetchGenericTypeToscaNameFromConfig();
322         assertEquals("org.openecomp.resource.abstract.nodes.VFC", result);
323         configurationManager.setConfiguration(existingConfiguration);
324     }
325
326     @Test
327     public void testFetchGenericTypeToscaNameFromConfigNoToscaTypeDefinedForRelevantCategory() throws Exception {
328         // default test
329         Resource testSubject = createTestSubject();
330         testSubject.addCategory("CategoryA", "SubCategoryC");
331         String result = testSubject.fetchGenericTypeToscaNameFromConfig();
332         assertEquals("org.openecomp.resource.abstract.nodes.VFC", result);
333     }
334
335     @Test
336     public void testFetchGenericTypeToscaNameFromConfigToscaTypeDefinedForCategory() throws Exception {
337         Resource testSubject = createTestSubject();
338         testSubject.addCategory("CategoryA", "SubCategoryB");
339         String result = testSubject.fetchGenericTypeToscaNameFromConfig();
340         assertEquals("org.openecomp.resource.abstract.nodes.B", result);
341     }
342
343     @Test
344     public void testAssetType() throws Exception {
345         Resource testSubject;
346         String result;
347
348         // default test
349         testSubject = createTestSubject();
350         result = testSubject.assetType();
351     }
352
353     @Test
354     public void testShouldGenerateInputs() throws Exception {
355         Resource testSubject;
356         boolean result;
357
358         // default test
359         testSubject = createTestSubject();
360         result = testSubject.shouldGenerateInputs();
361     }
362
363     @Test
364     public void testDeriveFromGeneric() throws Exception {
365         Resource testSubject;
366         boolean result;
367
368         // default test
369         testSubject = createTestSubject();
370         result = testSubject.deriveFromGeneric();
371     }
372
373     @Test
374     public void testGroupRelationsByInstanceName() throws Exception {
375         Resource testSubject;
376         Map<String, List<RequirementCapabilityRelDef>> result;
377
378         // default test
379         testSubject = createTestSubject();
380         Resource resource = new Resource();
381         resource.setComponentInstancesRelations(new LinkedList<RequirementCapabilityRelDef>());
382         result = testSubject.groupRelationsFromCsarByInstanceName(resource);
383     }
384
385 }