e3cfbd179eda92b80585e657d053af55e95b36e7
[aaf/authz.git] / auth / auth-cmd / src / test / java / org / onap / aaf / auth / cmd / test / JU_Cmd.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
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
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  * * limitations under the License.
18  * * ============LICENSE_END====================================================
19  * *
20  * *
21  ******************************************************************************/
22
23 package org.onap.aaf.auth.cmd.test;
24
25 import static org.junit.Assert.*;
26
27 import org.junit.After;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.mockito.Mock;
31 import org.mockito.Mockito;
32 import static org.mockito.Mockito.*;
33 import org.onap.aaf.auth.cmd.AAFcli;
34 import org.onap.aaf.auth.cmd.Cmd;
35 import org.onap.aaf.auth.cmd.Param;
36 import org.onap.aaf.auth.cmd.mgmt.Cache;
37 import org.onap.aaf.auth.cmd.mgmt.Clear;
38 import org.onap.aaf.auth.cmd.mgmt.Mgmt;
39 import org.onap.aaf.auth.common.Define;
40 import org.onap.aaf.auth.server.AbsService;
41 import org.onap.aaf.cadi.Access;
42 import org.onap.aaf.cadi.CadiException;
43 import org.onap.aaf.cadi.LocatorException;
44 import org.onap.aaf.cadi.PropAccess;
45 import org.onap.aaf.cadi.client.Future;
46 import org.onap.aaf.cadi.client.Retryable;
47 import org.onap.aaf.cadi.register.Registrant;
48 import org.onap.aaf.misc.env.APIException;
49 import org.onap.aaf.misc.env.impl.BasicEnv;
50
51 import aaf.v2_0.History;
52 import aaf.v2_0.History.Item;
53
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;
59
60 import javax.servlet.Filter;
61
62 import org.junit.Test;
63
64 public class JU_Cmd {
65
66     CmdStub cmd;
67     CmdStub cmd1;
68     CmdStub cmd2;
69     AAFcli cli;
70     
71     private class CmdStub extends Cmd {
72
73
74         public CmdStub(AAFcli aafcli, String name, Param[] params) {
75             super(aafcli, name, params);
76             // TODO Auto-generated constructor stub
77         }
78         
79         public CmdStub(Cmd parent, String name, Param[] params) {
80             super(parent, name, params);
81             // TODO Auto-generated constructor stub
82         }
83
84         @Override
85         protected int _exec(int idx, String... args) throws CadiException, APIException, LocatorException {
86             // TODO Auto-generated method stub
87             return 0;
88         }
89         
90         @Override
91         public void error(Future<?> future) {
92             super.error(future);
93         }
94
95     }
96     
97     @Before
98     public void setUp() throws APIException, LocatorException, GeneralSecurityException, IOException, CadiException {
99         cli = JU_AAFCli.getAAfCli();
100         Param[] param = new Param[] {new Param("name",true)};
101         
102         cmd = new CmdStub(cli,"test", param);
103         cmd1 = new CmdStub(cmd,"test", param);
104         cmd2 = new CmdStub(cmd,"test", param);
105     }
106     
107     @Test
108     public void testReportColHead() {
109         String[] args = new String[] {new String("test")};
110         cmd.reportColHead("format", args);
111     }
112     
113     @Test
114     public void testBuilder() {
115         StringBuilder detail = new StringBuilder();
116         StringBuilder sb = new StringBuilder("test 123");
117         
118         cmd.build(sb, detail);
119         detail.append("test");
120         cmd.build(sb, detail);
121     }
122     
123     @Test
124     public void testApi() throws APIException, CadiException {
125         StringBuilder sb = new StringBuilder("test 123");
126         Define def = new Define();
127         PropAccess prop = new PropAccess();
128         def.set(prop);
129         Mgmt mgmt = new Mgmt(cli);
130         Cache cache = new Cache(mgmt);
131         Clear clr = new Clear(cache);
132         clr.detailedHelp(0, sb);
133     }
134     
135     @Test
136     public void testToString() {
137         cmd.toString();
138     }
139     
140     @Test
141     public void testFullID() {
142         cmd.fullID("test");
143         cmd.fullID("t@st");
144         cmd.fullID(null);
145     }
146     
147     @Test
148     public void testError() {
149         Future<?> future = mock(Future.class);
150         cmd.error(future);
151         when(future.code()).thenReturn(401);
152         cmd.error(future);
153         when(future.code()).thenReturn(403);
154         cmd.error(future);
155         when(future.code()).thenReturn(404);
156         cmd.error(future);
157         when(future.body()).thenReturn("NotNull");
158         cmd.error(future);
159         when(future.body()).thenReturn("{NotNull");
160         cmd.error(future);
161         when(future.body()).thenReturn("<html>NotNull");
162         cmd.error(future);
163     }
164     
165     @Test
166     public void testActivity() {
167         History hist = new History();
168         cmd.activity(hist, "test");
169         cmd.activity(hist, "te[st");
170     }
171     
172     @Test
173     public void testWhichOption() throws CadiException {
174         String[] strArr = {"a", "b", "c"};
175         cmd.whichOption(strArr, "b");
176     }
177     
178     @Test
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
182     }
183     
184     @Test
185     public void testExec() throws CadiException, APIException, LocatorException {
186         String[] strArr = {"a", "b", "c"};
187         cmd.exec(1, strArr);
188     }
189     
190     
191
192 }