felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1680331 - in /felix/trunk/http/base/src: main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java test/java/org/apache/felix/http/base/internal/registry/ServletRegistryTest.java
Date Tue, 19 May 2015 16:19:46 GMT
Author: cziegeler
Date: Tue May 19 16:19:45 2015
New Revision: 1680331

URL: http://svn.apache.org/r1680331
Log:
FELIX-4888 : ServletHandler's are not sorted by longest matching path. DTO handling (WiP)

Modified:
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
    felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/registry/ServletRegistryTest.java

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java?rev=1680331&r1=1680330&r2=1680331&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
Tue May 19 16:19:45 2015
@@ -335,7 +335,7 @@ public final class ServletRegistry
             final long serviceId = entry.getKey().getServiceId();
             for(final Map.Entry<String, Integer> map : entry.getValue().pathToStatus.entrySet())
             {
-                if ( entry.getKey().isResource() )
+                if ( !entry.getKey().isResource() )
                 {
                     ServletDTO state = (map.getValue() == -1 ? servletDTOs.get(serviceId)
: failedServletDTOs.get(serviceId));
                     if ( state == null )

Modified: felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/registry/ServletRegistryTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/registry/ServletRegistryTest.java?rev=1680331&r1=1680330&r2=1680331&view=diff
==============================================================================
--- felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/registry/ServletRegistryTest.java
(original)
+++ felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/registry/ServletRegistryTest.java
Tue May 19 16:19:45 2015
@@ -17,7 +17,10 @@
 package org.apache.felix.http.base.internal.registry;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
@@ -33,6 +36,7 @@ import org.apache.felix.http.base.intern
 import org.apache.felix.http.base.internal.handler.HttpServiceServletHandler;
 import org.apache.felix.http.base.internal.handler.ServletHandler;
 import org.apache.felix.http.base.internal.runtime.ServletInfo;
+import org.apache.felix.http.base.internal.runtime.dto.FailedDTOHolder;
 import org.junit.Test;
 import org.mockito.Matchers;
 import org.osgi.framework.Bundle;
@@ -41,17 +45,41 @@ import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.http.runtime.dto.DTOConstants;
+import org.osgi.service.http.runtime.dto.FailedServletDTO;
+import org.osgi.service.http.runtime.dto.ServletContextDTO;
 import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
 
 public class ServletRegistryTest {
 
     private final ServletRegistry reg = new ServletRegistry();
 
+    private void assertEmpty(final ServletContextDTO dto, final FailedDTOHolder holder)
+    {
+        assertNull(dto.servletDTOs);
+        assertNull(dto.resourceDTOs);
+        assertTrue(holder.failedResourceDTOs.isEmpty());
+        assertTrue(holder.failedServletDTOs.isEmpty());
+    }
+
+    private void clear(final ServletContextDTO dto, final FailedDTOHolder holder)
+    {
+        dto.servletDTOs = null;
+        dto.resourceDTOs = null;
+        holder.failedResourceDTOs.clear();
+        holder.failedServletDTOs.clear();
+    }
+
     @Test public void testSingleServlet() throws InvalidSyntaxException, ServletException
     {
+        final FailedDTOHolder holder = new FailedDTOHolder();
+        final ServletContextDTO dto = new ServletContextDTO();
+
         final Map<ServletInfo, ServletRegistry.ServletRegistrationStatus> status =
reg.getServletStatusMapping();
         // empty reg
         assertEquals(0, status.size());
+        // check DTO
+        reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
+        assertEmpty(dto, holder);
 
         // register servlet
         final ServletHandler h1 = createServletHandler(1L, 0, "/foo");
@@ -66,6 +94,17 @@ public class ServletRegistryTest {
         final int code = status.get(h1.getServletInfo()).pathToStatus.get("/foo");
         assertEquals(-1, code);
 
+        // 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);
@@ -73,13 +112,23 @@ public class ServletRegistryTest {
 
         // empty again
         assertEquals(0, status.size());
+        // check DTO
+        clear(dto, holder);
+        reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
+        assertEmpty(dto, holder);
     }
 
     @Test public void testSimpleHiding() throws InvalidSyntaxException, ServletException
     {
+        final FailedDTOHolder holder = new FailedDTOHolder();
+        final ServletContextDTO dto = new ServletContextDTO();
+
         final Map<ServletInfo, ServletRegistry.ServletRegistrationStatus> status =
reg.getServletStatusMapping();
         // empty reg
         assertEquals(0, status.size());
+        // check DTO
+        reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
+        assertEmpty(dto, holder);
 
         // register servlets
         final ServletHandler h1 = createServletHandler(1L, 10, "/foo");
@@ -106,6 +155,23 @@ public class ServletRegistryTest {
         final int code2 = status.get(h2.getServletInfo()).pathToStatus.get("/foo");
         assertEquals(DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE, code2);
 
+        // check DTO
+        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);
@@ -118,6 +184,18 @@ public class ServletRegistryTest {
         final int code3 = status.get(h2.getServletInfo()).pathToStatus.get("/foo");
         assertEquals(-1, code3);
 
+        // 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]);
+        assertEquals(2, dto.servletDTOs[0].serviceId);
+
         // remove servlet 2
         final Servlet s2 = h2.getServlet();
         reg.removeServlet(h2.getServletInfo(), true);
@@ -125,6 +203,10 @@ public class ServletRegistryTest {
 
         // empty again
         assertEquals(0, status.size());
+        // check DTO
+        clear(dto, holder);
+        reg.getRuntimeInfo(dto, holder.failedServletDTOs, holder.failedResourceDTOs);
+        assertEmpty(dto, holder);
     }
 
     private static ServletInfo createServletInfo(final long id, final int ranking, final
String... paths) throws InvalidSyntaxException



Mime
View raw message