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