use of org.osgi.service.component.ComponentContext in project jackrabbit-oak by apache.
the class OsgiUtilTest method testComponentLookupWithStringValue.
@Test
public void testComponentLookupWithStringValue() {
Dictionary properties = mock(Dictionary.class);
doReturn(" value ").when(properties).get("name");
ComponentContext context = mock(ComponentContext.class);
doReturn(properties).when(context).getProperties();
assertEquals("value", lookup(context, "name"));
}
use of org.osgi.service.component.ComponentContext in project jackrabbit-oak by apache.
the class OsgiUtilTest method testFallbackLookupWithValueInComponent.
@Test
public void testFallbackLookupWithValueInComponent() {
Dictionary dictionary = mock(Dictionary.class);
doReturn("value").when(dictionary).get("cname");
BundleContext bundleContext = mock(BundleContext.class);
doReturn(null).when(bundleContext).getProperty("fname");
ComponentContext componentContext = mock(ComponentContext.class);
doReturn(dictionary).when(componentContext).getProperties();
doReturn(bundleContext).when(componentContext).getBundleContext();
assertEquals("value", lookupConfigurationThenFramework(componentContext, "cname", "fname"));
assertEquals("value", lookupFrameworkThenConfiguration(componentContext, "cname", "fname"));
}
use of org.osgi.service.component.ComponentContext in project sling by apache.
the class AdapterManagerTest method createComponentContext.
/**
* Helper method to create a mock component context
*/
protected ComponentContext createComponentContext() throws Exception {
final BundleContext bundleCtx = this.context.mock(BundleContext.class);
final Filter filter = this.context.mock(Filter.class);
final ComponentContext ctx = this.context.mock(ComponentContext.class);
this.context.checking(new Expectations() {
{
allowing(ctx).locateService(with(any(String.class)), with(any(ServiceReference.class)));
will(returnValue(new MockAdapterFactory()));
allowing(ctx).getBundleContext();
will(returnValue(bundleCtx));
allowing(bundleCtx).createFilter(with(any(String.class)));
will(returnValue(filter));
allowing(bundleCtx).addServiceListener(with(any(ServiceListener.class)), with(any(String.class)));
allowing(bundleCtx).getServiceReferences(with(any(String.class)), with(any(String.class)));
will(returnValue(null));
allowing(bundleCtx).removeServiceListener(with(any(ServiceListener.class)));
allowing(bundleCtx).registerService(with(Adaption.class), with(AdaptionImpl.INSTANCE), with(any(Dictionary.class)));
will(returnValue(null));
}
});
return ctx;
}
use of org.osgi.service.component.ComponentContext in project sling by apache.
the class MockFactory method mockComponentContext.
public static ComponentContext mockComponentContext() {
Mockery context = new JUnit4Mockery();
final BundleContext bc = context.mock(BundleContext.class);
context.checking(new Expectations() {
{
allowing(bc).registerService(with(any(String.class)), with(any(Object.class)), with(any(Dictionary.class)));
will(VoidAction.INSTANCE);
allowing(bc).getProperty(with(any(String.class)));
will(new ReturnValueAction("foo"));
}
});
final ComponentContext cc = context.mock(ComponentContext.class);
context.checking(new Expectations() {
{
allowing(cc).getProperties();
will(returnValue(new Properties()));
allowing(cc).getBundleContext();
will(returnValue(bc));
}
});
return cc;
}
use of org.osgi.service.component.ComponentContext in project sling by apache.
the class VirtualInstance method startJetty.
public synchronized void startJetty() throws Throwable {
if (jettyServer != null) {
return;
}
servletContext = new ServletContextHandler(ServletContextHandler.NO_SECURITY);
servletContext.setContextPath("/");
TopologyConnectorServlet servlet = new TopologyConnectorServlet();
PrivateAccessor.setField(servlet, "config", config);
PrivateAccessor.setField(servlet, "clusterViewService", clusterViewService);
PrivateAccessor.setField(servlet, "announcementRegistry", announcementRegistry);
Mockery context = new JUnit4Mockery();
final HttpService httpService = context.mock(HttpService.class);
context.checking(new Expectations() {
{
allowing(httpService).registerServlet(with(any(String.class)), with(any(Servlet.class)), with(any(Dictionary.class)), with(any(HttpContext.class)));
}
});
PrivateAccessor.setField(servlet, "httpService", httpService);
ComponentContext cc = null;
PrivateAccessor.invoke(servlet, "activate", new Class[] { ComponentContext.class }, new Object[] { cc });
ServletHolder holder = new ServletHolder(servlet);
servletContext.addServlet(holder, "/system/console/topology/*");
jettyServer = new Server();
jettyServer.setHandler(servletContext);
Connector connector = new SelectChannelConnector();
jettyServer.setConnectors(new Connector[] { connector });
jettyServer.start();
}
Aggregations