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