org.springframework.mock.web.test.MockMultipartFile Java Examples

The following examples show how to use org.springframework.mock.web.test.MockMultipartFile. 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: RequestParamMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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 #2
Source File: RequestPartMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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 java-technology-stack with MIT License 6 votes vote down vote up
@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 vote down vote up
@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 #5
Source File: RequestParamMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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 #6
Source File: RequestParamMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void resolveMultipartFileArray() throws Exception {
	MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
	MultipartFile expected1 = new MockMultipartFile("mfilearray", "Hello World 1".getBytes());
	MultipartFile expected2 = new MockMultipartFile("mfilearray", "Hello World 2".getBytes());
	request.addFile(expected1);
	request.addFile(expected2);
	request.addFile(new MockMultipartFile("other", "Hello World 3".getBytes()));
	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[]);
	MultipartFile[] parts = (MultipartFile[]) result;
	assertEquals(2, parts.length);
	assertEquals(parts[0], expected1);
	assertEquals(parts[1], expected2);
}
 
Example #7
Source File: RequestParamMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void resolveMultipartFileList() throws Exception {
	MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
	MultipartFile expected1 = new MockMultipartFile("mfilelist", "Hello World 1".getBytes());
	MultipartFile expected2 = new MockMultipartFile("mfilelist", "Hello World 2".getBytes());
	request.addFile(expected1);
	request.addFile(expected2);
	request.addFile(new MockMultipartFile("other", "Hello World 3".getBytes()));
	webRequest = new ServletWebRequest(request);

	MethodParameter param = this.testMethod.annotPresent(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 #8
Source File: ComplexPortletApplicationContext.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public MultipartActionRequest resolveMultipart(ActionRequest request) throws MultipartException {
	if (request.getAttribute("fail") != null) {
		throw new MaxUploadSizeExceededException(1000);
	}
	if (request instanceof MultipartActionRequest) {
		throw new IllegalStateException("Already a multipart request");
	}
	if (request.getAttribute("resolved") != null) {
		throw new IllegalStateException("Already resolved");
	}
	request.setAttribute("resolved", Boolean.TRUE);
	MultiValueMap<String, MultipartFile> files = new LinkedMultiValueMap<String, MultipartFile>();
	files.set("someFile", new MockMultipartFile("someFile", "someContent".getBytes()));
	Map<String, String[]> params = new HashMap<String, String[]>();
	params.put("someParam", new String[] {"someParam"});
	return new DefaultMultipartActionRequest(request, files, params, Collections.<String, String>emptyMap());
}
 
Example #9
Source File: RequestParamMapMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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 #10
Source File: RequestParamMapMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void resolveMapOfMultipartFile() throws Exception {
	MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
	MultipartFile expected1 = new MockMultipartFile("mfile", "Hello World".getBytes());
	MultipartFile expected2 = new MockMultipartFile("other", "Hello World 3".getBytes());
	request.addFile(expected1);
	request.addFile(expected2);
	webRequest = new ServletWebRequest(request);

	MethodParameter param = this.testMethod.annot(requestParam().noName()).arg(Map.class, String.class, MultipartFile.class);
	Object result = resolver.resolveArgument(param, null, webRequest, null);

	assertTrue(result instanceof Map);
	Map<String, MultipartFile> resultMap = (Map<String, MultipartFile>) result;
	assertEquals(2, resultMap.size());
	assertEquals(expected1, resultMap.get("mfile"));
	assertEquals(expected2, resultMap.get("other"));
}
 
Example #11
Source File: RequestParamMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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 #12
Source File: RequestParamMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void resolveMultipartFileArray() throws Exception {
	MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
	MultipartFile expected1 = new MockMultipartFile("mfilearray", "Hello World 1".getBytes());
	MultipartFile expected2 = new MockMultipartFile("mfilearray", "Hello World 2".getBytes());
	request.addFile(expected1);
	request.addFile(expected2);
	webRequest = new ServletWebRequest(request);

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

	assertTrue(result instanceof MultipartFile[]);
	MultipartFile[] parts = (MultipartFile[]) result;
	assertEquals(parts[0], expected1);
	assertEquals(parts[1], expected2);
}
 
Example #13
Source File: RequestParamMapMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void resolveMapOfMultipartFile() throws Exception {
	MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
	MultipartFile expected1 = new MockMultipartFile("mfile", "Hello World".getBytes());
	MultipartFile expected2 = new MockMultipartFile("other", "Hello World 3".getBytes());
	request.addFile(expected1);
	request.addFile(expected2);
	webRequest = new ServletWebRequest(request);

	MethodParameter param = this.testMethod.annot(requestParam().noName()).arg(Map.class, String.class, MultipartFile.class);
	Object result = resolver.resolveArgument(param, null, webRequest, null);

	assertTrue(result instanceof Map);
	Map<String, MultipartFile> resultMap = (Map<String, MultipartFile>) result;
	assertEquals(2, resultMap.size());
	assertEquals(expected1, resultMap.get("mfile"));
	assertEquals(expected2, resultMap.get("other"));
}
 
Example #14
Source File: RequestParamMapMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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 #15
Source File: RequestPartMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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 #16
Source File: RequestPartMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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 #17
Source File: RequestParamMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void resolveMultipartFileArray() throws Exception {
	MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
	MultipartFile expected1 = new MockMultipartFile("mfilearray", "Hello World 1".getBytes());
	MultipartFile expected2 = new MockMultipartFile("mfilearray", "Hello World 2".getBytes());
	request.addFile(expected1);
	request.addFile(expected2);
	request.addFile(new MockMultipartFile("other", "Hello World 3".getBytes()));
	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[]);
	MultipartFile[] parts = (MultipartFile[]) result;
	assertEquals(2, parts.length);
	assertEquals(parts[0], expected1);
	assertEquals(parts[1], expected2);
}
 
Example #18
Source File: RequestParamMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void resolveMultipartFileList() throws Exception {
	MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
	MultipartFile expected1 = new MockMultipartFile("mfilelist", "Hello World 1".getBytes());
	MultipartFile expected2 = new MockMultipartFile("mfilelist", "Hello World 2".getBytes());
	request.addFile(expected1);
	request.addFile(expected2);
	request.addFile(new MockMultipartFile("other", "Hello World 3".getBytes()));
	webRequest = new ServletWebRequest(request);

	MethodParameter param = this.testMethod.annotPresent(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 #19
Source File: RequestParamMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 #20
Source File: RequestParamMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void resolveMultipartFileList() throws Exception {
	MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
	MultipartFile expected1 = new MockMultipartFile("mfilelist", "Hello World 1".getBytes());
	MultipartFile expected2 = new MockMultipartFile("mfilelist", "Hello World 2".getBytes());
	request.addFile(expected1);
	request.addFile(expected2);
	webRequest = new ServletWebRequest(request);

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

	assertTrue(result instanceof List);
	assertEquals(Arrays.asList(expected1, expected2), result);
}
 
Example #21
Source File: RequestMappingHandlerAdapterIntegrationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void handleAndValidateRequestPart() throws Exception {
	MockMultipartHttpServletRequest multipartRequest = new MockMultipartHttpServletRequest();
	multipartRequest.addFile(new MockMultipartFile("requestPart", "", "text/plain", "content".getBytes("UTF-8")));

	HandlerMethod handlerMethod = handlerMethod("handleAndValidateRequestPart", String.class, Errors.class, Model.class);
	ModelAndView mav = handlerAdapter.handle(multipartRequest, response, handlerMethod);

	assertNotNull(mav);
	assertEquals(1, mav.getModelMap().get("error count"));
}
 
Example #22
Source File: RequestMappingHandlerAdapterIntegrationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 #23
Source File: ServletAnnotationControllerHandlerMethodTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 #24
Source File: ServletAnnotationControllerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #25
Source File: ServletAnnotationControllerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 #26
Source File: ServletAnnotationControllerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void multipartFileAsSingleString() throws Exception {
	initServlet(MultipartController.class);

	MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
	request.setRequestURI("/singleString");
	request.addFile(new MockMultipartFile("content", "Juergen".getBytes()));
	MockHttpServletResponse response = new MockHttpServletResponse();
	servlet.service(request, response);
	assertEquals("Juergen", response.getContentAsString());
}
 
Example #27
Source File: RequestParamMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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 #28
Source File: WebRequestDataBinderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
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]);
}
 
Example #29
Source File: WebRequestDataBinderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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 #30
Source File: WebRequestDataBinderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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());
}