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 ******************************************************************************/
23 package org.onap.aaf.auth.cmd.test;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertTrue;
27 import static org.junit.Assert.fail;
28 import static org.mockito.Mockito.mock;
30 import java.io.IOException;
31 import java.io.OutputStreamWriter;
32 import java.net.HttpURLConnection;
33 import java.security.GeneralSecurityException;
35 import org.junit.Assert;
36 import org.junit.BeforeClass;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 import org.mockito.runners.MockitoJUnitRunner;
40 import org.onap.aaf.auth.cmd.AAFcli;
41 import org.onap.aaf.auth.env.AuthzEnv;
42 import org.onap.aaf.cadi.CadiException;
43 import org.onap.aaf.cadi.Locator;
44 import org.onap.aaf.cadi.LocatorException;
45 import org.onap.aaf.cadi.config.Config;
46 import org.onap.aaf.cadi.config.SecurityInfo;
47 import org.onap.aaf.cadi.config.SecurityInfoC;
48 import org.onap.aaf.cadi.http.HBasicAuthSS;
49 import org.onap.aaf.cadi.http.HMangr;
50 import org.onap.aaf.cadi.locator.PropertyLocator;
51 import org.onap.aaf.misc.env.APIException;
53 @RunWith(MockitoJUnitRunner.class)
54 public class JU_AAFCli {
56 private static AAFcli cli;
57 private static int TIMEOUT = Integer.parseInt(Config.AAF_CONN_TIMEOUT_DEF);
60 public static void setUp() throws Exception, Exception {
65 public void eval() throws Exception {
66 assertTrue(cli.eval("#startswith"));
70 public void eval_empty() throws Exception {
71 assertTrue(cli.eval(""));
75 public void eval1() throws Exception {
76 assertTrue(cli.eval("@[123"));
80 // public void eval2() throws Exception {
81 // assertFalse(cli.eval("as @[ 123"));
85 public void eval3() throws Exception {
87 cli.eval("expect @[ 123");
88 } catch (Exception e) {
89 // TODO Auto-generated catch block
90 assertTrue(e instanceof CadiException);
94 public void eval31() throws Exception {
96 cli.eval("expect 1 @[ 123");
97 } catch (Exception e) {
98 // TODO Auto-generated catch block
99 assertTrue(e instanceof CadiException);
104 public void eval4() throws Exception {
106 cli.eval("sleep @[ 123");
107 } catch (Exception e) {
108 assertTrue(e instanceof NumberFormatException);
113 public void eval41() throws Exception {
114 assertTrue(cli.eval("sleep 1 @[ 123"));
118 public void eval5() throws Exception {
120 cli.eval("delay @[ 123");
121 } catch (Exception e) {
122 assertTrue(e instanceof NumberFormatException);
127 public void eval51() throws Exception {
128 assertTrue(cli.eval("delay 1 @[ 123"));
132 public void eval7() throws Exception {
133 assertFalse(cli.eval("exit @[ 123"));
137 public void eval8() throws Exception {
138 assertTrue(cli.eval("REQUEST @[ 123"));
142 public void eval9() throws Exception {
143 assertTrue(cli.eval("FORCE @[ 123"));
147 public void eval10() throws Exception {
148 assertTrue(cli.eval("set @[ 123"));
152 public void eval11() throws Exception {
153 assertTrue(cli.eval("DETAILS @[ 123"));
157 public void eval12() throws Exception {
158 assertTrue(cli.eval(". |/, .\"0 \" "));
162 public void keyboardHelp() throws Exception {
163 boolean noError=true;
166 } catch (Exception e) {
173 public void setProp() throws Exception {
174 boolean noError=true;
177 } catch (Exception e) {
184 public void eval_randomString() throws Exception {
185 assertTrue(cli.eval("Some random string @#&*& to check complete 100 coverage"));
188 public static AAFcli getAAfCli() throws APIException, LocatorException, GeneralSecurityException, IOException, CadiException {
189 final AuthzEnv env = new AuthzEnv(System.getProperties());
190 String aafUrl = "https://DME2RESOLVE";
191 SecurityInfoC<HttpURLConnection> si = mock(SecurityInfoC.class);
192 env.loadToSystemPropsStartsWith("AAF", "DME2");
194 loc = new PropertyLocator(aafUrl);
195 TIMEOUT = Integer.parseInt(env.getProperty(Config.AAF_CONN_TIMEOUT, Config.AAF_CONN_TIMEOUT_DEF));
196 HMangr hman = new HMangr(env, loc).readTimeout(TIMEOUT).apiVersion(Config.AAF_DEFAULT_API_VERSION);
198 // TODO: Consider requiring a default in properties
199 env.setProperty(Config.AAF_DEFAULT_REALM,
200 System.getProperty(Config.AAF_DEFAULT_REALM, Config.getDefaultRealm()));
202 HBasicAuthSS ss = mock(HBasicAuthSS.class);
203 env.setProperty(Config.AAF_APPPASS, "test");
204 return new AAFcli(env, new OutputStreamWriter(System.out), hman, si, ss);
208 public void testVerbose() {
214 public void testClose() {
219 public void testTimeout() {
220 Assert.assertNotNull(cli.timeout());
224 public void testTest() {
225 Assert.assertNotNull(cli.isTest());
229 public void testIsDetailed() {
230 Assert.assertNotNull(cli.isDetailed());
234 public void testAddRequest() {
235 Assert.assertNotNull(cli.addRequest());
239 public void testForceString() {
240 cli.clearSingleLineProperties();
241 Assert.assertNull(cli.forceString());
245 public void testClearSingleLineProperties() {
246 cli.clearSingleLineProperties();
250 public void testGui() {
256 public void testMain() {
257 String[] strArr = {"\\*","test1"};