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