2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.model.operations.impl;
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.janusgraph.JanusGraphClient;
30 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
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;
45 import java.util.ArrayList;
46 import java.util.List;
49 import static org.junit.Assert.assertEquals;
50 import static org.junit.Assert.assertTrue;
52 @RunWith(SpringJUnit4ClassRunner.class)
53 @ContextConfiguration("classpath:application-context-test.xml")
54 public class ElementOperationTest extends ModelTestBase {
56 @javax.annotation.Resource(name = "element-operation")
57 private ElementOperation elementOperation;
59 @javax.annotation.Resource(name = "janusgraph-generic-dao")
60 private JanusGraphGenericDao janusGraphDao;
62 private static String CATEGORY = "category";
63 private static String SUBCATEGORY = "subcategory";
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(),
78 public void testGetArtifactsTypes() {
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());
90 artifactTypesCfg.remove(0);
91 allArtifactTypes = elementOperation.getAllArtifactTypes();
92 assertTrue(allArtifactTypes.isLeft());
93 assertEquals(artifactTypesCfg.size(), allArtifactTypes.left().value().size());
95 artifactTypesCfg.add("type5");
99 public void testAllDeploymentArtifactTypes() {
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());
114 public void testGetResourceAndServiceCategoty() {
115 String id = OperationTestsUtil.deleteAndCreateResourceCategory(CATEGORY, SUBCATEGORY, janusGraphDao);
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());
123 id = OperationTestsUtil.deleteAndCreateServiceCategory(CATEGORY, janusGraphDao);
125 res = elementOperation.getCategory(NodeTypeEnum.ServiceNewCategory, id);
126 assertTrue(res.isLeft());
127 categoryDefinition = (CategoryDefinition) res.left().value();
128 assertEquals(CATEGORY, categoryDefinition.getName());
131 private ElementOperation createTestSubject() {
132 return new ElementOperation(new JanusGraphGenericDao(new JanusGraphClient()));
137 public void testGetAllServiceCategories() throws Exception {
138 ElementOperation testSubject;
139 Either<List<CategoryDefinition>, ActionStatus> result;
142 testSubject = createTestSubject();
143 result = testSubject.getAllServiceCategories();
148 public void testGetAllResourceCategories() throws Exception {
149 ElementOperation testSubject;
150 Either<List<CategoryDefinition>, ActionStatus> result;
153 testSubject = createTestSubject();
154 result = testSubject.getAllResourceCategories();
159 public void testGetAllProductCategories() throws Exception {
160 ElementOperation testSubject;
161 Either<List<CategoryDefinition>, ActionStatus> result;
164 testSubject = createTestSubject();
165 result = testSubject.getAllProductCategories();
170 public void testCreateCategory() throws Exception {
171 ElementOperation testSubject;
172 CategoryDefinition category = new CategoryDefinition();
173 NodeTypeEnum nodeType = NodeTypeEnum.AdditionalInfoParameters;
174 Either<CategoryDefinition, ActionStatus> result;
177 testSubject = createTestSubject();
178 result = testSubject.createCategory(category, nodeType);
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;
191 testSubject = createTestSubject();
192 result = testSubject.createCategory(category, nodeType, inTransaction);
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;
205 testSubject = createTestSubject();
206 result = testSubject.createSubCategory(categoryId, subCategory, nodeType);
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;
220 testSubject = createTestSubject();
221 result = testSubject.createSubCategory(categoryId, subCategory, nodeType, inTransaction);
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;
234 testSubject = createTestSubject();
235 result = testSubject.createGrouping(subCategoryId, grouping, nodeType);
240 public void testGetAllCategories() throws Exception {
241 ElementOperation testSubject;
242 NodeTypeEnum nodeType = NodeTypeEnum.Capability;
243 boolean inTransaction = false;
244 Either<List<CategoryDefinition>, ActionStatus> result;
247 testSubject = createTestSubject();
248 result = testSubject.getAllCategories(nodeType, inTransaction);
260 public void testGetCategory() throws Exception {
261 ElementOperation testSubject;
262 NodeTypeEnum nodeType = NodeTypeEnum.CapabilityType;
263 String categoryId = "";
264 Either<CategoryDefinition, ActionStatus> result;
267 testSubject = createTestSubject();
268 result = testSubject.getCategory(nodeType, categoryId);
273 public void testGetSubCategory() throws Exception {
274 ElementOperation testSubject;
275 NodeTypeEnum nodeType = NodeTypeEnum.Group;
276 String subCategoryId = "";
277 Either<SubCategoryDefinition, ActionStatus> result;
280 testSubject = createTestSubject();
281 result = testSubject.getSubCategory(nodeType, subCategoryId);
286 public void testDeleteCategory() throws Exception {
287 ElementOperation testSubject;
288 NodeTypeEnum nodeType = NodeTypeEnum.getByName("resource");
289 String categoryId = "";
290 Either<CategoryDefinition, ActionStatus> result;
293 testSubject = createTestSubject();
294 result = testSubject.deleteCategory(nodeType, categoryId);
299 public void testDeleteSubCategory() throws Exception {
300 ElementOperation testSubject;
301 NodeTypeEnum nodeType = NodeTypeEnum.Attribute;
302 String subCategoryId = "";
303 Either<SubCategoryDefinition, ActionStatus> result;
306 testSubject = createTestSubject();
307 result = testSubject.deleteSubCategory(nodeType, subCategoryId);
312 public void testDeleteGrouping() throws Exception {
313 ElementOperation testSubject;
314 NodeTypeEnum nodeType = NodeTypeEnum.DataType;
315 String groupingId = "";
316 Either<GroupingDefinition, ActionStatus> result;
319 testSubject = createTestSubject();
320 result = testSubject.deleteGrouping(nodeType, groupingId);
325 public void testIsCategoryUniqueForType() throws Exception {
326 ElementOperation testSubject;
327 NodeTypeEnum nodeType = null;
328 String normalizedName = "";
329 Either<Boolean, ActionStatus> result;
332 testSubject = createTestSubject();
333 result = testSubject.isCategoryUniqueForType(nodeType, normalizedName);
338 public void testIsSubCategoryUniqueForCategory() throws Exception {
339 ElementOperation testSubject;
340 NodeTypeEnum nodeType = null;
341 String subCategoryNormName = "";
342 String parentCategoryId = "";
343 Either<Boolean, ActionStatus> result;
346 testSubject = createTestSubject();
347 result = testSubject.isSubCategoryUniqueForCategory(nodeType, subCategoryNormName, parentCategoryId);
352 public void testIsGroupingUniqueForSubCategory() throws Exception {
353 ElementOperation testSubject;
354 NodeTypeEnum nodeType = null;
355 String groupingNormName = "";
356 String parentSubCategoryId = "";
357 Either<Boolean, ActionStatus> result;
360 testSubject = createTestSubject();
361 result = testSubject.isGroupingUniqueForSubCategory(nodeType, groupingNormName, parentSubCategoryId);
366 public void testGetSubCategoryUniqueForType() throws Exception {
367 ElementOperation testSubject;
368 NodeTypeEnum nodeType = null;
369 String normalizedName = "";
370 Either<SubCategoryDefinition, ActionStatus> result;
373 testSubject = createTestSubject();
374 result = testSubject.getSubCategoryUniqueForType(nodeType, normalizedName);
379 public void testGetGroupingUniqueForType() throws Exception {
380 ElementOperation testSubject;
381 NodeTypeEnum nodeType = null;
382 String groupingNormalizedName = "";
383 Either<GroupingDefinition, ActionStatus> result;
386 testSubject = createTestSubject();
387 result = testSubject.getGroupingUniqueForType(nodeType, groupingNormalizedName);
392 public void testGetAllTags() throws Exception {
393 ElementOperation testSubject;
394 Either<List<Tag>, ActionStatus> result;
397 testSubject = createTestSubject();
398 result = testSubject.getAllTags();
403 public void testGetCategoryData() throws Exception {
404 ElementOperation testSubject;
406 NodeTypeEnum type = NodeTypeEnum.DataType;
407 Class<T> clazz = null;
408 Either<org.openecomp.sdc.be.resources.data.CategoryData, StorageOperationStatus> result;
411 testSubject = createTestSubject();
413 result = testSubject.getCategoryData(name, type, null);
416 testSubject = createTestSubject();
418 result = testSubject.getCategoryData(name, type, null);
426 public void testGetAllPropertyScopes() throws Exception {
427 ElementOperation testSubject;
428 Either<List<PropertyScope>, ActionStatus> result;
431 testSubject = createTestSubject();
432 result = testSubject.getAllPropertyScopes();
437 public void testGetAllArtifactTypes() throws Exception {
438 ElementOperation testSubject;
439 Either<List<ArtifactType>, ActionStatus> result;
442 testSubject = createTestSubject();
443 result = testSubject.getAllArtifactTypes();
448 public void testGetAllDeploymentArtifactTypes() throws Exception {
449 ElementOperation testSubject;
450 Either<Map<String, Object>, ActionStatus> result;
453 testSubject = createTestSubject();
454 result = testSubject.getAllDeploymentArtifactTypes();
459 public void testGetDefaultHeatTimeout() throws Exception {
460 ElementOperation testSubject;
461 Either<Integer, ActionStatus> result;
464 testSubject = createTestSubject();
465 result = testSubject.getDefaultHeatTimeout();
470 public void testGetResourceTypesMap() throws Exception {
471 ElementOperation testSubject;
472 Either<Map<String, String>, ActionStatus> result;
475 testSubject = createTestSubject();
476 result = testSubject.getResourceTypesMap();
481 public void testGetNewCategoryData() throws Exception {
482 ElementOperation testSubject;
484 NodeTypeEnum type = NodeTypeEnum.HeatParameter;
485 Class<T> clazz = null;
486 Either<CategoryData, StorageOperationStatus> result;
489 testSubject = createTestSubject();
491 result = testSubject.getNewCategoryData(name, type, null);
494 testSubject = createTestSubject();
496 result = testSubject.getNewCategoryData(name, type, null);