3c5768097abd7048a6c32b38559c333279081009
[aaf/authz.git] / auth / auth-cmd / src / test / java / org / onap / aaf / auth / cmd / test / role / JU_User.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
4  * * ===========================================================================
5  * * Copyright © 2017 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  * * limitations under the License.
18  * * ============LICENSE_END====================================================
19  * *
20  * *
21  ******************************************************************************/
22 package org.onap.aaf.auth.cmd.test.role;
23
24 import org.junit.Assert;
25 import org.junit.Before;
26
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.fail;
29 import static org.mockito.Mockito.mock;
30 import static org.mockito.Mockito.when;
31
32 import java.io.Writer;
33 import java.net.HttpURLConnection;
34 import java.net.URI;
35 import java.net.URISyntaxException;
36
37 import org.junit.BeforeClass;
38 import org.junit.Test;
39 import org.junit.runner.RunWith;
40 import org.mockito.runners.MockitoJUnitRunner;
41 import org.onap.aaf.auth.cmd.AAFcli;
42 import org.onap.aaf.auth.cmd.perm.Perm;
43 import org.onap.aaf.auth.cmd.role.Role;
44 import org.onap.aaf.auth.cmd.role.User;
45 import org.onap.aaf.auth.cmd.test.JU_AAFCli;
46 import org.onap.aaf.auth.env.AuthzEnv;
47 import org.onap.aaf.cadi.CadiException;
48 import org.onap.aaf.cadi.Locator;
49 import org.onap.aaf.cadi.LocatorException;
50 import org.onap.aaf.cadi.PropAccess;
51 import org.onap.aaf.cadi.SecuritySetter;
52 import org.onap.aaf.cadi.Locator.Item;
53 import org.onap.aaf.cadi.http.HMangr;
54 import org.onap.aaf.cadi.http.HRcli;
55 import org.onap.aaf.misc.env.APIException;
56
57 @RunWith(MockitoJUnitRunner.class)
58 public class JU_User {
59         
60         private static User user;
61         PropAccess prop;
62         AuthzEnv aEnv;
63         Writer wtr;
64         Locator<URI> loc;
65         HMangr hman;    
66         AAFcli aafcli;
67         
68         @Before
69         public void setUp () throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException {
70                 prop = new PropAccess();
71                 aEnv = new AuthzEnv();
72                 wtr = mock(Writer.class);
73                 loc = mock(Locator.class);
74                 SecuritySetter<HttpURLConnection> secSet = mock(SecuritySetter.class);
75                 hman = new HMangr(aEnv, loc);   
76                 aafcli = new AAFcli(prop, aEnv, wtr, hman, null, secSet);
77                 Role role = new Role(aafcli);
78                 user = new User(role);
79         }
80         
81         @Test
82         public void testExec() throws APIException, LocatorException, CadiException, URISyntaxException {
83                 Item value = mock(Item.class);
84                 Locator.Item item = new Locator.Item() {
85                 };
86                 when(loc.best()).thenReturn(value);
87                 URI uri = new URI("http://java.sun.com/j2se/1.3/");
88                 when(loc.get(value)).thenReturn(uri);
89                 SecuritySetter<HttpURLConnection> secSet = mock(SecuritySetter.class);
90                 HRcli hcli = new HRcli(hman, uri, item, secSet);
91                 String[] strArr = {"add","del","setTo","extend","add","del","setTo","extend"};
92                 user._exec(0, strArr);
93                 
94                 String[] strArr1 = {"del","setTo","extend","add","del","setTo","extend"};
95                 user._exec(0, strArr1);
96                 
97                 String[] strArr2 = {"setTo","extend","add","del","setTo","extend"};
98                 user._exec(0, strArr2);
99                 
100                 String[] strArr3 = {"extend","add","del","setTo","extend"};
101                 user._exec(0, strArr3);
102                 
103         }
104         
105         @Test
106         public void detailedHelp() {
107                 boolean hasNoError = true;
108                 try {
109                         user.detailedHelp(1, new StringBuilder("test"));
110                 } catch (Exception e) {
111                         hasNoError = false;
112                 }
113                 assertEquals(hasNoError, true);
114         }
115 }