Search in sources :

Example 26 with Workspace

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

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

the class CommentSchedulerConflictNotifierTest method setUp.

@Before
public void setUp() throws Exception {
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(new JaxbUser("admin", "provider", new DefaultOrganization(), new JaxbRole("admin", new DefaultOrganization(), "test"))).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.replay(securityService);
    Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.get(EasyMock.anyObject(URI.class))).andReturn(IoSupport.classPathResourceAsFile("/dublincore.xml").get()).anyTimes();
    EasyMock.replay(workspace);
    EventCatalogUIAdapter episodeAdapter = EasyMock.createMock(EventCatalogUIAdapter.class);
    EasyMock.expect(episodeAdapter.getFlavor()).andReturn(new MediaPackageElementFlavor("dublincore", "episode")).anyTimes();
    EasyMock.expect(episodeAdapter.getOrganization()).andReturn(new DefaultOrganization().getId()).anyTimes();
    EasyMock.replay(episodeAdapter);
    EventCatalogUIAdapter extendedAdapter = EasyMock.createMock(EventCatalogUIAdapter.class);
    EasyMock.expect(extendedAdapter.getFlavor()).andReturn(new MediaPackageElementFlavor("extended", "episode")).anyTimes();
    EasyMock.expect(extendedAdapter.getOrganization()).andReturn(new DefaultOrganization().getId()).anyTimes();
    EasyMock.replay(extendedAdapter);
    conflictNotifier = new CommentSchedulerConflictNotifier();
    conflictNotifier.setSecurityService(securityService);
    conflictNotifier.setWorkspace(workspace);
    conflictNotifier.addCatalogUIAdapter(episodeAdapter);
    conflictNotifier.addCatalogUIAdapter(extendedAdapter);
}
Also used : JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) EventCatalogUIAdapter(org.opencastproject.metadata.dublincore.EventCatalogUIAdapter) JaxbUser(org.opencastproject.security.api.JaxbUser) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 28 with Workspace

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

the class EmailSchedulerConflictNotifierTest method setUp.

@Before
public void setUp() throws Exception {
    Dictionary<String, String> properties = new Hashtable<>();
    properties.put("to", "test@test.com");
    properties.put("subject", "Test email scheduler conflict");
    properties.put("template", "Dear Administrator,\n\nthe following recording schedules are conflicting with existing ones:\n\n${recordings}\nBye!");
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(new JaxbUser("admin", "provider", new DefaultOrganization(), new JaxbRole("admin", new DefaultOrganization(), "test"))).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.replay(securityService);
    Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.get(EasyMock.anyObject(URI.class))).andReturn(IoSupport.classPathResourceAsFile("/dublincore.xml").get()).anyTimes();
    EasyMock.replay(workspace);
    EventCatalogUIAdapter episodeAdapter = EasyMock.createMock(EventCatalogUIAdapter.class);
    EasyMock.expect(episodeAdapter.getFlavor()).andReturn(new MediaPackageElementFlavor("dublincore", "episode")).anyTimes();
    EasyMock.expect(episodeAdapter.getOrganization()).andReturn(new DefaultOrganization().getId()).anyTimes();
    EasyMock.replay(episodeAdapter);
    EventCatalogUIAdapter extendedAdapter = EasyMock.createMock(EventCatalogUIAdapter.class);
    EasyMock.expect(extendedAdapter.getFlavor()).andReturn(new MediaPackageElementFlavor("extended", "episode")).anyTimes();
    EasyMock.expect(extendedAdapter.getOrganization()).andReturn(new DefaultOrganization().getId()).anyTimes();
    EasyMock.replay(extendedAdapter);
    BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
    EasyMock.expect(bundleContext.getProperty(OpencastConstants.SERVER_URL_PROPERTY)).andReturn("http://localhost:8080").anyTimes();
    EasyMock.replay(bundleContext);
    ComponentContext componentContext = EasyMock.createNiceMock(ComponentContext.class);
    EasyMock.expect(componentContext.getBundleContext()).andReturn(bundleContext).anyTimes();
    EasyMock.expect(componentContext.getProperties()).andReturn(new Hashtable<String, Object>()).anyTimes();
    EasyMock.replay(componentContext);
    conflictNotifier = new EmailSchedulerConflictNotifier();
    conflictNotifier.setSecurityService(securityService);
    conflictNotifier.setWorkspace(workspace);
    conflictNotifier.addCatalogUIAdapter(episodeAdapter);
    conflictNotifier.addCatalogUIAdapter(extendedAdapter);
    conflictNotifier.activate(componentContext);
    conflictNotifier.updated(properties);
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext) Hashtable(java.util.Hashtable) JaxbUser(org.opencastproject.security.api.JaxbUser) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) EventCatalogUIAdapter(org.opencastproject.metadata.dublincore.EventCatalogUIAdapter) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Workspace(org.opencastproject.workspace.api.Workspace) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 29 with Workspace

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

the class OaiPmhRepositoryPersistenceTest method oaiPmhDatabase.

