1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.cmd;
\r
25 import static org.junit.Assert.assertFalse;
\r
26 import static org.junit.Assert.assertTrue;
\r
27 import static org.mockito.Mockito.mock;
\r
29 import java.io.IOException;
\r
30 import java.io.OutputStreamWriter;
\r
31 import java.net.HttpURLConnection;
\r
32 import java.security.GeneralSecurityException;
\r
34 import org.junit.BeforeClass;
\r
35 import org.junit.Test;
\r
36 import org.junit.runner.RunWith;
\r
37 import org.mockito.runners.MockitoJUnitRunner;
\r
38 import org.onap.aaf.authz.env.AuthzEnv;
\r
39 import org.onap.aaf.cmd.AAFcli;
\r
40 import org.onap.aaf.cadi.CadiException;
\r
41 import org.onap.aaf.cadi.Locator;
\r
42 import org.onap.aaf.cadi.LocatorException;
\r
43 import org.onap.aaf.cadi.client.PropertyLocator;
\r
44 import org.onap.aaf.cadi.config.Config;
\r
45 import org.onap.aaf.cadi.config.SecurityInfo;
\r
46 import org.onap.aaf.cadi.http.HBasicAuthSS;
\r
47 import org.onap.aaf.cadi.http.HMangr;
\r
48 import org.onap.aaf.inno.env.APIException;
\r
50 @RunWith(MockitoJUnitRunner.class)
\r
51 public class JU_AAFCli {
\r
53 private static AAFcli cli;
\r
54 private static int TIMEOUT = Integer.parseInt(Config.AAF_CONN_TIMEOUT_DEF);
\r
57 public static void setUp() throws Exception, Exception {
\r
62 public void eval() throws Exception {
\r
63 assertTrue(cli.eval("#startswith"));
\r
67 public void eval_empty() throws Exception {
\r
68 assertTrue(cli.eval(""));
\r
72 public void eval1() throws Exception {
\r
73 assertTrue(cli.eval("@[123"));
\r
77 public void eval2() throws Exception {
\r
78 assertFalse(cli.eval("as @[ 123"));
\r
82 public void eval3() throws Exception {
\r
84 cli.eval("expect @[ 123");
\r
85 } catch (Exception e) {
\r
86 // TODO Auto-generated catch block
\r
87 assertTrue(e instanceof CadiException);
\r
91 public void eval31() throws Exception {
\r
93 cli.eval("expect 1 @[ 123");
\r
94 } catch (Exception e) {
\r
95 // TODO Auto-generated catch block
\r
96 assertTrue(e instanceof CadiException);
\r
101 public void eval4() throws Exception {
\r
103 cli.eval("sleep @[ 123");
\r
104 } catch (Exception e) {
\r
105 assertTrue(e instanceof NumberFormatException);
\r
110 public void eval41() throws Exception {
\r
111 assertTrue(cli.eval("sleep 1 @[ 123"));
\r
115 public void eval5() throws Exception {
\r
117 cli.eval("delay @[ 123");
\r
118 } catch (Exception e) {
\r
119 assertTrue(e instanceof NumberFormatException);
\r
124 public void eval51() throws Exception {
\r
125 assertTrue(cli.eval("delay 1 @[ 123"));
\r
129 public void eval7() throws Exception {
\r
130 assertFalse(cli.eval("exit @[ 123"));
\r
134 public void eval8() throws Exception {
\r
135 assertTrue(cli.eval("REQUEST @[ 123"));
\r
139 public void eval9() throws Exception {
\r
140 assertTrue(cli.eval("FORCE @[ 123"));
\r
144 public void eval10() throws Exception {
\r
145 assertTrue(cli.eval("set @[ 123"));
\r
149 public void keyboardHelp() throws Exception {
\r
150 boolean noError=true;
\r
152 cli.keyboardHelp();
\r
153 } catch (Exception e) {
\r
156 assertTrue(noError);
\r
162 public void setProp() throws Exception {
\r
163 boolean noError=true;
\r
165 cli.keyboardHelp();
\r
166 } catch (Exception e) {
\r
169 assertTrue(noError);
\r
173 public void eval_randomString() throws Exception {
\r
174 assertTrue(cli.eval("Some random string @#&*& to check complete 100 coverage"));
\r
177 public static AAFcli getAAfCli() throws APIException, LocatorException, GeneralSecurityException, IOException {
\r
178 final AuthzEnv env = new AuthzEnv(System.getProperties());
\r
179 String aafUrl = "https://DME2RESOLVE";
\r
180 SecurityInfo si = new SecurityInfo(env);
\r
181 env.loadToSystemPropsStartsWith("AAF", "DME2");
\r
183 loc = new PropertyLocator(aafUrl);
\r
184 TIMEOUT = Integer.parseInt(env.getProperty(Config.AAF_CONN_TIMEOUT, Config.AAF_CONN_TIMEOUT_DEF));
\r
185 HMangr hman = new HMangr(env, loc).readTimeout(TIMEOUT).apiVersion("2.0");
\r
187 // TODO: Consider requiring a default in properties
\r
188 env.setProperty(Config.AAF_DEFAULT_REALM,
\r
189 System.getProperty(Config.AAF_DEFAULT_REALM, Config.getDefaultRealm()));
\r
190 HBasicAuthSS ss = mock(HBasicAuthSS.class);
\r
191 return new AAFcli(env, new OutputStreamWriter(System.out), hman, si, ss);
\r