c70e41b2f16a970de336351fad08a835c25f7046
[sdc.git] /
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 com.thinkaurelius.titan.core.TitanGraph;
24 import com.thinkaurelius.titan.core.TitanVertex;
25 import fj.data.Either;
26 import org.junit.*;
27 import org.junit.rules.TestName;
28 import org.junit.runner.RunWith;
29 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
30 import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
31 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
32 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
33 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
34 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
35 import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
36 import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
37 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
38 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
39 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
40 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
41 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
42 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
43 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
44 import org.openecomp.sdc.be.model.LifecycleStateEnum;
45 import org.openecomp.sdc.be.model.ModelTestBase;
46 import org.openecomp.sdc.be.model.User;
47 import org.openecomp.sdc.be.model.catalog.CatalogComponent;
48 import org.openecomp.sdc.be.model.category.CategoryDefinition;
49 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
50 import org.openecomp.sdc.be.model.jsontitan.datamodel.NodeType;
51 import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
52 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
53 import org.openecomp.sdc.be.model.jsontitan.operations.NodeTypeOperation;
54 import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
55 import org.openecomp.sdc.be.model.jsontitan.operations.ToscaElementLifecycleOperation;
56 import org.openecomp.sdc.be.model.jsontitan.utils.GraphTestUtils;
57 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
58 import org.openecomp.sdc.common.util.ValidationUtils;
59 import org.springframework.test.context.ContextConfiguration;
60 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
61
62 import java.util.*;
63
64 import static org.junit.Assert.assertEquals;
65 import static org.junit.Assert.assertSame;
66 import static org.junit.Assert.assertTrue;
67
68 @RunWith(SpringJUnit4ClassRunner.class)
69 @ContextConfiguration("classpath:application-context-test.xml")
70 public class ToscaElementLifecycleOperationTest extends ModelTestBase {
71
72     @javax.annotation.Resource
73     protected TitanDao titanDao;
74
75     @javax.annotation.Resource
76     private NodeTypeOperation nodeTypeOperation;
77
78     @javax.annotation.Resource
79     private TopologyTemplateOperation topologyTemplateOperation;
80
81     @javax.annotation.Resource
82     private ToscaElementLifecycleOperation lifecycleOperation;
83
84     String categoryName = "category";
85     String subcategory = "mycategory";
86     String outputDirectory = "C:\\Output";
87
88     @Rule
89     public TestName name = new TestName();
90
91     @BeforeClass
92     public static void initLifecycleOperation() {
93         ModelTestBase.init();
94     }
95
96     private GraphVertex ownerVertex;
97     private GraphVertex modifierVertex;
98     private GraphVertex vfVertex;
99     private GraphVertex serviceVertex;
100     private GraphVertex rootVertex;
101
102     @Before
103     public void setupBefore() {
104         clearGraph();
105         createUsers();
106         createResourceCategory();
107         createServiceCategory();
108         GraphTestUtils.createRootCatalogVertex(titanDao);
109         rootVertex = createRootNodeType();
110         createNodeType("firstVf");
111         serviceVertex = createTopologyTemplate("firstService");
112     }
113
114     @Test
115     public void lifecycleTest() {
116         Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) vfVertex.getMetadataProperty(GraphPropertyEnum.STATE)), vfVertex.getUniqueId(), modifierVertex.getUniqueId(),
117                 ownerVertex.getUniqueId());
118         StorageOperationStatus status;
119
120         assertTrue(res.isLeft());
121         // 1-node type
122         // 2-vf
123         // 3- service
124         verifyInCatalogData(3, null);
125
126         String id = res.left().value().getUniqueId();
127
128         res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
129         assertTrue(res.isLeft());
130         id = res.left().value().getUniqueId();
131
132         verifyInCatalogData(3, null);
133
134         PropertyDataDefinition prop55 = new PropertyDataDefinition();
135         prop55.setName("prop55");
136         prop55.setDefaultValue("def55");
137
138         status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop55, JsonPresentationFields.NAME);
139         assertSame(status, StorageOperationStatus.OK);
140
141         CapabilityDataDefinition cap1 = new CapabilityDataDefinition();
142         cap1.setName("cap1");
143         cap1.setDescription("create");
144         cap1.setUniqueId(UniqueIdBuilder.buildCapabilityUid(id, "cap1"));
145
146         status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILITIES, cap1, JsonPresentationFields.NAME);
147         assertSame(status, StorageOperationStatus.OK);
148
149         res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
150         assertTrue(res.isLeft());
151         id = res.left().value().getUniqueId();
152
153         res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
154         assertTrue(res.isLeft());
155         id = res.left().value().getUniqueId();
156
157         prop55.setDefaultValue("AAAAAAAA");
158         status = nodeTypeOperation.updateToscaDataOfToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop55, JsonPresentationFields.NAME);
159         assertSame(status, StorageOperationStatus.OK);
160
161         cap1.setDescription("update");
162
163         status = nodeTypeOperation.updateToscaDataOfToscaElement(id, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILITIES, cap1, JsonPresentationFields.NAME);
164         assertSame(status, StorageOperationStatus.OK);
165
166         PropertyDataDefinition prop66 = new PropertyDataDefinition();
167         prop66.setName("prop66");
168         prop66.setDefaultValue("def66");
169
170         status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop66, JsonPresentationFields.NAME);
171         assertSame(status, StorageOperationStatus.OK);
172
173         res = lifecycleOperation.requestCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
174         assertTrue(res.isLeft());
175         id = res.left().value().getUniqueId();
176
177         res = lifecycleOperation.startCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
178         assertTrue(res.isLeft());
179         id = res.left().value().getUniqueId();
180
181         res = lifecycleOperation.certifyToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
182         assertTrue(res.isLeft());
183         id = res.left().value().getUniqueId();
184
185         verifyInCatalogData(3, null);
186
187         res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
188         assertTrue(res.isLeft());
189         id = res.left().value().getUniqueId();
190
191         verifyInCatalogData(4, null);
192
193         PropertyDataDefinition prop77 = new PropertyDataDefinition();
194         prop77.setName("prop77");
195         prop77.setDefaultValue("def77");
196
197         status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop77, JsonPresentationFields.NAME);
198         assertSame(status, StorageOperationStatus.OK);
199
200         res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
201         assertTrue(res.isLeft());
202         id = res.left().value().getUniqueId();
203
204         res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
205         assertTrue(res.isLeft());
206         id = res.left().value().getUniqueId();
207
208         PropertyDataDefinition prop88 = new PropertyDataDefinition();
209         prop88.setName("prop88");
210         prop88.setDefaultValue("def88");
211
212         status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop88, JsonPresentationFields.NAME);
213         assertSame(status, StorageOperationStatus.OK);
214
215         res = lifecycleOperation.requestCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
216         assertTrue(res.isLeft());
217         id = res.left().value().getUniqueId();
218
219         res = lifecycleOperation.startCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
220         assertTrue(res.isLeft());
221         id = res.left().value().getUniqueId();
222
223         res = lifecycleOperation.certifyToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
224         assertTrue(res.isLeft());
225         id = res.left().value().getUniqueId();
226         verifyInCatalogData(3, null);
227
228         res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
229         assertTrue(res.isLeft());
230         id = res.left().value().getUniqueId();
231
232         verifyInCatalogData(4, null);
233
234         PropertyDataDefinition prop99 = new PropertyDataDefinition();
235         prop99.setName("prop99");
236         prop99.setDefaultValue("def99");
237
238         status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop99, JsonPresentationFields.NAME);
239         assertSame(status, StorageOperationStatus.OK);
240
241         res = lifecycleOperation.requestCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
242         assertTrue(res.isLeft());
243         id = res.left().value().getUniqueId();
244
245         res = lifecycleOperation.startCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
246         assertTrue(res.isLeft());
247         id = res.left().value().getUniqueId();
248
249         status = nodeTypeOperation.deleteToscaDataElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, "prop99", JsonPresentationFields.NAME);
250         assertSame(status, StorageOperationStatus.OK);
251
252         // cancel certification
253         res = lifecycleOperation.cancelOrFailCertification(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId(), LifecycleStateEnum.READY_FOR_CERTIFICATION);
254         assertTrue(res.isLeft());
255         id = res.left().value().getUniqueId();
256
257         res = lifecycleOperation.startCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
258         assertTrue(res.isLeft());
259         id = res.left().value().getUniqueId();
260
261         // fail certification
262         res = lifecycleOperation.cancelOrFailCertification(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId(), LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
263         assertTrue(res.isLeft());
264         id = res.left().value().getUniqueId();
265         verifyInCatalogData(4, null);
266         // exportGraphMl(titanDao.getGraph().left().value());
267
268     }
269
270     @Test
271     public void serviceConformanceLevelTest() {
272         Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) serviceVertex.getMetadataProperty(GraphPropertyEnum.STATE)), serviceVertex.getUniqueId(),
273                 modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
274
275         assertTrue(res.isLeft());
276         String id = res.left().value().getUniqueId();
277
278         res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
279         assertTrue(res.isLeft());
280
281         String conformanceLevel = res.left().value().getMetadataValue(JsonPresentationFields.CONFORMANCE_LEVEL).toString();
282         assertEquals(conformanceLevel, ModelTestBase.configurationManager.getConfiguration().getToscaConformanceLevel());
283     }
284
285     @Test
286     public void catalogTest() {
287         // start position - 3 in catalog
288         List<String> expectedIds = new ArrayList<>();
289         expectedIds.add(rootVertex.getUniqueId());
290         expectedIds.add(vfVertex.getUniqueId());
291         expectedIds.add(serviceVertex.getUniqueId());
292
293         verifyInCatalogData(3, expectedIds);
294
295         GraphVertex vertex4 = createTopologyTemplate("topTemp4");
296         expectedIds.add(vertex4.getUniqueId());
297         verifyInCatalogData(4, expectedIds);
298
299         Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.undoCheckout(vertex4.getUniqueId());
300         expectedIds.remove(vertex4.getUniqueId());
301         verifyInCatalogData(3, expectedIds);
302
303         vertex4 = createTopologyTemplate("topTemp4");
304         expectedIds.add(vertex4.getUniqueId());
305         verifyInCatalogData(4, expectedIds);
306
307         res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) vertex4.getMetadataProperty(GraphPropertyEnum.STATE)), vertex4.getUniqueId(), modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
308         Either<ToscaElement, StorageOperationStatus> certifyToscaElement = lifecycleOperation.certifyToscaElement(vertex4.getUniqueId(), modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
309         assertTrue(certifyToscaElement.isLeft());
310         expectedIds.remove(vertex4.getUniqueId());
311         String certifiedId = certifyToscaElement.left().value().getUniqueId();
312         expectedIds.add(certifiedId);
313         verifyInCatalogData(4, expectedIds);
314
315         res = lifecycleOperation.checkoutToscaElement(certifiedId, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
316         assertTrue(certifyToscaElement.isLeft());
317         expectedIds.add(res.left().value().getUniqueId());
318         verifyInCatalogData(5, expectedIds);
319     }
320
321     @Test
322     public void testGetToscaElOwner_Fail(){
323         Either<User, StorageOperationStatus> result;
324         String toscaEleId = "toscaElementId";
325         titanDao.getVertexById(toscaEleId, JsonParseFlagEnum.NoParse);
326         result = lifecycleOperation.getToscaElementOwner(toscaEleId);
327         assertEquals(StorageOperationStatus.NOT_FOUND, result.right().value());
328     }
329
330     private void createResourceCategory() {
331
332         GraphVertex cat = new GraphVertex(VertexTypeEnum.RESOURCE_CATEGORY);
333         Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
334         String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.RESOURCE_CATEGORY);
335         cat.setUniqueId(catId);
336         metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, catId);
337         metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_CATEGORY.getName());
338         metadataProperties.put(GraphPropertyEnum.NAME, categoryName);
339         metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
340         cat.setMetadataProperties(metadataProperties);
341         cat.updateMetadataJsonWithCurrentMetadataProperties();
342
343         GraphVertex subCat = new GraphVertex(VertexTypeEnum.RESOURCE_SUBCATEGORY);
344         metadataProperties = new HashMap<>();
345         String subCatId = UniqueIdBuilder.buildSubCategoryUid(cat.getUniqueId(), subcategory);
346         subCat.setUniqueId(subCatId);
347         metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, subCatId);
348         metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_SUBCATEGORY.getName());
349         metadataProperties.put(GraphPropertyEnum.NAME, subcategory);
350         metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(subcategory));
351         subCat.setMetadataProperties(metadataProperties);
352         subCat.updateMetadataJsonWithCurrentMetadataProperties();
353
354         Either<GraphVertex, TitanOperationStatus> catRes = titanDao.createVertex(cat);
355
356         Either<GraphVertex, TitanOperationStatus> subCatRes = titanDao.createVertex(subCat);
357
358         TitanOperationStatus status = titanDao.createEdge(catRes.left().value().getVertex(), subCatRes.left().value().getVertex(), EdgeLabelEnum.SUB_CATEGORY, new HashMap<>());
359         assertEquals(TitanOperationStatus.OK, status);
360     }
361
362     private void createServiceCategory() {
363
364         GraphVertex cat = new GraphVertex(VertexTypeEnum.SERVICE_CATEGORY);
365         Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
366         String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
367         cat.setUniqueId(catId);
368         metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, catId);
369         metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.SERVICE_CATEGORY.getName());
370         metadataProperties.put(GraphPropertyEnum.NAME, categoryName);
371         metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
372         cat.setMetadataProperties(metadataProperties);
373         cat.updateMetadataJsonWithCurrentMetadataProperties();
374
375         Either<GraphVertex, TitanOperationStatus> catRes = titanDao.createVertex(cat);
376
377         assertTrue(catRes.isLeft());
378     }
379
380     private GraphVertex createTopologyTemplate(String name) {
381
382         TopologyTemplate service = new TopologyTemplate();
383         String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
384         service.setUniqueId(uniqueId);
385         service.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
386         service.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), name);
387         service.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
388         service.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "0.1");
389         service.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VF.name());
390         service.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(), ComponentTypeEnum.RESOURCE);
391         List<CategoryDefinition> categories = new ArrayList<>();
392         CategoryDefinition cat = new CategoryDefinition();
393         categories.add(cat);
394         cat.setName(categoryName);
395         service.setCategories(categories);
396
397         service.setComponentType(ComponentTypeEnum.SERVICE);
398         Either<TopologyTemplate, StorageOperationStatus> createRes = topologyTemplateOperation.createTopologyTemplate(service);
399         assertTrue(createRes.isLeft());
400
401         Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createRes.left().value().getUniqueId());
402         assertTrue(getNodeTyeRes.isLeft());
403
404         // serviceVertex = getNodeTyeRes.left().value();
405
406         return getNodeTyeRes.left().value();
407     }
408
409     private <T extends ToscaDataDefinition> NodeType createNodeType(String nodeTypeName) {
410
411         NodeType vf = new NodeType();
412         String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
413         vf.setUniqueId(uniqueId);
414         vf.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
415         vf.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), nodeTypeName);
416         vf.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
417         vf.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "0.1");
418         vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VF.name());
419         vf.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(), ComponentTypeEnum.RESOURCE);
420         List<CategoryDefinition> categories = new ArrayList<>();
421         CategoryDefinition cat = new CategoryDefinition();
422         categories.add(cat);
423         cat.setName(categoryName);
424         List<SubCategoryDefinition> subCategories = new ArrayList<>();
425         SubCategoryDefinition subCat = new SubCategoryDefinition();
426         subCat.setName(subcategory);
427         subCategories.add(subCat);
428         cat.setSubcategories(subCategories);
429         vf.setCategories(categories);
430
431         List<String> derivedFrom = new ArrayList<>();
432         derivedFrom.add("root");
433         vf.setDerivedFrom(derivedFrom);
434
435         vf.setComponentType(ComponentTypeEnum.RESOURCE);
436         Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
437         assertTrue(createVFRes.isLeft());
438
439         Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createVFRes.left().value().getUniqueId());
440         assertTrue(getNodeTyeRes.isLeft());
441
442         vfVertex = getNodeTyeRes.left().value();
443
444         List<PropertyDataDefinition> addProperties = new ArrayList<>();
445         PropertyDataDefinition prop11 = new PropertyDataDefinition();
446         prop11.setName("prop11");
447         prop11.setDefaultValue("def11");
448
449         addProperties.add(prop11);
450
451         PropertyDataDefinition prop22 = new PropertyDataDefinition();
452         prop22.setName("prop22");
453         prop22.setDefaultValue("def22");
454         addProperties.add(prop22);
455
456         StorageOperationStatus status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, addProperties, JsonPresentationFields.NAME);
457         assertSame(status, StorageOperationStatus.OK);
458
459         PropertyDataDefinition prop33 = new PropertyDataDefinition();
460         prop33.setName("prop33");
461         prop33.setDefaultValue("def33");
462
463         status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop33, JsonPresentationFields.NAME);
464         assertSame(status, StorageOperationStatus.OK);
465
466         PropertyDataDefinition prop44 = new PropertyDataDefinition();
467         prop44.setName("prop44");
468         prop44.setDefaultValue("def44");
469
470         status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop44, JsonPresentationFields.NAME);
471         assertSame(status, StorageOperationStatus.OK);
472
473         PropertyDataDefinition capProp = new PropertyDataDefinition();
474         capProp.setName("capProp");
475         capProp.setDefaultValue("capPropDef");
476
477         MapDataDefinition dataToCreate = new MapPropertiesDataDefinition();
478         dataToCreate.put("capProp", capProp);
479
480         Map<String, MapDataDefinition> capProps = new HashMap();
481         capProps.put("capName", dataToCreate);
482
483         Either<GraphVertex, StorageOperationStatus> res = nodeTypeOperation.associateElementToData(vfVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES, EdgeLabelEnum.CAPABILITIES_PROPERTIES, capProps);
484
485         // exportGraphMl(titanDao.getGraph().left().value());
486
487         List<String> pathKeys = new ArrayList<>();
488         pathKeys.add("capName");
489         capProp.setDefaultValue("BBBB");
490         status = nodeTypeOperation.updateToscaDataDeepElementOfToscaElement(vfVertex, EdgeLabelEnum.CAPABILITIES_PROPERTIES, VertexTypeEnum.CAPABILITIES_PROPERTIES, capProp, pathKeys, JsonPresentationFields.NAME);
491         return vf;
492     }
493
494     private GraphVertex createRootNodeType() {
495
496         NodeType vf = new NodeType();
497         String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
498         vf.setUniqueId(uniqueId);
499         vf.setComponentType(ComponentTypeEnum.RESOURCE);
500         vf.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
501         vf.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), "root");
502         vf.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
503         vf.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "1.0");
504         vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VFC.name());
505         vf.getMetadata().put(JsonPresentationFields.LIFECYCLE_STATE.getPresentation(), LifecycleStateEnum.CERTIFIED.name());
506         vf.getMetadata().put(JsonPresentationFields.TOSCA_RESOURCE_NAME.getPresentation(), "root");
507         vf.getMetadata().put(JsonPresentationFields.HIGHEST_VERSION.getPresentation(), true);
508
509         List<CategoryDefinition> categories = new ArrayList<>();
510         CategoryDefinition cat = new CategoryDefinition();
511         categories.add(cat);
512         cat.setName(categoryName);
513         List<SubCategoryDefinition> subCategories = new ArrayList<>();
514         SubCategoryDefinition subCat = new SubCategoryDefinition();
515         subCat.setName(subcategory);
516         subCategories.add(subCat);
517         cat.setSubcategories(subCategories);
518         vf.setCategories(categories);
519
520         List<String> derivedFrom = new ArrayList<>();
521         vf.setDerivedFrom(derivedFrom);
522
523         Map<String, PropertyDataDefinition> properties = new HashMap<>();
524         PropertyDataDefinition prop1 = new PropertyDataDefinition();
525         prop1.setName("derived1");
526         prop1.setDefaultValue("deriveddef1");
527
528         properties.put("derived1", prop1);
529
530         PropertyDataDefinition prop2 = new PropertyDataDefinition();
531         prop2.setUniqueId("derived2");
532         prop2.setName("deriveddef2");
533         properties.put("derived2", prop2);
534
535         PropertyDataDefinition prop3 = new PropertyDataDefinition();
536         prop3.setName("derived3");
537         prop3.setDefaultValue("deriveddef3");
538         properties.put("derived3", prop3);
539
540         vf.setProperties(properties);
541         vf.setComponentType(ComponentTypeEnum.RESOURCE);
542         Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
543         assertTrue(createVFRes.isLeft());
544
545         Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createVFRes.left().value().getUniqueId());
546         assertTrue(getNodeTyeRes.isLeft());
547         return getNodeTyeRes.left().value();
548     }
549
550     private void createUsers() {
551
552         GraphVertex ownerV = new GraphVertex(VertexTypeEnum.USER);
553         ownerV.setUniqueId("user1");
554
555         Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
556         metadataProperties.put(GraphPropertyEnum.USERID, ownerV.getUniqueId());
557         metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
558         metadataProperties.put(GraphPropertyEnum.NAME, "user1");
559         ownerV.setMetadataProperties(metadataProperties);
560         ownerV.updateMetadataJsonWithCurrentMetadataProperties();
561         ownerV.setJson(new HashMap<>());
562         Either<GraphVertex, TitanOperationStatus> createUserRes = titanDao.createVertex(ownerV);
563         assertTrue(createUserRes.isLeft());
564
565         ownerVertex = createUserRes.left().value();
566
567         GraphVertex modifierV = new GraphVertex(VertexTypeEnum.USER);
568         modifierV.setUniqueId("user2");
569
570         metadataProperties = new HashMap<>();
571         metadataProperties.put(GraphPropertyEnum.USERID, modifierV.getUniqueId());
572         metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
573         metadataProperties.put(GraphPropertyEnum.NAME, "user2");
574         modifierV.setMetadataProperties(metadataProperties);
575         modifierV.updateMetadataJsonWithCurrentMetadataProperties();
576         modifierV.setJson(new HashMap<>());
577         createUserRes = titanDao.createVertex(modifierV);
578         assertTrue(createUserRes.isLeft());
579
580         modifierVertex = createUserRes.left().value();
581
582         Either<GraphVertex, TitanOperationStatus> getOwnerRes = lifecycleOperation.findUser(ownerVertex.getUniqueId());
583         assertTrue(getOwnerRes.isLeft());
584
585     }
586
587     public void verifyInCatalogData(int expected, List<String> expectedIds) {
588
589         Either<List<CatalogComponent>, StorageOperationStatus> highestResourcesRes = topologyTemplateOperation.getElementCatalogData(true, null);
590         assertTrue(highestResourcesRes.isLeft());
591         List<CatalogComponent> highestResources = highestResourcesRes.left().value();
592         // calculate expected count value
593         assertEquals(expected, highestResources.stream().count());
594         if (expectedIds != null) {
595             highestResources.forEach(a -> assertTrue(expectedIds.contains(a.getUniqueId())));
596         }
597     }
598
599     @After
600     public void teardown() {
601         clearGraph();
602     }
603
604     private void clearGraph() {
605         Either<TitanGraph, TitanOperationStatus> graphResult = titanDao.getGraph();
606         TitanGraph graph = graphResult.left().value();
607
608         Iterable<TitanVertex> vertices = graph.query().vertices();
609         if (vertices != null) {
610             Iterator<TitanVertex> iterator = vertices.iterator();
611             while (iterator.hasNext()) {
612                 TitanVertex vertex = iterator.next();
613                 vertex.remove();
614             }
615         }
616         titanDao.commit();
617     }
618 }