cf8539abb07cfff3ab764d438821c41cd4eac392
[aaf/authz.git] / auth / auth-cmd / src / test / java / org / onap / aaf / auth / cmd / test / ns / 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.ns;
22
23 import static org.junit.Assert.*;
24
25 import java.io.Writer;
26 import java.net.URI;
27 import java.util.ArrayList;
28
29 import org.onap.aaf.auth.cmd.ns.List;
30 import org.onap.aaf.auth.cmd.ns.NS;
31 import org.onap.aaf.auth.env.AuthzEnv;
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<Nss.Ns>();
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<Nss.Ns.Attrib>();
74                     }
75                     this.attrib.add(attrib);
76                 }
77                         
78                         public void addResponsible(String str) {
79                     if (this.responsible == null) {
80                         this.responsible = new ArrayList<String>();
81                     }
82                     this.responsible.add(str);
83                 }
84                         
85                         public void addAdmin(String str) {
86                     if (this.admin == null) {
87                         this.admin = new ArrayList<String>();
88                     }
89                     this.admin.add(str);
90                 }
91                 }
92                 
93                 
94                 
95                 
96         }
97         
98
99         @Before
100         public void setUp() throws APIException, LocatorException {
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("Cert", list.getType(user));
140                 user.setType(200);
141                 Assert.assertEquals("x509", list.getType(user));
142         }
143         
144 }