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