Search in sources :

Example 56 with ComponentContext

use of org.osgi.service.component.ComponentContext in project opencast by opencast.

the class RestPublisherTest method testResourceComparatorSameMatch.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testResourceComparatorSameMatch() {
    ServiceReference serviceReference = EasyMock.createNiceMock(ServiceReference.class);
    EasyMock.expect(serviceReference.getProperty(SERVICE_PATH_PROPERTY)).andReturn("/events").once();
    EasyMock.expect(serviceReference.getProperty(SERVICE_PATH_PROPERTY)).andReturn("/series").once();
    EasyMock.replay(serviceReference);
    BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
    EasyMock.expect(bc.getServiceReference(EasyMock.anyString())).andReturn(serviceReference).anyTimes();
    EasyMock.replay(bc);
    ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
    EasyMock.expect(cc.getBundleContext()).andReturn(bc).anyTimes();
    EasyMock.replay(cc);
    componentContext = cc;
    Message message = new MessageImpl();
    ExchangeImpl exchange = new ExchangeImpl();
    message.setExchange(exchange);
    message.put(Message.ENDPOINT_ADDRESS, "http://localhost:8080/series");
    ClassResourceInfo cri1 = new ClassResourceInfo(this.getClass());
    ClassResourceInfo cri2 = new ClassResourceInfo(RestPublisher.class.getClass());
    OperationResourceInfo oper1 = new OperationResourceInfo(this.getClass().getMethods()[0], cri1);
    OperationResourceInfo oper2 = new OperationResourceInfo(RestPublisher.class.getClass().getMethods()[0], cri2);
    Assert.assertEquals(1, rc.compare(cri1, cri2, message));
    Assert.assertEquals(1, rc.compare(oper1, oper2, message));
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext) Message(org.apache.cxf.message.Message) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) ServiceReference(org.osgi.framework.ServiceReference) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 57 with ComponentContext

use of org.osgi.service.component.ComponentContext in project opencast by opencast.

the class RestPublisherTest method testResourceComparatorSameNonMatch.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testResourceComparatorSameNonMatch() {
    ServiceReference serviceReference = EasyMock.createNiceMock(ServiceReference.class);
    EasyMock.expect(serviceReference.getProperty(SERVICE_PATH_PROPERTY)).andReturn("/events").once();
    EasyMock.expect(serviceReference.getProperty(SERVICE_PATH_PROPERTY)).andReturn("/org").once();
    EasyMock.replay(serviceReference);
    BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
    EasyMock.expect(bc.getServiceReference(EasyMock.anyString())).andReturn(serviceReference).anyTimes();
    EasyMock.replay(bc);
    ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
    EasyMock.expect(cc.getBundleContext()).andReturn(bc).anyTimes();
    EasyMock.replay(cc);
    componentContext = cc;
    Message message = new MessageImpl();
    ExchangeImpl exchange = new ExchangeImpl();
    message.setExchange(exchange);
    message.put(Message.ENDPOINT_ADDRESS, "http://localhost:8080/series");
    ClassResourceInfo cri1 = new ClassResourceInfo(this.getClass());
    ClassResourceInfo cri2 = new ClassResourceInfo(RestPublisher.class.getClass());
    OperationResourceInfo oper1 = new OperationResourceInfo(this.getClass().getMethods()[0], cri1);
    OperationResourceInfo oper2 = new OperationResourceInfo(RestPublisher.class.getClass().getMethods()[0], cri2);
    Assert.assertTrue(rc.compare(cri1, cri2, message) < 0);
    Assert.assertTrue(rc.compare(oper1, oper2, message) < 0);
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext) Message(org.apache.cxf.message.Message) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) ServiceReference(org.osgi.framework.ServiceReference) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 58 with ComponentContext

use of org.osgi.service.component.ComponentContext in project opencast by opencast.

the class CatalogUIAdapterFactoryTest method testRegisteringCommonCatalog.

@Test
public void testRegisteringCommonCatalog() throws Exception {
    ServiceRegistration service = EasyMock.createNiceMock(ServiceRegistration.class);
    BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
    EasyMock.expect(bundleContext.getServiceReferences(EasyMock.anyObject(Class.class), EasyMock.anyString())).andReturn(new ArrayList<>()).once();
    EasyMock.expect(bundleContext.registerService(EasyMock.anyObject(String[].class), EasyMock.anyObject(), EasyMock.anyObject(Dictionary.class))).andReturn(service).once();
    ComponentContext componentContext = EasyMock.createNiceMock(ComponentContext.class);
    EasyMock.expect(componentContext.getBundleContext()).andReturn(bundleContext).anyTimes();
    EasyMock.replay(componentContext, bundleContext, service);
    factory.activate(componentContext);
    factory.updated("testPid", configProperties);
    factory.deleted("testPid");
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext) ArrayList(java.util.ArrayList) ServiceRegistration(org.osgi.framework.ServiceRegistration) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 59 with ComponentContext

use of org.osgi.service.component.ComponentContext in project opencast by opencast.

the class SchedulerMigrationServiceTest method testSchedulerMigration.

@Test
@Ignore
public void testSchedulerMigration() throws Exception {
    BundleContext bundleContext = createNiceMock(BundleContext.class);
    expect(bundleContext.getProperty(SecurityUtil.PROPERTY_KEY_SYS_USER)).andReturn("root").anyTimes();
    expect(bundleContext.getProperty(CFG_ORGANIZATION)).andReturn("mh_default_org").anyTimes();
    ComponentContext cc = EasyMock.createNiceMock(ComponentContext.class);
    EasyMock.expect(cc.getBundleContext()).andReturn(bundleContext).anyTimes();
    EasyMock.replay(cc, bundleContext);
    DataSource dataSource = createDataSource("jdbc:mysql://localhost/test_scheduler", "opencast", "opencast");
    schedulerMigrationService.setDataSource(dataSource);
    schedulerMigrationService.activate(cc);
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext) BundleContext(org.osgi.framework.BundleContext) ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) DataSource(javax.sql.DataSource) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 60 with ComponentContext

use of org.osgi.service.component.ComponentContext 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

ComponentContext (org.osgi.service.component.ComponentContext)74 BundleContext (org.osgi.framework.BundleContext)46 Test (org.junit.Test)32 Dictionary (java.util.Dictionary)17 Before (org.junit.Before)12 JaxbUser (org.opencastproject.security.api.JaxbUser)11 SecurityService (org.opencastproject.security.api.SecurityService)11 Hashtable (java.util.Hashtable)10 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)10 JaxbRole (org.opencastproject.security.api.JaxbRole)10 File (java.io.File)9 Bundle (org.osgi.framework.Bundle)9 URI (java.net.URI)8 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)7 User (org.opencastproject.security.api.User)7 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)7 ServiceReference (org.osgi.framework.ServiceReference)7 Workspace (org.opencastproject.workspace.api.Workspace)6 Version (org.osgi.framework.Version)6 IOException (java.io.IOException)5