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