2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.dao.jsongraph;
23 import org.janusgraph.core.JanusGraph;
24 import fj.data.Either;
25 import org.apache.tinkerpop.gremlin.structure.Edge;
26 import org.apache.tinkerpop.gremlin.structure.Element;
27 import org.apache.tinkerpop.gremlin.structure.Property;
28 import org.apache.tinkerpop.gremlin.structure.Vertex;
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.mockito.Mockito;
33 import org.openecomp.sdc.be.dao.DAOJanusGraphStrategy;
34 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphClient;
35 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
36 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
37 import org.openecomp.sdc.be.dao.jsongraph.types.EdgePropertyEnum;
38 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
39 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
40 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
41 import org.openecomp.sdc.be.utils.DAOConfDependentTest;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
45 import java.util.Iterator;
46 import java.util.List;
49 public class JanusGraphDaoTest extends DAOConfDependentTest{
52 private static Logger logger = LoggerFactory.getLogger(JanusGraphDaoTest.class);
53 private JanusGraphDao dao = new JanusGraphDao(new JanusGraphClient(new DAOJanusGraphStrategy()));
57 dao.janusGraphClient.createGraph();
62 dao.janusGraphClient.cleanupGraph();
66 public void testCreateVertex() throws Exception {
67 Either<GraphVertex, JanusGraphOperationStatus> result;
70 GraphVertex graphVertex = new GraphVertex(VertexTypeEnum.REQUIREMENTS);
71 result = dao.createVertex(graphVertex);
73 graphVertex = new GraphVertex();
74 result = dao.createVertex(graphVertex);
78 public void testGetVertexByLabel() throws Exception {
79 Either<GraphVertex, JanusGraphOperationStatus> result;
82 result = dao.getVertexByLabel(VertexTypeEnum.ADDITIONAL_INFORMATION);
86 public void testCommit() throws Exception {
87 JanusGraphOperationStatus result;
91 result = dao.commit();
96 public void testRollback() throws Exception {
98 JanusGraphOperationStatus result;
102 result = dao.rollback();
106 public void testGetGraph() throws Exception {
108 Either<JanusGraph, JanusGraphOperationStatus> result;
112 result = dao.getGraph();
116 public void testGetVertexByPropertyAndLabel() throws Exception {
118 GraphPropertyEnum name = null;
120 VertexTypeEnum label = null;
121 Either<GraphVertex, JanusGraphOperationStatus> result;
125 result = dao.getVertexByPropertyAndLabel(name, value, label);
127 result = dao.getVertexByPropertyAndLabel(GraphPropertyEnum.COMPONENT_TYPE, new Object(), VertexTypeEnum.ADDITIONAL_INFORMATION);
131 public void testGetVertexByPropertyAndLabel_1() throws Exception {
133 GraphPropertyEnum name = null;
135 VertexTypeEnum label = null;
136 JsonParseFlagEnum parseFlag = null;
137 Either<GraphVertex, JanusGraphOperationStatus> result;
141 result = dao.getVertexByPropertyAndLabel(name, value, label, parseFlag);
146 public void testGetVertexById() throws Exception {
149 Either<GraphVertex, JanusGraphOperationStatus> result;
153 result = dao.getVertexById(id);
157 public void testGetVertexById_1() throws Exception {
160 JsonParseFlagEnum parseFlag = null;
161 Either<GraphVertex, JanusGraphOperationStatus> result;
166 result = dao.getVertexById(id, parseFlag);
171 result = dao.getVertexById(id, parseFlag);
175 public void testGetVertexProperties() throws Exception {
177 Element element = null;
178 Map<GraphPropertyEnum, Object> result;
183 result = dao.getVertexProperties(element);
188 public void testGetEdgeProperties() throws Exception {
190 Element element = null;
191 Map<EdgePropertyEnum, Object> result;
196 result = dao.getEdgeProperties(element);
200 public void testGetByCriteria() throws Exception {
202 VertexTypeEnum type = null;
203 Map<GraphPropertyEnum, Object> props = null;
204 Either<List<GraphVertex>, JanusGraphOperationStatus> result;
208 result = dao.getByCriteria(type, props);
212 public void testGetByCriteria_1() throws Exception {
214 VertexTypeEnum type = null;
215 Map<GraphPropertyEnum, Object> props = null;
216 JsonParseFlagEnum parseFlag = null;
217 Either<List<GraphVertex>, JanusGraphOperationStatus> result;
221 result = dao.getByCriteria(type, props, parseFlag);
226 public void testGetByCriteria_2() throws Exception {
228 VertexTypeEnum type = null;
229 Map<GraphPropertyEnum, Object> props = null;
230 Map<GraphPropertyEnum, Object> hasNotProps = null;
231 JsonParseFlagEnum parseFlag = null;
232 Either<List<GraphVertex>, JanusGraphOperationStatus> result;
236 result = dao.getByCriteria(type, props, hasNotProps, parseFlag);
240 public void testGetCatalogVerticies() throws Exception {
242 Either<Iterator<Vertex>, JanusGraphOperationStatus> result;
246 result = dao.getCatalogOrArchiveVerticies(true);
250 public void testGetParentVertecies_1() throws Exception {
252 Vertex parentVertex = null;
253 EdgeLabelEnum edgeLabel = null;
254 JsonParseFlagEnum parseFlag = null;
255 Either<List<Vertex>, JanusGraphOperationStatus> result;
259 result = dao.getParentVertecies(parentVertex, edgeLabel, parseFlag);
263 public void testGetChildrenVertecies_1() throws Exception {
265 Vertex parentVertex = null;
266 EdgeLabelEnum edgeLabel = null;
267 JsonParseFlagEnum parseFlag = null;
268 Either<List<Vertex>, JanusGraphOperationStatus> result;
272 result = dao.getChildrenVertecies(parentVertex, edgeLabel, parseFlag);
276 public void testUpdateVertexMetadataPropertiesWithJson() throws Exception {
278 Vertex vertex = null;
279 Map<GraphPropertyEnum, Object> properties = null;
280 JanusGraphOperationStatus result;
284 result = dao.updateVertexMetadataPropertiesWithJson(vertex, properties);
288 public void testGetProperty() throws Exception {
289 Edge edge = Mockito.mock(Edge.class);;
292 Property<Object> value = Mockito.mock(Property.class);
293 Mockito.when(edge.property(Mockito.any())).thenReturn(value);
296 result = dao.getProperty(edge, EdgePropertyEnum.STATE);
300 public void testGetProperty_1() throws Exception {
301 Edge edge = Mockito.mock(Edge.class);;
305 result = dao.getProperty(edge, EdgePropertyEnum.STATE);
309 public void testGetPropertyexception() throws Exception {
310 Edge edge = Mockito.mock(Edge.class);;
313 Property<Object> value = Mockito.mock(Property.class);
314 Mockito.when(edge.property(Mockito.any())).thenThrow(RuntimeException.class);
317 result = dao.getProperty(edge, EdgePropertyEnum.STATE);
321 public void testGetBelongingEdgeByCriteria_1() throws Exception {
323 String parentId = "";
324 EdgeLabelEnum label = null;
325 Map<GraphPropertyEnum, Object> properties = null;
326 Either<Edge, JanusGraphOperationStatus> result;
330 result = dao.getBelongingEdgeByCriteria(parentId, label, properties);