Improve test coverage
[sdc.git] / catalog-dao / src / test / java / org / openecomp / sdc / be / dao / janusgraph / JanusGraphDaoTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.dao.janusgraph;
22
23 import fj.data.Either;
24 import java.util.Iterator;
25 import java.util.List;
26 import java.util.Map;
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
45 class JanusGraphDaoTest extends DAOConfDependentTest {
46
47     private final JanusGraphDao dao = new JanusGraphDao(new JanusGraphClient(new DAOJanusGraphStrategy()));
48
49     @BeforeEach
50     void init() {
51         dao.getJanusGraphClient().createGraph();
52     }
53
54     @AfterEach
55     void end() {
56         dao.getJanusGraphClient().cleanupGraph();
57     }
58
59     @Test
60     void testCreateVertex() throws Exception {
61         Either<GraphVertex, JanusGraphOperationStatus> result;
62
63         // default test
64         GraphVertex graphVertex = new GraphVertex(VertexTypeEnum.REQUIREMENTS);
65         result = dao.createVertex(graphVertex);
66
67         graphVertex = new GraphVertex();
68         result = dao.createVertex(graphVertex);
69     }
70
71     @Test
72     void testGetVertexByLabel() throws Exception {
73         Either<GraphVertex, JanusGraphOperationStatus> result;
74
75         dao.createVertex(new GraphVertex(VertexTypeEnum.ADDITIONAL_INFORMATION));
76         // default test
77         result = dao.getVertexByLabel(VertexTypeEnum.ADDITIONAL_INFORMATION);
78     }
79
80     @Test
81     void testCommit() throws Exception {
82         JanusGraphOperationStatus result;
83
84         // default test
85
86         result = dao.commit();
87     }
88
89     @Test
90     void testRollback() throws Exception {
91
92         JanusGraphOperationStatus result;
93
94         // default test
95
96         result = dao.rollback();
97     }
98
99     @Test
100     void testGetGraph() throws Exception {
101
102         Either<JanusGraph, JanusGraphOperationStatus> result;
103
104         // default test
105
106         result = dao.getJanusGraphClient().getGraph();
107     }
108
109     @Test
110     void testGetVertexByPropertyAndLabel() throws Exception {
111
112         GraphPropertyEnum name = null;
113         Object value = null;
114         VertexTypeEnum label = null;
115         Either<GraphVertex, JanusGraphOperationStatus> result;
116
117         // default test
118
119         result = dao.getVertexByPropertyAndLabel(name, value, label);
120
121         result = dao.getVertexByPropertyAndLabel(GraphPropertyEnum.COMPONENT_TYPE, new Object(), VertexTypeEnum.ADDITIONAL_INFORMATION);
122     }
123
124     @Test
125     void testGetVertexByPropertyAndLabel_1() throws Exception {
126
127         GraphPropertyEnum name = null;
128         Object value = null;
129         VertexTypeEnum label = null;
130         JsonParseFlagEnum parseFlag = null;
131         Either<GraphVertex, JanusGraphOperationStatus> result;
132
133         // default test
134
135         result = dao.getVertexByPropertyAndLabel(name, value, label, parseFlag);
136     }
137
138     @Test
139     void testGetVertexById() throws Exception {
140
141         String id = "";
142         Either<GraphVertex, JanusGraphOperationStatus> result;
143
144         // default test
145
146         result = dao.getVertexById(id);
147     }
148
149     @Test
150     void testGetVertexById_1() throws Exception {
151
152         String id = "";
153         JsonParseFlagEnum parseFlag = null;
154         Either<GraphVertex, JanusGraphOperationStatus> result;
155
156         // test 1
157
158         id = null;
159         result = dao.getVertexById(id, parseFlag);
160
161         // test 2
162
163         id = "";
164         result = dao.getVertexById(id, parseFlag);
165     }
166
167     @Test
168     void testGetVertexProperties() throws Exception {
169
170         Element element = null;
171         Map<GraphPropertyEnum, Object> result;
172
173         // test 1
174
175         element = null;
176         result = dao.getVertexProperties(element);
177     }
178
179     @Test
180     void testGetEdgeProperties() throws Exception {
181
182         Element element = null;
183         Map<EdgePropertyEnum, Object> result;
184
185         // test 1
186
187         element = null;
188         result = dao.getEdgeProperties(element);
189     }
190
191     @Test
192     void testGetByCriteria() throws Exception {
193
194         VertexTypeEnum type = null;
195         Map<GraphPropertyEnum, Object> props = null;
196         Either<List<GraphVertex>, JanusGraphOperationStatus> result;
197
198         // default test
199
200         result = dao.getByCriteria(type, props);
201     }
202
203     @Test
204     void testGetByCriteria_1() throws Exception {
205
206         VertexTypeEnum type = null;
207         Map<GraphPropertyEnum, Object> props = null;
208         JsonParseFlagEnum parseFlag = null;
209         Either<List<GraphVertex>, JanusGraphOperationStatus> result;
210
211         // default test
212
213         result = dao.getByCriteria(type, props, parseFlag);
214     }
215
216     @Test
217     void testGetByCriteria_2() throws Exception {
218
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;
224
225         // default test
226
227         result = dao.getByCriteria(type, props, hasNotProps, parseFlag);
228     }
229
230     @Test
231     void testGetCatalogVerticies() throws Exception {
232
233         Either<Iterator<Vertex>, JanusGraphOperationStatus> result;
234
235         // default test
236
237         result = dao.getCatalogOrArchiveVertices(true);
238     }
239
240     @Test
241     void testGetParentVertecies_1() throws Exception {
242
243         Vertex parentVertex = null;
244         EdgeLabelEnum edgeLabel = null;
245         JsonParseFlagEnum parseFlag = null;
246         Either<List<Vertex>, JanusGraphOperationStatus> result;
247
248         // default test
249
250         result = dao.getParentVertices(parentVertex, edgeLabel);
251     }
252
253     @Test
254     void testGetChildrenVertecies_1() throws Exception {
255
256         Vertex parentVertex = null;
257         EdgeLabelEnum edgeLabel = null;
258         JsonParseFlagEnum parseFlag = null;
259         Either<List<Vertex>, JanusGraphOperationStatus> result;
260
261         // default test
262
263         result = dao.getChildrenVertices(parentVertex, edgeLabel);
264     }
265
266     @Test
267     void testUpdateVertexMetadataPropertiesWithJson() throws Exception {
268
269         Vertex vertex = null;
270         Map<GraphPropertyEnum, Object> properties = null;
271         JanusGraphOperationStatus result;
272
273         // default test
274
275         result = dao.updateVertexMetadataPropertiesWithJson(vertex, properties);
276     }
277
278     @Test
279     void testGetProperty() throws Exception {
280         Edge edge = Mockito.mock(Edge.class);
281         ;
282         Object result;
283
284         Property<Object> value = Mockito.mock(Property.class);
285         Mockito.when(edge.property(Mockito.any())).thenReturn(value);
286
287         // default test
288         result = dao.getProperty(edge, EdgePropertyEnum.STATE);
289     }
290
291     @Test
292     void testGetProperty_1() throws Exception {
293         Edge edge = Mockito.mock(Edge.class);
294         ;
295         Object result;
296
297         // default test
298         result = dao.getProperty(edge, EdgePropertyEnum.STATE);
299     }
300
301     @Test
302     void testGetPropertyexception() throws Exception {
303         Edge edge = Mockito.mock(Edge.class);
304         ;
305         Object result;
306
307         Property<Object> value = Mockito.mock(Property.class);
308         Mockito.when(edge.property(Mockito.any())).thenThrow(RuntimeException.class);
309
310         // default test
311         result = dao.getProperty(edge, EdgePropertyEnum.STATE);
312     }
313
314     @Test
315     void testGetBelongingEdgeByCriteria_1() throws Exception {
316
317         String parentId = "";
318         EdgeLabelEnum label = null;
319         Map<GraphPropertyEnum, Object> properties = null;
320         Either<Edge, JanusGraphOperationStatus> result;
321
322         // default test
323
324         result = dao.getBelongingEdgeByCriteria(parentId, label, properties);
325     }
326 }