1 package org.openecomp.sdc.be.dao.jsongraph;
3 import com.thinkaurelius.titan.core.TitanGraph;
5 import org.apache.tinkerpop.gremlin.structure.Edge;
6 import org.apache.tinkerpop.gremlin.structure.Element;
7 import org.apache.tinkerpop.gremlin.structure.Property;
8 import org.apache.tinkerpop.gremlin.structure.Vertex;
9 import org.junit.After;
10 import org.junit.Before;
11 import org.junit.Test;
12 import org.mockito.Mockito;
13 import org.openecomp.sdc.be.dao.DAOTitanStrategy;
14 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
15 import org.openecomp.sdc.be.dao.jsongraph.types.EdgePropertyEnum;
16 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
17 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
18 import org.openecomp.sdc.be.dao.titan.TitanGraphClient;
19 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
20 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
21 import org.openecomp.sdc.be.utils.DAOConfDependentTest;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 import java.util.Iterator;
26 import java.util.List;
29 public class TitanDaoTest extends DAOConfDependentTest{
32 private static Logger logger = LoggerFactory.getLogger(TitanDaoTest.class);
33 private TitanDao dao = new TitanDao(new TitanGraphClient(new DAOTitanStrategy()));
37 dao.titanClient.createGraph();
42 dao.titanClient.cleanupGraph();
46 public void testCreateVertex() throws Exception {
47 Either<GraphVertex, TitanOperationStatus> result;
50 GraphVertex graphVertex = new GraphVertex(VertexTypeEnum.REQUIREMENTS);
51 result = dao.createVertex(graphVertex);
53 graphVertex = new GraphVertex();
54 result = dao.createVertex(graphVertex);
58 public void testGetVertexByLabel() throws Exception {
59 Either<GraphVertex, TitanOperationStatus> result;
62 result = dao.getVertexByLabel(VertexTypeEnum.ADDITIONAL_INFORMATION);
66 public void testCommit() throws Exception {
67 TitanOperationStatus result;
71 result = dao.commit();
76 public void testRollback() throws Exception {
78 TitanOperationStatus result;
82 result = dao.rollback();
86 public void testGetGraph() throws Exception {
88 Either<TitanGraph, TitanOperationStatus> result;
92 result = dao.getGraph();
96 public void testGetVertexByPropertyAndLabel() throws Exception {
98 GraphPropertyEnum name = null;
100 VertexTypeEnum label = null;
101 Either<GraphVertex, TitanOperationStatus> result;
105 result = dao.getVertexByPropertyAndLabel(name, value, label);
107 result = dao.getVertexByPropertyAndLabel(GraphPropertyEnum.COMPONENT_TYPE, new Object(), VertexTypeEnum.ADDITIONAL_INFORMATION);
111 public void testGetVertexByPropertyAndLabel_1() throws Exception {
113 GraphPropertyEnum name = null;
115 VertexTypeEnum label = null;
116 JsonParseFlagEnum parseFlag = null;
117 Either<GraphVertex, TitanOperationStatus> result;
121 result = dao.getVertexByPropertyAndLabel(name, value, label, parseFlag);
126 public void testGetVertexById() throws Exception {
129 Either<GraphVertex, TitanOperationStatus> result;
133 result = dao.getVertexById(id);
137 public void testGetVertexById_1() throws Exception {
140 JsonParseFlagEnum parseFlag = null;
141 Either<GraphVertex, TitanOperationStatus> result;
146 result = dao.getVertexById(id, parseFlag);
151 result = dao.getVertexById(id, parseFlag);
155 public void testGetVertexProperties() throws Exception {
157 Element element = null;
158 Map<GraphPropertyEnum, Object> result;
163 result = dao.getVertexProperties(element);
168 public void testGetEdgeProperties() throws Exception {
170 Element element = null;
171 Map<EdgePropertyEnum, Object> result;
176 result = dao.getEdgeProperties(element);
180 public void testGetByCriteria() throws Exception {
182 VertexTypeEnum type = null;
183 Map<GraphPropertyEnum, Object> props = null;
184 Either<List<GraphVertex>, TitanOperationStatus> result;
188 result = dao.getByCriteria(type, props);
192 public void testGetByCriteria_1() throws Exception {
194 VertexTypeEnum type = null;
195 Map<GraphPropertyEnum, Object> props = null;
196 JsonParseFlagEnum parseFlag = null;
197 Either<List<GraphVertex>, TitanOperationStatus> result;
201 result = dao.getByCriteria(type, props, parseFlag);
206 public void testGetByCriteria_2() throws Exception {
208 VertexTypeEnum type = null;
209 Map<GraphPropertyEnum, Object> props = null;
210 Map<GraphPropertyEnum, Object> hasNotProps = null;
211 JsonParseFlagEnum parseFlag = null;
212 Either<List<GraphVertex>, TitanOperationStatus> result;
216 result = dao.getByCriteria(type, props, hasNotProps, parseFlag);
220 public void testGetCatalogVerticies() throws Exception {
222 Either<Iterator<Vertex>, TitanOperationStatus> result;
226 result = dao.getCatalogOrArchiveVerticies(true);
230 public void testGetParentVertecies_1() throws Exception {
232 Vertex parentVertex = null;
233 EdgeLabelEnum edgeLabel = null;
234 JsonParseFlagEnum parseFlag = null;
235 Either<List<Vertex>, TitanOperationStatus> result;
239 result = dao.getParentVertecies(parentVertex, edgeLabel, parseFlag);
243 public void testGetChildrenVertecies_1() throws Exception {
245 Vertex parentVertex = null;
246 EdgeLabelEnum edgeLabel = null;
247 JsonParseFlagEnum parseFlag = null;
248 Either<List<Vertex>, TitanOperationStatus> result;
252 result = dao.getChildrenVertecies(parentVertex, edgeLabel, parseFlag);
256 public void testUpdateVertexMetadataPropertiesWithJson() throws Exception {
258 Vertex vertex = null;
259 Map<GraphPropertyEnum, Object> properties = null;
260 TitanOperationStatus result;
264 result = dao.updateVertexMetadataPropertiesWithJson(vertex, properties);
268 public void testGetProperty() throws Exception {
269 Edge edge = Mockito.mock(Edge.class);;
272 Property<Object> value = Mockito.mock(Property.class);
273 Mockito.when(edge.property(Mockito.any())).thenReturn(value);
276 result = dao.getProperty(edge, EdgePropertyEnum.STATE);
280 public void testGetProperty_1() throws Exception {
281 Edge edge = Mockito.mock(Edge.class);;
285 result = dao.getProperty(edge, EdgePropertyEnum.STATE);
289 public void testGetPropertyexception() throws Exception {
290 Edge edge = Mockito.mock(Edge.class);;
293 Property<Object> value = Mockito.mock(Property.class);
294 Mockito.when(edge.property(Mockito.any())).thenThrow(RuntimeException.class);
297 result = dao.getProperty(edge, EdgePropertyEnum.STATE);
301 public void testGetBelongingEdgeByCriteria_1() throws Exception {
303 String parentId = "";
304 EdgeLabelEnum label = null;
305 Map<GraphPropertyEnum, Object> properties = null;
306 Either<Edge, TitanOperationStatus> result;
310 result = dao.getBelongingEdgeByCriteria(parentId, label, properties);