Added oparent to sdc main
[sdc.git] / common-app-api / src / test / java / org / openecomp / sdc / common / test / E2EHttpClientTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 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 package org.openecomp.sdc.common.test;
22
23 import org.junit.Ignore;
24 import org.junit.Test;
25 import org.openecomp.sdc.common.http.client.api.HttpExecuteException;
26 import org.openecomp.sdc.common.http.client.api.HttpRequest;
27 import org.openecomp.sdc.common.http.client.api.HttpResponse;
28 import org.openecomp.sdc.common.http.config.HttpClientConfig;
29 import org.openecomp.sdc.common.http.config.Timeouts;
30
31 import java.net.MalformedURLException;
32 import java.util.concurrent.ExecutorService;
33 import java.util.concurrent.Executors;
34 import java.util.concurrent.TimeUnit;
35
36 public class E2EHttpClientTest {
37
38     @Ignore
39     @Test
40     public void testSsl() throws MalformedURLException {
41
42         String url = "https://135.76.210.29:2443/certificate-manager-fe/v1";
43 //        String url = "http://135.76.123.110:1111//aai/v1/aai/cloud-infrastructure/operational-environments/operational-environment/12345";
44         try {
45             HttpClientConfig httpClientConfig = new HttpClientConfig(new Timeouts(10000, 5000));
46
47             HttpResponse<String> response = HttpRequest.get(url, httpClientConfig);
48             System.out.println(response);
49         }
50         catch (Exception e) {
51             e.printStackTrace();
52         }
53     } 
54     
55     @Ignore
56     @Test
57     public void testSslMutliThread() throws MalformedURLException {
58
59           String url = "https://135.76.210.29:2443/certificate-manager-fe/v1";
60 //          String url = "http://135.76.210.29:2080/certificate-manager-fe/v1";
61           String url2 = "http://135.76.123.110:1111//aai/v1/aai/cloud-infrastructure/operational-environments/operational-environment/12345";
62
63         HttpClientConfig httpClientConfig = new HttpClientConfig(new Timeouts(1000, 5000));
64
65         int threadCount = 10;
66         ExecutorService executor = Executors.newFixedThreadPool(threadCount);
67         for (int i = 0; i < threadCount; i++) {
68             Runnable worker = new Runnable() {
69                 @Override
70                 public void run() {
71                     int count = 10;
72                     try {
73                         int i = 0;
74                         while (i < count) {
75                             if(i%2==0) {
76                                 HttpResponse<String> response = HttpRequest.get(url, httpClientConfig);
77                                 System.out.println("Thead id=" + Thread.currentThread() + " Count = " + ++i + " " + response);
78                             }
79                             else {
80                                 HttpResponse<String> response = HttpRequest.get(url2, httpClientConfig);
81                                 System.out.println("Thead id=" + Thread.currentThread() + " Count = " + ++i + " " + response);
82                             }
83                         }
84                     }
85                     catch (HttpExecuteException e) {
86                         e.printStackTrace();
87                     }
88                 }
89             };
90             executor.execute(worker);
91         }
92
93         try {
94             executor.awaitTermination(1, TimeUnit.SECONDS);
95         }
96         catch (InterruptedException e) {
97             e.printStackTrace();
98         }
99         executor.shutdown();
100         while (!executor.isTerminated())
101             ;
102     }
103 }