re base code
[sdc.git] / catalog-dao / src / test / java / org / openecomp / sdc / be / dao / cassandra / SdcSchemaFilesCassandraDaoTest.java
1 package org.openecomp.sdc.be.dao.cassandra;
2
3 import com.datastax.driver.core.Session;
4 import com.datastax.driver.mapping.MappingManager;
5 import fj.data.Either;
6 import org.apache.commons.lang3.tuple.ImmutablePair;
7 import org.junit.Before;
8 import org.junit.Test;
9 import org.mockito.InjectMocks;
10 import org.mockito.Mock;
11 import org.mockito.Mockito;
12 import org.mockito.MockitoAnnotations;
13 import org.openecomp.sdc.be.resources.data.SdcSchemaFilesData;
14
15 import java.util.List;
16
17 import static org.junit.Assert.assertTrue;
18
19
20 public class SdcSchemaFilesCassandraDaoTest {
21
22         @InjectMocks
23         SdcSchemaFilesCassandraDao testSubject;
24
25         @Mock
26         CassandraClient clientMock;
27
28         @Before
29         public void setUp() throws Exception {
30                 MockitoAnnotations.initMocks(this);
31         }
32
33         @Test
34         public void testInit() throws Exception {
35
36                 // default test
37                 testSubject.init();
38
39                 Mockito.when(clientMock.isConnected()).thenReturn(true);
40                 Session sessMock = Mockito.mock(Session.class);
41                 MappingManager mappMock = Mockito.mock(MappingManager.class);
42                 ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
43                 Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
44                 Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
45                 testSubject.init();
46         }
47
48         @Test
49         public void testInitException() throws Exception {
50
51                 // default test
52                 testSubject.init();
53
54                 Mockito.when(clientMock.isConnected()).thenReturn(true);
55                 Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either
56                                 .right(CassandraOperationStatus.CLUSTER_NOT_CONNECTED);
57                 Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
58                 try {
59                         testSubject.init();
60                 } catch (Exception e) {
61                         assertTrue(e.getClass() == RuntimeException.class);
62                 }
63         }
64
65         @Test
66         public void testSaveSchemaFile() throws Exception {
67                 SdcSchemaFilesData schemaFileData = null;
68                 CassandraOperationStatus result;
69
70                 // default test
71                 result = testSubject.saveSchemaFile(schemaFileData);
72         }
73         
74         @Test
75         public void testGetSchemaFile() throws Exception {
76                 String schemaFileId = null;
77                 Either<SdcSchemaFilesData, CassandraOperationStatus> result;
78
79                 // default test
80                 result = testSubject.getSchemaFile(schemaFileId);
81         }
82         
83         @Test
84         public void testDeleteSchemaFile() throws Exception {
85                 String schemaFileId = null;
86                 CassandraOperationStatus result;
87
88                 // default test
89                 result = testSubject.deleteSchemaFile(schemaFileId);
90         }
91         
92         @Test
93         public void testGetSpecificSchemaFiles() throws Exception {
94                 String sdcreleasenum = "";
95                 String conformancelevel = "";
96                 Either<List<SdcSchemaFilesData>, CassandraOperationStatus> result;
97
98                 // default test
99                 result = testSubject.getSpecificSchemaFiles(sdcreleasenum, conformancelevel);
100         }
101
102         @Test
103         public void testDeleteAll() throws Exception {
104                 CassandraOperationStatus result;
105
106                 // default test
107                 result = testSubject.deleteAllArtifacts();
108                 
109                 Mockito.when(clientMock.isConnected()).thenReturn(true);
110                 Session sessMock = Mockito.mock(Session.class);
111                 MappingManager mappMock = Mockito.mock(MappingManager.class);
112                 ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
113                 Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
114                 Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
115                 testSubject.init();
116                 
117                 result = testSubject.deleteAllArtifacts();
118         }
119         
120         @Test
121         public void testIsTableEmpty() throws Exception {
122                 String tableName = "";
123                 Either<Boolean, CassandraOperationStatus> result;
124
125                 // default test
126                 result = testSubject.isTableEmpty(tableName);
127         }
128 }