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

The following examples show how to use org.springframework.mock.web.test.MockPart. 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 spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void resolvePartListArgument() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	MockPart part1 = new MockPart("requestPart", "Hello World 1".getBytes());
	MockPart part2 = new MockPart("requestPart", "Hello World 2".getBytes());
	request.addPart(part1);
	request.addPart(part2);
	request.addPart(new MockPart("otherPart", "Hello World".getBytes()));
	webRequest = new ServletWebRequest(request);

	Object result = resolver.resolveArgument(paramPartList, null, webRequest, null);
	assertTrue(result instanceof List);
	assertEquals(Arrays.asList(part1, part2), result);
}
 
Example #2
Source File: RequestParamMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void resolvePartArray() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	MockPart expected1 = new MockPart("pfilearray", "Hello World 1".getBytes());
	MockPart expected2 = new MockPart("pfilearray", "Hello World 2".getBytes());
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	request.addPart(expected1);
	request.addPart(expected2);
	webRequest = new ServletWebRequest(request);

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

	assertTrue(result instanceof Part[]);
	Part[] parts = (Part[]) result;
	assertEquals(parts[0], expected1);
	assertEquals(parts[1], expected2);
}
 
Example #3
Source File: RequestParamMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void resolvePartList() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	MockPart expected1 = new MockPart("pfilelist", "Hello World 1".getBytes());
	MockPart expected2 = new MockPart("pfilelist", "Hello World 2".getBytes());
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	request.addPart(expected1);
	request.addPart(expected2);
	webRequest = new ServletWebRequest(request);

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

	assertTrue(result instanceof List);
	assertEquals(Arrays.asList(expected1, expected2), result);
}
 
Example #4
Source File: RequestPartMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void resolvePartArrayArgument() throws Exception {
	MockPart part1 = new MockPart("requestPart1", "Hello World 1".getBytes());
	MockPart part2 = new MockPart("requestPart2", "Hello World 2".getBytes());
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	request.addPart(part1);
	request.addPart(part2);
	webRequest = new ServletWebRequest(request);

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

	assertTrue(result instanceof Part[]);
	Part[] parts = (Part[]) result;
	assertThat(parts, Matchers.arrayWithSize(2));
	assertEquals(parts[0], part1);
	assertEquals(parts[1], part2);
}
 
Example #5
Source File: RequestPartMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void resolvePartListArgument() throws Exception {
	MockPart part1 = new MockPart("requestPart1", "Hello World 1".getBytes());
	MockPart part2 = new MockPart("requestPart2", "Hello World 2".getBytes());
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	request.addPart(part1);
	request.addPart(part2);
	webRequest = new ServletWebRequest(request);

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

	assertTrue(result instanceof List);
	assertEquals(Arrays.asList(part1, part2), result);
}
 
Example #6
Source File: RequestParamMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void resolvePartArray() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	MockPart expected1 = new MockPart("pfilearray", "Hello World 1".getBytes());
	MockPart expected2 = new MockPart("pfilearray", "Hello World 2".getBytes());
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	request.addPart(expected1);
	request.addPart(expected2);
	request.addPart(new MockPart("other", "Hello World 3".getBytes()));
	webRequest = new ServletWebRequest(request);

	MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Part[].class);
	Object result = resolver.resolveArgument(param, null, webRequest, null);

	assertTrue(result instanceof Part[]);
	Part[] parts = (Part[]) result;
	assertEquals(2, parts.length);
	assertEquals(parts[0], expected1);
	assertEquals(parts[1], expected2);
}
 
Example #7
Source File: RequestParamMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void resolvePartList() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	MockPart expected1 = new MockPart("pfilelist", "Hello World 1".getBytes());
	MockPart expected2 = new MockPart("pfilelist", "Hello World 2".getBytes());
	request.addPart(expected1);
	request.addPart(expected2);
	request.addPart(new MockPart("other", "Hello World 3".getBytes()));
	webRequest = new ServletWebRequest(request);

	MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(List.class, Part.class);
	Object result = resolver.resolveArgument(param, null, webRequest, null);

	assertTrue(result instanceof List);
	assertEquals(Arrays.asList(expected1, expected2), result);
}
 
