Search in sources :

Example 6 with JobImpl

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()));
}
Also used : JobImpl(org.opencastproject.job.api.JobImpl) JaxbJob(org.opencastproject.job.api.JaxbJob) Arrays.mkString(org.opencastproject.util.data.Arrays.mkString) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) Test(org.junit.Test)

Example 7 with JobImpl

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);
}
Also used : JobImpl(org.opencastproject.job.api.JobImpl) ComponentContext(org.osgi.service.component.ComponentContext) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) List(java.util.List) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 8 with JobImpl

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);
}
Also used : JobImpl(org.opencastproject.job.api.JobImpl) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl) MediaInspectionService(org.opencastproject.inspection.api.MediaInspectionService) URI(java.net.URI) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) FileInputStream(java.io.FileInputStream) Catalog(org.opencastproject.mediapackage.Catalog) WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) MediaPackageBuilderImpl(org.opencastproject.mediapackage.MediaPackageBuilderImpl) AnimateService(org.opencastproject.animate.api.AnimateService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Id(org.opencastproject.mediapackage.identifier.Id) Job(org.opencastproject.job.api.Job) File(java.io.File) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 9 with JobImpl

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());
}
Also used : JobImpl(org.opencastproject.job.api.JobImpl) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) Job(org.opencastproject.job.api.Job) File(java.io.File) URI(java.net.URI) Capture(org.easymock.Capture) Workspace(org.opencastproject.workspace.api.Workspace) Test(org.junit.Test)

Example 10 with JobImpl

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]);
}
Also used : Playlist(com.google.api.services.youtube.model.Playlist) JobImpl(org.opencastproject.job.api.JobImpl) Video(com.google.api.services.youtube.model.Video) MediaPackage(org.opencastproject.mediapackage.MediaPackage) File(java.io.File) PlaylistItem(com.google.api.services.youtube.model.PlaylistItem) Test(org.junit.Test)

Aggregations

JobImpl (org.opencastproject.job.api.JobImpl)21 Job (org.opencastproject.job.api.Job)17 Before (org.junit.Before)9 Test (org.junit.Test)9 File (java.io.File)7 ServiceRegistry (org.opencastproject.serviceregistry.api.ServiceRegistry)7 Workspace (org.opencastproject.workspace.api.Workspace)7 ArrayList (java.util.ArrayList)6 MediaPackage (org.opencastproject.mediapackage.MediaPackage)6 URI (java.net.URI)5 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)5 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)5 InputStream (java.io.InputStream)4 List (java.util.List)4 SecurityService (org.opencastproject.security.api.SecurityService)4 WorkflowInstanceImpl (org.opencastproject.workflow.api.WorkflowInstanceImpl)4 Date (java.util.Date)3 TrackImpl (org.opencastproject.mediapackage.track.TrackImpl)3 JaxbRole (org.opencastproject.security.api.JaxbRole)3 JaxbUser (org.opencastproject.security.api.JaxbUser)3