Spring Framework StaticWebApplicationContext - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework StaticWebApplicationContext class.

This code example shows how to use the following methods:setServletContext, getBean, refresh, registerSingleton
 
	@Test 
	public void testDelegatingFilterProxyAndCustomContextAttribute() throws ServletException, IOException { 
		ServletContext sc = new MockServletContext(); 
 
		StaticWebApplicationContext wac = new StaticWebApplicationContext(); 
		wac.setServletContext(sc); 
		wac.registerSingleton("targetFilter", MockFilter.class); 
		wac.refresh(); 
		sc.setAttribute("CUSTOM_ATTR", wac); 
 
		MockFilter targetFilter = (MockFilter) wac.getBean("targetFilter"); 
 
		MockFilterConfig proxyConfig = new MockFilterConfig(sc); 
		proxyConfig.addInitParameter("targetBeanName", "targetFilter"); 
		proxyConfig.addInitParameter("contextAttribute", "CUSTOM_ATTR"); 
		DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(); 
		filterProxy.init(proxyConfig); 
 
		MockHttpServletRequest request = new MockHttpServletRequest(); 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setServletContext, getDefaultListableBeanFactory, refresh
				+ "http://www.springframework.org/schema/springfaces/springfaces.xsd\">\n" + content + "\n</beans>"; 
		return loadApplicationContext(new ByteArrayResource(xml.getBytes())); 
	} 
 
	public StaticWebApplicationContext loadApplicationContext(Resource resource) { 
		StaticWebApplicationContext applicationContext = new StaticWebApplicationContext(); 
		applicationContext.setServletContext(new MockServletContext()); 
		XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(applicationContext.getDefaultListableBeanFactory()); 
		reader.loadBeanDefinitions(resource); 
		applicationContext.refresh(); 
		return applicationContext; 
	} 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setServletContext
	private final JSFMockHelper jsfMock = new JSFMockHelper(); 
	private JsfAjaxHandler ajaxHandler; 
 
	protected void setUp() throws Exception { 
		this.jsfMock.setUp(); 
		StaticWebApplicationContext webappContext = new StaticWebApplicationContext(); 
		webappContext.setServletContext(this.jsfMock.servletContext()); 
		this.ajaxHandler = new JsfAjaxHandler(); 
		this.ajaxHandler.setApplicationContext(webappContext); 
	} 
 
	protected void tearDown() throws Exception { 
		this.jsfMock.tearDown(); 
	} 
 
	public void testSendAjaxRedirect() throws Exception { 
		this.ajaxHandler.sendAjaxRedirectInternal("/target", this.jsfMock.request(), this.jsfMock.response(), false); 
		assertTrue(this.jsfMock.contentAsString().matches("<partial-response.*><redirect url=\"/target\"/></partial-response>")); 
		assertEquals("application/xml", this.jsfMock.response().getContentType()); 
	} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:registerSingleton
		} 
 
		@Override 
		protected WebApplicationContext createServletApplicationContext() { 
			StaticWebApplicationContext servletContext = 
					new StaticWebApplicationContext(); 
			servletContext.registerSingleton("bean", MyBean.class); 
			return servletContext; 
		} 
 
		@Override 
		protected String[] getServletMappings() { 
			return new String[]{"/myservlet"}; 
		} 
 
		@Override 
		protected void customizeRegistration(ServletRegistration.Dynamic registration) { 
			registration.setRunAsRole("role"); 
		} 
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
		assertNotNull(actual);
		assertSame(this.requestContext.getFlowScope(), actual);
	} 
 
	public void testFlowResourceResolve() throws Exception {
		ApplicationContext applicationContext = new StaticWebApplicationContext();
		((Flow) this.requestContext.getActiveFlow()).setApplicationContext(applicationContext);
		Object actual = this.resolver.getValue(this.elContext, null, "resourceBundle");
		assertTrue(this.elContext.isPropertyResolved());
		assertNotNull(actual);
		assertSame(applicationContext, actual);
	} 
 
	public void testScopeResolve() throws Exception {
		this.requestContext.getFlowScope().put("test", "test");
		Object actual = this.resolver.getValue(this.elContext, null, "test");
		assertTrue(this.elContext.isPropertyResolved());
		assertEquals("test", actual);
	} 
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:refresh, registerSingleton
		assertEquals("gAttr2", mav.getModel().get("attr2")); 
	} 
 
	@Test 
	public void modelAttributeAdviceInParentContext() throws Exception { 
		StaticWebApplicationContext parent = new StaticWebApplicationContext(); 
		parent.registerSingleton("maa", ModelAttributeAdvice.class); 
		parent.refresh(); 
		this.webAppContext.setParent(parent); 
		this.webAppContext.refresh(); 
 
		HandlerMethod handlerMethod = handlerMethod(new SimpleController(), "handle"); 
		this.handlerAdapter.afterPropertiesSet(); 
		ModelAndView mav = this.handlerAdapter.handle(this.request, this.response, handlerMethod); 
 
		assertEquals("lAttr1", mav.getModel().get("attr1")); 
		assertEquals("gAttr2", mav.getModel().get("attr2")); 
	} 
 
	@Test 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:refresh, setParent
 
	@Before 
	public void beforeBase() throws Exception { 
		MockServletConfig servletConfig = new MockServletConfig("repository"); 
		servletConfig.addInitParameter("contextConfigLocation", "classpath:test-empty-context.xml"); 
		StaticWebApplicationContext webApplicationContext = new StaticWebApplicationContext(); 
		webApplicationContext.setParent(parentContext); 
		webApplicationContext.refresh(); 
		servletConfig.getServletContext().setAttribute(WebApplicationContext.class.getName() + ".ROOT", webApplicationContext); 
		dispatchServlet = new DispatcherServlet(); 
		dispatchServlet.init(servletConfig); 
		servletTestHelper.setUp(dispatchServlet); 
		entityServletHelper = new EntityServletTestHelper(dispatchServlet); 
	} 
 
	@After 
	public void afterBase() throws Exception { 
		servletTestHelper.tearDown(); 
	} 
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
    protected WicketTester tester;
 
    @Before 
    public void initTester() { 
        StaticWebApplicationContext mockedContext = new StaticWebApplicationContext();
 
        tester = new WicketTester(new TestAppFuseWicketApplication(mockedContext));
        //ensure english locale regardless of local system locale 
        tester.getSession().setLocale(Locale.ENGLISH);
 
        initSpringBeans(mockedContext);
    } 
 
    protected void initSpringBeans(StaticWebApplicationContext context) {
        MockitoAnnotations.initMocks(this);
 
        //Subclasses should register (mocked) beans in context e.g. 
        // context.getBeanFactory().registerSingleton("myBean", myBean) 
    } 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
   } 
 
   @Test(expected=RuntimeException.class) 
   public void testThatProviderFactoryIsRequired()  
   { 
      contextLoader.customizeContext( 
            mockServletContext(null,someRegistry(),someDispatcher()), 
            mockWebApplicationContext()); 
   } 
 
   @Test(expected=RuntimeException.class) 
   public void testThatRegistryIsRequired()  
   { 
      contextLoader.customizeContext( 
            mockServletContext(someProviderFactory(),null,someDispatcher()), 
            mockWebApplicationContext()); 
   } 
 
   @Test(expected=RuntimeException.class) 
   public void testThatDispatcherIsRequired()  

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setServletContext, refresh
 
	private MockHttpServletRequest request; 
 
	@Before 
	public void createViewResolver() { 
		StaticWebApplicationContext wac = new StaticWebApplicationContext(); 
		wac.setServletContext(new MockServletContext()); 
		wac.refresh(); 
		viewResolver = new ContentNegotiatingViewResolver(); 
		viewResolver.setApplicationContext(wac); 
		request = new MockHttpServletRequest("GET", "/test"); 
		RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); 
	} 
 
	@After 
	public void resetRequestContextHolder() { 
		RequestContextHolder.resetRequestAttributes(); 
	} 
 
	@Test 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Spring Framework StaticWebApplicationContext Methods: