1 package org.openecomp.sdc.be.dao.cassandra;
3 import com.datastax.driver.core.ResultSet;
4 import com.datastax.driver.core.Row;
5 import com.datastax.driver.core.Session;
6 import com.datastax.driver.mapping.MappingManager;
8 import org.apache.commons.lang3.tuple.ImmutablePair;
9 import org.junit.Before;
10 import org.junit.Test;
11 import org.mockito.InjectMocks;
12 import org.mockito.Mock;
13 import org.mockito.Mockito;
14 import org.mockito.MockitoAnnotations;
15 import org.openecomp.sdc.be.resources.data.ESArtifactData;
17 public class ArtifactCassandraDaoTest {
20 ArtifactCassandraDao testSubject;
23 CassandraClient client;
26 ArtifactAccessor artifactAccessor;
29 public void setUp() throws Exception {
30 MockitoAnnotations.initMocks(this);
33 @Test(expected = RuntimeException.class)
34 public void testInit() throws Exception {
35 Mockito.when(client.isConnected()).thenReturn(true);
36 Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.right(CassandraOperationStatus.CLUSTER_NOT_CONNECTED);
37 Mockito.when(client.connect(Mockito.anyString())).thenReturn(value);
42 public void testInitError() throws Exception {
47 public void testSaveArtifact() throws Exception {
48 ESArtifactData artifact = null;
49 CassandraOperationStatus result;
52 result = testSubject.saveArtifact(artifact);
56 public void testGetArtifact() throws Exception {
57 String artifactId = "";
58 Either<ESArtifactData, CassandraOperationStatus> result;
61 result = testSubject.getArtifact(artifactId);
65 public void testDeleteArtifact() throws Exception {
66 String artifactId = "";
67 CassandraOperationStatus result;
70 result = testSubject.deleteArtifact(artifactId);
74 public void testDeleteAllArtifacts() throws Exception {
75 CassandraOperationStatus result;
78 result = testSubject.deleteAllArtifacts();
82 public void testIsTableEmpty() throws Exception {
83 String tableName = "";
84 Either<Boolean, CassandraOperationStatus> result;
87 result = testSubject.isTableEmpty(tableName);
91 public void testGetCountOfArtifactById() throws Exception {
92 String uniqeId = "mock";
93 Either<Long, CassandraOperationStatus> result;
94 ResultSet value = Mockito.mock(ResultSet.class);
95 Row value2 = Mockito.mock(Row.class);
96 Mockito.when(value2.getLong(0)).thenReturn(0L);
97 Mockito.when(value.one()).thenReturn(value2);
98 Mockito.when(artifactAccessor.getNumOfArtifactsById(uniqeId)).thenReturn(value);
101 result = testSubject.getCountOfArtifactById(uniqeId);
105 public void testGetCountOfArtifactById1() throws Exception {
106 String uniqeId = "mock";
107 Either<Long, CassandraOperationStatus> result;
108 ResultSet value = Mockito.mock(ResultSet.class);
109 Mockito.when(artifactAccessor.getNumOfArtifactsById(uniqeId)).thenReturn(null);
112 result = testSubject.getCountOfArtifactById(uniqeId);