AT&T 2.0.19 Code drop, stage 3
[aaf/authz.git] / auth / auth-hello / src / test / java / org / onap / aaf / auth / hello / test / HelloTester.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 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.auth.hello.test;
23
24 import java.net.ConnectException;
25 import java.net.HttpURLConnection;
26 import java.net.URI;
27 import java.net.URISyntaxException;
28
29 import org.onap.aaf.auth.common.Define;
30 import org.onap.aaf.cadi.CadiException;
31 import org.onap.aaf.cadi.LocatorException;
32 import org.onap.aaf.cadi.PropAccess;
33 import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp;
34 import org.onap.aaf.cadi.aaf.v2_0.AAFLocator;
35 import org.onap.aaf.cadi.client.Future;
36 import org.onap.aaf.cadi.client.Rcli;
37 import org.onap.aaf.cadi.client.Retryable;
38 import org.onap.aaf.cadi.config.SecurityInfoC;
39 import org.onap.aaf.misc.env.APIException;
40
41 public class HelloTester {
42
43         public static void main(String[] args) {
44                 // Do Once and ONLY once
45                 PropAccess access =  new PropAccess(args);
46                 try {
47                         Define.set(access);
48                         String uriPrefix = access.getProperty("locatorURI","https://aaftest.test.att.com");
49                         
50                         SecurityInfoC<HttpURLConnection> si = SecurityInfoC.instance(access, HttpURLConnection.class);
51                         AAFLocator loc = new AAFLocator(si,new URI(uriPrefix+"/locate/"+Define.ROOT_NS()+".hello:1.0"));
52                         AAFConHttp aafcon = new AAFConHttp(access,loc,si);
53                         
54                         //
55                         String pathinfo = "/hello";
56                         final int iterations = Integer.parseInt(access.getProperty("iterations","5"));
57                         System.out.println("Calling " + loc + " with Path " + pathinfo + ' ' + iterations + " time" + (iterations==1?"":"s"));
58                         for(int i=0;i<iterations;++i) {
59                                 aafcon.best(new Retryable<Void> () {
60                                         @Override
61                                         public Void code(Rcli<?> client) throws CadiException, ConnectException, APIException {
62                                                 Future<String> fs = client.read("/hello","text/plain");
63                                                 if(fs.get(5000)) {
64                                                         System.out.print(fs.body());
65                                                 } else {
66                                                         System.err.println("Ooops, missed one: " + fs.code() + ": " + fs.body());
67                                                 }
68                                                 return null;
69
70                                         }
71                                 });
72                                 Thread.sleep(500L);
73                         }
74                 } catch (CadiException | LocatorException | URISyntaxException | APIException | InterruptedException e) {
75                         e.printStackTrace();
76                 }
77                 
78                 
79         }
80
81 }