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 com.thinkaurelius.titan.core.TitanGraph;
24 import com.thinkaurelius.titan.core.TitanVertex;
25 import fj.data.Either;
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.VertexTypeEnum;
33 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
34 import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
35 import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
36 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
37 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
38 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
39 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
40 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
41 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
42 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
43 import org.openecomp.sdc.be.model.LifecycleStateEnum;
44 import org.openecomp.sdc.be.model.ModelTestBase;
45 import org.openecomp.sdc.be.model.catalog.CatalogComponent;
46 import org.openecomp.sdc.be.model.category.CategoryDefinition;
47 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
48 import org.openecomp.sdc.be.model.jsontitan.datamodel.NodeType;
49 import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
50 import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
51 import org.openecomp.sdc.be.model.jsontitan.operations.NodeTypeOperation;
52 import org.openecomp.sdc.be.model.jsontitan.operations.TopologyTemplateOperation;
53 import org.openecomp.sdc.be.model.jsontitan.operations.ToscaElementLifecycleOperation;
54 import org.openecomp.sdc.be.model.jsontitan.utils.GraphTestUtils;
55 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
56 import org.openecomp.sdc.common.util.ValidationUtils;
57 import org.springframework.test.context.ContextConfiguration;
58 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
60 import java.io.BufferedOutputStream;
62 import java.io.FileOutputStream;
63 import java.io.OutputStream;
66 import static org.junit.Assert.assertEquals;
67 import static org.junit.Assert.assertSame;
68 import static org.junit.Assert.assertTrue;
70 @RunWith(SpringJUnit4ClassRunner.class)
71 @ContextConfiguration("classpath:application-context-test.xml")
72 public class ToscaElementLifecycleOperationTest extends ModelTestBase {
74 @javax.annotation.Resource
75 protected TitanDao titanDao;
77 @javax.annotation.Resource
78 private NodeTypeOperation nodeTypeOperation;
80 @javax.annotation.Resource
81 private TopologyTemplateOperation topologyTemplateOperation;
83 @javax.annotation.Resource
84 private ToscaElementLifecycleOperation lifecycleOperation;
86 String categoryName = "category";
87 String subcategory = "mycategory";
88 String outputDirectory = "C:\\Output";
91 public TestName name = new TestName();
94 public static void initLifecycleOperation() {
98 private GraphVertex ownerVertex;
99 private GraphVertex modifierVertex;
100 private GraphVertex vfVertex;
101 private GraphVertex serviceVertex;
102 private GraphVertex rootVertex;
105 public void setupBefore() {
108 createResourceCategory();
109 createServiceCategory();
110 GraphTestUtils.createRootCatalogVertex(titanDao);
111 rootVertex = createRootNodeType();
112 createNodeType("firstVf");
113 serviceVertex = createTopologyTemplate("firstService");
117 public void lifecycleTest() {
118 Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) vfVertex.getMetadataProperty(GraphPropertyEnum.STATE)), vfVertex.getUniqueId(), modifierVertex.getUniqueId(),
119 ownerVertex.getUniqueId());
120 StorageOperationStatus status;
122 assertTrue(res.isLeft());
126 verifyInCatalogData(3, null);
128 String id = res.left().value().getUniqueId();
130 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
131 assertTrue(res.isLeft());
132 id = res.left().value().getUniqueId();
134 verifyInCatalogData(3, null);
136 PropertyDataDefinition prop55 = new PropertyDataDefinition();
137 prop55.setName("prop55");
138 prop55.setDefaultValue("def55");
140 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop55, JsonPresentationFields.NAME);
141 assertSame(status, StorageOperationStatus.OK);
143 CapabilityDataDefinition cap1 = new CapabilityDataDefinition();
144 cap1.setName("cap1");
145 cap1.setDescription("create");
146 cap1.setUniqueId(UniqueIdBuilder.buildCapabilityUid(id, "cap1"));
148 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILTIES, cap1, JsonPresentationFields.NAME);
149 assertSame(status, StorageOperationStatus.OK);
151 res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
152 assertTrue(res.isLeft());
153 id = res.left().value().getUniqueId();
155 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
156 assertTrue(res.isLeft());
157 id = res.left().value().getUniqueId();
159 prop55.setDefaultValue("AAAAAAAA");
160 status = nodeTypeOperation.updateToscaDataOfToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop55, JsonPresentationFields.NAME);
161 assertSame(status, StorageOperationStatus.OK);
163 cap1.setDescription("update");
165 status = nodeTypeOperation.updateToscaDataOfToscaElement(id, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILTIES, cap1, JsonPresentationFields.NAME);
166 assertSame(status, StorageOperationStatus.OK);
168 PropertyDataDefinition prop66 = new PropertyDataDefinition();
169 prop66.setName("prop66");
170 prop66.setDefaultValue("def66");
172 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop66, JsonPresentationFields.NAME);
173 assertSame(status, StorageOperationStatus.OK);
175 res = lifecycleOperation.requestCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
176 assertTrue(res.isLeft());
177 id = res.left().value().getUniqueId();
179 res = lifecycleOperation.startCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
180 assertTrue(res.isLeft());
181 id = res.left().value().getUniqueId();
183 res = lifecycleOperation.certifyToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
184 assertTrue(res.isLeft());
185 id = res.left().value().getUniqueId();
187 verifyInCatalogData(3, null);
189 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
190 assertTrue(res.isLeft());
191 id = res.left().value().getUniqueId();
193 verifyInCatalogData(4, null);
195 PropertyDataDefinition prop77 = new PropertyDataDefinition();
196 prop77.setName("prop77");
197 prop77.setDefaultValue("def77");
199 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop77, JsonPresentationFields.NAME);
200 assertSame(status, StorageOperationStatus.OK);
202 res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
203 assertTrue(res.isLeft());
204 id = res.left().value().getUniqueId();
206 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
207 assertTrue(res.isLeft());
208 id = res.left().value().getUniqueId();
210 PropertyDataDefinition prop88 = new PropertyDataDefinition();
211 prop88.setName("prop88");
212 prop88.setDefaultValue("def88");
214 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop88, JsonPresentationFields.NAME);
215 assertSame(status, StorageOperationStatus.OK);
217 res = lifecycleOperation.requestCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
218 assertTrue(res.isLeft());
219 id = res.left().value().getUniqueId();
221 res = lifecycleOperation.startCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
222 assertTrue(res.isLeft());
223 id = res.left().value().getUniqueId();
225 res = lifecycleOperation.certifyToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
226 assertTrue(res.isLeft());
227 id = res.left().value().getUniqueId();
228 verifyInCatalogData(3, null);
230 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
231 assertTrue(res.isLeft());
232 id = res.left().value().getUniqueId();
234 verifyInCatalogData(4, null);
236 PropertyDataDefinition prop99 = new PropertyDataDefinition();
237 prop99.setName("prop99");
238 prop99.setDefaultValue("def99");
240 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop99, JsonPresentationFields.NAME);
241 assertSame(status, StorageOperationStatus.OK);
243 res = lifecycleOperation.requestCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
244 assertTrue(res.isLeft());
245 id = res.left().value().getUniqueId();
247 res = lifecycleOperation.startCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
248 assertTrue(res.isLeft());
249 id = res.left().value().getUniqueId();
251 status = nodeTypeOperation.deleteToscaDataElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, "prop99", JsonPresentationFields.NAME);
252 assertSame(status, StorageOperationStatus.OK);
254 // cancel certification
255 res = lifecycleOperation.cancelOrFailCertification(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId(), LifecycleStateEnum.READY_FOR_CERTIFICATION);
256 assertTrue(res.isLeft());
257 id = res.left().value().getUniqueId();
259 res = lifecycleOperation.startCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
260 assertTrue(res.isLeft());
261 id = res.left().value().getUniqueId();
263 // fail certification
264 res = lifecycleOperation.cancelOrFailCertification(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId(), LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
265 assertTrue(res.isLeft());
266 id = res.left().value().getUniqueId();
267 verifyInCatalogData(4, null);
268 // exportGraphMl(titanDao.getGraph().left().value());
273 public void serviceConformanceLevelTest() {
274 Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) serviceVertex.getMetadataProperty(GraphPropertyEnum.STATE)), serviceVertex.getUniqueId(),
275 modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
277 assertTrue(res.isLeft());
278 String id = res.left().value().getUniqueId();
280 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
281 assertTrue(res.isLeft());
283 String conformanceLevel = res.left().value().getMetadataValue(JsonPresentationFields.CONFORMANCE_LEVEL).toString();
284 assertEquals(conformanceLevel, ModelTestBase.configurationManager.getConfiguration().getToscaConformanceLevel());
288 public void catalogTest() {
289 // start position - 3 in catalog
290 List<String> expectedIds = new ArrayList<>();
291 expectedIds.add(rootVertex.getUniqueId());
292 expectedIds.add(vfVertex.getUniqueId());
293 expectedIds.add(serviceVertex.getUniqueId());
295 verifyInCatalogData(3, expectedIds);
297 GraphVertex vertex4 = createTopologyTemplate("topTemp4");
298 expectedIds.add(vertex4.getUniqueId());
299 verifyInCatalogData(4, expectedIds);
301 Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.undoCheckout(vertex4.getUniqueId());
302 expectedIds.remove(vertex4.getUniqueId());
303 verifyInCatalogData(3, expectedIds);
305 vertex4 = createTopologyTemplate("topTemp4");
306 expectedIds.add(vertex4.getUniqueId());
307 verifyInCatalogData(4, expectedIds);
309 res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) vertex4.getMetadataProperty(GraphPropertyEnum.STATE)), vertex4.getUniqueId(), modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
310 Either<ToscaElement, StorageOperationStatus> certifyToscaElement = lifecycleOperation.certifyToscaElement(vertex4.getUniqueId(), modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
311 assertTrue(certifyToscaElement.isLeft());
312 expectedIds.remove(vertex4.getUniqueId());
313 String certifiedId = certifyToscaElement.left().value().getUniqueId();
314 expectedIds.add(certifiedId);
315 verifyInCatalogData(4, expectedIds);
317 res = lifecycleOperation.checkoutToscaElement(certifiedId, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
318 assertTrue(certifyToscaElement.isLeft());
319 expectedIds.add(res.left().value().getUniqueId());
320 verifyInCatalogData(5, expectedIds);
323 private void createResourceCategory() {
325 GraphVertex cat = new GraphVertex(VertexTypeEnum.RESOURCE_CATEGORY);
326 Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
327 String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.RESOURCE_CATEGORY);
328 cat.setUniqueId(catId);
329 metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, catId);
330 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_CATEGORY.getName());
331 metadataProperties.put(GraphPropertyEnum.NAME, categoryName);
332 metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
333 cat.setMetadataProperties(metadataProperties);
334 cat.updateMetadataJsonWithCurrentMetadataProperties();
336 GraphVertex subCat = new GraphVertex(VertexTypeEnum.RESOURCE_SUBCATEGORY);
337 metadataProperties = new HashMap<>();
338 String subCatId = UniqueIdBuilder.buildSubCategoryUid(cat.getUniqueId(), subcategory);
339 subCat.setUniqueId(subCatId);
340 metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, subCatId);
341 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_SUBCATEGORY.getName());
342 metadataProperties.put(GraphPropertyEnum.NAME, subcategory);
343 metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(subcategory));
344 subCat.setMetadataProperties(metadataProperties);
345 subCat.updateMetadataJsonWithCurrentMetadataProperties();
347 Either<GraphVertex, TitanOperationStatus> catRes = titanDao.createVertex(cat);
349 Either<GraphVertex, TitanOperationStatus> subCatRes = titanDao.createVertex(subCat);
351 TitanOperationStatus status = titanDao.createEdge(catRes.left().value().getVertex(), subCatRes.left().value().getVertex(), EdgeLabelEnum.SUB_CATEGORY, new HashMap<>());
352 assertEquals(TitanOperationStatus.OK, status);
355 private void createServiceCategory() {
357 GraphVertex cat = new GraphVertex(VertexTypeEnum.SERVICE_CATEGORY);
358 Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
359 String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
360 cat.setUniqueId(catId);
361 metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, catId);
362 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.SERVICE_CATEGORY.getName());
363 metadataProperties.put(GraphPropertyEnum.NAME, categoryName);
364 metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
365 cat.setMetadataProperties(metadataProperties);
366 cat.updateMetadataJsonWithCurrentMetadataProperties();
368 Either<GraphVertex, TitanOperationStatus> catRes = titanDao.createVertex(cat);
370 assertTrue(catRes.isLeft());
373 private GraphVertex createTopologyTemplate(String name) {
375 TopologyTemplate service = new TopologyTemplate();
376 String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
377 service.setUniqueId(uniqueId);
378 service.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
379 service.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), name);
380 service.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
381 service.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "0.1");
382 service.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VF.name());
383 service.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(), ComponentTypeEnum.RESOURCE);
384 List<CategoryDefinition> categories = new ArrayList<>();
385 CategoryDefinition cat = new CategoryDefinition();
387 cat.setName(categoryName);
388 service.setCategories(categories);
390 service.setComponentType(ComponentTypeEnum.SERVICE);
391 Either<TopologyTemplate, StorageOperationStatus> createRes = topologyTemplateOperation.createTopologyTemplate(service);
392 assertTrue(createRes.isLeft());
394 Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createRes.left().value().getUniqueId());
395 assertTrue(getNodeTyeRes.isLeft());
397 // serviceVertex = getNodeTyeRes.left().value();
399 return getNodeTyeRes.left().value();
402 private <T extends ToscaDataDefinition> NodeType createNodeType(String nodeTypeName) {
404 NodeType vf = new NodeType();
405 String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
406 vf.setUniqueId(uniqueId);
407 vf.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
408 vf.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), nodeTypeName);
409 vf.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
410 vf.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "0.1");
411 vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VF.name());
412 vf.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(), ComponentTypeEnum.RESOURCE);
413 List<CategoryDefinition> categories = new ArrayList<>();
414 CategoryDefinition cat = new CategoryDefinition();
416 cat.setName(categoryName);
417 List<SubCategoryDefinition> subCategories = new ArrayList<>();
418 SubCategoryDefinition subCat = new SubCategoryDefinition();
419 subCat.setName(subcategory);
420 subCategories.add(subCat);
421 cat.setSubcategories(subCategories);
422 vf.setCategories(categories);
424 List<String> derivedFrom = new ArrayList<>();
425 derivedFrom.add("root");
426 vf.setDerivedFrom(derivedFrom);
428 vf.setComponentType(ComponentTypeEnum.RESOURCE);
429 Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
430 assertTrue(createVFRes.isLeft());
432 Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createVFRes.left().value().getUniqueId());
433 assertTrue(getNodeTyeRes.isLeft());
435 vfVertex = getNodeTyeRes.left().value();
437 List<PropertyDataDefinition> addProperties = new ArrayList<>();
438 PropertyDataDefinition prop11 = new PropertyDataDefinition();
439 prop11.setName("prop11");
440 prop11.setDefaultValue("def11");
442 addProperties.add(prop11);
444 PropertyDataDefinition prop22 = new PropertyDataDefinition();
445 prop22.setName("prop22");
446 prop22.setDefaultValue("def22");
447 addProperties.add(prop22);
449 StorageOperationStatus status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, addProperties, JsonPresentationFields.NAME);
450 assertSame(status, StorageOperationStatus.OK);
452 PropertyDataDefinition prop33 = new PropertyDataDefinition();
453 prop33.setName("prop33");
454 prop33.setDefaultValue("def33");
456 status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop33, JsonPresentationFields.NAME);
457 assertSame(status, StorageOperationStatus.OK);
459 PropertyDataDefinition prop44 = new PropertyDataDefinition();
460 prop44.setName("prop44");
461 prop44.setDefaultValue("def44");
463 status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop44, JsonPresentationFields.NAME);
464 assertSame(status, StorageOperationStatus.OK);
466 PropertyDataDefinition capProp = new PropertyDataDefinition();
467 capProp.setName("capProp");
468 capProp.setDefaultValue("capPropDef");
470 MapDataDefinition dataToCreate = new MapPropertiesDataDefinition();
471 dataToCreate.put("capProp", capProp);
473 Map<String, MapDataDefinition> capProps = new HashMap();
474 capProps.put("capName", dataToCreate);
476 Either<GraphVertex, StorageOperationStatus> res = nodeTypeOperation.associateElementToData(vfVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES, EdgeLabelEnum.CAPABILITIES_PROPERTIES, capProps);
478 // exportGraphMl(titanDao.getGraph().left().value());
480 List<String> pathKeys = new ArrayList<>();
481 pathKeys.add("capName");
482 capProp.setDefaultValue("BBBB");
483 status = nodeTypeOperation.updateToscaDataDeepElementOfToscaElement(vfVertex, EdgeLabelEnum.CAPABILITIES_PROPERTIES, VertexTypeEnum.CAPABILITIES_PROPERTIES, capProp, pathKeys, JsonPresentationFields.NAME);
487 private GraphVertex createRootNodeType() {
489 NodeType vf = new NodeType();
490 String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
491 vf.setUniqueId(uniqueId);
492 vf.setComponentType(ComponentTypeEnum.RESOURCE);
493 vf.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
494 vf.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), "root");
495 vf.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
496 vf.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "1.0");
497 vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VFC.name());
498 vf.getMetadata().put(JsonPresentationFields.LIFECYCLE_STATE.getPresentation(), LifecycleStateEnum.CERTIFIED.name());
499 vf.getMetadata().put(JsonPresentationFields.TOSCA_RESOURCE_NAME.getPresentation(), "root");
500 vf.getMetadata().put(JsonPresentationFields.HIGHEST_VERSION.getPresentation(), true);
502 List<CategoryDefinition> categories = new ArrayList<>();
503 CategoryDefinition cat = new CategoryDefinition();
505 cat.setName(categoryName);
506 List<SubCategoryDefinition> subCategories = new ArrayList<>();
507 SubCategoryDefinition subCat = new SubCategoryDefinition();
508 subCat.setName(subcategory);
509 subCategories.add(subCat);
510 cat.setSubcategories(subCategories);
511 vf.setCategories(categories);
513 List<String> derivedFrom = new ArrayList<>();
514 vf.setDerivedFrom(derivedFrom);
516 Map<String, PropertyDataDefinition> properties = new HashMap<>();
517 PropertyDataDefinition prop1 = new PropertyDataDefinition();
518 prop1.setName("derived1");
519 prop1.setDefaultValue("deriveddef1");
521 properties.put("derived1", prop1);
523 PropertyDataDefinition prop2 = new PropertyDataDefinition();
524 prop2.setUniqueId("derived2");
525 prop2.setName("deriveddef2");
526 properties.put("derived2", prop2);
528 PropertyDataDefinition prop3 = new PropertyDataDefinition();
529 prop3.setName("derived3");
530 prop3.setDefaultValue("deriveddef3");
531 properties.put("derived3", prop3);
533 vf.setProperties(properties);
534 vf.setComponentType(ComponentTypeEnum.RESOURCE);
535 Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
536 assertTrue(createVFRes.isLeft());
538 Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createVFRes.left().value().getUniqueId());
539 assertTrue(getNodeTyeRes.isLeft());
540 return getNodeTyeRes.left().value();
543 private void createUsers() {
545 GraphVertex ownerV = new GraphVertex(VertexTypeEnum.USER);
546 ownerV.setUniqueId("user1");
548 Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
549 metadataProperties.put(GraphPropertyEnum.USERID, ownerV.getUniqueId());
550 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
551 metadataProperties.put(GraphPropertyEnum.NAME, "user1");
552 ownerV.setMetadataProperties(metadataProperties);
553 ownerV.updateMetadataJsonWithCurrentMetadataProperties();
554 ownerV.setJson(new HashMap<>());
555 Either<GraphVertex, TitanOperationStatus> createUserRes = titanDao.createVertex(ownerV);
556 assertTrue(createUserRes.isLeft());
558 ownerVertex = createUserRes.left().value();
560 GraphVertex modifierV = new GraphVertex(VertexTypeEnum.USER);
561 modifierV.setUniqueId("user2");
563 metadataProperties = new HashMap<>();
564 metadataProperties.put(GraphPropertyEnum.USERID, modifierV.getUniqueId());
565 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
566 metadataProperties.put(GraphPropertyEnum.NAME, "user2");
567 modifierV.setMetadataProperties(metadataProperties);
568 modifierV.updateMetadataJsonWithCurrentMetadataProperties();
569 modifierV.setJson(new HashMap<>());
570 createUserRes = titanDao.createVertex(modifierV);
571 assertTrue(createUserRes.isLeft());
573 modifierVertex = createUserRes.left().value();
575 Either<GraphVertex, TitanOperationStatus> getOwnerRes = lifecycleOperation.findUser(ownerVertex.getUniqueId());
576 assertTrue(getOwnerRes.isLeft());
580 public void verifyInCatalogData(int expected, List<String> expectedIds) {
582 Either<List<CatalogComponent>, StorageOperationStatus> highestResourcesRes = topologyTemplateOperation.getElementCatalogData(true, null);
583 assertTrue(highestResourcesRes.isLeft());
584 List<CatalogComponent> highestResources = highestResourcesRes.left().value();
585 // calculate expected count value
586 assertEquals(expected, highestResources.stream().count());
587 if (expectedIds != null) {
588 highestResources.forEach(a -> assertTrue(expectedIds.contains(a.getUniqueId())));
593 public void teardown() {
597 private void clearGraph() {
598 Either<TitanGraph, TitanOperationStatus> graphResult = titanDao.getGraph();
599 TitanGraph graph = graphResult.left().value();
601 Iterable<TitanVertex> vertices = graph.query().vertices();
602 if (vertices != null) {
603 Iterator<TitanVertex> iterator = vertices.iterator();
604 while (iterator.hasNext()) {
605 TitanVertex vertex = iterator.next();