1 /*******************************************************************************
2 * ============LICENSE_START====================================================
4 * * ===========================================================================
5 * * Copyright © 2017 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
11 * * http://www.apache.org/licenses/LICENSE-2.0
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 * * limitations under the License.
18 * * ============LICENSE_END====================================================
21 ******************************************************************************/
22 package org.onap.aaf.auth.cmd.test;
24 import static org.junit.Assert.*;
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.mockito.Mock;
30 import org.mockito.Mockito;
31 import static org.mockito.Mockito.*;
32 import org.onap.aaf.auth.cmd.AAFcli;
33 import org.onap.aaf.auth.cmd.Cmd;
34 import org.onap.aaf.auth.cmd.Param;
35 import org.onap.aaf.auth.cmd.mgmt.Cache;
36 import org.onap.aaf.auth.cmd.mgmt.Clear;
37 import org.onap.aaf.auth.cmd.mgmt.Mgmt;
38 import org.onap.aaf.auth.common.Define;
39 import org.onap.aaf.auth.server.AbsService;
40 import org.onap.aaf.cadi.Access;
41 import org.onap.aaf.cadi.CadiException;
42 import org.onap.aaf.cadi.LocatorException;
43 import org.onap.aaf.cadi.PropAccess;
44 import org.onap.aaf.cadi.client.Future;
45 import org.onap.aaf.cadi.client.Retryable;
46 import org.onap.aaf.cadi.register.Registrant;
47 import org.onap.aaf.misc.env.APIException;
48 import org.onap.aaf.misc.env.impl.BasicEnv;
50 import aaf.v2_0.History;
51 import aaf.v2_0.History.Item;
53 import java.io.IOException;
54 import java.lang.reflect.InvocationTargetException;
55 import java.lang.reflect.Method;
56 import java.security.GeneralSecurityException;
57 import java.util.List;
59 import javax.servlet.Filter;
61 import org.junit.Test;
70 private class CmdStub extends Cmd {
73 public CmdStub(AAFcli aafcli, String name, Param[] params) {
74 super(aafcli, name, params);
75 // TODO Auto-generated constructor stub
78 public CmdStub(Cmd parent, String name, Param[] params) {
79 super(parent, name, params);
80 // TODO Auto-generated constructor stub
84 protected int _exec(int idx, String... args) throws CadiException, APIException, LocatorException {
85 // TODO Auto-generated method stub
90 public void error(Future<?> future) {
97 public void setUp() throws APIException, LocatorException, GeneralSecurityException, IOException {
98 cli = JU_AAFCli.getAAfCli();
99 Param[] param = new Param[] {new Param("name",true)};
101 cmd = new CmdStub(cli,"test", param);
102 cmd1 = new CmdStub(cmd,"test", param);
103 cmd2 = new CmdStub(cmd,"test", param);
107 public void testReportColHead() {
108 String[] args = new String[] {new String("test")};
109 cmd.reportColHead("format", args);
113 public void testBuilder() {
114 StringBuilder detail = new StringBuilder();
115 StringBuilder sb = new StringBuilder("test 123");
117 cmd.build(sb, detail);
118 detail.append("test");
119 cmd.build(sb, detail);
123 public void testApi() throws APIException, CadiException {
124 StringBuilder sb = new StringBuilder("test 123");
125 Define def = new Define();
126 PropAccess prop = new PropAccess();
128 Mgmt mgmt = new Mgmt(cli);
129 Cache cache = new Cache(mgmt);
130 Clear clr = new Clear(cache);
131 clr.detailedHelp(0, sb);
135 public void testToString() {
140 public void testFullID() {
147 public void testError() {
148 Future<?> future = mock(Future.class);
150 when(future.code()).thenReturn(401);
152 when(future.code()).thenReturn(403);
154 when(future.code()).thenReturn(404);
156 when(future.body()).thenReturn("NotNull");
158 when(future.body()).thenReturn("{NotNull");
160 when(future.body()).thenReturn("<html>NotNull");
165 public void testActivity() {
166 History hist = new History();
167 cmd.activity(hist, "test");
168 cmd.activity(hist, "te[st");
172 public void testWhichOption() throws CadiException {
173 String[] strArr = {"a", "b", "c"};
174 cmd.whichOption(strArr, "b");
178 public void testOneOf() throws APIException, CadiException, LocatorException {
179 Retryable retryable = mock(Retryable.class);
180 //cmd.oneOf(retryable, "host"); //TODO: AAF-111 need input for hMan
184 public void testExec() throws CadiException, APIException, LocatorException {
185 String[] strArr = {"a", "b", "c"};