Merge "Increased auth cmd to 53 percent"
[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.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.http.HMangr;
46 import org.onap.aaf.misc.env.APIException;
47
48 import aaf.v2_0.Perms;
49 import aaf.v2_0.Roles;
50 import aaf.v2_0.UserRoles;
51
52 import static org.mockito.Mockito.*;
53
54 import java.io.IOException;
55 import java.io.Writer;
56 import java.lang.reflect.InvocationTargetException;
57 import java.lang.reflect.Method;
58 import java.net.HttpURLConnection;
59 import java.net.URI;
60 import java.security.GeneralSecurityException;
61 import java.security.Principal;
62
63 import org.junit.Test;
64
65 public class JU_List {
66         
67         AAFcli cli;
68         Role role;
69         List list;
70         PropAccess prop;
71         AuthzEnv aEnv;
72         Writer wtr;
73         Locator<URI> loc;
74         HMangr hman;    
75         AAFcli aafcli;
76
77         private class ListRolesStub extends List {
78
79                 public ListRolesStub(Role parent) {
80                         super(parent);
81                         // TODO Auto-generated constructor stub
82                 }
83
84
85         }
86         
87         @Before
88         public void setUp() throws APIException, LocatorException, GeneralSecurityException, IOException{
89                 prop = new PropAccess();
90                 aEnv = new AuthzEnv();
91                 wtr = mock(Writer.class);
92                 loc = mock(Locator.class);
93                 SecuritySetter<HttpURLConnection> secSet = mock(SecuritySetter.class);
94                 hman = new HMangr(aEnv, loc);   
95                 aafcli = new AAFcli(prop, aEnv, wtr, hman, null, secSet);
96                 role = new Role(aafcli);
97                 list = new List(role);
98         }
99         
100         @Test
101         public void testRoles() throws APIException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
102                 Role role = new Role(aafcli);
103                 ListRolesStub listStub = new ListRolesStub(role);
104                 Future future = mock(Future.class);
105                 Rcli rcli = mock(Rcli.class);
106                 
107                 Class c = listStub.getClass();
108                 Class[] cArg = new Class[3];
109                 cArg[0] = Future.class;
110                 cArg[1] = Rcli.class;
111                 cArg[2] = String.class;//Steps to test a protected method
112                 //Method listMethod = c.getDeclaredMethod("list", cArg);
113                 //listMethod.setAccessible(true);
114                 //listMethod.invoke(listStub, future, rcli, "test");
115                 
116         }
117         
118         @Test
119         public void testReport() throws Exception {
120                 UserRoles urs = new UserRoles();
121                 Perms perms = new Perms();
122                 Roles roles = mock(Roles.class);
123                 list.report(roles, perms , urs , "test");
124                 AAFcli cli = JU_AAFCli.getAAfCli();
125                 cli.eval("DETAILS @[ 123");
126                 list.report(roles, perms , urs , "test");
127         }
128
129 }