Update project structure to org.onap.aaf
[aaf/authz.git] / authz-cmd / src / test / java / org / onap / aaf / cmd / JU_AAFCli.java
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
new file mode 100644 (file)
index 0000000..6a970ce
--- /dev/null
@@ -0,0 +1,90 @@
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aaf\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * ===========================================================================\r
+ * * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * * you may not use this file except in compliance with the License.\r
+ * * You may obtain a copy of the License at\r
+ * * \r
+ *  *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * * \r
+ *  * Unless required by applicable law or agreed to in writing, software\r
+ * * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * * See the License for the specific language governing permissions and\r
+ * * limitations under the License.\r
+ * * ============LICENSE_END====================================================\r
+ * *\r
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package org.onap.aaf.cmd;\r
+\r
+import static org.junit.Assert.assertTrue;\r
+import static org.mockito.Mockito.mock;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStreamWriter;\r
+import java.net.HttpURLConnection;\r
+import java.security.GeneralSecurityException;\r
+\r
+import org.junit.BeforeClass;\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+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.Locator;\r
+import org.onap.aaf.cadi.LocatorException;\r
+import org.onap.aaf.cadi.client.PropertyLocator;\r
+import org.onap.aaf.cadi.config.Config;\r
+import org.onap.aaf.cadi.config.SecurityInfo;\r
+import org.onap.aaf.cadi.http.HBasicAuthSS;\r
+import org.onap.aaf.cadi.http.HMangr;\r
+import org.onap.aaf.inno.env.APIException;\r
+\r
+@RunWith(MockitoJUnitRunner.class)\r
+public class JU_AAFCli {\r
+       \r
+       private static AAFcli cli;\r
+       private static int TIMEOUT = Integer.parseInt(Config.AAF_CONN_TIMEOUT_DEF);\r
+       \r
+       @BeforeClass\r
+       public static void setUp() throws Exception, Exception {\r
+               cli = getAAfCli();\r
+       }\r
+       \r
+       @Test\r
+       public void eval() throws Exception {\r
+               assertTrue(cli.eval("#startswith"));\r
+       }\r
+       \r
+       @Test\r
+       public void eval_empty() throws Exception{\r
+               assertTrue(cli.eval(""));\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
+       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
+               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
+               HBasicAuthSS ss = mock(HBasicAuthSS.class);\r
+               return new AAFcli(env, new OutputStreamWriter(System.out), hman, si, ss);\r
+       }\r
+}\r