re base code
[sdc.git] / common-app-api / src / test / java / org / openecomp / sdc / common / test / E2EHttpClientTest.java
1 package org.openecomp.sdc.common.test;
2
3 import org.junit.Ignore;
4 import org.junit.Test;
5 import org.openecomp.sdc.common.http.client.api.HttpExecuteException;
6 import org.openecomp.sdc.common.http.client.api.HttpRequest;
7 import org.openecomp.sdc.common.http.client.api.HttpResponse;
8 import org.openecomp.sdc.common.http.config.HttpClientConfig;
9 import org.openecomp.sdc.common.http.config.Timeouts;
10
11 import java.net.MalformedURLException;
12 import java.util.concurrent.ExecutorService;
13 import java.util.concurrent.Executors;
14 import java.util.concurrent.TimeUnit;
15
16 public class E2EHttpClientTest {
17
18     @Ignore
19     @Test
20     public void testSsl() throws MalformedURLException {
21
22         String url = "https://135.76.210.29:2443/certificate-manager-fe/v1";
23 //        String url = "http://135.76.123.110:1111//aai/v1/aai/cloud-infrastructure/operational-environments/operational-environment/12345";
24         try {
25             HttpClientConfig httpClientConfig = new HttpClientConfig(new Timeouts(10000, 5000));
26
27             HttpResponse<String> response = HttpRequest.get(url, httpClientConfig);
28             System.out.println(response);
29         }
30         catch (Exception e) {
31             e.printStackTrace();
32         }
33     } 
34     
35     @Ignore
36     @Test
37     public void testSslMutliThread() throws MalformedURLException {
38
39           String url = "https://135.76.210.29:2443/certificate-manager-fe/v1";
40 //          String url = "http://135.76.210.29:2080/certificate-manager-fe/v1";
41           String url2 = "http://135.76.123.110:1111//aai/v1/aai/cloud-infrastructure/operational-environments/operational-environment/12345";
42
43         HttpClientConfig httpClientConfig = new HttpClientConfig(new Timeouts(1000, 5000));
44
45         int threadCount = 10;
46         ExecutorService executor = Executors.newFixedThreadPool(threadCount);
47         for (int i = 0; i < threadCount; i++) {
48             Runnable worker = new Runnable() {
49                 @Override
50                 public void run() {
51                     int count = 10;
52                     try {
53                         int i = 0;
54                         while (i < count) {
55                             if(i%2==0) {
56                                 HttpResponse<String> response = HttpRequest.get(url, httpClientConfig);
57                                 System.out.println("Thead id=" + Thread.currentThread() + " Count = " + ++i + " " + response);
58                             }
59                             else {
60                                 HttpResponse<String> response = HttpRequest.get(url2, httpClientConfig);
61                                 System.out.println("Thead id=" + Thread.currentThread() + " Count = " + ++i + " " + response);
62                             }
63                         }
64                     }
65                     catch (HttpExecuteException e) {
66                         e.printStackTrace();
67                     }
68                 }
69             };
70             executor.execute(worker);
71         }
72
73         try {
74             executor.awaitTermination(1, TimeUnit.SECONDS);
75         }
76         catch (InterruptedException e) {
77             e.printStackTrace();
78         }
79         executor.shutdown();
80         while (!executor.isTerminated())
81             ;
82     }
83 }