Add rest-client-test module: @RestClientTest on Boot 4.1, Jackson 3 by default, and the RestClient-vs-RestTemplate root-URI matching trap (post #49)
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
# mvn test - full run, Spring Boot 4.1.1
|
||||
|
||||
[INFO] Running com.ankurm.restclienttest.RestClientEmployeeTest
|
||||
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.122 s -- in com.ankurm.restclienttest.RestClientEmployeeTest
|
||||
[INFO] Running com.ankurm.restclienttest.HttpInterfaceClientTest
|
||||
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.401 s -- in com.ankurm.restclienttest.HttpInterfaceClientTest
|
||||
[INFO] Running com.ankurm.restclienttest.ErrorScenarioTest
|
||||
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.067 s -- in com.ankurm.restclienttest.ErrorScenarioTest
|
||||
[INFO] Running com.ankurm.restclienttest.RestTemplateEmployeeTest
|
||||
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.280 s -- in com.ankurm.restclienttest.RestTemplateEmployeeTest
|
||||
[INFO] Results:
|
||||
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
|
||||
[INFO] BUILD SUCCESS
|
||||
@@ -0,0 +1,5 @@
|
||||
== RestClient-based EmployeeClient, real deserialized result and audit call ==
|
||||
|
||||
requestTo("http://hr-api.example.com/employees/1") -> 200 OK {"id":1,"firstName":"Ankur","lastName":"M","email":"[email protected]"}
|
||||
result = Employee[id=1, firstName=Ankur, lastName=M, [email protected]]
|
||||
auditLogger.logFetch(1) called = true
|
||||
@@ -0,0 +1,4 @@
|
||||
== RestTemplate-based EmployeeTemplateClient, identical MockRestServiceServer code ==
|
||||
|
||||
requestTo("/employees/2") -> 200 OK {"id":2,"firstName":"Priya","lastName":"V","email":"[email protected]"}
|
||||
result = Employee[id=2, firstName=Priya, lastName=V, [email protected]]
|
||||
@@ -0,0 +1,5 @@
|
||||
== A 404 response from MockRestServiceServer surfaces as HttpClientErrorException.NotFound ==
|
||||
|
||||
requestTo("http://hr-api.example.com/employees/99") -> 404 Not Found
|
||||
exception class = org.springframework.web.client.HttpClientErrorException$NotFound
|
||||
exception.getStatusCode() = 404 NOT_FOUND
|
||||
@@ -0,0 +1,4 @@
|
||||
== A declarative @HttpExchange interface client, mocked the same way as a hand-written one ==
|
||||
|
||||
requestTo("http://hr-api.example.com/employees/3") -> 200 OK {"id":3,"firstName":"Daniel","lastName":"O","email":"[email protected]"}
|
||||
result = Employee[id=3, firstName=Daniel, lastName=O, [email protected]]
|
||||
@@ -0,0 +1,26 @@
|
||||
# ScratchRelativeRequestToFailsDemoTest - run once to capture this real failure, then deleted.
|
||||
# Reproduces EmployeeClient (RestClient.Builder.baseUrl("http://hr-api.example.com")) with a
|
||||
# relative mockServer.expect(requestTo("/employees/1")) - the pattern that works fine for
|
||||
# EmployeeTemplateClient's RestTemplateBuilder.rootUri(). See scripts/run-all.sh to regenerate.
|
||||
|
||||
java.lang.AssertionError: Request URI expected:</employees/1> but was:<http://hr-api.example.com/employees/1>
|
||||
at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:62)
|
||||
at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:129)
|
||||
at org.springframework.test.web.client.match.MockRestRequestMatchers.lambda$requestTo$1(MockRestRequestMatchers.java:92)
|
||||
at org.springframework.test.web.client.DefaultRequestExpectation.match(DefaultRequestExpectation.java:86)
|
||||
at org.springframework.test.web.client.SimpleRequestExpectationManager.matchRequest(SimpleRequestExpectationManager.java:62)
|
||||
at org.springframework.test.web.client.AbstractRequestExpectationManager.validateRequest(AbstractRequestExpectationManager.java:92)
|
||||
at org.springframework.test.web.client.MockRestServiceServer$MockClientHttpRequestFactory$1.executeInternal(MockRestServiceServer.java:342)
|
||||
at org.springframework.mock.http.client.MockClientHttpRequest.execute(MockClientHttpRequest.java:140)
|
||||
at org.springframework.web.client.DefaultRestClient$DefaultRequestBodyUriSpec.exchangeInternal(DefaultRestClient.java:614)
|
||||
at org.springframework.web.client.DefaultRestClient$DefaultRequestBodyUriSpec.exchange(DefaultRestClient.java:572)
|
||||
at org.springframework.web.client.RestClient$RequestHeadersSpec.exchange(RestClient.java:747)
|
||||
at org.springframework.web.client.DefaultRestClient$DefaultResponseSpec.executeAndExtract(DefaultRestClient.java:924)
|
||||
at org.springframework.web.client.DefaultRestClient$DefaultResponseSpec.body(DefaultRestClient.java:833)
|
||||
at com.ankurm.restclienttest.EmployeeClient.getEmployeeById(EmployeeClient.java:31)
|
||||
at com.ankurm.restclienttest.ScratchRelativeRequestToFailsDemoTest.whenRequestToIsRelative_thenMismatch(ScratchRelativeRequestToFailsDemoTest.java:36)
|
||||
|
||||
[INFO]
|
||||
[INFO] Results:
|
||||
[INFO]
|
||||
[ERROR] Failures:
|
||||
@@ -0,0 +1,8 @@
|
||||
# mvn dependency:tree, trimmed to the spring-boot-starter-restclient / Jackson subtree.
|
||||
# Full raw output has an "[INFO] " prefix on every line, stripped here for quoting.
|
||||
|
||||
| +- org.springframework.boot:spring-boot-starter-jackson:jar:4.1.1:compile
|
||||
| | \- org.springframework.boot:spring-boot-jackson:jar:4.1.1:compile
|
||||
| | \- tools.jackson.core:jackson-databind:jar:3.1.5:compile
|
||||
| | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.21:compile
|
||||
| | \- tools.jackson.core:jackson-core:jar:3.1.5:compile
|
||||
Reference in New Issue
Block a user