AT&T 2.0.19 Code drop, stage 2
[aaf/authz.git] / cadi / aaf / src / test / java / org / onap / aaf / cadi / lur / aaf / test / JU_JMeter.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
4  * * ===========================================================================
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * * ===========================================================================
7  * * Licensed under the Apache License, Version 2.0 (the "License");
8  * * you may not use this file except in compliance with the License.
9  * * You may obtain a copy of the License at
10  * * 
11  *  *      http://www.apache.org/licenses/LICENSE-2.0
12  * * 
13  *  * Unless required by applicable law or agreed to in writing, software
14  * * distributed under the License is distributed on an "AS IS" BASIS,
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * * See the License for the specific language governing permissions and
17  * * limitations under the License.
18  * * ============LICENSE_END====================================================
19  * *
20  * *
21  ******************************************************************************/
22 package org.onap.aaf.cadi.lur.aaf.test;
23
24 import java.io.BufferedReader;
25 import java.io.File;
26 import java.io.FileReader;
27 import java.io.PrintWriter;
28 import java.io.StringWriter;
29 import java.net.HttpURLConnection;
30 import java.security.Principal;
31 import java.util.ArrayList;
32 import java.util.List;
33 import java.util.Properties;
34
35 import org.junit.BeforeClass;
36 import org.junit.Test;
37 import org.onap.aaf.cadi.Permission;
38 import org.onap.aaf.cadi.PropAccess;
39 import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn;
40 import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp;
41 import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm;
42 import org.onap.aaf.cadi.aaf.v2_0.AAFTaf;
43 import org.onap.aaf.cadi.config.Config;
44 import org.onap.aaf.cadi.locator.DNSLocator;
45 import org.onap.aaf.cadi.principal.CachedBasicPrincipal;
46
47 import junit.framework.Assert;
48
49 public class JU_JMeter {
50         private static AAFConHttp aaf;
51         private static AAFAuthn<HttpURLConnection> aafAuthn;
52         private static AAFLurPerm aafLur;
53         private static ArrayList<Principal> perfIDs;
54         
55         private static AAFTaf<HttpURLConnection> aafTaf;
56         private static PropAccess access;
57
58         @BeforeClass
59         public static void before() throws Exception {
60                 if(aafLur==null) {
61                         Properties props = System.getProperties();
62                         props.setProperty("AFT_LATITUDE", "32.780140");
63                         props.setProperty("AFT_LONGITUDE", "-96.800451");
64                         props.setProperty("DME2_EP_REGISTRY_CLASS","DME2FS");
65                         props.setProperty("AFT_DME2_EP_REGISTRY_FS_DIR","/Volumes/Data/src/authz/dme2reg");
66                         props.setProperty("AFT_ENVIRONMENT", "AFTUAT");
67                         props.setProperty("SCLD_PLATFORM", "NON-PROD");
68                         props.setProperty(Config.AAF_URL,"https://DME2RESOLVE/service=com.att.authz.AuthorizationService/version=2.0/envContext=DEV/routeOffer=BAU_SE");
69                         props.setProperty(Config.AAF_CALL_TIMEOUT, "2000");
70                         int timeToLive = 3000;
71                         props.setProperty(Config.AAF_CLEAN_INTERVAL, Integer.toString(timeToLive));
72                         props.setProperty(Config.AAF_HIGH_COUNT, "4");
73
74                         String aafPerfIDs = props.getProperty("AAF_PERF_IDS");
75                         perfIDs = new ArrayList<Principal>();
76                         File perfFile = null;
77                         if(aafPerfIDs!=null) {
78                                 perfFile = new File(aafPerfIDs);
79                         }
80
81                         access = new PropAccess();
82                         aaf = new AAFConHttp(access, new DNSLocator(access,"https","localhost","8100"));
83                         aafTaf = new AAFTaf<HttpURLConnection>(aaf,false);
84                         aafLur = aaf.newLur(aafTaf);
85                         aafAuthn = aaf.newAuthn(aafTaf);
86                         aaf.basicAuth("testid@aaf.att.com", "whatever");
87
88                         if(perfFile==null||!perfFile.exists()) {
89                                 perfIDs.add(new CachedBasicPrincipal(aafTaf, 
90                                                 "Basic dGVzdGlkOndoYXRldmVy", 
91                                                 "aaf.att.com",timeToLive));
92                                 perfIDs.add(new Princ("ab1234@aaf.att.com")); // Example of Local ID, which isn't looked up
93                         } else {
94                                 BufferedReader ir = new BufferedReader(new FileReader(perfFile));
95                                 try {
96                                         String line;
97                                         while((line = ir.readLine())!=null) {
98                                                 if((line=line.trim()).length()>0)
99                                                         perfIDs.add(new Princ(line));
100                                         }
101                                 } finally {
102                                         ir.close();
103                                 }
104                         }
105                         Assert.assertNotNull(aafLur);
106                 }
107         }
108
109         private static class Princ implements Principal {
110                 private String name;
111                 public Princ(String name) {
112                         this.name = name;
113                 }
114                 public String getName() {
115                         return name;
116                 }
117                 
118         };
119         
120         private static int index = -1;
121         
122         private synchronized Principal getIndex() {
123                 if(perfIDs.size()<=++index)index=0;
124                 return perfIDs.get(index);
125         }
126         @Test
127         public void test() {
128                 try {
129                                 aafAuthn.validate("testid@aaf.att.com", "whatever");
130                                 List<Permission> perms = new ArrayList<Permission>();
131                                 aafLur.fishAll(getIndex(), perms);
132 //                              Assert.assertFalse(perms.isEmpty());
133 //                              for(Permission p : perms) {
134 //                                      //access.log(Access.Level.AUDIT, p.permType());
135 //                              }
136                 } catch (Exception e) {
137                         StringWriter sw = new StringWriter();
138                         e.printStackTrace(new PrintWriter(sw));
139                         Assert.assertFalse(sw.toString(),true);
140                 }
141         }
142
143 }