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============================================
19 package org.onap.aaf.auth.cmd.test.ns;
21 import static org.junit.Assert.*;
23 import java.io.Writer;
25 import java.util.ArrayList;
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;
41 import aaf.v2_0.Roles;
42 import aaf.v2_0.Users.User;
43 import junit.framework.Assert;
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.*;
53 import org.junit.Test;
55 public class JU_List {
61 private class NssStub extends Nss {
62 public void addNs(Nss.Ns ns) {
63 if (this.ns == null) {
64 this.ns = new ArrayList<>();
69 private class NsStub extends Ns{
70 public void addAttrib(Nss.Ns.Attrib attrib) {
71 if ( this.attrib == null) {
72 this.attrib = new ArrayList<>();
74 this.attrib.add(attrib);
77 public void addResponsible(String str) {
78 if (this.responsible == null) {
79 this.responsible = new ArrayList<>();
81 this.responsible.add(str);
84 public void addAdmin(String str) {
85 if (this.admin == null) {
86 this.admin = new ArrayList<>();
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);
107 NS ns = new NS(aafcli);
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);
125 aafcli.eval("DETAILS @[ 123");
127 list.report(fu, "test");
131 public void testGetType() {
132 Assert.assertEquals("n/a", list.getType(user));
134 Assert.assertEquals("U/P", list.getType(user));
136 Assert.assertEquals("U/P2", list.getType(user));
138 Assert.assertEquals("Cert", list.getType(user));
140 Assert.assertEquals("x509", list.getType(user));