Package org.springframework.mock.web.test

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


    resolver = new RequestPartMethodArgumentResolver(Collections.<HttpMessageConverter<?>>singletonList(messageConverter));
    reset(messageConverter);

    multipartFile1 = new MockMultipartFile("requestPart", "", "text/plain", (byte[]) null);
    multipartFile2 = new MockMultipartFile("requestPart", "", "text/plain", (byte[]) null);
    multipartRequest = new MockMultipartHttpServletRequest();
    multipartRequest.addFile(multipartFile1);
    multipartRequest.addFile(multipartFile2);
    servletResponse = new MockHttpServletResponse();
    webRequest = new ServletWebRequest(multipartRequest, servletResponse);
  }
View Full Code Here


    assertEquals(parts[1], multipartFile2);
  }

  @Test
  public void resolveMultipartFileNotAnnotArgument() throws Exception {
    MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
    MultipartFile expected = new MockMultipartFile("multipartFileNotAnnot", "Hello World".getBytes());
    request.addFile(expected);
    webRequest = new ServletWebRequest(request);

    Object result = resolver.resolveArgument(paramMultipartFileNotAnnot, null, webRequest, null);

    assertTrue(result instanceof MultipartFile);
View Full Code Here

  public void testMultipartFileAsString() {
    TestBean target = new TestBean();
    WebRequestDataBinder binder = new WebRequestDataBinder(target);
    binder.registerCustomEditor(String.class, new StringMultipartFileEditor());

    MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
    request.addFile(new MockMultipartFile("name", "Juergen".getBytes()));
    binder.bind(new ServletWebRequest(request));
    assertEquals("Juergen", target.getName());
  }
View Full Code Here

  public void testMultipartFileAsStringArray() {
    TestBean target = new TestBean();
    WebRequestDataBinder binder = new WebRequestDataBinder(target);
    binder.registerCustomEditor(String.class, new StringMultipartFileEditor());

    MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
    request.addFile(new MockMultipartFile("stringArray", "Juergen".getBytes()));
    binder.bind(new ServletWebRequest(request));
    assertEquals(1, target.getStringArray().length);
    assertEquals("Juergen", target.getStringArray()[0]);
  }
View Full Code Here

  public void testMultipartFilesAsStringArray() {
    TestBean target = new TestBean();
    WebRequestDataBinder binder = new WebRequestDataBinder(target);
    binder.registerCustomEditor(String.class, new StringMultipartFileEditor());

    MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
    request.addFile(new MockMultipartFile("stringArray", "Juergen".getBytes()));
    request.addFile(new MockMultipartFile("stringArray", "Eva".getBytes()));
    binder.bind(new ServletWebRequest(request));
    assertEquals(2, target.getStringArray().length);
    assertEquals("Juergen", target.getStringArray()[0]);
    assertEquals("Eva", target.getStringArray()[1]);
  }
View Full Code Here

  @Test
  public void multipartFileAsStringArray() throws Exception {
    initServlet(MultipartController.class);

    MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
    request.setRequestURI("/stringArray");
    request.addFile(new MockMultipartFile("content", "Juergen".getBytes()));
    MockHttpServletResponse response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("Juergen", response.getContentAsString());
  }
View Full Code Here

  @Test
  public void multipartFilesAsStringArray() throws Exception {
    initServlet(MultipartController.class);

    MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
    request.setRequestURI("/stringArray");
    request.addFile(new MockMultipartFile("content", "Juergen".getBytes()));
    request.addFile(new MockMultipartFile("content", "Eva".getBytes()));
    MockHttpServletResponse response = new MockHttpServletResponse();
    servlet.service(request, response);
    assertEquals("Juergen-Eva", response.getContentAsString());
  }
View Full Code Here

  @Test
  public void multipartFileAsSingleString() throws Exception {
    initServletWithControllers(MultipartController.class);

    MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
    request.setRequestURI("/singleString");
    request.addFile(new MockMultipartFile("content", "Juergen".getBytes()));
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals("Juergen", response.getContentAsString());
  }
View Full Code Here

  @Test
  public void multipartFileAsStringArray() throws Exception {
    initServletWithControllers(MultipartController.class);

    MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
    request.setRequestURI("/stringArray");
    request.addFile(new MockMultipartFile("content", "Juergen".getBytes()));
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals("Juergen", response.getContentAsString());
  }
View Full Code Here

  @Test
  public void multipartFilesAsStringArray() throws Exception {
    initServletWithControllers(MultipartController.class);

    MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
    request.setRequestURI("/stringArray");
    request.addFile(new MockMultipartFile("content", "Juergen".getBytes()));
    request.addFile(new MockMultipartFile("content", "Eva".getBytes()));
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertEquals("Juergen-Eva", response.getContentAsString());
  }
View Full Code Here

TOP

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

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.