@Override protected WebApplicationContext initWebAppContext() { MockServletContext servletContext = new MockServletContext(); StubWebApplicationContext wac = new StubWebApplicationContext(servletContext); registerMvcSingletons(wac); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); return wac; }
/** * See SPR-12553 and SPR-13075. */ @Test public void rootWacServletContainerAttributePreviouslySet() { StubWebApplicationContext child = new StubWebApplicationContext(this.servletContext); this.servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, child); DefaultMockMvcBuilder builder = webAppContextSetup(child); assertSame(builder.initWebAppContext(), WebApplicationContextUtils.getRequiredWebApplicationContext(this.servletContext)); }
/** * See SPR-12553 and SPR-13075. */ @Test public void rootWacServletContainerAttributePreviouslySetWithContextHierarchy() { StubWebApplicationContext root = new StubWebApplicationContext(this.servletContext); this.servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, root); StaticWebApplicationContext child = new StaticWebApplicationContext(); child.setParent(root); child.setServletContext(this.servletContext); DefaultMockMvcBuilder builder = webAppContextSetup(child); assertSame(builder.initWebAppContext().getParent(), WebApplicationContextUtils.getRequiredWebApplicationContext(this.servletContext)); }
servletContext.setAttribute( WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext);
servletContext.setAttribute( WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext);
@Override protected void setupBeforeInitDispatcher() throws Exception { this.servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext); }
@Override protected void setupBeforeInitDispatcher() throws Exception { this.servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext); }
@Override protected void setupBeforeInitDispatcher() throws Exception { servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext); }
@Override protected void setupBeforeInitDispatcher() { this.servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext); }
@Override protected void setupBeforeInitDispatcher() { servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext); }
@Override public final ConfigurableApplicationContext loadContext(String... locations) throws Exception { XmlWebApplicationContext context = new XmlWebApplicationContext(); context.setConfigLocations(locations); MockServletContext sc = new MockServletContext(); sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context); context.setServletContext(sc); context.refresh(); return context; }
/** {@inheritDoc} */ public void setAttribute(String name, Object object) { if (servletContext == null) { super.setAttribute(name, object); return; } if (name == null) { throw new IllegalArgumentException("Attribute name == null"); } servletContext.setAttribute(name, object); }
@Autowired private WebApplicationContext webAppContext; @Before public void mockInit() { MockServletContext mockServletContext = new MockServletContext(); mockServletContext.setAttribute( WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webAppContext); new MyListener().contextInitialized(new ServletContextEvent( mockServletContext)); }
MockServletContext servletContext = new MockServletContextPatched(); MockServletConfig config = new MockServletConfig( servletContext ); ImageServlet servlet = new ImageServlet(); ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( "spring-data-app-context.xml" ); DefaultListableBeanFactory dlbf = new DefaultListableBeanFactory(appContext.getBeanFactory()); GenericWebApplicationContext gwac = new GenericWebApplicationContext(dlbf); servletContext.setAttribute(GenericWebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, gwac); gwac.setServletContext(servletContext); gwac.refresh(); servlet.init( config );
//create parent context ApplicationContext xmlContext = new GenericXmlApplicationContext("classpath:/spring-*.xml"); //create mock servlet context MockServletContext mockServletContext = new MockServletContext(); //create web context GenericWebApplicationContext webContext = new GenericWebApplicationContext(mockServletContext); //set attribute mockServletContext.setAttribute(GenericWebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webContext); //set parent context webContext.setParent(xmlContext); //refresh context webContext.refresh();
protected void setupBeforeInitDispatcher() throws Exception { // only load beans from spring once if (applicationContext == null) { GenericXmlContextLoader xmlContextLoader = new GenericXmlContextLoader(); applicationContext = xmlContextLoader.loadContext(getContextLocations()); } servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext); }
@Override protected WebApplicationContext initWebAppContext() { MockServletContext servletContext = new MockServletContext(); StubWebApplicationContext wac = new StubWebApplicationContext(servletContext); registerMvcSingletons(wac); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); return wac; }
@Override protected WebApplicationContext initWebAppContext() { MockServletContext servletContext = new MockServletContext(); StubWebApplicationContext wac = new StubWebApplicationContext(servletContext); registerMvcSingletons(wac); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); return wac; }
protected void prepareContext(GenericWebApplicationContext context) { MockServletContext servletContext = new MockServletContext(); context.setServletContext(servletContext); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context); } }
protected void setUp() { servletContext = new MockServletContext(); servletContext.setAttribute("aFoo", "bar"); request = new MockHttpServletRequest(); request.setAttribute("rFoo", "bar"); request.getSession(true).setAttribute("sFoo", "bar"); response = new MockHttpServletResponse(); context = new ServletExternalContext(servletContext, request, response); }