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.dao.cass.UserRoleDAO;
40 import org.onap.aaf.auth.env.AuthzTrans;
41 import org.onap.aaf.misc.env.Env;
42 import org.onap.aaf.misc.env.LogTarget;
43 import org.onap.aaf.misc.env.TimeTaken;
44 import org.onap.aaf.misc.env.Trans;
46 import com.datastax.driver.core.ResultSet;
47 import com.datastax.driver.core.Row;
48 import com.datastax.driver.core.Session;
49 import com.datastax.driver.core.SimpleStatement;
51 import junit.framework.Assert;
53 public class JU_UserRole {
63 userRole = new UserRole("user", "ns", "rname", date);
64 userRole = new UserRole("user", "role", "ns", "rname", date);
68 public void testTotalLoaded() {
69 Assert.assertEquals(0, userRole.totalLoaded());
73 public void testDeleted() {
74 Assert.assertEquals(0, userRole.deleted());
78 public void testExpunge() {
83 public void testSetDeleteStream() {
84 userRole.setDeleteStream(ds);
88 public void testSetRecoverStream() {
89 userRole.setRecoverStream(ds);
93 public void testUrdd() {
94 Assert.assertTrue(userRole.urdd() instanceof UserRoleDAO.Data);
98 public void testUser() {
99 Assert.assertEquals("user", userRole.user());
103 public void testRole() {
104 Assert.assertEquals("role", userRole.role());
108 public void testNs() {
109 Assert.assertEquals("ns", userRole.ns());
113 public void testRName() {
114 Assert.assertEquals("rname", userRole.rname());
118 public void testExpires() {
119 Assert.assertEquals(date, userRole.expires());
120 userRole.expires(date);
124 public void testToString() {
125 Assert.assertTrue(userRole.toString() instanceof String);
129 public void testGet() {
130 userRole.get("u", "r");
134 public void testResetLocalData() {
135 userRole.resetLocalData();
139 public void testSizeForDeletion() {
140 Assert.assertEquals(0, userRole.sizeForDeletion());
144 public void testPendingDelete() {
145 Assert.assertFalse(userRole.pendingDelete(userRole));
149 public void testActuateDeletionNow() {
150 AuthzTrans trans = mock(AuthzTrans.class);
151 URDelete urd = mock(URDelete.class);
152 userRole.actuateDeletionNow(trans, urd);
157 public void testLoad() {
158 Creator<UserRole> creator = mock(Creator.class);
159 Trans trans = mock(Trans.class);
160 Session session = mock(Session.class);
161 LogTarget target = mock(LogTarget.class);
162 TimeTaken tt = mock(TimeTaken.class);
163 ResultSet results = mock(ResultSet.class);
165 List<Row> rows = new ArrayList<Row>();
167 when(trans.info()).thenReturn(target);
168 when(trans.start("Read UserRoles", Env.REMOTE)).thenReturn(tt);
169 when(trans.start("Load UserRole", Env.SUB)).thenReturn(tt);
170 when(session.execute(any(SimpleStatement.class))).thenReturn(results);
171 when(results.iterator()).thenReturn(rows.iterator());