Search in sources :

Example 1 with DefaultMediaPackageSerializerImpl

use of org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl in project opencast by opencast.

the class TrackTest method testLiveMarshalling.

@Test
public void testLiveMarshalling() throws Exception {
    track.setFlavor(MediaPackageElements.PRESENTATION_SOURCE);
    track.setLive(true);
    JAXBContext context = JAXBContext.newInstance("org.opencastproject.mediapackage:org.opencastproject.mediapackage.track", MediaPackage.class.getClassLoader());
    Marshaller marshaller = context.createMarshaller();
    StringWriter writer = new StringWriter();
    marshaller.marshal(track, writer);
    Unmarshaller unmarshaller = context.createUnmarshaller();
    InputStream inputStream = IOUtils.toInputStream(writer.toString(), "UTF-8");
    try {
        TrackImpl t1 = unmarshaller.unmarshal(new StreamSource(inputStream), TrackImpl.class).getValue();
        Assert.assertEquals(MediaPackageElements.PRESENTATION_SOURCE, t1.getFlavor());
        Assert.assertEquals(true, t1.isLive());
    } finally {
        IoSupport.closeQuietly(inputStream);
    }
    // Now again without namespaces
    String xml = "<oc:track xmlns:oc=\"http://mediapackage.opencastproject.org\" type=\"presentation/source\"><oc:tags/><oc:url>http://downloads.opencastproject.org/media/movie.m4v</oc:url><oc:duration>-1</oc:duration><oc:live>true</oc:live></oc:track>";
    inputStream = IOUtils.toInputStream(xml);
    try {
        TrackImpl t2 = unmarshaller.unmarshal(new StreamSource(inputStream), TrackImpl.class).getValue();
        Assert.assertEquals(MediaPackageElements.PRESENTATION_SOURCE, t2.getFlavor());
        Assert.assertEquals("http://downloads.opencastproject.org/media/movie.m4v", t2.getURI().toString());
        Assert.assertEquals(true, t2.isLive());
    } finally {
        IoSupport.closeQuietly(inputStream);
    }
    // Get the xml from the object itself
    String xmlFromTrack = MediaPackageElementParser.getAsXml(track);
    Assert.assertTrue(xmlFromTrack.contains(MediaPackageElements.PRESENTATION_SOURCE.toString()));
    Assert.assertTrue(xmlFromTrack.replaceAll("\\b+", "").contains("<live>true</live>"));
    // And finally, using the element builder
    DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = docBuilder.parse(IOUtils.toInputStream(xml));
    Track t3 = (Track) MediaPackageElementBuilderFactory.newInstance().newElementBuilder().elementFromManifest(doc.getDocumentElement(), new DefaultMediaPackageSerializerImpl());
    Assert.assertEquals(MediaPackageElements.PRESENTATION_SOURCE, t3.getFlavor());
    Assert.assertEquals("http://downloads.opencastproject.org/media/movie.m4v", t3.getURI().toURL().toExternalForm());
    Assert.assertEquals(true, t3.isLive());
}
Also used : Marshaller(javax.xml.bind.Marshaller) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) JAXBContext(javax.xml.bind.JAXBContext) Document(org.w3c.dom.Document) DefaultMediaPackageSerializerImpl(org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl) StringWriter(java.io.StringWriter) DocumentBuilder(javax.xml.parsers.DocumentBuilder) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Unmarshaller(javax.xml.bind.Unmarshaller) Track(org.opencastproject.mediapackage.Track) Test(org.junit.Test)

Example 2 with DefaultMediaPackageSerializerImpl

use of org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl in project opencast by opencast.

the class TrackTest method testFlavorMarshalling.

