Update project structure for aaf/cadi
[aaf/cadi.git] / aaf / src / test / java / org / onap / aaf / cadi / lur / aaf / test / JU_JMeter.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.cadi.lur.aaf.test;\r
24 \r
25 import java.io.BufferedReader;\r
26 import java.io.File;\r
27 import java.io.FileReader;\r
28 import java.io.PrintWriter;\r
29 import java.io.StringWriter;\r
30 import java.net.HttpURLConnection;\r
31 import java.security.Principal;\r
32 import java.util.ArrayList;\r
33 import java.util.List;\r
34 import java.util.Properties;\r
35 \r
36 import org.junit.BeforeClass;\r
37 import org.junit.Test;\r
38 import org.onap.aaf.cadi.Permission;\r
39 import org.onap.aaf.cadi.PropAccess;\r
40 import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn;\r
41 import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp;\r
42 import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm;\r
43 import org.onap.aaf.cadi.aaf.v2_0.AAFTaf;\r
44 import org.onap.aaf.cadi.config.Config;\r
45 import org.onap.aaf.cadi.locator.DNSLocator;\r
46 import org.onap.aaf.cadi.principal.CachedBasicPrincipal;\r
47 \r
48 import junit.framework.Assert;\r
49 \r
50 public class JU_JMeter {\r
51         private static AAFConHttp aaf;\r
52         private static AAFAuthn<HttpURLConnection> aafAuthn;\r
53         private static AAFLurPerm aafLur;\r
54         private static ArrayList<Principal> perfIDs;\r
55         \r
56         private static AAFTaf<HttpURLConnection> aafTaf;\r
57         private static PropAccess access;\r
58 \r
59         @BeforeClass\r
60         public static void before() throws Exception {\r
61                 if(aafLur==null) {\r
62                         Properties props = System.getProperties();\r
63                         props.setProperty("AFT_LATITUDE", "32.780140");\r
64                         props.setProperty("AFT_LONGITUDE", "-96.800451");\r
65                         props.setProperty("DME2_EP_REGISTRY_CLASS","DME2FS");\r
66                         props.setProperty("AFT_DME2_EP_REGISTRY_FS_DIR","/Volumes/Data/src/authz/dme2reg");\r
67                         props.setProperty("AFT_ENVIRONMENT", "AFTUAT");\r
68                         props.setProperty("SCLD_PLATFORM", "NON-PROD");\r
69                         props.setProperty(Config.AAF_URL,"https://DME2RESOLVE/service=com.att.authz.AuthorizationService/version=2.0/envContext=DEV/routeOffer=BAU_SE");\r
70                         props.setProperty(Config.AAF_READ_TIMEOUT, "2000");\r
71                         int timeToLive = 3000;\r
72                         props.setProperty(Config.AAF_CLEAN_INTERVAL, Integer.toString(timeToLive));\r
73                         props.setProperty(Config.AAF_HIGH_COUNT, "4");\r
74 \r
75                         String aafPerfIDs = props.getProperty("AAF_PERF_IDS");\r
76                         perfIDs = new ArrayList<Principal>();\r
77                         File perfFile = null;\r
78                         if(aafPerfIDs!=null) {\r
79                                 perfFile = new File(aafPerfIDs);\r
80                         }\r
81 \r
82                         access = new PropAccess();\r
83                         aaf = new AAFConHttp(access, new DNSLocator(access,"https","localhost","8100"));\r
84                         aafTaf = new AAFTaf<HttpURLConnection>(aaf,false);\r
85                         aafLur = aaf.newLur(aafTaf);\r
86                         aafAuthn = aaf.newAuthn(aafTaf);\r
87                         aaf.basicAuth("testid@aaf.att.com", "whatever");\r
88 \r
89                         if(perfFile==null||!perfFile.exists()) {\r
90                                 perfIDs.add(new CachedBasicPrincipal(aafTaf, \r
91                                                 "Basic dGVzdGlkOndoYXRldmVy", \r
92                                                 "aaf.att.com",timeToLive));\r
93                                 perfIDs.add(new Princ("ab1234@aaf.att.com")); // Example of Local ID, which isn't looked up\r
94                         } else {\r
95                                 BufferedReader ir = new BufferedReader(new FileReader(perfFile));\r
96                                 try {\r
97                                         String line;\r
98                                         while((line = ir.readLine())!=null) {\r
99                                                 if((line=line.trim()).length()>0)\r
100                                                         perfIDs.add(new Princ(line));\r
101                                         }\r
102                                 } finally {\r
103                                         ir.close();\r
104                                 }\r
105                         }\r
106                         Assert.assertNotNull(aafLur);\r
107                 }\r
108         }\r
109 \r
110         private static class Princ implements Principal {\r
111                 private String name;\r
112                 public Princ(String name) {\r
113                         this.name = name;\r
114                 }\r
115                 public String getName() {\r
116                         return name;\r
117                 }\r
118                 \r
119         };\r
120         \r
121         private static int index = -1;\r
122         \r
123         private synchronized Principal getIndex() {\r
124                 if(perfIDs.size()<=++index)index=0;\r
125                 return perfIDs.get(index);\r
126         }\r
127         @Test\r
128         public void test() {\r
129                 try {\r
130                                 aafAuthn.validate("testid@aaf.att.com", "whatever");\r
131                                 List<Permission> perms = new ArrayList<Permission>();\r
132                                 aafLur.fishAll(getIndex(), perms);\r
133 //                              Assert.assertFalse(perms.isEmpty());\r
134 //                              for(Permission p : perms) {\r
135 //                                      //access.log(Access.Level.AUDIT, p.permType());\r
136 //                              }\r
137                 } catch (Exception e) {\r
138                         StringWriter sw = new StringWriter();\r
139                         e.printStackTrace(new PrintWriter(sw));\r
140                         Assert.assertFalse(sw.toString(),true);\r
141                 }\r
142         }\r
143 \r
144 }\r