Search in sources :

Example 11 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.

the class DefaultServerRequestTests method pathVariable.

@Test
public void pathVariable() {
    MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("https://example.com"));
    Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
    exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
    DefaultServerRequest request = new DefaultServerRequest(exchange, messageReaders);
    assertThat(request.pathVariable("foo")).isEqualTo("bar");
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.

the class DefaultServerRequestTests method cookies.

@Test
public void cookies() {
    HttpCookie cookie = new HttpCookie("foo", "bar");
    MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.method(HttpMethod.GET, "https://example.com").cookie(cookie));
    DefaultServerRequest request = new DefaultServerRequest(exchange, messageReaders);
    MultiValueMap<String, HttpCookie> expected = new LinkedMultiValueMap<>();
    expected.add("foo", cookie);
    assertThat(request.cookies()).isEqualTo(expected);
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) HttpCookie(org.springframework.http.HttpCookie) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.

the class DefaultServerRequestTests method pathVariableNotFound.

@Test
public void pathVariableNotFound() {
    MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("https://example.com"));
    Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
    exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
    DefaultServerRequest request = new DefaultServerRequest(exchange, messageReaders);
    assertThatIllegalArgumentException().isThrownBy(() -> request.pathVariable("baz"));
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.

the class ResourceTransformerSupportTests method resolveUrlPathWithRelativePath.

@Test
public void resolveUrlPathWithRelativePath() {
    Resource resource = getResource("main.css");
    MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get(""));
    String actual = this.transformer.resolveUrlPath("bar.css", exchange, resource, this.chain).block(TIMEOUT);
    assertThat(actual).isEqualTo("bar-11e16cf79faee7ac698c805cf28248d2.css");
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Example 15 with MockServerWebExchange

use of org.springframework.web.testfixture.server.MockServerWebExchange in project spring-framework by spring-projects.

the class ResourceTransformerSupportTests method toAbsolutePath.

@Test
public void toAbsolutePath() {
    MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/resources/main.css"));
    String absolute = this.transformer.toAbsolutePath("img/image.png", exchange);
    assertThat(absolute).isEqualTo("/resources/img/image.png");
    absolute = this.transformer.toAbsolutePath("/img/image.png", exchange);
    assertThat(absolute).isEqualTo("/img/image.png");
}
Also used : MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Test(org.junit.jupiter.api.Test)

Aggregations

MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)224 Test (org.junit.jupiter.api.Test)216 MockServerHttpRequest (org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest)61 ClassPathResource (org.springframework.core.io.ClassPathResource)26 HttpHeaders (org.springframework.http.HttpHeaders)25 Resource (org.springframework.core.io.Resource)24 HandlerResult (org.springframework.web.reactive.HandlerResult)23 MethodParameter (org.springframework.core.MethodParameter)22 MockServerHttpResponse (org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse)22 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)19 MediaType (org.springframework.http.MediaType)19 Mono (reactor.core.publisher.Mono)18 BeforeEach (org.junit.jupiter.api.BeforeEach)17 HttpMethod (org.springframework.http.HttpMethod)15 StepVerifier (reactor.test.StepVerifier)13 Arrays (java.util.Arrays)12 Collections (java.util.Collections)12 List (java.util.List)12 HttpStatus (org.springframework.http.HttpStatus)12 IOException (java.io.IOException)10