feat: json解析异常抛出数据详情test
parent
3adc99b701
commit
ebce3ea202
|
|
@ -1,5 +1,6 @@
|
|||
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.Test;
|
||||
|
||||
|
|
@ -52,22 +53,24 @@ class HttpResponseTest {
|
|||
Assertions.assertNotNull(httpResponse.getResponseBody());
|
||||
}
|
||||
|
||||
// @Test
|
||||
// void getServiceResponse() {
|
||||
// HttpResponse<String> httpResponse = new HttpResponse.Builder<String>()
|
||||
// .originalResponse(new OriginalResponse.Builder()
|
||||
// .request(new HttpRequest.Builder()
|
||||
// .httpMethod(HttpMethod.POST)
|
||||
// .url("/xx")
|
||||
// .headers(new HttpHeaders())
|
||||
// .body(new EncryptRequestBody.Builder().build())
|
||||
// .build())
|
||||
// .build())
|
||||
// .serviceResponseType(String.class)
|
||||
// .build();
|
||||
//
|
||||
// Assertions.assertEquals(String.class, httpResponse.getServiceResponse().getClass());
|
||||
// }
|
||||
@Test
|
||||
void getServiceResponseBuildJson() {
|
||||
HttpResponse.Builder<String> builder = new HttpResponse.Builder<String>()
|
||||
.originalResponse(new OriginalResponse.Builder()
|
||||
.body("<!doctype html><html lang=\"en\"><head><title>HTTP Status 404 – Not Found</title></html>")
|
||||
.request(new HttpRequest.Builder()
|
||||
.httpMethod(HttpMethod.POST)
|
||||
.url("/xx")
|
||||
.headers(new HttpHeaders())
|
||||
.body(new EncryptRequestBody.Builder().build())
|
||||
.build())
|
||||
.build())
|
||||
.serviceResponseType(String.class);
|
||||
|
||||
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
|
||||
void getOriginalBody() {
|
||||
|
|
@ -114,6 +117,6 @@ class HttpResponseTest {
|
|||
.originalBody("123456")
|
||||
.build();
|
||||
|
||||
Assertions.assertTrue(httpResponse.getResponseBody() instanceof UnkownResponseBody);
|
||||
Assertions.assertInstanceOf(UnkownResponseBody.class, httpResponse.getResponseBody());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue