Search in sources :

Example 1 with Logger

use of org.apache.felix.utils.log.Logger in project felix by apache.

the class StaxParserTest method createRepositoryAdmin.

private RepositoryAdminImpl createRepositoryAdmin(Class repositoryParser) throws Exception {
    BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
    Bundle systemBundle = EasyMock.createMock(Bundle.class);
    BundleRevision systemBundleRevision = EasyMock.createMock(BundleRevision.class);
    Activator.setContext(bundleContext);
    EasyMock.expect(bundleContext.getProperty(RepositoryAdminImpl.REPOSITORY_URL_PROP)).andReturn(getClass().getResource("/referral1_repository.xml").toExternalForm());
    EasyMock.expect(bundleContext.getProperty(RepositoryParser.OBR_PARSER_CLASS)).andReturn(repositoryParser.getName());
    EasyMock.expect(bundleContext.getProperty((String) EasyMock.anyObject())).andReturn(null).anyTimes();
    EasyMock.expect(bundleContext.getBundle(0)).andReturn(systemBundle);
    EasyMock.expect(systemBundle.getHeaders()).andReturn(new Hashtable());
    EasyMock.expect(systemBundle.getRegisteredServices()).andReturn(null);
    EasyMock.expect(new Long(systemBundle.getBundleId())).andReturn(new Long(0)).anyTimes();
    EasyMock.expect(systemBundle.getBundleContext()).andReturn(bundleContext);
    EasyMock.expect(systemBundleRevision.getCapabilities(null)).andReturn(Collections.<Capability>emptyList());
    EasyMock.expect(systemBundle.adapt(BundleRevision.class)).andReturn(systemBundleRevision);
    bundleContext.addBundleListener((BundleListener) EasyMock.anyObject());
    bundleContext.addServiceListener((ServiceListener) EasyMock.anyObject());
    EasyMock.expect(bundleContext.getBundles()).andReturn(new Bundle[] { systemBundle });
    final Capture c = new Capture();
    EasyMock.expect(bundleContext.createFilter((String) capture(c))).andAnswer(new IAnswer() {

        public Object answer() throws Throwable {
            return FilterImpl.newInstance((String) c.getValue());
        }
    }).anyTimes();
    EasyMock.replay(new Object[] { bundleContext, systemBundle, systemBundleRevision });
    RepositoryAdminImpl repoAdmin = new RepositoryAdminImpl(bundleContext, new Logger(bundleContext));
    // force initialization && remove all initial repositories
    Repository[] repos = repoAdmin.listRepositories();
    for (int i = 0; repos != null && i < repos.length; i++) {
        repoAdmin.removeRepository(repos[i].getURI());
    }
    return repoAdmin;
}
Also used : Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) Logger(org.apache.felix.utils.log.Logger) Capture(org.easymock.Capture) IAnswer(org.easymock.IAnswer) Repository(org.apache.felix.bundlerepository.Repository) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleContext(org.osgi.framework.BundleContext)

Example 2 with Logger

use of org.apache.felix.utils.log.Logger in project feature-flags-for-osgi by amitjoy.

the class FeatureManagerProvider method activate.

@Activate
protected void activate(final BundleContext bundleContext) throws Exception {
    logger = new Logger(bundleContext);
    extender = new MetaTypeExtender(metaTypeService, logger, bundlePids, allFeatures);
    extender.start(bundleContext);
}
Also used : Logger(org.apache.felix.utils.log.Logger) Activate(org.osgi.service.component.annotations.Activate)

Example 3 with Logger

use of org.apache.felix.utils.log.Logger in project felix by apache.

the class OSGiRepositoryImplTest method createRepositoryAdmin.

private RepositoryAdminImpl createRepositoryAdmin() throws Exception {
    Bundle sysBundle = Mockito.mock(Bundle.class);
    Mockito.when(sysBundle.getHeaders()).thenReturn(new Hashtable<String, String>());
    BundleRevision br = Mockito.mock(BundleRevision.class);
    Mockito.when(sysBundle.adapt(BundleRevision.class)).thenReturn(br);
    Capability cap1 = new OSGiCapabilityImpl("some.system.cap", Collections.<String, Object>singletonMap("sys.cap", "something"), Collections.singletonMap("x", "y"));
    Capability cap2 = new OSGiCapabilityImpl("some.system.cap", Collections.<String, Object>singletonMap("sys.cap", "somethingelse"), Collections.<String, String>emptyMap());
    Mockito.when(br.getCapabilities(null)).thenReturn(Arrays.asList(cap1, cap2));
    BundleContext bc = Mockito.mock(BundleContext.class);
    Mockito.when(bc.getBundle(0)).thenReturn(sysBundle);
    Mockito.when(sysBundle.getBundleContext()).thenReturn(bc);
    return new RepositoryAdminImpl(bc, new Logger(bc));
}
Also used : Capability(org.osgi.resource.Capability) Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision) Logger(org.apache.felix.utils.log.Logger) BundleContext(org.osgi.framework.BundleContext)

