fix(接口测试): 修复mock设置响应码不生效的缺陷

--bug=1040944 --user=王孝刚 【接口测试】Mock-Mock的响应码设置不生效
https://www.tapd.cn/55049933/s/1518359
This commit is contained in:
wxg0103 2024-05-22 15:41:20 +08:00 committed by Craftsman
parent da98861217
commit 8e098fde41
1 changed files with 3 additions and 3 deletions

View File

@ -242,7 +242,7 @@ public class MockServerService {
case "JSON" -> responseEntity(responseCode, responseBody.getJsonBody().getJsonWithSchema(), headers); case "JSON" -> responseEntity(responseCode, responseBody.getJsonBody().getJsonWithSchema(), headers);
case "XML" -> responseEntity(responseCode, responseBody.getXmlBody().getValue(), headers); case "XML" -> responseEntity(responseCode, responseBody.getXmlBody().getValue(), headers);
case "RAW" -> responseEntity(responseCode, responseBody.getRawBody().getValue(), headers); case "RAW" -> responseEntity(responseCode, responseBody.getRawBody().getValue(), headers);
case "BINARY" -> handleBinaryBody(responseBody, projectId, resourceId, isMock); case "BINARY" -> handleBinaryBody(responseCode, responseBody, projectId, resourceId, isMock);
default -> responseEntity(responseCode, StringUtils.EMPTY, headers); default -> responseEntity(responseCode, StringUtils.EMPTY, headers);
}; };
} }
@ -250,7 +250,7 @@ public class MockServerService {
return requestNotFound(); return requestNotFound();
} }
private ResponseEntity<?> handleBinaryBody(ResponseBody responseBody, String projectId, String resourceId, boolean isMock) { private ResponseEntity<?> handleBinaryBody(int responseCode, ResponseBody responseBody, String projectId, String resourceId, boolean isMock) {
String fileId = responseBody.getBinaryBody().getFile().getFileId(); String fileId = responseBody.getBinaryBody().getFile().getFileId();
String fileName = responseBody.getBinaryBody().getFile().getFileName(); String fileName = responseBody.getBinaryBody().getFile().getFileName();
String fileType = StringUtils.substring(fileName, fileName.lastIndexOf(".") + 1); String fileType = StringUtils.substring(fileName, fileName.lastIndexOf(".") + 1);
@ -291,7 +291,7 @@ public class MockServerService {
} }
} }
return ResponseEntity.ok() return ResponseEntity.status(responseCode)
.contentType(mediaType) .contentType(mediaType)
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"") .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"")
.body(bytes); .body(bytes);