diff options
Diffstat (limited to 'auth/auth-cmd/src')
3 files changed, 308 insertions, 171 deletions
diff --git a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/JU_AAFCli.java b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/JU_AAFCli.java index 27c7aa59..f73f0929 100644 --- a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/JU_AAFCli.java +++ b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/JU_AAFCli.java @@ -31,6 +31,7 @@ import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.security.GeneralSecurityException; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -42,157 +43,210 @@ import org.onap.aaf.cadi.Locator; import org.onap.aaf.cadi.LocatorException; import org.onap.aaf.cadi.config.Config; import org.onap.aaf.cadi.config.SecurityInfo; +import org.onap.aaf.cadi.config.SecurityInfoC; import org.onap.aaf.cadi.http.HBasicAuthSS; import org.onap.aaf.cadi.http.HMangr; import org.onap.aaf.cadi.locator.PropertyLocator; import org.onap.aaf.misc.env.APIException; + @RunWith(MockitoJUnitRunner.class) public class JU_AAFCli { private static AAFcli cli; private static int TIMEOUT = Integer.parseInt(Config.AAF_CONN_TIMEOUT_DEF); -// @BeforeClass -// public static void setUp() throws Exception, Exception { -// cli = getAAfCli(); -// } -// -// @Test -// public void eval() throws Exception { -// assertTrue(cli.eval("#startswith")); -// } -// -// @Test -// public void eval_empty() throws Exception { -// assertTrue(cli.eval("")); -// } -// -// @Test -// public void eval1() throws Exception { -// assertTrue(cli.eval("@[123")); -// } -// -// @Test -// public void eval2() throws Exception { -// assertFalse(cli.eval("as @[ 123")); -// } -// -// @Test -// public void eval3() throws Exception { -// try { -// cli.eval("expect @[ 123"); -// } catch (Exception e) { -// // TODO Auto-generated catch block -// assertTrue(e instanceof CadiException); -// } -// } -// -// public void eval31() throws Exception { -// try { -// cli.eval("expect 1 @[ 123"); -// } catch (Exception e) { -// // TODO Auto-generated catch block -// assertTrue(e instanceof CadiException); -// } -// } -// -// @Test -// public void eval4() throws Exception { -// try { -// cli.eval("sleep @[ 123"); -// } catch (Exception e) { -// assertTrue(e instanceof NumberFormatException); -// } -// } -// -// @Test -// public void eval41() throws Exception { -// assertTrue(cli.eval("sleep 1 @[ 123")); -// } -// -// @Test -// public void eval5() throws Exception { -// try { -// cli.eval("delay @[ 123"); -// } catch (Exception e) { -// assertTrue(e instanceof NumberFormatException); -// } -// } -// -// @Test -// public void eval51() throws Exception { -// assertTrue(cli.eval("delay 1 @[ 123")); -// } -// -// @Test -// public void eval7() throws Exception { -// assertFalse(cli.eval("exit @[ 123")); -// } -// -// @Test -// public void eval8() throws Exception { -// assertTrue(cli.eval("REQUEST @[ 123")); -// } -// -// @Test -// public void eval9() throws Exception { -// assertTrue(cli.eval("FORCE @[ 123")); -// } -// -// @Test -// public void eval10() throws Exception { -// assertTrue(cli.eval("set @[ 123")); -// } -// -// @Test -// public void keyboardHelp() throws Exception { -// boolean noError=true; -// try { -// cli.keyboardHelp(); -// } catch (Exception e) { -// noError=false; -// } -// assertTrue(noError); -// } -// -// -// -// @Test -// public void setProp() throws Exception { -// boolean noError=true; -// try { -// cli.keyboardHelp(); -// } catch (Exception e) { -// noError=false; -// } -// assertTrue(noError); -// } -// -// @Test -// public void eval_randomString() throws Exception { -// assertTrue(cli.eval("Some random string @#&*& to check complete 100 coverage")); -// } - -// public static AAFcli getAAfCli() throws APIException, LocatorException, GeneralSecurityException, IOException { -// final AuthzEnv env = new AuthzEnv(System.getProperties()); -// String aafUrl = "https://DME2RESOLVE"; -// SecurityInfo si = new SecurityInfo(env); -// env.loadToSystemPropsStartsWith("AAF", "DME2"); -// Locator loc; -// loc = new PropertyLocator(aafUrl); -// TIMEOUT = Integer.parseInt(env.getProperty(Config.AAF_CONN_TIMEOUT, Config.AAF_CONN_TIMEOUT_DEF)); -// HMangr hman = new HMangr(env, loc).readTimeout(TIMEOUT).apiVersion("2.0"); -// -// // TODO: Consider requiring a default in properties -// env.setProperty(Config.AAF_DEFAULT_REALM, -// System.getProperty(Config.AAF_DEFAULT_REALM, Config.getDefaultRealm())); -// HBasicAuthSS ss = mock(HBasicAuthSS.class); -// //TODO: Gabe[JUnit] constructor issue -// return new AAFcli(env, new OutputStreamWriter(System.out), hman, si, ss); -// } + @BeforeClass + public static void setUp() throws Exception, Exception { + cli = getAAfCli(); + } + + @Test + public void eval() throws Exception { + assertTrue(cli.eval("#startswith")); + } + + @Test + public void eval_empty() throws Exception { + assertTrue(cli.eval("")); + } + + @Test + public void eval1() throws Exception { + assertTrue(cli.eval("@[123")); + } + + @Test + public void eval2() throws Exception { + assertFalse(cli.eval("as @[ 123")); + } + + @Test + public void eval3() throws Exception { + try { + cli.eval("expect @[ 123"); + } catch (Exception e) { + // TODO Auto-generated catch block + assertTrue(e instanceof CadiException); + } + } + + public void eval31() throws Exception { + try { + cli.eval("expect 1 @[ 123"); + } catch (Exception e) { + // TODO Auto-generated catch block + assertTrue(e instanceof CadiException); + } + } + + @Test + public void eval4() throws Exception { + try { + cli.eval("sleep @[ 123"); + } catch (Exception e) { + assertTrue(e instanceof NumberFormatException); + } + } + + @Test + public void eval41() throws Exception { + assertTrue(cli.eval("sleep 1 @[ 123")); + } + + @Test + public void eval5() throws Exception { + try { + cli.eval("delay @[ 123"); + } catch (Exception e) { + assertTrue(e instanceof NumberFormatException); + } + } + + @Test + public void eval51() throws Exception { + assertTrue(cli.eval("delay 1 @[ 123")); + } + + @Test + public void eval7() throws Exception { + assertFalse(cli.eval("exit @[ 123")); + } + + @Test + public void eval8() throws Exception { + assertTrue(cli.eval("REQUEST @[ 123")); + } + + @Test + public void eval9() throws Exception { + assertTrue(cli.eval("FORCE @[ 123")); + } + + @Test + public void eval10() throws Exception { + assertTrue(cli.eval("set @[ 123")); + } + + @Test + public void keyboardHelp() throws Exception { + boolean noError=true; + try { + cli.keyboardHelp(); + } catch (Exception e) { + noError=false; + } + assertTrue(noError); + } + + + + @Test + public void setProp() throws Exception { + boolean noError=true; + try { + cli.keyboardHelp(); + } catch (Exception e) { + noError=false; + } + assertTrue(noError); + } + + @Test + public void eval_randomString() throws Exception { + assertTrue(cli.eval("Some random string @#&*& to check complete 100 coverage")); + } + + public static AAFcli getAAfCli() throws APIException, LocatorException, GeneralSecurityException, IOException { + final AuthzEnv env = new AuthzEnv(System.getProperties()); + String aafUrl = "https://DME2RESOLVE"; + SecurityInfoC<HttpURLConnection> si = mock(SecurityInfoC.class); + env.loadToSystemPropsStartsWith("AAF", "DME2"); + Locator loc; + loc = new PropertyLocator(aafUrl); + TIMEOUT = Integer.parseInt(env.getProperty(Config.AAF_CONN_TIMEOUT, Config.AAF_CONN_TIMEOUT_DEF)); + HMangr hman = new HMangr(env, loc).readTimeout(TIMEOUT).apiVersion("2.0"); + + // TODO: Consider requiring a default in properties + env.setProperty(Config.AAF_DEFAULT_REALM, + System.getProperty(Config.AAF_DEFAULT_REALM, Config.getDefaultRealm())); + + HBasicAuthSS ss = mock(HBasicAuthSS.class); + env.setProperty(Config.AAF_APPPASS, "test"); + return new AAFcli(env, new OutputStreamWriter(System.out), hman, si, ss); + } + + @Test + public void testVerbose() { + cli.verbose(true); + cli.verbose(false); + } + + @Test + public void testClose() { + cli.close(); + } - @Test //TODO: Temporary fix AAF-111 - public void netYetTested() { - assertTrue(true); + @Test + public void testTimeout() { + Assert.assertNotNull(cli.timeout()); } + + @Test + public void testMain() { + String[] str = {"test"}; + //cli.main(str); + } + + @Test + public void testTest() { + Assert.assertNotNull(cli.isTest()); + } + + @Test + public void testIsDetailed() { + Assert.assertNotNull(cli.isDetailed()); + } + + @Test + public void testAddRequest() { + Assert.assertNotNull(cli.addRequest()); + } + + @Test + public void testForceString() { + cli.clearSingleLineProperties(); + Assert.assertNull(cli.forceString()); + } + + @Test + public void testClearSingleLineProperties() { + cli.clearSingleLineProperties(); + } + + @Test + public void testGui() { + cli.gui(true); + cli.gui(false); + } + } diff --git a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/ns/JU_List.java b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/ns/JU_List.java new file mode 100644 index 00000000..99ad284b --- /dev/null +++ b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/ns/JU_List.java @@ -0,0 +1,82 @@ +/** + * ============LICENSE_START==================================================== + * org.onap.aaf + * =========================================================================== + * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * =========================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END==================================================== + * + */ +package org.onap.aaf.auth.cmd.test.ns; + +import static org.junit.Assert.*; + +import java.io.Writer; +import java.net.URI; + +import org.onap.aaf.auth.cmd.ns.List; +import org.onap.aaf.auth.cmd.ns.NS; +import org.onap.aaf.auth.env.AuthzEnv; +import org.onap.aaf.cadi.Locator; +import org.onap.aaf.cadi.LocatorException; +import org.onap.aaf.cadi.PropAccess; +import org.onap.aaf.cadi.SecuritySetter; +import org.onap.aaf.cadi.client.Future; +import org.onap.aaf.cadi.config.SecurityInfoC; +import org.onap.aaf.cadi.http.HMangr; +import org.onap.aaf.misc.env.APIException; + +import aaf.v2_0.Nss; + +import org.onap.aaf.auth.cmd.AAFcli; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import static org.mockito.Mockito.*; + +import org.junit.Test; + +public class JU_List { + + List list; + + @Before + public void setUp() throws APIException, LocatorException { + PropAccess prop = new PropAccess(); + AuthzEnv aEnv = new AuthzEnv(); + Writer wtr = mock(Writer.class); + Locator loc = mock(Locator.class); + HMangr hman = new HMangr(aEnv, loc); + AAFcli aafcli = new AAFcli(prop, aEnv, wtr, hman, null, null); + NS ns = new NS(aafcli); + + list = new List(ns); + } + + @Test + public void testReport() { + Future<Nss> fu = mock(Future.class); + Nss.Ns nss = new Nss.Ns(); + Nss ns = new Nss(); + fu.value = ns; + fu.value.getNs(); + System.out.print(fu.value.getNs()); + + list.report(null, "test"); + list.report(fu, "test"); + } + +} diff --git a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/ns/JU_ListUsersWithPerm.java b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/ns/JU_ListUsersWithPerm.java index 15e033c6..b8e83e6c 100644 --- a/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/ns/JU_ListUsersWithPerm.java +++ b/auth/auth-cmd/src/test/java/org/onap/aaf/auth/cmd/test/ns/JU_ListUsersWithPerm.java @@ -39,36 +39,37 @@ import org.onap.aaf.auth.cmd.test.JU_AAFCli; @RunWith(MockitoJUnitRunner.class) public class JU_ListUsersWithPerm { -// private static ListUsersWithPerm lsUserWithPerm; -// -// @BeforeClass -// public static void setUp() throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { -// AAFcli cli = JU_AAFCli.getAAfCli(); -// NS ns = new NS(cli); -// List ls = new List(ns);//possible wrong import, remove import org.onap.aaf.auth.cmd.ns to see other option -// ListUsers lsU = new ListUsers(ls); -// lsUserWithPerm = new ListUsersWithPerm(lsU); -// } -// -// @Test -// public void exec() { -// try { -// assertEquals(lsUserWithPerm._exec(0, "add", "del", "reset", "extend"), 500); -// } catch (Exception e) { -// assertEquals(e.getMessage(), "java.net.UnknownHostException: DME2RESOLVE"); -// } -// } -// -// @Test -// public void detailedHelp() { -// boolean hasNoError = true; -// try { -// lsUserWithPerm.detailedHelp(1, new StringBuilder("test")); -// } catch (Exception e) { -// hasNoError = false; -// } -// assertEquals(hasNoError, true); -// } + private static ListUsersWithPerm lsUserWithPerm; + + @BeforeClass + public static void setUp() throws NoSuchFieldException, SecurityException, Exception, IllegalAccessException { + AAFcli cli = JU_AAFCli.getAAfCli(); + NS ns = new NS(cli); + List ls = new List(ns);//possible wrong import, remove import org.onap.aaf.auth.cmd.ns to see other option + ListUsers lsU = new ListUsers(ls); + lsUserWithPerm = new ListUsersWithPerm(lsU); + } + + @Test + public void exec() { + try { + assertEquals(lsUserWithPerm._exec(0, "add", "del", "reset", "extend"), 500); + } catch (Exception e) { + assertEquals(e.getMessage(), "No Services Found for https://DME2RESOLVE [ ]"); + + } + } + + @Test + public void detailedHelp() { + boolean hasNoError = true; + try { + lsUserWithPerm.detailedHelp(1, new StringBuilder("test")); + } catch (Exception e) { + hasNoError = false; + } + assertEquals(hasNoError, true); + } @Test //TODO: Temporary fix AAF-111 public void netYetTested() { |