Search in sources :

Example 26 with RuntimeDTO

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);
}
Also used : HttpServiceRuntime(org.osgi.service.http.runtime.HttpServiceRuntime) RuntimeDTO(org.osgi.service.http.runtime.dto.RuntimeDTO) Test(org.junit.Test)

Example 27 with RuntimeDTO

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);
}
Also used : HttpServiceRuntime(org.osgi.service.http.runtime.HttpServiceRuntime) ServletContextDTO(org.osgi.service.http.runtime.dto.ServletContextDTO) RuntimeDTO(org.osgi.service.http.runtime.dto.RuntimeDTO)

Example 28 with RuntimeDTO

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);
}
Also used : HttpServiceRuntime(org.osgi.service.http.runtime.HttpServiceRuntime) RuntimeDTO(org.osgi.service.http.runtime.dto.RuntimeDTO) Test(org.junit.Test)

Example 29 with RuntimeDTO

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]);
}
Also used : ServletContextAttributeListener(javax.servlet.ServletContextAttributeListener) ServletRequestAttributeListener(javax.servlet.ServletRequestAttributeListener) HttpSessionListener(javax.servlet.http.HttpSessionListener) ServletContextListener(javax.servlet.ServletContextListener) HttpServiceRuntime(org.osgi.service.http.runtime.HttpServiceRuntime) ServletContextDTO(org.osgi.service.http.runtime.dto.ServletContextDTO) ServletRequestListener(javax.servlet.ServletRequestListener) HttpSessionAttributeListener(javax.servlet.http.HttpSessionAttributeListener) RuntimeDTO(org.osgi.service.http.runtime.dto.RuntimeDTO) Test(org.junit.Test)

Example 30 with RuntimeDTO

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);
}
Also used : HttpServiceRuntime(org.osgi.service.http.runtime.HttpServiceRuntime) ServletContextDTO(org.osgi.service.http.runtime.dto.ServletContextDTO) RuntimeDTO(org.osgi.service.http.runtime.dto.RuntimeDTO) Test(org.junit.Test)

Aggregations

RuntimeDTO (org.osgi.service.http.runtime.dto.RuntimeDTO)34 HttpServiceRuntime (org.osgi.service.http.runtime.HttpServiceRuntime)31 Test (org.junit.Test)30 ServletContextDTO (org.osgi.service.http.runtime.dto.ServletContextDTO)21 CountDownLatch (java.util.concurrent.CountDownLatch)12 ServletException (javax.servlet.ServletException)5 Servlet (javax.servlet.Servlet)4 FailedServletDTO (org.osgi.service.http.runtime.dto.FailedServletDTO)4 FailedErrorPageDTO (org.osgi.service.http.runtime.dto.FailedErrorPageDTO)3 FailedServletContextDTO (org.osgi.service.http.runtime.dto.FailedServletContextDTO)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 NoSuchElementException (java.util.NoSuchElementException)2 ServletRequestListener (javax.servlet.ServletRequestListener)2 FailedFilterDTO (org.osgi.service.http.runtime.dto.FailedFilterDTO)2 FailedListenerDTO (org.osgi.service.http.runtime.dto.FailedListenerDTO)2 FailedResourceDTO (org.osgi.service.http.runtime.dto.FailedResourceDTO)2 ServletDTO (org.osgi.service.http.runtime.dto.ServletDTO)2 PrintWriter (java.io.PrintWriter)1 Collection (java.util.Collection)1