Java 带查询参数的Spring webflux WebTestClient
在我的webflux应用程序中,我有一个Java 带查询参数的Spring webflux WebTestClient,java,testing,spring-webflux,Java,Testing,Spring Webflux,在我的webflux应用程序中,我有一个GET端点 v3/callback?state=cGF5bWVudGlkPTRiMmZlMG 我正在尝试使用WebTestClient @Test public void happyScenario() { webTestClient.get().uri("/v3/callback?state=cGF5bWVudGlkPTRiMmZlMG") .exchange() .expectStatus()
GET
端点
v3/callback?state=cGF5bWVudGlkPTRiMmZlMG
我正在尝试使用WebTestClient
@Test
public void happyScenario() {
webTestClient.get().uri("/v3/callback?state=cGF5bWVudGlkPTRiMmZlMG")
.exchange()
.expectStatus()
.isOk();
}
这个测试用例返回404notfound
,如果我删除了查询参数,它将被调用,但是state
参数将丢失
我尝试使用属性
webTestClient.get().uri("/v3/callback")
.attribute("state","cGF5bWVudGlkPTRiMmZlMG")
.exchange()
.expectStatus()
.isOk();
但是仍然缺少
state
参数,在使用webTestClient
时如何在请求中包含查询参数?您可以使用UriBuilder
webTestClient.get()
.uri(uriBuilder->
uriBuilder
.path(“/v3/callback”)
.queryParam(“状态”,“cgf5bwvudglptrimmzlmg”)
.build())
.exchange()
.预期状态()
.isOk();
这应该行得通