本文整理汇总了Java中org.springframework.mock.web.MockMultipartHttpServletRequest类的典型用法代码示例。如果您正苦于以下问题:Java MockMultipartHttpServletRequest类的具体用法?Java MockMultipartHttpServletRequest怎么用?Java MockMultipartHttpServletRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MockMultipartHttpServletRequest类属于org.springframework.mock.web包,在下文中一共展示了MockMultipartHttpServletRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldReturnHttpErrorCodeWhenChecksumFileSaveFails
import org.springframework.mock.web.MockMultipartHttpServletRequest; //导入依赖的package包/类
@Test
public void shouldReturnHttpErrorCodeWhenChecksumFileSaveFails() throws Exception {
File artifactFile = new File("junk");
when(artifactService.findArtifact(any(JobIdentifier.class), eq("some-path"))).thenReturn(artifactFile);
when(artifactService.saveFile(any(File.class), any(InputStream.class), eq(false), eq(1))).thenReturn(true);
when(artifactService.saveOrAppendFile(any(File.class), any(InputStream.class))).thenReturn(false);
MockMultipartHttpServletRequest mockMultipartHttpServletRequest = new MockMultipartHttpServletRequest();
mockMultipartHttpServletRequest.addFile(new MockMultipartFile(REGULAR_MULTIPART_FILENAME, "content".getBytes()));
mockMultipartHttpServletRequest.addFile(new MockMultipartFile(CHECKSUM_MULTIPART_FILENAME, "checksum-content".getBytes()));
ModelAndView modelAndView = artifactsController.postArtifact("pipeline-1", "1", "stage-1", "2", "job-1", 122L, "some-path", 1, mockMultipartHttpServletRequest);
ResponseCodeView view = (ResponseCodeView) modelAndView.getView();
assertThat(view.getStatusCode(), is(SC_INTERNAL_SERVER_ERROR));
assertThat(view.getContent(), is("Error saving checksum file for the artifact at path 'some-path'"));
}
示例2: doPipeHttpRequestTest
import org.springframework.mock.web.MockMultipartHttpServletRequest; //导入依赖的package包/类
@Test
public void doPipeHttpRequestTest() throws Exception {
StreamPipe streamPipe = new StreamPipe();
streamPipe.registerForward(createPipeSuccessForward());
MockMultipartHttpServletRequest request = createMultipartHttpRequest();
streamPipe.addParameter(createHttpRequestParameter(request, session));
streamPipe.configure();
PipeRunResult pipeRunResult = streamPipe.doPipe("", session);
assertEquals("success", pipeRunResult.getPipeForward().getName());
String expectedResult = "<parts>"
+ "<part type=\"string\" name=\"string1\" sessionKey=\"part_string\" size=\"19\"/>"
+ "<part type=\"file\" name=\"doc001.pdf\" sessionKey=\"part_file\" size=\"26358\" mimeType=\"application/octet-stream; charset=ISO-8859-1\"/>"
+ "<part type=\"file\" name=\"doc002.pdf\" sessionKey=\"part_file2\" size=\"25879\" mimeType=\"application/octet-stream; charset=ISO-8859-1\"/>"
+ "</parts>";
assertEquals(expectedResult, pipeRunResult.getResult());
}
示例3: doPipeHttpRequestAntiVirusTest
import org.springframework.mock.web.MockMultipartHttpServletRequest; //导入依赖的package包/类
@Test
public void doPipeHttpRequestAntiVirusTest() throws Exception {
StreamPipe streamPipe = new StreamPipe();
streamPipe.registerForward(createPipeSuccessForward());
MockMultipartHttpServletRequest request = createMultipartHttpRequest(
streamPipe, true);
streamPipe.addParameter(createHttpRequestParameter(request, session));
streamPipe.configure();
PipeRunResult pipeRunResult = streamPipe.doPipe("", session);
assertEquals("success", pipeRunResult.getPipeForward().getName());
String expectedResult = "<parts>"
+ "<part type=\"string\" name=\"string1\" sessionKey=\"part_string\" size=\"19\"/>"
+ "<part type=\"file\" name=\"doc001.pdf\" sessionKey=\"part_file\" size=\"26358\" mimeType=\"application/octet-stream; charset=ISO-8859-1\"/>"
+ "<part type=\"string\" name=\"antivirus_rc\" sessionKey=\"part_string2\" size=\"4\"/>"
+ "<part type=\"file\" name=\"doc002.pdf\" sessionKey=\"part_file2\" size=\"25879\" mimeType=\"application/octet-stream; charset=ISO-8859-1\"/>"
+ "<part type=\"string\" name=\"antivirus_rc\" sessionKey=\"part_string3\" size=\"4\"/>"
+ "</parts>";
assertEquals(expectedResult, pipeRunResult.getResult());
}
示例4: doPipeHttpRequestCheckAntiVirusPassedTest
import org.springframework.mock.web.MockMultipartHttpServletRequest; //导入依赖的package包/类
@Test
public void doPipeHttpRequestCheckAntiVirusPassedTest() throws Exception {
StreamPipe streamPipe = new StreamPipe();
streamPipe.setCheckAntiVirus(true);
streamPipe.registerForward(createPipeSuccessForward());
MockMultipartHttpServletRequest request = createMultipartHttpRequest(
streamPipe, true);
streamPipe.addParameter(createHttpRequestParameter(request, session));
streamPipe.configure();
PipeRunResult pipeRunResult = streamPipe.doPipe("", session);
assertEquals("success", pipeRunResult.getPipeForward().getName());
String expectedResult = "<parts>"
+ "<part type=\"string\" name=\"string1\" sessionKey=\"part_string\" size=\"19\"/>"
+ "<part type=\"file\" name=\"doc001.pdf\" sessionKey=\"part_file\" size=\"26358\" mimeType=\"application/octet-stream; charset=ISO-8859-1\"/>"
+ "<part type=\"file\" name=\"doc002.pdf\" sessionKey=\"part_file2\" size=\"25879\" mimeType=\"application/octet-stream; charset=ISO-8859-1\"/>"
+ "</parts>";
assertEquals(expectedResult, pipeRunResult.getResult());
}
示例5: doPipeHttpRequestCheckAntiVirusFailedTest
import org.springframework.mock.web.MockMultipartHttpServletRequest; //导入依赖的package包/类
@Test
public void doPipeHttpRequestCheckAntiVirusFailedTest() throws Exception {
StreamPipe streamPipe = new StreamPipe();
streamPipe.setCheckAntiVirus(true);
PipeForward pipeAntiVirusFailedForward = new PipeForward();
pipeAntiVirusFailedForward.setName(StreamPipe.ANTIVIRUS_FAILED_FORWARD);
streamPipe.registerForward(pipeAntiVirusFailedForward);
streamPipe.registerForward(createPipeSuccessForward());
MockMultipartHttpServletRequest request = createMultipartHttpRequest(
streamPipe, true, true);
streamPipe.addParameter(createHttpRequestParameter(request, session));
streamPipe.configure();
PipeRunResult pipeRunResult = streamPipe.doPipe("", session);
assertEquals("antiVirusFailed",
pipeRunResult.getPipeForward().getName());
String expectedResult = "multipart contains file [doc002.pdf] with antivirus status [Fail]";
assertEquals(expectedResult, pipeRunResult.getResult());
}
示例6: testValidationWithServletRequest
import org.springframework.mock.web.MockMultipartHttpServletRequest; //导入依赖的package包/类
@Test
public void testValidationWithServletRequest(){
Employee employee = new Employee();
MockHttpServletRequest request = new MockMultipartHttpServletRequest();
ServletRequestDataBinder binder = new ServletRequestDataBinder(employee, "employee");
request.addParameter("empId", "AA1001");
request.addParameter("empName", "But You");
request.addParameter("empAge", "12");
binder.bind(request);
Validator validator = new EmployeeValidator();
Errors errors = binder.getBindingResult();
validator.validate(employee, errors);
assertFalse(errors.hasFieldErrors("empId"));
assertFalse(errors.hasFieldErrors("empName"));
assertTrue(errors.hasFieldErrors("empAge"));
}
示例7: testCommandMapWithHttpMultiparRequest
import org.springframework.mock.web.MockMultipartHttpServletRequest; //导入依赖的package包/类
@Test
public void testCommandMapWithHttpMultiparRequest() throws ServletException, IOException{
MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest();
MockHttpServletResponse mockResponse = new MockHttpServletResponse();
mockRequest.setMethod("POST");
mockRequest.setRequestURI("/test.do");
mockRequest.addParameter("USA", "washington");
mockRequest.addParameter("japan", "tokyo");
mockRequest.addParameter("korea", "seoul");
dispatcher.service(mockRequest, mockResponse);
assertEquals("washington",mockRequest.getAttribute("USA"));
assertEquals("tokyo",mockRequest.getAttribute("japan"));
assertEquals("seoul",mockRequest.getAttribute("korea"));
}
示例8: createServletRequest
import org.springframework.mock.web.MockMultipartHttpServletRequest; //导入依赖的package包/类
/**
* Create a new {@link MockMultipartHttpServletRequest} based on the
* supplied {@code ServletContext} and the {@code MockMultipartFiles}
* added to this builder.
*/
@Override
protected final MockHttpServletRequest createServletRequest(ServletContext servletContext) {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(servletContext);
for (MockMultipartFile file : this.files) {
request.addFile(file);
}
return request;
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:MockMultipartHttpServletRequestBuilder.java
示例9: createServletRequest
import org.springframework.mock.web.MockMultipartHttpServletRequest; //导入依赖的package包/类
/**
* Create a new {@link MockMultipartHttpServletRequest} based on the supplied {@code
* ServletContext} and the {@code MockMultipartFiles} added to this builder.
*/
@Override
protected final MockHttpServletRequest createServletRequest(ServletContext servletContext) {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(servletContext);
for (MockMultipartFile file : this.files) {
request.addFile(file);
}
return request;
}
示例10: testMultipartRequest
import org.springframework.mock.web.MockMultipartHttpServletRequest; //导入依赖的package包/类
@Test
public void testMultipartRequest() throws Exception {
MockMultipartFile mockMultipartFile = new MockMultipartFile("schnobb.txt", "wobb".getBytes(Charset.forName("UTF-8")));
MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest();
mockRequest.addFile(mockMultipartFile);
ParameterMap params = new ParameterMap(mockRequest);
assertThat((MockMultipartFile) params.get("schnobb.txt"), sameInstance(mockMultipartFile));
}
示例11: createServletRequest
import org.springframework.mock.web.MockMultipartHttpServletRequest; //导入依赖的package包/类
@Override
protected final MockHttpServletRequest createServletRequest(ServletContext servletContext) {
MockMultipartHttpServletRequest request =
(servlet3Present ? createServlet3Request() : new MockMultipartHttpServletRequest());
for (MockMultipartFile file : this.files) {
request.addFile(file);
}
return request;
}
示例12: createServlet3Request
import org.springframework.mock.web.MockMultipartHttpServletRequest; //导入依赖的package包/类
private MockMultipartHttpServletRequest createServlet3Request() {
try {
String className = "org.springframework.test.web.servlet.request.Servlet3MockMultipartHttpServletRequest";
Class<?> clazz = ClassUtils.forName(className, MockMultipartHttpServletRequestBuilder.class.getClassLoader());
Constructor<?> constructor = clazz.getDeclaredConstructor();
return (MockMultipartHttpServletRequest) BeanUtils.instantiateClass(constructor);
}
catch (Throwable ex) {
throw new IllegalStateException("Failed to instantiate MockMultipartHttpServletRequest", ex);
}
}
示例13: mockMultipartHttpServletRequestWithByteArray
import org.springframework.mock.web.MockMultipartHttpServletRequest; //导入依赖的package包/类
@Test
public void mockMultipartHttpServletRequestWithByteArray() throws IOException {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
assertFalse(request.getFileNames().hasNext());
assertNull(request.getFile("file1"));
assertNull(request.getFile("file2"));
assertTrue(request.getFileMap().isEmpty());
request.addFile(new MockMultipartFile("file1", "myContent1".getBytes()));
request.addFile(new MockMultipartFile("file2", "myOrigFilename", "text/plain", "myContent2".getBytes()));
doTestMultipartHttpServletRequest(request);
}
示例14: mockMultipartHttpServletRequestWithInputStream
import org.springframework.mock.web.MockMultipartHttpServletRequest; //导入依赖的package包/类
@Test
public void mockMultipartHttpServletRequestWithInputStream() throws IOException {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
request.addFile(new MockMultipartFile("file1", new ByteArrayInputStream("myContent1".getBytes())));
request.addFile(new MockMultipartFile("file2", "myOrigFilename", "text/plain", new ByteArrayInputStream(
"myContent2".getBytes())));
doTestMultipartHttpServletRequest(request);
}
示例15: getFormValues
import org.springframework.mock.web.MockMultipartHttpServletRequest; //导入依赖的package包/类
@Override
public Values getFormValues() {
final Values values = new Values(delegate.getParameterMap());
if (delegate instanceof MockMultipartHttpServletRequest) {
for (final Map.Entry<String, List<MultipartFile>> entry : ((MockMultipartHttpServletRequest) delegate).getMultiFileMap().entrySet()) {
for (int i = 0; i < entry.getValue().size(); i++) {
values.addValue(entry.getKey(), new FileValue());
}
}
}
return values;
}