X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=authz-cmd%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faaf%2Fcmd%2FJU_AAFCli.java;h=f005738785b23070cce46380e50e16ce923c0601;hb=4ccc6b830291f15b8006fdee37a8aae21c22f9df;hp=6a970ce05a422c3a27e6539c7134c71937134514;hpb=0be0e0671b12c9b218023e505f3aec74fc8c8e4f;p=aaf%2Fauthz.git diff --git a/authz-cmd/src/test/java/org/onap/aaf/cmd/JU_AAFCli.java b/authz-cmd/src/test/java/org/onap/aaf/cmd/JU_AAFCli.java index 6a970ce0..f0057387 100644 --- a/authz-cmd/src/test/java/org/onap/aaf/cmd/JU_AAFCli.java +++ b/authz-cmd/src/test/java/org/onap/aaf/cmd/JU_AAFCli.java @@ -22,6 +22,7 @@ ******************************************************************************/ package org.onap.aaf.cmd; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; @@ -36,7 +37,7 @@ import org.junit.runner.RunWith; import org.mockito.runners.MockitoJUnitRunner; import org.onap.aaf.authz.env.AuthzEnv; import org.onap.aaf.cmd.AAFcli; - +import org.onap.aaf.cadi.CadiException; import org.onap.aaf.cadi.Locator; import org.onap.aaf.cadi.LocatorException; import org.onap.aaf.cadi.client.PropertyLocator; @@ -48,42 +49,144 @@ import org.onap.aaf.inno.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{ + 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); + 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())); + + // 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); return new AAFcli(env, new OutputStreamWriter(System.out), hman, si, ss); }