use of org.osgi.service.http.runtime.dto.RuntimeDTO in project felix by apache.
the class HttpServiceRuntimeTest method invalidContextHelperNameAppearsAsFailure.
// As specified in OSGi Compendium Release 6, Chapter 140.1
@Test
public void invalidContextHelperNameAppearsAsFailure() throws InterruptedException {
registerContext("context A", "");
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTO = serviceRuntime.getRuntimeDTO();
assertEquals(1, runtimeDTO.failedServletContextDTOs.length);
assertEquals("context A", runtimeDTO.failedServletContextDTOs[0].name);
assertEquals(FAILURE_REASON_VALIDATION_FAILED, runtimeDTO.failedServletContextDTOs[0].failureReason);
}
use of org.osgi.service.http.runtime.dto.RuntimeDTO in project felix by apache.
the class HttpServiceRuntimeTest method dtosForSuccesfullyRegisteredErrorPageWithWildcardErrorCode.
public void dtosForSuccesfullyRegisteredErrorPageWithWildcardErrorCode(String code, long startCode) throws Exception {
registerErrorPage("error page 1", asList(code));
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTOWithErrorPage = serviceRuntime.getRuntimeDTO();
assertEquals(0, runtimeDTOWithErrorPage.failedServletDTOs.length);
assertEquals(0, runtimeDTOWithErrorPage.failedErrorPageDTOs.length);
ServletContextDTO contextDTO = assertDefaultContext(runtimeDTOWithErrorPage);
assertEquals(1, contextDTO.errorPageDTOs.length);
assertEquals("error page 1", contextDTO.errorPageDTOs[0].name);
assertContainsAllHundredFrom(startCode, contextDTO.errorPageDTOs[0].errorCodes);
}
use of org.osgi.service.http.runtime.dto.RuntimeDTO in project felix by apache.
the class HttpServiceRuntimeTest method missingContextHelperNameAppearsAsFailure.
// As specified in OSGi Compendium Release 6, Chapter 140.1
@Test
public void missingContextHelperNameAppearsAsFailure() {
Dictionary<String, ?> properties = createDictionary(HTTP_WHITEBOARD_CONTEXT_PATH, "");
registrations.add(m_context.registerService(ServletContextHelper.class.getName(), mock(ServletContextHelper.class), properties));
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTO = serviceRuntime.getRuntimeDTO();
assertEquals(1, runtimeDTO.failedServletContextDTOs.length);
assertEquals(null, runtimeDTO.failedServletContextDTOs[0].name);
assertEquals(FAILURE_REASON_VALIDATION_FAILED, runtimeDTO.failedServletContextDTOs[0].failureReason);
}
use of org.osgi.service.http.runtime.dto.RuntimeDTO in project felix by apache.
the class HttpServiceRuntimeTest method dtosForSuccesfullyRegisteredListeners.
@Test
public void dtosForSuccesfullyRegisteredListeners() throws Exception {
// register a servlet context listenere as first listener
registerListener(ServletContextListener.class, true);
awaitService(ServletContextListener.class.getName());
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTOWithFirstListener = serviceRuntime.getRuntimeDTO();
assertEquals(0, runtimeDTOWithFirstListener.failedListenerDTOs.length);
ServletContextDTO contextDTO = assertDefaultContext(runtimeDTOWithFirstListener);
assertEquals(1, contextDTO.listenerDTOs.length);
assertEquals(ServletContextListener.class.getName(), contextDTO.listenerDTOs[0].types[0]);
// register all other listener types
registerListener(ServletContextAttributeListener.class, true);
registerListener(ServletRequestListener.class, true);
registerListener(ServletRequestAttributeListener.class, true);
registerListener(HttpSessionListener.class, true);
registerListener(HttpSessionAttributeListener.class, true);
awaitService(ServletContextAttributeListener.class.getName());
awaitService(ServletRequestListener.class.getName());
awaitService(ServletRequestAttributeListener.class.getName());
awaitService(HttpSessionListener.class.getName());
awaitService(HttpSessionAttributeListener.class.getName());
RuntimeDTO runtimeDTOWithAllListeners = serviceRuntime.getRuntimeDTO();
assertEquals(0, runtimeDTOWithAllListeners.failedListenerDTOs.length);
contextDTO = assertDefaultContext(runtimeDTOWithAllListeners);
assertEquals(6, contextDTO.listenerDTOs.length);
assertEquals(ServletContextListener.class.getName(), contextDTO.listenerDTOs[0].types[0]);
assertEquals(ServletContextAttributeListener.class.getName(), contextDTO.listenerDTOs[1].types[0]);
assertEquals(ServletRequestListener.class.getName(), contextDTO.listenerDTOs[2].types[0]);
assertEquals(ServletRequestAttributeListener.class.getName(), contextDTO.listenerDTOs[3].types[0]);
assertEquals(HttpSessionListener.class.getName(), contextDTO.listenerDTOs[4].types[0]);
assertEquals(HttpSessionAttributeListener.class.getName(), contextDTO.listenerDTOs[5].types[0]);
}
use of org.osgi.service.http.runtime.dto.RuntimeDTO in project felix by apache.
the class HttpServiceRuntimeTest method patternAndErrorPageSpecified.
// As specified in OSGi Compendium Release 6, Chapter 140.4.1
@Test
public void patternAndErrorPageSpecified() throws InterruptedException {
Dictionary<String, ?> properties = createDictionary(HTTP_WHITEBOARD_SERVLET_PATTERN, "/servlet", HTTP_WHITEBOARD_SERVLET_NAME, "servlet", HTTP_WHITEBOARD_SERVLET_ERROR_PAGE, asList("400"));
registrations.add(m_context.registerService(Servlet.class.getName(), new TestServlet(), properties));
awaitServiceRegistration();
HttpServiceRuntime serviceRuntime = (HttpServiceRuntime) getService(HttpServiceRuntime.class.getName());
assertNotNull("HttpServiceRuntime unavailable", serviceRuntime);
RuntimeDTO runtimeDTO = serviceRuntime.getRuntimeDTO();
ServletContextDTO defaultContext = assertDefaultContext(runtimeDTO);
assertEquals(0, runtimeDTO.failedErrorPageDTOs.length);
assertEquals(0, runtimeDTO.failedServletDTOs.length);
assertEquals(1, defaultContext.servletDTOs.length);
assertEquals(1, defaultContext.errorPageDTOs.length);
assertEquals("servlet", defaultContext.servletDTOs[0].name);
assertEquals("servlet", defaultContext.errorPageDTOs[0].name);
assertArrayEquals(new String[] { "/servlet" }, defaultContext.servletDTOs[0].patterns);
assertArrayEquals(new long[] { 400 }, defaultContext.errorPageDTOs[0].errorCodes);
}
Aggregations