Add WebFlux redirect integration test case
Issue: SPR-15291
This commit is contained in:
parent
40ae8d41a4
commit
226c9f9a73
|
|
@ -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<Void> request = RequestEntity.get(uri).accept(MediaType.ALL).build();
|
||||
ResponseEntity<Void> 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("<no name>") + "!");
|
||||
return "test";
|
||||
}
|
||||
|
||||
@GetMapping("/redirect")
|
||||
public Mono<String> redirect() {
|
||||
return Mono.just("redirect:/");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue