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 static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
26 import java.util.ArrayList;
27 import java.util.List;
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;
51 import fj.data.Either;
53 @RunWith(SpringJUnit4ClassRunner.class)
54 @ContextConfiguration("classpath:application-context-test.xml")
55 public class ElementOperationTest extends ModelTestBase {
57 @javax.annotation.Resource(name = "element-operation")
58 private ElementOperation elementOperation;
60 @javax.annotation.Resource(name = "titan-generic-dao")
61 private TitanGenericDao titanDao;
63 private static String CATEGORY = "category";
64 private static String SUBCATEGORY = "subcategory";
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(),
79 public void testGetArtifactsTypes() {
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());
91 artifactTypesCfg.remove(0);
92 allArtifactTypes = elementOperation.getAllArtifactTypes();
93 assertTrue(allArtifactTypes.isLeft());
94 assertEquals(artifactTypesCfg.size(), allArtifactTypes.left().value().size());
96 artifactTypesCfg.add("type5");
100 public void testAllDeploymentArtifactTypes() {
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());
115 public void testGetResourceAndServiceCategoty() {
116 String id = OperationTestsUtil.deleteAndCreateResourceCategory(CATEGORY, SUBCATEGORY, titanDao);
118 Either<CategoryDefinition, ActionStatus> res = elementOperation.getCategory(NodeTypeEnum.ResourceNewCategory,
120 assertTrue(res.isLeft());
121 CategoryDefinition categoryDefinition = (CategoryDefinition) res.left().value();
122 assertEquals(CATEGORY, categoryDefinition.getName());
123 assertEquals(SUBCATEGORY, categoryDefinition.getSubcategories().get(0).getName());
125 id = OperationTestsUtil.deleteAndCreateServiceCategory(CATEGORY, titanDao);
127 res = elementOperation.getCategory(NodeTypeEnum.ServiceNewCategory, id);
128 assertTrue(res.isLeft());
129 categoryDefinition = (CategoryDefinition) res.left().value();
130 assertEquals(CATEGORY, categoryDefinition.getName());
133 private ElementOperation createTestSubject() {
134 return new ElementOperation(new TitanGenericDao(new TitanGraphClient()));
139 public void testGetAllServiceCategories() throws Exception {
140 ElementOperation testSubject;
141 Either<List<CategoryDefinition>, ActionStatus> result;
144 testSubject = createTestSubject();
145 result = testSubject.getAllServiceCategories();
150 public void testGetAllResourceCategories() throws Exception {
151 ElementOperation testSubject;
152 Either<List<CategoryDefinition>, ActionStatus> result;
155 testSubject = createTestSubject();
156 result = testSubject.getAllResourceCategories();
161 public void testGetAllProductCategories() throws Exception {
162 ElementOperation testSubject;
163 Either<List<CategoryDefinition>, ActionStatus> result;
166 testSubject = createTestSubject();
167 result = testSubject.getAllProductCategories();
172 public void testCreateCategory() throws Exception {
173 ElementOperation testSubject;
174 CategoryDefinition category = new CategoryDefinition();
175 NodeTypeEnum nodeType = NodeTypeEnum.AdditionalInfoParameters;
176 Either<CategoryDefinition, ActionStatus> result;
179 testSubject = createTestSubject();
180 result = testSubject.createCategory(category, nodeType);
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;
193 testSubject = createTestSubject();
194 result = testSubject.createCategory(category, nodeType, inTransaction);
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;
207 testSubject = createTestSubject();
208 result = testSubject.createSubCategory(categoryId, subCategory, nodeType);
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;
222 testSubject = createTestSubject();
223 result = testSubject.createSubCategory(categoryId, subCategory, nodeType, inTransaction);
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;
236 testSubject = createTestSubject();
237 result = testSubject.createGrouping(subCategoryId, grouping, nodeType);
242 public void testGetAllCategories() throws Exception {
243 ElementOperation testSubject;
244 NodeTypeEnum nodeType = NodeTypeEnum.Capability;
245 boolean inTransaction = false;
246 Either<List<CategoryDefinition>, ActionStatus> result;
249 testSubject = createTestSubject();
250 result = testSubject.getAllCategories(nodeType, inTransaction);
262 public void testGetCategory() throws Exception {
263 ElementOperation testSubject;
264 NodeTypeEnum nodeType = NodeTypeEnum.CapabilityType;
265 String categoryId = "";
266 Either<CategoryDefinition, ActionStatus> result;
269 testSubject = createTestSubject();
270 result = testSubject.getCategory(nodeType, categoryId);
275 public void testGetSubCategory() throws Exception {
276 ElementOperation testSubject;
277 NodeTypeEnum nodeType = NodeTypeEnum.Group;
278 String subCategoryId = "";
279 Either<SubCategoryDefinition, ActionStatus> result;
282 testSubject = createTestSubject();
283 result = testSubject.getSubCategory(nodeType, subCategoryId);
288 public void testDeleteCategory() throws Exception {
289 ElementOperation testSubject;
290 NodeTypeEnum nodeType = NodeTypeEnum.getByName("resource");
291 String categoryId = "";
292 Either<CategoryDefinition, ActionStatus> result;
295 testSubject = createTestSubject();
296 result = testSubject.deleteCategory(nodeType, categoryId);
301 public void testDeleteSubCategory() throws Exception {
302 ElementOperation testSubject;
303 NodeTypeEnum nodeType = NodeTypeEnum.Attribute;
304 String subCategoryId = "";
305 Either<SubCategoryDefinition, ActionStatus> result;
308 testSubject = createTestSubject();
309 result = testSubject.deleteSubCategory(nodeType, subCategoryId);
314 public void testDeleteGrouping() throws Exception {
315 ElementOperation testSubject;
316 NodeTypeEnum nodeType = NodeTypeEnum.DataType;
317 String groupingId = "";
318 Either<GroupingDefinition, ActionStatus> result;
321 testSubject = createTestSubject();
322 result = testSubject.deleteGrouping(nodeType, groupingId);
327 public void testIsCategoryUniqueForType() throws Exception {
328 ElementOperation testSubject;
329 NodeTypeEnum nodeType = null;
330 String normalizedName = "";
331 Either<Boolean, ActionStatus> result;
334 testSubject = createTestSubject();
335 result = testSubject.isCategoryUniqueForType(nodeType, normalizedName);
340 public void testIsSubCategoryUniqueForCategory() throws Exception {
341 ElementOperation testSubject;
342 NodeTypeEnum nodeType = null;
343 String subCategoryNormName = "";
344 String parentCategoryId = "";
345 Either<Boolean, ActionStatus> result;
348 testSubject = createTestSubject();
349 result = testSubject.isSubCategoryUniqueForCategory(nodeType, subCategoryNormName, parentCategoryId);
354 public void testIsGroupingUniqueForSubCategory() throws Exception {
355 ElementOperation testSubject;
356 NodeTypeEnum nodeType = null;
357 String groupingNormName = "";
358 String parentSubCategoryId = "";
359 Either<Boolean, ActionStatus> result;
362 testSubject = createTestSubject();
363 result = testSubject.isGroupingUniqueForSubCategory(nodeType, groupingNormName, parentSubCategoryId);
368 public void testGetSubCategoryUniqueForType() throws Exception {
369 ElementOperation testSubject;
370 NodeTypeEnum nodeType = null;
371 String normalizedName = "";
372 Either<SubCategoryDefinition, ActionStatus> result;
375 testSubject = createTestSubject();
376 result = testSubject.getSubCategoryUniqueForType(nodeType, normalizedName);
381 public void testGetGroupingUniqueForType() throws Exception {
382 ElementOperation testSubject;
383 NodeTypeEnum nodeType = null;
384 String groupingNormalizedName = "";
385 Either<GroupingDefinition, ActionStatus> result;
388 testSubject = createTestSubject();
389 result = testSubject.getGroupingUniqueForType(nodeType, groupingNormalizedName);
394 public void testGetAllTags() throws Exception {
395 ElementOperation testSubject;
396 Either<List<Tag>, ActionStatus> result;
399 testSubject = createTestSubject();
400 result = testSubject.getAllTags();
405 public void testGetCategoryData() throws Exception {
406 ElementOperation testSubject;
408 NodeTypeEnum type = NodeTypeEnum.DataType;
409 Class<T> clazz = null;
410 Either<org.openecomp.sdc.be.resources.data.CategoryData, StorageOperationStatus> result;
413 testSubject = createTestSubject();
415 result = testSubject.getCategoryData(name, type, null);
418 testSubject = createTestSubject();
420 result = testSubject.getCategoryData(name, type, null);
428 public void testGetAllPropertyScopes() throws Exception {
429 ElementOperation testSubject;
430 Either<List<PropertyScope>, ActionStatus> result;
433 testSubject = createTestSubject();
434 result = testSubject.getAllPropertyScopes();
439 public void testGetAllArtifactTypes() throws Exception {
440 ElementOperation testSubject;
441 Either<List<ArtifactType>, ActionStatus> result;
444 testSubject = createTestSubject();
445 result = testSubject.getAllArtifactTypes();
450 public void testGetAllDeploymentArtifactTypes() throws Exception {
451 ElementOperation testSubject;
452 Either<Map<String, Object>, ActionStatus> result;
455 testSubject = createTestSubject();
456 result = testSubject.getAllDeploymentArtifactTypes();
461 public void testGetDefaultHeatTimeout() throws Exception {
462 ElementOperation testSubject;
463 Either<Integer, ActionStatus> result;
466 testSubject = createTestSubject();
467 result = testSubject.getDefaultHeatTimeout();
472 public void testGetResourceTypesMap() throws Exception {
473 ElementOperation testSubject;
474 Either<Map<String, String>, ActionStatus> result;
477 testSubject = createTestSubject();
478 result = testSubject.getResourceTypesMap();
483 public void testGetNewCategoryData() throws Exception {
484 ElementOperation testSubject;
486 NodeTypeEnum type = NodeTypeEnum.HeatParameter;
487 Class<T> clazz = null;
488 Either<CategoryData, StorageOperationStatus> result;
491 testSubject = createTestSubject();
493 result = testSubject.getNewCategoryData(name, type, null);
496 testSubject = createTestSubject();
498 result = testSubject.getNewCategoryData(name, type, null);