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