use of org.apache.felix.http.base.internal.runtime.dto.FailedDTOHolder in project felix by apache.
the class FilterRegistryTest method testSingleListener.
@Test
public void testSingleListener() throws InvalidSyntaxException, ServletException {
final EventListenerRegistry reg = new EventListenerRegistry();
final FailedDTOHolder holder = new FailedDTOHolder();
final ServletContextDTO dto = new ServletContextDTO();
// check DTO
reg.getRuntimeInfo(dto, holder.failedListenerDTOs);
assertEmpty(dto, holder);
// register listener
final ListenerHandler h1 = createListenerHandler(1L, 0, ServletContextListener.class);
reg.addListeners(h1);
// one entry in DTO
clear(dto, holder);
reg.getRuntimeInfo(dto, holder.failedListenerDTOs);
assertTrue(holder.failedListenerDTOs.isEmpty());
assertNotNull(dto.listenerDTOs);
assertEquals(1, dto.listenerDTOs.length);
assertEquals(1, dto.listenerDTOs[0].types.length);
assertEquals(ServletContextListener.class.getName(), dto.listenerDTOs[0].types[0]);
// remove listener
reg.removeListeners(h1.getListenerInfo());
// empty again
clear(dto, holder);
reg.getRuntimeInfo(dto, holder.failedListenerDTOs);
assertEmpty(dto, holder);
}
use of org.apache.felix.http.base.internal.runtime.dto.FailedDTOHolder in project felix by apache.
the class HandlerRegistryTest method testAddRemoveServlet.
@Test
public void testAddRemoveServlet() throws Exception {
registry.init();
final FailedDTOHolder holder = new FailedDTOHolder();
final ServletContextDTO dto = new ServletContextDTO();
dto.serviceId = HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID;
dto.servletDTOs = new ServletDTO[0];
Servlet servlet = Mockito.mock(Servlet.class);
final ServletInfo info = new ServletInfo("foo", "/foo", Collections.<String, String>emptyMap());
ServletHandler handler = new HttpServiceServletHandler(null, info, servlet);
assertTrue(registry.getRuntimeInfo(dto, holder));
assertEquals("Precondition", 0, dto.servletDTOs.length);
registry.getRegistry(handler.getContextServiceId()).registerServlet(handler);
Mockito.verify(servlet, Mockito.times(1)).init(Mockito.any(ServletConfig.class));
assertTrue(registry.getRuntimeInfo(dto, holder));
assertEquals(1, dto.servletDTOs.length);
assertEquals(info.getServiceId(), dto.servletDTOs[0].serviceId);
final ServletInfo info2 = new ServletInfo("bar", "/bar", Collections.<String, String>emptyMap());
ServletHandler handler2 = new HttpServiceServletHandler(null, info2, Mockito.mock(Servlet.class));
registry.getRegistry(handler.getContextServiceId()).registerServlet(handler2);
assertTrue(registry.getRuntimeInfo(dto, holder));
assertEquals(2, dto.servletDTOs.length);
final ServletInfo info3 = new ServletInfo("zar", "/foo", Collections.<String, String>emptyMap());
ServletHandler handler3 = new HttpServiceServletHandler(null, info3, Mockito.mock(Servlet.class));
registry.getRegistry(handler.getContextServiceId()).registerServlet(handler3);
assertTrue(registry.getRuntimeInfo(dto, holder));
assertEquals(2, dto.servletDTOs.length);
assertEquals(1, holder.failedServletDTOs.size());
registry.shutdown();
}
use of org.apache.felix.http.base.internal.runtime.dto.FailedDTOHolder in project felix by apache.
the class ServletRegistryTest method testSimpleHiding.
@Test
public void testSimpleHiding() throws InvalidSyntaxException, ServletException {
final FailedDTOHolder holder = new FailedDTOHolder();
final ServletContextDTO dto = new ServletContextDTO();
// empty reg
reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
assertEmpty(dto, holder);
// register servlets
final ServletHandler h1 = createServletHandler(1L, 10, "/foo");
reg.addServlet(h1);
verify(h1.getServlet()).init(Matchers.any(ServletConfig.class));
final ServletHandler h2 = createServletHandler(2L, 0, "/foo");
reg.addServlet(h2);
verify(h2.getServlet(), never()).init(Matchers.any(ServletConfig.class));
verify(h1.getServlet(), never()).destroy();
// two entries in reg
// h1 is active
// h2 is hidden
clear(dto, holder);
reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
assertNull(dto.resourceDTOs);
assertTrue(holder.failedResourceDTOs.isEmpty());
assertFalse(holder.failedServletDTOs.isEmpty());
assertNotNull(dto.servletDTOs);
assertEquals(1, dto.servletDTOs.length);
assertEquals(1, dto.servletDTOs[0].patterns.length);
assertEquals("/foo", dto.servletDTOs[0].patterns[0]);
assertEquals(1, dto.servletDTOs[0].serviceId);
assertEquals(1, holder.failedServletDTOs.size());
final FailedServletDTO failedDTO = holder.failedServletDTOs.iterator().next();
assertEquals(1, failedDTO.patterns.length);
assertEquals("/foo", failedDTO.patterns[0]);
assertEquals(2, failedDTO.serviceId);
// remove servlet 1
final Servlet s1 = h1.getServlet();
reg.removeServlet(h1.getServletInfo(), true);
verify(s1).destroy();
verify(h2.getServlet()).init(Matchers.any(ServletConfig.class));
// h2 is active
clear(dto, holder);
reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
assertNull(dto.resourceDTOs);
assertTrue(holder.failedResourceDTOs.isEmpty());
assertTrue(holder.failedServletDTOs.isEmpty());
assertNotNull(dto.servletDTOs);
assertEquals(1, dto.servletDTOs.length);
assertEquals(1, dto.servletDTOs[0].patterns.length);
assertEquals("/foo", dto.servletDTOs[0].patterns[0]);
assertEquals(2, dto.servletDTOs[0].serviceId);
// remove servlet 2
final Servlet s2 = h2.getServlet();
reg.removeServlet(h2.getServletInfo(), true);
verify(s2).destroy();
// empty again
clear(dto, holder);
reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
assertEmpty(dto, holder);
}
use of org.apache.felix.http.base.internal.runtime.dto.FailedDTOHolder in project felix by apache.
the class ServletRegistryTest method testSingleServlet.
@Test
public void testSingleServlet() throws InvalidSyntaxException, ServletException {
final FailedDTOHolder holder = new FailedDTOHolder();
final ServletContextDTO dto = new ServletContextDTO();
// empty reg
reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
assertEmpty(dto, holder);
// register servlet
final ServletHandler h1 = createServletHandler(1L, 0, "/foo");
reg.addServlet(h1);
verify(h1.getServlet()).init(Matchers.any(ServletConfig.class));
// one entry in reg
// check DTO
clear(dto, holder);
reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
assertNull(dto.resourceDTOs);
assertTrue(holder.failedResourceDTOs.isEmpty());
assertTrue(holder.failedServletDTOs.isEmpty());
assertNotNull(dto.servletDTOs);
assertEquals(1, dto.servletDTOs.length);
assertEquals(1, dto.servletDTOs[0].patterns.length);
assertEquals("/foo", dto.servletDTOs[0].patterns[0]);
// remove servlet
final Servlet s = h1.getServlet();
reg.removeServlet(h1.getServletInfo(), true);
verify(s).destroy();
// empty again
clear(dto, holder);
reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
assertEmpty(dto, holder);
}
use of org.apache.felix.http.base.internal.runtime.dto.FailedDTOHolder in project felix by apache.
the class ErrorPageRegistryTest method testRangeRegistration.
@Test
public void testRangeRegistration() throws InvalidSyntaxException {
final ErrorPageRegistry reg = new ErrorPageRegistry();
final FailedDTOHolder holder = new FailedDTOHolder();
final ServletContextDTO dto = new ServletContextDTO();
final ServletHandler handler4 = createServletHandler(1L, 0, "4xx");
final ServletHandler handler5 = createServletHandler(2L, 0, "5xx");
reg.addServlet(handler4);
reg.addServlet(handler5);
// check DTO
reg.getRuntimeInfo(dto, holder.failedErrorPageDTOs);
assertTrue(holder.failedErrorPageDTOs.isEmpty());
assertEquals(2, dto.errorPageDTOs.length);
assertEquals(100, dto.errorPageDTOs[0].errorCodes.length);
final Set<Long> codes4 = new HashSet<Long>();
for (final long c : dto.errorPageDTOs[0].errorCodes) {
assertTrue(c >= 400 && c < 500);
codes4.add(c);
}
assertEquals(100, codes4.size());
assertEquals(100, dto.errorPageDTOs[1].errorCodes.length);
final Set<Long> codes5 = new HashSet<Long>();
for (final long c : dto.errorPageDTOs[1].errorCodes) {
assertTrue(c >= 500 && c < 600);
codes5.add(c);
}
assertEquals(100, codes5.size());
}
Aggregations