I don't get why #26039 is closed, but I think my use case is valid.
I use WebTestClient
to write integration tests (using my own library based on spring-cloud-wiremock) to test servlet-based applications.
There are no mocks at all and I'm not gonna use MockMvc
, the sample is the following:
@SpringBootTest(
webEnvironment = WebEnvironment.RANDOM_PORT,
classes = SampleApplicationTest.SampleApplication.class)
@TestPropertySource(properties = "server.servlet.context-path=/test")
class SampleApplicationTest {
@Autowired
private TestRestTemplate testRestTemplate;
@Autowired
private WebTestClient webTestClient;
@Test
void shouldReturnResources() {
var actual = testRestTemplate.getForEntity("/resources", String.class);
assertThat(actual.getStatusCode()).isEqualTo(OK);
assertThat(actual.getBody()).isEqualTo("test-resource");
webTestClient.get().uri("/resources").exchange()
// will fail with 404 cos context path is not configured
.expectStatus().isOk()
.expectBody(String.class).isEqualTo("test-resource");
}
@SpringBootApplication
static class SampleApplication {
static void main(String[] args) {
SpringApplication.run(SampleApplication.class, args);
}
@RestController
static class Controller {
@GetMapping("/resources")
String resources() {
return "test-resource";
}
}
}
}
I'd like to have possibility to configure baseUrl for WebTestClient
, so I can allow consumers of the library to use either TestRestTemplate
or WebTestClient
using the same url. Currently there is no way to customize base path for WebTestClient
.
Comment From: rstoyanchev
@20fps there is no need to open new issues.