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============================================
20 package org.onap.aaf.auth.cmd.test.role;
22 import static org.junit.Assert.*;
24 import org.junit.After;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.Mock;
28 import org.mockito.Mockito;
29 import org.onap.aaf.auth.cmd.AAFcli;
30 import org.onap.aaf.auth.cmd.role.List;
31 import org.onap.aaf.auth.cmd.role.Role;
32 import org.onap.aaf.auth.cmd.test.JU_AAFCli;
33 import org.onap.aaf.auth.cmd.Cmd;
34 import org.onap.aaf.auth.cmd.Param;
35 import org.onap.aaf.auth.env.AuthzEnv;
36 import org.onap.aaf.auth.env.AuthzTrans;
37 import org.onap.aaf.cadi.Access;
38 import org.onap.aaf.cadi.CadiException;
39 import org.onap.aaf.cadi.Locator;
40 import org.onap.aaf.cadi.LocatorException;
41 import org.onap.aaf.cadi.PropAccess;
42 import org.onap.aaf.cadi.SecuritySetter;
43 import org.onap.aaf.cadi.client.Future;
44 import org.onap.aaf.cadi.client.Rcli;
45 import org.onap.aaf.cadi.config.SecurityInfoC;
46 import org.onap.aaf.cadi.http.HMangr;
47 import org.onap.aaf.misc.env.APIException;
49 import aaf.v2_0.Perms;
51 import aaf.v2_0.Roles;
52 import aaf.v2_0.UserRoles;
54 import static org.mockito.Mockito.*;
56 import java.io.IOException;
57 import java.io.Writer;
58 import java.lang.reflect.InvocationTargetException;
59 import java.lang.reflect.Method;
60 import java.net.HttpURLConnection;
62 import java.security.GeneralSecurityException;
63 import java.security.Principal;
64 import java.util.ArrayList;
66 import org.junit.Test;
68 public class JU_List {
80 private class ListRolesStub extends List {
82 public ListRolesStub(Role parent) {
84 // TODO Auto-generated constructor stub
88 private class RolesStub extends Roles {
89 public void addRole(aaf.v2_0.Role role) {
90 if (this.role == null) {
91 this.role = new ArrayList<>();
97 private class RoleStub extends aaf.v2_0.Role {
99 public void addPerms(Pkey perms) {
100 if (this.perms == null) {
101 this.perms = new ArrayList<>();
103 this.perms.add(perms);
108 public void setUp() throws APIException, LocatorException, GeneralSecurityException, IOException, CadiException{
109 prop = new PropAccess();
110 aEnv = new AuthzEnv();
111 wtr = mock(Writer.class);
112 loc = mock(Locator.class);
113 SecuritySetter<HttpURLConnection> secSet = mock(SecuritySetter.class);
114 hman = new HMangr(aEnv, loc);
115 aafcli = new AAFcli(prop, aEnv, wtr, hman, null, secSet);
116 role = new Role(aafcli);
117 list = new List(role);
121 public void testRoles() throws APIException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
122 Role role = new Role(aafcli);
123 ListRolesStub listStub = new ListRolesStub(role);
124 Future future = mock(Future.class);
125 Rcli rcli = mock(Rcli.class);
127 Class c = listStub.getClass();
128 Class[] cArg = new Class[3];
129 cArg[0] = Future.class;
130 cArg[1] = Rcli.class;
131 cArg[2] = String.class;//Steps to test a protected method
132 //Method listMethod = c.getDeclaredMethod("list", cArg);
133 //listMethod.setAccessible(true);
134 //listMethod.invoke(listStub, future, rcli, "test");
139 public void testReport() throws Exception {
140 UserRoles urs = new UserRoles();
141 Perms perms = new Perms();
142 RolesStub roles = new RolesStub();
143 list.report(roles, perms , urs , "test");
144 AAFcli cli = JU_AAFCli.getAAfCli();
145 RoleStub role = new RoleStub();
147 Pkey pkey = new Pkey();
148 pkey.setInstance("test");
149 pkey.setAction("test");
150 pkey.setInstance("test");
151 pkey.setType("test");
153 list.report(roles, perms , null , "test");
154 list.report(roles, perms , urs , "test");
156 aafcli.eval("DETAILS @[ 123");
157 role.setName("test");
159 list.report(roles, perms , urs , "test");