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