+ thrown.expectMessage("Failed to query data from server through GET method!");
+ String url = "host";
+ Map<String, String> header = new HashMap<>();
+ header.put("accept", "application/json");
+ HttpResponse httpResponse = HttpsUtils.get(url, header);
+ String response = HttpsUtils.extractResponseEntity(httpResponse);
+ assertThat(response, equalTo(""));
+ }
+
+ @Test
+ public void testHttpsUtil_get_normal() throws Exception {
+ HttpClientBuilder hcb = PowerMock.createMock(HttpClientBuilder.class);
+ CloseableHttpClient httpClient = PowerMock.createMock(CloseableHttpClient.class);
+ PowerMock.mockStatic(HttpClients.class);
+ EasyMock.expect(HttpClients.custom()).andReturn(hcb);
+ EasyMock.expect(hcb.setDefaultRequestConfig(EasyMock.anyObject(RequestConfig.class))).andReturn(hcb);
+ EasyMock.expect(hcb.setSSLSocketFactory(EasyMock.anyObject(SSLConnectionSocketFactory.class))).andReturn(hcb);
+ EasyMock.expect(hcb.setConnectionManager(EasyMock.anyObject(PoolingHttpClientConnectionManager.class))).andReturn(hcb);
+ EasyMock.expect(hcb.setConnectionManagerShared(true)).andReturn(hcb);
+ EasyMock.expect(hcb.build()).andReturn(httpClient);
+
+ CloseableHttpResponse response = PowerMock.createMock(CloseableHttpResponse.class);
+ EasyMock.expect(httpClient.execute(EasyMock.anyObject(HttpRequestBase.class))).andReturn(response);
+ StatusLine sl = PowerMock.createMock(StatusLine.class);
+ EasyMock.expect(response.getStatusLine()).andReturn(sl);
+ EasyMock.expect(sl.getStatusCode()).andReturn(HttpStatus.SC_OK);
+ HttpEntity responseEntity = new StringEntity("Test");
+ EasyMock.expect(response.getEntity()).andReturn(responseEntity);
+
+ httpClient.close();
+ EasyMock.expectLastCall();
+
+ PowerMock.replayAll();
+
+
+ String url = "localhost";
+ Map<String, String> header = new HashMap<>();
+ header.put("accept", "application/json");
+
+ HttpEntity entity = new StringEntity("Test");
+ HttpResponse httpResponse = HttpsUtils.get(url, header);
+ String res = HttpsUtils.extractResponseEntity(httpResponse);
+
+ PowerMock.verifyAll();
+
+ assertThat(res, equalTo("Test"));
+ }
+
+ @Test
+ public void testHttpsUtil_delete_excepiton() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("Failed to query data from server through DELETE method!");
+ String url = "host";
+ Map<String, String> header = new HashMap<>();
+ header.put("accept", "application/json");
+ HttpResponse httpResponse = HttpsUtils.delete(url, header);
+ String response = HttpsUtils.extractResponseEntity(httpResponse);
+ assertThat(response, equalTo(""));
+ }
+
+ @Test
+ public void testHttpsUtil_delete_normal() throws Exception {
+ HttpClientBuilder hcb = PowerMock.createMock(HttpClientBuilder.class);
+ CloseableHttpClient httpClient = PowerMock.createMock(CloseableHttpClient.class);
+ PowerMock.mockStatic(HttpClients.class);
+ EasyMock.expect(HttpClients.custom()).andReturn(hcb);
+ EasyMock.expect(hcb.setDefaultRequestConfig(EasyMock.anyObject(RequestConfig.class))).andReturn(hcb);
+ EasyMock.expect(hcb.setSSLSocketFactory(EasyMock.anyObject(SSLConnectionSocketFactory.class))).andReturn(hcb);
+ EasyMock.expect(hcb.setConnectionManager(EasyMock.anyObject(PoolingHttpClientConnectionManager.class))).andReturn(hcb);
+ EasyMock.expect(hcb.setConnectionManagerShared(true)).andReturn(hcb);
+ EasyMock.expect(hcb.build()).andReturn(httpClient);
+
+ CloseableHttpResponse response = PowerMock.createMock(CloseableHttpResponse.class);
+ EasyMock.expect(httpClient.execute(EasyMock.anyObject(HttpRequestBase.class))).andReturn(response);
+ StatusLine sl = PowerMock.createMock(StatusLine.class);
+ EasyMock.expect(response.getStatusLine()).andReturn(sl);
+ EasyMock.expect(sl.getStatusCode()).andReturn(HttpStatus.SC_OK);
+ HttpEntity responseEntity = new StringEntity("Test");
+ EasyMock.expect(response.getEntity()).andReturn(responseEntity);
+
+ httpClient.close();
+ EasyMock.expectLastCall();
+
+ PowerMock.replayAll();
+
+
+ String url = "localhost";
+ Map<String, String> header = new HashMap<>();
+ header.put("accept", "application/json");
+
+ HttpEntity entity = new StringEntity("Test");
+ HttpResponse httpResponse = HttpsUtils.delete(url, header);
+ String res = HttpsUtils.extractResponseEntity(httpResponse);
+
+ PowerMock.verifyAll();
+
+ assertThat(res, equalTo("Test"));
+ }
+
+ @Test
+ public void testHttpsUtil_post_excepiton() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("Failed to query data from server through POST method!");