Java Code Examples for org.springframework.mock.web.test.MockMultipartHttpServletRequest#addFile()
The following examples show how to use
org.springframework.mock.web.test.MockMultipartHttpServletRequest#addFile() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequestParamMapMethodArgumentResolverTests.java From java-technology-stack with MIT License | 6 votes |
@Test @SuppressWarnings("unchecked") public void resolveMultiValueMapOfMultipartFile() throws Exception { MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); MultipartFile expected1 = new MockMultipartFile("mfilelist", "Hello World 1".getBytes()); MultipartFile expected2 = new MockMultipartFile("mfilelist", "Hello World 2".getBytes()); MultipartFile expected3 = new MockMultipartFile("other", "Hello World 3".getBytes()); request.addFile(expected1); request.addFile(expected2); request.addFile(expected3); webRequest = new ServletWebRequest(request); MethodParameter param = this.testMethod.annot(requestParam().noName()).arg(MultiValueMap.class, String.class, MultipartFile.class); Object result = resolver.resolveArgument(param, null, webRequest, null); assertTrue(result instanceof MultiValueMap); MultiValueMap<String, MultipartFile> resultMap = (MultiValueMap<String, MultipartFile>) result; assertEquals(2, resultMap.size()); assertEquals(2, resultMap.get("mfilelist").size()); assertEquals(expected1, resultMap.get("mfilelist").get(0)); assertEquals(expected2, resultMap.get("mfilelist").get(1)); assertEquals(1, resultMap.get("other").size()); assertEquals(expected3, resultMap.get("other").get(0)); }
Example 2
Source File: RequestPartMethodArgumentResolverTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void resolveOptionalMultipartFileArgument() throws Exception { MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); MultipartFile expected = new MockMultipartFile("optionalMultipartFile", "Hello World".getBytes()); request.addFile(expected); request.addFile(new MockMultipartFile("otherPart", "", "text/plain", "Hello World".getBytes())); webRequest = new ServletWebRequest(request); Object actualValue = resolver.resolveArgument(optionalMultipartFile, null, webRequest, null); assertTrue(actualValue instanceof Optional); assertEquals("Invalid result", expected, ((Optional<?>) actualValue).get()); actualValue = resolver.resolveArgument(optionalMultipartFile, null, webRequest, null); assertTrue(actualValue instanceof Optional); assertEquals("Invalid result", expected, ((Optional<?>) actualValue).get()); }
Example 3
Source File: RequestPartMethodArgumentResolverTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void resolveOptionalMultipartFileList() throws Exception { MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); MultipartFile expected = new MockMultipartFile("requestPart", "Hello World".getBytes()); request.addFile(expected); request.addFile(new MockMultipartFile("otherPart", "", "text/plain", "Hello World".getBytes())); webRequest = new ServletWebRequest(request); Object actualValue = resolver.resolveArgument(optionalMultipartFileList, null, webRequest, null); assertTrue(actualValue instanceof Optional); assertEquals("Invalid result", Collections.singletonList(expected), ((Optional<?>) actualValue).get()); actualValue = resolver.resolveArgument(optionalMultipartFileList, null, webRequest, null); assertTrue(actualValue instanceof Optional); assertEquals("Invalid result", Collections.singletonList(expected), ((Optional<?>) actualValue).get()); }
Example 4
Source File: RequestParamMethodArgumentResolverTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void resolveMultipartFileListNotannot() throws Exception { MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); MultipartFile expected1 = new MockMultipartFile("multipartFileList", "Hello World 1".getBytes()); MultipartFile expected2 = new MockMultipartFile("multipartFileList", "Hello World 2".getBytes()); request.addFile(expected1); request.addFile(expected2); webRequest = new ServletWebRequest(request); MethodParameter param = this.testMethod .annotNotPresent(RequestParam.class).arg(List.class, MultipartFile.class); Object result = resolver.resolveArgument(param, null, webRequest, null); assertTrue(result instanceof List); assertEquals(Arrays.asList(expected1, expected2), result); }
Example 5
Source File: RequestParamMethodArgumentResolverTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void resolveOptionalMultipartFile() throws Exception { ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer(); initializer.setConversionService(new DefaultConversionService()); WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer); MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); MultipartFile expected = new MockMultipartFile("mfile", "Hello World".getBytes()); request.addFile(expected); webRequest = new ServletWebRequest(request); MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, MultipartFile.class); Object result = resolver.resolveArgument(param, null, webRequest, binderFactory); assertTrue(result instanceof Optional); assertEquals("Invalid result", expected, ((Optional<?>) result).get()); }
Example 6
Source File: WebRequestDataBinderTests.java From spring-analysis-note with MIT License | 5 votes |
@Test 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]); }
Example 7
Source File: WebRequestDataBinderTests.java From spring-analysis-note with MIT License | 5 votes |
@Test 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()); }
Example 8
Source File: RequestParamMethodArgumentResolverTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void isMultipartRequestHttpPut() throws Exception { MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); MultipartFile expected = new MockMultipartFile("multipartFileList", "Hello World".getBytes()); request.addFile(expected); request.setMethod("PUT"); webRequest = new ServletWebRequest(request); Object actual = resolver.resolveArgument(paramMultipartFileListNotAnnot, null, webRequest, null); assertTrue(actual instanceof List); assertEquals(expected, ((List<?>) actual).get(0)); }
Example 9
Source File: RequestParamMethodArgumentResolverTests.java From spring-analysis-note with MIT License | 5 votes |
@Test // SPR-9079 public void isMultipartRequestHttpPut() throws Exception { MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); MultipartFile expected = new MockMultipartFile("multipartFileList", "Hello World".getBytes()); request.addFile(expected); request.setMethod("PUT"); webRequest = new ServletWebRequest(request); MethodParameter param = this.testMethod .annotNotPresent(RequestParam.class).arg(List.class, MultipartFile.class); Object actual = resolver.resolveArgument(param, null, webRequest, null); assertTrue(actual instanceof List); assertEquals(expected, ((List<?>) actual).get(0)); }
Example 10
Source File: RequestMappingHandlerAdapterIntegrationTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void handleRequestPart() throws Exception { MockMultipartHttpServletRequest multipartRequest = new MockMultipartHttpServletRequest(); multipartRequest.addFile(new MockMultipartFile("requestPart", "", "text/plain", "content".getBytes("UTF-8"))); HandlerMethod handlerMethod = handlerMethod("handleRequestPart", String.class, Model.class); ModelAndView mav = handlerAdapter.handle(multipartRequest, response, handlerMethod); assertNotNull(mav); assertEquals("content", mav.getModelMap().get("requestPart")); }
Example 11
Source File: ServletAnnotationControllerHandlerMethodTests.java From java-technology-stack with MIT License | 5 votes |
@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()); }
Example 12
Source File: WebRequestDataBinderTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test 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]); }
Example 13
Source File: ServletAnnotationControllerHandlerMethodTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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()); }
Example 14
Source File: WebRequestDataBinderTests.java From java-technology-stack with MIT License | 5 votes |
@Test 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]); }
Example 15
Source File: RequestParamMethodArgumentResolverTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void resolveMultipartFileListNotAnnotated() throws Exception { MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); MultipartFile expected1 = new MockMultipartFile("multipartFileList", "Hello World 1".getBytes()); MultipartFile expected2 = new MockMultipartFile("multipartFileList", "Hello World 2".getBytes()); request.addFile(expected1); request.addFile(expected2); webRequest = new ServletWebRequest(request); Object result = resolver.resolveArgument(paramMultipartFileListNotAnnot, null, webRequest, null); assertTrue(result instanceof List); assertEquals(Arrays.asList(expected1, expected2), result); }
Example 16
Source File: ServletAnnotationControllerHandlerMethodTests.java From spring-analysis-note with MIT License | 5 votes |
@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()); }
Example 17
Source File: RequestParamMethodArgumentResolverTests.java From java-technology-stack with MIT License | 5 votes |
@Test // SPR-9079 public void isMultipartRequestHttpPut() throws Exception { MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); MultipartFile expected = new MockMultipartFile("multipartFileList", "Hello World".getBytes()); request.addFile(expected); request.setMethod("PUT"); webRequest = new ServletWebRequest(request); MethodParameter param = this.testMethod .annotNotPresent(RequestParam.class).arg(List.class, MultipartFile.class); Object actual = resolver.resolveArgument(param, null, webRequest, null); assertTrue(actual instanceof List); assertEquals(expected, ((List<?>) actual).get(0)); }
Example 18
Source File: RequestPartMethodArgumentResolverTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void resolveMultipartFileNotAnnotArgument() throws Exception { MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); MultipartFile expected = new MockMultipartFile("multipartFileNotAnnot", "Hello World".getBytes()); request.addFile(expected); request.addFile(new MockMultipartFile("otherPart", "", "text/plain", "Hello World".getBytes())); webRequest = new ServletWebRequest(request); Object result = resolver.resolveArgument(paramMultipartFileNotAnnot, null, webRequest, null); assertTrue(result instanceof MultipartFile); assertEquals("Invalid result", expected, result); }
Example 19
Source File: ServletAnnotationControllerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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()); }
Example 20
Source File: RequestParamMethodArgumentResolverTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void resolveMultipartFile() throws Exception { MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); MultipartFile expected = new MockMultipartFile("mfile", "Hello World".getBytes()); request.addFile(expected); webRequest = new ServletWebRequest(request); MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultipartFile.class); Object result = resolver.resolveArgument(param, null, webRequest, null); assertTrue(result instanceof MultipartFile); assertEquals("Invalid result", expected, result); }