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.Session;
24 import com.datastax.driver.mapping.MappingManager;
25 import fj.data.Either;
26 import org.apache.commons.lang3.tuple.ImmutablePair;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.mockito.InjectMocks;
30 import org.mockito.Mock;
31 import org.mockito.Mockito;
32 import org.mockito.MockitoAnnotations;
33 import org.openecomp.sdc.be.resources.data.SdcSchemaFilesData;
35 import java.util.List;
37 import static org.junit.Assert.assertTrue;
40 public class SdcSchemaFilesCassandraDaoTest {
43 SdcSchemaFilesCassandraDao testSubject;
46 CassandraClient clientMock;
49 public void setUp() throws Exception {
50 MockitoAnnotations.openMocks(this);
54 public void testInit() throws Exception {
59 Mockito.when(clientMock.isConnected()).thenReturn(true);
60 Session sessMock = Mockito.mock(Session.class);
61 MappingManager mappMock = Mockito.mock(MappingManager.class);
62 ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
63 Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
64 Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
69 public void testInitException() throws Exception {
74 Mockito.when(clientMock.isConnected()).thenReturn(true);
75 Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either
76 .right(CassandraOperationStatus.CLUSTER_NOT_CONNECTED);
77 Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
80 } catch (Exception e) {
81 assertTrue(e.getClass() == RuntimeException.class);
86 public void testSaveSchemaFile() throws Exception {
87 SdcSchemaFilesData schemaFileData = null;
88 CassandraOperationStatus result;
91 result = testSubject.saveSchemaFile(schemaFileData);
95 public void testGetSchemaFile() throws Exception {
96 String schemaFileId = null;
97 Either<SdcSchemaFilesData, CassandraOperationStatus> result;
100 result = testSubject.getSchemaFile(schemaFileId);
104 public void testDeleteSchemaFile() throws Exception {
105 String schemaFileId = null;
106 CassandraOperationStatus result;
109 result = testSubject.deleteSchemaFile(schemaFileId);
113 public void testGetSpecificSchemaFiles() throws Exception {
114 String sdcreleasenum = "";
115 String conformancelevel = "";
116 Either<List<SdcSchemaFilesData>, CassandraOperationStatus> result;
119 result = testSubject.getSpecificSchemaFiles(sdcreleasenum, conformancelevel);
123 public void testDeleteAll() throws Exception {
124 CassandraOperationStatus result;
127 result = testSubject.deleteAllArtifacts();
129 Mockito.when(clientMock.isConnected()).thenReturn(true);
130 Session sessMock = Mockito.mock(Session.class);
131 MappingManager mappMock = Mockito.mock(MappingManager.class);
132 ImmutablePair<Session, MappingManager> ipMock = ImmutablePair.of(sessMock, mappMock);
133 Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> value = Either.left(ipMock);
134 Mockito.when(clientMock.connect(Mockito.any())).thenReturn(value);
137 result = testSubject.deleteAllArtifacts();
141 public void testIsTableEmpty() throws Exception {
142 String tableName = "";
143 Either<Boolean, CassandraOperationStatus> result;
146 result = testSubject.isTableEmpty(tableName);