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.mockito.Matchers.any;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.when;
28 import java.io.PrintStream;
29 import java.util.ArrayList;
30 import java.util.Date;
31 import java.util.List;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.aaf.auth.batch.helpers.Creator;
36 import org.onap.aaf.auth.batch.helpers.UserRole;
37 import org.onap.aaf.auth.dao.cass.UserRoleDAO;
38 import org.onap.aaf.misc.env.Env;
39 import org.onap.aaf.misc.env.LogTarget;
40 import org.onap.aaf.misc.env.TimeTaken;
41 import org.onap.aaf.misc.env.Trans;
43 import com.datastax.driver.core.ResultSet;
44 import com.datastax.driver.core.Row;
45 import com.datastax.driver.core.Session;
46 import com.datastax.driver.core.SimpleStatement;
48 import junit.framework.Assert;
50 public class JU_UserRole {
60 userRole = new UserRole("user", "ns", "rname", date);
61 userRole = new UserRole("user", "role", "ns", "rname", date);
65 public void testTotalLoaded() {
66 Assert.assertEquals(0, userRole.totalLoaded());
70 public void testDeleted() {
71 Assert.assertEquals(0, userRole.deleted());
75 public void testExpunge() {
80 public void testSetDeleteStream() {
81 userRole.setDeleteStream(ds);
85 public void testSetRecoverStream() {
86 userRole.setRecoverStream(ds);
90 public void testUrdd() {
91 Assert.assertTrue(userRole.urdd() instanceof UserRoleDAO.Data);
95 public void testUser() {
96 Assert.assertEquals("user", userRole.user());
100 public void testRole() {
101 Assert.assertEquals("role", userRole.role());
105 public void testNs() {
106 Assert.assertEquals("ns", userRole.ns());
110 public void testRName() {
111 Assert.assertEquals("rname", userRole.rname());
115 public void testExpires() {
116 Assert.assertEquals(date, userRole.expires());
117 userRole.expires(date);
121 public void testToString() {
122 Assert.assertTrue(userRole.toString() instanceof String);
126 public void testGet() {
127 userRole.get("u", "r");
131 public void testResetLocalData() {
132 userRole.resetLocalData();
136 public void testLoad() {
137 Creator<UserRole> creator = mock(Creator.class);
138 Trans trans = mock(Trans.class);
139 Session session = mock(Session.class);
140 LogTarget target = mock(LogTarget.class);
141 TimeTaken tt = mock(TimeTaken.class);
142 ResultSet results = mock(ResultSet.class);
144 List<Row> rows = new ArrayList<Row>();
146 when(trans.info()).thenReturn(target);
147 when(trans.start("Read UserRoles", Env.REMOTE)).thenReturn(tt);
148 when(trans.start("Load UserRole", Env.SUB)).thenReturn(tt);
149 when(session.execute(any(SimpleStatement.class))).thenReturn(results);
150 when(results.iterator()).thenReturn(rows.iterator());