use of org.apache.felix.utils.log.Logger in project felix by apache.
the class RepositoryImplTest 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 });
EasyMock.expect(bundleContext.createFilter(null)).andReturn(new Filter() {
public boolean match(ServiceReference reference) {
return true;
}
public boolean match(Dictionary dictionary) {
return true;
}
public boolean matchCase(Dictionary dictionary) {
return true;
}
public boolean matches(Map<String, ?> map) {
return true;
}
}).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;
}
use of org.apache.felix.utils.log.Logger in project felix by apache.
the class ResolverImplTest 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(RepositoryAdminImpl.REPOSITORY_URL_PROP)).andReturn(getClass().getResource("/referred.xml").toExternalForm());
EasyMock.expect(bundleContext.getProperty((String) EasyMock.anyObject())).andReturn(null).anyTimes();
EasyMock.expect(bundleContext.getBundle(0)).andReturn(systemBundle);
EasyMock.expect(bundleContext.installBundle((String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(systemBundle);
EasyMock.expect(systemBundle.getHeaders()).andReturn(new Hashtable()).anyTimes();
systemBundle.start();
EasyMock.expectLastCall().anyTimes();
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;
}
use of org.apache.felix.utils.log.Logger in project felix by apache.
the class ResolverImplTest method testFindUpdatableLocalResource.
public void testFindUpdatableLocalResource() throws Exception {
LocalResource resource = EasyMock.createMock(LocalResource.class);
EasyMock.expect(resource.getSymbolicName()).andReturn("com.test.bundleA").anyTimes();
EasyMock.expect(resource.getRequirements()).andReturn(null).anyTimes();
EasyMock.expect(resource.getCapabilities()).andReturn(null).anyTimes();
EasyMock.expect(resource.getURI()).andReturn("http://test.com").anyTimes();
EasyMock.expect(resource.isLocal()).andReturn(true).anyTimes();
Repository localRepo = EasyMock.createMock(Repository.class);
Repository[] localRepos = { localRepo };
final LocalResource[] localResources = { resource };
EasyMock.expect(localRepo.getResources()).andReturn(localResources).anyTimes();
EasyMock.expect(localRepo.getURI()).andReturn(Repository.LOCAL).anyTimes();
EasyMock.expect(localRepo.getLastModified()).andReturn(System.currentTimeMillis()).anyTimes();
BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
EasyMock.replay(resource, localRepo);
ResolverImpl resolver = new ResolverImpl(bundleContext, localRepos, new Logger(bundleContext)) {
@Override
public LocalResource[] getLocalResources() {
return localResources;
}
};
resolver.add(resource);
boolean exceptionThrown = false;
try {
resolver.resolve();
resolver.deploy(Resolver.START);
} catch (Exception e) {
e.printStackTrace();
exceptionThrown = true;
}
assertFalse(exceptionThrown);
}
use of org.apache.felix.utils.log.Logger in project felix by apache.
the class Activator method start.
public void start(BundleContext context) {
Activator.context = context;
Activator.logger = new Logger(context);
// Register bundle repository service.
m_repoAdmin = new RepositoryAdminImpl(context, logger);
context.registerService(RepositoryAdmin.class.getName(), m_repoAdmin, null);
// Register the OSGi Repository-spec compliant facade
context.registerService(Repository.class.getName(), new OSGiRepositoryImpl(m_repoAdmin), null);
try {
context.registerService(org.osgi.service.obr.RepositoryAdmin.class.getName(), Wrapper.wrap(m_repoAdmin), null);
} catch (Throwable th) {
// Ignore
}
// the exception when we try to register the command service.
try {
// Register "obr" impl command service as a
// wrapper for the bundle repository service.
context.registerService(org.apache.felix.shell.Command.class.getName(), new ObrCommandImpl(Activator.context, m_repoAdmin), null);
} catch (Throwable th) {
// Ignore.
}
try {
Hashtable dict = new Hashtable();
dict.put("osgi.command.scope", "obr");
dict.put("osgi.command.function", new String[] { "deploy", "info", "javadoc", "list", "repos", "source" });
context.registerService(ObrGogoCommand.class.getName(), new ObrGogoCommand(Activator.context, m_repoAdmin), dict);
} catch (Throwable th) {
// Ignore
}
try {
Hashtable dict = new Hashtable();
dict.put(URLConstants.URL_HANDLER_PROTOCOL, "obr");
context.registerService(URLStreamHandlerService.class.getName(), new ObrURLStreamHandlerService(Activator.context, m_repoAdmin), dict);
} catch (Exception e) {
throw new RuntimeException("could not register obr url handler");
}
}
Aggregations