Mass removal of all Tabs (Style Warnings)
[aaf/authz.git] / auth / auth-cmd / src / test / java / org / onap / aaf / auth / cmd / test / JU_AAFCli.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.assertFalse;
25 import static org.junit.Assert.assertTrue;
26 import static org.junit.Assert.fail;
27 import static org.mockito.Mockito.mock;
28
29 import java.io.IOException;
30 import java.io.OutputStreamWriter;
31 import java.net.HttpURLConnection;
32 import java.security.GeneralSecurityException;
33
34 import org.junit.Assert;
35 import org.junit.BeforeClass;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.mockito.runners.MockitoJUnitRunner;
39 import org.onap.aaf.auth.cmd.AAFcli;
40 import org.onap.aaf.auth.env.AuthzEnv;
41 import org.onap.aaf.cadi.CadiException;
42 import org.onap.aaf.cadi.Locator;
43 import org.onap.aaf.cadi.LocatorException;
44 import org.onap.aaf.cadi.config.Config;
45 import org.onap.aaf.cadi.config.SecurityInfo;
46 import org.onap.aaf.cadi.config.SecurityInfoC;
47 import org.onap.aaf.cadi.http.HBasicAuthSS;
48 import org.onap.aaf.cadi.http.HMangr;
49 import org.onap.aaf.cadi.locator.PropertyLocator;
50 import org.onap.aaf.misc.env.APIException;
51
52 @RunWith(MockitoJUnitRunner.class)
53 public class JU_AAFCli {
54
55     private static AAFcli cli;
56     private static int TIMEOUT = Integer.parseInt(Config.AAF_CONN_TIMEOUT_DEF);
57
58     @BeforeClass
59     public static void setUp() throws Exception, Exception {
60         cli = getAAfCli();
61     }
62
63     @Test
64     public void eval() throws Exception {
65         assertTrue(cli.eval("#startswith"));
66     }
67
68     @Test
69     public void eval_empty() throws Exception {
70         assertTrue(cli.eval(""));
71     }
72
73     @Test
74     public void eval1() throws Exception {
75         assertTrue(cli.eval("@[123"));
76     }
77
78 //    @Test
79 //    public void eval2() throws Exception {
80 //        assertFalse(cli.eval("as @[ 123"));
81 //    }
82
83     @Test
84     public void eval3() throws Exception {
85         try {
86             cli.eval("expect @[ 123");
87         } catch (Exception e) {
88             // TODO Auto-generated catch block
89             assertTrue(e instanceof CadiException);
90         }
91     }
92
93     public void eval31() throws Exception {
94         try {
95             cli.eval("expect 1 @[ 123");
96         } catch (Exception e) {
97             // TODO Auto-generated catch block
98             assertTrue(e instanceof CadiException);
99         }
100     }
101
102     @Test
103     public void eval4() throws Exception {
104         try {
105             cli.eval("sleep @[ 123");
106         } catch (Exception e) {
107             assertTrue(e instanceof NumberFormatException);
108         }
109     }
110
111     @Test
112     public void eval41() throws Exception {
113         assertTrue(cli.eval("sleep 1 @[ 123"));
114     }
115
116     @Test
117     public void eval5() throws Exception {
118         try {
119             cli.eval("delay @[ 123");
120         } catch (Exception e) {
121             assertTrue(e instanceof NumberFormatException);
122         }
123     }
124
125     @Test
126     public void eval51() throws Exception {
127         assertTrue(cli.eval("delay 1 @[ 123"));
128     }
129
130     @Test
131     public void eval7() throws Exception {
132         assertFalse(cli.eval("exit @[ 123"));
133     }
134
135     @Test
136     public void eval8() throws Exception {
137         assertTrue(cli.eval("REQUEST @[ 123"));
138     }
139
140     @Test
141     public void eval9() throws Exception {
142         assertTrue(cli.eval("FORCE @[ 123"));
143     }
144
145     @Test
146     public void eval10() throws Exception {
147         assertTrue(cli.eval("set @[ 123"));
148     }
149     
150     @Test
151     public void eval11() throws Exception {
152         assertTrue(cli.eval("DETAILS @[ 123"));
153     }
154     
155     @Test
156     public void eval12() throws Exception {
157         assertTrue(cli.eval(". |/, .\"0 \" "));
158     }
159
160     @Test
161     public void keyboardHelp() throws Exception {
162         boolean noError=true;
163         try {
164             cli.keyboardHelp();
165         } catch (Exception e) {
166             noError=false;
167         }
168         assertTrue(noError);
169     }
170
171     @Test
172     public void setProp() throws Exception {
173         boolean noError=true;
174         try {
175             cli.keyboardHelp();
176         } catch (Exception e) {
177             noError=false;
178         }
179         assertTrue(noError);
180     }
181     
182     @Test
183     public void eval_randomString() throws Exception {
184         assertTrue(cli.eval("Some random string @#&*& to check complete 100 coverage"));
185     }
186
187     public static AAFcli getAAfCli() throws APIException, LocatorException, GeneralSecurityException, IOException, CadiException {
188         final AuthzEnv env = new AuthzEnv(System.getProperties());
189         String aafUrl = "https://DME2RESOLVE";
190         SecurityInfoC<HttpURLConnection> si = mock(SecurityInfoC.class);
191         env.loadToSystemPropsStartsWith("AAF", "DME2");
192         Locator loc;
193         loc = new PropertyLocator(aafUrl);
194         TIMEOUT = Integer.parseInt(env.getProperty(Config.AAF_CONN_TIMEOUT, Config.AAF_CONN_TIMEOUT_DEF));
195         HMangr hman = new HMangr(env, loc).readTimeout(TIMEOUT).apiVersion("2.0");
196
197         // TODO: Consider requiring a default in properties
198         env.setProperty(Config.AAF_DEFAULT_REALM,
199                 System.getProperty(Config.AAF_DEFAULT_REALM, Config.getDefaultRealm()));
200         
201         HBasicAuthSS ss = mock(HBasicAuthSS.class);
202         env.setProperty(Config.AAF_APPPASS, "test");
203         return new AAFcli(env, new OutputStreamWriter(System.out), hman, si, ss);
204     }
205     
206     @Test
207     public void testVerbose() {
208         cli.verbose(true);
209         cli.verbose(false);
210     }
211     
212     @Test
213     public void testClose() {
214         cli.close();
215     }
216     
217     @Test
218     public void testTimeout() {
219         Assert.assertNotNull(cli.timeout());
220     }
221     
222     @Test
223     public void testTest() {
224         Assert.assertNotNull(cli.isTest());
225     }
226     
227     @Test
228     public void testIsDetailed() {
229         Assert.assertNotNull(cli.isDetailed());
230     }
231     
232     @Test
233     public void testAddRequest() {
234         Assert.assertNotNull(cli.addRequest());
235     }
236     
237     @Test
238     public void testForceString() {
239         cli.clearSingleLineProperties();
240         Assert.assertNull(cli.forceString());
241     }
242     
243     @Test
244     public void testClearSingleLineProperties() {
245         cli.clearSingleLineProperties();
246     }
247     
248     @Test
249     public void testGui() {
250         cli.gui(true);
251         cli.gui(false);
252     }
253     
254     @Test
255     public void testMain() {
256         String[] strArr = {"\\*","test1"};
257         //cli.main(strArr);
258     }
259     
260 }