|
|
|
@ -150,13 +150,28 @@ public class HttpTaskTest {
|
|
|
|
|
prepareParamsMap.put("day", "20220812"); |
|
|
|
|
// The MockWebServer will return the request body as response body directly
|
|
|
|
|
// So we just need to check if the response body contains string "20220812"
|
|
|
|
|
HttpTask httpTask = generateHttpTask(MOCK_DISPATCH_PATH_REQ_BODY_TO_RES_BODY, HttpMethod.POST, |
|
|
|
|
HttpTask httpTask = generateHttpTask(MOCK_DISPATCH_PATH_REQ_BODY_TO_RES_BODY, HttpMethod.POST, null, |
|
|
|
|
httpParams, prepareParamsMap, HttpCheckCondition.BODY_CONTAINS, "20220812", |
|
|
|
|
HttpStatus.SC_OK, ""); |
|
|
|
|
httpTask.handle(null); |
|
|
|
|
Assertions.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testHandleWithHttpBody() throws Exception { |
|
|
|
|
String httpBody = "{\"day\": ${day}}"; |
|
|
|
|
|
|
|
|
|
Map<String, String> prepareParamsMap = new HashMap<>(); |
|
|
|
|
prepareParamsMap.put("day", "20220812"); |
|
|
|
|
// The MockWebServer will return the request body as response body directly
|
|
|
|
|
// So we just need to check if the response body contains string "20220812"
|
|
|
|
|
HttpTask httpTask = generateHttpTask(MOCK_DISPATCH_PATH_REQ_BODY_TO_RES_BODY, HttpMethod.POST, httpBody, |
|
|
|
|
null, prepareParamsMap, HttpCheckCondition.BODY_CONTAINS, "20220812", |
|
|
|
|
HttpStatus.SC_OK, ""); |
|
|
|
|
httpTask.handle(null); |
|
|
|
|
Assertions.assertEquals(EXIT_CODE_SUCCESS, httpTask.getExitStatusCode()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testHandleWithHttpParameterParams() throws Exception { |
|
|
|
|
List<HttpProperty> httpParams = new ArrayList<>(); |
|
|
|
@ -170,7 +185,7 @@ public class HttpTaskTest {
|
|
|
|
|
prepareParamsMap.put("day", "20220812"); |
|
|
|
|
// The MockWebServer will return the request parameter as response body directly
|
|
|
|
|
// So we just need to check if the response body contains string "20220812"
|
|
|
|
|
HttpTask httpTask = generateHttpTask(MOCK_DISPATCH_PATH_REQ_PARAMS_TO_RES_BODY, HttpMethod.POST, |
|
|
|
|
HttpTask httpTask = generateHttpTask(MOCK_DISPATCH_PATH_REQ_PARAMS_TO_RES_BODY, HttpMethod.POST, null, |
|
|
|
|
httpParams, prepareParamsMap, HttpCheckCondition.BODY_CONTAINS, "20220812", |
|
|
|
|
HttpStatus.SC_OK, ""); |
|
|
|
|
httpTask.handle(null); |
|
|
|
@ -203,22 +218,24 @@ public class HttpTaskTest {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private HttpTask generateHttpTask(HttpMethod httpMethod, int actualResponseCode) throws IOException { |
|
|
|
|
return generateHttpTask("/test", httpMethod, null, null, |
|
|
|
|
return generateHttpTask("/test", httpMethod, null, null, null, |
|
|
|
|
HttpCheckCondition.STATUS_CODE_DEFAULT, "", actualResponseCode, ""); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private HttpTask generateHttpTask(HttpMethod httpMethod, HttpCheckCondition httpCheckConditionType, |
|
|
|
|
String condition, int actualResponseCode, |
|
|
|
|
String actualResponseBody) throws IOException { |
|
|
|
|
return generateHttpTask("/test", httpMethod, null, null, |
|
|
|
|
return generateHttpTask("/test", httpMethod, null, null, null, |
|
|
|
|
httpCheckConditionType, condition, actualResponseCode, actualResponseBody); |
|
|
|
|
} |
|
|
|
|
private HttpTask generateHttpTask(String mockPath, HttpMethod httpMethod, List<HttpProperty> httpParams, |
|
|
|
|
private HttpTask generateHttpTask(String mockPath, HttpMethod httpMethod, String httpBody, |
|
|
|
|
List<HttpProperty> httpParams, |
|
|
|
|
Map<String, String> prepareParamsMap, HttpCheckCondition httpCheckConditionType, |
|
|
|
|
String condition, int actualResponseCode, |
|
|
|
|
String actualResponseBody) throws IOException { |
|
|
|
|
String url = withMockWebServer(mockPath, actualResponseCode, actualResponseBody); |
|
|
|
|
String paramData = generateHttpParameters(url, httpMethod, httpParams, httpCheckConditionType, condition); |
|
|
|
|
String paramData = |
|
|
|
|
generateHttpParameters(url, httpMethod, httpBody, httpParams, httpCheckConditionType, condition); |
|
|
|
|
return generateHttpTaskFromParamData(paramData, prepareParamsMap); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -240,13 +257,15 @@ public class HttpTaskTest {
|
|
|
|
|
return httpTask; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String generateHttpParameters(String url, HttpMethod httpMethod, List<HttpProperty> httpParams, |
|
|
|
|
private String generateHttpParameters(String url, HttpMethod httpMethod, String httpBody, |
|
|
|
|
List<HttpProperty> httpParams, |
|
|
|
|
HttpCheckCondition httpCheckConditionType, |
|
|
|
|
String condition) throws JsonProcessingException { |
|
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
|
HttpParameters httpParameters = new HttpParameters(); |
|
|
|
|
httpParameters.setUrl(url); |
|
|
|
|
httpParameters.setHttpMethod(httpMethod); |
|
|
|
|
httpParameters.setHttpBody(httpBody); |
|
|
|
|
httpParameters.setHttpCheckCondition(httpCheckConditionType); |
|
|
|
|
httpParameters.setCondition(condition); |
|
|
|
|
httpParameters.setConnectTimeout(10000); |
|
|
|
|