re base code
[sdc.git] / catalog-dao / src / test / java / org / openecomp / sdc / be / dao / jsongraph / TitanDaoMockTest.java
1 package org.openecomp.sdc.be.dao.jsongraph;
2
3 import com.thinkaurelius.titan.core.TitanGraph;
4 import com.thinkaurelius.titan.core.TitanVertex;
5 import fj.data.Either;
6 import mockit.Deencapsulation;
7 import org.apache.commons.lang3.tuple.ImmutablePair;
8 import org.apache.tinkerpop.gremlin.structure.Direction;
9 import org.apache.tinkerpop.gremlin.structure.Edge;
10 import org.apache.tinkerpop.gremlin.structure.Element;
11 import org.apache.tinkerpop.gremlin.structure.Vertex;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.mockito.InjectMocks;
15 import org.mockito.Mock;
16 import org.mockito.Mockito;
17 import org.mockito.MockitoAnnotations;
18 import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
19 import org.openecomp.sdc.be.dao.jsongraph.types.EdgePropertyEnum;
20 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
21 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
22 import org.openecomp.sdc.be.dao.titan.TitanGraphClient;
23 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
24 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
25
26 import java.util.HashMap;
27 import java.util.Iterator;
28 import java.util.List;
29 import java.util.Map;
30
31 public class TitanDaoMockTest {
32
33         @InjectMocks
34         TitanDao testSubject;
35
36         @Mock
37         TitanGraphClient titanClient;
38
39         @Before
40         public void setUp() throws Exception {
41                 MockitoAnnotations.initMocks(this);
42         }
43
44         @Test
45         public void testCommit() throws Exception {
46                 TitanOperationStatus result;
47
48                 // default test
49                 result = testSubject.commit();
50         }
51
52         @Test
53         public void testRollback() throws Exception {
54                 TitanOperationStatus result;
55
56                 // default test
57                 result = testSubject.rollback();
58         }
59
60         @Test
61         public void testGetGraph() throws Exception {
62
63                 Either<TitanGraph, TitanOperationStatus> result;
64
65                 // default test
66
67                 result = testSubject.getGraph();
68         }
69
70         @Test
71         public void testCreateVertex() throws Exception {
72
73                 GraphVertex graphVertex = new GraphVertex();
74                 graphVertex.setLabel(VertexTypeEnum.ADDITIONAL_INFORMATION);
75                 Either<GraphVertex, TitanOperationStatus> result;
76
77                 TitanGraph tg = Mockito.mock(TitanGraph.class);
78                 Either<TitanGraph, TitanOperationStatus> value = Either.left(tg);
79                 // default test
80                 TitanVertex value2 = Mockito.mock(TitanVertex.class);
81                 Mockito.when(tg.addVertex()).thenReturn(value2);
82                 Mockito.when(titanClient.getGraph()).thenReturn(value);
83                 result = testSubject.createVertex(graphVertex);
84         }
85
86         @Test
87         public void testCreateVertexErrorGetGraph() throws Exception {
88
89                 GraphVertex graphVertex = new GraphVertex();
90                 graphVertex.setLabel(VertexTypeEnum.ADDITIONAL_INFORMATION);
91                 Either<GraphVertex, TitanOperationStatus> result;
92
93                 Either<TitanGraph, TitanOperationStatus> value = Either.right(TitanOperationStatus.GENERAL_ERROR);
94                 // default test
95                 Mockito.when(titanClient.getGraph()).thenReturn(value);
96                 result = testSubject.createVertex(graphVertex);
97         }
98
99         @Test
100         public void testCreateVertexException() throws Exception {
101
102                 GraphVertex graphVertex = new GraphVertex();
103                 graphVertex.setLabel(VertexTypeEnum.ADDITIONAL_INFORMATION);
104                 Either<GraphVertex, TitanOperationStatus> result;
105
106                 TitanGraph tg = Mockito.mock(TitanGraph.class);
107                 Either<TitanGraph, TitanOperationStatus> value = Either.left(tg);
108                 // default test
109                 Mockito.when(tg.addVertex()).thenThrow(RuntimeException.class);
110                 Mockito.when(titanClient.getGraph()).thenReturn(value);
111                 result = testSubject.createVertex(graphVertex);
112         }
113
114         @Test
115         public void testGetVertexByPropertyAndLabel() throws Exception {
116                 Either<GraphVertex, TitanOperationStatus> result;
117
118                 // default test
119                 Mockito.when(titanClient.getGraph()).thenReturn(Either.right(TitanOperationStatus.GENERAL_ERROR));
120                 result = testSubject.getVertexByPropertyAndLabel(GraphPropertyEnum.COMPONENT_TYPE, "mock",
121                                 VertexTypeEnum.ADDITIONAL_INFORMATION);
122         }
123
124         @Test
125         public void testGetFirstFoundVertex() throws Exception {
126                 Iterable<TitanVertex> vertices = Mockito.mock(Iterable.class);
127                 Either<GraphVertex, TitanOperationStatus> result;
128
129                 Iterator<TitanVertex> value = Mockito.mock(Iterator.class);
130                 Mockito.when(vertices.iterator()).thenReturn(value);
131                 Mockito.when(value.hasNext()).thenReturn(true);
132                 TitanVertex value2 = Mockito.mock(TitanVertex.class);
133                 Mockito.when(value.next()).thenReturn(value2);
134
135                 // default test
136                 result = Deencapsulation.invoke(testSubject, "getFirstFoundVertex", JsonParseFlagEnum.NoParse, vertices);
137         }
138
139         @Test
140         public void testGetFirstFoundVertexNotFound() throws Exception {
141                 Iterable<TitanVertex> vertices = Mockito.mock(Iterable.class);
142                 Either<GraphVertex, TitanOperationStatus> result;
143
144                 Iterator<TitanVertex> value = Mockito.mock(Iterator.class);
145                 Mockito.when(vertices.iterator()).thenReturn(value);
146                 Mockito.when(value.hasNext()).thenReturn(false);
147                 TitanVertex value2 = Mockito.mock(TitanVertex.class);
148                 Mockito.when(value.next()).thenReturn(value2);
149
150                 // default test
151                 result = Deencapsulation.invoke(testSubject, "getFirstFoundVertex", JsonParseFlagEnum.NoParse, vertices);
152         }
153
154         @Test
155         public void testGetVertexById_1Exception() throws Exception {
156
157                 String id = "mock";
158                 Either<GraphVertex, TitanOperationStatus> result;
159
160                 TitanGraph tg = Mockito.mock(TitanGraph.class);
161                 Either<TitanGraph, TitanOperationStatus> value = Either.left(tg);
162                 // default test
163                 TitanVertex value2 = Mockito.mock(TitanVertex.class);
164                 Mockito.when(tg.addVertex()).thenReturn(value2);
165                 Mockito.when(titanClient.getGraph()).thenReturn(value);
166
167                 // test 1
168                 result = testSubject.getVertexById(id, JsonParseFlagEnum.NoParse);
169                 // Assert.assertEquals(null, result);
170         }
171
172         @Test
173         public void testGetVertexById_1GraphClosed() throws Exception {
174
175                 String id = "mock";
176                 Either<GraphVertex, TitanOperationStatus> result;
177
178                 Object b;
179                 Either<TitanGraph, TitanOperationStatus> value = Either.right(TitanOperationStatus.GENERAL_ERROR);
180                 // default test
181                 TitanVertex value2 = Mockito.mock(TitanVertex.class);
182                 Mockito.when(titanClient.getGraph()).thenReturn(value);
183
184                 // test 1
185                 result = testSubject.getVertexById(id, JsonParseFlagEnum.NoParse);
186                 // Assert.assertEquals(null, result);
187         }
188
189         @Test
190         public void testSetVertexProperties_1() throws Exception {
191                 Vertex vertex = Mockito.mock(Vertex.class);
192                 Map<String, Object> properties = new HashMap<>();
193                 properties.put("mock", "mock");
194
195                 // default test
196                 testSubject.setVertexProperties(vertex, properties);
197         }
198
199         @Test
200         public void testCreateAndFill() throws Exception {
201
202                 TitanVertex vertex = Mockito.mock(TitanVertex.class);
203                 JsonParseFlagEnum parseFlag = null;
204                 GraphVertex result;
205
206                 // default test
207
208                 result = Deencapsulation.invoke(testSubject, "createAndFill", vertex, JsonParseFlagEnum.NoParse);
209         }
210
211         @Test
212         public void testParseVertexProperties() throws Exception {
213
214                 GraphVertex graphVertex = new GraphVertex();
215                 TitanVertex vertex = Mockito.mock(TitanVertex.class);
216                 graphVertex.setVertex(vertex);
217                 JsonParseFlagEnum parseFlag = null;
218
219                 // default test
220
221                 testSubject.parseVertexProperties(graphVertex, JsonParseFlagEnum.NoParse);
222         }
223
224
225         @Test
226         public void testCreateEdge() throws Exception {
227
228                 GraphVertex from = Mockito.mock(GraphVertex.class);
229                 GraphVertex to = Mockito.mock(GraphVertex.class);
230                 
231                 TitanVertex value = Mockito.mock(TitanVertex.class);
232                 Mockito.when(from.getVertex()).thenReturn(value);
233                 Mockito.when(to.getVertex()).thenReturn(value);
234                 Map<EdgePropertyEnum, Object> properties = new HashMap<>();
235                 TitanOperationStatus result;
236
237                 // default test
238
239                 result = testSubject.createEdge(from, to, EdgeLabelEnum.ADDITIONAL_INFORMATION, properties);
240                 from = new GraphVertex();
241                 to = new GraphVertex();
242                 result = testSubject.createEdge(from, to, EdgeLabelEnum.ADDITIONAL_INFORMATION, properties);
243         }
244
245         @Test
246         public void testSetEdgeProperties() throws Exception {
247
248                 Element element = Mockito.mock(Element.class);
249                 Map<EdgePropertyEnum, Object> properties = new HashMap<>();
250
251                 // test 1
252
253                 properties.put(EdgePropertyEnum.STATE, "mock");
254                 testSubject.setEdgeProperties(element, properties);
255         }
256
257         @Test
258         public void testGetByCriteria() throws Exception {
259                 Map<GraphPropertyEnum, Object> props = new HashMap<>();
260                 Either<List<GraphVertex>, TitanOperationStatus> result;
261
262                 TitanGraph tg = Mockito.mock(TitanGraph.class);
263                 Either<TitanGraph, TitanOperationStatus> value = Either.left(tg);
264                 TitanVertex value2 = Mockito.mock(TitanVertex.class);
265                 Mockito.when(tg.addVertex()).thenReturn(value2);
266                 Mockito.when(titanClient.getGraph()).thenReturn(value);
267                 
268                 // default test
269                 result = testSubject.getByCriteria(VertexTypeEnum.ADDITIONAL_INFORMATION, props);
270         }
271
272         @Test
273         public void testGetByCriteria_1() throws Exception {
274
275                 Map<GraphPropertyEnum, Object> props = new HashMap<>();
276                 Either<List<GraphVertex>, TitanOperationStatus> result;
277
278                 Either<TitanGraph, TitanOperationStatus> value = Either.right(TitanOperationStatus.GENERAL_ERROR);
279                 TitanVertex value2 = Mockito.mock(TitanVertex.class);
280                 Mockito.when(titanClient.getGraph()).thenReturn(value);
281
282                 // default test
283                 result = testSubject.getByCriteria(VertexTypeEnum.ADDITIONAL_INFORMATION, props, JsonParseFlagEnum.NoParse);
284         }
285
286         @Test
287         public void testGetCatalogVerticies() throws Exception {
288                 Either<Iterator<Vertex>, TitanOperationStatus> result;
289
290                 Either<TitanGraph, TitanOperationStatus> value = Either.right(TitanOperationStatus.GENERAL_ERROR);
291                 // default test
292                 TitanVertex value2 = Mockito.mock(TitanVertex.class);
293                 Mockito.when(titanClient.getGraph()).thenReturn(value);
294                 
295                 // default test
296                 result = testSubject.getCatalogOrArchiveVerticies(true);
297         }
298
299         @Test
300         public void testGetChildVertex() throws Exception {
301
302                 GraphVertex parentVertex = new GraphVertex();
303                 EdgeLabelEnum edgeLabel = null;
304                 JsonParseFlagEnum parseFlag = null;
305                 Either<GraphVertex, TitanOperationStatus> result;
306
307                 Either<TitanGraph, TitanOperationStatus> value = Either.right(TitanOperationStatus.GENERAL_ERROR);
308                 TitanVertex value2 = Mockito.mock(TitanVertex.class);
309                 Mockito.when(titanClient.getGraph()).thenReturn(value);
310                 
311                 // default test
312                 result = testSubject.getChildVertex(parentVertex, EdgeLabelEnum.ADDITIONAL_INFORMATION, JsonParseFlagEnum.NoParse);
313         }
314
315         @Test
316         public void testGetChildVertex_1() throws Exception {
317
318                 Vertex parentVertex = null;
319                 EdgeLabelEnum edgeLabel = null;
320                 JsonParseFlagEnum parseFlag = null;
321                 Either<Vertex, TitanOperationStatus> result;
322
323                 Either<TitanGraph, TitanOperationStatus> value = Either.right(TitanOperationStatus.GENERAL_ERROR);
324                 TitanVertex value2 = Mockito.mock(TitanVertex.class);
325                 Mockito.when(titanClient.getGraph()).thenReturn(value);
326
327                 // default test
328                 result = testSubject.getChildVertex(parentVertex, edgeLabel, parseFlag);
329         }
330
331
332         @Test
333         public void testGetParentVertex_1() throws Exception {
334
335                 Vertex parentVertex = null;
336                 EdgeLabelEnum edgeLabel = null;
337                 JsonParseFlagEnum parseFlag = null;
338                 Either<Vertex, TitanOperationStatus> result;
339
340                 // default test
341
342                 result = testSubject.getParentVertex(parentVertex, edgeLabel, parseFlag);
343         }
344
345         @Test
346         public void testGetParentVertecies_1() throws Exception {
347
348                 Vertex parentVertex = null;
349                 EdgeLabelEnum edgeLabel = null;
350                 JsonParseFlagEnum parseFlag = null;
351                 Either<List<Vertex>, TitanOperationStatus> result;
352
353                 // default test
354
355                 result = testSubject.getParentVertecies(parentVertex, edgeLabel, parseFlag);
356         }
357
358         @Test
359         public void testGetAdjacentVerticies() throws Exception {
360
361                 Vertex parentVertex = null;
362                 EdgeLabelEnum edgeLabel = null;
363                 JsonParseFlagEnum parseFlag = null;
364                 Direction direction = null;
365                 Either<List<Vertex>, TitanOperationStatus> result;
366
367                 Either<TitanGraph, TitanOperationStatus> value = Either.right(TitanOperationStatus.GENERAL_ERROR);
368                 TitanVertex value2 = Mockito.mock(TitanVertex.class);
369                 Mockito.when(titanClient.getGraph()).thenReturn(value);
370                 // default test
371                 result = Deencapsulation.invoke(testSubject, "getAdjacentVerticies",
372                                 new Object[] { Vertex.class, EdgeLabelEnum.class, JsonParseFlagEnum.class, Direction.class });
373         }
374
375         @Test
376         public void testGetChildrenVertecies_1() throws Exception {
377
378                 Vertex parentVertex = null;
379                 EdgeLabelEnum edgeLabel = null;
380                 JsonParseFlagEnum parseFlag = null;
381                 Either<List<Vertex>, TitanOperationStatus> result;
382
383                 // default test
384
385                 result = testSubject.getChildrenVertecies(parentVertex, edgeLabel, parseFlag);
386         }
387
388
389         @Test
390         public void testDeleteBelongingEdgeByCriteria() throws Exception {
391
392                 GraphVertex vertex = null;
393                 EdgeLabelEnum label = null;
394                 Map<GraphPropertyEnum, Object> properties = null;
395                 Either<Edge, TitanOperationStatus> result;
396
397                 // default test
398
399                 result = testSubject.deleteBelongingEdgeByCriteria(vertex, label, properties);
400         }
401
402         @Test
403         public void testDeleteEdge() throws Exception {
404
405                 GraphVertex fromVertex = new GraphVertex();
406                 GraphVertex toVertex = new GraphVertex();
407                 Either<Edge, TitanOperationStatus> result;
408
409                 Either<TitanGraph, TitanOperationStatus> value = Either.right(TitanOperationStatus.GENERAL_ERROR);
410                 TitanVertex value2 = Mockito.mock(TitanVertex.class);
411                 Mockito.when(titanClient.getGraph()).thenReturn(value);
412                 
413                 // default test
414                 result = testSubject.deleteEdge(fromVertex, toVertex, EdgeLabelEnum.ADDITIONAL_INFORMATION);
415         }
416
417         @Test
418         public void testDeleteEdgeByDirection() throws Exception {
419                 GraphVertex fromVertex = new GraphVertex();
420                 TitanOperationStatus result;
421
422                 // default test
423                 result = testSubject.deleteEdgeByDirection(fromVertex, Direction.BOTH, EdgeLabelEnum.ADDITIONAL_INFORMATION);
424         }
425
426         @Test
427         public void testDeleteEdgeByDirectionMock() throws Exception {
428                 GraphVertex fromVertex = Mockito.mock(GraphVertex.class);
429                 TitanOperationStatus result;
430
431                 TitanVertex value = Mockito.mock(TitanVertex.class);;
432                 Mockito.when(fromVertex.getVertex()).thenReturn(value);
433                 Iterator<Edge> value2 = Mockito.mock(Iterator.class);;
434                 Mockito.when(value.edges(Mockito.any(), Mockito.any())).thenReturn(value2);
435                 Mockito.when(value2.hasNext()).thenReturn(true, false);
436                 Edge value3 = Mockito.mock(Edge.class);;
437                 Mockito.when(value2.next()).thenReturn(value3);
438                 // default test
439                 result = testSubject.deleteEdgeByDirection(fromVertex, Direction.BOTH, EdgeLabelEnum.ADDITIONAL_INFORMATION);
440         }
441         
442         @Test
443         public void testUpdateVertex() throws Exception {
444
445                 GraphVertex graphVertex = new GraphVertex();
446                 Either<GraphVertex, TitanOperationStatus> result;
447
448                 // default test
449
450                 result = testSubject.updateVertex(graphVertex);
451         }
452
453         @Test
454         public void testGetVerticesByUniqueIdAndParseFlag() throws Exception {
455
456                 Map<String, ImmutablePair<GraphPropertyEnum, JsonParseFlagEnum>> verticesToGet = new HashMap<>();
457                 Either<Map<String, GraphVertex>, TitanOperationStatus> result;
458                 
459                 // default test
460                 result = testSubject.getVerticesByUniqueIdAndParseFlag(verticesToGet);
461                 ImmutablePair<GraphPropertyEnum, JsonParseFlagEnum> value3 = ImmutablePair.of(GraphPropertyEnum.COMPONENT_TYPE, JsonParseFlagEnum.NoParse);
462                 verticesToGet.put("mock", value3);
463                 try {
464                         result = testSubject.getVerticesByUniqueIdAndParseFlag(verticesToGet);
465                 } catch (Exception e) {
466                         // TODO Auto-generated catch block
467                         e.printStackTrace();
468                 }
469         }
470
471         @Test
472         public void testCreateEdge_2() throws Exception {
473
474                 Vertex from = null;
475                 Vertex to = null;
476                 EdgeLabelEnum label = null;
477                 Edge edgeToCopy = null;
478                 TitanOperationStatus result;
479
480                 // default test
481
482                 result = testSubject.createEdge(from, to, label, edgeToCopy);
483         }
484
485
486         @Test
487         public void testReplaceEdgeLabel() throws Exception {
488
489                 Vertex fromVertex = null;
490                 Vertex toVertex = null;
491                 Edge prevEdge = null;
492                 EdgeLabelEnum prevLabel = null;
493                 EdgeLabelEnum newLabel = null;
494                 TitanOperationStatus result;
495
496                 // default test
497
498                 result = testSubject.replaceEdgeLabel(fromVertex, toVertex, prevEdge, prevLabel, newLabel);
499         }
500
501         @Test
502         public void testUpdateVertexMetadataPropertiesWithJson() throws Exception {
503
504                 Vertex vertex = Mockito.mock(Vertex.class);;
505                 Map<GraphPropertyEnum, Object> properties = new HashMap<>();
506                 properties.put(GraphPropertyEnum.COMPONENT_TYPE, "mock");
507                 TitanOperationStatus result;
508
509                 // default test
510
511                 result = testSubject.updateVertexMetadataPropertiesWithJson(vertex, properties);
512         }
513
514         //TODO Last
515         @Test
516         public void testDisassociateAndDeleteLast() throws Exception {
517
518                 GraphVertex vertex = Mockito.mock(GraphVertex.class);
519                 TitanOperationStatus result;
520                 
521                 TitanVertex value = Mockito.mock(TitanVertex.class);
522                 Iterator<Edge> mockiter = Mockito.mock(Iterator.class);
523                 Edge nextmock = Mockito.mock(Edge.class);
524                 Mockito.when(vertex.getVertex()).thenReturn(value);
525                 Mockito.when(value.edges(Mockito.any(), Mockito.any())).thenReturn(mockiter);
526                 Mockito.when(mockiter.hasNext()).thenReturn(true, false);
527                 Mockito.when(mockiter.next()).thenReturn(nextmock);
528                 Vertex secondVertex = Mockito.mock(Vertex.class);
529                 Mockito.when(nextmock.outVertex()).thenReturn(secondVertex);
530                 Mockito.when(nextmock.inVertex()).thenReturn(secondVertex);
531                 Iterator<Edge> restOfEdges = Mockito.mock(Iterator.class);
532                 Mockito.when(secondVertex.edges(Mockito.any(), Mockito.any())).thenReturn(restOfEdges);
533                 Mockito.when(restOfEdges.hasNext()).thenReturn(false);
534                 
535                 // default test
536                 result = testSubject.disassociateAndDeleteLast(vertex, Direction.OUT, EdgeLabelEnum.ADDITIONAL_INFORMATION);
537         }
538         
539         @Test
540         public void testDisassociateAndDeleteLastOut() throws Exception {
541
542                 GraphVertex vertex = Mockito.mock(GraphVertex.class);
543                 TitanOperationStatus result;
544                 
545                 TitanVertex value = Mockito.mock(TitanVertex.class);
546                 Iterator<Edge> mockiter = Mockito.mock(Iterator.class);
547                 Edge nextmock = Mockito.mock(Edge.class);
548                 Mockito.when(vertex.getVertex()).thenReturn(value);
549                 Mockito.when(value.edges(Mockito.any(), Mockito.any())).thenReturn(mockiter);
550                 Mockito.when(mockiter.hasNext()).thenReturn(true, false);
551                 Mockito.when(mockiter.next()).thenReturn(nextmock);
552                 Vertex secondVertex = Mockito.mock(Vertex.class);
553                 Mockito.when(nextmock.outVertex()).thenReturn(secondVertex);
554                 Mockito.when(nextmock.inVertex()).thenReturn(secondVertex);
555                 Iterator<Edge> restOfEdges = Mockito.mock(Iterator.class);
556                 Mockito.when(secondVertex.edges(Mockito.any(), Mockito.any())).thenReturn(restOfEdges);
557                 Mockito.when(restOfEdges.hasNext()).thenReturn(false);
558                 
559                 // default test
560                 result = testSubject.disassociateAndDeleteLast(vertex, Direction.IN, EdgeLabelEnum.ADDITIONAL_INFORMATION);
561         }
562         
563         @Test
564         public void testDisassociateAndDeleteLastException() throws Exception {
565
566                 GraphVertex vertex = Mockito.mock(GraphVertex.class);
567                 TitanOperationStatus result;
568                 
569                 Mockito.when(vertex.getVertex()).thenThrow(RuntimeException.class);
570                 
571                 // default test
572                 result = testSubject.disassociateAndDeleteLast(vertex, Direction.OUT, EdgeLabelEnum.ADDITIONAL_INFORMATION);
573         }
574
575         @Test
576         public void testMoveEdge() throws Exception {
577
578                 GraphVertex vertexA = new GraphVertex();
579                 GraphVertex vertexB = new GraphVertex();
580                 TitanOperationStatus result;
581
582                 // default test
583
584                 result = testSubject.moveEdge(vertexA, vertexB, EdgeLabelEnum.ADDITIONAL_INFORMATION, Direction.BOTH);
585         }
586 }