Example #8
Source File: RequestParamMapMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void resolveMultiValueMapOfPart() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setContentType("multipart/form-data");
	Part expected1 = new MockPart("mfilelist", "Hello World 1".getBytes());
	Part expected2 = new MockPart("mfilelist", "Hello World 2".getBytes());
	Part expected3 = new MockPart("other", "Hello World 3".getBytes());
	request.addPart(expected1);
	request.addPart(expected2);
	request.addPart(expected3);
	webRequest = new ServletWebRequest(request);

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

	assertTrue(result instanceof MultiValueMap);
	MultiValueMap<String, Part> resultMap = (MultiValueMap<String, Part>) 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 #9
Source File: RequestParamMapMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void resolveMapOfPart() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setContentType("multipart/form-data");
	Part expected1 = new MockPart("mfile", "Hello World".getBytes());
	Part expected2 = new MockPart("other", "Hello World 3".getBytes());
	request.addPart(expected1);
	request.addPart(expected2);
	webRequest = new ServletWebRequest(request);

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

	assertTrue(result instanceof Map);
	Map<String, Part> resultMap = (Map<String, Part>) result;
	assertEquals(2, resultMap.size());
	assertEquals(expected1, resultMap.get("mfile"));
	assertEquals(expected2, resultMap.get("other"));
}
 
Example #10
Source File: RequestPartMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void resolveOptionalPartList() throws Exception {
	MockPart expected = new MockPart("requestPart", "Hello World".getBytes());
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	request.addPart(expected);
	request.addPart(new MockPart("otherPart", "Hello World".getBytes()));
	webRequest = new ServletWebRequest(request);

	Object actualValue = resolver.resolveArgument(optionalPartList, null, webRequest, null);
	assertTrue(actualValue instanceof Optional);
	assertEquals("Invalid result", Collections.singletonList(expected), ((Optional<?>) actualValue).get());

	actualValue = resolver.resolveArgument(optionalPartList, null, webRequest, null);
	assertTrue(actualValue instanceof Optional);
	assertEquals("Invalid result", Collections.singletonList(expected), ((Optional<?>) actualValue).get());
}
 
Example #11
Source File: RequestPartMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void resolveOptionalPartArgument() throws Exception {
	MockPart expected = new MockPart("optionalPart", "Hello World".getBytes());
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	request.addPart(expected);
	request.addPart(new MockPart("otherPart", "Hello World".getBytes()));
	webRequest = new ServletWebRequest(request);

	Object actualValue = resolver.resolveArgument(optionalPart, null, webRequest, null);
	assertTrue(actualValue instanceof Optional);
	assertEquals("Invalid result", expected, ((Optional<?>) actualValue).get());

	actualValue = resolver.resolveArgument(optionalPart, null, webRequest, null);
	assertTrue(actualValue instanceof Optional);
	assertEquals("Invalid result", expected, ((Optional<?>) actualValue).get());
}
 
Example #12
Source File: RequestPartMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void resolvePartArrayArgument() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	MockPart part1 = new MockPart("requestPart", "Hello World 1".getBytes());
	MockPart part2 = new MockPart("requestPart", "Hello World 2".getBytes());
	request.addPart(part1);
	request.addPart(part2);
	request.addPart(new MockPart("otherPart", "Hello World".getBytes()));
	webRequest = new ServletWebRequest(request);

	Object result = resolver.resolveArgument(paramPartArray, null, webRequest, null);
	assertTrue(result instanceof Part[]);
	Part[] parts = (Part[]) result;
	assertEquals(2, parts.length);
	assertEquals(parts[0], part1);
	assertEquals(parts[1], part2);
}
 
Example #13
Source File: RequestPartMethodArgumentResolverTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void resolvePartListArgument() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	MockPart part1 = new MockPart("requestPart", "Hello World 1".getBytes());
	MockPart part2 = new MockPart("requestPart", "Hello World 2".getBytes());
	request.addPart(part1);
	request.addPart(part2);
	request.addPart(new MockPart("otherPart", "Hello World".getBytes()));
	webRequest = new ServletWebRequest(request);

	Object result = resolver.resolveArgument(paramPartList, null, webRequest, null);
	assertTrue(result instanceof List);
	assertEquals(Arrays.asList(part1, part2), result);
}
 
Example #14
Source File: RequestParamMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void resolvePartArray() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	MockPart expected1 = new MockPart("pfilearray", "Hello World 1".getBytes());
	MockPart expected2 = new MockPart("pfilearray", "Hello World 2".getBytes());
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	request.addPart(expected1);
	request.addPart(expected2);
	request.addPart(new MockPart("other", "Hello World 3".getBytes()));
	webRequest = new ServletWebRequest(request);

	MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Part[].class);
	Object result = resolver.resolveArgument(param, null, webRequest, null);

	assertTrue(result instanceof Part[]);
	Part[] parts = (Part[]) result;
	assertEquals(2, parts.length);
	assertEquals(parts[0], expected1);
	assertEquals(parts[1], expected2);
}
 
Example #15
Source File: RequestParamMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void resolvePartList() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	MockPart expected1 = new MockPart("pfilelist", "Hello World 1".getBytes());
	MockPart expected2 = new MockPart("pfilelist", "Hello World 2".getBytes());
	request.addPart(expected1);
	request.addPart(expected2);
	request.addPart(new MockPart("other", "Hello World 3".getBytes()));
	webRequest = new ServletWebRequest(request);

	MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(List.class, Part.class);
	Object result = resolver.resolveArgument(param, null, webRequest, null);

	assertTrue(result instanceof List);
	assertEquals(Arrays.asList(expected1, expected2), result);
}
 
Example #16
Source File: RequestPartMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void resolvePartArrayArgument() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	MockPart part1 = new MockPart("requestPart", "Hello World 1".getBytes());
	MockPart part2 = new MockPart("requestPart", "Hello World 2".getBytes());
	request.addPart(part1);
	request.addPart(part2);
	request.addPart(new MockPart("otherPart", "Hello World".getBytes()));
	webRequest = new ServletWebRequest(request);

	Object result = resolver.resolveArgument(paramPartArray, null, webRequest, null);
	assertTrue(result instanceof Part[]);
	Part[] parts = (Part[]) result;
	assertEquals(2, parts.length);
	assertEquals(parts[0], part1);
	assertEquals(parts[1], part2);
}
 
Example #17
Source File: RequestParamMapMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void resolveMultiValueMapOfPart() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setContentType("multipart/form-data");
	Part expected1 = new MockPart("mfilelist", "Hello World 1".getBytes());
	Part expected2 = new MockPart("mfilelist", "Hello World 2".getBytes());
	Part expected3 = new MockPart("other", "Hello World 3".getBytes());
	request.addPart(expected1);
	request.addPart(expected2);
	request.addPart(expected3);
	webRequest = new ServletWebRequest(request);

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

	assertTrue(result instanceof MultiValueMap);
	MultiValueMap<String, Part> resultMap = (MultiValueMap<String, Part>) 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 #18
Source File: RequestParamMapMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void resolveMapOfPart() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setContentType("multipart/form-data");
	Part expected1 = new MockPart("mfile", "Hello World".getBytes());
	Part expected2 = new MockPart("other", "Hello World 3".getBytes());
	request.addPart(expected1);
	request.addPart(expected2);
	webRequest = new ServletWebRequest(request);

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

	assertTrue(result instanceof Map);
	Map<String, Part> resultMap = (Map<String, Part>) result;
	assertEquals(2, resultMap.size());
	assertEquals(expected1, resultMap.get("mfile"));
	assertEquals(expected2, resultMap.get("other"));
}
 
Example #19
Source File: RequestPartMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void resolveOptionalPartArgument() throws Exception {
	MockPart expected = new MockPart("optionalPart", "Hello World".getBytes());
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	request.addPart(expected);
	request.addPart(new MockPart("otherPart", "Hello World".getBytes()));
	webRequest = new ServletWebRequest(request);

	Object actualValue = resolver.resolveArgument(optionalPart, null, webRequest, null);
	assertTrue(actualValue instanceof Optional);
	assertEquals("Invalid result", expected, ((Optional<?>) actualValue).get());

	actualValue = resolver.resolveArgument(optionalPart, null, webRequest, null);
	assertTrue(actualValue instanceof Optional);
	assertEquals("Invalid result", expected, ((Optional<?>) actualValue).get());
}
 
Example #20
Source File: RequestPartMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void resolveOptionalPartList() throws Exception {
	MockPart expected = new MockPart("requestPart", "Hello World".getBytes());
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	request.addPart(expected);
	request.addPart(new MockPart("otherPart", "Hello World".getBytes()));
	webRequest = new ServletWebRequest(request);

	Object actualValue = resolver.resolveArgument(optionalPartList, null, webRequest, null);
	assertTrue(actualValue instanceof Optional);
	assertEquals("Invalid result", Collections.singletonList(expected), ((Optional<?>) actualValue).get());

	actualValue = resolver.resolveArgument(optionalPartList, null, webRequest, null);
	assertTrue(actualValue instanceof Optional);
	assertEquals("Invalid result", Collections.singletonList(expected), ((Optional<?>) actualValue).get());
}
 
