feat: json解析异常抛出数据详情test

main
13009 2024-08-07 15:25:55 +08:00
parent 3adc99b701
commit ebce3ea202
1 changed files with 20 additions and 17 deletions

View File

@ -1,5 +1,6 @@
package com.czcb.scfs.api.core.http; package com.czcb.scfs.api.core.http;
import com.czcb.scfs.api.core.exception.ApiClientException;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -52,22 +53,24 @@ class HttpResponseTest {
Assertions.assertNotNull(httpResponse.getResponseBody()); Assertions.assertNotNull(httpResponse.getResponseBody());
} }
// @Test @Test
// void getServiceResponse() { void getServiceResponseBuildJson() {
// HttpResponse<String> httpResponse = new HttpResponse.Builder<String>() HttpResponse.Builder<String> builder = new HttpResponse.Builder<String>()
// .originalResponse(new OriginalResponse.Builder() .originalResponse(new OriginalResponse.Builder()
// .request(new HttpRequest.Builder() .body("<!doctype html><html lang=\"en\"><head><title>HTTP Status 404 Not Found</title></html>")
// .httpMethod(HttpMethod.POST) .request(new HttpRequest.Builder()
// .url("/xx") .httpMethod(HttpMethod.POST)
// .headers(new HttpHeaders()) .url("/xx")
// .body(new EncryptRequestBody.Builder().build()) .headers(new HttpHeaders())
// .build()) .body(new EncryptRequestBody.Builder().build())
// .build()) .build())
// .serviceResponseType(String.class) .build())
// .build(); .serviceResponseType(String.class);
//
// Assertions.assertEquals(String.class, httpResponse.getServiceResponse().getClass()); ApiClientException exception = Assertions.assertThrows(ApiClientException.class, builder::build);
// } Assertions.assertInstanceOf(ApiClientException.class, exception);
Assertions.assertEquals("解析JSON数据失败:<!doctype html><html lang=\"en\"><head><title>HTTP Status 404 Not Found</title></html>", exception.getMessage());
}
@Test @Test
void getOriginalBody() { void getOriginalBody() {
@ -114,6 +117,6 @@ class HttpResponseTest {
.originalBody("123456") .originalBody("123456")
.build(); .build();
Assertions.assertTrue(httpResponse.getResponseBody() instanceof UnkownResponseBody); Assertions.assertInstanceOf(UnkownResponseBody.class, httpResponse.getResponseBody());
} }
} }