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.After;
41 import org.junit.Before;
42 import org.junit.BeforeClass;
43 import org.junit.Rule;
44 import org.junit.Test;
45 import org.junit.rules.TestName;
46 import org.junit.runner.RunWith;
47 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
48 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
49 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
50 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
51 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
52 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
53 import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
54 import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
55 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
56 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
57 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
58 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
59 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
60 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
61 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
62 import org.openecomp.sdc.be.model.LifecycleStateEnum;
63 import org.openecomp.sdc.be.model.ModelTestBase;
64 import org.openecomp.sdc.be.model.User;
65 import org.openecomp.sdc.be.model.catalog.CatalogComponent;
66 import org.openecomp.sdc.be.model.category.CategoryDefinition;
67 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
68 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.NodeType;
69 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
70 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
71 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeTypeOperation;
72 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.TopologyTemplateOperation;
73 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementLifecycleOperation;
74 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.GraphTestUtils;
75 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
76 import org.openecomp.sdc.common.util.ValidationUtils;
77 import org.springframework.test.context.ContextConfiguration;
78 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
80 @RunWith(SpringJUnit4ClassRunner.class)
81 @ContextConfiguration("classpath:application-context-test.xml")
82 public class ToscaElementLifecycleOperationTest extends ModelTestBase {
84 @javax.annotation.Resource
85 protected JanusGraphDao janusGraphDao;
87 @javax.annotation.Resource
88 private NodeTypeOperation nodeTypeOperation;
90 @javax.annotation.Resource
91 private TopologyTemplateOperation topologyTemplateOperation;
93 @javax.annotation.Resource
94 private ToscaElementLifecycleOperation lifecycleOperation;
96 String categoryName = "category";
97 String subcategory = "mycategory";
98 String outputDirectory = "C:\\Output";
101 public TestName name = new TestName();
104 public static void initLifecycleOperation() {
105 ModelTestBase.init();
108 private GraphVertex ownerVertex;
109 private GraphVertex modifierVertex;
110 private GraphVertex vfVertex;
111 private GraphVertex serviceVertex;
112 private GraphVertex rootVertex;
115 public void setupBefore() {
118 createResourceCategory();
119 createServiceCategory();
120 GraphTestUtils.createRootCatalogVertex(janusGraphDao);
121 rootVertex = createRootNodeType();
122 createNodeType("firstVf");
123 serviceVertex = createTopologyTemplate("firstService");
127 public void lifecycleTest() {
128 Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) vfVertex.getMetadataProperty(GraphPropertyEnum.STATE)), vfVertex.getUniqueId(), modifierVertex.getUniqueId(),
129 ownerVertex.getUniqueId());
130 StorageOperationStatus status;
132 assertTrue(res.isLeft());
136 verifyInCatalogData(3, null);
138 String id = res.left().value().getUniqueId();
140 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
141 assertTrue(res.isLeft());
142 id = res.left().value().getUniqueId();
144 verifyInCatalogData(3, null);
146 PropertyDataDefinition prop55 = new PropertyDataDefinition();
147 prop55.setName("prop55");
148 prop55.setDefaultValue("def55");
150 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop55, JsonPresentationFields.NAME);
151 assertSame(status, StorageOperationStatus.OK);
153 CapabilityDataDefinition cap1 = new CapabilityDataDefinition();
154 cap1.setName("cap1");
155 cap1.setDescription("create");
156 cap1.setUniqueId(UniqueIdBuilder.buildCapabilityUid(id, "cap1"));
158 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILITIES, cap1, JsonPresentationFields.NAME);
159 assertSame(status, StorageOperationStatus.OK);
161 res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
162 assertTrue(res.isLeft());
163 id = res.left().value().getUniqueId();
165 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
166 assertTrue(res.isLeft());
167 id = res.left().value().getUniqueId();
169 prop55.setDefaultValue("AAAAAAAA");
170 status = nodeTypeOperation.updateToscaDataOfToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop55, JsonPresentationFields.NAME);
171 assertSame(status, StorageOperationStatus.OK);
173 cap1.setDescription("update");
175 status = nodeTypeOperation.updateToscaDataOfToscaElement(id, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILITIES, cap1, JsonPresentationFields.NAME);
176 assertSame(status, StorageOperationStatus.OK);
178 PropertyDataDefinition prop66 = new PropertyDataDefinition();
179 prop66.setName("prop66");
180 prop66.setDefaultValue("def66");
182 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop66, JsonPresentationFields.NAME);
183 assertSame(status, StorageOperationStatus.OK);
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.certifyToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
220 assertTrue(res.isLeft());
221 id = res.left().value().getUniqueId();
222 verifyInCatalogData(3, null);
224 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
225 assertTrue(res.isLeft());
226 id = res.left().value().getUniqueId();
228 verifyInCatalogData(4, null);
230 PropertyDataDefinition prop99 = new PropertyDataDefinition();
231 prop99.setName("prop99");
232 prop99.setDefaultValue("def99");
234 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop99, JsonPresentationFields.NAME);
235 assertSame(status, StorageOperationStatus.OK);
237 status = nodeTypeOperation.deleteToscaDataElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, "prop99", JsonPresentationFields.NAME);
238 assertSame(status, StorageOperationStatus.OK);
240 verifyInCatalogData(4, null);
244 public void serviceConformanceLevelTest() {
245 Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) serviceVertex.getMetadataProperty(GraphPropertyEnum.STATE)), serviceVertex.getUniqueId(),
246 modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
248 assertTrue(res.isLeft());
249 String id = res.left().value().getUniqueId();
251 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
252 assertTrue(res.isLeft());
254 String conformanceLevel = res.left().value().getMetadataValue(JsonPresentationFields.CONFORMANCE_LEVEL).toString();
255 assertEquals(conformanceLevel, ModelTestBase.configurationManager.getConfiguration().getToscaConformanceLevel());
259 public void catalogTest() {
260 // start position - 3 in catalog
261 List<String> expectedIds = new ArrayList<>();
262 expectedIds.add(rootVertex.getUniqueId());
263 expectedIds.add(vfVertex.getUniqueId());
264 expectedIds.add(serviceVertex.getUniqueId());
266 verifyInCatalogData(3, expectedIds);
268 GraphVertex vertex4 = createTopologyTemplate("topTemp4");
269 expectedIds.add(vertex4.getUniqueId());
270 verifyInCatalogData(4, expectedIds);
272 lifecycleOperation.undoCheckout(vertex4.getUniqueId(), null);
273 expectedIds.remove(vertex4.getUniqueId());
274 verifyInCatalogData(3, expectedIds);
276 vertex4 = createTopologyTemplate("topTemp4");
277 expectedIds.add(vertex4.getUniqueId());
278 verifyInCatalogData(4, expectedIds);
280 lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) vertex4.getMetadataProperty(GraphPropertyEnum.STATE)), vertex4.getUniqueId(), modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
281 Either<ToscaElement, StorageOperationStatus> certifyToscaElement = lifecycleOperation.certifyToscaElement(vertex4.getUniqueId(), modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
282 assertTrue(certifyToscaElement.isLeft());
283 expectedIds.remove(vertex4.getUniqueId());
284 String certifiedId = certifyToscaElement.left().value().getUniqueId();
285 expectedIds.add(certifiedId);
286 verifyInCatalogData(4, expectedIds);
288 Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.checkoutToscaElement(certifiedId, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
289 assertTrue(certifyToscaElement.isLeft());
290 expectedIds.add(res.left().value().getUniqueId());
291 verifyInCatalogData(5, expectedIds);
295 public void testGetToscaElOwner_Fail(){
296 Either<User, StorageOperationStatus> result;
297 String toscaEleId = "toscaElementId";
298 janusGraphDao.getVertexById(toscaEleId, JsonParseFlagEnum.NoParse);
299 result = lifecycleOperation.getToscaElementOwner(toscaEleId);
300 assertEquals(StorageOperationStatus.NOT_FOUND, result.right().value());
303 private void createResourceCategory() {
305 GraphVertex cat = new GraphVertex(VertexTypeEnum.RESOURCE_CATEGORY);
306 Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
307 String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.RESOURCE_CATEGORY);
308 cat.setUniqueId(catId);
309 metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, catId);
310 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_CATEGORY.getName());
311 metadataProperties.put(GraphPropertyEnum.NAME, categoryName);
312 metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
313 metadataProperties.put(GraphPropertyEnum.METADATA_KEYS, "[]");
314 metadataProperties.put(GraphPropertyEnum.MODEL, "[]");
315 cat.setMetadataProperties(metadataProperties);
316 cat.updateMetadataJsonWithCurrentMetadataProperties();
318 GraphVertex subCat = new GraphVertex(VertexTypeEnum.RESOURCE_SUBCATEGORY);
319 metadataProperties = new HashMap<>();
320 String subCatId = UniqueIdBuilder.buildSubCategoryUid(cat.getUniqueId(), subcategory);
321 subCat.setUniqueId(subCatId);
322 metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, subCatId);
323 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_SUBCATEGORY.getName());
324 metadataProperties.put(GraphPropertyEnum.NAME, subcategory);
325 metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(subcategory));
326 metadataProperties.put(GraphPropertyEnum.METADATA_KEYS, "[]");
327 subCat.setMetadataProperties(metadataProperties);
328 subCat.updateMetadataJsonWithCurrentMetadataProperties();
330 Either<GraphVertex, JanusGraphOperationStatus> catRes = janusGraphDao.createVertex(cat);
332 Either<GraphVertex, JanusGraphOperationStatus> subCatRes = janusGraphDao.createVertex(subCat);
334 JanusGraphOperationStatus
335 status = janusGraphDao
336 .createEdge(catRes.left().value().getVertex(), subCatRes.left().value().getVertex(), EdgeLabelEnum.SUB_CATEGORY, new HashMap<>());
337 assertEquals(JanusGraphOperationStatus.OK, status);
340 private void createServiceCategory() {
342 GraphVertex cat = new GraphVertex(VertexTypeEnum.SERVICE_CATEGORY);
343 Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
344 String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
345 cat.setUniqueId(catId);
346 metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, catId);
347 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.SERVICE_CATEGORY.getName());
348 metadataProperties.put(GraphPropertyEnum.NAME, categoryName);
349 metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
350 metadataProperties.put(GraphPropertyEnum.METADATA_KEYS, "[]");
351 metadataProperties.put(GraphPropertyEnum.MODEL, "[]");
352 cat.setMetadataProperties(metadataProperties);
353 cat.updateMetadataJsonWithCurrentMetadataProperties();
355 Either<GraphVertex, JanusGraphOperationStatus> catRes = janusGraphDao.createVertex(cat);
357 assertTrue(catRes.isLeft());
360 private GraphVertex createTopologyTemplate(String name) {
362 TopologyTemplate service = new TopologyTemplate();
363 String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
364 service.setUniqueId(uniqueId);
365 service.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
366 service.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), name);
367 service.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
368 service.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "0.1");
369 service.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VF.name());
370 service.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(), ComponentTypeEnum.RESOURCE);
371 List<CategoryDefinition> categories = new ArrayList<>();
372 CategoryDefinition cat = new CategoryDefinition();
374 cat.setName(categoryName);
375 service.setCategories(categories);
377 service.setComponentType(ComponentTypeEnum.SERVICE);
378 Either<TopologyTemplate, StorageOperationStatus> createRes = topologyTemplateOperation.createTopologyTemplate(service);
379 assertTrue(createRes.isLeft());
381 Either<GraphVertex, JanusGraphOperationStatus> getNodeTyeRes = janusGraphDao
382 .getVertexById(createRes.left().value().getUniqueId());
383 assertTrue(getNodeTyeRes.isLeft());
385 // serviceVertex = getNodeTyeRes.left().value();
387 return getNodeTyeRes.left().value();
390 private <T extends ToscaDataDefinition> NodeType createNodeType(String nodeTypeName) {
392 NodeType vf = new NodeType();
393 String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
394 vf.setUniqueId(uniqueId);
395 vf.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
396 vf.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), nodeTypeName);
397 vf.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
398 vf.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "0.1");
399 vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VF.name());
400 vf.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(), ComponentTypeEnum.RESOURCE);
401 List<CategoryDefinition> categories = new ArrayList<>();
402 CategoryDefinition cat = new CategoryDefinition();
404 cat.setName(categoryName);
405 List<SubCategoryDefinition> subCategories = new ArrayList<>();
406 SubCategoryDefinition subCat = new SubCategoryDefinition();
407 subCat.setName(subcategory);
408 subCategories.add(subCat);
409 cat.setSubcategories(subCategories);
410 vf.setCategories(categories);
412 List<String> derivedFrom = new ArrayList<>();
413 derivedFrom.add("root");
414 vf.setDerivedFrom(derivedFrom);
416 // Map<String, PropertyDataDefinition> properties = new HashMap<>();
417 // PropertyDataDefinition prop1 = new PropertyDataDefinition();
418 // prop1.setName("prop1");
419 // prop1.setDefaultValue("def1");
421 // properties.put("prop1", prop1);
423 // PropertyDataDefinition prop2 = new PropertyDataDefinition();
424 // prop2.setName("prop2");
425 // prop2.setDefaultValue("def2");
426 // properties.put("prop2", prop2);
428 // PropertyDataDefinition prop3 = new PropertyDataDefinition();
429 // prop3.setName("prop3");
430 // prop3.setDefaultValue("def3");
431 // properties.put("prop3", prop3);
433 // vf.setProperties(properties);
434 vf.setComponentType(ComponentTypeEnum.RESOURCE);
435 Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
436 assertTrue(createVFRes.isLeft());
438 Either<GraphVertex, JanusGraphOperationStatus> getNodeTyeRes = janusGraphDao
439 .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(janusGraphDao.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, JanusGraphOperationStatus> getNodeTyeRes = janusGraphDao
546 .getVertexById(createVFRes.left().value().getUniqueId());
547 assertTrue(getNodeTyeRes.isLeft());
548 return getNodeTyeRes.left().value();
551 private void createUsers() {
553 GraphVertex ownerV = new GraphVertex(VertexTypeEnum.USER);
554 ownerV.setUniqueId("user1");
556 Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
557 metadataProperties.put(GraphPropertyEnum.USERID, ownerV.getUniqueId());
558 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
559 metadataProperties.put(GraphPropertyEnum.NAME, "user1");
560 ownerV.setMetadataProperties(metadataProperties);
561 ownerV.updateMetadataJsonWithCurrentMetadataProperties();
562 ownerV.setJson(new HashMap<>());
563 Either<GraphVertex, JanusGraphOperationStatus> createUserRes = janusGraphDao.createVertex(ownerV);
564 assertTrue(createUserRes.isLeft());
566 ownerVertex = createUserRes.left().value();
568 GraphVertex modifierV = new GraphVertex(VertexTypeEnum.USER);
569 modifierV.setUniqueId("user2");
571 metadataProperties = new HashMap<>();
572 metadataProperties.put(GraphPropertyEnum.USERID, modifierV.getUniqueId());
573 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
574 metadataProperties.put(GraphPropertyEnum.NAME, "user2");
575 modifierV.setMetadataProperties(metadataProperties);
576 modifierV.updateMetadataJsonWithCurrentMetadataProperties();
577 modifierV.setJson(new HashMap<>());
578 createUserRes = janusGraphDao.createVertex(modifierV);
579 assertTrue(createUserRes.isLeft());
581 modifierVertex = createUserRes.left().value();
583 Either<GraphVertex, JanusGraphOperationStatus> getOwnerRes = lifecycleOperation.findUser(ownerVertex.getUniqueId());
584 assertTrue(getOwnerRes.isLeft());
588 public void verifyInCatalogData(int expected, List<String> expectedIds) {
590 Either<List<CatalogComponent>, StorageOperationStatus> highestResourcesRes = topologyTemplateOperation.getElementCatalogData(true, null);
591 assertTrue(highestResourcesRes.isLeft());
592 List<CatalogComponent> highestResources = highestResourcesRes.left().value();
593 // calculate expected count value
594 assertEquals(expected, highestResources.stream().count());
595 if (expectedIds != null) {
596 highestResources.forEach(a -> assertTrue(expectedIds.contains(a.getUniqueId())));
601 public void teardown() {
605 private void clearGraph() {
606 Either<JanusGraph, JanusGraphOperationStatus> graphResult = janusGraphDao.getGraph();
607 JanusGraph graph = graphResult.left().value();
609 Iterable<JanusGraphVertex> vertices = graph.query().vertices();
610 if (vertices != null) {
611 Iterator<JanusGraphVertex> iterator = vertices.iterator();
612 while (iterator.hasNext()) {
613 JanusGraphVertex vertex = iterator.next();
617 janusGraphDao.commit();
620 private String exportGraphMl(JanusGraph graph) {
621 String result = null;
622 String outputFile = outputDirectory + File.separator + "exportGraph." + System.currentTimeMillis() + ".graphml";
624 try (final OutputStream os = new BufferedOutputStream(new FileOutputStream(outputFile))) {
625 graph.io(IoCore.graphml()).writer().normalize(true).create().writeGraph(os, graph);
629 } catch (Exception e) {
630 graph.tx().rollback();