Package org.springframework.mock.web.test

Examples of org.springframework.mock.web.test.MockServletContext


  @Test
  public void testVelocityToolboxView() throws Exception {
    final String templateName = "test.vm";

    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.setServletContext(new MockServletContext());
    final Template expectedTemplate = new Template();
    VelocityConfig vc = new VelocityConfig() {
      @Override
      public VelocityEngine getVelocityEngine() {
        return new TestVelocityEngine(templateName, expectedTemplate);
View Full Code Here


  @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);
View Full Code Here

    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("name", "tb");
    wac.registerSingleton("testBean", TestBean.class, pvs);

    MockServletContext sc = new MockServletContext();
    wac.setServletContext(sc);
    wac.refresh();
    sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);

    InjectionTarget target = new InjectionTarget();
    SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(target, sc);
    assertTrue(target.testBean instanceof TestBean);
    assertEquals("tb", target.name);
View Full Code Here


  @Before
  public void setUp() {
    this.context = new StaticWebApplicationContext();
    this.context.setServletContext(new MockServletContext(new FileSystemResourceLoader()));
    this.context.registerSingleton("controller", TestController.class);

    this.config = new TestWebMvcConfigurationSupport();
    this.config.setApplicationContext(this.context);
    this.config.setServletContext(this.context.getServletContext());
View Full Code Here

  private static final String NAME = "scoped";


  private WebApplicationContext initApplicationContext(String scope) {
    MockServletContext sc = new MockServletContext();
    GenericWebApplicationContext ac = new GenericWebApplicationContext(sc);
    GenericBeanDefinition bd = new GenericBeanDefinition();
    bd.setBeanClass(DerivedTestBean.class);
    bd.setScope(scope);
    ac.registerBeanDefinition(NAME, bd);
View Full Code Here

*/
public class RequestContextListenerTests extends TestCase {

  public void testRequestContextListenerWithSameThread() {
    RequestContextListener listener = new RequestContextListener();
    MockServletContext context = new MockServletContext();
    MockHttpServletRequest request = new MockHttpServletRequest(context);
    request.setAttribute("test", "value");

    assertNull(RequestContextHolder.getRequestAttributes());
    listener.requestInitialized(new ServletRequestEvent(context, request));
View Full Code Here

    assertTrue(runnable.wasExecuted());
  }

  public void testRequestContextListenerWithSameThreadAndAttributesGone() {
    RequestContextListener listener = new RequestContextListener();
    MockServletContext context = new MockServletContext();
    MockHttpServletRequest request = new MockHttpServletRequest(context);
    request.setAttribute("test", "value");

    assertNull(RequestContextHolder.getRequestAttributes());
    listener.requestInitialized(new ServletRequestEvent(context, request));
View Full Code Here

    assertTrue(runnable.wasExecuted());
  }

  public void testRequestContextListenerWithDifferentThread() {
    final RequestContextListener listener = new RequestContextListener();
    final MockServletContext context = new MockServletContext();
    final MockHttpServletRequest request = new MockHttpServletRequest(context);
    request.setAttribute("test", "value");

    assertNull(RequestContextHolder.getRequestAttributes());
    listener.requestInitialized(new ServletRequestEvent(context, request));
View Full Code Here

  }


  private ApplicationContext initContext(Class... configClasses) {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setServletContext(new MockServletContext());
    context.register(configClasses);
    context.refresh();
    return context;
  }
View Full Code Here

    doTestWithApplicationContext(true);
  }

  private void doTestWithApplicationContext(boolean lazy) throws Exception {
    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.setServletContext(new MockServletContext());
    wac.getServletContext().setAttribute(WebUtils.TEMP_DIR_CONTEXT_ATTRIBUTE, new File("mytemp"));
    wac.refresh();
    MockCommonsMultipartResolver resolver = new MockCommonsMultipartResolver();
    resolver.setMaxUploadSize(1000);
    resolver.setMaxInMemorySize(100);
View Full Code Here

TOP

Related Classes of org.springframework.mock.web.test.MockServletContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.