|
|
|
@ -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(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|