2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.model.operations.impl;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertSame;
25 import static org.junit.Assert.assertTrue;
27 import fj.data.Either;
28 import java.io.BufferedOutputStream;
30 import java.io.FileOutputStream;
31 import java.io.OutputStream;
32 import java.util.ArrayList;
33 import java.util.HashMap;
34 import java.util.Iterator;
35 import java.util.List;
37 import org.apache.tinkerpop.gremlin.structure.io.IoCore;
38 import org.janusgraph.core.JanusGraph;
39 import org.janusgraph.core.JanusGraphVertex;
40 import org.junit.Rule;
41 import org.junit.jupiter.api.AfterEach;
42 import org.junit.jupiter.api.BeforeAll;
43 import org.junit.jupiter.api.BeforeEach;
44 import org.junit.jupiter.api.Test;
45 import org.junit.rules.TestName;
46 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
47 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
48 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
49 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
50 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
51 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
52 import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
53 import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
54 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
55 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
56 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
57 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
58 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
59 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
60 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
61 import org.openecomp.sdc.be.model.LifecycleStateEnum;
62 import org.openecomp.sdc.be.model.ModelTestBase;
63 import org.openecomp.sdc.be.model.User;
64 import org.openecomp.sdc.be.model.catalog.CatalogComponent;
65 import org.openecomp.sdc.be.model.category.CategoryDefinition;
66 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
67 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.NodeType;
68 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
69 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
70 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeTypeOperation;
71 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.TopologyTemplateOperation;
72 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementLifecycleOperation;
73 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.GraphTestUtils;
74 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
75 import org.openecomp.sdc.common.util.ValidationUtils;
76 import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
78 @SpringJUnitConfig(locations = "classpath:application-context-test.xml")
79 public class ToscaElementLifecycleOperationTest extends ModelTestBase {
82 public TestName name = new TestName();
83 @javax.annotation.Resource
84 protected JanusGraphDao janusGraphDao;
85 String categoryName = "category";
86 String subcategory = "mycategory";
87 String outputDirectory = "C:\\Output";
88 @javax.annotation.Resource
89 private NodeTypeOperation nodeTypeOperation;
90 @javax.annotation.Resource
91 private TopologyTemplateOperation topologyTemplateOperation;
92 @javax.annotation.Resource
93 private ToscaElementLifecycleOperation lifecycleOperation;
94 private GraphVertex ownerVertex;
95 private GraphVertex modifierVertex;
96 private GraphVertex vfVertex;
97 private GraphVertex serviceVertex;
98 private GraphVertex rootVertex;
101 public static void initLifecycleOperation() {
102 ModelTestBase.init();
106 public void setupBefore() {
109 createResourceCategory();
110 createServiceCategory();
111 GraphTestUtils.createRootCatalogVertex(janusGraphDao);
112 rootVertex = createRootNodeType();
113 createNodeType("firstVf");
114 serviceVertex = createTopologyTemplate("firstService");
118 public void lifecycleTest() {
119 Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.checkinToscaELement(
120 LifecycleStateEnum.findState((String) vfVertex.getMetadataProperty(GraphPropertyEnum.STATE)), vfVertex.getUniqueId(),
121 modifierVertex.getUniqueId(),
122 ownerVertex.getUniqueId());
123 StorageOperationStatus status;
125 assertTrue(res.isLeft());
129 verifyInCatalogData(3, null);
131 String id = res.left().value().getUniqueId();
133 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
134 assertTrue(res.isLeft());
135 id = res.left().value().getUniqueId();
137 verifyInCatalogData(3, null);
139 PropertyDataDefinition prop55 = new PropertyDataDefinition();
140 prop55.setName("prop55");
141 prop55.setDefaultValue("def55");
143 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop55,
144 JsonPresentationFields.NAME);
145 assertSame(status, StorageOperationStatus.OK);
147 CapabilityDataDefinition cap1 = new CapabilityDataDefinition();
148 cap1.setName("cap1");
149 cap1.setDescription("create");
150 cap1.setUniqueId(UniqueIdBuilder.buildCapabilityUid(id, "cap1"));
152 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILITIES, cap1,
153 JsonPresentationFields.NAME);
154 assertSame(status, StorageOperationStatus.OK);
156 res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, id, ownerVertex.getUniqueId(),
157 ownerVertex.getUniqueId());
158 assertTrue(res.isLeft());
159 id = res.left().value().getUniqueId();
161 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
162 assertTrue(res.isLeft());
163 id = res.left().value().getUniqueId();
165 prop55.setDefaultValue("AAAAAAAA");
166 status = nodeTypeOperation.updateToscaDataOfToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop55,
167 JsonPresentationFields.NAME);
168 assertSame(status, StorageOperationStatus.OK);
170 cap1.setDescription("update");
172 status = nodeTypeOperation.updateToscaDataOfToscaElement(id, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILITIES, cap1,
173 JsonPresentationFields.NAME);
174 assertSame(status, StorageOperationStatus.OK);
176 PropertyDataDefinition prop66 = new PropertyDataDefinition();
177 prop66.setName("prop66");
178 prop66.setDefaultValue("def66");
180 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop66,
181 JsonPresentationFields.NAME);
182 assertSame(status, StorageOperationStatus.OK);
184 res = lifecycleOperation.certifyToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
185 assertTrue(res.isLeft());
186 id = res.left().value().getUniqueId();
188 verifyInCatalogData(3, null);
190 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
191 assertTrue(res.isLeft());
192 id = res.left().value().getUniqueId();
194 verifyInCatalogData(4, null);
196 PropertyDataDefinition prop77 = new PropertyDataDefinition();
197 prop77.setName("prop77");
198 prop77.setDefaultValue("def77");
200 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop77,
201 JsonPresentationFields.NAME);
202 assertSame(status, StorageOperationStatus.OK);
204 res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, id, ownerVertex.getUniqueId(),
205 ownerVertex.getUniqueId());
206 assertTrue(res.isLeft());
207 id = res.left().value().getUniqueId();
209 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
210 assertTrue(res.isLeft());
211 id = res.left().value().getUniqueId();
213 PropertyDataDefinition prop88 = new PropertyDataDefinition();
214 prop88.setName("prop88");
215 prop88.setDefaultValue("def88");
217 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop88,
218 JsonPresentationFields.NAME);
219 assertSame(status, StorageOperationStatus.OK);
221 res = lifecycleOperation.certifyToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
222 assertTrue(res.isLeft());
223 id = res.left().value().getUniqueId();
224 verifyInCatalogData(3, null);
226 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
227 assertTrue(res.isLeft());
228 id = res.left().value().getUniqueId();
230 verifyInCatalogData(4, null);
232 PropertyDataDefinition prop99 = new PropertyDataDefinition();
233 prop99.setName("prop99");
234 prop99.setDefaultValue("def99");
236 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop99,
237 JsonPresentationFields.NAME);
238 assertSame(status, StorageOperationStatus.OK);
240 status = nodeTypeOperation.deleteToscaDataElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, "prop99",
241 JsonPresentationFields.NAME);
242 assertSame(status, StorageOperationStatus.OK);
244 verifyInCatalogData(4, null);
248 public void serviceConformanceLevelTest() {
249 Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.checkinToscaELement(
250 LifecycleStateEnum.findState((String) serviceVertex.getMetadataProperty(GraphPropertyEnum.STATE)), serviceVertex.getUniqueId(),
251 modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
253 assertTrue(res.isLeft());
254 String id = res.left().value().getUniqueId();
256 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
257 assertTrue(res.isLeft());
259 String conformanceLevel = res.left().value().getMetadataValue(JsonPresentationFields.CONFORMANCE_LEVEL).toString();
260 assertEquals(conformanceLevel, ModelTestBase.configurationManager.getConfiguration().getToscaConformanceLevel());
264 public void catalogTest() {
265 // start position - 3 in catalog
266 List<String> expectedIds = new ArrayList<>();
267 expectedIds.add(rootVertex.getUniqueId());
268 expectedIds.add(vfVertex.getUniqueId());
269 expectedIds.add(serviceVertex.getUniqueId());
271 verifyInCatalogData(3, expectedIds);
273 GraphVertex vertex4 = createTopologyTemplate("topTemp4");
274 expectedIds.add(vertex4.getUniqueId());
275 verifyInCatalogData(4, expectedIds);
277 lifecycleOperation.undoCheckout(vertex4.getUniqueId(), null);
278 expectedIds.remove(vertex4.getUniqueId());
279 verifyInCatalogData(3, expectedIds);
281 vertex4 = createTopologyTemplate("topTemp4");
282 expectedIds.add(vertex4.getUniqueId());
283 verifyInCatalogData(4, expectedIds);
285 lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) vertex4.getMetadataProperty(GraphPropertyEnum.STATE)),
286 vertex4.getUniqueId(), modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
287 Either<ToscaElement, StorageOperationStatus> certifyToscaElement = lifecycleOperation.certifyToscaElement(vertex4.getUniqueId(),
288 modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
289 assertTrue(certifyToscaElement.isLeft());
290 expectedIds.remove(vertex4.getUniqueId());
291 String certifiedId = certifyToscaElement.left().value().getUniqueId();
292 expectedIds.add(certifiedId);
293 verifyInCatalogData(4, expectedIds);
295 Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.checkoutToscaElement(certifiedId, modifierVertex.getUniqueId(),
296 ownerVertex.getUniqueId());
297 assertTrue(certifyToscaElement.isLeft());
298 expectedIds.add(res.left().value().getUniqueId());
299 verifyInCatalogData(5, expectedIds);
303 public void testGetToscaElOwner_Fail() {
304 Either<User, StorageOperationStatus> result;
305 String toscaEleId = "toscaElementId";
306 janusGraphDao.getVertexById(toscaEleId, JsonParseFlagEnum.NoParse);
307 result = lifecycleOperation.getToscaElementOwner(toscaEleId);
308 assertEquals(StorageOperationStatus.NOT_FOUND, result.right().value());
311 private void createResourceCategory() {
313 GraphVertex cat = new GraphVertex(VertexTypeEnum.RESOURCE_CATEGORY);
314 Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
315 String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.RESOURCE_CATEGORY);
316 cat.setUniqueId(catId);
317 metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, catId);
318 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_CATEGORY.getName());
319 metadataProperties.put(GraphPropertyEnum.NAME, categoryName);
320 metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
321 metadataProperties.put(GraphPropertyEnum.METADATA_KEYS, "[]");
322 metadataProperties.put(GraphPropertyEnum.MODEL, "[]");
323 cat.setMetadataProperties(metadataProperties);
324 cat.updateMetadataJsonWithCurrentMetadataProperties();
326 GraphVertex subCat = new GraphVertex(VertexTypeEnum.RESOURCE_SUBCATEGORY);
327 metadataProperties = new HashMap<>();
328 String subCatId = UniqueIdBuilder.buildSubCategoryUid(cat.getUniqueId(), subcategory);
329 subCat.setUniqueId(subCatId);
330 metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, subCatId);
331 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_SUBCATEGORY.getName());
332 metadataProperties.put(GraphPropertyEnum.NAME, subcategory);
333 metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(subcategory));
334 metadataProperties.put(GraphPropertyEnum.METADATA_KEYS, "[]");
335 subCat.setMetadataProperties(metadataProperties);
336 subCat.updateMetadataJsonWithCurrentMetadataProperties();
338 Either<GraphVertex, JanusGraphOperationStatus> catRes = janusGraphDao.createVertex(cat);
340 Either<GraphVertex, JanusGraphOperationStatus> subCatRes = janusGraphDao.createVertex(subCat);
342 JanusGraphOperationStatus
343 status = janusGraphDao
344 .createEdge(catRes.left().value().getVertex(), subCatRes.left().value().getVertex(), EdgeLabelEnum.SUB_CATEGORY, new HashMap<>());
345 assertEquals(JanusGraphOperationStatus.OK, status);
348 private void createServiceCategory() {
350 GraphVertex cat = new GraphVertex(VertexTypeEnum.SERVICE_CATEGORY);
351 Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
352 String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
353 cat.setUniqueId(catId);
354 metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, catId);
355 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.SERVICE_CATEGORY.getName());
356 metadataProperties.put(GraphPropertyEnum.NAME, categoryName);
357 metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
358 metadataProperties.put(GraphPropertyEnum.METADATA_KEYS, "[]");
359 metadataProperties.put(GraphPropertyEnum.MODEL, "[]");
360 cat.setMetadataProperties(metadataProperties);
361 cat.updateMetadataJsonWithCurrentMetadataProperties();
363 Either<GraphVertex, JanusGraphOperationStatus> catRes = janusGraphDao.createVertex(cat);
365 assertTrue(catRes.isLeft());
368 private GraphVertex createTopologyTemplate(String name) {
370 TopologyTemplate service = new TopologyTemplate();
371 String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
372 service.setUniqueId(uniqueId);
373 service.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
374 service.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), name);
375 service.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
376 service.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "0.1");
377 service.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VF.name());
378 service.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(), ComponentTypeEnum.RESOURCE);
379 List<CategoryDefinition> categories = new ArrayList<>();
380 CategoryDefinition cat = new CategoryDefinition();
382 cat.setName(categoryName);
383 service.setCategories(categories);
385 service.setComponentType(ComponentTypeEnum.SERVICE);
386 Either<TopologyTemplate, StorageOperationStatus> createRes = topologyTemplateOperation.createTopologyTemplate(service);
387 assertTrue(createRes.isLeft());
389 Either<GraphVertex, JanusGraphOperationStatus> getNodeTyeRes = janusGraphDao
390 .getVertexById(createRes.left().value().getUniqueId());
391 assertTrue(getNodeTyeRes.isLeft());
393 // serviceVertex = getNodeTyeRes.left().value();
395 return getNodeTyeRes.left().value();
398 private <T extends ToscaDataDefinition> NodeType createNodeType(String nodeTypeName) {
400 NodeType vf = new NodeType();
401 String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
402 vf.setUniqueId(uniqueId);
403 vf.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
404 vf.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), nodeTypeName);
405 vf.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
406 vf.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "0.1");
407 vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VF.name());
408 vf.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(), ComponentTypeEnum.RESOURCE);
409 List<CategoryDefinition> categories = new ArrayList<>();
410 CategoryDefinition cat = new CategoryDefinition();
412 cat.setName(categoryName);
413 List<SubCategoryDefinition> subCategories = new ArrayList<>();
414 SubCategoryDefinition subCat = new SubCategoryDefinition();
415 subCat.setName(subcategory);
416 subCategories.add(subCat);
417 cat.setSubcategories(subCategories);
418 vf.setCategories(categories);
420 List<String> derivedFrom = new ArrayList<>();
421 derivedFrom.add("root");
422 vf.setDerivedFrom(derivedFrom);
424 // Map<String, PropertyDataDefinition> properties = new HashMap<>();
425 // PropertyDataDefinition prop1 = new PropertyDataDefinition();
426 // prop1.setName("prop1");
427 // prop1.setDefaultValue("def1");
429 // properties.put("prop1", prop1);
431 // PropertyDataDefinition prop2 = new PropertyDataDefinition();
432 // prop2.setName("prop2");
433 // prop2.setDefaultValue("def2");
434 // properties.put("prop2", prop2);
436 // PropertyDataDefinition prop3 = new PropertyDataDefinition();
437 // prop3.setName("prop3");
438 // prop3.setDefaultValue("def3");
439 // properties.put("prop3", prop3);
441 // vf.setProperties(properties);
442 vf.setComponentType(ComponentTypeEnum.RESOURCE);
443 Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
444 assertTrue(createVFRes.isLeft());
446 Either<GraphVertex, JanusGraphOperationStatus> getNodeTyeRes = janusGraphDao
447 .getVertexById(createVFRes.left().value().getUniqueId());
448 assertTrue(getNodeTyeRes.isLeft());
450 vfVertex = getNodeTyeRes.left().value();
452 List<PropertyDataDefinition> addProperties = new ArrayList<>();
453 PropertyDataDefinition prop11 = new PropertyDataDefinition();
454 prop11.setName("prop11");
455 prop11.setDefaultValue("def11");
457 addProperties.add(prop11);
459 PropertyDataDefinition prop22 = new PropertyDataDefinition();
460 prop22.setName("prop22");
461 prop22.setDefaultValue("def22");
462 addProperties.add(prop22);
464 StorageOperationStatus status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES,
465 addProperties, JsonPresentationFields.NAME);
466 assertSame(status, StorageOperationStatus.OK);
468 PropertyDataDefinition prop33 = new PropertyDataDefinition();
469 prop33.setName("prop33");
470 prop33.setDefaultValue("def33");
472 status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop33,
473 JsonPresentationFields.NAME);
474 assertSame(status, StorageOperationStatus.OK);
476 PropertyDataDefinition prop44 = new PropertyDataDefinition();
477 prop44.setName("prop44");
478 prop44.setDefaultValue("def44");
480 status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop44,
481 JsonPresentationFields.NAME);
482 assertSame(status, StorageOperationStatus.OK);
484 PropertyDataDefinition capProp = new PropertyDataDefinition();
485 capProp.setName("capProp");
486 capProp.setDefaultValue("capPropDef");
488 MapDataDefinition dataToCreate = new MapPropertiesDataDefinition();
489 dataToCreate.put("capProp", capProp);
491 Map<String, MapDataDefinition> capProps = new HashMap();
492 capProps.put("capName", dataToCreate);
494 Either<GraphVertex, StorageOperationStatus> res = nodeTypeOperation.associateElementToData(vfVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES,
495 EdgeLabelEnum.CAPABILITIES_PROPERTIES, capProps);
497 // exportGraphMl(janusGraphDao.getGraph().left().value());
499 List<String> pathKeys = new ArrayList<>();
500 pathKeys.add("capName");
501 capProp.setDefaultValue("BBBB");
502 status = nodeTypeOperation.updateToscaDataDeepElementOfToscaElement(vfVertex, EdgeLabelEnum.CAPABILITIES_PROPERTIES,
503 VertexTypeEnum.CAPABILITIES_PROPERTIES, capProp, pathKeys, JsonPresentationFields.NAME);
507 private GraphVertex createRootNodeType() {
509 NodeType vf = new NodeType();
510 String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
511 vf.setUniqueId(uniqueId);
512 vf.setComponentType(ComponentTypeEnum.RESOURCE);
513 vf.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
514 vf.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), "root");
515 vf.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
516 vf.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "1.0");
517 vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VFC.name());
518 vf.getMetadata().put(JsonPresentationFields.LIFECYCLE_STATE.getPresentation(), LifecycleStateEnum.CERTIFIED.name());
519 vf.getMetadata().put(JsonPresentationFields.TOSCA_RESOURCE_NAME.getPresentation(), "root");
520 vf.getMetadata().put(JsonPresentationFields.HIGHEST_VERSION.getPresentation(), true);
522 List<CategoryDefinition> categories = new ArrayList<>();
523 CategoryDefinition cat = new CategoryDefinition();
525 cat.setName(categoryName);
526 List<SubCategoryDefinition> subCategories = new ArrayList<>();
527 SubCategoryDefinition subCat = new SubCategoryDefinition();
528 subCat.setName(subcategory);
529 subCategories.add(subCat);
530 cat.setSubcategories(subCategories);
531 vf.setCategories(categories);
533 List<String> derivedFrom = new ArrayList<>();
534 vf.setDerivedFrom(derivedFrom);
536 Map<String, PropertyDataDefinition> properties = new HashMap<>();
537 PropertyDataDefinition prop1 = new PropertyDataDefinition();
538 prop1.setName("derived1");
539 prop1.setDefaultValue("deriveddef1");
541 properties.put("derived1", prop1);
543 PropertyDataDefinition prop2 = new PropertyDataDefinition();
544 prop2.setUniqueId("derived2");
545 prop2.setName("deriveddef2");
546 properties.put("derived2", prop2);
548 PropertyDataDefinition prop3 = new PropertyDataDefinition();
549 prop3.setName("derived3");
550 prop3.setDefaultValue("deriveddef3");
551 properties.put("derived3", prop3);
553 vf.setProperties(properties);
554 vf.setComponentType(ComponentTypeEnum.RESOURCE);
555 Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
556 assertTrue(createVFRes.isLeft());
558 Either<GraphVertex, JanusGraphOperationStatus> getNodeTyeRes = janusGraphDao
559 .getVertexById(createVFRes.left().value().getUniqueId());
560 assertTrue(getNodeTyeRes.isLeft());
561 return getNodeTyeRes.left().value();
564 private void createUsers() {
566 GraphVertex ownerV = new GraphVertex(VertexTypeEnum.USER);
567 ownerV.setUniqueId("user1");
569 Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
570 metadataProperties.put(GraphPropertyEnum.USERID, ownerV.getUniqueId());
571 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
572 metadataProperties.put(GraphPropertyEnum.NAME, "user1");
573 ownerV.setMetadataProperties(metadataProperties);
574 ownerV.updateMetadataJsonWithCurrentMetadataProperties();
575 ownerV.setJson(new HashMap<>());
576 Either<GraphVertex, JanusGraphOperationStatus> createUserRes = janusGraphDao.createVertex(ownerV);
577 assertTrue(createUserRes.isLeft());
579 ownerVertex = createUserRes.left().value();
581 GraphVertex modifierV = new GraphVertex(VertexTypeEnum.USER);
582 modifierV.setUniqueId("user2");
584 metadataProperties = new HashMap<>();
585 metadataProperties.put(GraphPropertyEnum.USERID, modifierV.getUniqueId());
586 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
587 metadataProperties.put(GraphPropertyEnum.NAME, "user2");
588 modifierV.setMetadataProperties(metadataProperties);
589 modifierV.updateMetadataJsonWithCurrentMetadataProperties();
590 modifierV.setJson(new HashMap<>());
591 createUserRes = janusGraphDao.createVertex(modifierV);
592 assertTrue(createUserRes.isLeft());
594 modifierVertex = createUserRes.left().value();
596 Either<GraphVertex, JanusGraphOperationStatus> getOwnerRes = lifecycleOperation.findUser(ownerVertex.getUniqueId());
597 assertTrue(getOwnerRes.isLeft());
601 public void verifyInCatalogData(int expected, List<String> expectedIds) {
603 Either<List<CatalogComponent>, StorageOperationStatus> highestResourcesRes = topologyTemplateOperation.getElementCatalogData(true, null);
604 assertTrue(highestResourcesRes.isLeft());
605 List<CatalogComponent> highestResources = highestResourcesRes.left().value();
606 // calculate expected count value
607 assertEquals(expected, highestResources.stream().count());
608 if (expectedIds != null) {
609 highestResources.forEach(a -> assertTrue(expectedIds.contains(a.getUniqueId())));
614 public void teardown() {
618 private void clearGraph() {
619 Either<JanusGraph, JanusGraphOperationStatus> graphResult = janusGraphDao.getJanusGraphClient().getGraph();
620 JanusGraph graph = graphResult.left().value();
622 Iterable<JanusGraphVertex> vertices = graph.query().vertices();
623 if (vertices != null) {
624 Iterator<JanusGraphVertex> iterator = vertices.iterator();
625 while (iterator.hasNext()) {
626 JanusGraphVertex vertex = iterator.next();
630 janusGraphDao.commit();
633 private String exportGraphMl(JanusGraph graph) {
634 String result = null;
635 String outputFile = outputDirectory + File.separator + "exportGraph." + System.currentTimeMillis() + ".graphml";
637 try (final OutputStream os = new BufferedOutputStream(new FileOutputStream(outputFile))) {
638 graph.io(IoCore.graphml()).writer().normalize(true).create().writeGraph(os, graph);
642 } catch (Exception e) {
643 graph.tx().rollback();