Search in sources :

Example 1 with WorkingFileRepositoryImpl

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());
}
Also used : InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) Document(org.w3c.dom.Document) URI(java.net.URI) FileInputStream(java.io.FileInputStream) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Catalog(org.opencastproject.mediapackage.Catalog) URISyntaxException(java.net.URISyntaxException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkingFileRepositoryImpl(org.opencastproject.workingfilerepository.impl.WorkingFileRepositoryImpl) File(java.io.File) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Test (org.junit.Test)1 Catalog (org.opencastproject.mediapackage.Catalog)1 MediaPackage (org.opencastproject.mediapackage.MediaPackage)1 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)1 NotFoundException (org.opencastproject.util.NotFoundException)1 WorkingFileRepositoryImpl (org.opencastproject.workingfilerepository.impl.WorkingFileRepositoryImpl)1 Document (org.w3c.dom.Document)1 InputSource (org.xml.sax.InputSource)1