Collection syntax change because of Sonar
[aaf/authz.git] / auth / auth-cmd / src / test / java / org / onap / aaf / auth / cmd / test / role / JU_List.java
1 /*
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
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
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============================================
18  */
19 package org.onap.aaf.auth.cmd.test.role;
20
21 import static org.junit.Assert.*;
22
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;
47
48 import aaf.v2_0.Perms;
49 import aaf.v2_0.Pkey;
50 import aaf.v2_0.Roles;
51 import aaf.v2_0.UserRoles;
52
53 import static org.mockito.Mockito.*;
54
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;
60 import java.net.URI;
61 import java.security.GeneralSecurityException;
62 import java.security.Principal;
63 import java.util.ArrayList;
64
65 import org.junit.Test;
66
67 public class JU_List {
68         
69         AAFcli cli;
70         Role role;
71         List list;
72         PropAccess prop;
73         AuthzEnv aEnv;
74         Writer wtr;
75         Locator<URI> loc;
76         HMangr hman;    
77         AAFcli aafcli;
78
79         private class ListRolesStub extends List {
80
81                 public ListRolesStub(Role parent) {
82                         super(parent);
83                         // TODO Auto-generated constructor stub
84                 }
85         }
86         
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<>();
91                         }
92                         this.role.add(role);
93                 }
94         }
95         
96         private class RoleStub extends aaf.v2_0.Role {
97                 
98                 public void addPerms(Pkey perms) {
99                 if (this.perms == null) {
100                     this.perms = new ArrayList<>();
101                 }
102                 this.perms.add(perms); 
103             }
104         }
105         
106         @Before
107         public void setUp() throws APIException, LocatorException, GeneralSecurityException, IOException, CadiException{
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);
117         }
118         
119         @Test
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);
125                 
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");
134                 
135         }
136         
137         @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();
145                 roles.addRole(role);
146                 Pkey pkey = new Pkey();
147                 pkey.setInstance("test");
148                 pkey.setAction("test");
149                 pkey.setInstance("test");
150                 pkey.setType("test");
151                 role.addPerms(pkey);
152                 list.report(roles, perms , null , "test");
153                 list.report(roles, perms , urs , "test");
154                 
155                 aafcli.eval("DETAILS @[ 123");
156                 role.setName("test");
157
158                 list.report(roles, perms , urs , "test");
159         }
160
161 }