Search in sources :

Example 1 with MockHttpServletRequest

use of org.apache.commons.fileupload.MockHttpServletRequest in project opencast by opencast.

the class IngestRestServiceTest method newPartialMockRequest.

private MockHttpServletRequest newPartialMockRequest() throws Exception {
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    StringBuilder requestBody = new StringBuilder();
    requestBody.append("-----1234\r\n");
    requestBody.append("Content-Disposition: form-data; name=\"flavor\"\r\n");
    requestBody.append("\r\ntest/flavor\r\n");
    requestBody.append("-----1234\r\n");
    requestBody.append("Content-Disposition: form-data; name=\"mediaPackage\"\r\n");
    requestBody.append("\r\n");
    requestBody.append(MediaPackageParser.getAsXml(mp));
    requestBody.append("\r\n");
    requestBody.append("-----1234\r\n");
    requestBody.append("Content-Disposition: form-data; name=\"startTime\"\r\n");
    requestBody.append("\r\n2000\r\n");
    requestBody.append("-----1234\r\n");
    requestBody.append("Content-Disposition: form-data; name=\"file\"; filename=\"catalog.txt\"\r\n");
    requestBody.append("Content-Type: text/whatever\r\n");
    requestBody.append("\r\n");
    requestBody.append("This is the content of the file\n");
    requestBody.append("\r\n");
    requestBody.append("-----1234");
    return new MockHttpServletRequest(requestBody.toString().getBytes("UTF-8"), "multipart/form-data; boundary=---1234");
}
Also used : MockHttpServletRequest(org.apache.commons.fileupload.MockHttpServletRequest) MediaPackage(org.opencastproject.mediapackage.MediaPackage)

Example 2 with MockHttpServletRequest

use of org.apache.commons.fileupload.MockHttpServletRequest in project opencast by opencast.

the class StaticFileRestServiceTest method newUnsizedMockRequest.

private MockHttpServletRequest newUnsizedMockRequest() throws Exception {
    StringBuilder requestBody = new StringBuilder();
    requestBody.append("-----1234\r\n");
    requestBody.append("Content-Disposition: form-data; name=\"file\"; filename=\"other.mov\"\r\n");
    requestBody.append("Content-Type: text/whatever\r\n");
    requestBody.append("\r\n");
    requestBody.append(MOCK_FILE_CONTENT);
    requestBody.append("\r\n");
    requestBody.append("-----1234");
    return new MockHttpServletRequest(new ByteArrayInputStream(requestBody.toString().getBytes("UTF-8")), -1, "multipart/form-data; boundary=---1234");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MockHttpServletRequest(org.apache.commons.fileupload.MockHttpServletRequest)

Example 3 with MockHttpServletRequest

use of org.apache.commons.fileupload.MockHttpServletRequest in project opencast by opencast.

the class IngestRestServiceTest method newMockRequest.

private HttpServletRequest newMockRequest() throws Exception {
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    StringBuilder requestBody = new StringBuilder();
    requestBody.append("-----1234\r\n");
    requestBody.append("Content-Disposition: form-data; name=\"flavor\"\r\n");
    requestBody.append("\r\ntest/flavor\r\n");
    requestBody.append("-----1234\r\n");
    requestBody.append("Content-Disposition: form-data; name=\"mediaPackage\"\r\n");
    requestBody.append("\r\n");
    requestBody.append(MediaPackageParser.getAsXml(mp));
    requestBody.append("\r\n");
    requestBody.append("-----1234\r\n");
    requestBody.append("Content-Disposition: form-data; name=\"file\"; filename=\"catalog.txt\"\r\n");
    requestBody.append("Content-Type: text/whatever\r\n");
    requestBody.append("\r\n");
    requestBody.append("This is the content of the file\n");
    requestBody.append("\r\n");
    requestBody.append("-----1234");
    return new MockHttpServletRequest(requestBody.toString().getBytes("UTF-8"), "multipart/form-data; boundary=---1234");
}
Also used : MockHttpServletRequest(org.apache.commons.fileupload.MockHttpServletRequest) MediaPackage(org.opencastproject.mediapackage.MediaPackage)

Example 4 with MockHttpServletRequest

use of org.apache.commons.fileupload.MockHttpServletRequest in project opencast by opencast.

the class IngestRestServiceTest method testAddMediaPackageTrackWithStartTime.

@Test
public void testAddMediaPackageTrackWithStartTime() throws Exception {
    IngestService ingestService = EasyMock.createNiceMock(IngestService.class);
    EasyMock.expect(ingestService.addPartialTrack((InputStream) EasyMock.anyObject(), (String) EasyMock.anyObject(), (MediaPackageElementFlavor) EasyMock.anyObject(), EasyMock.anyLong(), (MediaPackage) EasyMock.anyObject())).andReturn(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew()).once();
    EasyMock.expect(ingestService.addTrack((InputStream) EasyMock.anyObject(), (String) EasyMock.anyObject(), (MediaPackageElementFlavor) EasyMock.anyObject(), (String[]) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject())).andReturn(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew()).once();
    EasyMock.replay(ingestService);
    restService.setIngestService(ingestService);
    MockHttpServletRequest request = newPartialMockRequest();
    request.setPathInfo("/addTrack");
    Response response = restService.addMediaPackageTrack(request);
    assertEquals(Status.OK.getStatusCode(), response.getStatus());
    request = newPartialMockRequest();
    request.setPathInfo("/addPartialTrack");
    response = restService.addMediaPackageTrack(request);
    assertEquals(Status.OK.getStatusCode(), response.getStatus());
    EasyMock.verify(ingestService);
}
Also used : Response(javax.ws.rs.core.Response) IngestService(org.opencastproject.ingest.api.IngestService) ServletInputStream(javax.servlet.ServletInputStream) InputStream(java.io.InputStream) MockHttpServletRequest(org.apache.commons.fileupload.MockHttpServletRequest) MediaPackage(org.opencastproject.mediapackage.MediaPackage) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) Test(org.junit.Test)

Aggregations

MockHttpServletRequest (org.apache.commons.fileupload.MockHttpServletRequest)4 MediaPackage (org.opencastproject.mediapackage.MediaPackage)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ServletInputStream (javax.servlet.ServletInputStream)1 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1 IngestService (org.opencastproject.ingest.api.IngestService)1 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)1