Example usage for org.apache.commons.httpclient.methods PostMethod PostMethod

List of usage examples for org.apache.commons.httpclient.methods PostMethod PostMethod

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods PostMethod PostMethod.

Prototype

public PostMethod() 

Source Link

Usage

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();
}