Search in sources :

Example 1 with SeriesService

use of org.opencastproject.series.api.SeriesService in project opencast by opencast.

the class IngestServiceImplTest method testSeriesUpdateNewAndExisting.

/**
 * Test method for {@link org.opencastproject.ingest.impl.IngestServiceImpl#updateSeries(java.net.URI)}
 */
private void testSeriesUpdateNewAndExisting(Dictionary<String, String> properties) throws Exception {
    // default expectation for series overwrite is True
    boolean isExpectSeriesOverwrite = true;
    if (properties != null) {
        service.updated(properties);
        try {
            boolean testForValue = Boolean.parseBoolean(properties.get(IngestServiceImpl.PROPKEY_OVERWRITE_SERIES).trim());
            isExpectSeriesOverwrite = testForValue;
        } catch (Exception e) {
        // If key or value not found or not boolean, use the default overwrite expectation
        }
    }
    // Get test series dublin core for the mock return value
    File catalogFile = new File(urlCatalog2);
    if (!catalogFile.exists() || !catalogFile.canRead())
        throw new Exception("Unable to access test catalog " + urlCatalog2.getPath());
    FileInputStream in = new FileInputStream(catalogFile);
    DublinCoreCatalog series = DublinCores.read(in);
    IOUtils.closeQuietly(in);
    // Set dublinCore service to return test dublin core
    dublinCoreService = org.easymock.EasyMock.createNiceMock(DublinCoreCatalogService.class);
    org.easymock.EasyMock.expect(dublinCoreService.load((InputStream) EasyMock.anyObject())).andReturn(series).anyTimes();
    org.easymock.EasyMock.replay(dublinCoreService);
    service.setDublinCoreService(dublinCoreService);
    // Test with mock found series
    seriesService = EasyMock.createNiceMock(SeriesService.class);
    EasyMock.expect(seriesService.getSeries((String) EasyMock.anyObject())).andReturn(series).once();
    EasyMock.expect(seriesService.updateSeries(series)).andReturn(series).once();
    EasyMock.replay(seriesService);
    service.setSeriesService(seriesService);
    // This is true or false depending on the isOverwrite value
    Assert.assertEquals("Desire to update series is " + String.valueOf(isExpectSeriesOverwrite) + ".", isExpectSeriesOverwrite, service.updateSeries(urlCatalog2));
    // Test with mock not found exception
    EasyMock.reset(seriesService);
    EasyMock.expect(seriesService.updateSeries(series)).andReturn(series).once();
    EasyMock.expect(seriesService.getSeries((String) EasyMock.anyObject())).andThrow(new NotFoundException()).once();
    EasyMock.replay(seriesService);
    service.setSeriesService(seriesService);
    // This should be true, i.e. create new series, in all cases
    Assert.assertEquals("Always create a new series catalog.", true, service.updateSeries(urlCatalog2));
}
Also used : SeriesService(org.opencastproject.series.api.SeriesService) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) NotFoundException(org.opencastproject.util.NotFoundException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) File(java.io.File) URISyntaxException(java.net.URISyntaxException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) DublinCoreCatalogService(org.opencastproject.metadata.dublincore.DublinCoreCatalogService)

Example 2 with SeriesService

use of org.opencastproject.series.api.SeriesService in project opencast by opencast.

the class SeriesWorkflowOperationHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    mp = builder.loadFromXml(getClass().getResourceAsStream("/series_mediapackage.xml"));
    URI uri = getClass().getResource("/dublincore.xml").toURI();
    File file = new File(uri);
    seriesCatalog = DublinCores.mkOpencast().getCatalog();
    seriesCatalog.set(DublinCore.PROPERTY_TITLE, "Series 1");
    SeriesService seriesService = EasyMock.createNiceMock(SeriesService.class);
    EasyMock.expect(seriesService.getSeries(EasyMock.anyString())).andReturn(seriesCatalog).anyTimes();
    EasyMock.expect(seriesService.getSeriesAccessControl(EasyMock.anyString())).andReturn(new AccessControlList()).anyTimes();
    EasyMock.expect(seriesService.getSeriesElementData(EasyMock.anyString(), EasyMock.anyString())).andReturn(Opt.some(FileUtils.readFileToByteArray(file))).anyTimes();
    EasyMock.replay(seriesService);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.replay(securityService);
    capturedStream = Capture.newInstance(CaptureType.FIRST);
    Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.get(EasyMock.anyObject(URI.class))).andReturn(file).anyTimes();
    EasyMock.expect(workspace.read(EasyMock.anyObject(URI.class))).andAnswer(() -> getClass().getResourceAsStream("/dublincore.xml")).anyTimes();
    EasyMock.expect(workspace.put(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyString(), EasyMock.capture(capturedStream))).andReturn(uri).anyTimes();
    EasyMock.replay(workspace);
    AuthorizationService authorizationService = EasyMock.createNiceMock(AuthorizationService.class);
    EasyMock.replay(authorizationService);
    SeriesCatalogUIAdapter adapter = EasyMock.createNiceMock(SeriesCatalogUIAdapter.class);
    EasyMock.expect(adapter.getOrganization()).andReturn(new DefaultOrganization().getId()).anyTimes();
    EasyMock.expect(adapter.getFlavor()).andReturn("creativecommons/series").anyTimes();
    EasyMock.replay(adapter);
    SeriesCatalogUIAdapter seriesAdapter = EasyMock.createNiceMock(SeriesCatalogUIAdapter.class);
    EasyMock.expect(seriesAdapter.getOrganization()).andReturn(new DefaultOrganization().getId()).anyTimes();
    EasyMock.expect(seriesAdapter.getFlavor()).andReturn("dublincore/series").anyTimes();
    EasyMock.replay(seriesAdapter);
    // set up the handler
    operationHandler = new SeriesWorkflowOperationHandler();
    operationHandler.setSeriesService(seriesService);
    operationHandler.setSecurityService(securityService);
    operationHandler.setWorkspace(workspace);
    operationHandler.setAuthorizationService(authorizationService);
    operationHandler.addCatalogUIAdapter(adapter);
    operationHandler.addCatalogUIAdapter(seriesAdapter);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) SeriesService(org.opencastproject.series.api.SeriesService) AuthorizationService(org.opencastproject.security.api.AuthorizationService) SecurityService(org.opencastproject.security.api.SecurityService) SeriesCatalogUIAdapter(org.opencastproject.metadata.dublincore.SeriesCatalogUIAdapter) URI(java.net.URI) File(java.io.File) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 3 with SeriesService

use of org.opencastproject.series.api.SeriesService 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 4 with SeriesService

use of org.opencastproject.series.api.SeriesService 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 5 with SeriesService

use of org.opencastproject.series.api.SeriesService in project opencast by opencast.

the class PresetProviderImplTest method setUp.

@Before
public void setUp() throws SeriesException, NotFoundException, UnauthorizedException {
    Map<String, String> properties = new TreeMap<String, String>();
    properties.put(ORG_PROPERTY_NAME, ORG_PROPERTY_VALUE);
    organization = EasyMock.createMock(Organization.class);
    EasyMock.expect(organization.getProperties()).andReturn(properties).anyTimes();
    EasyMock.replay(organization);
    SecurityService securityService = EasyMock.createMock(SecurityService.class);
    EasyMock.expect(securityService.getOrganization()).andReturn(organization);
    EasyMock.replay(securityService);
    seriesService = EasyMock.createMock(SeriesService.class);
    EasyMock.expect(seriesService.getSeriesProperty(SERIES_ID, SERIES_PROPERTY_NAME)).andReturn(SERIES_PROPERTY_VALUE).anyTimes();
    EasyMock.expect(seriesService.getSeriesProperty(SERIES_ID, ORG_PROPERTY_NAME)).andThrow(new NotFoundException()).anyTimes();
    EasyMock.expect(seriesService.getSeriesProperty(SERIES_ID, NOT_FOUND_NAME)).andThrow(new NotFoundException()).anyTimes();
    EasyMock.replay(seriesService);
    presetProviderImpl = new PresetProviderImpl();
    presetProviderImpl.setSeriesService(seriesService);
    presetProviderImpl.setSecurityService(securityService);
}
Also used : Organization(org.opencastproject.security.api.Organization) SeriesService(org.opencastproject.series.api.SeriesService) SecurityService(org.opencastproject.security.api.SecurityService) NotFoundException(org.opencastproject.util.NotFoundException) TreeMap(java.util.TreeMap) Before(org.junit.Before)

Aggregations

SeriesService (org.opencastproject.series.api.SeriesService)10 SecurityService (org.opencastproject.security.api.SecurityService)6 Before (org.junit.Before)5 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)5 Workspace (org.opencastproject.workspace.api.Workspace)5 File (java.io.File)4 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)4 AccessControlList (org.opencastproject.security.api.AccessControlList)4 URI (java.net.URI)3 MediaPackage (org.opencastproject.mediapackage.MediaPackage)3 Organization (org.opencastproject.security.api.Organization)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 Hashtable (java.util.Hashtable)2 Capture (org.easymock.Capture)2 DublinCoreCatalogService (org.opencastproject.metadata.dublincore.DublinCoreCatalogService)2 JaxbUser (org.opencastproject.security.api.JaxbUser)2 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)2 NotFoundException (org.opencastproject.util.NotFoundException)2