|
|
@@ -115,6 +115,8 @@ class UnifiedNotifyControllerTest {
|
|
|
|
|
|
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
|
|
|
assertEquals("FAIL", response.getBody());
|
|
|
+ assertEquals("text/plain;charset=UTF-8",
|
|
|
+ response.getHeaders().getContentType().toString());
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@@ -125,6 +127,8 @@ class UnifiedNotifyControllerTest {
|
|
|
|
|
|
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
|
|
|
assertEquals("FAIL", response.getBody());
|
|
|
+ assertEquals("text/plain;charset=UTF-8",
|
|
|
+ response.getHeaders().getContentType().toString());
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@@ -137,6 +141,8 @@ class UnifiedNotifyControllerTest {
|
|
|
|
|
|
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
|
|
|
assertEquals("FAIL", response.getBody());
|
|
|
+ assertEquals("text/plain;charset=UTF-8",
|
|
|
+ response.getHeaders().getContentType().toString());
|
|
|
verifyNoInteractions(notifyService);
|
|
|
}
|
|
|
|
|
|
@@ -156,6 +162,8 @@ class UnifiedNotifyControllerTest {
|
|
|
|
|
|
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
|
|
|
assertEquals("FAIL", response.getBody());
|
|
|
+ assertEquals("text/plain;charset=UTF-8",
|
|
|
+ response.getHeaders().getContentType().toString());
|
|
|
verifyNoInteractions(notifyService);
|
|
|
}
|
|
|
|
|
|
@@ -215,6 +223,8 @@ class UnifiedNotifyControllerTest {
|
|
|
|
|
|
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
|
|
|
assertEquals("FAIL", response.getBody());
|
|
|
+ assertEquals("text/plain;charset=UTF-8",
|
|
|
+ response.getHeaders().getContentType().toString());
|
|
|
verifyNoInteractions(notifyService);
|
|
|
}
|
|
|
|
|
|
@@ -226,9 +236,53 @@ class UnifiedNotifyControllerTest {
|
|
|
|
|
|
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
|
|
|
assertEquals("FAIL", response.getBody());
|
|
|
+ assertEquals("text/plain;charset=UTF-8",
|
|
|
+ response.getHeaders().getContentType().toString());
|
|
|
verifyNoInteractions(notifyService);
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ void parameterMapRuntimeException_returns400Fail_withoutDispatch() {
|
|
|
+ // 容器解析参数时可能抛 IllegalStateException(如 form 解析器状态坏掉);
|
|
|
+ // 不得漏成 500/空白应答 —— 上游只认 FAIL 才能重推
|
|
|
+ MockHttpServletRequest request = new MockHttpServletRequest("POST", ROOT + "/order") {
|
|
|
+ @Override
|
|
|
+ public Map<String, String[]> getParameterMap() {
|
|
|
+ throw new IllegalStateException("参数解析失败");
|
|
|
+ }
|
|
|
+ };
|
|
|
+ request.setContentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
|
|
|
+
|
|
|
+ ResponseEntity<String> response = controller.orderNotify(request);
|
|
|
+
|
|
|
+ assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
|
|
|
+ assertEquals("FAIL", response.getBody());
|
|
|
+ assertEquals("text/plain;charset=UTF-8",
|
|
|
+ response.getHeaders().getContentType().toString());
|
|
|
+ verifyNoInteractions(notifyService);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void exactly64KJsonBody_isAccepted() {
|
|
|
+ when(notifyService.handleOrder(any())).thenReturn(UnifiedNotifyOutcome.SUCCESS);
|
|
|
+ String prefix = "{\"mchNo\":\"M1\",\"pad\":\"";
|
|
|
+ String suffix = "\"}";
|
|
|
+ int padLength = 65536 - prefix.getBytes(StandardCharsets.UTF_8).length
|
|
|
+ - suffix.getBytes(StandardCharsets.UTF_8).length;
|
|
|
+ String body = prefix + " ".repeat(padLength) + suffix;
|
|
|
+ assertEquals(65536, body.getBytes(StandardCharsets.UTF_8).length,
|
|
|
+ "测试报文必须恰好 65536 字节(上限含等号)");
|
|
|
+
|
|
|
+ ResponseEntity<String> response = controller.orderNotify(jsonRequest(body));
|
|
|
+
|
|
|
+ assertEquals(HttpStatus.OK, response.getStatusCode(),
|
|
|
+ "恰好 64KB 不算超限,必须受理");
|
|
|
+ assertEquals("SUCCESS", response.getBody());
|
|
|
+ Map<String, String> params = capturedOrderParams();
|
|
|
+ assertEquals("M1", params.get("mchNo"));
|
|
|
+ assertEquals(padLength, params.get("pad").length());
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
void emptyForm_isDispatchedWithEmptyMap_andMappedNormally() {
|
|
|
when(notifyService.handleOrder(any())).thenReturn(UnifiedNotifyOutcome.UNAUTHORIZED);
|