Example 4 with Logger

use of org.apache.felix.utils.log.Logger in project felix by apache.

the class OSGiRepositoryXMLTest method createRepositoryAdmin.

private RepositoryAdminImpl createRepositoryAdmin() throws Exception {
    Bundle sysBundle = Mockito.mock(Bundle.class);
    Mockito.when(sysBundle.getHeaders()).thenReturn(new Hashtable<String, String>());
    BundleRevision br = Mockito.mock(BundleRevision.class);
    Mockito.when(sysBundle.adapt(BundleRevision.class)).thenReturn(br);
    BundleContext bc = Mockito.mock(BundleContext.class);
    Mockito.when(bc.getBundle(0)).thenReturn(sysBundle);
    Mockito.when(sysBundle.getBundleContext()).thenReturn(bc);
    return new RepositoryAdminImpl(bc, new Logger(bc));
}
Also used : Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision) Logger(org.apache.felix.utils.log.Logger) BundleContext(org.osgi.framework.BundleContext)

Example 5 with Logger

use of org.apache.felix.utils.log.Logger in project felix by apache.

the class RepositoryAdminTest method createRepositoryAdmin.

private RepositoryAdminImpl createRepositoryAdmin() throws Exception {
    BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
    Bundle systemBundle = EasyMock.createMock(Bundle.class);
    BundleRevision systemBundleRevision = EasyMock.createMock(BundleRevision.class);
    Activator.setContext(bundleContext);
    EasyMock.expect(bundleContext.getProperty((String) EasyMock.anyObject())).andReturn(null).anyTimes();
    EasyMock.expect(bundleContext.getBundle(0)).andReturn(systemBundle);
    EasyMock.expect(systemBundle.getHeaders()).andReturn(new Hashtable());
    EasyMock.expect(systemBundle.getRegisteredServices()).andReturn(null);
    EasyMock.expect(new Long(systemBundle.getBundleId())).andReturn(new Long(0)).anyTimes();
    EasyMock.expect(systemBundle.getBundleContext()).andReturn(bundleContext);
    EasyMock.expect(systemBundleRevision.getCapabilities(null)).andReturn(Collections.<Capability>emptyList());
    EasyMock.expect(systemBundle.adapt(BundleRevision.class)).andReturn(systemBundleRevision);
    bundleContext.addBundleListener((BundleListener) EasyMock.anyObject());
    bundleContext.addServiceListener((ServiceListener) EasyMock.anyObject());
    EasyMock.expect(bundleContext.getBundles()).andReturn(new Bundle[] { systemBundle });
    final Capture c = new Capture();
    EasyMock.expect(bundleContext.createFilter((String) capture(c))).andAnswer(new IAnswer() {

        public Object answer() throws Throwable {
            return FilterImpl.newInstance((String) c.getValue());
        }
    }).anyTimes();
    EasyMock.replay(new Object[] { bundleContext, systemBundle, systemBundleRevision });
    RepositoryAdminImpl repoAdmin = new RepositoryAdminImpl(bundleContext, new Logger(bundleContext));
    // force initialization && remove all initial repositories
    org.apache.felix.bundlerepository.Repository[] repos = repoAdmin.listRepositories();
    for (int i = 0; repos != null && i < repos.length; i++) {
        repoAdmin.removeRepository(repos[i].getURI());
    }
    return repoAdmin;
}
Also used : Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) Logger(org.apache.felix.utils.log.Logger) Capture(org.easymock.Capture) IAnswer(org.easymock.IAnswer) Repository(org.apache.felix.bundlerepository.Repository) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleContext(org.osgi.framework.BundleContext)

Aggregations

Logger (org.apache.felix.utils.log.Logger)9 BundleRevision (org.osgi.framework.wiring.BundleRevision)6 Hashtable (java.util.Hashtable)5 Bundle (org.osgi.framework.Bundle)5 BundleContext (org.osgi.framework.BundleContext)5 Repository (org.apache.felix.bundlerepository.Repository)3 Capture (org.easymock.Capture)3 IAnswer (org.easymock.IAnswer)3 Dictionary (java.util.Dictionary)1 Map (java.util.Map)1 RepositoryAdmin (org.apache.felix.bundlerepository.RepositoryAdmin)1 Filter (org.osgi.framework.Filter)1 ServiceReference (org.osgi.framework.ServiceReference)1 Capability (org.osgi.resource.Capability)1 Activate (org.osgi.service.component.annotations.Activate)1 Repository (org.osgi.service.repository.Repository)1 URLStreamHandlerService (org.osgi.service.url.URLStreamHandlerService)1