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