use of org.opencastproject.series.api.SeriesService in project opencast by opencast.
the class TestRestService method newSeriesService.
private static SeriesService newSeriesService() {
AccessControlList acl = new AccessControlList();
SeriesService seriesService = EasyMock.createNiceMock(SeriesService.class);
try {
EasyMock.expect(seriesService.getSeriesAccessControl((String) EasyMock.anyObject())).andReturn(acl).anyTimes();
EasyMock.expect(seriesService.updateAccessControl((String) EasyMock.anyObject(), (AccessControlList) EasyMock.anyObject())).andThrow(new NotFoundException()).andReturn(true);
} catch (Exception e) {
throw new RuntimeException(e);
}
EasyMock.replay(seriesService);
return seriesService;
}
use of org.opencastproject.series.api.SeriesService in project opencast by opencast.
the class IndexServiceImplTest method testUpdateMediaPackageMetadata.
@Test
public void testUpdateMediaPackageMetadata() throws Exception {
// mock/initialize dependencies
String username = "user1";
String org = "mh_default_org";
String testResourceLocation = "/events/update-event.json";
String metadataJson = IOUtils.toString(getClass().getResourceAsStream(testResourceLocation));
MetadataCollection metadataCollection = new DublinCoreMetadataCollection();
metadataCollection.addField(MetadataField.createTextMetadataField("title", Opt.some("title"), "EVENTS.EVENTS.DETAILS.METADATA.TITLE", false, true, Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none()));
metadataCollection.addField(MetadataField.createTextLongMetadataField("creator", Opt.some("creator"), "EVENTS.EVENTS.DETAILS.METADATA.PRESENTERS", false, false, Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none()));
metadataCollection.addField(MetadataField.createTextMetadataField("isPartOf", Opt.some("isPartOf"), "EVENTS.EVENTS.DETAILS.METADATA.SERIES", false, false, Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none()));
MetadataList metadataList = new MetadataList(metadataCollection, metadataJson);
String eventId = "event-1";
Event event = new Event(eventId, org);
event.setTitle("Test Event 1");
SearchQuery query = EasyMock.createMock(SearchQuery.class);
EasyMock.expect(query.getLimit()).andReturn(100);
EasyMock.expect(query.getOffset()).andReturn(0);
EasyMock.replay(query);
SearchResultItemImpl<Event> searchResultItem = new SearchResultItemImpl<>(1.0, event);
SearchResultImpl<Event> searchResult = new SearchResultImpl<>(query, 0, 0);
searchResult.addResultItem(searchResultItem);
SecurityService securityService = setupSecurityService(username, org);
AbstractSearchIndex index = EasyMock.createMock(AbstractSearchIndex.class);
MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(getClass().getResourceAsStream("/events/update-event-mp.xml"));
EasyMock.expect(index.getByQuery(EasyMock.anyObject(EventSearchQuery.class))).andReturn(searchResult);
EasyMock.replay(index);
Workspace workspace = EasyMock.createMock(Workspace.class);
EasyMock.expect(workspace.put(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyObject())).andReturn(getClass().getResource("/dublincore.xml").toURI()).anyTimes();
EasyMock.expect(workspace.read(EasyMock.anyObject())).andAnswer(() -> getClass().getResourceAsStream("/dublincore.xml")).anyTimes();
EasyMock.replay(workspace);
CommonEventCatalogUIAdapter commonEventCatalogUIAdapter = setupCommonCatalogUIAdapter(workspace).getA();
// Using scheduler as the source of the media package here.
SchedulerService schedulerService = EasyMock.createMock(SchedulerService.class);
EasyMock.expect(schedulerService.getMediaPackage(EasyMock.anyString())).andReturn(mp);
Capture<Opt<MediaPackage>> mpCapture = new Capture<>();
schedulerService.updateEvent(EasyMock.anyString(), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.capture(mpCapture), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyString());
EasyMock.expectLastCall();
EasyMock.replay(schedulerService);
SeriesService seriesService = EasyMock.createMock(SeriesService.class);
DublinCoreCatalog seriesDC = DublinCores.read(getClass().getResourceAsStream("/events/update-event-series.xml"));
EasyMock.expect(seriesService.getSeries(EasyMock.anyString())).andReturn(seriesDC);
EasyMock.expect(seriesService.getSeriesAccessControl(EasyMock.anyString())).andReturn(null);
EasyMock.expect(seriesService.getSeriesElements(EasyMock.anyString())).andReturn(Opt.none());
EasyMock.replay(seriesService);
// create service
IndexServiceImpl indexService = new IndexServiceImpl();
indexService.setSecurityService(securityService);
indexService.setSchedulerService(schedulerService);
indexService.setCommonEventCatalogUIAdapter(commonEventCatalogUIAdapter);
indexService.addCatalogUIAdapter(commonEventCatalogUIAdapter);
indexService.setSeriesService(seriesService);
indexService.setWorkspace(workspace);
MetadataList updateEventMetadata = indexService.updateEventMetadata(org, metadataList, index);
Assert.assertTrue(mpCapture.hasCaptured());
Assert.assertEquals("series-1", mp.getSeries());
Assert.assertEquals(1, mp.getCatalogs(MediaPackageElements.SERIES).length);
}
use of org.opencastproject.series.api.SeriesService in project opencast by opencast.
the class TestThemesEndpoint method setupServices.
private void setupServices() throws Exception {
user = new JaxbUser("test", null, "Test User", "test@test.com", "test", new DefaultOrganization(), new HashSet<JaxbRole>());
UserDirectoryService userDirectoryService = EasyMock.createNiceMock(UserDirectoryService.class);
EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(user).anyTimes();
EasyMock.replay(userDirectoryService);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
EasyMock.replay(securityService);
SeriesService seriesService = EasyMock.createNiceMock(SeriesService.class);
EasyMock.replay(seriesService);
MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
messageSender.sendObjectMessage(EasyMock.anyObject(String.class), EasyMock.anyObject(MessageSender.DestinationType.class), EasyMock.anyObject(Serializable.class));
EasyMock.expectLastCall().anyTimes();
EasyMock.replay(messageSender);
// Create AdminUI Search Index
AdminUISearchIndex adminUISearchIndex = EasyMock.createMock(AdminUISearchIndex.class);
final Capture<ThemeSearchQuery> themeQueryCapture = new Capture<ThemeSearchQuery>();
EasyMock.expect(adminUISearchIndex.getByQuery(EasyMock.capture(themeQueryCapture))).andAnswer(new IAnswer<SearchResult<org.opencastproject.index.service.impl.index.theme.Theme>>() {
@Override
public SearchResult<org.opencastproject.index.service.impl.index.theme.Theme> answer() throws Throwable {
return createThemeCaptureResult(themeQueryCapture);
}
});
final Capture<SeriesSearchQuery> seriesQueryCapture = new Capture<SeriesSearchQuery>();
EasyMock.expect(adminUISearchIndex.getByQuery(EasyMock.capture(seriesQueryCapture))).andAnswer(new IAnswer<SearchResult<Series>>() {
@Override
public SearchResult<Series> answer() throws Throwable {
return createSeriesCaptureResult(seriesQueryCapture);
}
});
EasyMock.replay(adminUISearchIndex);
themesServiceDatabaseImpl = new ThemesServiceDatabaseImpl();
themesServiceDatabaseImpl.setEntityManagerFactory(newTestEntityManagerFactory(ThemesServiceDatabaseImpl.PERSISTENCE_UNIT));
themesServiceDatabaseImpl.setUserDirectoryService(userDirectoryService);
themesServiceDatabaseImpl.setSecurityService(securityService);
themesServiceDatabaseImpl.setMessageSender(messageSender);
themesServiceDatabaseImpl.activate(null);
StaticFileService staticFileService = EasyMock.createNiceMock(StaticFileService.class);
EasyMock.expect(staticFileService.getFile(EasyMock.anyString())).andReturn(new ByteArrayInputStream("test".getBytes("utf-8"))).anyTimes();
EasyMock.expect(staticFileService.getFileName(EasyMock.anyString())).andStubReturn("test.mp4");
EasyMock.replay(staticFileService);
BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
EasyMock.expect(bundleContext.getProperty("org.opencastproject.server.url")).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);
StaticFileRestService staticFileRestService = new StaticFileRestService();
staticFileRestService.setStaticFileService(staticFileService);
staticFileRestService.activate(componentContext);
this.setThemesServiceDatabase(themesServiceDatabaseImpl);
this.setSecurityService(securityService);
this.setSeriesService(seriesService);
this.setStaticFileService(staticFileService);
this.setStaticFileRestService(staticFileRestService);
this.setIndex(adminUISearchIndex);
}
use of org.opencastproject.series.api.SeriesService in project opencast by opencast.
the class SearchServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
// workspace
Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andAnswer(new IAnswer<File>() {
@Override
public File answer() throws Throwable {
return new File(new URI(EasyMock.getCurrentArguments()[0].toString()));
}
}).anyTimes();
EasyMock.replay(workspace);
// User, organization and service registry
userResponder = new Responder<User>(defaultUser);
organizationResponder = new Responder<Organization>(defaultOrganization);
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
EasyMock.expect(securityService.getUser()).andAnswer(userResponder).anyTimes();
EasyMock.expect(securityService.getOrganization()).andAnswer(organizationResponder).anyTimes();
EasyMock.replay(securityService);
User anonymous = new JaxbUser("anonymous", "test", defaultOrganization, new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, defaultOrganization));
UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
EasyMock.replay(userDirectoryService);
Organization organization = new DefaultOrganization();
OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
EasyMock.replay(organizationDirectoryService);
// mpeg7 service
Mpeg7CatalogService mpeg7CatalogService = new Mpeg7CatalogService();
// Persistence storage
searchDatabase = new SearchServiceDatabaseImpl();
searchDatabase.setEntityManagerFactory(newTestEntityManagerFactory(SearchServiceDatabaseImpl.PERSISTENCE_UNIT));
searchDatabase.activate(null);
searchDatabase.setSecurityService(securityService);
// search service
service = new SearchServiceImpl();
serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
StaticMetadataService mdService = newStaticMetadataService(workspace);
SeriesService seriesService = EasyMock.createNiceMock(SeriesService.class);
DublinCoreCatalog seriesCatalog = getSeriesDublinCoreCatalog("/series-dublincore.xml");
AccessControlList seriesAcl = new AccessControlList();
EasyMock.expect(seriesService.getSeries((String) EasyMock.anyObject())).andReturn(seriesCatalog).anyTimes();
EasyMock.expect(seriesService.getSeriesAccessControl((String) EasyMock.anyObject())).andReturn(seriesAcl).anyTimes();
EasyMock.replay(seriesService);
service.setStaticMetadataService(mdService);
service.setWorkspace(workspace);
service.setMpeg7CatalogService(mpeg7CatalogService);
service.setSecurityService(securityService);
service.setOrganizationDirectoryService(organizationDirectoryService);
service.setUserDirectoryService(userDirectoryService);
service.setServiceRegistry(serviceRegistry);
service.setPersistence(searchDatabase);
SolrServer solrServer = SearchServiceImpl.setupSolr(new File(solrRoot));
service.testSetup(solrServer, new SolrRequester(solrServer, securityService), new SolrIndexManager(solrServer, workspace, Arrays.asList(mdService), seriesService, mpeg7CatalogService, securityService));
// acl
String anonymousRole = securityService.getOrganization().getAnonymousRole();
acl = new AccessControlList(new AccessControlEntry(anonymousRole, Permissions.Action.READ.toString(), true));
authorizationService = EasyMock.createNiceMock(AuthorizationService.class);
EasyMock.expect(authorizationService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
EasyMock.expect(authorizationService.hasPermission((MediaPackage) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(true).anyTimes();
service.setAuthorizationService(authorizationService);
EasyMock.replay(authorizationService);
}
use of org.opencastproject.series.api.SeriesService in project opencast by opencast.
the class SchedulerServiceImplTest method setUp.
@Before
public void setUp() throws Exception {
String seriesIdentifier = Long.toString(System.currentTimeMillis());
DublinCoreCatalog seriesCatalog = getSampleSeriesDublinCoreCatalog(seriesIdentifier);
List<DublinCoreCatalog> seriesCatalogs = new ArrayList<>();
seriesCatalogs.add(seriesCatalog);
seriesService = EasyMock.createMock(SeriesService.class);
EasyMock.expect(seriesService.getSeries(EasyMock.anyString())).andReturn(seriesCatalog).anyTimes();
EasyMock.expect(seriesService.getSeries(EasyMock.anyObject(SeriesQuery.class))).andReturn(new DublinCoreCatalogList(seriesCatalogs, 1)).anyTimes();
EasyMock.expect(seriesService.isOptOut(EasyMock.anyString())).andReturn(false).anyTimes();
EasyMock.replay(seriesService);
schedSvc.setSeriesService(seriesService);
assetManager = mkAssetManager();
schedSvc.setAssetManager(assetManager);
}
Aggregations