Make Service base type optional
[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.Test;
30 import org.openecomp.sdc.be.config.Configuration;
31 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
32 import org.openecomp.sdc.be.unittests.utils.ModelConfDependentTest;
33
34 public class ResourceTest extends ModelConfDependentTest {
35
36     private Resource createTestSubject() {
37         return new Resource();
38     }
39
40     @Test
41     public void testCtor() throws Exception {
42         ComponentMetadataDefinition componentMetadataDefinition = new ResourceMetadataDefinition();
43         new Resource(componentMetadataDefinition);
44     }
45
46     @Test
47     public void testIsAbstract() throws Exception {
48         Resource testSubject;
49         Boolean result;
50
51         // default test
52         testSubject = createTestSubject();
53         result = testSubject.isAbstract();
54     }
55
56     @Test
57     public void testSetAbstract() throws Exception {
58         Resource testSubject;
59         Boolean isAbstract = null;
60
61         // default test
62         testSubject = createTestSubject();
63         testSubject.setAbstract(isAbstract);
64     }
65
66     @Test
67     public void testGetCost() throws Exception {
68         Resource testSubject;
69         String result;
70
71         // default test
72         testSubject = createTestSubject();
73         result = testSubject.getCost();
74     }
75
76     @Test
77     public void testSetCost() throws Exception {
78         Resource testSubject;
79         String cost = "";
80
81         // default test
82         testSubject = createTestSubject();
83         testSubject.setCost(cost);
84     }
85
86     @Test
87     public void testGetLicenseType() throws Exception {
88         Resource testSubject;
89         String result;
90
91         // default test
92         testSubject = createTestSubject();
93         result = testSubject.getLicenseType();
94     }
95
96     @Test
97     public void testSetLicenseType() throws Exception {
98         Resource testSubject;
99         String licenseType = "";
100
101         // default test
102         testSubject = createTestSubject();
103         testSubject.setLicenseType(licenseType);
104     }
105
106     @Test
107     public void testGetToscaResourceName() throws Exception {
108         Resource testSubject;
109         String result;
110
111         // default test
112         testSubject = createTestSubject();
113         result = testSubject.getToscaResourceName();
114     }
115
116     @Test
117     public void testSetToscaResourceName() throws Exception {
118         Resource testSubject;
119         String toscaResourceName = "";
120
121         // default test
122         testSubject = createTestSubject();
123         testSubject.setToscaResourceName(toscaResourceName);
124     }
125
126     @Test
127     public void testGetResourceType() throws Exception {
128         Resource testSubject;
129         ResourceTypeEnum result;
130
131         // default test
132         testSubject = createTestSubject();
133         result = testSubject.getResourceType();
134     }
135
136     @Test
137     public void testSetResourceType() throws Exception {
138         Resource testSubject;
139         ResourceTypeEnum resourceType = null;
140
141         // default test
142         testSubject = createTestSubject();
143         testSubject.setResourceType(resourceType);
144     }
145
146     @Test
147     public void testSetVendorName() throws Exception {
148         Resource testSubject;
149         String vendorName = "";
150
151         // default test
152         testSubject = createTestSubject();
153         testSubject.setVendorName(vendorName);
154     }
155
156     @Test
157     public void testSetVendorRelease() throws Exception {
158         Resource testSubject;
159         String vendorRelease = "";
160
161         // default test
162         testSubject = createTestSubject();
163         testSubject.setVendorRelease(vendorRelease);
164     }
165
166     @Test
167     public void testSetResourceVendorModelNumber() throws Exception {
168         Resource testSubject;
169         String resourceVendorModelNumber = "";
170
171         // default test
172         testSubject = createTestSubject();
173         testSubject.setResourceVendorModelNumber(resourceVendorModelNumber);
174     }
175
176     @Test
177     public void testGetVendorName() throws Exception {
178         Resource testSubject;
179         String result;
180
181         // default test
182         testSubject = createTestSubject();
183         result = testSubject.getVendorName();
184     }
185
186     @Test
187     public void testGetVendorRelease() throws Exception {
188         Resource testSubject;
189         String result;
190
191         // default test
192         testSubject = createTestSubject();
193         result = testSubject.getVendorRelease();
194     }
195
196     @Test
197     public void testGetResourceVendorModelNumber() throws Exception {
198         Resource testSubject;
199         String result;
200
201         // default test
202         testSubject = createTestSubject();
203         result = testSubject.getResourceVendorModelNumber();
204     }
205
206     @Test
207     public void testFetchGenericTypeToscaNameFromConfigNoToscaTypesDefinedForCategories() throws Exception {
208         Resource testSubject = createTestSubject();
209         testSubject.addCategory("CategoryA", "SubCategoryB");
210
211         Configuration existingConfiguration = configurationManager.getConfiguration();
212         Configuration newConfiguration = new Configuration();
213         newConfiguration.setServiceBaseNodeTypes(null);
214         Map<String, String> genericAssetNodeTypes = new HashMap<>();
215         genericAssetNodeTypes.put("VFC", "org.openecomp.resource.abstract.nodes.VFC");
216         newConfiguration.setGenericAssetNodeTypes(genericAssetNodeTypes);
217         configurationManager.setConfiguration(newConfiguration);
218
219         String result = testSubject.fetchGenericTypeToscaNameFromConfig();
220         assertEquals("org.openecomp.resource.abstract.nodes.VFC", result);
221         configurationManager.setConfiguration(existingConfiguration);
222     }
223
224     @Test
225     public void testFetchGenericTypeToscaNameFromConfigNoToscaTypeDefinedForRelevantCategory() throws Exception {
226         // default test
227         Resource testSubject = createTestSubject();
228         testSubject.addCategory("CategoryA", "SubCategoryC");
229         String result = testSubject.fetchGenericTypeToscaNameFromConfig();
230         assertEquals("org.openecomp.resource.abstract.nodes.VFC", result);
231     }
232
233     @Test
234     public void testFetchGenericTypeToscaNameFromConfigToscaTypeDefinedForCategory() throws Exception {
235         Resource testSubject = createTestSubject();
236         testSubject.addCategory("CategoryA", "SubCategoryB");
237         String result = testSubject.fetchGenericTypeToscaNameFromConfig();
238         assertEquals("org.openecomp.resource.abstract.nodes.B", result);
239     }
240
241     @Test
242     public void testAssetType() throws Exception {
243         Resource testSubject;
244         String result;
245
246         // default test
247         testSubject = createTestSubject();
248         result = testSubject.assetType();
249     }
250
251     @Test
252     public void testShouldGenerateInputs() throws Exception {
253         Resource testSubject;
254         boolean result;
255
256         // default test
257         testSubject = createTestSubject();
258         result = testSubject.shouldGenerateInputs();
259     }
260
261     @Test
262     public void testDeriveFromGeneric() throws Exception {
263         Resource testSubject;
264         boolean result;
265
266         // default test
267         testSubject = createTestSubject();
268         result = testSubject.deriveFromGeneric();
269     }
270
271     @Test
272     public void testGroupRelationsByInstanceName() throws Exception {
273         Resource testSubject;
274         Map<String, List<RequirementCapabilityRelDef>> result;
275
276         // default test
277         testSubject = createTestSubject();
278         Resource resource = new Resource();
279         resource.setComponentInstancesRelations(new LinkedList<RequirementCapabilityRelDef>());
280         result = testSubject.groupRelationsFromCsarByInstanceName(resource);
281     }
282
283 }