summaryrefslogtreecommitdiffstats
path: root/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDaoTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDaoTest.java')
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDaoTest.java99
1 files changed, 88 insertions, 11 deletions
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDaoTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDaoTest.java
index 96e8a7e70b..402cfc56d8 100644
--- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDaoTest.java
+++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDaoTest.java
@@ -1,53 +1,130 @@
package org.openecomp.sdc.be.dao.cassandra;
+import static org.junit.Assert.assertTrue;
+
import java.util.List;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.junit.Before;
import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.resources.data.SdcSchemaFilesData;
+import com.datastax.driver.core.Session;
+import com.datastax.driver.mapping.MappingManager;
+
import fj.data.Either;
public class SdcSchemaFilesCassandraDaoTest {
- private SdcSchemaFilesCassandraDao createTestSubject() {
- return new SdcSchemaFilesCassandraDao();
+ @InjectMocks
+ SdcSchemaFilesCassandraDao testSubject;
+
+ @Mock
+ CassandraClient clientMock;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testInit() throws Exception {
+
+ // default test
+ testSubject.init();
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Session sessMock = Mockito.mock(Session.class);
+ MappingManager mappMock = Mockito.mock(MappingManager.class);
+ ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ testSubject.init();
+ }
+
+ @Test
+ public void testInitException() throws Exception {
+
+ // default test
+ testSubject.init();
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either
+ .right(CassandraOperationStatus.CLUSTER_NOT_CONNECTED);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ try {
+ testSubject.init();
+ } catch (Exception e) {
+ assertTrue(e.getClass() == RuntimeException.class);
+ }
+ }
+
+ @Test
+ public void testSaveSchemaFile() throws Exception {
+ SdcSchemaFilesData schemaFileData = null;
+ CassandraOperationStatus result;
+
+ // default test
+ result = testSubject.saveSchemaFile(schemaFileData);
}
+
+ @Test
+ public void testGetSchemaFile() throws Exception {
+ String schemaFileId = null;
+ Either<SdcSchemaFilesData, CassandraOperationStatus> result;
+ // default test
+ result = testSubject.getSchemaFile(schemaFileId);
+ }
+
+ @Test
+ public void testDeleteSchemaFile() throws Exception {
+ String schemaFileId = null;
+ CassandraOperationStatus result;
+ // default test
+ result = testSubject.deleteSchemaFile(schemaFileId);
+ }
@Test
public void testGetSpecificSchemaFiles() throws Exception {
- SdcSchemaFilesCassandraDao testSubject;
String sdcreleasenum = "";
String conformancelevel = "";
Either<List<SdcSchemaFilesData>, CassandraOperationStatus> result;
// default test
- testSubject = createTestSubject();
result = testSubject.getSpecificSchemaFiles(sdcreleasenum, conformancelevel);
}
-
@Test
- public void testDeleteAllArtifacts() throws Exception {
- SdcSchemaFilesCassandraDao testSubject;
+ public void testDeleteAll() throws Exception {
CassandraOperationStatus result;
// default test
- testSubject = createTestSubject();
+ result = testSubject.deleteAllArtifacts();
+
+ Mockito.when(clientMock.isConnected()).thenReturn(true);
+ Session sessMock = Mockito.mock(Session.class);
+ MappingManager mappMock = Mockito.mock(MappingManager.class);
+ ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
+ Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
+ testSubject.init();
+
result = testSubject.deleteAllArtifacts();
}
-
@Test
public void testIsTableEmpty() throws Exception {
- SdcSchemaFilesCassandraDao testSubject;
String tableName = "";
Either<Boolean, CassandraOperationStatus> result;
// default test
- testSubject = createTestSubject();
result = testSubject.isTableEmpty(tableName);
}
} \ No newline at end of file