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.janusgraph;
23 import fj.data.Either;
24 import java.util.Iterator;
25 import java.util.List;
27 import org.apache.tinkerpop.gremlin.structure.Edge;
28 import org.apache.tinkerpop.gremlin.structure.Element;
29 import org.apache.tinkerpop.gremlin.structure.Property;
30 import org.apache.tinkerpop.gremlin.structure.Vertex;
31 import org.janusgraph.core.JanusGraph;
32 import org.junit.jupiter.api.AfterEach;
33 import org.junit.jupiter.api.BeforeEach;
34 import org.junit.jupiter.api.Test;
35 import org.mockito.Mockito;
36 import org.openecomp.sdc.be.dao.DAOJanusGraphStrategy;
37 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
38 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
39 import org.openecomp.sdc.be.dao.jsongraph.types.EdgePropertyEnum;
40 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
41 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
42 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
43 import org.openecomp.sdc.be.utils.DAOConfDependentTest;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
47 class JanusGraphDaoTest extends DAOConfDependentTest {
49 private static final Logger logger = LoggerFactory.getLogger(JanusGraphDaoTest.class);
50 private final JanusGraphDao dao = new JanusGraphDao(new JanusGraphClient(new DAOJanusGraphStrategy()));
54 dao.janusGraphClient.createGraph();
59 dao.janusGraphClient.cleanupGraph();
63 void testCreateVertex() throws Exception {
64 Either<GraphVertex, JanusGraphOperationStatus> result;
67 GraphVertex graphVertex = new GraphVertex(VertexTypeEnum.REQUIREMENTS);
68 result = dao.createVertex(graphVertex);
70 graphVertex = new GraphVertex();
71 result = dao.createVertex(graphVertex);
75 void testGetVertexByLabel() throws Exception {
76 Either<GraphVertex, JanusGraphOperationStatus> result;
78 dao.createVertex(new GraphVertex(VertexTypeEnum.ADDITIONAL_INFORMATION));
80 result = dao.getVertexByLabel(VertexTypeEnum.ADDITIONAL_INFORMATION);
84 void testCommit() throws Exception {
85 JanusGraphOperationStatus result;
89 result = dao.commit();
93 void testRollback() throws Exception {
95 JanusGraphOperationStatus result;
99 result = dao.rollback();
103 void testGetGraph() throws Exception {
105 Either<JanusGraph, JanusGraphOperationStatus> result;
109 result = dao.getGraph();
113 void testGetVertexByPropertyAndLabel() throws Exception {
115 GraphPropertyEnum name = null;
117 VertexTypeEnum label = null;
118 Either<GraphVertex, JanusGraphOperationStatus> result;
122 result = dao.getVertexByPropertyAndLabel(name, value, label);
124 result = dao.getVertexByPropertyAndLabel(GraphPropertyEnum.COMPONENT_TYPE, new Object(), VertexTypeEnum.ADDITIONAL_INFORMATION);
128 void testGetVertexByPropertyAndLabel_1() throws Exception {
130 GraphPropertyEnum name = null;
132 VertexTypeEnum label = null;
133 JsonParseFlagEnum parseFlag = null;
134 Either<GraphVertex, JanusGraphOperationStatus> result;
138 result = dao.getVertexByPropertyAndLabel(name, value, label, parseFlag);
142 void testGetVertexById() throws Exception {
145 Either<GraphVertex, JanusGraphOperationStatus> result;
149 result = dao.getVertexById(id);
153 void testGetVertexById_1() throws Exception {
156 JsonParseFlagEnum parseFlag = null;
157 Either<GraphVertex, JanusGraphOperationStatus> result;
162 result = dao.getVertexById(id, parseFlag);
167 result = dao.getVertexById(id, parseFlag);
171 void testGetVertexProperties() throws Exception {
173 Element element = null;
174 Map<GraphPropertyEnum, Object> result;
179 result = dao.getVertexProperties(element);
183 void testGetEdgeProperties() throws Exception {
185 Element element = null;
186 Map<EdgePropertyEnum, Object> result;
191 result = dao.getEdgeProperties(element);
195 void testGetByCriteria() throws Exception {
197 VertexTypeEnum type = null;
198 Map<GraphPropertyEnum, Object> props = null;
199 Either<List<GraphVertex>, JanusGraphOperationStatus> result;
203 result = dao.getByCriteria(type, props);
207 void testGetByCriteria_1() throws Exception {
209 VertexTypeEnum type = null;
210 Map<GraphPropertyEnum, Object> props = null;
211 JsonParseFlagEnum parseFlag = null;
212 Either<List<GraphVertex>, JanusGraphOperationStatus> result;
216 result = dao.getByCriteria(type, props, parseFlag);
220 void testGetByCriteria_2() throws Exception {
222 VertexTypeEnum type = null;
223 Map<GraphPropertyEnum, Object> props = null;
224 Map<GraphPropertyEnum, Object> hasNotProps = null;
225 JsonParseFlagEnum parseFlag = null;
226 Either<List<GraphVertex>, JanusGraphOperationStatus> result;
230 result = dao.getByCriteria(type, props, hasNotProps, parseFlag);
234 void testGetCatalogVerticies() throws Exception {
236 Either<Iterator<Vertex>, JanusGraphOperationStatus> result;
240 result = dao.getCatalogOrArchiveVerticies(true);
244 void testGetParentVertecies_1() throws Exception {
246 Vertex parentVertex = null;
247 EdgeLabelEnum edgeLabel = null;
248 JsonParseFlagEnum parseFlag = null;
249 Either<List<Vertex>, JanusGraphOperationStatus> result;
253 result = dao.getParentVertices(parentVertex, edgeLabel, parseFlag);
257 void testGetChildrenVertecies_1() throws Exception {
259 Vertex parentVertex = null;
260 EdgeLabelEnum edgeLabel = null;
261 JsonParseFlagEnum parseFlag = null;
262 Either<List<Vertex>, JanusGraphOperationStatus> result;
266 result = dao.getChildrenVertices(parentVertex, edgeLabel, parseFlag);
270 void testUpdateVertexMetadataPropertiesWithJson() throws Exception {
272 Vertex vertex = null;
273 Map<GraphPropertyEnum, Object> properties = null;
274 JanusGraphOperationStatus result;
278 result = dao.updateVertexMetadataPropertiesWithJson(vertex, properties);
282 void testGetProperty() throws Exception {
283 Edge edge = Mockito.mock(Edge.class);
287 Property<Object> value = Mockito.mock(Property.class);
288 Mockito.when(edge.property(Mockito.any())).thenReturn(value);
291 result = dao.getProperty(edge, EdgePropertyEnum.STATE);
295 void testGetProperty_1() throws Exception {
296 Edge edge = Mockito.mock(Edge.class);
301 result = dao.getProperty(edge, EdgePropertyEnum.STATE);
305 void testGetPropertyexception() throws Exception {
306 Edge edge = Mockito.mock(Edge.class);
310 Property<Object> value = Mockito.mock(Property.class);
311 Mockito.when(edge.property(Mockito.any())).thenThrow(RuntimeException.class);
314 result = dao.getProperty(edge, EdgePropertyEnum.STATE);
318 void testGetBelongingEdgeByCriteria_1() throws Exception {
320 String parentId = "";
321 EdgeLabelEnum label = null;
322 Map<GraphPropertyEnum, Object> properties = null;
323 Either<Edge, JanusGraphOperationStatus> result;
327 result = dao.getBelongingEdgeByCriteria(parentId, label, properties);