Package org.springframework.mock.web.test

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


  public void testParameterizableViewController() throws Exception {
    String viewName = "viewName";
    ParameterizableViewController pvc = new ParameterizableViewController();
    pvc.setViewName(viewName);
    // We don't care about the params.
    ModelAndView mv = pvc.handleRequest(new MockHttpServletRequest("GET", "foo.html"), null);
    assertTrue("model has no data", mv.getModel().size() == 0);
    assertTrue("model has correct viewname", mv.getViewName().equals(viewName));
    assertTrue("getViewName matches", pvc.getViewName().equals(viewName));
  }
View Full Code Here


    String modelKey = "key";
    view.setModelKey("invalidKey");
    Map<String, Object> model = new HashMap<String, Object>();
    model.put(modelKey, toBeMarshalled);

    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();

    try {
      view.render(model, request, response);
      fail("IllegalStateException expected");
View Full Code Here

  public void renderNullModelValue() throws Exception {
    String modelKey = "key";
    Map<String, Object> model = new HashMap<String, Object>();
    model.put(modelKey, null);

    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();

    try {
      view.render(model, request, response);
      fail("IllegalStateException expected");
View Full Code Here

      verify(dispatcher).forward(request, response);
    }
  }

  public void testServletWrappingController() throws Exception {
    HttpServletRequest request = new MockHttpServletRequest("GET", "/somePath");
    HttpServletResponse response = new MockHttpServletResponse();

    ServletWrappingController swc = new ServletWrappingController();
    swc.setServletClass(TestServlet.class);
    swc.setServletName("action");
View Full Code Here

    assertNull(((TimeZoneAwareLocaleContext) loc).getTimeZone());
  }

  @Test
  public void testResolveLocaleWithoutCookieAndDefaultLocale() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addPreferredLocale(Locale.TAIWAN);

    CookieLocaleResolver resolver = new CookieLocaleResolver();
    resolver.setDefaultLocale(Locale.GERMAN);

    Locale loc = resolver.resolveLocale(request);
View Full Code Here

    String modelKey = "key";
    view.setModelKey(modelKey);
    Map<String, Object> model = new HashMap<String, Object>();
    model.put(modelKey, toBeMarshalled);

    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();

    given(marshallerMock.supports(Object.class)).willReturn(false);

    try {
View Full Code Here

    swc.destroy();
    assertTrue(TestServlet.destroyed);
  }

  public void testServletWrappingControllerWithBeanName() throws Exception {
    HttpServletRequest request = new MockHttpServletRequest("GET", "/somePath");
    HttpServletResponse response = new MockHttpServletResponse();

    ServletWrappingController swc = new ServletWrappingController();
    swc.setServletClass(TestServlet.class);
    swc.setBeanName("action");
View Full Code Here

    Object toBeMarshalled = new Object();
    String modelKey = "key";
    Map<String, Object> model = new HashMap<String, Object>();
    model.put(modelKey, toBeMarshalled);

    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();

    given(marshallerMock.supports(Object.class)).willReturn(true);

    view.render(model, request, response);
View Full Code Here

    String modelKey = "key";
    Map<String, Object> model = new LinkedHashMap<String, Object>();
    model.put(BindingResult.MODEL_KEY_PREFIX + modelKey, new BeanPropertyBindingResult(toBeMarshalled, modelKey));
    model.put(modelKey, toBeMarshalled);

    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();

    given(marshallerMock.supports(BeanPropertyBindingResult.class)).willReturn(true);
    given(marshallerMock.supports(Object.class)).willReturn(true);
View Full Code Here

    assertEquals(Locale.GERMAN, loc);
  }

  @Test
  public void testResolveLocaleContextWithoutCookieAndDefaultLocale() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addPreferredLocale(Locale.TAIWAN);

    CookieLocaleResolver resolver = new CookieLocaleResolver();
    resolver.setDefaultLocale(Locale.GERMAN);
    resolver.setDefaultTimeZone(TimeZone.getTimeZone("GMT+1"));
View Full Code Here

TOP

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

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.