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;
45 class JanusGraphDaoTest extends DAOConfDependentTest {
47 private final JanusGraphDao dao = new JanusGraphDao(new JanusGraphClient(new DAOJanusGraphStrategy()));
51 dao.getJanusGraphClient().createGraph();
56 dao.getJanusGraphClient().cleanupGraph();
60 void testCreateVertex() throws Exception {
61 Either<GraphVertex, JanusGraphOperationStatus> result;
64 GraphVertex graphVertex = new GraphVertex(VertexTypeEnum.REQUIREMENTS);
65 result = dao.createVertex(graphVertex);
67 graphVertex = new GraphVertex();
68 result = dao.createVertex(graphVertex);
72 void testGetVertexByLabel() throws Exception {
73 Either<GraphVertex, JanusGraphOperationStatus> result;
75 dao.createVertex(new GraphVertex(VertexTypeEnum.ADDITIONAL_INFORMATION));
77 result = dao.getVertexByLabel(VertexTypeEnum.ADDITIONAL_INFORMATION);
81 void testCommit() throws Exception {
82 JanusGraphOperationStatus result;
86 result = dao.commit();
90 void testRollback() throws Exception {
92 JanusGraphOperationStatus result;
96 result = dao.rollback();
100 void testGetGraph() throws Exception {
102 Either<JanusGraph, JanusGraphOperationStatus> result;
106 result = dao.getJanusGraphClient().getGraph();
110 void testGetVertexByPropertyAndLabel() throws Exception {
112 GraphPropertyEnum name = null;
114 VertexTypeEnum label = null;
115 Either<GraphVertex, JanusGraphOperationStatus> result;
119 result = dao.getVertexByPropertyAndLabel(name, value, label);
121 result = dao.getVertexByPropertyAndLabel(GraphPropertyEnum.COMPONENT_TYPE, new Object(), VertexTypeEnum.ADDITIONAL_INFORMATION);
125 void testGetVertexByPropertyAndLabel_1() throws Exception {
127 GraphPropertyEnum name = null;
129 VertexTypeEnum label = null;
130 JsonParseFlagEnum parseFlag = null;
131 Either<GraphVertex, JanusGraphOperationStatus> result;
135 result = dao.getVertexByPropertyAndLabel(name, value, label, parseFlag);
139 void testGetVertexById() throws Exception {
142 Either<GraphVertex, JanusGraphOperationStatus> result;
146 result = dao.getVertexById(id);
150 void testGetVertexById_1() throws Exception {
153 JsonParseFlagEnum parseFlag = null;
154 Either<GraphVertex, JanusGraphOperationStatus> result;
159 result = dao.getVertexById(id, parseFlag);
164 result = dao.getVertexById(id, parseFlag);
168 void testGetVertexProperties() throws Exception {
170 Element element = null;
171 Map<GraphPropertyEnum, Object> result;
176 result = dao.getVertexProperties(element);
180 void testGetEdgeProperties() throws Exception {
182 Element element = null;
183 Map<EdgePropertyEnum, Object> result;
188 result = dao.getEdgeProperties(element);
192 void testGetByCriteria() throws Exception {
194 VertexTypeEnum type = null;
195 Map<GraphPropertyEnum, Object> props = null;
196 Either<List<GraphVertex>, JanusGraphOperationStatus> result;
200 result = dao.getByCriteria(type, props);
204 void testGetByCriteria_1() throws Exception {
206 VertexTypeEnum type = null;
207 Map<GraphPropertyEnum, Object> props = null;
208 JsonParseFlagEnum parseFlag = null;
209 Either<List<GraphVertex>, JanusGraphOperationStatus> result;
213 result = dao.getByCriteria(type, props, parseFlag);
217 void testGetByCriteria_2() throws Exception {
219 VertexTypeEnum type = null;
220 Map<GraphPropertyEnum, Object> props = null;
221 Map<GraphPropertyEnum, Object> hasNotProps = null;
222 JsonParseFlagEnum parseFlag = null;
223 Either<List<GraphVertex>, JanusGraphOperationStatus> result;
227 result = dao.getByCriteria(type, props, hasNotProps, parseFlag);
231 void testGetCatalogVerticies() throws Exception {
233 Either<Iterator<Vertex>, JanusGraphOperationStatus> result;
237 result = dao.getCatalogOrArchiveVertices(true);
241 void testGetParentVertecies_1() throws Exception {
243 Vertex parentVertex = null;
244 EdgeLabelEnum edgeLabel = null;
245 JsonParseFlagEnum parseFlag = null;
246 Either<List<Vertex>, JanusGraphOperationStatus> result;
250 result = dao.getParentVertices(parentVertex, edgeLabel);
254 void testGetChildrenVertecies_1() throws Exception {
256 Vertex parentVertex = null;
257 EdgeLabelEnum edgeLabel = null;
258 JsonParseFlagEnum parseFlag = null;
259 Either<List<Vertex>, JanusGraphOperationStatus> result;
263 result = dao.getChildrenVertices(parentVertex, edgeLabel);
267 void testUpdateVertexMetadataPropertiesWithJson() throws Exception {
269 Vertex vertex = null;
270 Map<GraphPropertyEnum, Object> properties = null;
271 JanusGraphOperationStatus result;
275 result = dao.updateVertexMetadataPropertiesWithJson(vertex, properties);
279 void testGetProperty() throws Exception {
280 Edge edge = Mockito.mock(Edge.class);
284 Property<Object> value = Mockito.mock(Property.class);
285 Mockito.when(edge.property(Mockito.any())).thenReturn(value);
288 result = dao.getProperty(edge, EdgePropertyEnum.STATE);
292 void testGetProperty_1() throws Exception {
293 Edge edge = Mockito.mock(Edge.class);
298 result = dao.getProperty(edge, EdgePropertyEnum.STATE);
302 void testGetPropertyexception() throws Exception {
303 Edge edge = Mockito.mock(Edge.class);
307 Property<Object> value = Mockito.mock(Property.class);
308 Mockito.when(edge.property(Mockito.any())).thenThrow(RuntimeException.class);
311 result = dao.getProperty(edge, EdgePropertyEnum.STATE);
315 void testGetBelongingEdgeByCriteria_1() throws Exception {
317 String parentId = "";
318 EdgeLabelEnum label = null;
319 Map<GraphPropertyEnum, Object> properties = null;
320 Either<Edge, JanusGraphOperationStatus> result;
324 result = dao.getBelongingEdgeByCriteria(parentId, label, properties);