本文整理汇总了Java中org.springframework.mock.web.MockMultipartHttpServletRequest.addFile方法的典型用法代码示例。如果您正苦于以下问题:Java MockMultipartHttpServletRequest.addFile方法的具体用法?Java MockMultipartHttpServletRequest.addFile怎么用?Java MockMultipartHttpServletRequest.addFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.mock.web.MockMultipartHttpServletRequest
的用法示例。
在下文中一共展示了MockMultipartHttpServletRequest.addFile方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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
示例3: 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;
}
示例4: 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));
}
示例5: 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;
}
示例6: 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);
}
示例7: 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);
}
示例8: getMockMultipartHttpServletRequestForMockObsWithComplexConcept
import org.springframework.mock.web.MockMultipartHttpServletRequest; //导入方法依赖的package包/类
/**
* Convenience method constructing a multipart http servlet request for the tests
*/
public static MockMultipartHttpServletRequest getMockMultipartHttpServletRequestForMockObsWithComplexConcept() {
MockMultipartHttpServletRequest mockRequest = new MockMultipartHttpServletRequest();
mockRequest.addFile(getMockMultipartFileForMockObsWithComplexConcept());
return mockRequest;
}