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