2 * ============LICENSE_START==========================================
3 * ===================================================================
4 * Copyright © 2018 AT&T Intellectual Property. All rights reserved.
5 * ===================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END============================================
19 package org.onap.aaf.auth.cmd.test.role;
21 import static org.junit.Assert.*;
23 import org.junit.After;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.mockito.Mock;
27 import org.mockito.Mockito;
28 import org.onap.aaf.auth.cmd.AAFcli;
29 import org.onap.aaf.auth.cmd.role.List;
30 import org.onap.aaf.auth.cmd.role.Role;
31 import org.onap.aaf.auth.cmd.test.JU_AAFCli;
32 import org.onap.aaf.auth.cmd.Cmd;
33 import org.onap.aaf.auth.cmd.Param;
34 import org.onap.aaf.auth.env.AuthzEnv;
35 import org.onap.aaf.auth.env.AuthzTrans;
36 import org.onap.aaf.cadi.Access;
37 import org.onap.aaf.cadi.CadiException;
38 import org.onap.aaf.cadi.Locator;
39 import org.onap.aaf.cadi.LocatorException;
40 import org.onap.aaf.cadi.PropAccess;
41 import org.onap.aaf.cadi.SecuritySetter;
42 import org.onap.aaf.cadi.client.Future;
43 import org.onap.aaf.cadi.client.Rcli;
44 import org.onap.aaf.cadi.config.SecurityInfoC;
45 import org.onap.aaf.cadi.http.HMangr;
46 import org.onap.aaf.misc.env.APIException;
48 import aaf.v2_0.Perms;
50 import aaf.v2_0.Roles;
51 import aaf.v2_0.UserRoles;
53 import static org.mockito.Mockito.*;
55 import java.io.IOException;
56 import java.io.Writer;
57 import java.lang.reflect.InvocationTargetException;
58 import java.lang.reflect.Method;
59 import java.net.HttpURLConnection;
61 import java.security.GeneralSecurityException;
62 import java.security.Principal;
63 import java.util.ArrayList;
65 import org.junit.Test;
67 public class JU_List {
79 private class ListRolesStub extends List {
81 public ListRolesStub(Role parent) {
83 // TODO Auto-generated constructor stub
87 private class RolesStub extends Roles {
88 public void addRole(aaf.v2_0.Role role) {
89 if (this.role == null) {
90 this.role = new ArrayList<aaf.v2_0.Role>();
96 private class RoleStub extends aaf.v2_0.Role {
98 public void addPerms(Pkey perms) {
99 if (this.perms == null) {
100 this.perms = new ArrayList<Pkey>();
102 this.perms.add(perms);
107 public void setUp() throws APIException, LocatorException, GeneralSecurityException, IOException{
108 prop = new PropAccess();
109 aEnv = new AuthzEnv();
110 wtr = mock(Writer.class);
111 loc = mock(Locator.class);
112 SecuritySetter<HttpURLConnection> secSet = mock(SecuritySetter.class);
113 hman = new HMangr(aEnv, loc);
114 aafcli = new AAFcli(prop, aEnv, wtr, hman, null, secSet);
115 role = new Role(aafcli);
116 list = new List(role);
120 public void testRoles() throws APIException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
121 Role role = new Role(aafcli);
122 ListRolesStub listStub = new ListRolesStub(role);
123 Future future = mock(Future.class);
124 Rcli rcli = mock(Rcli.class);
126 Class c = listStub.getClass();
127 Class[] cArg = new Class[3];
128 cArg[0] = Future.class;
129 cArg[1] = Rcli.class;
130 cArg[2] = String.class;//Steps to test a protected method
131 //Method listMethod = c.getDeclaredMethod("list", cArg);
132 //listMethod.setAccessible(true);
133 //listMethod.invoke(listStub, future, rcli, "test");
138 public void testReport() throws Exception {
139 UserRoles urs = new UserRoles();
140 Perms perms = new Perms();
141 RolesStub roles = new RolesStub();
142 list.report(roles, perms , urs , "test");
143 AAFcli cli = JU_AAFCli.getAAfCli();
144 RoleStub role = new RoleStub();
146 Pkey pkey = new Pkey();
147 pkey.setInstance("test");
148 pkey.setAction("test");
149 pkey.setInstance("test");
150 pkey.setType("test");
152 list.report(roles, perms , null , "test");
153 list.report(roles, perms , urs , "test");
155 aafcli.eval("DETAILS @[ 123");
156 role.setName("test");
158 list.report(roles, perms , urs , "test");