2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.dao.cassandra;
23 import com.datastax.driver.core.ResultSet;
24 import com.datastax.driver.core.Row;
25 import com.datastax.driver.core.Session;
26 import com.datastax.driver.mapping.MappingManager;
27 import fj.data.Either;
28 import org.apache.commons.lang3.tuple.ImmutablePair;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.InjectMocks;
32 import org.mockito.Mock;
33 import org.mockito.Mockito;
34 import org.mockito.MockitoAnnotations;
35 import org.openecomp.sdc.be.resources.data.DAOArtifactData;
36 import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
38 public class ArtifactCassandraDaoTest {
41 private ArtifactCassandraDao testSubject;
44 private CassandraClient client;
47 private ArtifactAccessor artifactAccessor;
50 private MappingManager mappingManager;
53 public void setUp() throws Exception {
54 MockitoAnnotations.openMocks(this);
57 @Test(expected = RuntimeException.class)
58 public void testInit() throws Exception {
59 Mockito.when(client.isConnected()).thenReturn(true);
60 Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.right(CassandraOperationStatus.CLUSTER_NOT_CONNECTED);
61 Mockito.when(client.connect(Mockito.anyString())).thenReturn(value);
66 public void testInitError() throws Exception {
71 public void testSaveArtifact() throws Exception {
72 DAOArtifactData artifact = null;
73 CassandraOperationStatus result;
76 result = testSubject.saveArtifact(artifact);
80 public void testGetArtifact() throws Exception {
81 String artifactId = "";
82 Either<DAOArtifactData, CassandraOperationStatus> result;
85 result = testSubject.getArtifact(artifactId);
89 public void testDeleteArtifact() throws Exception {
90 String artifactId = "";
91 CassandraOperationStatus result;
94 result = testSubject.deleteArtifact(artifactId);
98 public void testDeleteAllArtifacts() throws Exception {
99 CassandraOperationStatus result;
102 result = testSubject.deleteAllArtifacts();
106 public void testIsTableEmpty() throws Exception {
107 String tableName = "";
108 Either<Boolean, CassandraOperationStatus> result;
111 result = testSubject.isTableEmpty(tableName);
115 public void testGetCountOfArtifactById() throws Exception {
116 Mockito.when(client.isConnected()).thenReturn(true);
117 Mockito.when(client.connect(AuditingTypesConstants.ARTIFACT_KEYSPACE)).thenReturn(Either.left(ImmutablePair.of(null,mappingManager)));
118 Mockito.when(mappingManager.createAccessor(ArtifactAccessor.class)).thenReturn(artifactAccessor);
119 String uniqeId = "mock";
120 Either<Long, CassandraOperationStatus> result;
121 ResultSet value = Mockito.mock(ResultSet.class);
122 Row value2 = Mockito.mock(Row.class);
123 Mockito.when(value2.getLong(0)).thenReturn(0L);
124 Mockito.when(value.one()).thenReturn(value2);
125 Mockito.when(artifactAccessor.getNumOfArtifactsById(uniqeId)).thenReturn(value);
129 result = testSubject.getCountOfArtifactById(uniqeId);
133 public void testGetCountOfArtifactById1() throws Exception {
134 Mockito.when(client.isConnected()).thenReturn(true);
135 Mockito.when(client.connect(AuditingTypesConstants.ARTIFACT_KEYSPACE)).thenReturn(Either.left(ImmutablePair.of(null,mappingManager)));
136 Mockito.when(mappingManager.createAccessor(ArtifactAccessor.class)).thenReturn(artifactAccessor);
137 String uniqeId = "mock";
138 Either<Long, CassandraOperationStatus> result;
139 ResultSet value = Mockito.mock(ResultSet.class);
140 Mockito.when(artifactAccessor.getNumOfArtifactsById(uniqeId)).thenReturn(null);
143 result = testSubject.getCountOfArtifactById(uniqeId);