re base code
[sdc.git] / catalog-dao / src / test / java / org / openecomp / sdc / be / dao / cassandra / ArtifactCassandraDaoTest.java
1 package org.openecomp.sdc.be.dao.cassandra;
2
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;
7 import fj.data.Either;
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;
16
17 public class ArtifactCassandraDaoTest {
18
19         @InjectMocks
20         ArtifactCassandraDao testSubject;
21         
22         @Mock
23         CassandraClient client;
24         
25         @Mock
26         ArtifactAccessor artifactAccessor;
27         
28         @Before
29         public void setUp() throws Exception {
30                 MockitoAnnotations.initMocks(this);
31         }
32
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);
38                 testSubject.init();
39         }
40         
41         @Test
42         public void testInitError() throws Exception {
43                 testSubject.init();
44         }
45
46         @Test
47         public void testSaveArtifact() throws Exception {
48                 ESArtifactData artifact = null;
49                 CassandraOperationStatus result;
50
51                 // default test
52                 result = testSubject.saveArtifact(artifact);
53         }
54
55         @Test
56         public void testGetArtifact() throws Exception {
57                 String artifactId = "";
58                 Either<ESArtifactData, CassandraOperationStatus> result;
59
60                 // default test
61                 result = testSubject.getArtifact(artifactId);
62         }
63
64         @Test
65         public void testDeleteArtifact() throws Exception {
66                 String artifactId = "";
67                 CassandraOperationStatus result;
68
69                 // default test
70                 result = testSubject.deleteArtifact(artifactId);
71         }
72
73         @Test
74         public void testDeleteAllArtifacts() throws Exception {
75                 CassandraOperationStatus result;
76
77                 // default test
78                 result = testSubject.deleteAllArtifacts();
79         }
80
81         @Test
82         public void testIsTableEmpty() throws Exception {
83                 String tableName = "";
84                 Either<Boolean, CassandraOperationStatus> result;
85
86                 // default test
87                 result = testSubject.isTableEmpty(tableName);
88         }
89
90         @Test
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);
99                 
100                 // default test
101                 result = testSubject.getCountOfArtifactById(uniqeId);
102         }
103         
104         @Test
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);
110                 
111                 // default test
112                 result = testSubject.getCountOfArtifactById(uniqeId);
113         }
114 }