Merge "Resolved problem Jacoco analysing 0 classes"
[aaf/authz.git] / auth / auth-cmd / src / test / java / org / onap / aaf / auth / cmd / test / role / JU_List.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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====================================================
18  *
19  */
20
21 package org.onap.aaf.auth.cmd.test.role;
22
23 import static org.junit.Assert.*;
24
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;
49
50 import aaf.v2_0.Perms;
51 import aaf.v2_0.Pkey;
52 import aaf.v2_0.Roles;
53 import aaf.v2_0.UserRoles;
54
55 import static org.mockito.Mockito.*;
56
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;
62 import java.net.URI;
63 import java.security.GeneralSecurityException;
64 import java.security.Principal;
65 import java.util.ArrayList;
66
67 import org.junit.Test;
68
69 public class JU_List {
70         
71         AAFcli cli;
72         Role role;
73         List list;
74         PropAccess prop;
75         AuthzEnv aEnv;
76         Writer wtr;
77         Locator<URI> loc;
78         HMangr hman;    
79         AAFcli aafcli;
80
81         private class ListRolesStub extends List {
82
83                 public ListRolesStub(Role parent) {
84                         super(parent);
85                         // TODO Auto-generated constructor stub
86                 }
87         }
88         
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>();
93                         }
94                         this.role.add(role);
95                 }
96         }
97         
98         private class RoleStub extends aaf.v2_0.Role {
99                 
100                 public void addPerms(Pkey perms) {
101                 if (this.perms == null) {
102                     this.perms = new ArrayList<Pkey>();
103                 }
104                 this.perms.add(perms); 
105             }
106         }
107         
108         @Before
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);
119         }
120         
121         @Test
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);
127                 
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");
136                 
137         }
138         
139         @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();
147                 roles.addRole(role);
148                 Pkey pkey = new Pkey();
149                 pkey.setInstance("test");
150                 pkey.setAction("test");
151                 pkey.setInstance("test");
152                 pkey.setType("test");
153                 
154                 list.report(roles, perms , urs , "test");
155                 list.report(roles, perms , null , "test");
156                 cli.eval("DETAILS @[ 123");
157                 role.setName("test");
158                 role.addPerms(pkey);
159                 list.report(roles, perms , urs , "test");
160         }
161
162 }