1 package org.openecomp.sdc.be.model.jsontitan.operations;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertTrue;
6 import com.thinkaurelius.titan.core.TitanGraph;
7 import com.thinkaurelius.titan.core.TitanVertex;
9 import java.io.BufferedOutputStream;
11 import java.io.FileOutputStream;
12 import java.io.OutputStream;
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.Iterator;
16 import java.util.List;
18 import javax.annotation.Resource;
19 import org.apache.tinkerpop.gremlin.structure.io.IoCore;
20 import org.junit.After;
21 import org.junit.Assert;
22 import org.junit.Before;
23 import org.junit.BeforeClass;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
27 import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
28 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
29 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
30 import org.openecomp.sdc.be.dao.titan.TitanGraphClient;
31 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
32 import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition;
33 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
34 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
35 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
36 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
37 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
38 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
39 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
40 import org.openecomp.sdc.be.model.InterfaceDefinition;
41 import org.openecomp.sdc.be.model.LifecycleStateEnum;
42 import org.openecomp.sdc.be.model.ModelTestBase;
43 import org.openecomp.sdc.be.model.Operation;
44 import org.openecomp.sdc.be.model.User;
45 import org.openecomp.sdc.be.model.catalog.CatalogComponent;
46 import org.openecomp.sdc.be.model.category.CategoryDefinition;
47 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
48 import org.openecomp.sdc.be.model.jsontitan.datamodel.NodeType;
49 import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
50 import org.openecomp.sdc.be.model.jsontitan.utils.GraphTestUtils;
51 import org.openecomp.sdc.be.model.operations.api.IElementOperation;
52 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
53 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
54 import org.openecomp.sdc.common.util.ValidationUtils;
55 import org.springframework.beans.factory.annotation.Autowired;
56 import org.springframework.test.context.ContextConfiguration;
57 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
59 @RunWith(SpringJUnit4ClassRunner.class)
60 @ContextConfiguration("classpath:application-context-test.xml")
61 public class InterfacesOperationTest extends ModelTestBase{
63 protected TitanDao titanDao;
65 private InterfaceOperation interfaceOperation;
68 protected TitanGraphClient titanGraphClient;
71 protected NodeTypeOperation nodeTypeOperation;
73 protected ToscaOperationFacade toscaOperationFacade;
76 protected TopologyTemplateOperation topologyTemplateOperation;
79 protected IElementOperation elementDao;
82 private ToscaElementLifecycleOperation lifecycleOperation;
84 protected static final String USER_ID = "jh0003";
85 protected static final String VF_NAME = "VF_NAME";
88 public static final String RESOURCE_CATEGORY = "Network Layer 2-3";
89 public static final String RESOURCE_SUBCATEGORY = "Router";
90 public static final String RESOURCE_NAME = "Resource Name";
92 private CategoryDefinition categoryDefinition;
93 private SubCategoryDefinition subCategoryDefinition = new SubCategoryDefinition();
94 protected static final String RESOURCE_ID = "resourceID";
95 protected static final String WORKFLOW_OPERATION_ID = "workflowOperationId";
96 public static final String DERIVED_NAME = "derivedName";
97 public static final String CSAR_UUID = "bla bla";
100 String categoryName = "category";
101 String subcategory = "mycategory";
102 String outputDirectory = "C:\\Output";
105 public static void initInterfacesOperation() {
109 private GraphVertex ownerVertex;
110 private GraphVertex modifierVertex;
111 private GraphVertex vfVertex;
112 private GraphVertex serviceVertex;
113 private GraphVertex rootVertex;
116 public void setupBefore() {
119 createResourceCategory();
120 createServiceCategory();
121 GraphTestUtils.createRootCatalogVertex(titanDao);
122 rootVertex = createRootNodeType();
123 createNodeType("firstVf");
124 serviceVertex = createTopologyTemplate("firstService");
128 public void cleanAfter() {
133 public void testAddInterface() {
134 org.openecomp.sdc.be.model.Resource resource = createResource();
135 InterfaceDefinition interfaceDefinition = buildInterfaceDefinition();
136 Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(resource.getUniqueId(),
137 interfaceDefinition);
138 Assert.assertTrue(res.isLeft());
142 public void testUpdateInterface() {
143 org.openecomp.sdc.be.model.Resource resource = createResource();
144 InterfaceDefinition interfaceDefinition = buildInterfaceDefinition();
145 interfaceDefinition.setOperationsMap(createMockOperationMap());
146 Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(resource.getUniqueId(),
147 interfaceDefinition);
148 Assert.assertTrue(res.isLeft());
149 InterfaceDefinition value = res.left().value();
150 String new_description = "New Description";
151 value.setDescription(new_description);
152 res = interfaceOperation.updateInterface(resource.getUniqueId(),
153 interfaceDefinition);
154 assertTrue(res.isLeft());
155 assertEquals(new_description,res.left().value().getDescription());
159 public void testUpdateInterfaceShouldFailWhenNOtCreatedFirst() {
160 org.openecomp.sdc.be.model.Resource resource = createResource();
161 InterfaceDefinition interfaceDefinition = buildInterfaceDefinition();
162 interfaceDefinition.setOperationsMap(createMockOperationMap());
163 Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.updateInterface(resource.getUniqueId(),
164 interfaceDefinition);
165 Assert.assertTrue(res.isRight());
168 private InterfaceDefinition buildInterfaceDefinition() {
169 InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
170 interfaceDefinition.setType("tosca.interfaces.standard");
171 interfaceDefinition.setCreationDate(new Long(101232));
174 return interfaceDefinition;
177 private org.openecomp.sdc.be.model.Resource createResource() {
178 org.openecomp.sdc.be.model.Resource resource = new org.openecomp.sdc.be.model.Resource();
179 resource.setUniqueId(RESOURCE_ID);
180 resource.setName(RESOURCE_NAME);
181 resource.addCategory(RESOURCE_CATEGORY, RESOURCE_SUBCATEGORY);
182 resource.setDescription("My short description");
183 resource.setInterfaces(createMockInterfaceDefinition());
188 private InterfaceDefinition createInterface(String uniqueID, String description, String type, String toscaResourceName,
189 Map<String, Operation> op) {
190 InterfaceDefinition id = new InterfaceDefinition();
192 id.setDescription(description);
193 id.setUniqueId(uniqueID);
194 id.setToscaResourceName(toscaResourceName);
195 id.setOperationsMap(op);
199 private Map<String, InterfaceDefinition> createMockInterfaceDefinition() {
200 Map<String, Operation> operationMap = createMockOperationMap();
201 Map<String, InterfaceDefinition> interfaceDefinitionMap = new HashMap<>();
202 interfaceDefinitionMap.put("int1", createInterface("int1", "Interface 1",
203 "lifecycle", "tosca", operationMap));
205 return interfaceDefinitionMap;
208 private Map<String, Operation> createMockOperationMap() {
209 Operation operation = new Operation();
210 operation.setDefinition(false);
211 operation.setName("create");
212 Map<String, Operation> operationMap = new HashMap<>();
213 operationMap.put("op1", operation);
220 private void createResourceCategory() {
222 GraphVertex cat = new GraphVertex(VertexTypeEnum.RESOURCE_CATEGORY);
223 Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
224 String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.RESOURCE_CATEGORY);
225 cat.setUniqueId(catId);
226 metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, catId);
227 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_CATEGORY.getName());
228 metadataProperties.put(GraphPropertyEnum.NAME, categoryName);
229 metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
230 cat.setMetadataProperties(metadataProperties);
231 cat.updateMetadataJsonWithCurrentMetadataProperties();
233 GraphVertex subCat = new GraphVertex(VertexTypeEnum.RESOURCE_SUBCATEGORY);
234 metadataProperties = new HashMap<>();
235 String subCatId = UniqueIdBuilder.buildSubCategoryUid(cat.getUniqueId(), subcategory);
236 subCat.setUniqueId(subCatId);
237 metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, subCatId);
238 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_SUBCATEGORY.getName());
239 metadataProperties.put(GraphPropertyEnum.NAME, subcategory);
240 metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(subcategory));
241 subCat.setMetadataProperties(metadataProperties);
242 subCat.updateMetadataJsonWithCurrentMetadataProperties();
244 Either<GraphVertex, TitanOperationStatus> catRes = titanDao.createVertex(cat);
246 Either<GraphVertex, TitanOperationStatus> subCatRes = titanDao.createVertex(subCat);
248 TitanOperationStatus status = titanDao.createEdge(catRes.left().value().getVertex(), subCatRes.left().value().getVertex(), EdgeLabelEnum.SUB_CATEGORY, new HashMap<>());
249 assertEquals(TitanOperationStatus.OK, status);
252 private void createServiceCategory() {
254 GraphVertex cat = new GraphVertex(VertexTypeEnum.SERVICE_CATEGORY);
255 Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
256 String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.SERVICE_CATEGORY);
257 cat.setUniqueId(catId);
258 metadataProperties.put(GraphPropertyEnum.UNIQUE_ID, catId);
259 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.SERVICE_CATEGORY.getName());
260 metadataProperties.put(GraphPropertyEnum.NAME, categoryName);
261 metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName));
262 cat.setMetadataProperties(metadataProperties);
263 cat.updateMetadataJsonWithCurrentMetadataProperties();
265 Either<GraphVertex, TitanOperationStatus> catRes = titanDao.createVertex(cat);
267 assertTrue(catRes.isLeft());
270 private GraphVertex createTopologyTemplate(String name) {
272 TopologyTemplate service = new TopologyTemplate();
273 String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
274 service.setUniqueId(uniqueId);
275 service.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
276 service.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), name);
277 service.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
278 service.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "0.1");
279 service.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VF.name());
280 service.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(), ComponentTypeEnum.RESOURCE);
281 List<CategoryDefinition> categories = new ArrayList<>();
282 CategoryDefinition cat = new CategoryDefinition();
284 cat.setName(categoryName);
285 service.setCategories(categories);
287 service.setComponentType(ComponentTypeEnum.SERVICE);
288 Either<TopologyTemplate, StorageOperationStatus> createRes = topologyTemplateOperation.createTopologyTemplate(service);
289 assertTrue(createRes.isLeft());
291 Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createRes.left().value().getUniqueId());
292 assertTrue(getNodeTyeRes.isLeft());
294 // serviceVertex = getNodeTyeRes.left().value();
296 return getNodeTyeRes.left().value();
299 private <T extends ToscaDataDefinition> NodeType createNodeType(String nodeTypeName) {
301 NodeType vf = new NodeType();
302 String uniqueId = RESOURCE_ID; // UniqueIdBuilder.buildResourceUniqueId();
303 vf.setUniqueId(uniqueId);
304 vf.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
305 vf.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), nodeTypeName);
306 vf.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
307 vf.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "0.1");
308 vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VF.name());
309 vf.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(), ComponentTypeEnum.RESOURCE);
310 List<CategoryDefinition> categories = new ArrayList<>();
311 CategoryDefinition cat = new CategoryDefinition();
313 cat.setName(categoryName);
314 List<SubCategoryDefinition> subCategories = new ArrayList<>();
315 SubCategoryDefinition subCat = new SubCategoryDefinition();
316 subCat.setName(subcategory);
317 subCategories.add(subCat);
318 cat.setSubcategories(subCategories);
319 vf.setCategories(categories);
321 List<String> derivedFrom = new ArrayList<>();
322 derivedFrom.add("root");
323 vf.setDerivedFrom(derivedFrom);
325 // Map<String, PropertyDataDefinition> properties = new HashMap<>();
326 // PropertyDataDefinition prop1 = new PropertyDataDefinition();
327 // prop1.setName("prop1");
328 // prop1.setDefaultValue("def1");
330 // properties.put("prop1", prop1);
332 // PropertyDataDefinition prop2 = new PropertyDataDefinition();
333 // prop2.setName("prop2");
334 // prop2.setDefaultValue("def2");
335 // properties.put("prop2", prop2);
337 // PropertyDataDefinition prop3 = new PropertyDataDefinition();
338 // prop3.setName("prop3");
339 // prop3.setDefaultValue("def3");
340 // properties.put("prop3", prop3);
342 // vf.setProperties(properties);
343 vf.setComponentType(ComponentTypeEnum.RESOURCE);
344 Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
345 assertTrue(createVFRes.isLeft());
347 Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createVFRes.left().value().getUniqueId());
348 assertTrue(getNodeTyeRes.isLeft());
350 vfVertex = getNodeTyeRes.left().value();
352 List<PropertyDataDefinition> addProperties = new ArrayList<>();
353 PropertyDataDefinition prop11 = new PropertyDataDefinition();
354 prop11.setName("prop11");
355 prop11.setDefaultValue("def11");
357 addProperties.add(prop11);
359 PropertyDataDefinition prop22 = new PropertyDataDefinition();
360 prop22.setName("prop22");
361 prop22.setDefaultValue("def22");
362 addProperties.add(prop22);
364 StorageOperationStatus status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, addProperties, JsonPresentationFields.NAME);
365 assertTrue(status == StorageOperationStatus.OK);
367 PropertyDataDefinition prop33 = new PropertyDataDefinition();
368 prop33.setName("prop33");
369 prop33.setDefaultValue("def33");
371 status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop33, JsonPresentationFields.NAME);
372 assertTrue(status == StorageOperationStatus.OK);
374 PropertyDataDefinition prop44 = new PropertyDataDefinition();
375 prop44.setName("prop44");
376 prop44.setDefaultValue("def44");
378 status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop44, JsonPresentationFields.NAME);
379 assertTrue(status == StorageOperationStatus.OK);
381 PropertyDataDefinition capProp = new PropertyDataDefinition();
382 capProp.setName("capProp");
383 capProp.setDefaultValue("capPropDef");
385 MapDataDefinition dataToCreate = new MapPropertiesDataDefinition();
386 dataToCreate.put("capProp", capProp);
388 Map<String, MapDataDefinition> capProps = new HashMap();
389 capProps.put("capName", dataToCreate);
391 Either<GraphVertex, StorageOperationStatus> res = nodeTypeOperation.assosiateElementToData(vfVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES, EdgeLabelEnum.CAPABILITIES_PROPERTIES, capProps);
393 // exportGraphMl(titanDao.getGraph().left().value());
395 List<String> pathKeys = new ArrayList<>();
396 pathKeys.add("capName");
397 capProp.setDefaultValue("BBBB");
398 status = nodeTypeOperation.updateToscaDataDeepElementOfToscaElement(vfVertex, EdgeLabelEnum.CAPABILITIES_PROPERTIES, VertexTypeEnum.CAPABILITIES_PROPERTIES, capProp, pathKeys, JsonPresentationFields.NAME);
402 private GraphVertex createRootNodeType() {
404 NodeType vf = new NodeType();
405 String uniqueId = UniqueIdBuilder.buildResourceUniqueId();
406 vf.setUniqueId(uniqueId);
407 vf.setComponentType(ComponentTypeEnum.RESOURCE);
408 vf.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID));
409 vf.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), "root");
410 vf.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), uniqueId);
411 vf.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "1.0");
412 vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VFC.name());
413 vf.getMetadata().put(JsonPresentationFields.LIFECYCLE_STATE.getPresentation(), LifecycleStateEnum.CERTIFIED.name());
414 vf.getMetadata().put(JsonPresentationFields.TOSCA_RESOURCE_NAME.getPresentation(), "root");
415 vf.getMetadata().put(JsonPresentationFields.HIGHEST_VERSION.getPresentation(), true);
417 List<CategoryDefinition> categories = new ArrayList<>();
418 CategoryDefinition cat = new CategoryDefinition();
420 cat.setName(categoryName);
421 List<SubCategoryDefinition> subCategories = new ArrayList<>();
422 SubCategoryDefinition subCat = new SubCategoryDefinition();
423 subCat.setName(subcategory);
424 subCategories.add(subCat);
425 cat.setSubcategories(subCategories);
426 vf.setCategories(categories);
428 List<String> derivedFrom = new ArrayList<>();
429 vf.setDerivedFrom(derivedFrom);
431 Map<String, PropertyDataDefinition> properties = new HashMap<>();
432 PropertyDataDefinition prop1 = new PropertyDataDefinition();
433 prop1.setName("derived1");
434 prop1.setDefaultValue("deriveddef1");
436 properties.put("derived1", prop1);
438 PropertyDataDefinition prop2 = new PropertyDataDefinition();
439 prop2.setUniqueId("derived2");
440 prop2.setName("deriveddef2");
441 properties.put("derived2", prop2);
443 PropertyDataDefinition prop3 = new PropertyDataDefinition();
444 prop3.setName("derived3");
445 prop3.setDefaultValue("deriveddef3");
446 properties.put("derived3", prop3);
448 vf.setProperties(properties);
449 vf.setComponentType(ComponentTypeEnum.RESOURCE);
450 Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf);
451 assertTrue(createVFRes.isLeft());
453 Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createVFRes.left().value().getUniqueId());
454 assertTrue(getNodeTyeRes.isLeft());
455 return getNodeTyeRes.left().value();
458 private void createUsers() {
460 GraphVertex ownerV = new GraphVertex(VertexTypeEnum.USER);
461 ownerV.setUniqueId("user1");
463 Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>();
464 metadataProperties.put(GraphPropertyEnum.USERID, ownerV.getUniqueId());
465 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
466 metadataProperties.put(GraphPropertyEnum.NAME, "user1");
467 ownerV.setMetadataProperties(metadataProperties);
468 ownerV.updateMetadataJsonWithCurrentMetadataProperties();
469 ownerV.setJson(new HashMap<>());
470 Either<GraphVertex, TitanOperationStatus> createUserRes = titanDao.createVertex(ownerV);
471 assertTrue(createUserRes.isLeft());
473 ownerVertex = createUserRes.left().value();
475 GraphVertex modifierV = new GraphVertex(VertexTypeEnum.USER);
476 modifierV.setUniqueId("user2");
478 metadataProperties = new HashMap<>();
479 metadataProperties.put(GraphPropertyEnum.USERID, modifierV.getUniqueId());
480 metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.USER.getName());
481 metadataProperties.put(GraphPropertyEnum.NAME, "user2");
482 modifierV.setMetadataProperties(metadataProperties);
483 modifierV.updateMetadataJsonWithCurrentMetadataProperties();
484 modifierV.setJson(new HashMap<>());
485 createUserRes = titanDao.createVertex(modifierV);
486 assertTrue(createUserRes.isLeft());
488 modifierVertex = createUserRes.left().value();
490 Either<GraphVertex, TitanOperationStatus> getOwnerRes = lifecycleOperation.findUser(ownerVertex.getUniqueId());
491 assertTrue(getOwnerRes.isLeft());
495 public void verifyInCatalogData(int expected, List<String> expectedIds) {
497 Either<List<CatalogComponent>, StorageOperationStatus> highestResourcesRes = topologyTemplateOperation.getElementCatalogData();
498 assertTrue(highestResourcesRes.isLeft());
499 List<CatalogComponent> highestResources = highestResourcesRes.left().value();
500 // calculate expected count value
501 assertEquals(expected, highestResources.stream().count());
502 if (expectedIds != null) {
503 highestResources.forEach(a -> assertTrue(expectedIds.contains(a.getUniqueId())));
508 public void teardown() {
512 private void clearGraph() {
513 Either<TitanGraph, TitanOperationStatus> graphResult = titanDao.getGraph();
514 TitanGraph graph = graphResult.left().value();
516 Iterable<TitanVertex> vertices = graph.query().vertices();
517 if (vertices != null) {
518 Iterator<TitanVertex> iterator = vertices.iterator();
519 while (iterator.hasNext()) {
520 TitanVertex vertex = iterator.next();
527 private String exportGraphMl(TitanGraph graph) {
528 String result = null;
529 String outputFile = outputDirectory + File.separator + "exportGraph." + System.currentTimeMillis() + ".graphml";
531 try (final OutputStream os = new BufferedOutputStream(new FileOutputStream(outputFile))) {
532 graph.io(IoCore.graphml()).writer().normalize(true).create().writeGraph(os, graph);
536 } catch (Exception e) {
537 graph.tx().rollback();