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");
}
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");
}
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");
}
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);
}
Aggregations