Package org.springframework.mock.web.test

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


    }
  }

  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");
    Properties props = new Properties();
View Full Code Here


    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

    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(true);
    marshallerMock.marshal(eq(toBeMarshalled), isA(StreamResult.class));

    view.render(model, request, response);
    assertEquals("Invalid content type", "application/xml", response.getContentType());
    assertEquals("Invalid content length", 0, response.getContentLength());
  }
View Full Code Here

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

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

    given(marshallerMock.supports(String.class)).willReturn(true);
    marshallerMock.marshal(eq(toBeMarshalled), isA(StreamResult.class));

    view.render(model, request, response);
    assertEquals("Invalid content type", "application/xml", response.getContentType());
    assertEquals("Invalid content length", 0, response.getContentLength());
  }
View Full Code Here

    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");
    }
    catch (IllegalStateException ex) {
      // expected
    }
    assertEquals("Invalid content length", 0, response.getContentLength());
  }
View Full Code Here

    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");
    }
    catch (IllegalStateException ex) {
      // expected
    }
    assertEquals("Invalid content length", 0, response.getContentLength());
  }
View Full Code Here

    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.render(model, request, response);
View Full Code Here

    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);
    assertEquals("Invalid content type", "application/xml", response.getContentType());
    assertEquals("Invalid content length", 0, response.getContentLength());
    verify(marshallerMock).marshal(eq(toBeMarshalled), isA(StreamResult.class));
  }
View Full Code Here

  }

  @Test
  public void render() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();

    Map<String, String> model = new LinkedHashMap<String, String>();
    model.put("2", "This is entry 2");
    model.put("1", "This is entry 1");

    view.render(model, request, response);
    assertEquals("Invalid content-type", "application/atom+xml", response.getContentType());
    String expected = "<feed xmlns=\"http://www.w3.org/2005/Atom\">" + "<title>Test Feed</title>" +
        "<entry><title>2</title><summary>This is entry 2</summary></entry>" +
        "<entry><title>1</title><summary>This is entry 1</summary></entry>" + "</feed>";
    assertXMLEqual(expected, response.getContentAsString());
  }
View Full Code Here

  @Before
  public void setUp() throws Exception {
    this.resolver = new ExceptionHandlerExceptionResolver();
    this.request = new MockHttpServletRequest("GET", "/");
    this.response = new MockHttpServletResponse();
  }
View Full Code Here

TOP

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

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.