import java.util.Map;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
+import org.apache.http.HttpResponse;
import org.jvnet.hk2.annotations.Service;
import org.onap.holmes.common.aai.config.AaiConfig;
import org.onap.holmes.common.aai.entity.VmEntity;
}
private String getResponse(String url) throws CorrelationException {
- String response = "";
+ String response;
try {
- response = HttpsUtils.get(url, getHeaders());
+ HttpResponse httpResponse = HttpsUtils.get(url, getHeaders());
+ response = HttpsUtils.extractResponseEntity(httpResponse);
} catch (Exception e) {
throw new CorrelationException("Failed to get data from aai", e);
}
*/\r
package org.onap.holmes.common.dmaap;\r
\r
+import org.onap.holmes.common.dmaap.entity.PolicyMsg;\r
+import org.onap.holmes.common.exception.CorrelationException;\r
import com.alibaba.fastjson.JSON;\r
-import javax.ws.rs.client.Client;\r
-import javax.ws.rs.client.ClientBuilder;\r
-import javax.ws.rs.client.Entity;\r
-import javax.ws.rs.client.WebTarget;\r
+import java.util.HashMap;\r
import javax.ws.rs.core.MediaType;\r
-import javax.ws.rs.core.Response;\r
import lombok.Getter;\r
import lombok.Setter;\r
+import org.apache.http.HttpResponse;\r
import org.apache.http.HttpStatus;\r
+import org.apache.http.entity.StringEntity;\r
import org.jvnet.hk2.annotations.Service;\r
-import org.onap.holmes.common.dmaap.entity.PolicyMsg;\r
-import org.onap.holmes.common.exception.CorrelationException;\r
+import org.onap.holmes.common.utils.HttpsUtils;\r
\r
@Getter\r
@Setter\r
private String authExpDate;\r
\r
public boolean publish(PolicyMsg msg) throws CorrelationException {\r
- Client client = ClientBuilder.newClient();\r
- String content = JSON.toJSONString(msg);\r
- WebTarget webTarget = client.target(url);\r
- Response response = null;\r
+ String content;\r
+ try {\r
+ content = JSON.toJSONString(msg);\r
+ } catch (Exception e) {\r
+ throw new CorrelationException("Failed to convert the message object to a json string.",\r
+ e);\r
+ }\r
+ HttpResponse httpResponse;\r
+ HashMap<String, String> headers = new HashMap<>();\r
+ headers.put("Accept", MediaType.APPLICATION_JSON);\r
+ headers.put("Content-Type", MediaType.APPLICATION_JSON);\r
try {\r
- response = webTarget.request(MediaType.APPLICATION_JSON)\r
- .post(Entity.entity(content, MediaType.APPLICATION_JSON));\r
+ httpResponse = HttpsUtils.post(url, headers, new HashMap<>(), new StringEntity(content, "utf-8"));\r
} catch (Exception e) {\r
throw new CorrelationException("Failed to connect to DCAE.", e);\r
}\r
- return checkStatus(response);\r
+ return checkStatus(httpResponse);\r
}\r
\r
- private boolean checkStatus(Response response) {\r
- return response.getStatus() == HttpStatus.SC_OK;\r
+ private boolean checkStatus(HttpResponse httpResponse) {\r
+ return (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) ? true : false;\r
}\r
}\r
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
public class HttpsUtils {
private static final String HTTP = "http";
private static final String HTTPS = "https";
+ private static final int DEFUALT_TIMEOUT = 30000;
private static SSLConnectionSocketFactory sslConnectionSocketFactory = null;
private static PoolingHttpClientConnectionManager connectionManager = null;
private static SSLContextBuilder sslContextBuilder = null;
}
}
- public static String post(String url, Map<String, String> header, Map<String, String> param,
- HttpEntity entity) throws Exception {
- HttpResponse httpResponse = null;
+ public static HttpResponse post(String url, Map<String, String> header, Map<String, String> param,
+ HttpEntity entity) throws CorrelationException {
+ return post(url, header, param, entity, DEFUALT_TIMEOUT);
+ }
+
+ public static HttpResponse post(String url, Map<String, String> header, Map<String, String> param,
+ HttpEntity entity, int timeout) throws CorrelationException {
+ HttpResponse response;
+ HttpPost httpPost = new HttpPost(url);
try {
- CloseableHttpClient httpClient = getHttpClient();
- HttpPost httpPost = getHttpPost(url, header, param, entity);
- httpResponse = getHttpResponse(httpClient, httpPost);
+ CloseableHttpClient httpClient = getHttpClient(timeout);
+ addHeaders(header, httpPost);
+ addParams(param, httpPost);
+ if (entity != null) {
+ httpPost.setEntity(entity);
+ }
+ response = executeRequest(httpClient, httpPost);
} catch (Exception e) {
- throw new CorrelationException("Failed to use post method query data from server");
+ throw new CorrelationException("Failed to query data from server through POST method!");
}
- return getResponseEntity(httpResponse);
+ return response;
}
- public static String get(String url, Map<String, String> header) throws Exception {
- HttpResponse httpResponse = null;
- CloseableHttpClient httpClient = null;
- HttpGet httpGet = null;
- String response = "";
+ public static HttpResponse put(String url, Map<String, String> header, Map<String, String> param,
+ HttpEntity entity) throws CorrelationException {
+ return put(url, header, param, entity, DEFUALT_TIMEOUT);
+ }
+
+ public static HttpResponse put(String url, Map<String, String> header, Map<String, String> param,
+ HttpEntity entity, int timeout) throws CorrelationException {
+ HttpResponse response;
+ HttpPut httpPut = new HttpPut(url);
try {
- httpClient = getHttpClient();
- httpGet = getHttpGet(url, header);
- httpResponse = getHttpResponse(httpClient, httpGet);
- response = getResponseEntity(httpResponse);
- } catch (Exception e) {
- throw new CorrelationException("Failed to use get method query data from server");
- } finally {
- if (httpGet != null) {
- httpGet.releaseConnection();
- }
- if (httpResponse != null) {
- httpClient.close();
+ CloseableHttpClient httpClient = getHttpClient(timeout);
+ addHeaders(header, httpPut);
+ addParams(param, httpPut);
+ if (entity != null) {
+ httpPut.setEntity(entity);
}
+ response = executeRequest(httpClient, httpPut);
+ } catch (Exception e) {
+ throw new CorrelationException("Failed to query data from server through PUT method!");
}
return response;
}
- private static HttpPost getHttpPost(String url, Map<String, String> header,
- Map<String, String> param, HttpEntity entity) {
- HttpPost httpPost = new HttpPost(url);
- if (!header.isEmpty()) {
- for (Map.Entry<String, String> entry : header.entrySet()) {
- httpPost.addHeader(entry.getKey(), entry.getValue());
- }
+ public static HttpResponse get(String url, Map<String, String> header) throws CorrelationException {
+ return get(url, header, DEFUALT_TIMEOUT);
+ }
+
+ public static HttpResponse get(String url, Map<String, String> header, int timeout) throws CorrelationException {
+ HttpResponse response;
+ HttpGet httpGet = new HttpGet(url);
+ try {
+ CloseableHttpClient httpClient = getHttpClient(timeout);
+ addHeaders(header, httpGet);
+ response = executeRequest(httpClient, httpGet);
+ } catch (Exception e) {
+ throw new CorrelationException("Failed to query data from server through GET method!");
+ }
+ return response;
+ }
+
+ public static HttpResponse delete(String url, Map<String, String> header) throws CorrelationException {
+ return delete(url, header, DEFUALT_TIMEOUT);
+ }
+
+ public static HttpResponse delete(String url, Map<String, String> header, int timeout) throws CorrelationException {
+ HttpResponse response;
+ HttpDelete httpDelete = new HttpDelete(url);
+ try {
+ CloseableHttpClient httpClient = getHttpClient(timeout);
+ addHeaders(header, httpDelete);
+ response = executeRequest(httpClient, httpDelete);
+ } catch (Exception e) {
+ throw new CorrelationException("Failed to query data from server through DELETE method!");
}
+ return response;
+ }
+
+ private static void addParams(Map<String, String> param, HttpEntityEnclosingRequestBase requestBase) {
if (!param.isEmpty()) {
List<NameValuePair> formparams = new ArrayList<>();
for (Map.Entry<String, String> entry : param.entrySet()) {
}
UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(formparams,
Consts.UTF_8);
- httpPost.setEntity(urlEncodedFormEntity);
- }
- if (entity != null) {
- httpPost.setEntity(entity);
+ requestBase.setEntity(urlEncodedFormEntity);
}
- return httpPost;
}
- private static HttpGet getHttpGet(String url, Map<String, String> header) {
- HttpGet httpGet = new HttpGet(url);
+ private static HttpRequestBase addHeaders(Map<String, String> header, HttpRequestBase httpRequestBase) {
if (!header.isEmpty()) {
for (Map.Entry<String, String> entry : header.entrySet()) {
- httpGet.addHeader(entry.getKey(), entry.getValue());
+ httpRequestBase.addHeader(entry.getKey(), entry.getValue());
}
}
- return httpGet;
+ return httpRequestBase;
}
- private static String getResponseEntity(HttpResponse httpResponse) throws IOException {
+ public static String extractResponseEntity(HttpResponse httpResponse)
+ throws CorrelationException, IOException {
String result = "";
if (httpResponse != null) {
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
HttpEntity resEntity = httpResponse.getEntity();
result = EntityUtils.toString(resEntity);
+ } else {
+ throw new CorrelationException("Get a error status from server : " + statusCode);
}
}
return result;
}
- private static HttpResponse getHttpResponse(CloseableHttpClient httpClient, HttpRequestBase httpRequest)
+ private static HttpResponse executeRequest(CloseableHttpClient httpClient, HttpRequestBase httpRequest)
throws Exception {
- HttpResponse httpResponse = null;
+ HttpResponse httpResponse;
try {
httpResponse = httpClient.execute(httpRequest);
} catch (Exception e) {
throw new CorrelationException("Failed to get data from server");
+ } finally {
+ if (httpRequest != null) {
+ httpRequest.releaseConnection();
+ }
+ if (httpClient != null) {
+ httpClient.close();
+ }
}
return httpResponse;
}
- private static CloseableHttpClient getHttpClient() throws Exception {
+ private static CloseableHttpClient getHttpClient(int timeout) throws Exception {
+ RequestConfig defaultRequestConfig = RequestConfig.custom()
+ .setSocketTimeout(timeout)
+ .setConnectTimeout(timeout)
+ .setConnectionRequestTimeout(timeout)
+ .build();
CloseableHttpClient httpClient = HttpClients.custom()
+ .setDefaultRequestConfig(defaultRequestConfig)
.setSSLSocketFactory(sslConnectionSocketFactory)
.setConnectionManager(connectionManager)
.setConnectionManagerShared(true)
import java.util.HashMap;
import java.util.Map;
+import org.apache.http.HttpResponse;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
headers.put("Authorization", AaiConfig.getAuthenticationCredentials());
headers.put("Accept", "application/json");
String url = "http://10.96.33.33/api/aai-cloudInfrastructure/v11";
- when(HttpsUtils.get(url, headers)).thenReturn("{}");
+ HttpResponse httpResponse = PowerMock.createMock(HttpResponse.class);
+ when(HttpsUtils.get(url, headers)).thenReturn(httpResponse);
+ when(HttpsUtils.extractResponseEntity(httpResponse)).thenReturn("{}");
PowerMockito.mockStatic(MicroServiceConfig.class);
when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenReturn("http://10.96.33.33:80");
assertThat(vmEntity == null, equalTo(true));
}
-
-
-
-
@Test
public void testAaiQuery_getAaiVmData_httpsutils_exception() throws Exception {
PowerMock.resetAll();
headers.put("Accept", "application/json");
String url = "host_url";
- when(HttpsUtils.get(url, headers)).thenReturn("");
+ HttpResponse httpResponse = PowerMock.createMock(HttpResponse.class);
+ when(HttpsUtils.get(url, headers)).thenReturn(httpResponse);
+ when(HttpsUtils.extractResponseEntity(httpResponse)).thenReturn("");
PowerMock.replayAll();
String resource = Whitebox.invokeMethod(aaiQuery, "getResponse", "host_url");
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
+import java.util.HashMap;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
+import org.apache.http.StatusLine;
+import org.apache.http.entity.StringEntity;
import org.easymock.EasyMock;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
+import org.mockito.Matchers;
import org.onap.holmes.common.dmaap.entity.PolicyMsg;
import org.onap.holmes.common.exception.CorrelationException;
+import org.onap.holmes.common.utils.HttpsUtils;
import org.powermock.api.easymock.PowerMock;
+import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-@PrepareForTest({Client.class, WebTarget.class, ClientBuilder.class, Response.class, Builder.class})
+@PrepareForTest({HttpsUtils.class, HttpResponse.class})
@RunWith(PowerMockRunner.class)
public class PublisherTest {
Publisher publisher = new Publisher();
publisher.setUrl(URL);
- WebTarget target = PowerMock.createMock(WebTarget.class);
- Client client = PowerMock.createMock(Client.class);
- Builder builder = PowerMock.createMock(Builder.class);
- Response response = PowerMock.createMock(Response.class);
- PowerMock.mockStatic(ClientBuilder.class);
-
- EasyMock.expect(ClientBuilder.newClient()).andReturn(client);
- EasyMock.expect(client.target(publisher.getUrl())).andReturn(target);
- EasyMock.expect(target.request(MediaType.APPLICATION_JSON)).andReturn(builder);
- EasyMock.expect(builder.post(EasyMock.anyObject(Entity.class))).andReturn(response);
- EasyMock.expect(response.getStatus()).andReturn(HttpStatus.SC_OK);
+ PowerMockito.mockStatic(HttpsUtils.class);
+ HttpResponse httpResponse = PowerMockito.mock(HttpResponse.class);
+ PowerMockito.when(HttpsUtils.post(Matchers.eq("http://localhost/dmaapTopic"),
+ Matchers.any(HashMap.class), Matchers.any(HashMap.class), Matchers.any(StringEntity.class))).thenReturn(httpResponse);
+ StatusLine statusLine = PowerMockito.mock(StatusLine.class);
+ PowerMockito.when(httpResponse.getStatusLine()).thenReturn(statusLine);
+ PowerMockito.when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_OK);
PowerMock.replayAll();
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
-import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
@Test
public void testHttpsUtil_get_excepiton() throws Exception {
thrown.expect(CorrelationException.class);
- thrown.expectMessage("Failed to use get method query data from server");
+ 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");
- String response = HttpsUtils.get(url, header);
+ HttpResponse httpResponse = HttpsUtils.get(url, header);
+ String response = HttpsUtils.extractResponseEntity(httpResponse);
assertThat(response, equalTo(""));
}
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);
header.put("accept", "application/json");
HttpEntity entity = new StringEntity("Test");
- String res = HttpsUtils.get(url, header);
+ 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();
@Test
public void testHttpsUtil_post_excepiton() throws Exception {
thrown.expect(CorrelationException.class);
- thrown.expectMessage("Failed to use post method query data from server");
+ thrown.expectMessage("Failed to query data from server through POST method!");
String url = "host";
Map<String, String> header = new HashMap<>();
header.put("accept", "application/json");
Map<String, String> para = new HashMap<>();
para.put("tset", "1111");
- String response = HttpsUtils.post(url, header, para, null);
+
+ HttpResponse httpResponse = HttpsUtils.post(url, header, para, null);
+ String response = HttpsUtils.extractResponseEntity(httpResponse);
assertThat(response, equalTo(""));
}
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);
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");
+ Map<String, String> para = new HashMap<>();
+ para.put("tset", "1111");
+
+ HttpEntity entity = new StringEntity("Test");
+ HttpResponse httpResponse = HttpsUtils.post(url, header, para, entity);
+ String res = HttpsUtils.extractResponseEntity(httpResponse);
+
+ PowerMock.verifyAll();
+
+ assertThat(res, equalTo("Test"));
+ }
+
+ @Test
+ public void testHttpsUtil_put_excepiton() throws Exception {
+ thrown.expect(CorrelationException.class);
+ thrown.expectMessage("Failed to query data from server through PUT method!");
+ String url = "host";
+ Map<String, String> header = new HashMap<>();
+ header.put("accept", "application/json");
+ Map<String, String> para = new HashMap<>();
+ para.put("tset", "1111");
+
+ HttpResponse httpResponse = HttpsUtils.put(url, header, para, null);
+ String response = HttpsUtils.extractResponseEntity(httpResponse);
+ assertThat(response, equalTo(""));
+ }
+
+ @Test
+ public void testHttpsUtil_put_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();
para.put("tset", "1111");
HttpEntity entity = new StringEntity("Test");
- String res = HttpsUtils.post(url, header, para, entity);
+ HttpResponse httpResponse = HttpsUtils.put(url, header, para, entity);
+ String res = HttpsUtils.extractResponseEntity(httpResponse);
PowerMock.verifyAll();
PowerMock.resetAll();
httpsUtils = PowerMock.createMock(HttpsUtils.class);
PowerMock.replayAll();
- String actual = Whitebox.invokeMethod(httpsUtils, "getResponseEntity", null);
+ String actual = Whitebox.invokeMethod(httpsUtils, "extractResponseEntity", null);
PowerMock.verifyAll();
assertThat(actual, equalTo(""));
}