Improve code coverage for aaf authz modules
[aaf/authz.git] / authz-cmd / src / test / java / org / onap / aaf / cmd / JU_AAFCli.java
index 6a970ce..f005738 100644 (file)
@@ -22,6 +22,7 @@
  ******************************************************************************/\r
 package org.onap.aaf.cmd;\r
 \r
+import static org.junit.Assert.assertFalse;\r
 import static org.junit.Assert.assertTrue;\r
 import static org.mockito.Mockito.mock;\r
 \r
@@ -36,7 +37,7 @@ import org.junit.runner.RunWith;
 import org.mockito.runners.MockitoJUnitRunner;\r
 import org.onap.aaf.authz.env.AuthzEnv;\r
 import org.onap.aaf.cmd.AAFcli;\r
-\r
+import org.onap.aaf.cadi.CadiException;\r
 import org.onap.aaf.cadi.Locator;\r
 import org.onap.aaf.cadi.LocatorException;\r
 import org.onap.aaf.cadi.client.PropertyLocator;\r
@@ -48,42 +49,144 @@ import org.onap.aaf.inno.env.APIException;
 \r
 @RunWith(MockitoJUnitRunner.class)\r
 public class JU_AAFCli {\r
-       \r
+\r
        private static AAFcli cli;\r
        private static int TIMEOUT = Integer.parseInt(Config.AAF_CONN_TIMEOUT_DEF);\r
-       \r
+\r
        @BeforeClass\r
        public static void setUp() throws Exception, Exception {\r
                cli = getAAfCli();\r
        }\r
-       \r
+\r
        @Test\r
        public void eval() throws Exception {\r
                assertTrue(cli.eval("#startswith"));\r
        }\r
-       \r
+\r
        @Test\r
-       public void eval_empty() throws Exception{\r
+       public void eval_empty() throws Exception {\r
                assertTrue(cli.eval(""));\r
        }\r
+\r
+       @Test\r
+       public void eval1() throws Exception {\r
+               assertTrue(cli.eval("@[123"));\r
+       }\r
+\r
+       @Test\r
+       public void eval2() throws Exception {\r
+               assertFalse(cli.eval("as @[ 123"));\r
+       }\r
+\r
+       @Test\r
+       public void eval3() throws Exception {\r
+               try {\r
+                       cli.eval("expect @[ 123");\r
+               } catch (Exception e) {\r
+                       // TODO Auto-generated catch block\r
+                       assertTrue(e instanceof CadiException);\r
+               }\r
+       }\r
+\r
+       public void eval31() throws Exception {\r
+               try {\r
+                       cli.eval("expect 1 @[ 123");\r
+               } catch (Exception e) {\r
+                       // TODO Auto-generated catch block\r
+                       assertTrue(e instanceof CadiException);\r
+               }\r
+       }\r
+\r
+       @Test\r
+       public void eval4() throws Exception {\r
+               try {\r
+                       cli.eval("sleep @[ 123");\r
+               } catch (Exception e) {\r
+                       assertTrue(e instanceof NumberFormatException);\r
+               }\r
+       }\r
+\r
+       @Test\r
+       public void eval41() throws Exception {\r
+               assertTrue(cli.eval("sleep 1 @[ 123"));\r
+       }\r
+\r
+       @Test\r
+       public void eval5() throws Exception {\r
+               try {\r
+                       cli.eval("delay @[ 123");\r
+               } catch (Exception e) {\r
+                       assertTrue(e instanceof NumberFormatException);\r
+               }\r
+       }\r
+\r
+       @Test\r
+       public void eval51() throws Exception {\r
+               assertTrue(cli.eval("delay 1 @[ 123"));\r
+       }\r
+\r
+       @Test\r
+       public void eval7() throws Exception {\r
+               assertFalse(cli.eval("exit @[ 123"));\r
+       }\r
+\r
+       @Test\r
+       public void eval8() throws Exception {\r
+               assertTrue(cli.eval("REQUEST @[ 123"));\r
+       }\r
+\r
+       @Test\r
+       public void eval9() throws Exception {\r
+               assertTrue(cli.eval("FORCE @[ 123"));\r
+       }\r
+\r
+       @Test\r
+       public void eval10() throws Exception {\r
+               assertTrue(cli.eval("set @[ 123"));\r
+       }\r
+\r
+       @Test\r
+       public void keyboardHelp() throws Exception {\r
+               boolean noError=true;\r
+               try {\r
+                       cli.keyboardHelp();\r
+               } catch (Exception e) {\r
+                       noError=false;\r
+               }\r
+               assertTrue(noError);\r
+       }\r
+       \r
+\r
+       \r
+       @Test\r
+       public void setProp() throws Exception {\r
+               boolean noError=true;\r
+               try {\r
+                       cli.keyboardHelp();\r
+               } catch (Exception e) {\r
+                       noError=false;\r
+               }\r
+               assertTrue(noError);\r
+       }\r
        \r
        @Test\r
        public void eval_randomString() throws Exception {\r
                assertTrue(cli.eval("Some random string @#&*& to check complete 100 coverage"));\r
        }\r
-       \r
+\r
        public static AAFcli getAAfCli() throws APIException, LocatorException, GeneralSecurityException, IOException {\r
                final AuthzEnv env = new AuthzEnv(System.getProperties());\r
                String aafUrl = "https://DME2RESOLVE";\r
                SecurityInfo si = new SecurityInfo(env);\r
                env.loadToSystemPropsStartsWith("AAF", "DME2");\r
                Locator loc;\r
-               loc = new PropertyLocator(aafUrl);                                              \r
+               loc = new PropertyLocator(aafUrl);\r
                TIMEOUT = Integer.parseInt(env.getProperty(Config.AAF_CONN_TIMEOUT, Config.AAF_CONN_TIMEOUT_DEF));\r
                HMangr hman = new HMangr(env, loc).readTimeout(TIMEOUT).apiVersion("2.0");\r
-               \r
-               //TODO: Consider requiring a default in properties\r
-               env.setProperty(Config.AAF_DEFAULT_REALM, System.getProperty(Config.AAF_DEFAULT_REALM,Config.getDefaultRealm()));\r
+\r
+               // TODO: Consider requiring a default in properties\r
+               env.setProperty(Config.AAF_DEFAULT_REALM,\r
+                               System.getProperty(Config.AAF_DEFAULT_REALM, Config.getDefaultRealm()));\r
                HBasicAuthSS ss = mock(HBasicAuthSS.class);\r
                return new AAFcli(env, new OutputStreamWriter(System.out), hman, si, ss);\r
        }\r