f3d721cefcfae4a63e408c98ca6843141335a5eb
[aaf/authz.git] / authz-cmd / src / test / java / com / att / cmd / JU_AAFCli.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aai\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * Copyright © 2017 Amdocs\r
7  * * ===========================================================================\r
8  * * Licensed under the Apache License, Version 2.0 (the "License");\r
9  * * you may not use this file except in compliance with the License.\r
10  * * You may obtain a copy of the License at\r
11  * * \r
12  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
13  * * \r
14  *  * Unless required by applicable law or agreed to in writing, software\r
15  * * distributed under the License is distributed on an "AS IS" BASIS,\r
16  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * * See the License for the specific language governing permissions and\r
18  * * limitations under the License.\r
19  * * ============LICENSE_END====================================================\r
20  * *\r
21  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
22  * *\r
23  ******************************************************************************/\r
24 package com.att.cmd;\r
25 \r
26 import static org.junit.Assert.assertTrue;\r
27 import static org.mockito.Mockito.mock;\r
28 \r
29 import java.io.IOException;\r
30 import java.io.OutputStreamWriter;\r
31 import java.net.HttpURLConnection;\r
32 import java.security.GeneralSecurityException;\r
33 \r
34 import org.junit.BeforeClass;\r
35 import org.junit.Test;\r
36 import org.junit.runner.RunWith;\r
37 import org.mockito.runners.MockitoJUnitRunner;\r
38 \r
39 import com.att.authz.env.AuthzEnv;\r
40 import com.att.cadi.Locator;\r
41 import com.att.cadi.LocatorException;\r
42 import com.att.cadi.client.PropertyLocator;\r
43 import com.att.cadi.config.Config;\r
44 import com.att.cadi.config.SecurityInfo;\r
45 import com.att.cadi.http.HBasicAuthSS;\r
46 import com.att.cadi.http.HMangr;\r
47 import com.att.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