List of usage examples for org.apache.commons.httpclient.methods PostMethod PostMethod
public PostMethod()
From source file:ch.sportchef.business.event.bundary.EventImageResourceTest.java
@Test public void uploadImageWithOK() throws IOException, ServletException { // arrange/*from ww w. ja v a 2 s. c o m*/ final byte[] fileContent = readTestImage(); final Part[] parts = new Part[] { new FilePart(TEST_IMAGE_NAME, new ByteArrayPartSource(TEST_IMAGE_NAME, fileContent)) }; final MultipartRequestEntity multipartRequestEntity = new MultipartRequestEntity(parts, new PostMethod().getParams()); final ByteArrayOutputStream requestContent = new ByteArrayOutputStream(); multipartRequestEntity.writeRequest(requestContent); final ByteArrayInputStream inputStream = new ByteArrayInputStream(requestContent.toByteArray()); final ServletInputStreamMock inputStreamMock = new ServletInputStreamMock(inputStream); final String contentType = multipartRequestEntity.getContentType(); expect(httpServletRequest.getContentType()).andStubReturn(contentType); expect(httpServletRequest.getInputStream()).andStubReturn(inputStreamMock); eventImageServiceMock.uploadImage(anyLong(), anyObject()); mockProvider.replayAll(); // act final Response response = eventImageResource.uploadImage(httpServletRequest); // assert assertThat(response.getStatus(), is(OK.getStatusCode())); mockProvider.verifyAll(); }