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