@Test
public void testFlavorMarshalling() throws Exception {
    track.setFlavor(MediaPackageElements.PRESENTATION_SOURCE);
    JAXBContext context = JAXBContext.newInstance("org.opencastproject.mediapackage:org.opencastproject.mediapackage.track", MediaPackage.class.getClassLoader());
    Marshaller marshaller = context.createMarshaller();
    StringWriter writer = new StringWriter();
    marshaller.marshal(track, writer);
    Unmarshaller unmarshaller = context.createUnmarshaller();
    InputStream inputStream = IOUtils.toInputStream(writer.toString(), "UTF-8");
    try {
        TrackImpl t1 = unmarshaller.unmarshal(new StreamSource(inputStream), TrackImpl.class).getValue();
        Assert.assertEquals(MediaPackageElements.PRESENTATION_SOURCE, t1.getFlavor());
    } finally {
        IoSupport.closeQuietly(inputStream);
    }
    // Now again without namespaces
    String xml = "<oc:track xmlns:oc=\"http://mediapackage.opencastproject.org\" type=\"presentation/source\"><oc:tags/><oc:url>http://downloads.opencastproject.org/media/movie.m4v</oc:url><oc:duration>-1</oc:duration></oc:track>";
    inputStream = IOUtils.toInputStream(xml);
    try {
        TrackImpl t2 = unmarshaller.unmarshal(new StreamSource(inputStream), TrackImpl.class).getValue();
        Assert.assertEquals(MediaPackageElements.PRESENTATION_SOURCE, t2.getFlavor());
        Assert.assertEquals("http://downloads.opencastproject.org/media/movie.m4v", t2.getURI().toString());
    } finally {
        IoSupport.closeQuietly(inputStream);
    }
    // Get the xml from the object itself
    String xmlFromTrack = MediaPackageElementParser.getAsXml(track);
    Assert.assertTrue(xmlFromTrack.contains(MediaPackageElements.PRESENTATION_SOURCE.toString()));
    // And finally, using the element builder
    DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = docBuilder.parse(IOUtils.toInputStream(xml));
    Track t3 = (Track) MediaPackageElementBuilderFactory.newInstance().newElementBuilder().elementFromManifest(doc.getDocumentElement(), new DefaultMediaPackageSerializerImpl());
    Assert.assertEquals(MediaPackageElements.PRESENTATION_SOURCE, t3.getFlavor());
    Assert.assertEquals("http://downloads.opencastproject.org/media/movie.m4v", t3.getURI().toURL().toExternalForm());
}
Also used : Marshaller(javax.xml.bind.Marshaller) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) JAXBContext(javax.xml.bind.JAXBContext) Document(org.w3c.dom.Document) DefaultMediaPackageSerializerImpl(org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl) StringWriter(java.io.StringWriter) DocumentBuilder(javax.xml.parsers.DocumentBuilder) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Unmarshaller(javax.xml.bind.Unmarshaller) Track(org.opencastproject.mediapackage.Track) Test(org.junit.Test)

Example 3 with DefaultMediaPackageSerializerImpl

use of org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl in project opencast by opencast.

the class SearchServiceImplTest method getMediaPackage.

private MediaPackage getMediaPackage(String path) throws MediaPackageException {
    MediaPackageBuilderFactory builderFactory = MediaPackageBuilderFactory.newInstance();
    MediaPackageBuilder mediaPackageBuilder = builderFactory.newMediaPackageBuilder();
    URL rootUrl = SearchServiceImplTest.class.getResource("/");
    mediaPackageBuilder.setSerializer(new DefaultMediaPackageSerializerImpl(rootUrl));
    // Load the simple media package
    MediaPackage mediaPackage = null;
    InputStream is = null;
    try {
        is = SearchServiceImplTest.class.getResourceAsStream(path);
        mediaPackage = mediaPackageBuilder.loadFromXml(is);
    } finally {
        IOUtils.closeQuietly(is);
    }
    return mediaPackage;
}
Also used : DefaultMediaPackageSerializerImpl(org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) InputStream(java.io.InputStream) MediaPackage(org.opencastproject.mediapackage.MediaPackage) MediaPackageBuilderFactory(org.opencastproject.mediapackage.MediaPackageBuilderFactory) URL(java.net.URL)

Example 4 with DefaultMediaPackageSerializerImpl

use of org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl in project opencast by opencast.

the class StaticMetadataServiceDublinCoreImplTest method newMediaPackage.

private MediaPackage newMediaPackage(String manifest) throws Exception {
    MediaPackageBuilderFactory builderFactory = MediaPackageBuilderFactory.newInstance();
    MediaPackageBuilder mediaPackageBuilder = builderFactory.newMediaPackageBuilder();
    URL rootUrl = getClass().getResource("/");
    mediaPackageBuilder.setSerializer(new DefaultMediaPackageSerializerImpl(rootUrl));
    InputStream is = null;
    try {
        is = getClass().getResourceAsStream(manifest);
        return mediaPackageBuilder.loadFromXml(is);
    } finally {
        IOUtils.closeQuietly(is);
    }
}
Also used : DefaultMediaPackageSerializerImpl(org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) InputStream(java.io.InputStream) MediaPackageBuilderFactory(org.opencastproject.mediapackage.MediaPackageBuilderFactory) URL(java.net.URL)

Example 5 with DefaultMediaPackageSerializerImpl

use of org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl in project opencast by opencast.

the class HoldStateTest method setUp.

