diff options
author | Fu Jinhua <fu.jinhua@zte.com.cn> | 2017-09-27 02:07:43 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2017-09-27 02:07:43 +0000 |
commit | de60e0a0d50c6dc5eab7afcfd6c3769eec89d9f6 (patch) | |
tree | a76e492512a265a3a0a4a2a9e189824f7426a44d /wfenginemgrservice/src | |
parent | 038a2c99fb7979cd3b4f42717f5827099a305446 (diff) | |
parent | 26626fc79558f525b8c8f4c7bce808cccd3bb1d4 (diff) |
Merge "Add unit test for vfc-nfvo-wfengine-mgrservice"
Diffstat (limited to 'wfenginemgrservice/src')
-rw-r--r-- | wfenginemgrservice/src/main/java/org/onap/workflow/common/RestClient.java | 33 | ||||
-rw-r--r-- | wfenginemgrservice/src/test/java/org/onap/workflow/resources/WorkflowResourceTest.java | 4 |
2 files changed, 22 insertions, 15 deletions
diff --git a/wfenginemgrservice/src/main/java/org/onap/workflow/common/RestClient.java b/wfenginemgrservice/src/main/java/org/onap/workflow/common/RestClient.java index f037757..f179fe6 100644 --- a/wfenginemgrservice/src/main/java/org/onap/workflow/common/RestClient.java +++ b/wfenginemgrservice/src/main/java/org/onap/workflow/common/RestClient.java @@ -46,7 +46,7 @@ public class RestClient { private static final String HTTP = "http"; private static final Logger logger = LoggerFactory.getLogger(RestClient.class); - enum HttpMethod { + public enum HttpMethod { GET, POST, PUT, DELETE } @@ -76,13 +76,13 @@ public class RestClient { } HttpHost target = new HttpHost(ip, port, HTTP); HttpRequest request = getRequest(method, url, body); - logger.info("deployfile method send ip"+ip); + logger.info("deployfile method send ip" + ip); request.addHeader(Constants.AUTHORIZATION, ToolUtil.getHeader()); httpResponse = httpclient.execute(target, request); HttpEntity entity = httpResponse.getEntity(); logger.info("deployfile method send"); - if (entity != null) { + if (entity != null && httpResponse.getStatusLine()!=null) { result.setStatusCode(httpResponse.getStatusLine().getStatusCode()); logger.info("reply status code deploy"+httpResponse.getStatusLine().getStatusCode()); result.setResult(EntityUtils.toString(entity)); @@ -101,7 +101,7 @@ public class RestClient { return result; } - private static HttpRequest getRequest(HttpMethod method, String url, HttpEntity body) { + public static HttpRequest getRequest(HttpMethod method, String url, HttpEntity body) { HttpRequest request = null; switch (method) { case GET: @@ -185,7 +185,9 @@ public class RestClient { if (ip == null) { ip = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrIp(); } - port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort(); + if(port==null) { + port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort(); + } RestResponse result = new RestResponse(); CloseableHttpClient httpClient = HttpClients.createDefault(); try { @@ -204,8 +206,10 @@ public class RestClient { httpDeteTest.setEntity(new StringEntity(jsonStr)); // returnValue = httpClient.execute(httpDeteTest, responseHandler); // 调接口获取返回值时,必须用此方法 CloseableHttpResponse httpResonse = httpClient.execute(httpDeteTest); - int statusCode = httpResonse.getStatusLine().getStatusCode(); - result.setStatusCode(statusCode); + if(httpResonse!=null && httpResonse.getStatusLine()!=null) { + int statusCode = httpResonse.getStatusLine().getStatusCode(); + result.setStatusCode(statusCode); + } // result.setResult(EntityUtils.toString(httpResonse.getEntity())); } catch (Exception e) { e.printStackTrace(); @@ -245,8 +249,9 @@ public class RestClient { if (ip == null) { ip = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrIp(); } - port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort(); - + if(ip==null) { + port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort(); + } HttpPost httpPost = new HttpPost(Constants.HTTP_HEADER + ip + ":" + port + url); Gson gson = new Gson(); String jsonStr = gson.toJson(object, ActivitiStartProcessRequest.class); @@ -257,10 +262,12 @@ public class RestClient { httpPost.setEntity(requestEntity); returnValue = httpClient.execute(httpPost, responseHandler); // 调接口获取返回值时,必须用此方法 CloseableHttpResponse httpResonse = httpClient.execute(httpPost); - int statusCode = httpResonse.getStatusLine().getStatusCode(); - returnValue = EntityUtils.toString(httpResonse.getEntity(),"UTF-8"); - result.setStatusCode(statusCode); - result.setResult(returnValue); + if(httpResonse!=null && httpResonse.getStatusLine()!=null) { + int statusCode = httpResonse.getStatusLine().getStatusCode(); + returnValue = EntityUtils.toString(httpResonse.getEntity(), "UTF-8"); + result.setStatusCode(statusCode); + result.setResult(returnValue); + } } catch (Exception e) { e.printStackTrace(); } diff --git a/wfenginemgrservice/src/test/java/org/onap/workflow/resources/WorkflowResourceTest.java b/wfenginemgrservice/src/test/java/org/onap/workflow/resources/WorkflowResourceTest.java index c3cb392..e7d6523 100644 --- a/wfenginemgrservice/src/test/java/org/onap/workflow/resources/WorkflowResourceTest.java +++ b/wfenginemgrservice/src/test/java/org/onap/workflow/resources/WorkflowResourceTest.java @@ -44,7 +44,7 @@ public class WorkflowResourceTest { workflowInstanceWrapper = mock(WorkflowInstanceWrapper.class);
Whitebox.setInternalState(WorkflowInstanceWrapper.class, "wrapper", workflowInstanceWrapper);
-
+
workflowResource = new WorkflowResource();
}
@@ -57,7 +57,7 @@ public class WorkflowResourceTest { Response result = Response.ok("success").build();
when(workflowInstanceWrapper.deployBpmnFile(Mockito.anyString(), Mockito.anyObject(), Mockito.anyObject())).thenReturn(result);
-
+
assertThat(workflowResource.deployBpmnFile(fileInputStream,fileDetail), is(result));
}
|