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.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;
62 import java.io.BufferedOutputStream;
64 import java.io.FileOutputStream;
65 import java.io.OutputStream;
68 import static org.junit.Assert.assertEquals;
69 import static org.junit.Assert.assertSame;
70 import static org.junit.Assert.assertTrue;
72 @RunWith(SpringJUnit4ClassRunner.class)
73 @ContextConfiguration("classpath:application-context-test.xml")
74 public class ToscaElementLifecycleOperationTest extends ModelTestBase {
76 @javax.annotation.Resource
77 protected TitanDao titanDao;
79 @javax.annotation.Resource
80 private NodeTypeOperation nodeTypeOperation;
82 @javax.annotation.Resource
83 private TopologyTemplateOperation topologyTemplateOperation;
85 @javax.annotation.Resource
86 private ToscaElementLifecycleOperation lifecycleOperation;
88 String categoryName = "category";
89 String subcategory = "mycategory";
90 String outputDirectory = "C:\\Output";
93 public TestName name = new TestName();
96 public static void initLifecycleOperation() {
100 private GraphVertex ownerVertex;
101 private GraphVertex modifierVertex;
102 private GraphVertex vfVertex;
103 private GraphVertex serviceVertex;
104 private GraphVertex rootVertex;
107 public void setupBefore() {
110 createResourceCategory();
111 createServiceCategory();
112 GraphTestUtils.createRootCatalogVertex(titanDao);
113 rootVertex = createRootNodeType();
114 createNodeType("firstVf");
115 serviceVertex = createTopologyTemplate("firstService");
119 public void lifecycleTest() {
120 Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) vfVertex.getMetadataProperty(GraphPropertyEnum.STATE)), vfVertex.getUniqueId(), modifierVertex.getUniqueId(),
121 ownerVertex.getUniqueId());
122 StorageOperationStatus status;
124 assertTrue(res.isLeft());
128 verifyInCatalogData(3, null);
130 String id = res.left().value().getUniqueId();
132 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
133 assertTrue(res.isLeft());
134 id = res.left().value().getUniqueId();
136 verifyInCatalogData(3, null);
138 PropertyDataDefinition prop55 = new PropertyDataDefinition();
139 prop55.setName("prop55");
140 prop55.setDefaultValue("def55");
142 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop55, JsonPresentationFields.NAME);
143 assertSame(status, StorageOperationStatus.OK);
145 CapabilityDataDefinition cap1 = new CapabilityDataDefinition();
146 cap1.setName("cap1");
147 cap1.setDescription("create");
148 cap1.setUniqueId(UniqueIdBuilder.buildCapabilityUid(id, "cap1"));
150 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILTIES, cap1, JsonPresentationFields.NAME);
151 assertSame(status, StorageOperationStatus.OK);
153 res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
154 assertTrue(res.isLeft());
155 id = res.left().value().getUniqueId();
157 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
158 assertTrue(res.isLeft());
159 id = res.left().value().getUniqueId();
161 prop55.setDefaultValue("AAAAAAAA");
162 status = nodeTypeOperation.updateToscaDataOfToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop55, JsonPresentationFields.NAME);
163 assertSame(status, StorageOperationStatus.OK);
165 cap1.setDescription("update");
167 status = nodeTypeOperation.updateToscaDataOfToscaElement(id, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILTIES, cap1, JsonPresentationFields.NAME);
168 assertSame(status, StorageOperationStatus.OK);
170 PropertyDataDefinition prop66 = new PropertyDataDefinition();
171 prop66.setName("prop66");
172 prop66.setDefaultValue("def66");
174 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop66, JsonPresentationFields.NAME);
175 assertSame(status, StorageOperationStatus.OK);
177 res = lifecycleOperation.requestCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
178 assertTrue(res.isLeft());
179 id = res.left().value().getUniqueId();
181 res = lifecycleOperation.startCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
182 assertTrue(res.isLeft());
183 id = res.left().value().getUniqueId();
185 res = lifecycleOperation.certifyToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
186 assertTrue(res.isLeft());
187 id = res.left().value().getUniqueId();
189 verifyInCatalogData(3, null);
191 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
192 assertTrue(res.isLeft());
193 id = res.left().value().getUniqueId();
195 verifyInCatalogData(4, null);
197 PropertyDataDefinition prop77 = new PropertyDataDefinition();
198 prop77.setName("prop77");
199 prop77.setDefaultValue("def77");
201 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop77, JsonPresentationFields.NAME);
202 assertSame(status, StorageOperationStatus.OK);
204 res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
205 assertTrue(res.isLeft());
206 id = res.left().value().getUniqueId();
208 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
209 assertTrue(res.isLeft());
210 id = res.left().value().getUniqueId();
212 PropertyDataDefinition prop88 = new PropertyDataDefinition();
213 prop88.setName("prop88");
214 prop88.setDefaultValue("def88");
216 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop88, JsonPresentationFields.NAME);
217 assertSame(status, StorageOperationStatus.OK);
219 res = lifecycleOperation.requestCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
220 assertTrue(res.isLeft());
221 id = res.left().value().getUniqueId();
223 res = lifecycleOperation.startCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
224 assertTrue(res.isLeft());
225 id = res.left().value().getUniqueId();
227 res = lifecycleOperation.certifyToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
228 assertTrue(res.isLeft());
229 id = res.left().value().getUniqueId();
230 verifyInCatalogData(3, null);
232 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
233 assertTrue(res.isLeft());
234 id = res.left().value().getUniqueId();
236 verifyInCatalogData(4, null);
238 PropertyDataDefinition prop99 = new PropertyDataDefinition();
239 prop99.setName("prop99");
240 prop99.setDefaultValue("def99");
242 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop99, JsonPresentationFields.NAME);
243 assertSame(status, StorageOperationStatus.OK);
245 res = lifecycleOperation.requestCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
246 assertTrue(res.isLeft());
247 id = res.left().value().getUniqueId();
249 res = lifecycleOperation.startCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
250 assertTrue(res.isLeft());
251 id = res.left().value().getUniqueId();
253 status = nodeTypeOperation.deleteToscaDataElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, "prop99", JsonPresentationFields.NAME);
254 assertSame(status, StorageOperationStatus.OK);
256 // cancel certification
257 res = lifecycleOperation.cancelOrFailCertification(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId(), LifecycleStateEnum.READY_FOR_CERTIFICATION);
258 assertTrue(res.isLeft());
259 id = res.left().value().getUniqueId();
261 res = lifecycleOperation.startCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
262 assertTrue(res.isLeft());
263 id = res.left().value().getUniqueId();
265 // fail certification
266 res = lifecycleOperation.cancelOrFailCertification(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId(), LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
267 assertTrue(res.isLeft());
268 id = res.left().value().getUniqueId();
269 verifyInCatalogData(4, null);
270 // exportGraphMl(titanDao.getGraph().left().value());
275 public void serviceConformanceLevelTest() {
276 Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) serviceVertex.getMetadataProperty(GraphPropertyEnum.STATE)), serviceVertex.getUniqueId(),
277 modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
279 assertTrue(res.isLeft());
280 String id = res.left().value().getUniqueId();
282 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
283 assertTrue(res.isLeft());
285 String conformanceLevel = res.left().value().getMetadataValue(JsonPresentationFields.CONFORMANCE_LEVEL).toString();
286 assertEquals(conformanceLevel, ModelTestBase.configurationManager.getConfiguration().getToscaConformanceLevel());
290 public void catalogTest() {
291 // start position - 3 in catalog
292 List<String> expectedIds = new ArrayList<>();
293 expectedIds.add(rootVertex.getUniqueId());
294 expectedIds.add(vfVertex.getUniqueId());
295 expectedIds.add(serviceVertex.getUniqueId());
297 verifyInCatalogData(3, expectedIds);
299 GraphVertex vertex4 = createTopologyTemplate("topTemp4");
300 expectedIds.add(vertex4.getUniqueId());
301 verifyInCatalogData(4, expectedIds);
303 Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.undoCheckout(vertex4.getUniqueId());
304 expectedIds.remove(vertex4.getUniqueId());
305 verifyInCatalogData(3, expectedIds);
307 vertex4 = createTopologyTemplate("topTemp4");
308 expectedIds.add(vertex4.getUniqueId());
309 verifyInCatalogData(4, expectedIds);
311 res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) vertex4.getMetadataProperty(GraphPropertyEnum.STATE)), vertex4.getUniqueId(), modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
312 Either<ToscaElement, StorageOperationStatus> certifyToscaElement = lifecycleOperation.certifyToscaElement(vertex4.getUniqueId(), modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
313 assertTrue(certifyToscaElement.isLeft());
314 expectedIds.remove(vertex4.getUniqueId());
315 String certifiedId = certifyToscaElement.left().value().getUniqueId();
316 expectedIds.add(certifiedId);
317 verifyInCatalogData(4, expectedIds);
319 res = lifecycleOperation.checkoutToscaElement(certifiedId, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
320 assertTrue(certifyToscaElement.isLeft());
321 expectedIds.add(res.left().value().getUniqueId());
322 verifyInCatalogData(5, expectedIds);
326 public void testGetToscaElOwner_Fail(){
327 Either<User, StorageOperationStatus> result;
328 String toscaEleId = "toscaElementId";
329 titanDao.getVertexById(toscaEleId, JsonParseFlagEnum.NoParse);
330 result = lifecycleOperation.getToscaElementOwner(toscaEleId);
331 assertEquals(StorageOperationStatus.NOT_FOUND, result.right().value());
334 private void createResourceCategory() {
336 GraphVertex cat = new GraphVertex(VertexTypeEnum.RESOURCE_CATEGORY);
337 Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
338 String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.RESOURCE_CATEGORY);
339 cat.setUniqueId(catId);
340 metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, catId);
341 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_CATEGORY.getName());
342 metadataProperties.put(GraphPropertyEnum.NAME, categoryName);
343 metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
344 cat.setMetadataProperties(metadataProperties);
345 cat.updateMetadataJsonWithCurrentMetadataProperties();
347 GraphVertex subCat = new GraphVertex(VertexTypeEnum.RESOURCE_SUBCATEGORY);
348 metadataProperties = new HashMap<>();
349 String subCatId = UniqueIdBuilder.buildSubCategoryUid(cat.getUniqueId(), subcategory);
350 subCat.setUniqueId(subCatId);
351 metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, subCatId);
352 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_SUBCATEGORY.getName());
353 metadataProperties.put(GraphPropertyEnum.NAME, subcategory);
354 metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(subcategory));
355 subCat.setMetadataProperties(metadataProperties);
356 subCat.updateMetadataJsonWithCurrentMetadataProperties();
358 Either<GraphVertex, TitanOperationStatus> catRes = titanDao.createVertex(cat);
360 Either<GraphVertex, TitanOperationStatus> subCatRes = titanDao.createVertex(subCat);
362 TitanOperationStatus status = titanDao.createEdge(catRes.left().value().getVertex(), subCatRes.left().value().getVertex(), EdgeLabelEnum.SUB_CATEGORY, new HashMap<>());
363 assertEquals(TitanOperationStatus.OK, status);
366 private void createServiceCategory() {
368 GraphVertex cat = new GraphVertex(VertexTypeEnum.SERVICE_CATEGORY);
369 Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
370 String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
371 cat.setUniqueId(catId);
372 metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, catId);
373 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.SERVICE_CATEGORY.getName());
374 metadataProperties.put(GraphPropertyEnum.NAME, categoryName);
375 metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
376 cat.setMetadataProperties(metadataProperties);
377 cat.updateMetadataJsonWithCurrentMetadataProperties();
379 Either<GraphVertex, TitanOperationStatus> catRes = titanDao.createVertex(cat);
381 assertTrue(catRes.isLeft());
384 private GraphVertex createTopologyTemplate(String name) {
386 TopologyTemplate service = new TopologyTemplate();
387 String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
388 service.setUniqueId(uniqueId);
389 service.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
390 service.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), name);
391 service.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
392 service.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "0.1");
393 service.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VF.name());
394 service.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(), ComponentTypeEnum.RESOURCE);
395 List<CategoryDefinition> categories = new ArrayList<>();
396 CategoryDefinition cat = new CategoryDefinition();
398 cat.setName(categoryName);
399 service.setCategories(categories);
401 service.setComponentType(ComponentTypeEnum.SERVICE);
402 Either<TopologyTemplate, StorageOperationStatus> createRes = topologyTemplateOperation.createTopologyTemplate(service);
403 assertTrue(createRes.isLeft());
405 Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createRes.left().value().getUniqueId());
406 assertTrue(getNodeTyeRes.isLeft());
408 // serviceVertex = getNodeTyeRes.left().value();
410 return getNodeTyeRes.left().value();
413 private <T extends ToscaDataDefinition> NodeType createNodeType(String nodeTypeName) {
415 NodeType vf = new NodeType();
416 String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
417 vf.setUniqueId(uniqueId);
418 vf.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
419 vf.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), nodeTypeName);
420 vf.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
421 vf.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "0.1");
422 vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VF.name());
423 vf.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(), ComponentTypeEnum.RESOURCE);
424 List<CategoryDefinition> categories = new ArrayList<>();
425 CategoryDefinition cat = new CategoryDefinition();
427 cat.setName(categoryName);
428 List<SubCategoryDefinition> subCategories = new ArrayList<>();
429 SubCategoryDefinition subCat = new SubCategoryDefinition();
430 subCat.setName(subcategory);
431 subCategories.add(subCat);
432 cat.setSubcategories(subCategories);
433 vf.setCategories(categories);
435 List<String> derivedFrom = new ArrayList<>();
436 derivedFrom.add("root");
437 vf.setDerivedFrom(derivedFrom);
439 vf.setComponentType(ComponentTypeEnum.RESOURCE);
440 Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
441 assertTrue(createVFRes.isLeft());
443 Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createVFRes.left().value().getUniqueId());
444 assertTrue(getNodeTyeRes.isLeft());
446 vfVertex = getNodeTyeRes.left().value();
448 List<PropertyDataDefinition> addProperties = new ArrayList<>();
449 PropertyDataDefinition prop11 = new PropertyDataDefinition();
450 prop11.setName("prop11");
451 prop11.setDefaultValue("def11");
453 addProperties.add(prop11);
455 PropertyDataDefinition prop22 = new PropertyDataDefinition();
456 prop22.setName("prop22");
457 prop22.setDefaultValue("def22");
458 addProperties.add(prop22);
460 StorageOperationStatus status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, addProperties, JsonPresentationFields.NAME);
461 assertSame(status, StorageOperationStatus.OK);
463 PropertyDataDefinition prop33 = new PropertyDataDefinition();
464 prop33.setName("prop33");
465 prop33.setDefaultValue("def33");
467 status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop33, JsonPresentationFields.NAME);
468 assertSame(status, StorageOperationStatus.OK);
470 PropertyDataDefinition prop44 = new PropertyDataDefinition();
471 prop44.setName("prop44");
472 prop44.setDefaultValue("def44");
474 status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop44, JsonPresentationFields.NAME);
475 assertSame(status, StorageOperationStatus.OK);
477 PropertyDataDefinition capProp = new PropertyDataDefinition();
478 capProp.setName("capProp");
479 capProp.setDefaultValue("capPropDef");
481 MapDataDefinition dataToCreate = new MapPropertiesDataDefinition();
482 dataToCreate.put("capProp", capProp);
484 Map<String, MapDataDefinition> capProps = new HashMap();
485 capProps.put("capName", dataToCreate);
487 Either<GraphVertex, StorageOperationStatus> res = nodeTypeOperation.associateElementToData(vfVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES, EdgeLabelEnum.CAPABILITIES_PROPERTIES, capProps);
489 // exportGraphMl(titanDao.getGraph().left().value());
491 List<String> pathKeys = new ArrayList<>();
492 pathKeys.add("capName");
493 capProp.setDefaultValue("BBBB");
494 status = nodeTypeOperation.updateToscaDataDeepElementOfToscaElement(vfVertex, EdgeLabelEnum.CAPABILITIES_PROPERTIES, VertexTypeEnum.CAPABILITIES_PROPERTIES, capProp, pathKeys, JsonPresentationFields.NAME);
498 private GraphVertex createRootNodeType() {
500 NodeType vf = new NodeType();
501 String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
502 vf.setUniqueId(uniqueId);
503 vf.setComponentType(ComponentTypeEnum.RESOURCE);
504 vf.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
505 vf.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), "root");
506 vf.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
507 vf.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "1.0");
508 vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VFC.name());
509 vf.getMetadata().put(JsonPresentationFields.LIFECYCLE_STATE.getPresentation(), LifecycleStateEnum.CERTIFIED.name());
510 vf.getMetadata().put(JsonPresentationFields.TOSCA_RESOURCE_NAME.getPresentation(), "root");
511 vf.getMetadata().put(JsonPresentationFields.HIGHEST_VERSION.getPresentation(), true);
513 List<CategoryDefinition> categories = new ArrayList<>();
514 CategoryDefinition cat = new CategoryDefinition();
516 cat.setName(categoryName);
517 List<SubCategoryDefinition> subCategories = new ArrayList<>();
518 SubCategoryDefinition subCat = new SubCategoryDefinition();
519 subCat.setName(subcategory);
520 subCategories.add(subCat);
521 cat.setSubcategories(subCategories);
522 vf.setCategories(categories);
524 List<String> derivedFrom = new ArrayList<>();
525 vf.setDerivedFrom(derivedFrom);
527 Map<String, PropertyDataDefinition> properties = new HashMap<>();
528 PropertyDataDefinition prop1 = new PropertyDataDefinition();
529 prop1.setName("derived1");
530 prop1.setDefaultValue("deriveddef1");
532 properties.put("derived1", prop1);
534 PropertyDataDefinition prop2 = new PropertyDataDefinition();
535 prop2.setUniqueId("derived2");
536 prop2.setName("deriveddef2");
537 properties.put("derived2", prop2);
539 PropertyDataDefinition prop3 = new PropertyDataDefinition();
540 prop3.setName("derived3");
541 prop3.setDefaultValue("deriveddef3");
542 properties.put("derived3", prop3);
544 vf.setProperties(properties);
545 vf.setComponentType(ComponentTypeEnum.RESOURCE);
546 Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
547 assertTrue(createVFRes.isLeft());
549 Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createVFRes.left().value().getUniqueId());
550 assertTrue(getNodeTyeRes.isLeft());
551 return getNodeTyeRes.left().value();
554 private void createUsers() {
556 GraphVertex ownerV = new GraphVertex(VertexTypeEnum.USER);
557 ownerV.setUniqueId("user1");
559 Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
560 metadataProperties.put(GraphPropertyEnum.USERID, ownerV.getUniqueId());
561 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
562 metadataProperties.put(GraphPropertyEnum.NAME, "user1");
563 ownerV.setMetadataProperties(metadataProperties);
564 ownerV.updateMetadataJsonWithCurrentMetadataProperties();
565 ownerV.setJson(new HashMap<>());
566 Either<GraphVertex, TitanOperationStatus> createUserRes = titanDao.createVertex(ownerV);
567 assertTrue(createUserRes.isLeft());
569 ownerVertex = createUserRes.left().value();
571 GraphVertex modifierV = new GraphVertex(VertexTypeEnum.USER);
572 modifierV.setUniqueId("user2");
574 metadataProperties = new HashMap<>();
575 metadataProperties.put(GraphPropertyEnum.USERID, modifierV.getUniqueId());
576 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
577 metadataProperties.put(GraphPropertyEnum.NAME, "user2");
578 modifierV.setMetadataProperties(metadataProperties);
579 modifierV.updateMetadataJsonWithCurrentMetadataProperties();
580 modifierV.setJson(new HashMap<>());
581 createUserRes = titanDao.createVertex(modifierV);
582 assertTrue(createUserRes.isLeft());
584 modifierVertex = createUserRes.left().value();
586 Either<GraphVertex, TitanOperationStatus> getOwnerRes = lifecycleOperation.findUser(ownerVertex.getUniqueId());
587 assertTrue(getOwnerRes.isLeft());
591 public void verifyInCatalogData(int expected, List<String> expectedIds) {
593 Either<List<CatalogComponent>, StorageOperationStatus> highestResourcesRes = topologyTemplateOperation.getElementCatalogData(true, null);
594 assertTrue(highestResourcesRes.isLeft());
595 List<CatalogComponent> highestResources = highestResourcesRes.left().value();
596 // calculate expected count value
597 assertEquals(expected, highestResources.stream().count());
598 if (expectedIds != null) {
599 highestResources.forEach(a -> assertTrue(expectedIds.contains(a.getUniqueId())));
604 public void teardown() {
608 private void clearGraph() {
609 Either<TitanGraph, TitanOperationStatus> graphResult = titanDao.getGraph();
610 TitanGraph graph = graphResult.left().value();
612 Iterable<TitanVertex> vertices = graph.query().vertices();
613 if (vertices != null) {
614 Iterator<TitanVertex> iterator = vertices.iterator();
615 while (iterator.hasNext()) {
616 TitanVertex vertex = iterator.next();