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
10 * http://www.apache.org/licenses/LICENSE-2.0
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============================================
20 package org.onap.aaf.auth.cmd.test.ns;
22 import static org.junit.Assert.*;
24 import java.io.Writer;
26 import java.util.ArrayList;
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;
42 import aaf.v2_0.Roles;
43 import aaf.v2_0.Users.User;
44 import junit.framework.Assert;
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.*;
54 import org.junit.Test;
56 public class JU_List {
62 private class NssStub extends Nss {
63 public void addNs(Nss.Ns ns) {
64 if (this.ns == null) {
65 this.ns = new ArrayList<>();
70 private class NsStub extends Ns{
71 public void addAttrib(Nss.Ns.Attrib attrib) {
72 if ( this.attrib == null) {
73 this.attrib = new ArrayList<>();
75 this.attrib.add(attrib);
78 public void addResponsible(String str) {
79 if (this.responsible == null) {
80 this.responsible = new ArrayList<>();
82 this.responsible.add(str);
85 public void addAdmin(String str) {
86 if (this.admin == null) {
87 this.admin = new ArrayList<>();
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);
108 NS ns = new NS(aafcli);
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);
126 aafcli.eval("DETAILS @[ 123");
128 list.report(fu, "test");
132 public void testGetType() {
133 Assert.assertEquals("n/a", list.getType(user));
135 Assert.assertEquals("U/P", list.getType(user));
137 Assert.assertEquals("U/P2", list.getType(user));
139 Assert.assertEquals("Cert", list.getType(user));
141 Assert.assertEquals("x509", list.getType(user));