/** * See SPR-12553 and SPR-13075. */ @Test public void rootWacServletContainerAttributeNotPreviouslySet() { StubWebApplicationContext root = new StubWebApplicationContext(this.servletContext); DefaultMockMvcBuilder builder = webAppContextSetup(root); WebApplicationContext wac = builder.initWebAppContext(); assertSame(root, wac); assertSame(root, WebApplicationContextUtils.getRequiredWebApplicationContext(this.servletContext)); }
/** * 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)); }
/** * See SPR-12553 and SPR-13075. */ @Test public void rootWacServletContainerAttributeNotPreviouslySetWithContextHierarchy() { StaticApplicationContext ear = new StaticApplicationContext(); StaticWebApplicationContext root = new StaticWebApplicationContext(); root.setParent(ear); root.setServletContext(this.servletContext); StaticWebApplicationContext dispatcher = new StaticWebApplicationContext(); dispatcher.setParent(root); dispatcher.setServletContext(this.servletContext); DefaultMockMvcBuilder builder = webAppContextSetup(dispatcher); WebApplicationContext wac = builder.initWebAppContext(); assertSame(dispatcher, wac); assertSame(root, wac.getParent()); assertSame(ear, wac.getParent().getParent()); assertSame(root, WebApplicationContextUtils.getRequiredWebApplicationContext(this.servletContext)); }