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

The following examples show how to use org.springframework.mock.web.test.MockMultipartHttpServletRequest. 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: 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 #2
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 #3
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 #4
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 #5
Source File: RequestPartServletServerHttpRequestTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test  // SPR-13096
public void getBodyViaRequestParameter() throws Exception {
	MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest() {
		@Override
		public HttpHeaders getMultipartHeaders(String paramOrFileName) {
			HttpHeaders headers = new HttpHeaders();
			headers.setContentType(new MediaType("application", "octet-stream", StandardCharsets.ISO_8859_1));
			return headers;
		}
	};

	byte[] bytes = {(byte) 0xC4};
	mockRequest.setParameter("part", new String(bytes, StandardCharsets.ISO_8859_1));
	ServerHttpRequest request = new RequestPartServletServerHttpRequest(mockRequest, "part");
	byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
	assertArrayEquals(bytes, result);
}
 
Example #6
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 #7
Source File: RequestPartServletServerHttpRequestTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void getBodyViaRequestParameterWithRequestEncoding() throws Exception {
	MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest() {
		@Override
		public HttpHeaders getMultipartHeaders(String paramOrFileName) {
			HttpHeaders headers = new HttpHeaders();
			headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
			return headers;
		}
	};

	byte[] bytes = {(byte) 0xC4};
	mockRequest.setParameter("part", new String(bytes, StandardCharsets.ISO_8859_1));
	mockRequest.setCharacterEncoding("iso-8859-1");
	ServerHttpRequest request = new RequestPartServletServerHttpRequest(mockRequest, "part");
	byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
	assertArrayEquals(bytes, result);
}
 
Example #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
Source File: RequestPartServletServerHttpRequestTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test  // SPR-13096
public void getBodyViaRequestParameter() throws Exception {
	MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest() {
		@Override
		public HttpHeaders getMultipartHeaders(String paramOrFileName) {
			HttpHeaders headers = new HttpHeaders();
			headers.setContentType(new MediaType("application", "octet-stream", StandardCharsets.ISO_8859_1));
			return headers;
		}
	};

	byte[] bytes = {(byte) 0xC4};
	mockRequest.setParameter("part", new String(bytes, StandardCharsets.ISO_8859_1));
	ServerHttpRequest request = new RequestPartServletServerHttpRequest(mockRequest, "part");
	byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
	assertArrayEquals(bytes, result);
}
 
Example #17
Source File: RequestPartServletServerHttpRequestTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void getBodyViaRequestParameterWithRequestEncoding() throws Exception {
	MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest() {
		@Override
		public HttpHeaders getMultipartHeaders(String paramOrFileName) {
			HttpHeaders headers = new HttpHeaders();
			headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
			return headers;
		}
	};

	byte[] bytes = {(byte) 0xC4};
	mockRequest.setParameter("part", new String(bytes, StandardCharsets.ISO_8859_1));
	mockRequest.setCharacterEncoding("iso-8859-1");
	ServerHttpRequest request = new RequestPartServletServerHttpRequest(mockRequest, "part");
	byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
	assertArrayEquals(bytes, result);
}
 
Example #18
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 #19
Source File: RequestPartServletServerHttpRequestTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void getBodyViaRequestParameter() throws Exception {
	MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest() {

		@Override
		public HttpHeaders getMultipartHeaders(String paramOrFileName) {
			HttpHeaders headers = new HttpHeaders();
			headers.setContentType(new MediaType("application", "octet-stream", Charset.forName("iso-8859-1")));
			return headers;
		}
	};
	byte[] bytes = {(byte) 0xC4};
	mockRequest.setParameter("part", new String(bytes, Charset.forName("iso-8859-1")));
	ServerHttpRequest request = new RequestPartServletServerHttpRequest(mockRequest, "part");

	byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
	assertArrayEquals(bytes, result);
}
 
Example #20
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 #21
Source File: RequestPartServletServerHttpRequestTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void getBodyViaRequestParameterWithRequestEncoding() throws Exception {
	MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest() {

		@Override
		public HttpHeaders getMultipartHeaders(String paramOrFileName) {
			HttpHeaders headers = new HttpHeaders();
			headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
			return headers;
		}
	};
	byte[] bytes = {(byte) 0xC4};
	mockRequest.setParameter("part", new String(bytes, Charset.forName("iso-8859-1")));
	mockRequest.setCharacterEncoding("iso-8859-1");
	ServerHttpRequest request = new RequestPartServletServerHttpRequest(mockRequest, "part");

	byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
	assertArrayEquals(bytes, result);
}
 
Example #22
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 #23
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 #24
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 #25
Source File: ServletAnnotationControllerHandlerMethodTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 #26
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 #27
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());
}
 
Example #28
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 #29
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 #30
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());
}