use of org.opencastproject.workingfilerepository.impl.WorkingFileRepositoryImpl in project opencast by opencast.
the class IngestServiceImplTest method testSmilCreation.
@Test
public void testSmilCreation() throws Exception {
service.setWorkingFileRepository(new WorkingFileRepositoryImpl() {
@Override
public URI put(String mediaPackageID, String mediaPackageElementID, String filename, InputStream in) throws IOException {
File file = new File(FileUtils.getTempDirectory(), mediaPackageElementID);
file.deleteOnExit();
FileUtils.write(file, IOUtils.toString(in), "UTF-8");
return file.toURI();
}
@Override
public InputStream get(String mediaPackageID, String mediaPackageElementID) throws NotFoundException, IOException {
File file = new File(FileUtils.getTempDirectory(), mediaPackageElementID);
return new FileInputStream(file);
}
});
URI presenterUri = URI.create("http://localhost:8080/presenter.mp4");
URI presenterUri2 = URI.create("http://localhost:8080/presenter2.mp4");
URI presentationUri = URI.create("http://localhost:8080/presentation.mp4");
MediaPackage mediaPackage = service.createMediaPackage();
Catalog[] catalogs = mediaPackage.getCatalogs(MediaPackageElements.SMIL);
Assert.assertEquals(0, catalogs.length);
mediaPackage = service.addPartialTrack(presenterUri, MediaPackageElements.PRESENTER_SOURCE_PARTIAL, 60000L, mediaPackage);
mediaPackage = service.addPartialTrack(presenterUri2, MediaPackageElements.PRESENTER_SOURCE_PARTIAL, 120000L, mediaPackage);
mediaPackage = service.addPartialTrack(presentationUri, MediaPackageElements.PRESENTATION_SOURCE_PARTIAL, 0L, mediaPackage);
catalogs = mediaPackage.getCatalogs(MediaPackageElements.SMIL);
Assert.assertEquals(0, catalogs.length);
service.ingest(mediaPackage);
catalogs = mediaPackage.getCatalogs(MediaPackageElements.SMIL);
Assert.assertEquals(1, catalogs.length);
Assert.assertEquals(MimeTypes.SMIL, catalogs[0].getMimeType());
Either<Exception, Document> eitherDoc = XmlUtil.parseNs(new InputSource(catalogs[0].getURI().toURL().openStream()));
Assert.assertTrue(eitherDoc.isRight());
Document document = eitherDoc.right().value();
Assert.assertEquals(1, document.getElementsByTagName("par").getLength());
Assert.assertEquals(2, document.getElementsByTagName("seq").getLength());
Assert.assertEquals(2, document.getElementsByTagName("video").getLength());
Assert.assertEquals(1, document.getElementsByTagName("audio").getLength());
}
Aggregations