@Before
public void setUp() throws Exception {
    // always start with a fresh solr root directory
    sRoot = new File(getStorageRoot());
    try {
        FileUtils.deleteDirectory(sRoot);
        FileUtils.forceMkdir(sRoot);
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }
    MediaPackageBuilder mediaPackageBuilder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    mediaPackageBuilder.setSerializer(new DefaultMediaPackageSerializerImpl(new File("target/test-classes")));
    InputStream is = CountWorkflowsTest.class.getResourceAsStream("/mediapackage-1.xml");
    mp = mediaPackageBuilder.loadFromXml(is);
    IOUtils.closeQuietly(is);
    // create operation handlers for our workflows
    final Set<HandlerRegistration> handlerRegistrations = new HashSet<HandlerRegistration>();
    holdingOperationHandler = new ResumableTestWorkflowOperationHandler();
    handlerRegistrations.add(new HandlerRegistration("op1", holdingOperationHandler));
    handlerRegistrations.add(new HandlerRegistration("op2", new ContinuingWorkflowOperationHandler()));
    // instantiate a service implementation and its DAO, overriding the methods that depend on the osgi runtime
    service = new WorkflowServiceImpl() {

        @Override
        public Set<HandlerRegistration> getRegisteredHandlers() {
            return handlerRegistrations;
        }
    };
    scanner = new WorkflowDefinitionScanner();
    service.addWorkflowDefinitionScanner(scanner);
    // security service
    securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(SecurityServiceStub.DEFAULT_ORG_ADMIN).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.replay(securityService);
    service.setSecurityService(securityService);
    AuthorizationService authzService = EasyMock.createNiceMock(AuthorizationService.class);
    EasyMock.expect(authzService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
    EasyMock.replay(authzService);
    service.setAuthorizationService(authzService);
    UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(DEFAULT_ORG_ADMIN).anyTimes();
    EasyMock.replay(userDirectoryService);
    service.setUserDirectoryService(userDirectoryService);
    Organization organization = new DefaultOrganization();
    List<Organization> organizationList = new ArrayList<Organization>();
    organizationList.add(organization);
    OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
    EasyMock.expect(organizationDirectoryService.getOrganizations()).andReturn(organizationList).anyTimes();
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
    EasyMock.replay(organizationDirectoryService);
    service.setOrganizationDirectoryService(organizationDirectoryService);
    MediaPackageMetadataService mds = EasyMock.createNiceMock(MediaPackageMetadataService.class);
    EasyMock.replay(mds);
    service.addMetadataService(mds);
    MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
    EasyMock.replay(messageSender);
    ServiceRegistryInMemoryImpl serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
    dao = new WorkflowServiceSolrIndex();
    dao.solrRoot = sRoot + File.separator + "solr";
    dao.setServiceRegistry(serviceRegistry);
    dao.setAuthorizationService(authzService);
    dao.setSecurityService(securityService);
    dao.setOrgDirectory(organizationDirectoryService);
    dao.activate("System Admin");
    service.setDao(dao);
    service.setMessageSender(messageSender);
    service.activate(null);
    service.setServiceRegistry(serviceRegistry);
    serviceRegistry.registerService(service);
    is = HoldStateTest.class.getResourceAsStream("/workflow-definition-holdstate.xml");
    def = WorkflowParser.parseWorkflowDefinition(is);
    IOUtils.closeQuietly(is);
    service.registerWorkflowDefinition(def);
}
Also used : IncidentService(org.opencastproject.serviceregistry.api.IncidentService) Set(java.util.Set) HashSet(java.util.HashSet) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) MessageSender(org.opencastproject.message.broker.api.MessageSender) ArrayList(java.util.ArrayList) MediaPackageMetadataService(org.opencastproject.metadata.api.MediaPackageMetadataService) DefaultMediaPackageSerializerImpl(org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) SecurityService(org.opencastproject.security.api.SecurityService) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) HashSet(java.util.HashSet) HandlerRegistration(org.opencastproject.workflow.impl.WorkflowServiceImpl.HandlerRegistration) InputStream(java.io.InputStream) IOException(java.io.IOException) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) AuthorizationService(org.opencastproject.security.api.AuthorizationService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) File(java.io.File) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Before(org.junit.Before)

Aggregations

DefaultMediaPackageSerializerImpl (org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl)12 InputStream (java.io.InputStream)11 MediaPackage (org.opencastproject.mediapackage.MediaPackage)11 MediaPackageBuilder (org.opencastproject.mediapackage.MediaPackageBuilder)9 File (java.io.File)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 Set (java.util.Set)7 Before (org.junit.Before)7 MessageSender (org.opencastproject.message.broker.api.MessageSender)7 MediaPackageMetadataService (org.opencastproject.metadata.api.MediaPackageMetadataService)7 AuthorizationService (org.opencastproject.security.api.AuthorizationService)7 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)7 Organization (org.opencastproject.security.api.Organization)7 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)7 SecurityService (org.opencastproject.security.api.SecurityService)7 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)7 ServiceRegistryInMemoryImpl (org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl)7 HandlerRegistration (org.opencastproject.workflow.impl.WorkflowServiceImpl.HandlerRegistration)7