Search in sources :

Example 1 with ThemesServiceDatabaseImpl

use of org.opencastproject.themes.persistence.ThemesServiceDatabaseImpl in project opencast by opencast.

the class ThemesServiceDatabaseTest method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    // Mock up a security service
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    User user = new JaxbUser("admin", "test", new DefaultOrganization(), new JaxbRole(SecurityConstants.GLOBAL_ADMIN_ROLE, new DefaultOrganization()));
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
    EasyMock.replay(securityService);
    UserDirectoryService userDirectoryService = EasyMock.createNiceMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser(EasyMock.anyString())).andReturn(user).anyTimes();
    EasyMock.replay(userDirectoryService);
    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);
    themesDatabase = new ThemesServiceDatabaseImpl();
    themesDatabase.setEntityManagerFactory(newTestEntityManagerFactory(ThemesServiceDatabaseImpl.PERSISTENCE_UNIT));
    themesDatabase.setSecurityService(securityService);
    themesDatabase.setUserDirectoryService(userDirectoryService);
    themesDatabase.setMessageSender(messageSender);
    themesDatabase.activate(null);
}
Also used : ThemesServiceDatabaseImpl(org.opencastproject.themes.persistence.ThemesServiceDatabaseImpl) Serializable(java.io.Serializable) User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) MessageSender(org.opencastproject.message.broker.api.MessageSender) JaxbUser(org.opencastproject.security.api.JaxbUser) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) Before(org.junit.Before)

Example 2 with ThemesServiceDatabaseImpl

use of org.opencastproject.themes.persistence.ThemesServiceDatabaseImpl 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);
}
Also used : Serializable(java.io.Serializable) MessageSender(org.opencastproject.message.broker.api.MessageSender) AdminUISearchIndex(org.opencastproject.adminui.impl.index.AdminUISearchIndex) JaxbUser(org.opencastproject.security.api.JaxbUser) StaticFileRestService(org.opencastproject.staticfiles.endpoint.StaticFileRestService) Capture(org.easymock.Capture) ThemesServiceDatabaseImpl(org.opencastproject.themes.persistence.ThemesServiceDatabaseImpl) SecurityService(org.opencastproject.security.api.SecurityService) HashSet(java.util.HashSet) ComponentContext(org.osgi.service.component.ComponentContext) SeriesSearchQuery(org.opencastproject.index.service.impl.index.series.SeriesSearchQuery) Hashtable(java.util.Hashtable) SearchResult(org.opencastproject.matterhorn.search.SearchResult) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) StaticFileService(org.opencastproject.staticfiles.api.StaticFileService) SeriesService(org.opencastproject.series.api.SeriesService) ByteArrayInputStream(java.io.ByteArrayInputStream) ThemeSearchQuery(org.opencastproject.index.service.impl.index.theme.ThemeSearchQuery) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) BundleContext(org.osgi.framework.BundleContext)

Aggregations

Serializable (java.io.Serializable)2 MessageSender (org.opencastproject.message.broker.api.MessageSender)2 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)2 JaxbUser (org.opencastproject.security.api.JaxbUser)2 SecurityService (org.opencastproject.security.api.SecurityService)2 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)2 ThemesServiceDatabaseImpl (org.opencastproject.themes.persistence.ThemesServiceDatabaseImpl)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HashSet (java.util.HashSet)1 Hashtable (java.util.Hashtable)1 Capture (org.easymock.Capture)1 Before (org.junit.Before)1 AdminUISearchIndex (org.opencastproject.adminui.impl.index.AdminUISearchIndex)1 SeriesSearchQuery (org.opencastproject.index.service.impl.index.series.SeriesSearchQuery)1 ThemeSearchQuery (org.opencastproject.index.service.impl.index.theme.ThemeSearchQuery)1 SearchResult (org.opencastproject.matterhorn.search.SearchResult)1 JaxbRole (org.opencastproject.security.api.JaxbRole)1 User (org.opencastproject.security.api.User)1 SeriesService (org.opencastproject.series.api.SeriesService)1 StaticFileService (org.opencastproject.staticfiles.api.StaticFileService)1