6a970ce05a422c3a27e6539c7134c71937134514
[aaf/authz.git] / authz-cmd / src / test / java / org / onap / aaf / cmd / JU_AAFCli.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aaf\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
10  * * \r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * * \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
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 package org.onap.aaf.cmd;\r
24 \r
25 import static org.junit.Assert.assertTrue;\r
26 import static org.mockito.Mockito.mock;\r
27 \r
28 import java.io.IOException;\r
29 import java.io.OutputStreamWriter;\r
30 import java.net.HttpURLConnection;\r
31 import java.security.GeneralSecurityException;\r
32 \r
33 import org.junit.BeforeClass;\r
34 import org.junit.Test;\r
35 import org.junit.runner.RunWith;\r
36 import org.mockito.runners.MockitoJUnitRunner;\r
37 import org.onap.aaf.authz.env.AuthzEnv;\r
38 import org.onap.aaf.cmd.AAFcli;\r
39 \r
40 import org.onap.aaf.cadi.Locator;\r
41 import org.onap.aaf.cadi.LocatorException;\r
42 import org.onap.aaf.cadi.client.PropertyLocator;\r
43 import org.onap.aaf.cadi.config.Config;\r
44 import org.onap.aaf.cadi.config.SecurityInfo;\r
45 import org.onap.aaf.cadi.http.HBasicAuthSS;\r
46 import org.onap.aaf.cadi.http.HMangr;\r
47 import org.onap.aaf.inno.env.APIException;\r
48 \r
49 @RunWith(MockitoJUnitRunner.class)\r
50 public class JU_AAFCli {\r
51         \r
52         private static AAFcli cli;\r
53         private static int TIMEOUT = Integer.parseInt(Config.AAF_CONN_TIMEOUT_DEF);\r
54         \r
55         @BeforeClass\r
56         public static void setUp() throws Exception, Exception {\r
57                 cli = getAAfCli();\r
58         }\r
59         \r
60         @Test\r
61         public void eval() throws Exception {\r
62                 assertTrue(cli.eval("#startswith"));\r
63         }\r
64         \r
65         @Test\r
66         public void eval_empty() throws Exception{\r
67                 assertTrue(cli.eval(""));\r
68         }\r
69         \r
70         @Test\r
71         public void eval_randomString() throws Exception {\r
72                 assertTrue(cli.eval("Some random string @#&*& to check complete 100 coverage"));\r
73         }\r
74         \r
75         public static AAFcli getAAfCli() throws APIException, LocatorException, GeneralSecurityException, IOException {\r
76                 final AuthzEnv env = new AuthzEnv(System.getProperties());\r
77                 String aafUrl = "https://DME2RESOLVE";\r
78                 SecurityInfo si = new SecurityInfo(env);\r
79                 env.loadToSystemPropsStartsWith("AAF", "DME2");\r
80                 Locator loc;\r
81                 loc = new PropertyLocator(aafUrl);                                              \r
82                 TIMEOUT = Integer.parseInt(env.getProperty(Config.AAF_CONN_TIMEOUT, Config.AAF_CONN_TIMEOUT_DEF));\r
83                 HMangr hman = new HMangr(env, loc).readTimeout(TIMEOUT).apiVersion("2.0");\r
84                 \r
85                 //TODO: Consider requiring a default in properties\r
86                 env.setProperty(Config.AAF_DEFAULT_REALM, System.getProperty(Config.AAF_DEFAULT_REALM,Config.getDefaultRealm()));\r
87                 HBasicAuthSS ss = mock(HBasicAuthSS.class);\r
88                 return new AAFcli(env, new OutputStreamWriter(System.out), hman, si, ss);\r
89         }\r
90 }\r