use of org.opencastproject.serviceregistry.api.ServiceRegistry in project opencast by opencast.
the class CompositeWorkflowOperationHandlerTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
// test resources
URI uriMP = InspectWorkflowOperationHandler.class.getResource("/composite_mediapackage.xml").toURI();
URI uriMPEncode = InspectWorkflowOperationHandler.class.getResource("/compound_mediapackage.xml").toURI();
mp = builder.loadFromXml(uriMP.toURL().openStream());
mpEncode = builder.loadFromXml(uriMPEncode.toURL().openStream());
encodedTracks = mpEncode.getTracks();
// set up mock workspace
workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.moveTo((URI) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(uriMPEncode);
EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andReturn(new File(getClass().getResource("/watermark.jpg").toURI()));
EasyMock.replay(workspace);
// set up mock receipt
job = EasyMock.createNiceMock(Job.class);
EasyMock.expect(job.getPayload()).andReturn(MediaPackageElementParser.getAsXml(encodedTracks[0])).anyTimes();
EasyMock.expect(job.getStatus()).andReturn(Job.Status.FINISHED);
EasyMock.expect(job.getDateCreated()).andReturn(new Date());
EasyMock.expect(job.getDateStarted()).andReturn(new Date());
EasyMock.expect(job.getQueueTime()).andReturn(new Long(0));
EasyMock.replay(job);
// set up mock service registry
ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(serviceRegistry.getJob(EasyMock.anyLong())).andReturn(job);
EasyMock.replay(serviceRegistry);
// set up service
operationHandler = new CompositeWorkflowOperationHandler();
operationHandler.setJobBarrierPollingInterval(0);
operationHandler.setWorkspace(workspace);
operationHandler.setServiceRegistry(serviceRegistry);
}
use of org.opencastproject.serviceregistry.api.ServiceRegistry in project opencast by opencast.
the class CompositeWorkflowOperationHandlerTest method testSingleVideoStream.
@Test
public void testSingleVideoStream() throws URISyntaxException, MalformedURLException, MediaPackageException, IOException, IllegalArgumentException, NotFoundException, ServiceRegistryException {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
// test resources
URI uriMP = InspectWorkflowOperationHandler.class.getResource("/composite_mediapackage.xml").toURI();
URI uriMPEncode = InspectWorkflowOperationHandler.class.getResource("/compound_mediapackage.xml").toURI();
mp = builder.loadFromXml(uriMP.toURL().openStream());
mpEncode = builder.loadFromXml(uriMPEncode.toURL().openStream());
encodedTracks = mpEncode.getTracks();
// set up mock workspace
workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.moveTo((URI) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(uriMPEncode);
EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andReturn(new File(getClass().getResource("/watermark.jpg").toURI()));
EasyMock.replay(workspace);
// set up mock receipt
job = EasyMock.createNiceMock(Job.class);
EasyMock.expect(job.getPayload()).andReturn(MediaPackageElementParser.getAsXml(encodedTracks[0])).anyTimes();
EasyMock.expect(job.getStatus()).andReturn(Job.Status.FINISHED);
EasyMock.expect(job.getDateCreated()).andReturn(new Date());
EasyMock.expect(job.getDateStarted()).andReturn(new Date());
EasyMock.expect(job.getQueueTime()).andReturn(new Long(0));
EasyMock.replay(job);
// set up mock service registry
ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(serviceRegistry.getJob(EasyMock.anyLong())).andReturn(job);
EasyMock.replay(serviceRegistry);
// set up service
operationHandler = new CompositeWorkflowOperationHandler();
operationHandler.setWorkspace(workspace);
operationHandler.setServiceRegistry(serviceRegistry);
}
use of org.opencastproject.serviceregistry.api.ServiceRegistry in project opencast by opencast.
the class ImageToVideoWorkflowOperationHandlerTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
// test resources
URI uriMP = InspectWorkflowOperationHandler.class.getResource("/imagetovideo_mediapackage.xml").toURI();
URI uriMPEncode = InspectWorkflowOperationHandler.class.getResource("/imagetovideo_converted_mediapackage.xml").toURI();
mp = builder.loadFromXml(uriMP.toURL().openStream());
mpEncode = builder.loadFromXml(uriMPEncode.toURL().openStream());
encodedTracks = mpEncode.getTracks();
// set up mock workspace
workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.moveTo((URI) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(uriMP);
EasyMock.replay(workspace);
// set up mock receipt
job = EasyMock.createNiceMock(Job.class);
EasyMock.expect(job.getPayload()).andReturn(MediaPackageElementParser.getAsXml(encodedTracks[0])).anyTimes();
EasyMock.expect(job.getStatus()).andReturn(Job.Status.FINISHED);
EasyMock.expect(job.getDateCreated()).andReturn(new Date());
EasyMock.expect(job.getDateStarted()).andReturn(new Date());
EasyMock.expect(job.getQueueTime()).andReturn(new Long(0));
EasyMock.replay(job);
// set up mock service registry
ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(serviceRegistry.getJob(EasyMock.anyLong())).andReturn(job);
EasyMock.replay(serviceRegistry);
// set up service
operationHandler = new ImageToVideoWorkflowOperationHandler();
operationHandler.setJobBarrierPollingInterval(0);
operationHandler.setWorkspace(workspace);
operationHandler.setServiceRegistry(serviceRegistry);
}
use of org.opencastproject.serviceregistry.api.ServiceRegistry in project opencast by opencast.
the class ComposerServiceTest method setUp.
@Before
public void setUp() throws Exception {
// Skip tests if FFmpeg is not installed
Assume.assumeTrue(ffmpegInstalled);
// Create video only file
File f = getFile("/video.mp4");
sourceVideoOnly = File.createTempFile(FilenameUtils.getBaseName(f.getName()), ".mp4", testDir);
FileUtils.copyFile(f, sourceVideoOnly);
// Create another audio only file
f = getFile("/audio.mp3");
sourceAudioOnly = File.createTempFile(FilenameUtils.getBaseName(f.getName()), ".mp3", testDir);
FileUtils.copyFile(f, sourceAudioOnly);
// Create an image file
f = getFile("/image.jpg");
sourceImage = File.createTempFile(FilenameUtils.getBaseName(f.getName()), ".jpg", testDir);
FileUtils.copyFile(f, sourceImage);
// create the needed mocks
BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
EasyMock.expect(bc.getProperty(EasyMock.anyString())).andReturn(FFMPEG_BINARY);
ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
EasyMock.expect(cc.getBundleContext()).andReturn(bc).anyTimes();
JaxbOrganization org = new DefaultOrganization();
HashSet<JaxbRole> roles = new HashSet<>();
roles.add(new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ADMIN, org, ""));
User user = new JaxbUser("admin", "test", org, roles);
OrganizationDirectoryService orgDirectory = EasyMock.createNiceMock(OrganizationDirectoryService.class);
EasyMock.expect(orgDirectory.getOrganization((String) EasyMock.anyObject())).andReturn(org).anyTimes();
UserDirectoryService userDirectory = EasyMock.createNiceMock(UserDirectoryService.class);
EasyMock.expect(userDirectory.loadUser("admin")).andReturn(user).anyTimes();
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getOrganization()).andReturn(org).anyTimes();
EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.get(EasyMock.anyObject())).andReturn(sourceVideoOnly).anyTimes();
profileScanner = new EncodingProfileScanner();
File encodingProfile = getFile("/encodingprofiles.properties");
assertNotNull("Encoding profile must exist", encodingProfile);
profileScanner.install(encodingProfile);
// Finish setting up the mocks
EasyMock.replay(bc, cc, orgDirectory, userDirectory, securityService, workspace);
// Create an encoding engine factory
inspectedTrack = (Track) MediaPackageElementParser.getFromXml(IOUtils.toString(ComposerServiceTest.class.getResourceAsStream("/composer_test_source_track_video.xml"), Charset.defaultCharset()));
sourceVideoTrack = (Track) MediaPackageElementParser.getFromXml(IOUtils.toString(ComposerServiceTest.class.getResourceAsStream("/composer_test_source_track_video.xml"), Charset.defaultCharset()));
sourceAudioTrack = (Track) MediaPackageElementParser.getFromXml(IOUtils.toString(ComposerServiceTest.class.getResourceAsStream("/composer_test_source_track_audio.xml"), Charset.defaultCharset()));
// Create and populate the composer service
composerService = new ComposerServiceImpl() {
@Override
protected Job inspect(Job job, URI workspaceURI) throws EncoderException {
Job inspectionJob = EasyMock.createNiceMock(Job.class);
try {
EasyMock.expect(inspectionJob.getPayload()).andReturn(MediaPackageElementParser.getAsXml(inspectedTrack));
} catch (MediaPackageException e) {
throw new RuntimeException(e);
}
EasyMock.replay(inspectionJob);
return inspectionJob;
}
};
ServiceRegistry serviceRegistry = EasyMock.createMock(ServiceRegistry.class);
final Capture<String> type = EasyMock.newCapture();
final Capture<String> operation = EasyMock.newCapture();
final Capture<List<String>> args = EasyMock.newCapture();
EasyMock.expect(serviceRegistry.createJob(capture(type), capture(operation), capture(args), EasyMock.anyFloat())).andAnswer(() -> {
// you could do work here to return something different if you needed.
Job job = new JobImpl(0);
job.setJobType(type.getValue());
job.setOperation(operation.getValue());
job.setArguments(args.getValue());
job.setPayload(composerService.process(job));
return job;
}).anyTimes();
composerService.setServiceRegistry(serviceRegistry);
composerService.setProfileScanner(profileScanner);
composerService.setWorkspace(workspace);
EasyMock.replay(serviceRegistry);
}
use of org.opencastproject.serviceregistry.api.ServiceRegistry in project opencast by opencast.
the class PartialImportWorkflowOperationHandlerTest method checkForMuxingInputPresenterVideoPresentationAudioExpectsMux.
@Test
public void checkForMuxingInputPresenterVideoPresentationAudioExpectsMux() throws EncoderException, MediaPackageException, WorkflowOperationException, NotFoundException, ServiceRegistryException, IOException, URISyntaxException {
// Setup tracks
Track audioTrack = createTrack(PRESENTER_TARGET_FLAVOR, "audio.mp4", false, true);
Track videoTrack = createTrack(PRESENTATION_TARGET_FLAVOR, "video.mp4", true, false);
Track[] tracks = { audioTrack, videoTrack };
// Setup media package
MediaPackage mediaPackage = EasyMock.createMock(MediaPackage.class);
EasyMock.expect(mediaPackage.getTracks()).andReturn(tracks).anyTimes();
// Create a Job for the mux Job to return.
Job muxJob = EasyMock.createMock(Job.class);
EasyMock.expect(muxJob.getId()).andReturn(1L);
// Create the composer service to track muxing of tracks.
ComposerService composerService = EasyMock.createMock(ComposerService.class);
EasyMock.expect(composerService.mux(videoTrack, audioTrack, PrepareAVWorkflowOperationHandler.MUX_AV_PROFILE)).andReturn(muxJob);
// Service Registry
ServiceRegistry serviceRegistry = EasyMock.createMock(ServiceRegistry.class);
EasyMock.expect(serviceRegistry.getJob(1L)).andReturn(muxJob);
// Replay all mocks
EasyMock.replay(composerService, mediaPackage, serviceRegistry);
TestPartialImportWorkflowOperationHandler handler = new TestPartialImportWorkflowOperationHandler(videoTrack, audioTrack);
handler.setComposerService(composerService);
handler.setServiceRegistry(serviceRegistry);
handler.checkForMuxing(mediaPackage, PRESENTATION_TARGET_FLAVOR, PRESENTER_TARGET_FLAVOR, false, new ArrayList<MediaPackageElement>());
}
Aggregations