1 package org.openecomp.sdc.be.dao.cassandra;
3 import com.datastax.driver.core.Session;
4 import com.datastax.driver.mapping.MappingManager;
6 import org.apache.commons.lang3.tuple.ImmutablePair;
7 import org.junit.Before;
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;
15 import java.util.List;
17 import static org.junit.Assert.assertTrue;
20 public class SdcSchemaFilesCassandraDaoTest {
23 SdcSchemaFilesCassandraDao testSubject;
26 CassandraClient clientMock;
29 public void setUp() throws Exception {
30 MockitoAnnotations.initMocks(this);
34 public void testInit() throws Exception {
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);
49 public void testInitException() throws Exception {
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);
60 } catch (Exception e) {
61 assertTrue(e.getClass() == RuntimeException.class);
66 public void testSaveSchemaFile() throws Exception {
67 SdcSchemaFilesData schemaFileData = null;
68 CassandraOperationStatus result;
71 result = testSubject.saveSchemaFile(schemaFileData);
75 public void testGetSchemaFile() throws Exception {
76 String schemaFileId = null;
77 Either<SdcSchemaFilesData, CassandraOperationStatus> result;
80 result = testSubject.getSchemaFile(schemaFileId);
84 public void testDeleteSchemaFile() throws Exception {
85 String schemaFileId = null;
86 CassandraOperationStatus result;
89 result = testSubject.deleteSchemaFile(schemaFileId);
93 public void testGetSpecificSchemaFiles() throws Exception {
94 String sdcreleasenum = "";
95 String conformancelevel = "";
96 Either<List<SdcSchemaFilesData>, CassandraOperationStatus> result;
99 result = testSubject.getSpecificSchemaFiles(sdcreleasenum, conformancelevel);
103 public void testDeleteAll() throws Exception {
104 CassandraOperationStatus result;
107 result = testSubject.deleteAllArtifacts();
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);
117 result = testSubject.deleteAllArtifacts();
121 public void testIsTableEmpty() throws Exception {
122 String tableName = "";
123 Either<Boolean, CassandraOperationStatus> result;
126 result = testSubject.isTableEmpty(tableName);