use of cn.taketoday.web.context.support.StaticWebServletApplicationContext 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();
}
use of cn.taketoday.web.context.support.StaticWebServletApplicationContext in project today-infrastructure by TAKETODAY.
the class ControllerTests method doTestServletForwardingController.
private void doTestServletForwardingController(ServletForwardingController sfc, boolean include) throws Exception {
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
ServletContext context = mock(ServletContext.class);
RequestDispatcher dispatcher = mock(RequestDispatcher.class);
given(request.getMethod()).willReturn("GET");
given(context.getNamedDispatcher("action")).willReturn(dispatcher);
if (include) {
given(request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI)).willReturn("somePath");
} else {
given(request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI)).willReturn(null);
}
StaticWebServletApplicationContext sac = new StaticWebServletApplicationContext();
sac.setServletContext(context);
sfc.setApplicationContext(sac);
sfc.setServletContext(context);
ServletRequestContext servletRequestContext = new ServletRequestContext(sac, request, response);
assertThat(sfc.handleRequest(servletRequestContext)).isNull();
if (include) {
verify(dispatcher).include(request, response);
} else {
verify(dispatcher).forward(request, response);
}
}
use of cn.taketoday.web.context.support.StaticWebServletApplicationContext in project today-infrastructure by TAKETODAY.
the class EnvironmentSystemIntegrationTests method staticWebApplicationContext.
@Test
void staticWebApplicationContext() {
StaticWebServletApplicationContext ctx = new StaticWebServletApplicationContext();
assertHasStandardServletEnvironment(ctx);
registerEnvironmentBeanDefinition(ctx);
ctx.setEnvironment(prodWebEnv);
ctx.refresh();
assertHasEnvironment(ctx, prodWebEnv);
assertEnvironmentBeanRegistered(ctx);
assertEnvironmentAwareInvoked(ctx, prodWebEnv);
}
use of cn.taketoday.web.context.support.StaticWebServletApplicationContext in project today-infrastructure by TAKETODAY.
the class ScriptTemplateViewTests method setup.
@BeforeEach
public void setup() {
this.configurer = new ScriptTemplateConfigurer();
this.wac = new StaticWebServletApplicationContext();
this.wac.getBeanFactory().registerSingleton("scriptTemplateConfigurer", this.configurer);
this.view = new ScriptTemplateView();
}
use of cn.taketoday.web.context.support.StaticWebServletApplicationContext in project today-infrastructure by TAKETODAY.
the class ServletContextSupportTests method testServletContextAttributeFactoryBean.
@Test
@SuppressWarnings("resource")
public void testServletContextAttributeFactoryBean() {
MockServletContext sc = new MockServletContext();
sc.setAttribute("myAttr", "myValue");
StaticWebServletApplicationContext wac = new StaticWebServletApplicationContext();
wac.setServletContext(sc);
PropertyValues pvs = new PropertyValues();
pvs.add("attributeName", "myAttr");
wac.registerSingleton("importedAttr", ServletContextAttributeFactoryBean.class, pvs);
wac.refresh();
Object value = wac.getBean("importedAttr");
assertThat(value).isEqualTo("myValue");
}
Aggregations