From 226c9f9a73d9468b5c0b1c7dfc35700619e06386 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Mon, 27 Feb 2017 17:14:56 -0500 Subject: [PATCH] Add WebFlux redirect integration test case Issue: SPR-15291 --- ...MappingViewResolutionIntegrationTests.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java index 66e4063d702..16db9e768b8 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java @@ -16,10 +16,15 @@ package org.springframework.web.reactive.result.method.annotation; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.Proxy; import java.net.URI; +import java.net.URL; import java.util.Optional; import org.junit.Test; +import reactor.core.publisher.Mono; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -30,16 +35,19 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; +import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.client.RestTemplate; import org.springframework.web.reactive.config.ViewResolverRegistry; import org.springframework.web.reactive.config.WebFluxConfigurationSupport; import org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer; import org.springframework.web.server.ServerWebExchange; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; /** * {@code @RequestMapping} integration tests with view resolution scenarios. @@ -73,6 +81,25 @@ public class RequestMappingViewResolutionIntegrationTests extends AbstractReques assertNull(response.getBody()); } + @Test // SPR-15291 + public void redirect() throws Exception { + SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory() { + + @Override + protected void prepareConnection(HttpURLConnection conn, String method) throws IOException { + super.prepareConnection(conn, method); + conn.setInstanceFollowRedirects(false); + } + }; + + URI uri = new URI("http://localhost:" + this.port + "/redirect"); + RequestEntity request = RequestEntity.get(uri).accept(MediaType.ALL).build(); + ResponseEntity response = new RestTemplate(factory).exchange(request, Void.class); + + assertEquals(HttpStatus.SEE_OTHER, response.getStatusCode()); + assertEquals("/", response.getHeaders().getLocation().toString()); + } + @Configuration @ComponentScan(resourcePattern = "**/RequestMappingViewResolutionIntegrationTests$*.class") @@ -108,6 +135,11 @@ public class RequestMappingViewResolutionIntegrationTests extends AbstractReques model.addAttribute("hello", "Hello: " + name.orElse("") + "!"); return "test"; } + + @GetMapping("/redirect") + public Mono redirect() { + return Mono.just("redirect:/"); + } } }