Mass removal of all Tabs (Style Warnings)
[aaf/authz.git] / auth / auth-cmd / src / test / java / org / onap / aaf / auth / cmd / test / ns / 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.ns;
20
21 import static org.junit.Assert.*;
22
23 import java.io.Writer;
24 import java.net.URI;
25 import java.util.ArrayList;
26
27 import org.onap.aaf.auth.cmd.ns.List;
28 import org.onap.aaf.auth.cmd.ns.NS;
29 import org.onap.aaf.auth.env.AuthzEnv;
30 import org.onap.aaf.cadi.CadiException;
31 import org.onap.aaf.cadi.Locator;
32 import org.onap.aaf.cadi.LocatorException;
33 import org.onap.aaf.cadi.PropAccess;
34 import org.onap.aaf.cadi.SecuritySetter;
35 import org.onap.aaf.cadi.client.Future;
36 import org.onap.aaf.cadi.config.SecurityInfoC;
37 import org.onap.aaf.cadi.http.HMangr;
38 import org.onap.aaf.misc.env.APIException;
39
40 import aaf.v2_0.Nss;
41 import aaf.v2_0.Roles;
42 import aaf.v2_0.Users.User;
43 import junit.framework.Assert;
44
45 import org.onap.aaf.auth.cmd.AAFcli;
46 import org.junit.After;
47 import org.junit.Before;
48 import org.junit.Test;
49 import org.mockito.Mock;
50 import org.mockito.Mockito;
51 import static org.mockito.Mockito.*;
52
53 import org.junit.Test;
54
55 public class JU_List {
56     
57     List list;
58     AAFcli aafcli;
59     User user;
60     
61     private class NssStub extends Nss {
62         public void addNs(Nss.Ns ns) {    
63             if (this.ns == null) {
64                 this.ns = new ArrayList<>();
65             }
66             this.ns.add(ns);
67         }
68         
69         private class NsStub extends Ns{
70             public void addAttrib(Nss.Ns.Attrib attrib) {
71                 if ( this.attrib == null) {
72                     this.attrib = new ArrayList<>();
73                 }
74                 this.attrib.add(attrib);
75             }
76             
77             public void addResponsible(String str) {
78                 if (this.responsible == null) {
79                     this.responsible = new ArrayList<>();
80                 }
81                 this.responsible.add(str);
82             }
83             
84             public void addAdmin(String str) {
85                 if (this.admin == null) {
86                     this.admin = new ArrayList<>();
87                 }
88                 this.admin.add(str);
89             }
90         }
91         
92         
93         
94         
95     }
96     
97
98     @Before
99     public void setUp() throws APIException, LocatorException, CadiException {
100         PropAccess prop = new PropAccess();
101         AuthzEnv aEnv = new AuthzEnv();
102         Writer wtr = mock(Writer.class);
103         Locator loc = mock(Locator.class);
104         HMangr hman = new HMangr(aEnv, loc);        
105         aafcli = new AAFcli(prop, aEnv, wtr, hman, null, null);
106         user = new User();
107         NS ns = new NS(aafcli);
108         
109         list = new List(ns);
110     }
111     
112     @Test
113     public void testReport() throws Exception {
114         Future<Nss> fu = mock(Future.class);
115         NssStub nssStub = new NssStub();
116         NssStub.NsStub nsStub = nssStub.new NsStub();
117         Nss.Ns.Attrib attrib = mock(Nss.Ns.Attrib.class);
118         when(attrib.getKey()).thenReturn("key");
119         when(attrib.getValue()).thenReturn("value");
120         nsStub.addAttrib(attrib);
121         nsStub.addResponsible("test");
122         nsStub.addAdmin("admin");
123         nssStub.addNs(nsStub);
124         fu.value = nssStub;
125         aafcli.eval("DETAILS @[ 123");
126         
127         list.report(fu, "test");
128     }
129     
130     @Test
131     public void testGetType() {
132         Assert.assertEquals("n/a", list.getType(user));
133         user.setType(1);
134         Assert.assertEquals("U/P", list.getType(user));
135         user.setType(2);
136         Assert.assertEquals("U/P2", list.getType(user));
137         user.setType(10);
138         Assert.assertEquals("Cert", list.getType(user));
139         user.setType(200);
140         Assert.assertEquals("x509", list.getType(user));
141     }
142     
143 }