Search in sources :

Example 1 with ContextLoader

use of org.springframework.web.context.ContextLoader in project spring-framework by spring-projects.

the class RedirectViewTests method updateTargetUrlWithContextLoader.

@Test
public void updateTargetUrlWithContextLoader() throws Exception {
    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
    MockServletContext servletContext = new MockServletContext();
    ContextLoader contextLoader = new ContextLoader(wac);
    contextLoader.initWebApplicationContext(servletContext);
    try {
        RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
        wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);
        RedirectView rv = new RedirectView();
        rv.setUrl("/path");
        given(mockProcessor.processUrl(request, "/path")).willReturn("/path?key=123");
        rv.render(new ModelMap(), request, response);
        verify(mockProcessor).processUrl(request, "/path");
    } finally {
        contextLoader.closeWebApplicationContext(servletContext);
    }
}
Also used : ContextLoader(org.springframework.web.context.ContextLoader) RequestDataValueProcessor(org.springframework.web.servlet.support.RequestDataValueProcessor) RequestDataValueProcessorWrapper(org.springframework.web.servlet.support.RequestDataValueProcessorWrapper) ModelMap(org.springframework.ui.ModelMap) StaticWebApplicationContext(org.springframework.web.context.support.StaticWebApplicationContext) MockServletContext(org.springframework.mock.web.test.MockServletContext) Test(org.junit.Test)

Example 2 with ContextLoader

use of org.springframework.web.context.ContextLoader in project spring-framework by spring-projects.

the class SpringConfiguratorTests method setup.

@Before
public void setup() {
    this.servletContext = new MockServletContext();
    this.webAppContext = new AnnotationConfigWebApplicationContext();
    this.webAppContext.register(Config.class);
    this.contextLoader = new ContextLoader(this.webAppContext);
    this.contextLoader.initWebApplicationContext(this.servletContext);
    this.configurator = new SpringConfigurator();
}
Also used : ContextLoader(org.springframework.web.context.ContextLoader) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.test.MockServletContext) Before(org.junit.Before)

Aggregations

MockServletContext (org.springframework.mock.web.test.MockServletContext)2 ContextLoader (org.springframework.web.context.ContextLoader)2 Before (org.junit.Before)1 Test (org.junit.Test)1 ModelMap (org.springframework.ui.ModelMap)1 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)1 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)1 RequestDataValueProcessor (org.springframework.web.servlet.support.RequestDataValueProcessor)1 RequestDataValueProcessorWrapper (org.springframework.web.servlet.support.RequestDataValueProcessorWrapper)1