private static AbstractOaiPmhDatabase oaiPmhDatabase(MediaPackage... mps) {
    try {
        final Organization org = new DefaultOrganization();
        final SecurityService secSvc = EasyMock.createNiceMock(SecurityService.class);
        // security service
        final User user = createSystemUser("admin", org);
        expect(secSvc.getOrganization()).andReturn(org).anyTimes();
        expect(secSvc.getUser()).andReturn(user).anyTimes();
        EasyMock.replay(secSvc);
        // series service
        final SeriesService seriesService = EasyMock.createNiceMock(SeriesService.class);
        final String xacml = IOUtils.toString(OaiPmhRepositoryPersistenceTest.class.getResource("/xacml.xml").toURI());
        final AccessControlList securityACL = AccessControlParser.parseAcl(xacml);
        EasyMock.expect(seriesService.getSeriesAccessControl("10.0000/1")).andReturn(securityACL).anyTimes();
        EasyMock.replay(seriesService);
        // workspace
        final Workspace workspace = EasyMock.createNiceMock(Workspace.class);
        final File episodeDublinCore = new File(OaiPmhRepositoryPersistenceTest.class.getResource("/episode-dublincore.xml").toURI());
        final File seriesDublinCore = new File(OaiPmhRepositoryPersistenceTest.class.getResource("/series-dublincore.xml").toURI());
        expect(workspace.read(EasyMock.anyObject())).andAnswer(() -> {
            final String uri = getCurrentArguments()[0].toString();
            if ("dublincore.xml".equals(uri))
                return new FileInputStream(episodeDublinCore);
            if ("series-dublincore.xml".equals(uri))
                return new FileInputStream(seriesDublinCore);
            throw new Error("Workspace mock does not know about file " + uri);
        }).anyTimes();
        EasyMock.replay(workspace);
        // oai-pmh database
        final EntityManagerFactory emf = PersistenceUtil.newTestEntityManagerFactory(OaiPmhDatabaseImpl.PERSISTENCE_UNIT_NAME);
        final AbstractOaiPmhDatabase db = new AbstractOaiPmhDatabase() {

            @Override
            public EntityManagerFactory getEmf() {
                return emf;
            }

            @Override
            public SecurityService getSecurityService() {
                return secSvc;
            }

            @Override
            public Workspace getWorkspace() {
                return workspace;
            }

            @Override
            public Date currentDate() {
                return new Date();
            }
        };
        for (MediaPackage mp : mps) db.store(mp, REPOSITORY_ID);
        return db;
    } catch (Exception e) {
        return chuck(e);
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) AbstractOaiPmhDatabase(org.opencastproject.oaipmh.persistence.impl.AbstractOaiPmhDatabase) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) User(org.opencastproject.security.api.User) SecurityUtil.createSystemUser(org.opencastproject.security.util.SecurityUtil.createSystemUser) FileInputStream(java.io.FileInputStream) Date(java.util.Date) EncodingSchemeUtils.encodeDate(org.opencastproject.metadata.dublincore.EncodingSchemeUtils.encodeDate) TransformerException(javax.xml.transform.TransformerException) SeriesService(org.opencastproject.series.api.SeriesService) SecurityService(org.opencastproject.security.api.SecurityService) EntityManagerFactory(javax.persistence.EntityManagerFactory) MediaPackage(org.opencastproject.mediapackage.MediaPackage) File(java.io.File) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Workspace(org.opencastproject.workspace.api.Workspace)

Example 30 with Workspace

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

the class YouTubeV3PublicationServiceImplTest method before.

@Before
public void before() throws Exception {
    youTubeService = createMock(YouTubeAPIVersion3Service.class);
    youTubeService.initialize(anyObject(ClientCredentials.class));
    expectLastCall();
    orgDirectory = createMock(OrganizationDirectoryService.class);
    security = createMock(SecurityService.class);
    registry = createMock(ServiceRegistry.class);
    List<HostRegistration> hosts = new LinkedList<HostRegistration>();
    HostRegistration host = new HostRegistrationInMemory("localhost", "localhost", 1.0F, 1, 1024L);
    hosts.add(host);
    expect(registry.getHostRegistrations()).andReturn(hosts).anyTimes();
    userDirectoryService = createMock(UserDirectoryService.class);
    workspace = createMock(Workspace.class);
    // 
    service = new YouTubeV3PublicationServiceImpl(youTubeService);
    service.setOrganizationDirectoryService(orgDirectory);
    service.setSecurityService(security);
    service.setServiceRegistry(registry);
    service.setUserDirectoryService(userDirectoryService);
    service.setWorkspace(workspace);
}
Also used : HostRegistrationInMemory(org.opencastproject.serviceregistry.api.HostRegistrationInMemory) SecurityService(org.opencastproject.security.api.SecurityService) HostRegistration(org.opencastproject.serviceregistry.api.HostRegistration) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) ClientCredentials(org.opencastproject.publication.youtube.auth.ClientCredentials) LinkedList(java.util.LinkedList) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) 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