List of usage examples for org.springframework.web.context.support StaticWebApplicationContext StaticWebApplicationContext
public StaticWebApplicationContext()
From source file:fiftyfive.wicket.examples.BaseWicketUnitTest.java
@Before public void createTester() { _tester = new WicketTester(new WicketApplication() { @Override/*from ww w. ja v a 2 s .c o m*/ public String getConfigurationType() { // Don't test in development mode, since debug utilities // can break XHTML compliance. return DEPLOYMENT; } @Override protected ApplicationContext getApplicationContext() { // Provide a static Spring context that can be configured // with mock beans for testing purposes. StaticWebApplicationContext context; context = new StaticWebApplicationContext(); initSpringContext(context); return context; } @Override public WicketSession newSession(Request request, Response response) { // Enforce a singleton session object to be used for the entire // test. This allows us to modify the contents of the session // with prerequisite values before starting a test. if (null == _session) { _session = super.newSession(request, response); } return _session; } }); }
From source file:org.hdiv.web.servlet.view.freemarker.FreeMarkerMacroTests.java
public void setUp() throws Exception { wac = new StaticWebApplicationContext(); wac.setServletContext(new MockServletContext()); //final Template expectedTemplate = new Template(); fc = new FreeMarkerConfigurer(); fc.setPreferFileSystemAccess(false); fc.afterPropertiesSet();//from www . ja va 2s .c om wac.getDefaultListableBeanFactory().registerSingleton("freeMarkerConfigurer", fc); wac.refresh(); request = new MockHttpServletRequest(); request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver()); request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver()); response = new MockHttpServletResponse(); }
From source file:net.sourceforge.vulcan.web.ServletTestCase.java
@Override public void setUp() throws Exception { wac = new StaticWebApplicationContext(); ((AbstractMessageSource) wac.getBean(AbstractApplicationContext.MESSAGE_SOURCE_BEAN_NAME)) .setUseCodeAsDefaultMessage(true); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); mgr = createStrictMock(StateAndProjectManager.class); wac.getBeanFactory().registerSingleton(Keys.STATE_MANAGER, mgr); buildManager = createStrictMock(BuildManager.class); wac.getBeanFactory().registerSingleton(Keys.BUILD_MANAGER, buildManager); wac.getBeanFactory().registerSingleton(Keys.EVENT_POOL, Boolean.TRUE); eventHandler = createStrictMock(EventHandler.class); wac.getBeanFactory().registerSingleton(Keys.EVENT_HANDLER, eventHandler); }
From source file:net.sf.json.spring.web.servlet.view.JsonViewTest.java
protected void setUp() throws Exception { servletContext = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(servletContext); servletRequest = new MockHttpServletRequest(servletContext); servletResponse = new MockHttpServletResponse(); servletResponse.setBufferSize(100);/* ww w. j a v a2s . c o m*/ jsTester = new JsTester(); jsTester.onSetUp(); }
From source file:org.hdiv.web.servlet.view.freemarker.FreeMarkerViewTests.java
@Test public void testFreeMarkerViewResolver() throws Exception { FreeMarkerConfigurer configurer = new FreeMarkerConfigurer(); configurer.setConfiguration(new FreeMarkerTestConfiguration()); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(new MockServletContext()); wac.getBeanFactory().registerSingleton("configurer", configurer); wac.refresh();/*from w w w .j a va2 s . c om*/ FreeMarkerViewResolver vr = new FreeMarkerViewResolver(); vr.setPrefix("prefix_"); vr.setSuffix("_suffix"); vr.setApplicationContext(wac); View view = vr.resolveViewName("test", Locale.CANADA); assertEquals("Correct view class", FreeMarkerView.class, view.getClass()); assertEquals("Correct URL", "prefix_test_suffix", ((FreeMarkerView) view).getUrl()); view = vr.resolveViewName("non-existing", Locale.CANADA); assertNull(view); view = vr.resolveViewName("redirect:myUrl", Locale.getDefault()); assertEquals("Correct view class", RedirectView.class, view.getClass()); assertEquals("Correct URL", "myUrl", ((RedirectView) view).getUrl()); view = vr.resolveViewName("forward:myUrl", Locale.getDefault()); assertEquals("Correct view class", InternalResourceView.class, view.getClass()); assertEquals("Correct URL", "myUrl", ((InternalResourceView) view).getUrl()); }
From source file:com.javaetmoi.core.mvc.tag.TestHtml5InputTag.java
protected MockPageContext createPageContext() { MockServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc);/*from w ww. j a v a2 s. c om*/ wac.setNamespace("test"); wac.registerSingleton("validator", org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.class); wac.refresh(); MockHttpServletRequest request = new MockHttpServletRequest(sc); MockHttpServletResponse response = new MockHttpServletResponse(); request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); LocaleResolver lr = new AcceptHeaderLocaleResolver(); request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, lr); ThemeResolver tr = new FixedThemeResolver(); request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, tr); request.setAttribute(DispatcherServlet.THEME_SOURCE_ATTRIBUTE, wac); return new MockPageContext(sc, request, response); }
From source file:org.hdiv.AbstractHDIVTestCase.java
protected final void setUp() throws Exception { String[] files = { "/org/hdiv/config/hdiv-core-applicationContext.xml", "/org/hdiv/config/hdiv-config.xml", "/org/hdiv/config/hdiv-validations.xml", "/org/hdiv/config/applicationContext-test.xml", "/org/hdiv/config/applicationContext-extra.xml" }; if (this.applicationContext == null) { this.applicationContext = new ClassPathXmlApplicationContext(files); }/*from ww w .ja va 2 s .co m*/ // Servlet API mock HttpServletRequest request = (MockHttpServletRequest) this.applicationContext.getBean("mockRequest"); HttpSession httpSession = request.getSession(); ServletContext servletContext = httpSession.getServletContext(); HDIVUtil.setHttpServletRequest(request); // Put Spring context on ServletContext StaticWebApplicationContext webApplicationContext = new StaticWebApplicationContext(); webApplicationContext.setServletContext(servletContext); webApplicationContext.setParent(this.applicationContext); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webApplicationContext); // Initialize config this.config = (HDIVConfig) this.applicationContext.getBean("config"); InitListener initListener = new InitListener(); // Initialize ServletContext ServletContextEvent servletContextEvent = new ServletContextEvent(servletContext); initListener.contextInitialized(servletContextEvent); // Initialize HttpSession HttpSessionEvent httpSessionEvent = new HttpSessionEvent(httpSession); initListener.sessionCreated(httpSessionEvent); // Initialize request ServletRequestEvent requestEvent = new ServletRequestEvent(servletContext, request); initListener.requestInitialized(requestEvent); if (log.isDebugEnabled()) { log.debug("Hdiv test context initialized"); } onSetUp(); }
From source file:org.hdiv.hateoas.jackson.AbstractHDIVTestCase.java
protected void setUp() throws Exception { String[] files = { "/org/hdiv/config/hdiv-core-applicationContext.xml", "/org/hdiv/config/hdiv-config.xml", "/org/hdiv/config/hdiv-validations.xml", "/org/hdiv/config/applicationContext-test.xml", "/org/hdiv/config/applicationContext-extra.xml" }; if (this.applicationContext == null) { this.applicationContext = new ClassPathXmlApplicationContext(files); }//from ww w. jav a 2 s . co m // Servlet API mock HttpServletRequest request = (MockHttpServletRequest) this.applicationContext.getBean("mockRequest"); HttpSession httpSession = request.getSession(); ServletContext servletContext = httpSession.getServletContext(); HDIVUtil.setHttpServletRequest(request); // Put Spring context on ServletContext StaticWebApplicationContext webApplicationContext = new StaticWebApplicationContext(); webApplicationContext.setServletContext(servletContext); webApplicationContext.setParent(this.applicationContext); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webApplicationContext); // Initialize config this.config = (HDIVConfig) this.applicationContext.getBean("config"); InitListener initListener = new InitListener(); // Initialize ServletContext ServletContextEvent servletContextEvent = new ServletContextEvent(servletContext); initListener.contextInitialized(servletContextEvent); // Initialize HttpSession HttpSessionEvent httpSessionEvent = new HttpSessionEvent(httpSession); initListener.sessionCreated(httpSessionEvent); // Initialize request ServletRequestEvent requestEvent = new ServletRequestEvent(servletContext, request); initListener.requestInitialized(requestEvent); if (log.isDebugEnabled()) { log.debug("Hdiv test context initialized"); } onSetUp(); }
From source file:org.springframework.faces.mvc.servlet.FacesHandlerAdapterTests.java
protected void setUp() throws Exception { super.setUp(); this.adapter = new FacesHandlerAdapter(); this.adapter.setBeanName("testAdapterBean"); this.context = new StaticWebApplicationContext(); adapter.setApplicationContext(context); adapter.setFacesServletClass(TrackingMockServlet.class); }