'WebTestClient keeps returning 500 despite existing stub / mock

I'm building a Spring Cloud Gateway which is supposed to reach a URI and then the resource under /star_matter. I have the following unit test:

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureWireMock(port = 0)
public class ControllerTest {

  @LocalServerPort int port;
  private WebTestClient client;

  @BeforeEach
  public void setup() {
    client = WebTestClient.bindToServer().baseUrl("http://localhost:" + port).build();
  }

  @Test
  void starMatter_noFIPAuthentication() {
    final String postXMLPayload = "<message>\"Is anybody there?\"</message>";
    stubFor(
        post(urlEqualTo("/star_matter"))
            .willReturn(
                aResponse()
                    .withBody("<message>\"Hello World!\"</message>")
                    .withStatus(200)
                    .withHeader("Content-Type", "text/xml")));

    WebTestClient.ResponseSpec exchangeValue = client.post().uri("/star_matter").bodyValue(postXMLPayload).exchange().expectStatus().is2xxSuccessful();
  }
}

Unfortunately, the wiring doesn't appear to work and I'm hitting a 500, triggering an AssertionError. Any ideas?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source