Introduction: I'm currently writing integration tests for my API Gateway with Zuul Proxy using SpringBootTest. I've already created a working mock microservice on port 8089 returning some json data, to which the gateway application should forward incoming requests.
Problem: Zuul manages to match the routes correctly, however it fails somehow to forward the request, because the response is always an empty HTTP 200, whereas it should contain the json data returned by the mocked microservice. This problem occures only in test . It works fine in production.
Recent observations: While debugging I've figured out that in test, the FilterLoader does not provide any filters of type route, while in production it provides a list of three filters which are then used by the route() method of the ZuulServlet. After the route() method is processed, the response is populated with data obtained from the microservice. It does not happen in test.
I've also tried to replace the mock server with a real one - result was exactly the same.
Question: I would appreciate any advice on this problem ;)
Zuul Config:
logging:
level:
org:
springframework:
cloud:
netflix: trace
ribbon:
eureka:
enabled: false
eureka:
client:
enabled: false
zuul:
routes:
restuarant:
path: /restaurant/**
url: http://localhost:8089
spring:
cloud:
discovery:
enabled: false
...
Test Class Annotations:
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
@AutoConfigureWebTestClient(timeout = "30000")
Calling the tested endpoint
//the mocked microservice has an endpoint http://localhost:8089/restaurants
private WebTestClient.ResponseSpec getResource(String accessToken) {
return webClient.get()
.uri("/restaurant/restaurants")
.accept(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, TokenType.BEARER.getValue() + " " + accessToken)
.exchange();
}
Aucun commentaire:
Enregistrer un commentaire