use of org.apache.felix.http.base.internal.registry.HandlerRegistry in project felix by apache.
the class HttpServiceFactoryTest method testGetServiceActiveInActive.
@Test
public void testGetServiceActiveInActive() throws Exception {
BundleContext bc = Mockito.mock(BundleContext.class);
Mockito.when(bc.createFilter(Mockito.anyString())).then(new Answer<Filter>() {
@Override
public Filter answer(InvocationOnMock invocation) throws Throwable {
return FrameworkUtil.createFilter((String) invocation.getArguments()[0]);
}
});
final HandlerRegistry reg = new HandlerRegistry();
reg.init();
HttpServiceFactory hsf = new HttpServiceFactory(bc, reg);
Assert.assertNull("Not yet active", hsf.getService(Mockito.mock(Bundle.class), null));
ServletContext sctx = Mockito.mock(ServletContext.class);
hsf.start(sctx, new Hashtable<String, Object>());
HttpService svc = hsf.getService(Mockito.mock(Bundle.class), null);
Assert.assertNotNull(svc);
hsf.stop();
Assert.assertNull("Not active any more", hsf.getService(Mockito.mock(Bundle.class), null));
}
use of org.apache.felix.http.base.internal.registry.HandlerRegistry in project felix by apache.
the class ServletContextImplTest method setUp.
@Before
public void setUp() {
this.bundle = Mockito.mock(Bundle.class);
ServletContext globalContext = new MockServletContext();
this.httpContext = Mockito.mock(HttpContext.class);
this.listener = new AttributeListener();
final HandlerRegistry reg = new HandlerRegistry();
reg.init();
contextRegistry = reg.getRegistry(HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID);
final EventListenerRegistry eventReg = contextRegistry.getEventListenerRegistry();
final ListenerInfo info = Mockito.mock(ListenerInfo.class);
when(info.getListenerTypes()).thenReturn(new String[] { ServletContextAttributeListener.class.getName() });
when(info.isListenerType(ServletContextAttributeListener.class.getName())).thenReturn(true);
final ListenerHandler handler = Mockito.mock(ListenerHandler.class);
when(handler.getListenerInfo()).thenReturn(info);
when(handler.getContextServiceId()).thenReturn(HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID);
when(handler.getListener()).thenReturn(listener);
when(handler.init()).thenReturn(-1);
eventReg.addListeners(handler);
this.context = new ServletContextImpl(this.bundle, globalContext, this.httpContext, false, contextRegistry);
}
Aggregations