Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring webflux WebTestClient with query parameter

In my webflux application, i have this GET endpoint

v3/callback?state=cGF5bWVudGlkPTRiMmZlMG

I am trying to write an integration test using WebTestClient

@Test
public void happyScenario() {
    webTestClient.get().uri("/v3/callback?state=cGF5bWVudGlkPTRiMmZlMG")
            .exchange()
            .expectStatus()
            .isOk();
}

This test case return 404 notFound, if i removed the query parameter it will be called but the state parameter it will be missing

I tried to use attribute

  webTestClient.get().uri("/v3/callback")
            .attribute("state","cGF5bWVudGlkPTRiMmZlMG")
            .exchange()
            .expectStatus()
            .isOk();

but still the state parameter is missing, How can i include a query parameter with request when using webTestClient ?

like image 937
Melad Basilius Avatar asked Oct 16 '19 09:10

Melad Basilius


1 Answers

You can make use of UriBuilder.

webTestClient.get()
            .uri(uriBuilder ->
                    uriBuilder
                            .path("/v3/callback")
                            .queryParam("state", "cGF5bWVudGlkPTRiMmZlMG")
                            .build())
            .exchange()
            .expectStatus()
            .isOk();

This should work.

like image 59
Akhil Bojedla Avatar answered Oct 06 '22 00:10

Akhil Bojedla