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 org.janusgraph.core.JanusGraph;
24 import org.janusgraph.core.JanusGraphVertex;
25 import fj.data.Either;
26 import org.apache.tinkerpop.gremlin.structure.io.IoCore;
28 import org.junit.rules.TestName;
29 import org.junit.runner.RunWith;
30 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
31 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
32 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
33 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
34 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
35 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
36 import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
37 import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
38 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
39 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
40 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
41 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
42 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
43 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
44 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
45 import org.openecomp.sdc.be.model.LifecycleStateEnum;
46 import org.openecomp.sdc.be.model.ModelTestBase;
47 import org.openecomp.sdc.be.model.User;
48 import org.openecomp.sdc.be.model.catalog.CatalogComponent;
49 import org.openecomp.sdc.be.model.category.CategoryDefinition;
50 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
51 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.NodeType;
52 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
53 import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement;
54 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeTypeOperation;
55 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.TopologyTemplateOperation;
56 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementLifecycleOperation;
57 import org.openecomp.sdc.be.model.jsonjanusgraph.utils.GraphTestUtils;
58 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
59 import org.openecomp.sdc.common.util.ValidationUtils;
60 import org.springframework.test.context.ContextConfiguration;
61 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
63 import java.io.BufferedOutputStream;
65 import java.io.FileOutputStream;
66 import java.io.OutputStream;
69 import static org.junit.Assert.assertEquals;
70 import static org.junit.Assert.assertSame;
71 import static org.junit.Assert.assertTrue;
73 @RunWith(SpringJUnit4ClassRunner.class)
74 @ContextConfiguration("classpath:application-context-test.xml")
75 public class ToscaElementLifecycleOperationTest extends ModelTestBase {
77 @javax.annotation.Resource
78 protected JanusGraphDao janusGraphDao;
80 @javax.annotation.Resource
81 private NodeTypeOperation nodeTypeOperation;
83 @javax.annotation.Resource
84 private TopologyTemplateOperation topologyTemplateOperation;
86 @javax.annotation.Resource
87 private ToscaElementLifecycleOperation lifecycleOperation;
89 String categoryName = "category";
90 String subcategory = "mycategory";
91 String outputDirectory = "C:\\Output";
94 public TestName name = new TestName();
97 public static void initLifecycleOperation() {
101 private GraphVertex ownerVertex;
102 private GraphVertex modifierVertex;
103 private GraphVertex vfVertex;
104 private GraphVertex serviceVertex;
105 private GraphVertex rootVertex;
108 public void setupBefore() {
111 createResourceCategory();
112 createServiceCategory();
113 GraphTestUtils.createRootCatalogVertex(janusGraphDao);
114 rootVertex = createRootNodeType();
115 createNodeType("firstVf");
116 serviceVertex = createTopologyTemplate("firstService");
120 public void lifecycleTest() {
121 Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) vfVertex.getMetadataProperty(GraphPropertyEnum.STATE)), vfVertex.getUniqueId(), 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, JsonPresentationFields.NAME);
144 assertSame(status, StorageOperationStatus.OK);
146 CapabilityDataDefinition cap1 = new CapabilityDataDefinition();
147 cap1.setName("cap1");
148 cap1.setDescription("create");
149 cap1.setUniqueId(UniqueIdBuilder.buildCapabilityUid(id, "cap1"));
151 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILITIES, cap1, JsonPresentationFields.NAME);
152 assertSame(status, StorageOperationStatus.OK);
154 res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
155 assertTrue(res.isLeft());
156 id = res.left().value().getUniqueId();
158 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
159 assertTrue(res.isLeft());
160 id = res.left().value().getUniqueId();
162 prop55.setDefaultValue("AAAAAAAA");
163 status = nodeTypeOperation.updateToscaDataOfToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop55, JsonPresentationFields.NAME);
164 assertSame(status, StorageOperationStatus.OK);
166 cap1.setDescription("update");
168 status = nodeTypeOperation.updateToscaDataOfToscaElement(id, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILITIES, cap1, JsonPresentationFields.NAME);
169 assertSame(status, StorageOperationStatus.OK);
171 PropertyDataDefinition prop66 = new PropertyDataDefinition();
172 prop66.setName("prop66");
173 prop66.setDefaultValue("def66");
175 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop66, JsonPresentationFields.NAME);
176 assertSame(status, StorageOperationStatus.OK);
178 res = lifecycleOperation.certifyToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
179 assertTrue(res.isLeft());
180 id = res.left().value().getUniqueId();
182 verifyInCatalogData(3, null);
184 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
185 assertTrue(res.isLeft());
186 id = res.left().value().getUniqueId();
188 verifyInCatalogData(4, null);
190 PropertyDataDefinition prop77 = new PropertyDataDefinition();
191 prop77.setName("prop77");
192 prop77.setDefaultValue("def77");
194 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop77, JsonPresentationFields.NAME);
195 assertSame(status, StorageOperationStatus.OK);
197 res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
198 assertTrue(res.isLeft());
199 id = res.left().value().getUniqueId();
201 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
202 assertTrue(res.isLeft());
203 id = res.left().value().getUniqueId();
205 PropertyDataDefinition prop88 = new PropertyDataDefinition();
206 prop88.setName("prop88");
207 prop88.setDefaultValue("def88");
209 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop88, JsonPresentationFields.NAME);
210 assertSame(status, StorageOperationStatus.OK);
212 res = lifecycleOperation.certifyToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
213 assertTrue(res.isLeft());
214 id = res.left().value().getUniqueId();
215 verifyInCatalogData(3, null);
217 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId());
218 assertTrue(res.isLeft());
219 id = res.left().value().getUniqueId();
221 verifyInCatalogData(4, null);
223 PropertyDataDefinition prop99 = new PropertyDataDefinition();
224 prop99.setName("prop99");
225 prop99.setDefaultValue("def99");
227 status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop99, JsonPresentationFields.NAME);
228 assertSame(status, StorageOperationStatus.OK);
230 status = nodeTypeOperation.deleteToscaDataElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, "prop99", JsonPresentationFields.NAME);
231 assertSame(status, StorageOperationStatus.OK);
233 verifyInCatalogData(4, null);
237 public void serviceConformanceLevelTest() {
238 Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) serviceVertex.getMetadataProperty(GraphPropertyEnum.STATE)), serviceVertex.getUniqueId(),
239 modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
241 assertTrue(res.isLeft());
242 String id = res.left().value().getUniqueId();
244 res = lifecycleOperation.checkoutToscaElement(id, ownerVertex.getUniqueId(), modifierVertex.getUniqueId());
245 assertTrue(res.isLeft());
247 String conformanceLevel = res.left().value().getMetadataValue(JsonPresentationFields.CONFORMANCE_LEVEL).toString();
248 assertEquals(conformanceLevel, ModelTestBase.configurationManager.getConfiguration().getToscaConformanceLevel());
252 public void catalogTest() {
253 // start position - 3 in catalog
254 List<String> expectedIds = new ArrayList<>();
255 expectedIds.add(rootVertex.getUniqueId());
256 expectedIds.add(vfVertex.getUniqueId());
257 expectedIds.add(serviceVertex.getUniqueId());
259 verifyInCatalogData(3, expectedIds);
261 GraphVertex vertex4 = createTopologyTemplate("topTemp4");
262 expectedIds.add(vertex4.getUniqueId());
263 verifyInCatalogData(4, expectedIds);
265 lifecycleOperation.undoCheckout(vertex4.getUniqueId());
266 expectedIds.remove(vertex4.getUniqueId());
267 verifyInCatalogData(3, expectedIds);
269 vertex4 = createTopologyTemplate("topTemp4");
270 expectedIds.add(vertex4.getUniqueId());
271 verifyInCatalogData(4, expectedIds);
273 lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) vertex4.getMetadataProperty(GraphPropertyEnum.STATE)), vertex4.getUniqueId(), modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
274 Either<ToscaElement, StorageOperationStatus> certifyToscaElement = lifecycleOperation.certifyToscaElement(vertex4.getUniqueId(), modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
275 assertTrue(certifyToscaElement.isLeft());
276 expectedIds.remove(vertex4.getUniqueId());
277 String certifiedId = certifyToscaElement.left().value().getUniqueId();
278 expectedIds.add(certifiedId);
279 verifyInCatalogData(4, expectedIds);
281 Either<ToscaElement, StorageOperationStatus> res = lifecycleOperation.checkoutToscaElement(certifiedId, modifierVertex.getUniqueId(), ownerVertex.getUniqueId());
282 assertTrue(certifyToscaElement.isLeft());
283 expectedIds.add(res.left().value().getUniqueId());
284 verifyInCatalogData(5, expectedIds);
288 public void testGetToscaElOwner_Fail(){
289 Either<User, StorageOperationStatus> result;
290 String toscaEleId = "toscaElementId";
291 janusGraphDao.getVertexById(toscaEleId, JsonParseFlagEnum.NoParse);
292 result = lifecycleOperation.getToscaElementOwner(toscaEleId);
293 assertEquals(StorageOperationStatus.NOT_FOUND, result.right().value());
296 private void createResourceCategory() {
298 GraphVertex cat = new GraphVertex(VertexTypeEnum.RESOURCE_CATEGORY);
299 Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
300 String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.RESOURCE_CATEGORY);
301 cat.setUniqueId(catId);
302 metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, catId);
303 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_CATEGORY.getName());
304 metadataProperties.put(GraphPropertyEnum.NAME, categoryName);
305 metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
306 metadataProperties.put(GraphPropertyEnum.METADATA_KEYS, "[]");
307 cat.setMetadataProperties(metadataProperties);
308 cat.updateMetadataJsonWithCurrentMetadataProperties();
310 GraphVertex subCat = new GraphVertex(VertexTypeEnum.RESOURCE_SUBCATEGORY);
311 metadataProperties = new HashMap<>();
312 String subCatId = UniqueIdBuilder.buildSubCategoryUid(cat.getUniqueId(), subcategory);
313 subCat.setUniqueId(subCatId);
314 metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, subCatId);
315 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_SUBCATEGORY.getName());
316 metadataProperties.put(GraphPropertyEnum.NAME, subcategory);
317 metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(subcategory));
318 metadataProperties.put(GraphPropertyEnum.METADATA_KEYS, "[]");
319 subCat.setMetadataProperties(metadataProperties);
320 subCat.updateMetadataJsonWithCurrentMetadataProperties();
322 Either<GraphVertex, JanusGraphOperationStatus> catRes = janusGraphDao.createVertex(cat);
324 Either<GraphVertex, JanusGraphOperationStatus> subCatRes = janusGraphDao.createVertex(subCat);
326 JanusGraphOperationStatus
327 status = janusGraphDao
328 .createEdge(catRes.left().value().getVertex(), subCatRes.left().value().getVertex(), EdgeLabelEnum.SUB_CATEGORY, new HashMap<>());
329 assertEquals(JanusGraphOperationStatus.OK, status);
332 private void createServiceCategory() {
334 GraphVertex cat = new GraphVertex(VertexTypeEnum.SERVICE_CATEGORY);
335 Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
336 String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
337 cat.setUniqueId(catId);
338 metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, catId);
339 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.SERVICE_CATEGORY.getName());
340 metadataProperties.put(GraphPropertyEnum.NAME, categoryName);
341 metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
342 metadataProperties.put(GraphPropertyEnum.METADATA_KEYS, "[]");
343 cat.setMetadataProperties(metadataProperties);
344 cat.updateMetadataJsonWithCurrentMetadataProperties();
346 Either<GraphVertex, JanusGraphOperationStatus> catRes = janusGraphDao.createVertex(cat);
348 assertTrue(catRes.isLeft());
351 private GraphVertex createTopologyTemplate(String name) {
353 TopologyTemplate service = new TopologyTemplate();
354 String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
355 service.setUniqueId(uniqueId);
356 service.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
357 service.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), name);
358 service.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
359 service.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "0.1");
360 service.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VF.name());
361 service.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(), ComponentTypeEnum.RESOURCE);
362 List<CategoryDefinition> categories = new ArrayList<>();
363 CategoryDefinition cat = new CategoryDefinition();
365 cat.setName(categoryName);
366 service.setCategories(categories);
368 service.setComponentType(ComponentTypeEnum.SERVICE);
369 Either<TopologyTemplate, StorageOperationStatus> createRes = topologyTemplateOperation.createTopologyTemplate(service);
370 assertTrue(createRes.isLeft());
372 Either<GraphVertex, JanusGraphOperationStatus> getNodeTyeRes = janusGraphDao
373 .getVertexById(createRes.left().value().getUniqueId());
374 assertTrue(getNodeTyeRes.isLeft());
376 // serviceVertex = getNodeTyeRes.left().value();
378 return getNodeTyeRes.left().value();
381 private <T extends ToscaDataDefinition> NodeType createNodeType(String nodeTypeName) {
383 NodeType vf = new NodeType();
384 String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
385 vf.setUniqueId(uniqueId);
386 vf.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
387 vf.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), nodeTypeName);
388 vf.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
389 vf.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "0.1");
390 vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VF.name());
391 vf.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(), ComponentTypeEnum.RESOURCE);
392 List<CategoryDefinition> categories = new ArrayList<>();
393 CategoryDefinition cat = new CategoryDefinition();
395 cat.setName(categoryName);
396 List<SubCategoryDefinition> subCategories = new ArrayList<>();
397 SubCategoryDefinition subCat = new SubCategoryDefinition();
398 subCat.setName(subcategory);
399 subCategories.add(subCat);
400 cat.setSubcategories(subCategories);
401 vf.setCategories(categories);
403 List<String> derivedFrom = new ArrayList<>();
404 derivedFrom.add("root");
405 vf.setDerivedFrom(derivedFrom);
407 // Map<String, PropertyDataDefinition> properties = new HashMap<>();
408 // PropertyDataDefinition prop1 = new PropertyDataDefinition();
409 // prop1.setName("prop1");
410 // prop1.setDefaultValue("def1");
412 // properties.put("prop1", prop1);
414 // PropertyDataDefinition prop2 = new PropertyDataDefinition();
415 // prop2.setName("prop2");
416 // prop2.setDefaultValue("def2");
417 // properties.put("prop2", prop2);
419 // PropertyDataDefinition prop3 = new PropertyDataDefinition();
420 // prop3.setName("prop3");
421 // prop3.setDefaultValue("def3");
422 // properties.put("prop3", prop3);
424 // vf.setProperties(properties);
425 vf.setComponentType(ComponentTypeEnum.RESOURCE);
426 Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
427 assertTrue(createVFRes.isLeft());
429 Either<GraphVertex, JanusGraphOperationStatus> getNodeTyeRes = janusGraphDao
430 .getVertexById(createVFRes.left().value().getUniqueId());
431 assertTrue(getNodeTyeRes.isLeft());
433 vfVertex = getNodeTyeRes.left().value();
435 List<PropertyDataDefinition> addProperties = new ArrayList<>();
436 PropertyDataDefinition prop11 = new PropertyDataDefinition();
437 prop11.setName("prop11");
438 prop11.setDefaultValue("def11");
440 addProperties.add(prop11);
442 PropertyDataDefinition prop22 = new PropertyDataDefinition();
443 prop22.setName("prop22");
444 prop22.setDefaultValue("def22");
445 addProperties.add(prop22);
447 StorageOperationStatus status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, addProperties, JsonPresentationFields.NAME);
448 assertSame(status, StorageOperationStatus.OK);
450 PropertyDataDefinition prop33 = new PropertyDataDefinition();
451 prop33.setName("prop33");
452 prop33.setDefaultValue("def33");
454 status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop33, JsonPresentationFields.NAME);
455 assertSame(status, StorageOperationStatus.OK);
457 PropertyDataDefinition prop44 = new PropertyDataDefinition();
458 prop44.setName("prop44");
459 prop44.setDefaultValue("def44");
461 status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop44, JsonPresentationFields.NAME);
462 assertSame(status, StorageOperationStatus.OK);
464 PropertyDataDefinition capProp = new PropertyDataDefinition();
465 capProp.setName("capProp");
466 capProp.setDefaultValue("capPropDef");
468 MapDataDefinition dataToCreate = new MapPropertiesDataDefinition();
469 dataToCreate.put("capProp", capProp);
471 Map<String, MapDataDefinition> capProps = new HashMap();
472 capProps.put("capName", dataToCreate);
474 Either<GraphVertex, StorageOperationStatus> res = nodeTypeOperation.associateElementToData(vfVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES, EdgeLabelEnum.CAPABILITIES_PROPERTIES, capProps);
476 // exportGraphMl(janusGraphDao.getGraph().left().value());
478 List<String> pathKeys = new ArrayList<>();
479 pathKeys.add("capName");
480 capProp.setDefaultValue("BBBB");
481 status = nodeTypeOperation.updateToscaDataDeepElementOfToscaElement(vfVertex, EdgeLabelEnum.CAPABILITIES_PROPERTIES, VertexTypeEnum.CAPABILITIES_PROPERTIES, capProp, pathKeys, JsonPresentationFields.NAME);
485 private GraphVertex createRootNodeType() {
487 NodeType vf = new NodeType();
488 String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
489 vf.setUniqueId(uniqueId);
490 vf.setComponentType(ComponentTypeEnum.RESOURCE);
491 vf.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
492 vf.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), "root");
493 vf.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
494 vf.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "1.0");
495 vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VFC.name());
496 vf.getMetadata().put(JsonPresentationFields.LIFECYCLE_STATE.getPresentation(), LifecycleStateEnum.CERTIFIED.name());
497 vf.getMetadata().put(JsonPresentationFields.TOSCA_RESOURCE_NAME.getPresentation(), "root");
498 vf.getMetadata().put(JsonPresentationFields.HIGHEST_VERSION.getPresentation(), true);
500 List<CategoryDefinition> categories = new ArrayList<>();
501 CategoryDefinition cat = new CategoryDefinition();
503 cat.setName(categoryName);
504 List<SubCategoryDefinition> subCategories = new ArrayList<>();
505 SubCategoryDefinition subCat = new SubCategoryDefinition();
506 subCat.setName(subcategory);
507 subCategories.add(subCat);
508 cat.setSubcategories(subCategories);
509 vf.setCategories(categories);
511 List<String> derivedFrom = new ArrayList<>();
512 vf.setDerivedFrom(derivedFrom);
514 Map<String, PropertyDataDefinition> properties = new HashMap<>();
515 PropertyDataDefinition prop1 = new PropertyDataDefinition();
516 prop1.setName("derived1");
517 prop1.setDefaultValue("deriveddef1");
519 properties.put("derived1", prop1);
521 PropertyDataDefinition prop2 = new PropertyDataDefinition();
522 prop2.setUniqueId("derived2");
523 prop2.setName("deriveddef2");
524 properties.put("derived2", prop2);
526 PropertyDataDefinition prop3 = new PropertyDataDefinition();
527 prop3.setName("derived3");
528 prop3.setDefaultValue("deriveddef3");
529 properties.put("derived3", prop3);
531 vf.setProperties(properties);
532 vf.setComponentType(ComponentTypeEnum.RESOURCE);
533 Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
534 assertTrue(createVFRes.isLeft());
536 Either<GraphVertex, JanusGraphOperationStatus> getNodeTyeRes = janusGraphDao
537 .getVertexById(createVFRes.left().value().getUniqueId());
538 assertTrue(getNodeTyeRes.isLeft());
539 return getNodeTyeRes.left().value();
542 private void createUsers() {
544 GraphVertex ownerV = new GraphVertex(VertexTypeEnum.USER);
545 ownerV.setUniqueId("user1");
547 Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
548 metadataProperties.put(GraphPropertyEnum.USERID, ownerV.getUniqueId());
549 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
550 metadataProperties.put(GraphPropertyEnum.NAME, "user1");
551 ownerV.setMetadataProperties(metadataProperties);
552 ownerV.updateMetadataJsonWithCurrentMetadataProperties();
553 ownerV.setJson(new HashMap<>());
554 Either<GraphVertex, JanusGraphOperationStatus> createUserRes = janusGraphDao.createVertex(ownerV);
555 assertTrue(createUserRes.isLeft());
557 ownerVertex = createUserRes.left().value();
559 GraphVertex modifierV = new GraphVertex(VertexTypeEnum.USER);
560 modifierV.setUniqueId("user2");
562 metadataProperties = new HashMap<>();
563 metadataProperties.put(GraphPropertyEnum.USERID, modifierV.getUniqueId());
564 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
565 metadataProperties.put(GraphPropertyEnum.NAME, "user2");
566 modifierV.setMetadataProperties(metadataProperties);
567 modifierV.updateMetadataJsonWithCurrentMetadataProperties();
568 modifierV.setJson(new HashMap<>());
569 createUserRes = janusGraphDao.createVertex(modifierV);
570 assertTrue(createUserRes.isLeft());
572 modifierVertex = createUserRes.left().value();
574 Either<GraphVertex, JanusGraphOperationStatus> getOwnerRes = lifecycleOperation.findUser(ownerVertex.getUniqueId());
575 assertTrue(getOwnerRes.isLeft());
579 public void verifyInCatalogData(int expected, List<String> expectedIds) {
581 Either<List<CatalogComponent>, StorageOperationStatus> highestResourcesRes = topologyTemplateOperation.getElementCatalogData(true, null);
582 assertTrue(highestResourcesRes.isLeft());
583 List<CatalogComponent> highestResources = highestResourcesRes.left().value();
584 // calculate expected count value
585 assertEquals(expected, highestResources.stream().count());
586 if (expectedIds != null) {
587 highestResources.forEach(a -> assertTrue(expectedIds.contains(a.getUniqueId())));
592 public void teardown() {
596 private void clearGraph() {
597 Either<JanusGraph, JanusGraphOperationStatus> graphResult = janusGraphDao.getGraph();
598 JanusGraph graph = graphResult.left().value();
600 Iterable<JanusGraphVertex> vertices = graph.query().vertices();
601 if (vertices != null) {
602 Iterator<JanusGraphVertex> iterator = vertices.iterator();
603 while (iterator.hasNext()) {
604 JanusGraphVertex vertex = iterator.next();
608 janusGraphDao.commit();
611 private String exportGraphMl(JanusGraph graph) {
612 String result = null;
613 String outputFile = outputDirectory + File.separator + "exportGraph." + System.currentTimeMillis() + ".graphml";
615 try (final OutputStream os = new BufferedOutputStream(new FileOutputStream(outputFile))) {
616 graph.io(IoCore.graphml()).writer().normalize(true).create().writeGraph(os, graph);
620 } catch (Exception e) {
621 graph.tx().rollback();