Search in sources :

Example 21 with Workspace

use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.

the class StaticMetadataServiceDublinCoreImplTest method newWorkspace.

private Workspace newWorkspace() throws Exception {
    // mock workspace
    Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    final File dcFile = new File(getClass().getResource("/dublincore.xml").toURI());
    final File dcFileDefect = new File(getClass().getResource("/dublincore-defect.xml").toURI());
    Assert.assertNotNull(dcFile);
    // set expectations
    EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andAnswer(new IAnswer<File>() {

        @Override
        public File answer() throws Throwable {
            return EasyMock.getCurrentArguments()[0].toString().contains("-defect") ? dcFileDefect : dcFile;
        }
    }).anyTimes();
    // put into replay mode
    EasyMock.replay(workspace);
    return workspace;
}
Also used : IAnswer(org.easymock.IAnswer) File(java.io.File) URI(java.net.URI) Workspace(org.opencastproject.workspace.api.Workspace)

Example 22 with Workspace

use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.

the class LiveScheduleServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    mimeType = MimeTypes.parseMimeType(MIME_TYPE);
    // Osgi Services
    serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    searchService = EasyMock.createNiceMock(SearchService.class);
    seriesService = EasyMock.createNiceMock(SeriesService.class);
    captureAgentService = EasyMock.createNiceMock(CaptureAgentStateService.class);
    EasyMock.expect(captureAgentService.getAgentCapabilities("demo-capture-agent")).andReturn(new Properties());
    downloadDistributionService = EasyMock.createNiceMock(DownloadDistributionService.class);
    EasyMock.expect(downloadDistributionService.getDistributionType()).andReturn(LiveScheduleServiceImpl.DEFAULT_LIVE_DISTRIBUTION_SERVICE).anyTimes();
    workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.put(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyObject(InputStream.class))).andReturn(new URI("http://someUrl"));
    dublinCoreService = EasyMock.createNiceMock(DublinCoreCatalogService.class);
    assetManager = EasyMock.createNiceMock(AssetManager.class);
    authService = new AuthorizationServiceMock();
    organizationService = EasyMock.createNiceMock(OrganizationDirectoryService.class);
    Organization defOrg = new DefaultOrganization();
    Map<String, String> orgProps = new HashMap<String, String>();
    orgProps.put(LiveScheduleServiceImpl.PLAYER_PROPERTY, PATH_TO_PLAYER);
    orgProps.put(LiveScheduleServiceImpl.ENGAGE_URL_PROPERTY, ENGAGE_URL);
    org = new JaxbOrganization(ORG_ID, "Test Organization", defOrg.getServers(), defOrg.getAdminRole(), defOrg.getAnonymousRole(), orgProps);
    EasyMock.expect(organizationService.getOrganization(ORG_ID)).andReturn(org).anyTimes();
    // Live service configuration
    BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(LiveScheduleServiceImpl.LIVE_STREAMING_URL, STREAMING_SERVER_URL);
    props.put(LiveScheduleServiceImpl.LIVE_STREAM_MIME_TYPE, "video/x-flv");
    props.put(LiveScheduleServiceImpl.LIVE_STREAM_NAME, STREAM_NAME);
    props.put(LiveScheduleServiceImpl.LIVE_STREAM_RESOLUTION, "1920x540,960x270");
    props.put(LiveScheduleServiceImpl.LIVE_TARGET_FLAVORS, "presenter/delivery");
    cc = EasyMock.createNiceMock(ComponentContext.class);
    EasyMock.expect(cc.getBundleContext()).andReturn(bc);
    EasyMock.expect(cc.getProperties()).andReturn(props);
    EasyMock.replay(bc, cc);
    service = new LiveScheduleServiceImpl();
    service.setJobPollingInterval(1L);
    service.setSearchService(searchService);
    service.setSeriesService(seriesService);
    service.setCaptureAgentService(captureAgentService);
    service.setServiceRegistry(serviceRegistry);
    service.setWorkspace(workspace);
    service.setDublinCoreService(dublinCoreService);
    service.setAssetManager(assetManager);
    service.setAuthorizationService(authService);
    service.setOrganizationService(organizationService);
    service.activate(cc);
}
Also used : Organization(org.opencastproject.security.api.Organization) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) HashMap(java.util.HashMap) Properties(java.util.Properties) URI(java.net.URI) DublinCoreCatalogService(org.opencastproject.metadata.dublincore.DublinCoreCatalogService) SearchService(org.opencastproject.search.api.SearchService) CaptureAgentStateService(org.opencastproject.capture.admin.api.CaptureAgentStateService) AssetManager(org.opencastproject.assetmanager.api.AssetManager) ComponentContext(org.osgi.service.component.ComponentContext) InputStream(java.io.InputStream) Hashtable(java.util.Hashtable) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) DownloadDistributionService(org.opencastproject.distribution.api.DownloadDistributionService) SeriesService(org.opencastproject.series.api.SeriesService) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Workspace(org.opencastproject.workspace.api.Workspace) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 23 with Workspace

