Skip to content

Commit 226c9f9

Browse files
committed
Add WebFlux redirect integration test case
Issue: SPR-15291
1 parent 40ae8d4 commit 226c9f9

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@
1616

1717
package org.springframework.web.reactive.result.method.annotation;
1818

19+
import java.io.IOException;
20+
import java.net.HttpURLConnection;
21+
import java.net.Proxy;
1922
import java.net.URI;
23+
import java.net.URL;
2024
import java.util.Optional;
2125

2226
import org.junit.Test;
27+
import reactor.core.publisher.Mono;
2328

2429
import org.springframework.context.ApplicationContext;
2530
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -30,16 +35,19 @@
3035
import org.springframework.http.MediaType;
3136
import org.springframework.http.RequestEntity;
3237
import org.springframework.http.ResponseEntity;
38+
import org.springframework.http.client.SimpleClientHttpRequestFactory;
3339
import org.springframework.stereotype.Controller;
3440
import org.springframework.ui.Model;
3541
import org.springframework.web.bind.annotation.GetMapping;
3642
import org.springframework.web.bind.annotation.RequestParam;
43+
import org.springframework.web.client.RestTemplate;
3744
import org.springframework.web.reactive.config.ViewResolverRegistry;
3845
import org.springframework.web.reactive.config.WebFluxConfigurationSupport;
3946
import org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer;
4047
import org.springframework.web.server.ServerWebExchange;
4148

42-
import static org.junit.Assert.*;
49+
import static org.junit.Assert.assertEquals;
50+
import static org.junit.Assert.assertNull;
4351

4452
/**
4553
* {@code @RequestMapping} integration tests with view resolution scenarios.
@@ -73,6 +81,25 @@ public void etagCheckWithNotModifiedResponse() throws Exception {
7381
assertNull(response.getBody());
7482
}
7583

84+
@Test // SPR-15291
85+
public void redirect() throws Exception {
86+
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory() {
87+
88+
@Override
89+
protected void prepareConnection(HttpURLConnection conn, String method) throws IOException {
90+
super.prepareConnection(conn, method);
91+
conn.setInstanceFollowRedirects(false);
92+
}
93+
};
94+
95+
URI uri = new URI("http://localhost:" + this.port + "/redirect");
96+
RequestEntity<Void> request = RequestEntity.get(uri).accept(MediaType.ALL).build();
97+
ResponseEntity<Void> response = new RestTemplate(factory).exchange(request, Void.class);
98+
99+
assertEquals(HttpStatus.SEE_OTHER, response.getStatusCode());
100+
assertEquals("/", response.getHeaders().getLocation().toString());
101+
}
102+
76103

77104
@Configuration
78105
@ComponentScan(resourcePattern = "**/RequestMappingViewResolutionIntegrationTests$*.class")
@@ -108,6 +135,11 @@ public String getHtmlPage(@RequestParam Optional<String> name, Model model,
108135
model.addAttribute("hello", "Hello: " + name.orElse("<no name>") + "!");
109136
return "test";
110137
}
138+
139+
@GetMapping("/redirect")
140+
public Mono<String> redirect() {
141+
return Mono.just("redirect:/");
142+
}
111143
}
112144

113145
}

0 commit comments

Comments
 (0)