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;
64 import static org.junit.Assert.assertEquals;
65 import static org.junit.Assert.assertSame;
66 import static org.junit.Assert.assertTrue;
68 @RunWith(SpringJUnit4ClassRunner.class)
69 @ContextConfiguration("classpath:application-context-test.xml")
70 public class ToscaElementLifecycleOperationTest extends ModelTestBase {
72 @javax.annotation.Resource
73 protected TitanDao titanDao;
75 @javax.annotation.Resource
76 private NodeTypeOperation nodeTypeOperation;
78 @javax.annotation.Resource
79 private TopologyTemplateOperation topologyTemplateOperation;
81 @javax.annotation.Resource
82 private ToscaElementLifecycleOperation lifecycleOperation;
84 String categoryName = "category";
85 String subcategory = "mycategory";
86 String outputDirectory = "C:\\Output";
89 public TestName name = new TestName();
92 public static void initLifecycleOperation() {
96 private GraphVertex ownerVertex;
97 private GraphVertex modifierVertex;
98 private GraphVertex vfVertex;
99 private GraphVertex serviceVertex;
100 private GraphVertex rootVertex;
103 public void setupBefore() {
106 createResourceCategory();
107 createServiceCategory();
108 GraphTestUtils.createRootCatalogVertex(titanDao);
109 rootVertex = createRootNodeType();
110 createNodeType("firstVf");
111 serviceVertex = createTopologyTemplate("firstService");
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;
120 assertTrue(res.isLeft());
124 verifyInCatalogData(3, null);
126 String id = res.left().value().getUniqueId();
128 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
129 assertTrue(res.isLeft());
130 id = res.left().value().getUniqueId();
132 verifyInCatalogData(3, null);
134 PropertyDataDefinition prop55 = new PropertyDataDefinition();
135 prop55.setName("prop55");
136 prop55.setDefaultValue("def55");
138 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop55, JsonPresentationFields.NAME);
139 assertSame(status, StorageOperationStatus.OK);
141 CapabilityDataDefinition cap1 = new CapabilityDataDefinition();
142 cap1.setName("cap1");
143 cap1.setDescription("create");
144 cap1.setUniqueId(UniqueIdBuilder.buildCapabilityUid(id, "cap1"));
146 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILITIES, cap1, JsonPresentationFields.NAME);
147 assertSame(status, StorageOperationStatus.OK);
149 res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
150 assertTrue(res.isLeft());
151 id = res.left().value().getUniqueId();
153 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
154 assertTrue(res.isLeft());
155 id = res.left().value().getUniqueId();
157 prop55.setDefaultValue("AAAAAAAA");
158 status = nodeTypeOperation.updateToscaDataOfToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop55, JsonPresentationFields.NAME);
159 assertSame(status, StorageOperationStatus.OK);
161 cap1.setDescription("update");
163 status = nodeTypeOperation.updateToscaDataOfToscaElement(id, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILITIES, cap1, JsonPresentationFields.NAME);
164 assertSame(status, StorageOperationStatus.OK);
166 PropertyDataDefinition prop66 = new PropertyDataDefinition();
167 prop66.setName("prop66");
168 prop66.setDefaultValue("def66");
170 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop66, JsonPresentationFields.NAME);
171 assertSame(status, StorageOperationStatus.OK);
173 res = lifecycleOperation.requestCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
174 assertTrue(res.isLeft());
175 id = res.left().value().getUniqueId();
177 res = lifecycleOperation.startCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
178 assertTrue(res.isLeft());
179 id = res.left().value().getUniqueId();
181 res = lifecycleOperation.certifyToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
182 assertTrue(res.isLeft());
183 id = res.left().value().getUniqueId();
185 verifyInCatalogData(3, null);
187 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
188 assertTrue(res.isLeft());
189 id = res.left().value().getUniqueId();
191 verifyInCatalogData(4, null);
193 PropertyDataDefinition prop77 = new PropertyDataDefinition();
194 prop77.setName("prop77");
195 prop77.setDefaultValue("def77");
197 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop77, JsonPresentationFields.NAME);
198 assertSame(status, StorageOperationStatus.OK);
200 res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
201 assertTrue(res.isLeft());
202 id = res.left().value().getUniqueId();
204 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
205 assertTrue(res.isLeft());
206 id = res.left().value().getUniqueId();
208 PropertyDataDefinition prop88 = new PropertyDataDefinition();
209 prop88.setName("prop88");
210 prop88.setDefaultValue("def88");
212 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop88, JsonPresentationFields.NAME);
213 assertSame(status, StorageOperationStatus.OK);
215 res = lifecycleOperation.requestCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
216 assertTrue(res.isLeft());
217 id = res.left().value().getUniqueId();
219 res = lifecycleOperation.startCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
220 assertTrue(res.isLeft());
221 id = res.left().value().getUniqueId();
223 res = lifecycleOperation.certifyToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
224 assertTrue(res.isLeft());
225 id = res.left().value().getUniqueId();
226 verifyInCatalogData(3, null);
228 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
229 assertTrue(res.isLeft());
230 id = res.left().value().getUniqueId();
232 verifyInCatalogData(4, null);
234 PropertyDataDefinition prop99 = new PropertyDataDefinition();
235 prop99.setName("prop99");
236 prop99.setDefaultValue("def99");
238 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop99, JsonPresentationFields.NAME);
239 assertSame(status, StorageOperationStatus.OK);
241 res = lifecycleOperation.requestCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
242 assertTrue(res.isLeft());
243 id = res.left().value().getUniqueId();
245 res = lifecycleOperation.startCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
246 assertTrue(res.isLeft());
247 id = res.left().value().getUniqueId();
249 status = nodeTypeOperation.deleteToscaDataElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, "prop99", JsonPresentationFields.NAME);
250 assertSame(status, StorageOperationStatus.OK);
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();
257 res = lifecycleOperation.startCertificationToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
258 assertTrue(res.isLeft());
259 id = res.left().value().getUniqueId();
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());
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());
275 assertTrue(res.isLeft());
276 String id = res.left().value().getUniqueId();
278 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
279 assertTrue(res.isLeft());
281 String conformanceLevel = res.left().value().getMetadataValue(JsonPresentationFields.CONFORMANCE_LEVEL).toString();
282 assertEquals(conformanceLevel, ModelTestBase.configurationManager.getConfiguration().getToscaConformanceLevel());
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());
293 verifyInCatalogData(3, expectedIds);
295 GraphVertex vertex4 = createTopologyTemplate("topTemp4");
296 expectedIds.add(vertex4.getUniqueId());
297 verifyInCatalogData(4, expectedIds);
299 Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.undoCheckout(vertex4.getUniqueId());
300 expectedIds.remove(vertex4.getUniqueId());
301 verifyInCatalogData(3, expectedIds);
303 vertex4 = createTopologyTemplate("topTemp4");
304 expectedIds.add(vertex4.getUniqueId());
305 verifyInCatalogData(4, expectedIds);
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);
315 res = lifecycleOperation.checkoutToscaElement(certifiedId, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
316 assertTrue(certifyToscaElement.isLeft());
317 expectedIds.add(res.left().value().getUniqueId());
318 verifyInCatalogData(5, expectedIds);
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());
330 private void createResourceCategory() {
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();
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();
354 Either<GraphVertex, TitanOperationStatus> catRes = titanDao.createVertex(cat);
356 Either<GraphVertex, TitanOperationStatus> subCatRes = titanDao.createVertex(subCat);
358 TitanOperationStatus status = titanDao.createEdge(catRes.left().value().getVertex(), subCatRes.left().value().getVertex(), EdgeLabelEnum.SUB_CATEGORY, new HashMap<>());
359 assertEquals(TitanOperationStatus.OK, status);
362 private void createServiceCategory() {
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();
375 Either<GraphVertex, TitanOperationStatus> catRes = titanDao.createVertex(cat);
377 assertTrue(catRes.isLeft());
380 private GraphVertex createTopologyTemplate(String name) {
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();
394 cat.setName(categoryName);
395 service.setCategories(categories);
397 service.setComponentType(ComponentTypeEnum.SERVICE);
398 Either<TopologyTemplate, StorageOperationStatus> createRes = topologyTemplateOperation.createTopologyTemplate(service);
399 assertTrue(createRes.isLeft());
401 Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createRes.left().value().getUniqueId());
402 assertTrue(getNodeTyeRes.isLeft());
404 // serviceVertex = getNodeTyeRes.left().value();
406 return getNodeTyeRes.left().value();
409 private <T extends ToscaDataDefinition> NodeType createNodeType(String nodeTypeName) {
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();
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);
431 List<String> derivedFrom = new ArrayList<>();
432 derivedFrom.add("root");
433 vf.setDerivedFrom(derivedFrom);
435 vf.setComponentType(ComponentTypeEnum.RESOURCE);
436 Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
437 assertTrue(createVFRes.isLeft());
439 Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createVFRes.left().value().getUniqueId());
440 assertTrue(getNodeTyeRes.isLeft());
442 vfVertex = getNodeTyeRes.left().value();
444 List<PropertyDataDefinition> addProperties = new ArrayList<>();
445 PropertyDataDefinition prop11 = new PropertyDataDefinition();
446 prop11.setName("prop11");
447 prop11.setDefaultValue("def11");
449 addProperties.add(prop11);
451 PropertyDataDefinition prop22 = new PropertyDataDefinition();
452 prop22.setName("prop22");
453 prop22.setDefaultValue("def22");
454 addProperties.add(prop22);
456 StorageOperationStatus status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, addProperties, JsonPresentationFields.NAME);
457 assertSame(status, StorageOperationStatus.OK);
459 PropertyDataDefinition prop33 = new PropertyDataDefinition();
460 prop33.setName("prop33");
461 prop33.setDefaultValue("def33");
463 status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop33, JsonPresentationFields.NAME);
464 assertSame(status, StorageOperationStatus.OK);
466 PropertyDataDefinition prop44 = new PropertyDataDefinition();
467 prop44.setName("prop44");
468 prop44.setDefaultValue("def44");
470 status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop44, JsonPresentationFields.NAME);
471 assertSame(status, StorageOperationStatus.OK);
473 PropertyDataDefinition capProp = new PropertyDataDefinition();
474 capProp.setName("capProp");
475 capProp.setDefaultValue("capPropDef");
477 MapDataDefinition dataToCreate = new MapPropertiesDataDefinition();
478 dataToCreate.put("capProp", capProp);
480 Map<String, MapDataDefinition> capProps = new HashMap();
481 capProps.put("capName", dataToCreate);
483 Either<GraphVertex, StorageOperationStatus> res = nodeTypeOperation.associateElementToData(vfVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES, EdgeLabelEnum.CAPABILITIES_PROPERTIES, capProps);
485 // exportGraphMl(titanDao.getGraph().left().value());
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);
494 private GraphVertex createRootNodeType() {
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);
509 List<CategoryDefinition> categories = new ArrayList<>();
510 CategoryDefinition cat = new CategoryDefinition();
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);
520 List<String> derivedFrom = new ArrayList<>();
521 vf.setDerivedFrom(derivedFrom);
523 Map<String, PropertyDataDefinition> properties = new HashMap<>();
524 PropertyDataDefinition prop1 = new PropertyDataDefinition();
525 prop1.setName("derived1");
526 prop1.setDefaultValue("deriveddef1");
528 properties.put("derived1", prop1);
530 PropertyDataDefinition prop2 = new PropertyDataDefinition();
531 prop2.setUniqueId("derived2");
532 prop2.setName("deriveddef2");
533 properties.put("derived2", prop2);
535 PropertyDataDefinition prop3 = new PropertyDataDefinition();
536 prop3.setName("derived3");
537 prop3.setDefaultValue("deriveddef3");
538 properties.put("derived3", prop3);
540 vf.setProperties(properties);
541 vf.setComponentType(ComponentTypeEnum.RESOURCE);
542 Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
543 assertTrue(createVFRes.isLeft());
545 Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createVFRes.left().value().getUniqueId());
546 assertTrue(getNodeTyeRes.isLeft());
547 return getNodeTyeRes.left().value();
550 private void createUsers() {
552 GraphVertex ownerV = new GraphVertex(VertexTypeEnum.USER);
553 ownerV.setUniqueId("user1");
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());
565 ownerVertex = createUserRes.left().value();
567 GraphVertex modifierV = new GraphVertex(VertexTypeEnum.USER);
568 modifierV.setUniqueId("user2");
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());
580 modifierVertex = createUserRes.left().value();
582 Either<GraphVertex, TitanOperationStatus> getOwnerRes = lifecycleOperation.findUser(ownerVertex.getUniqueId());
583 assertTrue(getOwnerRes.isLeft());
587 public void verifyInCatalogData(int expected, List<String> expectedIds) {
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())));
600 public void teardown() {
604 private void clearGraph() {
605 Either<TitanGraph, TitanOperationStatus> graphResult = titanDao.getGraph();
606 TitanGraph graph = graphResult.left().value();
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();