Update AAF Version 1.0.0
[aaf/authz.git] / authz-cmd / src / test / java / com / att / 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 com.att.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 \r
38 import com.att.authz.env.AuthzEnv;\r
39 import com.att.cadi.Locator;\r
40 import com.att.cadi.LocatorException;\r
41 import com.att.cadi.client.PropertyLocator;\r
42 import com.att.cadi.config.Config;\r
43 import com.att.cadi.config.SecurityInfo;\r
44 import com.att.cadi.http.HBasicAuthSS;\r
45 import com.att.cadi.http.HMangr;\r
46 import com.att.inno.env.APIException;\r
47 \r
48 @RunWith(MockitoJUnitRunner.class)\r
49 public class JU_AAFCli {\r
50         \r
51         private static AAFcli cli;\r
52         private static int TIMEOUT = Integer.parseInt(Config.AAF_CONN_TIMEOUT_DEF);\r
53         \r
54         @BeforeClass\r
55         public static void setUp() throws Exception, Exception {\r
56                 cli = getAAfCli();\r
57         }\r
58         \r
59         @Test\r
60         public void eval() throws Exception {\r
61                 assertTrue(cli.eval("#startswith"));\r
62         }\r
63         \r
64         @Test\r
65         public void eval_empty() throws Exception{\r
66                 assertTrue(cli.eval(""));\r
67         }\r
68         \r
69         @Test\r
70         public void eval_randomString() throws Exception {\r
71                 assertTrue(cli.eval("Some random string @#&*& to check complete 100 coverage"));\r
72         }\r
73         \r
74         public static AAFcli getAAfCli() throws APIException, LocatorException, GeneralSecurityException, IOException {\r
75                 final AuthzEnv env = new AuthzEnv(System.getProperties());\r
76                 String aafUrl = "https://DME2RESOLVE";\r
77                 SecurityInfo si = new SecurityInfo(env);\r
78                 env.loadToSystemPropsStartsWith("AAF", "DME2");\r
79                 Locator loc;\r
80                 loc = new PropertyLocator(aafUrl);                                              \r
81                 TIMEOUT = Integer.parseInt(env.getProperty(Config.AAF_CONN_TIMEOUT, Config.AAF_CONN_TIMEOUT_DEF));\r
82                 HMangr hman = new HMangr(env, loc).readTimeout(TIMEOUT).apiVersion("2.0");\r
83                 \r
84                 //TODO: Consider requiring a default in properties\r
85                 env.setProperty(Config.AAF_DEFAULT_REALM, System.getProperty(Config.AAF_DEFAULT_REALM,Config.getDefaultRealm()));\r
86                 HBasicAuthSS ss = mock(HBasicAuthSS.class);\r
87                 return new AAFcli(env, new OutputStreamWriter(System.out), hman, si, ss);\r
88         }\r
89 }\r