Example #21
Source File: StandardMultipartHttpServletRequestTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private StandardMultipartHttpServletRequest requestWithPart(String name, String disposition, String content) {
	MockHttpServletRequest request = new MockHttpServletRequest();
	MockPart part = new MockPart(name, null, content.getBytes(StandardCharsets.UTF_8));
	part.getHeaders().set("Content-Disposition", disposition);
	request.addPart(part);
	return new StandardMultipartHttpServletRequest(request);
}
 
Example #22
Source File: RequestParamMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void resolvePartNotAnnot() throws Exception {
	MockPart expected = new MockPart("part", "Hello World".getBytes());
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	request.addPart(expected);
	webRequest = new ServletWebRequest(request);

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

	assertTrue(result instanceof Part);
	assertEquals("Invalid result", expected, result);
}
 
Example #23
Source File: RequestPartMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void resolvePartArgument() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	MockPart expected = new MockPart("part", "Hello World".getBytes());
	request.addPart(expected);
	request.addPart(new MockPart("otherPart", "Hello World".getBytes()));
	webRequest = new ServletWebRequest(request);

	Object result = resolver.resolveArgument(paramPart, null, webRequest, null);
	assertTrue(result instanceof Part);
	assertEquals("Invalid result", expected, result);
}
 
Example #24
Source File: RequestParamMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void resolvePart() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	MockPart expected = new MockPart("pfile", "Hello World".getBytes());
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	request.addPart(expected);
	webRequest = new ServletWebRequest(request);

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

	assertTrue(result instanceof Part);
	assertEquals("Invalid result", expected, result);
}
 
Example #25
Source File: RequestPartMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void resolveOptionalPartArgument() throws Exception {
	MockPart expected = new MockPart("optionalPart", "Hello World".getBytes());
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	request.addPart(expected);
	webRequest = new ServletWebRequest(request);

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

	assertTrue(result instanceof Optional);
	assertEquals("Invalid result", expected, ((Optional) result).get());
}
 
Example #26
Source File: RequestPartMethodArgumentResolverTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void resolvePartArgument() throws Exception {
	MockPart expected = new MockPart("part", "Hello World".getBytes());
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	request.addPart(expected);
	webRequest = new ServletWebRequest(request);

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

	assertTrue(result instanceof Part);
	assertEquals("Invalid result", expected, result);
}
 
Example #27
Source File: RequestParamMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void resolvePartNotAnnot() throws Exception {
	MockPart expected = new MockPart("part", "Hello World".getBytes());
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	request.addPart(expected);
	webRequest = new ServletWebRequest(request);

	MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(Part.class);
	Object result = resolver.resolveArgument(param, null, webRequest, null);
	assertTrue(result instanceof Part);
	assertEquals("Invalid result", expected, result);
}
 
Example #28
Source File: RequestPartMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void resolvePartArgument() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	MockPart expected = new MockPart("part", "Hello World".getBytes());
	request.addPart(expected);
	request.addPart(new MockPart("otherPart", "Hello World".getBytes()));
	webRequest = new ServletWebRequest(request);

	Object result = resolver.resolveArgument(paramPart, null, webRequest, null);
	assertTrue(result instanceof Part);
	assertEquals("Invalid result", expected, result);
}
 
Example #29
Source File: RequestParamMethodArgumentResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void resolvePart() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	MockPart expected = new MockPart("pfile", "Hello World".getBytes());
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	request.addPart(expected);
	webRequest = new ServletWebRequest(request);

	MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Part.class);
	Object result = resolver.resolveArgument(param, null, webRequest, null);

	assertTrue(result instanceof Part);
	assertEquals("Invalid result", expected, result);
}
 
Example #30
Source File: RequestParamMethodArgumentResolverTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void resolvePart() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	MockPart expected = new MockPart("pfile", "Hello World".getBytes());
	request.setMethod("POST");
	request.setContentType("multipart/form-data");
	request.addPart(expected);
	webRequest = new ServletWebRequest(request);

	MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Part.class);
	Object result = resolver.resolveArgument(param, null, webRequest, null);

	assertTrue(result instanceof Part);
	assertEquals("Invalid result", expected, result);
}