This commit is contained in:
Rossen Stoyanchev 2017-02-27 17:26:20 -05:00
parent 226c9f9a73
commit 5237e47e66
3 changed files with 27 additions and 20 deletions

View File

@ -18,9 +18,7 @@ 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;
@ -41,8 +39,9 @@ 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.EnableWebFlux;
import org.springframework.web.reactive.config.ViewResolverRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurationSupport;
import org.springframework.web.reactive.config.WebFluxConfigurer;
import org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer;
import org.springframework.web.server.ServerWebExchange;
@ -102,12 +101,13 @@ public class RequestMappingViewResolutionIntegrationTests extends AbstractReques
@Configuration
@EnableWebFlux
@ComponentScan(resourcePattern = "**/RequestMappingViewResolutionIntegrationTests$*.class")
@SuppressWarnings({"unused", "WeakerAccess"})
static class WebConfig extends WebFluxConfigurationSupport {
static class WebConfig implements WebFluxConfigurer {
@Override
protected void configureViewResolvers(ViewResolverRegistry registry) {
public void configureViewResolvers(ViewResolverRegistry registry) {
registry.freeMarker();
}
@ -122,7 +122,7 @@ public class RequestMappingViewResolutionIntegrationTests extends AbstractReques
@Controller
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "OptionalUsedAsFieldOrParameterType"})
private static class TestController {
@GetMapping("/html")

View File

@ -16,6 +16,7 @@
package org.springframework.web.reactive.result.view;
import java.time.Duration;
import java.util.Locale;
import java.util.Map;
@ -41,31 +42,32 @@ public class UrlBasedViewResolverTests {
private UrlBasedViewResolver resolver;
@Before
public void setup() {
StaticApplicationContext context = new StaticApplicationContext();
context.refresh();
resolver = new UrlBasedViewResolver();
resolver.setApplicationContext(context);
this.resolver = new UrlBasedViewResolver();
this.resolver.setApplicationContext(context);
}
@Test
public void viewNames() throws Exception {
resolver.setViewClass(TestView.class);
resolver.setViewNames("my*");
this.resolver.setViewClass(TestView.class);
this.resolver.setViewNames("my*");
Mono<View> mono = resolver.resolveViewName("my-view", Locale.US);
Mono<View> mono = this.resolver.resolveViewName("my-view", Locale.US);
assertNotNull(mono.block());
mono = resolver.resolveViewName("not-my-view", Locale.US);
mono = this.resolver.resolveViewName("not-my-view", Locale.US);
assertNull(mono.block());
}
@Test
public void redirectView() throws Exception {
Mono<View> mono = resolver.resolveViewName("redirect:foo", Locale.US);
assertNotNull(mono.block());
Mono<View> mono = this.resolver.resolveViewName("redirect:foo", Locale.US);
StepVerifier.create(mono)
.consumeNextWith(view -> {
assertEquals(RedirectView.class, view.getClass());
@ -73,14 +75,15 @@ public class UrlBasedViewResolverTests {
assertEquals(redirectView.getUrl(), "foo");
assertEquals(redirectView.getStatusCode(), HttpStatus.SEE_OTHER);
})
.expectComplete();
.expectComplete()
.verify(Duration.ZERO);
}
@Test
public void customizedRedirectView() throws Exception {
resolver.setRedirectViewProvider(url -> new RedirectView(url, HttpStatus.FOUND));
Mono<View> mono = resolver.resolveViewName("redirect:foo", Locale.US);
assertNotNull(mono.block());
this.resolver.setRedirectViewProvider(url -> new RedirectView(url, HttpStatus.FOUND));
Mono<View> mono = this.resolver.resolveViewName("redirect:foo", Locale.US);
StepVerifier.create(mono)
.consumeNextWith(view -> {
assertEquals(RedirectView.class, view.getClass());
@ -88,7 +91,8 @@ public class UrlBasedViewResolverTests {
assertEquals(redirectView.getUrl(), "foo");
assertEquals(redirectView.getStatusCode(), HttpStatus.FOUND);
})
.expectComplete();
.expectComplete()
.verify(Duration.ZERO);
}
@ -102,6 +106,7 @@ public class UrlBasedViewResolverTests {
@Override
protected Mono<Void> renderInternal(Map<String, Object> attributes, MediaType contentType,
ServerWebExchange exchange) {
return Mono.empty();
}
}

View File

@ -65,7 +65,9 @@ import static org.springframework.core.ResolvableType.*;
import static org.springframework.http.MediaType.*;
/**
* Unit tests for {@link ViewResolutionResultHandler}.
* ViewResolutionResultHandler relying on a canned {@link TestViewResolver}
* or a (Mockito) "mock".
*
* @author Rossen Stoyanchev
*/
public class ViewResolutionResultHandlerTests {