Browse Source

Polish

pull/1338/merge
Rossen Stoyanchev 9 years ago
parent
commit
5237e47e66
  1. 12
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java
  2. 31
      spring-webflux/src/test/java/org/springframework/web/reactive/result/view/UrlBasedViewResolverTests.java
  3. 4
      spring-webflux/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java

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

@ -18,9 +18,7 @@ package org.springframework.web.reactive.result.method.annotation;
import java.io.IOException; import java.io.IOException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.Proxy;
import java.net.URI; import java.net.URI;
import java.net.URL;
import java.util.Optional; import java.util.Optional;
import org.junit.Test; 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.GetMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.RestTemplate; 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.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.reactive.result.view.freemarker.FreeMarkerConfigurer;
import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebExchange;
@ -102,12 +101,13 @@ public class RequestMappingViewResolutionIntegrationTests extends AbstractReques
@Configuration @Configuration
@EnableWebFlux
@ComponentScan(resourcePattern = "**/RequestMappingViewResolutionIntegrationTests$*.class") @ComponentScan(resourcePattern = "**/RequestMappingViewResolutionIntegrationTests$*.class")
@SuppressWarnings({"unused", "WeakerAccess"}) @SuppressWarnings({"unused", "WeakerAccess"})
static class WebConfig extends WebFluxConfigurationSupport { static class WebConfig implements WebFluxConfigurer {
@Override @Override
protected void configureViewResolvers(ViewResolverRegistry registry) { public void configureViewResolvers(ViewResolverRegistry registry) {
registry.freeMarker(); registry.freeMarker();
} }
@ -122,7 +122,7 @@ public class RequestMappingViewResolutionIntegrationTests extends AbstractReques
@Controller @Controller
@SuppressWarnings("unused") @SuppressWarnings({"unused", "OptionalUsedAsFieldOrParameterType"})
private static class TestController { private static class TestController {
@GetMapping("/html") @GetMapping("/html")

31
spring-webflux/src/test/java/org/springframework/web/reactive/result/view/UrlBasedViewResolverTests.java

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

4
spring-webflux/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java

@ -65,7 +65,9 @@ import static org.springframework.core.ResolvableType.*;
import static org.springframework.http.MediaType.*; 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 * @author Rossen Stoyanchev
*/ */
public class ViewResolutionResultHandlerTests { public class ViewResolutionResultHandlerTests {

Loading…
Cancel
Save