use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.

the class SoxServiceTest method setUp.

@Before
public void setUp() throws Exception {
    if (!soxInstalled)
        return;
    // Copy an existing media file to a temp file
    File f = new File("src/test/resources/audio-test.flac");
    source = File.createTempFile(FilenameUtils.getBaseName(f.getName()), ".flac");
    FileUtils.copyFile(f, source);
    f = null;
    JaxbOrganization org = new DefaultOrganization();
    User user = new JaxbUser("admin", "test", org, new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ADMIN, org));
    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((URI) EasyMock.anyObject())).andReturn(source).anyTimes();
    BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
    EasyMock.expect(bc.getProperty(SoxServiceImpl.CONFIG_SOX_PATH)).andReturn(SOX_BINARY).anyTimes();
    ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
    EasyMock.expect(cc.getBundleContext()).andReturn(bc).anyTimes();
    IncidentService incidentService = EasyMock.createNiceMock(IncidentService.class);
    // Finish setting up the mocks
    EasyMock.replay(bc, cc, orgDirectory, userDirectory, securityService, workspace, incidentService);
    // Create and populate the composer service
    soxService = new SoxServiceImpl();
    serviceRegistry = new ServiceRegistryInMemoryImpl(soxService, securityService, userDirectory, orgDirectory, incidentService);
    soxService.setOrganizationDirectoryService(orgDirectory);
    soxService.setSecurityService(securityService);
    soxService.setServiceRegistry(serviceRegistry);
    soxService.setUserDirectoryService(userDirectory);
    soxService.setWorkspace(workspace);
    soxService.activate(cc);
}
Also used : IncidentService(org.opencastproject.serviceregistry.api.IncidentService) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) ComponentContext(org.osgi.service.component.ComponentContext) JaxbOrganization(org.opencastproject.security.api.JaxbOrganization) JaxbUser(org.opencastproject.security.api.JaxbUser) URI(java.net.URI) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) File(java.io.File) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Workspace(org.opencastproject.workspace.api.Workspace) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 24 with Workspace

use of org.opencastproject.workspace.api.Workspace 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 25 with Workspace

use of org.opencastproject.workspace.api.Workspace 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)

Aggregations

Workspace (org.opencastproject.workspace.api.Workspace)71 Before (org.junit.Before)47 File (java.io.File)41 URI (java.net.URI)38 SecurityService (org.opencastproject.security.api.SecurityService)30 MediaPackageBuilder (org.opencastproject.mediapackage.MediaPackageBuilder)25 Job (org.opencastproject.job.api.Job)23 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)23 InputStream (java.io.InputStream)20 MediaPackage (org.opencastproject.mediapackage.MediaPackage)20 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)19 ServiceRegistry (org.opencastproject.serviceregistry.api.ServiceRegistry)18 Test (org.junit.Test)17 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)17 ArrayList (java.util.ArrayList)15 JaxbUser (org.opencastproject.security.api.JaxbUser)15 Organization (org.opencastproject.security.api.Organization)14 ServiceRegistryInMemoryImpl (org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl)14 AuthorizationService (org.opencastproject.security.api.AuthorizationService)13 JaxbRole (org.opencastproject.security.api.JaxbRole)13