use of org.opencastproject.job.api.JobImpl in project opencast by opencast.
the class JobTest method testMarshallingWithJsonPayload.
@Test
public void testMarshallingWithJsonPayload() throws Exception {
final String payload = "{'foo' : 'bar'}";
Job job = new JobImpl();
job.setPayload(payload);
String marshalledJob = JobParser.toXml(new JaxbJob(job));
Job unmarshalledJob = JobParser.parseJob(marshalledJob);
assertEquals("json from unmarshalled job should remain unchanged", StringUtils.trim(payload), StringUtils.trim(unmarshalledJob.getPayload()));
}
use of org.opencastproject.job.api.JobImpl in project opencast by opencast.
the class AnimateServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
// Skip tests if synfig is not installed
Assume.assumeTrue(runSynfigTests);
// create animate service
animateService = new AnimateServiceImpl();
// create the needed mocks
BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
EasyMock.expect(cc.getBundleContext()).andReturn(bc).anyTimes();
Workspace workspace = EasyMock.createMock(Workspace.class);
final String directory = testFolder.newFolder().getAbsolutePath();
EasyMock.expect(workspace.rootDirectory()).andReturn(directory).anyTimes();
final Capture<String> collection = EasyMock.newCapture();
final Capture<String> name = EasyMock.newCapture();
final Capture<InputStream> in = EasyMock.newCapture();
EasyMock.expect(workspace.putInCollection(capture(collection), capture(name), capture(in))).andAnswer(() -> {
File output = new File(directory, "out.mp4");
FileUtils.copyInputStreamToFile(in.getValue(), output);
return output.toURI();
}).once();
// Finish setting up the mocks
EasyMock.replay(bc, cc, workspace);
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(animateService.process(job));
return job;
}).anyTimes();
EasyMock.replay(serviceRegistry);
animateService.setServiceRegistry(serviceRegistry);
animateService.setWorkspace(workspace);
}
use of org.opencastproject.job.api.JobImpl in project opencast by opencast.
the class AnimateWorkflowOperationHandlerTest method setUp.
@Before
public void setUp() throws Exception {
handler = new AnimateWorkflowOperationHandler() {
@Override
protected JobBarrier.Result waitForStatus(Job... jobs) throws IllegalStateException, IllegalArgumentException {
JobBarrier.Result result = EasyMock.createNiceMock(JobBarrier.Result.class);
EasyMock.expect(result.isSuccess()).andReturn(true).anyTimes();
EasyMock.replay(result);
return result;
}
};
file = new File(getClass().getResource("/dc-episode.xml").toURI());
MediaPackage mediaPackage = new MediaPackageBuilderImpl().createNew();
mediaPackage.setIdentifier(new IdImpl("123-456"));
InputStream in = new FileInputStream(file);
Catalog catalog = DublinCores.read(in);
catalog.setFlavor(MediaPackageElements.EPISODE);
// catalog.setURI(getClass().getResource("/dc-episode.xml").toURI());
mediaPackage.add(catalog);
instance = EasyMock.createNiceMock(WorkflowOperationInstanceImpl.class);
EasyMock.expect(instance.getConfiguration("target-flavor")).andReturn("a/b").anyTimes();
EasyMock.expect(instance.getConfiguration("target-tags")).andReturn("a,b,c").anyTimes();
workflow = EasyMock.createMock(WorkflowInstanceImpl.class);
EasyMock.expect(workflow.getMediaPackage()).andReturn(mediaPackage).anyTimes();
EasyMock.expect(workflow.getCurrentOperation()).andReturn(instance).anyTimes();
Job job = new JobImpl(0);
job.setPayload(file.getAbsolutePath());
AnimateService animateService = EasyMock.createMock(AnimateService.class);
EasyMock.expect(animateService.animate(anyObject(), anyObject(), anyObject())).andReturn(job);
Workspace workspace = EasyMock.createMock(Workspace.class);
EasyMock.expect(workspace.put(anyString(), anyString(), anyString(), anyObject())).andReturn(file.toURI()).anyTimes();
EasyMock.expect(workspace.read(anyObject())).andAnswer(() -> getClass().getResourceAsStream("/dc-episode.xml")).anyTimes();
workspace.cleanup(anyObject(Id.class));
EasyMock.expectLastCall();
workspace.delete(anyObject(URI.class));
EasyMock.expectLastCall();
job = new JobImpl(1);
job.setPayload(MediaPackageElementParser.getAsXml(new TrackImpl()));
MediaInspectionService mediaInspectionService = EasyMock.createMock(MediaInspectionService.class);
EasyMock.expect(mediaInspectionService.enrich(anyObject(), anyBoolean())).andReturn(job).once();
EasyMock.replay(animateService, workspace, workflow, mediaInspectionService);
handler.setAnimateService(animateService);
handler.setMediaInspectionService(mediaInspectionService);
handler.setWorkspace(workspace);
}
use of org.opencastproject.job.api.JobImpl in project opencast by opencast.
the class TimelinePreviewsServiceImplTest method testProcess.
/**
* Test of process method of class TimelinePreviewsServiceImpl.
* @throws java.lang.Exception
*/
@Test
public void testProcess() throws Exception {
File file = new File(track.getURI());
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andReturn(file);
Capture filenameCapture = new Capture();
EasyMock.expect(workspace.putInCollection(EasyMock.anyString(), (String) EasyMock.capture(filenameCapture), (InputStream) EasyMock.anyObject())).andReturn(new URI("timelinepreviews.png"));
EasyMock.replay(workspace);
TimelinePreviewsServiceImpl instance = new TimelinePreviewsServiceImpl();
instance.setWorkspace(workspace);
String trackXml = MediaPackageElementParser.getAsXml(track);
Job job = new JobImpl(1);
job.setJobType(TimelinePreviewsServiceImpl.JOB_TYPE);
job.setOperation(TimelinePreviewsServiceImpl.Operation.TimelinePreview.toString());
job.setArguments(Arrays.asList(trackXml, String.valueOf(10)));
String result = instance.process(job);
assertNotNull(result);
MediaPackageElement timelinepreviewsAttachment = MediaPackageElementParser.getFromXml(result);
assertEquals(new URI("timelinepreviews.png"), timelinepreviewsAttachment.getURI());
assertTrue(filenameCapture.hasCaptured());
}
use of org.opencastproject.job.api.JobImpl in project opencast by opencast.
the class YouTubeV3PublicationServiceImplTest method testPublishNewPlaylist.
@Test
public void testPublishNewPlaylist() throws Exception {
final File baseDir = new File(this.getClass().getResource("/mediapackage").toURI());
final String xml = FileUtils.readFileToString(new File(baseDir, "manifest.xml"));
final MediaPackage mediaPackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(xml);
//
expect(youTubeService.getMyPlaylistByTitle(mediaPackage.getTitle())).andReturn(null).once();
expect(youTubeService.createPlaylist(mediaPackage.getSeriesTitle(), null, mediaPackage.getSeries())).andReturn(new Playlist()).once();
expect(youTubeService.addVideoToMyChannel(anyObject(VideoUpload.class))).andReturn(new Video()).once();
expect(youTubeService.addPlaylistItem(anyObject(String.class), anyObject(String.class))).andReturn(new PlaylistItem()).once();
expect(registry.createJob(anyObject(String.class), anyObject(String.class), anyObject(List.class), anyObject(Float.class))).andReturn(new JobImpl()).once();
replay(youTubeService, orgDirectory, security, registry, userDirectoryService, workspace);
service.updated(getServiceProperties());
service.publish(mediaPackage, mediaPackage.getTracks()[0]);
}
Aggregations