Search in sources :

Example 1 with HandlerRegistry

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));
}
Also used : Bundle(org.osgi.framework.Bundle) HandlerRegistry(org.apache.felix.http.base.internal.registry.HandlerRegistry) Filter(org.osgi.framework.Filter) InvocationOnMock(org.mockito.invocation.InvocationOnMock) HttpService(org.osgi.service.http.HttpService) ServletContext(javax.servlet.ServletContext) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 2 with HandlerRegistry

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);
}
Also used : ServletContextAttributeListener(javax.servlet.ServletContextAttributeListener) HandlerRegistry(org.apache.felix.http.base.internal.registry.HandlerRegistry) PerContextHandlerRegistry(org.apache.felix.http.base.internal.registry.PerContextHandlerRegistry) ListenerInfo(org.apache.felix.http.base.internal.runtime.ListenerInfo) Bundle(org.osgi.framework.Bundle) ServletContextImpl(org.apache.felix.http.base.internal.service.ServletContextImpl) HttpContext(org.osgi.service.http.HttpContext) ServletContext(javax.servlet.ServletContext) ServletContextAttributeListener(javax.servlet.ServletContextAttributeListener) ListenerHandler(org.apache.felix.http.base.internal.handler.ListenerHandler) EventListenerRegistry(org.apache.felix.http.base.internal.registry.EventListenerRegistry) Before(org.junit.Before)

Aggregations

ServletContext (javax.servlet.ServletContext)2 HandlerRegistry (org.apache.felix.http.base.internal.registry.HandlerRegistry)2 Bundle (org.osgi.framework.Bundle)2 ServletContextAttributeListener (javax.servlet.ServletContextAttributeListener)1 ListenerHandler (org.apache.felix.http.base.internal.handler.ListenerHandler)1 EventListenerRegistry (org.apache.felix.http.base.internal.registry.EventListenerRegistry)1 PerContextHandlerRegistry (org.apache.felix.http.base.internal.registry.PerContextHandlerRegistry)1 ListenerInfo (org.apache.felix.http.base.internal.runtime.ListenerInfo)1 ServletContextImpl (org.apache.felix.http.base.internal.service.ServletContextImpl)1 Before (org.junit.Before)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 BundleContext (org.osgi.framework.BundleContext)1 Filter (org.osgi.framework.Filter)1 HttpContext (org.osgi.service.http.HttpContext)1 HttpService (org.osgi.service.http.HttpService)1