当前位置: 首页>>代码示例>>Java>>正文


Java MockMultipartHttpServletRequest类代码示例

本文整理汇总了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'"));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:19,代码来源:ArtifactsControllerTest.java

示例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());
}
 
开发者ID:ibissource,项目名称:iaf,代码行数:17,代码来源:StreamPipeTest.java

示例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());
}
 
开发者ID:ibissource,项目名称:iaf,代码行数:20,代码来源:StreamPipeTest.java

示例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());
}
 
开发者ID:ibissource,项目名称:iaf,代码行数:19,代码来源:StreamPipeTest.java

示例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());
}
 
开发者ID:ibissource,项目名称:iaf,代码行数:19,代码来源:StreamPipeTest.java

示例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"));		
}
 
开发者ID:eGovFrame,项目名称:egovframework.rte.root,代码行数:21,代码来源:FormValidationTest.java

示例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"));				
}
 
开发者ID:eGovFrame,项目名称:egovframework.rte.root,代码行数:18,代码来源:CommandMapArgumentResolverTest.java

示例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;
}
 
开发者ID:reflectoring,项目名称:coderadar,代码行数:13,代码来源:ExtendedMockHttpServletRequestBuilder.java

示例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));
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:11,代码来源:ParameterMapTests.java

示例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;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:10,代码来源:MockMultipartHttpServletRequestBuilder.java

示例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);
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:12,代码来源:MockMultipartHttpServletRequestBuilder.java

示例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);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:13,代码来源:MockMultipartHttpServletRequestTests.java

示例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);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:9,代码来源:MockMultipartHttpServletRequestTests.java

示例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;
}
 
开发者ID:nidi3,项目名称:raml-tester,代码行数:13,代码来源:SpringMockRamlRequest.java


注:本文中的org.springframework.mock.web.MockMultipartHttpServletRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。