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