Search in sources :

Example 1 with InternalResourceViewResolver

use of cn.taketoday.web.servlet.view.InternalResourceViewResolver in project today-infrastructure by TAKETODAY.

the class ContentNegotiatingViewResolverTests method nestedViewResolverIsNotSpringBean.

@Test
public void nestedViewResolverIsNotSpringBean() throws Exception {
    StaticWebServletApplicationContext webAppContext = new StaticWebServletApplicationContext();
    webAppContext.setServletContext(new MockServletContext());
    webAppContext.refresh();
    InternalResourceViewResolver nestedResolver = new InternalResourceViewResolver();
    nestedResolver.setApplicationContext(webAppContext);
    nestedResolver.setViewClass(InternalResourceView.class);
    viewResolver.setViewResolvers(new ArrayList<>(Arrays.asList(nestedResolver)));
    FixedContentNegotiationStrategy fixedStrategy = new FixedContentNegotiationStrategy(MediaType.TEXT_HTML);
    viewResolver.setContentNegotiationManager(new ContentNegotiationManager(fixedStrategy));
    viewResolver.afterPropertiesSet();
    String viewName = "view";
    Locale locale = Locale.ENGLISH;
    View result = viewResolver.resolveViewName(viewName, locale);
    assertThat(result).as("Invalid view").isNotNull();
}
Also used : Locale(java.util.Locale) ContentNegotiationManager(cn.taketoday.web.accept.ContentNegotiationManager) FixedContentNegotiationStrategy(cn.taketoday.web.accept.FixedContentNegotiationStrategy) StaticWebServletApplicationContext(cn.taketoday.web.context.support.StaticWebServletApplicationContext) InternalResourceView(cn.taketoday.web.servlet.view.InternalResourceView) MockServletContext(cn.taketoday.web.mock.MockServletContext) InternalResourceViewResolver(cn.taketoday.web.servlet.view.InternalResourceViewResolver) Test(org.junit.jupiter.api.Test)

Example 2 with InternalResourceViewResolver

use of cn.taketoday.web.servlet.view.InternalResourceViewResolver in project today-infrastructure by TAKETODAY.

the class ViewResolverTests method cacheRemoval.

@Test
public void cacheRemoval() throws Exception {
    this.wac.refresh();
    InternalResourceViewResolver vr = new InternalResourceViewResolver();
    vr.setViewClass(JstlView.class);
    vr.setApplicationContext(this.wac);
    View view = vr.resolveViewName("example1", Locale.getDefault());
    View cached = vr.resolveViewName("example1", Locale.getDefault());
    assertThat(cached).isSameAs(view);
    vr.removeFromCache("example1", Locale.getDefault());
    cached = vr.resolveViewName("example1", Locale.getDefault());
    // the chance of having the same reference (hashCode) twice is negligible.
    assertThat(cached).as("removed from cache").isNotSameAs(view);
}
Also used : JstlView(cn.taketoday.web.servlet.view.JstlView) InternalResourceView(cn.taketoday.web.servlet.view.InternalResourceView) InternalResourceViewResolver(cn.taketoday.web.servlet.view.InternalResourceViewResolver) Test(org.junit.jupiter.api.Test)

Example 3 with InternalResourceViewResolver

use of cn.taketoday.web.servlet.view.InternalResourceViewResolver in project today-infrastructure by TAKETODAY.

the class WebMvcAutoConfiguration method defaultViewResolver.

@Component
@ConditionalOnMissingBean
public InternalResourceViewResolver defaultViewResolver() {
    InternalResourceViewResolver resolver = new InternalResourceViewResolver();
    resolver.setPrefix(this.mvcProperties.getView().getPrefix());
    resolver.setSuffix(this.mvcProperties.getView().getSuffix());
    return resolver;
}
Also used : InternalResourceViewResolver(cn.taketoday.web.servlet.view.InternalResourceViewResolver) ConditionalOnMissingBean(cn.taketoday.context.condition.ConditionalOnMissingBean) Component(cn.taketoday.lang.Component)

Example 4 with InternalResourceViewResolver

use of cn.taketoday.web.servlet.view.InternalResourceViewResolver in project today-framework by TAKETODAY.

the class ViewResolverRegistryTests method customViewResolver.

@Test
public void customViewResolver() {
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver("/", ".jsp");
    this.registry.viewResolver(viewResolver);
    assertThat(this.registry.getViewResolvers().get(0)).isSameAs(viewResolver);
}
Also used : InternalResourceViewResolver(cn.taketoday.web.servlet.view.InternalResourceViewResolver) Test(org.junit.jupiter.api.Test)

Example 5 with InternalResourceViewResolver

use of cn.taketoday.web.servlet.view.InternalResourceViewResolver in project today-framework by TAKETODAY.

the class ViewResolverRegistryTests method jspDefaultValues.

@Test
public void jspDefaultValues() {
    this.registry.jsp();
    InternalResourceViewResolver resolver = checkAndGetResolver(InternalResourceViewResolver.class);
    checkPropertyValues(resolver, "prefix", "/WEB-INF/", "suffix", ".jsp");
}
Also used : InternalResourceViewResolver(cn.taketoday.web.servlet.view.InternalResourceViewResolver) Test(org.junit.jupiter.api.Test)

Aggregations

InternalResourceViewResolver (cn.taketoday.web.servlet.view.InternalResourceViewResolver)24 Test (org.junit.jupiter.api.Test)20 InternalResourceView (cn.taketoday.web.servlet.view.InternalResourceView)14 JstlView (cn.taketoday.web.servlet.view.JstlView)10 HashMap (java.util.HashMap)8 Locale (java.util.Locale)8 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)6 StaticWebServletApplicationContext (cn.taketoday.web.context.support.StaticWebServletApplicationContext)4 AcceptHeaderLocaleResolver (cn.taketoday.web.i18n.AcceptHeaderLocaleResolver)4 FixedLocaleResolver (cn.taketoday.web.i18n.FixedLocaleResolver)4 LocalizationContext (jakarta.servlet.jsp.jstl.fmt.LocalizationContext)4 Properties (java.util.Properties)4 ConditionalOnMissingBean (cn.taketoday.context.condition.ConditionalOnMissingBean)2 Component (cn.taketoday.lang.Component)2 ContentNegotiationManager (cn.taketoday.web.accept.ContentNegotiationManager)2 FixedContentNegotiationStrategy (cn.taketoday.web.accept.FixedContentNegotiationStrategy)2 MockServletContext (cn.taketoday.web.mock.MockServletContext)2 ServletRequestContext (cn.taketoday.web.servlet.ServletRequestContext)2 MockServletContext (cn.taketoday.web.testfixture.servlet.MockServletContext)2