2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 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====================================================
22 package org.onap.aaf.auth.batch.helpers.test;
24 import static org.junit.Assert.assertEquals;
25 import static org.mockito.Matchers.any;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
29 import java.io.PrintStream;
30 import java.util.ArrayList;
31 import java.util.Date;
32 import java.util.List;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.onap.aaf.auth.batch.actions.URDelete;
37 import org.onap.aaf.auth.batch.helpers.Creator;
38 import org.onap.aaf.auth.batch.helpers.UserRole;
39 import org.onap.aaf.auth.batch.helpers.creators.RowCreator;
40 import org.onap.aaf.auth.dao.cass.UserRoleDAO;
41 import org.onap.aaf.auth.env.AuthzTrans;
42 import org.onap.aaf.misc.env.Env;
43 import org.onap.aaf.misc.env.LogTarget;
44 import org.onap.aaf.misc.env.TimeTaken;
45 import org.onap.aaf.misc.env.Trans;
47 import com.datastax.driver.core.ResultSet;
48 import com.datastax.driver.core.Row;
49 import com.datastax.driver.core.Session;
50 import com.datastax.driver.core.SimpleStatement;
52 import junit.framework.Assert;
54 public class JU_UserRole {
64 userRole = new UserRole("user", "ns", "rname", date);
65 userRole = new UserRole("user", "role", "ns", "rname", date);
69 public void testTotalLoaded() {
70 Assert.assertEquals(0, userRole.totalLoaded());
74 public void testDeleted() {
75 Assert.assertEquals(0, userRole.deleted());
79 public void testExpunge() {
84 public void testSetDeleteStream() {
85 userRole.setDeleteStream(ds);
89 public void testSetRecoverStream() {
90 userRole.setRecoverStream(ds);
94 public void testUrdd() {
95 Assert.assertTrue(userRole.urdd() instanceof UserRoleDAO.Data);
99 public void testUser() {
100 Assert.assertEquals("user", userRole.user());
104 public void testRole() {
105 Assert.assertEquals("role", userRole.role());
109 public void testNs() {
110 Assert.assertEquals("ns", userRole.ns());
114 public void testRName() {
115 Assert.assertEquals("rname", userRole.rname());
119 public void testExpires() {
120 Assert.assertEquals(date, userRole.expires());
121 userRole.expires(date);
125 public void testToString() {
126 Assert.assertTrue(userRole.toString() instanceof String);
130 public void testGet() {
131 userRole.get("u", "r");
135 public void testResetLocalData() {
136 userRole.resetLocalData();
140 public void testSizeForDeletion() {
141 Assert.assertEquals(0, userRole.sizeForDeletion());
145 public void testPendingDelete() {
146 Assert.assertFalse(userRole.pendingDelete(userRole));
150 public void testActuateDeletionNow() {
151 AuthzTrans trans = mock(AuthzTrans.class);
152 URDelete urd = mock(URDelete.class);
153 userRole.actuateDeletionNow(trans, urd);
157 public void testV2() {
158 UserRole.v2_0_11.create(RowCreator.getRow());
159 assertEquals("select user,role,ns,rname,expires from authz.user_role", UserRole.v2_0_11.select());
163 public void testLoad() {
164 Creator<UserRole> creator = mock(Creator.class);
165 Trans trans = mock(Trans.class);
166 Session session = mock(Session.class);
167 LogTarget target = mock(LogTarget.class);
168 TimeTaken tt = mock(TimeTaken.class);
169 ResultSet results = mock(ResultSet.class);
171 List<Row> rows = new ArrayList<Row>();
173 when(trans.info()).thenReturn(target);
174 when(trans.start("Read UserRoles", Env.REMOTE)).thenReturn(tt);
175 when(trans.start("Load UserRole", Env.SUB)).thenReturn(tt);
176 when(session.execute(any(SimpleStatement.class))).thenReturn(results);
177 when(results.iterator()).thenReturn(rows.iterator());
179 List<Row> list = new ArrayList<Row>();
180 list.add(RowCreator.getRow());
181 list.add(RowCreator.getRow());
183 UserRole.load(trans, session, creator, new UserRole.DataLoadVisitor());