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));
}
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);
}
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);
}
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);
}
}
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);
}
Aggregations