1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.dao;
\r
25 import static org.junit.Assert.*;
\r
27 import org.junit.Before;
\r
28 import org.junit.Test;
\r
29 import org.junit.runner.RunWith;
\r
30 import org.mockito.Mock;
\r
31 import org.onap.aaf.authz.env.AuthzTrans;
\r
32 import org.onap.aaf.dao.CassDAOImpl;
\r
33 import org.onap.aaf.dao.Loader;
\r
34 import org.powermock.api.mockito.PowerMockito;
\r
35 import org.powermock.modules.junit4.PowerMockRunner;
\r
37 import org.onap.aaf.inno.env.Data;
\r
38 import org.onap.aaf.inno.env.Trans;
\r
39 import org.onap.aaf.inno.env.TransStore;
\r
40 import com.datastax.driver.core.Cluster;
\r
41 import com.datastax.driver.core.ConsistencyLevel;
\r
43 @RunWith(PowerMockRunner.class)
\r
44 public class JU_CassDAOImpl {
\r
46 public static final String CASS_READ_CONSISTENCY="cassandra.readConsistency";
\r
47 public static final String CASS_WRITE_CONSISTENCY="cassandra.writeConsistency";
\r
49 CassDAOImpl cassDAOImpl;
\r
53 TransStore transStoreMock;
\r
54 @SuppressWarnings("rawtypes")
\r
56 @SuppressWarnings("rawtypes")
\r
58 Cluster clusterMock;
\r
59 Class<Data> classDataMock;
\r
60 ConsistencyLevel consistencyLevelMock;
\r
64 AuthzTrans authzTransMock;
\r
68 @SuppressWarnings({ "rawtypes", "unchecked" })
\r
72 String name = "name";
\r
73 String keySpace = "keySpace";
\r
74 String table = "table";
\r
75 cassDAOImpl = new CassDAOImpl(transStoreMock, name, clusterMock, keySpace, classDataMock, table, consistencyLevelMock, consistencyLevelMock);
\r
80 public void testReadConsistency() {
\r
81 String table = "users";
\r
82 PowerMockito.when(authzTransMock.getProperty(CASS_READ_CONSISTENCY+'.'+table)).thenReturn("TWO");
\r
83 ConsistencyLevel consistencyLevel = cassDAOImpl.readConsistency(authzTransMock, table);
\r
84 System.out.println("Consistency level" + consistencyLevel.name());
\r
85 assertEquals("TWO", consistencyLevel.name());
\r
89 public void testWriteConsistency() {
\r
90 String table = "users";
\r
91 PowerMockito.when(authzTransMock.getProperty(CASS_WRITE_CONSISTENCY+'.'+table)).thenReturn(null);
\r
92 ConsistencyLevel consistencyLevel = cassDAOImpl.writeConsistency(authzTransMock, table);
\r
93 System.out.println("Consistency level" + consistencyLevel.name());
\r
94 assertEquals("ONE", consistencyLevel.name());
\r