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 org.onap.aaf.auth.cmd.AAFcli;
32 import org.onap.aaf.auth.cmd.Cmd;
33 import org.onap.aaf.auth.cmd.Param;
34 import org.onap.aaf.auth.cmd.mgmt.Cache;
35 import org.onap.aaf.auth.cmd.mgmt.Clear;
36 import org.onap.aaf.auth.cmd.mgmt.Mgmt;
37 import org.onap.aaf.auth.common.Define;
38 import org.onap.aaf.auth.server.AbsService;
39 import org.onap.aaf.cadi.Access;
40 import org.onap.aaf.cadi.CadiException;
41 import org.onap.aaf.cadi.LocatorException;
42 import org.onap.aaf.cadi.PropAccess;
43 import org.onap.aaf.cadi.client.Future;
44 import org.onap.aaf.cadi.client.Retryable;
45 import org.onap.aaf.cadi.register.Registrant;
46 import org.onap.aaf.misc.env.APIException;
47 import org.onap.aaf.misc.env.impl.BasicEnv;
49 import aaf.v2_0.History;
50 import aaf.v2_0.History.Item;
52 import static org.mockito.Mockito.*;
54 import java.io.IOException;
55 import java.lang.reflect.InvocationTargetException;
56 import java.lang.reflect.Method;
57 import java.security.GeneralSecurityException;
58 import java.util.List;
60 import javax.servlet.Filter;
62 import org.junit.Test;
71 private class CmdStub extends Cmd {
74 public CmdStub(AAFcli aafcli, String name, Param[] params) {
75 super(aafcli, name, params);
76 // TODO Auto-generated constructor stub
79 public CmdStub(Cmd parent, String name, Param[] params) {
80 super(parent, name, params);
81 // TODO Auto-generated constructor stub
85 protected int _exec(int idx, String... args) throws CadiException, APIException, LocatorException {
86 // TODO Auto-generated method stub
91 public void error(Future<?> future) {
98 public void setUp() throws APIException, LocatorException, GeneralSecurityException, IOException {
99 cli = JU_AAFCli.getAAfCli();
100 Param[] param = new Param[] {new Param("name",true)};
102 cmd = new CmdStub(cli,"test", param);
103 cmd1 = new CmdStub(cmd,"test", param);
104 cmd2 = new CmdStub(cmd,"test", param);
108 public void testReportColHead() {
109 String[] args = new String[] {new String("test")};
110 cmd.reportColHead("format", args);
114 public void testBuilder() {
115 StringBuilder detail = new StringBuilder();
116 StringBuilder sb = new StringBuilder("test 123");
118 cmd.build(sb, detail);
119 detail.append("test");
120 cmd.build(sb, detail);
124 public void testApi() throws APIException, CadiException {
125 StringBuilder sb = new StringBuilder("test 123");
126 Define def = new Define();
127 PropAccess prop = new PropAccess();
129 Mgmt mgmt = new Mgmt(cli);
130 Cache cache = new Cache(mgmt);
131 Clear clr = new Clear(cache);
132 clr.detailedHelp(0, sb);
136 public void testToString() {
141 public void testFullID() {
148 public void testError() {
149 Future<?> future = mock(Future.class);
151 when(future.code()).thenReturn(401);
153 when(future.code()).thenReturn(403);
155 when(future.code()).thenReturn(404);
157 when(future.body()).thenReturn("NotNull");
159 when(future.body()).thenReturn("{NotNull");
161 when(future.body()).thenReturn("<html>NotNull");
166 public void testActivity() {
167 History hist = new History();
168 cmd.activity(hist, "test");
169 cmd.activity(hist, "te[st");
173 public void testWhichOption() throws CadiException {
174 String[] strArr = {"a", "b", "c"};
175 cmd.whichOption(strArr, "b");
179 public void testOneOf() throws APIException, CadiException, LocatorException {
180 Retryable retryable = mock(Retryable.class);
181 //cmd.oneOf(retryable, "host"); //TODO: AAF-111 need input for hMan