use of org.opencastproject.mediapackage.MediaPackageBuilder in project opencast by opencast.
the class CleanupWorkflowOperationHandlerTest method testCreanupWOHwithPreservedFlavorAndCollectionPathPrefix.
@Test
public void testCreanupWOHwithPreservedFlavorAndCollectionPathPrefix() throws WorkflowOperationException, MediaPackageException {
Map<String, String> wfInstConfig = new Hashtable<>();
wfInstConfig.put(CleanupWorkflowOperationHandler.PRESERVE_FLAVOR_PROPERTY, "*/source,smil/trimmed,security/*");
wfInstConfig.put(CleanupWorkflowOperationHandler.DELETE_EXTERNAL, "true");
MediaPackageBuilder mpBuilder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
MediaPackage mp = mpBuilder.createNew();
MediaPackageElement track1 = addElementToMediaPackage(mp, MediaPackageElement.Type.Track, "presenter", "source", null);
track1.setURI(UrlSupport.uri(HOSTNAME_NODE1, WFR_URL_PREFIX, WorkingFileRepository.COLLECTION_PATH_PREFIX, "asset", mp.getIdentifier().compact(), track1.getIdentifier(), "track.mp4"));
MediaPackageElement track2 = addElementToMediaPackage(mp, MediaPackageElement.Type.Track, "presentation", "work", null);
track2.setURI(UrlSupport.uri(HOSTNAME_NODE2, WFR_URL_PREFIX, WorkingFileRepository.COLLECTION_PATH_PREFIX, "compose", mp.getIdentifier().compact(), track2.getIdentifier(), "track.mp4"));
MediaPackageElement att1 = addElementToMediaPackage(mp, MediaPackageElement.Type.Attachment, "presentation", "preview", null);
att1.setURI(UrlSupport.uri(HOSTNAME_NODE2, WFR_URL_PREFIX, WorkingFileRepository.COLLECTION_PATH_PREFIX, "compose", mp.getIdentifier().compact(), att1.getIdentifier(), "preview.png"));
MediaPackageElement att2 = addElementToMediaPackage(mp, MediaPackageElement.Type.Attachment, "smil", "trimmed", null);
att2.setURI(UrlSupport.uri(HOSTNAME_NODE1, WFR_URL_PREFIX, WorkingFileRepository.COLLECTION_PATH_PREFIX, "silence", mp.getIdentifier().compact(), att2.getIdentifier(), "trimmed.smil"));
MediaPackageElement cat1 = addElementToMediaPackage(mp, MediaPackageElement.Type.Catalog, "dublincore", "episode", null);
cat1.setURI(UrlSupport.uri(HOSTNAME_NODE1, WFR_URL_PREFIX, WorkingFileRepository.COLLECTION_PATH_PREFIX, "asset", mp.getIdentifier().compact(), cat1.getIdentifier(), "dublincore.xml"));
MediaPackageElement cat2 = addElementToMediaPackage(mp, MediaPackageElement.Type.Catalog, "security", "xaml", null);
cat2.setURI(UrlSupport.uri(HOSTNAME_NODE1, WFR_URL_PREFIX, WorkingFileRepository.COLLECTION_PATH_PREFIX, "security", mp.getIdentifier().compact(), cat2.getIdentifier(), "security.xml"));
cleanupWOH.start(createWorkflowInstance(wfInstConfig, mp), null);
Assert.assertEquals("Media package should contain at least tree elements", 3, mp.getElements().length);
SimpleElementSelector elementSelector = new SimpleElementSelector();
elementSelector.addFlavor("*/source");
Assert.assertFalse("Media package doesn't contain an element with a preserved flavor '*/source'", elementSelector.select(mp, false).isEmpty());
elementSelector = new SimpleElementSelector();
elementSelector.addFlavor("smil/trimmed");
Assert.assertFalse("Media package doesn't contain an element with a preserved flavor 'smil/trimmed'", elementSelector.select(mp, false).isEmpty());
elementSelector = new SimpleElementSelector();
elementSelector.addFlavor("security/*");
Assert.assertFalse("Media package doesn't contain an element with a preserved flavor 'security/*'", elementSelector.select(mp, false).isEmpty());
Assert.assertEquals("At least one file wasn't deleted on remote repository", 3, deletedFilesURIs.size());
}
use of org.opencastproject.mediapackage.MediaPackageBuilder in project opencast by opencast.
the class WorkflowOperationSkippingTest method setUp.
@Before
public void setUp() throws Exception {
sRoot = new File(getStorageRoot());
try {
FileUtils.forceMkdir(sRoot);
} catch (IOException e) {
Assert.fail(e.getMessage());
}
// create operation handlers for our workflows
succeedingOperationHandler = new SucceedingWorkflowOperationHandler(mediapackage1);
handlerRegistrations = new HashSet<HandlerRegistration>();
handlerRegistrations.add(new HandlerRegistration("op1", succeedingOperationHandler));
handlerRegistrations.add(new HandlerRegistration("op2", succeedingOperationHandler));
// 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);
MediaPackageMetadataService mds = EasyMock.createNiceMock(MediaPackageMetadataService.class);
EasyMock.replay(mds);
service.addMetadataService(mds);
workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.getCollectionContents((String) EasyMock.anyObject())).andReturn(new URI[0]);
EasyMock.replay(workspace);
// security service
SecurityService 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);
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);
ServiceRegistryInMemoryImpl serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
dao = new WorkflowServiceSolrIndex();
dao.solrRoot = sRoot + File.separator + "solr." + System.currentTimeMillis();
MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
EasyMock.replay(messageSender);
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);
dao.setServiceRegistry(serviceRegistry);
dao.setSecurityService(securityService);
dao.setAuthorizationService(authzService);
dao.setOrgDirectory(organizationDirectoryService);
dao.activate("System Admin");
service.setDao(dao);
service.setServiceRegistry(serviceRegistry);
service.setMessageSender(messageSender);
service.setUserDirectoryService(userDirectoryService);
service.activate(null);
InputStream is = null;
try {
is = WorkflowOperationSkippingTest.class.getResourceAsStream("/workflow-definition-skipping.xml");
workingDefinition = WorkflowParser.parseWorkflowDefinition(is);
service.registerWorkflowDefinition(workingDefinition);
IOUtils.closeQuietly(is);
MediaPackageBuilder mediaPackageBuilder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
mediaPackageBuilder.setSerializer(new DefaultMediaPackageSerializerImpl(new File("target/test-classes")));
is = WorkflowOperationSkippingTest.class.getResourceAsStream("/mediapackage-1.xml");
mediapackage1 = mediaPackageBuilder.loadFromXml(is);
IOUtils.closeQuietly(is);
Assert.assertNotNull(mediapackage1.getIdentifier());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of org.opencastproject.mediapackage.MediaPackageBuilder in project opencast by opencast.
the class InspectWorkflowOperationHandlerTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
// test resources
uriMP = InspectWorkflowOperationHandler.class.getResource("/inspect_mediapackage.xml").toURI();
uriMPUpdated = InspectWorkflowOperationHandler.class.getResource("/inspect_mediapackage_updated.xml").toURI();
mp = builder.loadFromXml(uriMP.toURL().openStream());
mpUpdatedDC = builder.loadFromXml(uriMPUpdated.toURL().openStream());
newTrack = (Track) mpUpdatedDC.getTracks()[0];
// set up service
operationHandler = new InspectWorkflowOperationHandler();
operationHandler.setJobBarrierPollingInterval(0);
// set up mock metadata and metadata service providing it
metadata = EasyMock.createNiceMock(MediaPackageMetadata.class);
EasyMock.expect(metadata.getDate()).andReturn(DATE);
EasyMock.expect(metadata.getLanguage()).andReturn(LANGUAGE);
EasyMock.expect(metadata.getLicense()).andReturn(LICENSE);
EasyMock.expect(metadata.getSeriesIdentifier()).andReturn(SERIES);
EasyMock.expect(metadata.getSeriesTitle()).andReturn(SERIES_TITLE);
EasyMock.expect(metadata.getTitle()).andReturn(TITLE);
EasyMock.replay(metadata);
// set up mock dublin core and dcService providing it
DublinCoreCatalog dc = EasyMock.createStrictMock(DublinCoreCatalog.class);
EasyMock.expect(dc.hasValue(DublinCore.PROPERTY_EXTENT)).andReturn(false);
dc.set((EName) EasyMock.anyObject(), (DublinCoreValue) EasyMock.anyObject());
EasyMock.expect(dc.hasValue(DublinCore.PROPERTY_CREATED)).andReturn(false);
dc.set((EName) EasyMock.anyObject(), (DublinCoreValue) EasyMock.anyObject());
dc.toXml((ByteArrayOutputStream) EasyMock.anyObject(), EasyMock.anyBoolean());
// EasyMock.expect(dc.getIdentifier()).andReturn("123");
EasyMock.replay(dc);
dcService = EasyMock.createNiceMock(DublinCoreCatalogService.class);
EasyMock.expect(dcService.getMetadata((MediaPackage) EasyMock.anyObject())).andReturn(metadata);
EasyMock.expect(dcService.load((InputStream) EasyMock.anyObject())).andReturn(dc);
EasyMock.replay(dcService);
operationHandler.setDublincoreService(dcService);
// set up mock receipt and inspect service providing it
job = EasyMock.createNiceMock(Job.class);
EasyMock.expect(job.getPayload()).andReturn(MediaPackageElementParser.getAsXml(newTrack)).anyTimes();
EasyMock.expect(job.getId()).andReturn(new Long(123));
EasyMock.expect(job.getStatus()).andReturn(Status.FINISHED);
EasyMock.expect(job.getDateCreated()).andReturn(new Date());
EasyMock.expect(job.getDateStarted()).andReturn(new Date());
EasyMock.replay(job);
// set up mock service registry
ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(serviceRegistry.getJob(EasyMock.anyLong())).andReturn(job).anyTimes();
EasyMock.replay(serviceRegistry);
operationHandler.setServiceRegistry(serviceRegistry);
inspectionService = EasyMock.createNiceMock(MediaInspectionService.class);
EasyMock.expect(inspectionService.enrich((Track) EasyMock.anyObject(), EasyMock.anyBoolean(), (Map<String, String>) EasyMock.anyObject())).andReturn(job);
EasyMock.replay(inspectionService);
operationHandler.setInspectionService(inspectionService);
// set up mock workspace
workspace = EasyMock.createNiceMock(Workspace.class);
// workspace.delete((String) EasyMock.anyObject(), (String) EasyMock.anyObject());
URI newURI = new URI(NEW_DC_URL);
EasyMock.expect(workspace.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(newURI);
EasyMock.expect(workspace.getURI((String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(newURI);
EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andReturn(new File(getClass().getResource("/dublincore.xml").toURI()));
EasyMock.replay(workspace);
operationHandler.setWorkspace(workspace);
}
use of org.opencastproject.mediapackage.MediaPackageBuilder in project opencast by opencast.
the class HttpNotificationWorkflowOperationHandlerTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
// test resources
URI uriMP = getClass().getResource("/concat_mediapackage.xml").toURI();
mp = builder.loadFromXml(uriMP.toURL().openStream());
// set up mock trusted http client
client = EasyMock.createNiceMock(TrustedHttpClient.class);
HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_ACCEPTED, ""));
EasyMock.expect(client.execute((HttpUriRequest) EasyMock.anyObject(), EasyMock.anyInt(), EasyMock.anyInt())).andReturn(response);
EasyMock.replay(client);
// set up service
operationHandler = new HttpNotificationWorkflowOperationHandler();
}
use of org.opencastproject.mediapackage.MediaPackageBuilder in project opencast by opencast.
the class MediaPackagePostOperationHandlerTest method testHTTPPostXML.
@Test
public void testHTTPPostXML() throws Exception {
// create a dummy mediapackage
MediaPackageBuilderFactory factory = MediaPackageBuilderFactory.newInstance();
MediaPackageBuilder builder = factory.newMediaPackageBuilder();
MediaPackage mp = builder.createNew(new IdImpl("xyz"));
mp.setTitle("test");
mp.addContributor("lkiesow");
mp.addContributor("lkiesow");
/* Sending stuff to port 9 shound never return anything as the Discard
* Protocol uses port 9 */
InstanceAndHandler tuple = createWorkflow("http://127.0.0.1:9", "xml");
MediaPackagePostOperationHandler handler = (MediaPackagePostOperationHandler) tuple.workflowHandler;
tuple.workflowInstance.setMediaPackage(mp);
try {
tuple.workflowHandler.start(tuple.workflowInstance, null);
/* This should raise an exception. Something is wrong if not. */
Assert.fail();
} catch (WorkflowOperationException e) {
logger.info(e.toString());
}
}
Aggregations