new unit tests for sdc-model
[sdc.git] / catalog-model / src / test / java / org / openecomp / sdc / be / model / operations / impl / ElementOperationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 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.operations.impl;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
25
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.Map;
29
30 import org.apache.tinkerpop.gremlin.structure.T;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.openecomp.sdc.be.dao.api.ActionStatus;
35 import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
36 import org.openecomp.sdc.be.dao.titan.TitanGraphClient;
37 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
38 import org.openecomp.sdc.be.model.ArtifactType;
39 import org.openecomp.sdc.be.model.ModelTestBase;
40 import org.openecomp.sdc.be.model.PropertyScope;
41 import org.openecomp.sdc.be.model.Tag;
42 import org.openecomp.sdc.be.model.category.CategoryDefinition;
43 import org.openecomp.sdc.be.model.category.GroupingDefinition;
44 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
45 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
46 import org.openecomp.sdc.be.model.operations.impl.util.OperationTestsUtil;
47 import org.openecomp.sdc.be.resources.data.category.CategoryData;
48 import org.springframework.test.context.ContextConfiguration;
49 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
50
51 import fj.data.Either;
52
53 @RunWith(SpringJUnit4ClassRunner.class)
54 @ContextConfiguration("classpath:application-context-test.xml")
55 public class ElementOperationTest extends ModelTestBase {
56
57         @javax.annotation.Resource(name = "element-operation")
58         private ElementOperation elementOperation;
59
60         @javax.annotation.Resource(name = "titan-generic-dao")
61         private TitanGenericDao titanDao;
62
63         private static String CATEGORY = "category";
64         private static String SUBCATEGORY = "subcategory";
65
66         @BeforeClass
67         public static void setupBeforeClass() {
68                 // ExternalConfiguration.setAppName("catalog-model");
69                 // String appConfigDir = "src/test/resources/config/catalog-model";
70                 // ConfigurationSource configurationSource = new
71                 // FSConfigurationSource(ExternalConfiguration.getChangeListener(),
72                 // appConfigDir);
73
74                 ModelTestBase.init();
75
76         }
77
78         @Test
79         public void testGetArtifactsTypes() {
80
81                 List<String> artifactTypesCfg = new ArrayList<String>();
82                 artifactTypesCfg.add("type1");
83                 artifactTypesCfg.add("type2");
84                 artifactTypesCfg.add("type3");
85                 artifactTypesCfg.add("type4");
86                 configurationManager.getConfiguration().setArtifactTypes(artifactTypesCfg);
87                 Either<List<ArtifactType>, ActionStatus> allArtifactTypes = elementOperation.getAllArtifactTypes();
88                 assertTrue(allArtifactTypes.isLeft());
89                 assertEquals(artifactTypesCfg.size(), allArtifactTypes.left().value().size());
90
91                 artifactTypesCfg.remove(0);
92                 allArtifactTypes = elementOperation.getAllArtifactTypes();
93                 assertTrue(allArtifactTypes.isLeft());
94                 assertEquals(artifactTypesCfg.size(), allArtifactTypes.left().value().size());
95
96                 artifactTypesCfg.add("type5");
97         }
98
99         @Test
100         public void testAllDeploymentArtifactTypes() {
101
102                 List<String> artifactTypesCfg = new ArrayList<String>();
103                 artifactTypesCfg.add("type1");
104                 artifactTypesCfg.add("type2");
105                 artifactTypesCfg.add("type3");
106                 configurationManager.getConfiguration().setArtifactTypes(artifactTypesCfg);
107                 Either<Map<String, Object>, ActionStatus> allDeploymentArtifactTypes = elementOperation
108                                 .getAllDeploymentArtifactTypes();
109                 assertTrue(allDeploymentArtifactTypes.isLeft());
110                 assertEquals(artifactTypesCfg.size(), allDeploymentArtifactTypes.left().value().size());
111
112         }
113
114         // @Test
115         public void testGetResourceAndServiceCategoty() {
116                 String id = OperationTestsUtil.deleteAndCreateResourceCategory(CATEGORY, SUBCATEGORY, titanDao);
117
118                 Either<CategoryDefinition, ActionStatus> res = elementOperation.getCategory(NodeTypeEnum.ResourceNewCategory,
119                                 id);
120                 assertTrue(res.isLeft());
121                 CategoryDefinition categoryDefinition = (CategoryDefinition) res.left().value();
122                 assertEquals(CATEGORY, categoryDefinition.getName());
123                 assertEquals(SUBCATEGORY, categoryDefinition.getSubcategories().get(0).getName());
124
125                 id = OperationTestsUtil.deleteAndCreateServiceCategory(CATEGORY, titanDao);
126
127                 res = elementOperation.getCategory(NodeTypeEnum.ServiceNewCategory, id);
128                 assertTrue(res.isLeft());
129                 categoryDefinition = (CategoryDefinition) res.left().value();
130                 assertEquals(CATEGORY, categoryDefinition.getName());
131         }
132
133         private ElementOperation createTestSubject() {
134                 return new ElementOperation(new TitanGenericDao(new TitanGraphClient()));
135         }
136
137         
138         @Test
139         public void testGetAllServiceCategories() throws Exception {
140                 ElementOperation testSubject;
141                 Either<List<CategoryDefinition>, ActionStatus> result;
142
143                 // default test
144                 testSubject = createTestSubject();
145                 result = testSubject.getAllServiceCategories();
146         }
147
148         
149         @Test
150         public void testGetAllResourceCategories() throws Exception {
151                 ElementOperation testSubject;
152                 Either<List<CategoryDefinition>, ActionStatus> result;
153
154                 // default test
155                 testSubject = createTestSubject();
156                 result = testSubject.getAllResourceCategories();
157         }
158
159         
160         @Test
161         public void testGetAllProductCategories() throws Exception {
162                 ElementOperation testSubject;
163                 Either<List<CategoryDefinition>, ActionStatus> result;
164
165                 // default test
166                 testSubject = createTestSubject();
167                 result = testSubject.getAllProductCategories();
168         }
169
170         
171         @Test
172         public void testCreateCategory() throws Exception {
173                 ElementOperation testSubject;
174                 CategoryDefinition category = new CategoryDefinition();
175                 NodeTypeEnum nodeType = NodeTypeEnum.AdditionalInfoParameters;
176                 Either<CategoryDefinition, ActionStatus> result;
177
178                 // default test
179                 testSubject = createTestSubject();
180                 result = testSubject.createCategory(category, nodeType);
181         }
182
183         
184         @Test
185         public void testCreateCategory_1() throws Exception {
186                 ElementOperation testSubject;
187                 CategoryDefinition category = new CategoryDefinition();
188                 NodeTypeEnum nodeType = NodeTypeEnum.ArtifactRef;
189                 boolean inTransaction = false;
190                 Either<CategoryDefinition, ActionStatus> result;
191
192                 // default test
193                 testSubject = createTestSubject();
194                 result = testSubject.createCategory(category, nodeType, inTransaction);
195         }
196
197         
198         @Test
199         public void testCreateSubCategory() throws Exception {
200                 ElementOperation testSubject;
201                 String categoryId = "";
202                 SubCategoryDefinition subCategory = null;
203                 NodeTypeEnum nodeType = null;
204                 Either<SubCategoryDefinition, ActionStatus> result;
205
206                 // default test
207                 testSubject = createTestSubject();
208                 result = testSubject.createSubCategory(categoryId, subCategory, nodeType);
209         }
210
211         
212         @Test
213         public void testCreateSubCategory_1() throws Exception {
214                 ElementOperation testSubject;
215                 String categoryId = "";
216                 SubCategoryDefinition subCategory = null;
217                 NodeTypeEnum nodeType = null;
218                 boolean inTransaction = false;
219                 Either<SubCategoryDefinition, ActionStatus> result;
220
221                 // default test
222                 testSubject = createTestSubject();
223                 result = testSubject.createSubCategory(categoryId, subCategory, nodeType, inTransaction);
224         }
225
226         
227         @Test
228         public void testCreateGrouping() throws Exception {
229                 ElementOperation testSubject;
230                 String subCategoryId = "";
231                 GroupingDefinition grouping = null;
232                 NodeTypeEnum nodeType = null;
233                 Either<GroupingDefinition, ActionStatus> result;
234
235                 // default test
236                 testSubject = createTestSubject();
237                 result = testSubject.createGrouping(subCategoryId, grouping, nodeType);
238         }
239
240         
241         @Test
242         public void testGetAllCategories() throws Exception {
243                 ElementOperation testSubject;
244                 NodeTypeEnum nodeType = NodeTypeEnum.Capability;
245                 boolean inTransaction = false;
246                 Either<List<CategoryDefinition>, ActionStatus> result;
247
248                 // default test
249                 testSubject = createTestSubject();
250                 result = testSubject.getAllCategories(nodeType, inTransaction);
251         }
252
253         
254
255
256         
257
258         
259         
260         
261         @Test
262         public void testGetCategory() throws Exception {
263                 ElementOperation testSubject;
264                 NodeTypeEnum nodeType = NodeTypeEnum.CapabilityType;
265                 String categoryId = "";
266                 Either<CategoryDefinition, ActionStatus> result;
267
268                 // default test
269                 testSubject = createTestSubject();
270                 result = testSubject.getCategory(nodeType, categoryId);
271         }
272
273         
274         @Test
275         public void testGetSubCategory() throws Exception {
276                 ElementOperation testSubject;
277                 NodeTypeEnum nodeType = NodeTypeEnum.Group;
278                 String subCategoryId = "";
279                 Either<SubCategoryDefinition, ActionStatus> result;
280
281                 // default test
282                 testSubject = createTestSubject();
283                 result = testSubject.getSubCategory(nodeType, subCategoryId);
284         }
285
286         
287         @Test
288         public void testDeleteCategory() throws Exception {
289                 ElementOperation testSubject;
290                 NodeTypeEnum nodeType = NodeTypeEnum.getByName("resource");
291                 String categoryId = "";
292                 Either<CategoryDefinition, ActionStatus> result;
293
294                 // default test
295                 testSubject = createTestSubject();
296                 result = testSubject.deleteCategory(nodeType, categoryId);
297         }
298
299         
300         @Test
301         public void testDeleteSubCategory() throws Exception {
302                 ElementOperation testSubject;
303                 NodeTypeEnum nodeType = NodeTypeEnum.Attribute;
304                 String subCategoryId = "";
305                 Either<SubCategoryDefinition, ActionStatus> result;
306
307                 // default test
308                 testSubject = createTestSubject();
309                 result = testSubject.deleteSubCategory(nodeType, subCategoryId);
310         }
311
312         
313         @Test
314         public void testDeleteGrouping() throws Exception {
315                 ElementOperation testSubject;
316                 NodeTypeEnum nodeType = NodeTypeEnum.DataType;
317                 String groupingId = "";
318                 Either<GroupingDefinition, ActionStatus> result;
319
320                 // default test
321                 testSubject = createTestSubject();
322                 result = testSubject.deleteGrouping(nodeType, groupingId);
323         }
324
325         
326         @Test
327         public void testIsCategoryUniqueForType() throws Exception {
328                 ElementOperation testSubject;
329                 NodeTypeEnum nodeType = null;
330                 String normalizedName = "";
331                 Either<Boolean, ActionStatus> result;
332
333                 // default test
334                 testSubject = createTestSubject();
335                 result = testSubject.isCategoryUniqueForType(nodeType, normalizedName);
336         }
337
338         
339         @Test
340         public void testIsSubCategoryUniqueForCategory() throws Exception {
341                 ElementOperation testSubject;
342                 NodeTypeEnum nodeType = null;
343                 String subCategoryNormName = "";
344                 String parentCategoryId = "";
345                 Either<Boolean, ActionStatus> result;
346
347                 // default test
348                 testSubject = createTestSubject();
349                 result = testSubject.isSubCategoryUniqueForCategory(nodeType, subCategoryNormName, parentCategoryId);
350         }
351
352         
353         @Test
354         public void testIsGroupingUniqueForSubCategory() throws Exception {
355                 ElementOperation testSubject;
356                 NodeTypeEnum nodeType = null;
357                 String groupingNormName = "";
358                 String parentSubCategoryId = "";
359                 Either<Boolean, ActionStatus> result;
360
361                 // default test
362                 testSubject = createTestSubject();
363                 result = testSubject.isGroupingUniqueForSubCategory(nodeType, groupingNormName, parentSubCategoryId);
364         }
365
366         
367         @Test
368         public void testGetSubCategoryUniqueForType() throws Exception {
369                 ElementOperation testSubject;
370                 NodeTypeEnum nodeType = null;
371                 String normalizedName = "";
372                 Either<SubCategoryDefinition, ActionStatus> result;
373
374                 // default test
375                 testSubject = createTestSubject();
376                 result = testSubject.getSubCategoryUniqueForType(nodeType, normalizedName);
377         }
378
379         
380         @Test
381         public void testGetGroupingUniqueForType() throws Exception {
382                 ElementOperation testSubject;
383                 NodeTypeEnum nodeType = null;
384                 String groupingNormalizedName = "";
385                 Either<GroupingDefinition, ActionStatus> result;
386
387                 // default test
388                 testSubject = createTestSubject();
389                 result = testSubject.getGroupingUniqueForType(nodeType, groupingNormalizedName);
390         }
391
392         
393         @Test
394         public void testGetAllTags() throws Exception {
395                 ElementOperation testSubject;
396                 Either<List<Tag>, ActionStatus> result;
397
398                 // default test
399                 testSubject = createTestSubject();
400                 result = testSubject.getAllTags();
401         }
402
403         
404         @Test
405         public void testGetCategoryData() throws Exception {
406                 ElementOperation testSubject;
407                 String name = "";
408                 NodeTypeEnum type = NodeTypeEnum.DataType;
409                 Class<T> clazz = null;
410                 Either<org.openecomp.sdc.be.resources.data.CategoryData, StorageOperationStatus> result;
411
412                 // test 1
413                 testSubject = createTestSubject();
414                 name = null;
415                 result = testSubject.getCategoryData(name, type, null);
416
417                 // test 2
418                 testSubject = createTestSubject();
419                 name = "";
420                 result = testSubject.getCategoryData(name, type, null);
421         }
422
423         
424
425
426         
427         @Test
428         public void testGetAllPropertyScopes() throws Exception {
429                 ElementOperation testSubject;
430                 Either<List<PropertyScope>, ActionStatus> result;
431
432                 // default test
433                 testSubject = createTestSubject();
434                 result = testSubject.getAllPropertyScopes();
435         }
436
437         
438         @Test
439         public void testGetAllArtifactTypes() throws Exception {
440                 ElementOperation testSubject;
441                 Either<List<ArtifactType>, ActionStatus> result;
442
443                 // default test
444                 testSubject = createTestSubject();
445                 result = testSubject.getAllArtifactTypes();
446         }
447
448         
449         @Test
450         public void testGetAllDeploymentArtifactTypes() throws Exception {
451                 ElementOperation testSubject;
452                 Either<Map<String, Object>, ActionStatus> result;
453
454                 // default test
455                 testSubject = createTestSubject();
456                 result = testSubject.getAllDeploymentArtifactTypes();
457         }
458
459         
460         @Test
461         public void testGetDefaultHeatTimeout() throws Exception {
462                 ElementOperation testSubject;
463                 Either<Integer, ActionStatus> result;
464
465                 // default test
466                 testSubject = createTestSubject();
467                 result = testSubject.getDefaultHeatTimeout();
468         }
469
470         
471         @Test
472         public void testGetResourceTypesMap() throws Exception {
473                 ElementOperation testSubject;
474                 Either<Map<String, String>, ActionStatus> result;
475
476                 // default test
477                 testSubject = createTestSubject();
478                 result = testSubject.getResourceTypesMap();
479         }
480
481         
482         @Test
483         public void testGetNewCategoryData() throws Exception {
484                 ElementOperation testSubject;
485                 String name = "";
486                 NodeTypeEnum type = NodeTypeEnum.HeatParameter;
487                 Class<T> clazz = null;
488                 Either<CategoryData, StorageOperationStatus> result;
489
490                 // test 1
491                 testSubject = createTestSubject();
492                 name = null;
493                 result = testSubject.getNewCategoryData(name, type, null);
494
495                 // test 2
496                 testSubject = createTestSubject();
497                 name = "";
498                 result = testSubject.getNewCategoryData(name, type, null);
499         }
500 }