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