Java Code Examples for org.springframework.test.web.reactive.server.WebTestClient#ResponseSpec

The following examples show how to use org.springframework.test.web.reactive.server.WebTestClient#ResponseSpec . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringDocApp3RedirectDefaultTest.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRedirectWithDefaultQueryParams() throws Exception {
	WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/documentation/swagger-ui.html").exchange()
			.expectStatus().isTemporaryRedirect();
	responseSpec.expectHeader()
			.value("Location", Matchers.is("/documentation/webjars/swagger-ui/index.html?configUrl=/documentation/v3/api-docs/swagger-config"));

	webTestClient.get().uri("/documentation/v3/api-docs/swagger-config").exchange()
			.expectStatus().isOk().expectBody()
			.jsonPath("$.validatorUrl").isEqualTo("")
			.jsonPath("$.oauth2RedirectUrl").isEqualTo("/documentation/webjars/swagger-ui/oauth2-redirect.html");
}
 
Example 2
Source File: SpringDocApp3RedirectWithPrefixTest.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRedirectWithPrefix() throws Exception {
	WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/documentation/swagger-ui.html").exchange()
			.expectStatus().isTemporaryRedirect();
	responseSpec.expectHeader()
			.value("Location", Matchers.is("/documentation/webjars-pref/swagger-ui/index.html?configUrl=/documentation/v3/api-docs/swagger-config"));
	webTestClient.get().uri("/documentation/webjars-pref/swagger-ui/index.html").exchange()
			.expectStatus().isOk();
	webTestClient.get().uri("/documentation/v3/api-docs/swagger-config").exchange()
			.expectStatus().isOk().expectBody().jsonPath("$.validatorUrl").isEqualTo("");
}
 
Example 3
Source File: SpringDocApp1RedirectQueryParams1Test.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRedirectWithQueryParamsWithoutOauth2() throws Exception {

	WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/swagger-ui.html").exchange()
			.expectStatus().isTemporaryRedirect();
	responseSpec.expectHeader()
			.value("Location", Matchers.is("/webjars/swagger-ui/index.html?url=/v3/api-docs"));

}
 
Example 4
Source File: SpringDocApp1RedirectWithConfigTest.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRedirectWithConfiguredParams() throws Exception {
	WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/swagger-ui.html").exchange()
			.expectStatus().isTemporaryRedirect();

	responseSpec.expectHeader()
			.value("Location", Matchers.is("/webjars/swagger-ui/index.html?configUrl=/baf/batz/swagger-config"));

	webTestClient.get().uri("/baf/batz/swagger-config").exchange()
			.expectStatus().isOk().expectBody().jsonPath("$.validatorUrl").isEqualTo("/foo/validate");
}
 
Example 5
Source File: SpringDocApp1RedirectQueryParams2Test.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRedirectWithQueryParams() throws Exception {

	WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/swagger-ui.html").exchange()
			.expectStatus().isTemporaryRedirect();
	responseSpec.expectHeader()
			.value("Location", Matchers.is("/webjars/swagger-ui/index.html?oauth2RedirectUrl=/webjars/swagger-ui/oauth2-redirect.html&url=/v3/api-docs"));

}
 
Example 6
Source File: SpringDocApp1RedirecFilterTest.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRedirectWithConfigUrlIgnoringQueryParams() throws Exception {

	WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/swagger-ui.html").exchange()
			.expectStatus().isTemporaryRedirect();
	responseSpec.expectHeader()
			.value("Location", Matchers.is("/webjars/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config&filter=false"));

}
 
Example 7
Source File: SpringDocApp1RedirectDefaultTest.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRedirectWithDefaultQueryParams() throws Exception {
	WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/swagger-ui.html").exchange()
			.expectStatus().isTemporaryRedirect();
	responseSpec.expectHeader()
			.value("Location", Matchers.is("/webjars/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config"));

	webTestClient.get().uri("/v3/api-docs/swagger-config").exchange()
			.expectStatus().isOk().expectBody().jsonPath("$.validatorUrl").isEqualTo("");

}
 
Example 8
Source File: SpringDocApp1RedirectConfigUrlTest.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRedirectWithConfigUrlIgnoringQueryParams() throws Exception {

	WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/swagger-ui.html").exchange()
			.expectStatus().isTemporaryRedirect();
	responseSpec.expectHeader()
			.value("Location", Matchers.is("/webjars/swagger-ui/index.html?configUrl=/foo/bar"));

}
 
Example 9
Source File: SpringDocApp1RedirectLayoutTest.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRedirectWithConfigUrlIgnoringQueryParams() throws Exception {

	WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/swagger-ui.html").exchange()
			.expectStatus().isTemporaryRedirect();
	responseSpec.expectHeader()
			.value("Location", Matchers.is("/webjars/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config&layout=BaseLayout"));

}
 
Example 10
Source File: ApiGatewayApplicationTests.java    From java-microservices-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testCorsConfiguration() {
    Jwt jwt = jwt();
    when(this.jwtDecoder.decode(anyString())).thenReturn(Mono.just(jwt));
    WebTestClient.ResponseSpec response = webTestClient.put().uri("/")
            .headers(addJwt(jwt))
            .header("Origin", "http://example.com")
            .exchange();

    response.expectHeader().valueEquals("Access-Control-Allow-Origin", "*");
}
 
Example 11
Source File: TimeoutLiveTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void shouldNotTimeout() {
    WebTestClient.ResponseSpec response = webTestClient.get()
      .uri("/timeout/{timeout}", 1)
      .exchange();
    response.expectStatus()
      .isOk()
      .expectBody(String.class)
      .isEqualTo("OK");
}
 
Example 12
Source File: SetStatusGatewayFilterFactoryTests.java    From spring-cloud-gateway with Apache License 2.0 4 votes vote down vote up
private WebTestClient.ResponseSpec setStatusStringTest(String host,
		HttpStatus status) {
	return testClient.get().uri("/headers").header("Host", host).exchange()
			.expectStatus().isEqualTo(status);
}