felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1680011 [2/2] - in /felix/trunk/http/base/src: main/java/org/apache/felix/http/base/internal/handler/ main/java/org/apache/felix/http/base/internal/registry/ main/java/org/apache/felix/http/base/internal/runtime/dto/ main/java/org/apache/f...
Date Mon, 18 May 2015 12:44:56 GMT
Modified: felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceHelper.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceHelper.java?rev=1680011&r1=1680010&r2=1680011&view=diff
==============================================================================
--- felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceHelper.java
(original)
+++ felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceHelper.java
Mon May 18 12:44:55 2015
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.when;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicLong;
 
@@ -34,28 +35,28 @@ import javax.servlet.Servlet;
 import org.apache.felix.http.base.internal.context.ExtServletContext;
 import org.apache.felix.http.base.internal.handler.HttpServiceFilterHandler;
 import org.apache.felix.http.base.internal.handler.HttpServiceServletHandler;
-import org.apache.felix.http.base.internal.runtime.dto.ErrorPageRuntime;
-import org.apache.felix.http.base.internal.runtime.dto.FilterRuntime;
-import org.apache.felix.http.base.internal.runtime.dto.ServletRuntime;
+import org.apache.felix.http.base.internal.handler.ServletHandler;
+import org.apache.felix.http.base.internal.runtime.dto.state.FilterState;
+import org.apache.felix.http.base.internal.runtime.dto.state.ServletState;
 import org.osgi.framework.ServiceReference;
 
 public final class WhiteboardServiceHelper
 {
     public static final AtomicLong ID_COUNTER = new AtomicLong();
 
-    public static FilterRuntime createTestFilterWithServiceId(String identifier,
+    public static FilterState createTestFilterWithServiceId(String identifier,
             ExtServletContext context)
     {
         return createTestFilter(identifier, context, ID_COUNTER.incrementAndGet());
     }
 
-    public static FilterRuntime createTestFilter(String identifier,
+    public static FilterState createTestFilter(String identifier,
             ExtServletContext context)
     {
         return createTestFilter(identifier, context, -ID_COUNTER.incrementAndGet());
     }
 
-    private static FilterRuntime createTestFilter(String identifier,
+    private static FilterState createTestFilter(String identifier,
             ExtServletContext context,
             Long serviceId)
     {
@@ -97,19 +98,19 @@ public final class WhiteboardServiceHelp
         return info;
     }
 
-    public static ServletRuntime createTestServletWithServiceId(String identifier,
+    public static ServletState createTestServletWithServiceId(String identifier,
             ExtServletContext context,
             long contextServiceId)
     {
         return createTestServlet(identifier, context, ID_COUNTER.incrementAndGet(), contextServiceId);
     }
 
-    public static ServletRuntime createTestServlet(String identifier, ExtServletContext context,
long contextServiceId)
+    public static ServletState createTestServlet(String identifier, ExtServletContext context,
long contextServiceId)
     {
         return createTestServlet(identifier, context, -ID_COUNTER.incrementAndGet(), contextServiceId);
     }
 
-    private static ServletRuntime createTestServlet(String identifier,
+    private static ServletState createTestServlet(String identifier,
             ExtServletContext context,
             Long serviceId,
             Long contextServiceId)
@@ -117,7 +118,35 @@ public final class WhiteboardServiceHelp
         ServletInfo servletInfo = createServletInfo(identifier, serviceId);
         Servlet servlet = mock(Servlet.class);
         when(servlet.getServletInfo()).thenReturn("info_" + identifier);
-        return new HttpServiceServletHandler(contextServiceId, context, servletInfo, servlet);
+        final ServletHandler h = new HttpServiceServletHandler(contextServiceId, context,
servletInfo, servlet);
+
+        return new ServletState() {
+
+            @Override
+            public ServletInfo getServletInfo() {
+                return h.getServletInfo();
+            }
+
+            @Override
+            public Servlet getServlet() {
+                return h.getServlet();
+            }
+
+            @Override
+            public String[] getPatterns() {
+                return h.getServletInfo().getPatterns();
+            }
+
+            @Override
+            public String[] getErrorExceptions() {
+                return null;
+            }
+
+            @Override
+            public long[] getErrorCodes() {
+                return null;
+            }
+        };
     }
 
     private static ServletInfo createServletInfo(String identifier, Long serviceId)
@@ -158,26 +187,64 @@ public final class WhiteboardServiceHelp
                 };
     }
 
-    public static ErrorPageRuntime createErrorPageWithServiceId(String identifier, ExtServletContext
context, long contextServiceId)
+    public static ServletState createErrorPageWithServiceId(String identifier, ExtServletContext
context, long contextServiceId)
     {
         return createErrorPage(identifier, context, ID_COUNTER.incrementAndGet(), contextServiceId);
     }
 
-    public static ErrorPageRuntime createErrorPage(String identifier, ExtServletContext context,
long contextServiceId)
+    public static ServletState createErrorPage(String identifier, ExtServletContext context,
long contextServiceId)
     {
         return createErrorPage(identifier, context, -ID_COUNTER.incrementAndGet(), contextServiceId);
     }
 
-    private static ErrorPageRuntime createErrorPage(String identifier,
+    private static ServletState createErrorPage(String identifier,
             ExtServletContext context,
             Long serviceId,
             long contextServiceId)
     {
-        ServletRuntime servletHandler = createTestServlet(identifier, context, serviceId,
contextServiceId);
-        Collection<Long> errorCodes = Arrays.asList(400L, 500L);
-        Collection<String> exceptions = Arrays.asList("Bad request", "Error");
-
-        return new ErrorPageRuntime(servletHandler, errorCodes, exceptions);
+        final ServletState servletHandler = createTestServlet(identifier, context, serviceId,
contextServiceId);
+        final Collection<Long> errorCodes = Arrays.asList(400L, 500L);
+        final Collection<String> exceptions = Arrays.asList("Bad request", "Error");
+
+        return new ServletState()
+        {
+
+            @Override
+            public ServletInfo getServletInfo()
+            {
+                return servletHandler.getServletInfo();
+            }
+
+            @Override
+            public Servlet getServlet()
+            {
+                return servletHandler.getServlet();
+            }
+
+            @Override
+            public String[] getPatterns()
+            {
+                return servletHandler.getPatterns();
+            }
+
+            @Override
+            public String[] getErrorExceptions()
+            {
+                return exceptions.toArray(new String[1]);
+            }
+
+            @Override
+            public long[] getErrorCodes()
+            {
+                final long[] codes = new long[errorCodes.size()];
+                final Iterator<Long> iter = errorCodes.iterator();
+                for(int i=0; i<codes.length; i++)
+                {
+                    codes[i] = iter.next();
+                }
+                return codes;
+            }
+        };
     }
 
     public static ServletContextHelperInfo createContextInfo(int serviceRanking,

Modified: felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilderTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilderTest.java?rev=1680011&r1=1680010&r2=1680011&view=diff
==============================================================================
--- felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilderTest.java
(original)
+++ felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/runtime/dto/RuntimeDTOBuilderTest.java
Mon May 18 12:44:55 2015
@@ -58,10 +58,13 @@ import javax.servlet.ServletContext;
 import org.apache.felix.http.base.internal.context.ExtServletContext;
 import org.apache.felix.http.base.internal.handler.HttpServiceFilterHandler;
 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.AbstractInfo;
 import org.apache.felix.http.base.internal.runtime.FilterInfo;
 import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
 import org.apache.felix.http.base.internal.runtime.ServletInfo;
+import org.apache.felix.http.base.internal.runtime.dto.state.FilterState;
+import org.apache.felix.http.base.internal.runtime.dto.state.ServletState;
 import org.apache.felix.http.base.internal.whiteboard.ContextHandler;
 import org.apache.felix.http.base.internal.whiteboard.PerContextEventListener;
 import org.junit.Before;
@@ -181,7 +184,9 @@ public class RuntimeDTOBuilderTest
         sharedContext.setAttribute("stringAttr", "one");
         sharedContext.setAttribute("dtoAttr", testDTO);
 
-        return contextHandler;
+        // TODO
+        return null;
+//        return contextHandler;
     }
 
     private Map<String, String> createInitParameterMap()
@@ -223,10 +228,12 @@ public class RuntimeDTOBuilderTest
             Map<Long, Collection<ServiceReference<?>>> listenerRuntimes,
             FailureRuntime failures)
     {
+        /** TODO
         registry = new RegistryRuntime(contexts,
             contextRuntimes,
             listenerRuntimes,
             failures);
+            */
     }
 
     @Test
@@ -236,30 +243,30 @@ public class RuntimeDTOBuilderTest
         ServletContextHelperRuntime contextHelper_A = setupContext(context_A, "A", ID_A);
         ServletContextHelperRuntime contextHelper_B = setupContext(context_B, "B", ID_B);
 
-        List<ServletRuntime> servlets = new ArrayList<ServletRuntime>();
-        List<ServletRuntime> resources = new ArrayList<ServletRuntime>();
+        List<ServletState> servlets = new ArrayList<ServletState>();
+        List<ServletState> resources = new ArrayList<ServletState>();
 
         servlets.add(createTestServlet("1", context_0, ID_0));
         resources.add(createTestServlet("1", context_0, ID_0));
-        List<FilterRuntime> filters_0 = asList(createTestFilter("1", context_0));
-        List<ErrorPageRuntime> errorPages_0 = asList(createErrorPage("E_1", context_0,
ID_0));
-        ContextRuntime contextRuntime_0 = new ContextRuntime(filters_0, errorPages_0, null,
null, ID_0);
+        List<FilterState> filters_0 = asList(createTestFilter("1", context_0));
+        List<ServletState> errorPages_0 = asList(createErrorPage("E_1", context_0,
ID_0));
+        ContextRuntime contextRuntime_0 = new ContextRuntime(filters_0, errorPages_0, null,
null, null, null, null, null);
 
         servlets.add(createTestServlet("A_1", context_A, ID_A));
         resources.add(createTestServlet("A_1", context_A, ID_A));
-        List<FilterRuntime> filters_A = asList(createTestFilter("A_1", context_A));
-        List<ErrorPageRuntime> errorPages_A = asList(createErrorPage("E_A_1", context_A,
ID_A));
-        ContextRuntime contextRuntime_A = new ContextRuntime(filters_A, errorPages_A, null,
null, ID_A);
+        List<FilterState> filters_A = asList(createTestFilter("A_1", context_A));
+        List<ServletState> errorPages_A = asList(createErrorPage("E_A_1", context_A,
ID_A));
+        ContextRuntime contextRuntime_A = new ContextRuntime(filters_A, errorPages_A, null,
null, null, null, null, null);
 
         servlets.addAll(asList(createTestServletWithServiceId("B_1", context_B, ID_B),
                 createTestServletWithServiceId("B_2", context_B, ID_B)));
         resources.addAll(asList(createTestServletWithServiceId("B_1", context_B, ID_B),
             createTestServletWithServiceId("B_2", context_B, ID_B)));
-        List<FilterRuntime> filters_B = asList(createTestFilterWithServiceId("B_1",
context_B),
+        List<FilterState> filters_B = asList(createTestFilterWithServiceId("B_1", context_B),
                 createTestFilterWithServiceId("B_2", context_B));
-        List<ErrorPageRuntime> errorPages_B = asList(createErrorPageWithServiceId("E_B_1",
context_B, ID_B),
+        List<ServletState> errorPages_B = asList(createErrorPageWithServiceId("E_B_1",
context_B, ID_B),
                 createErrorPageWithServiceId("E_B_2", context_B, ID_B));
-        ContextRuntime contextRuntime_B = new ContextRuntime(filters_B, errorPages_B, null,
null, ID_B);
+        ContextRuntime contextRuntime_B = new ContextRuntime(filters_B, errorPages_B, null,
null, null, null, null, null);
 
         Map<Long, Collection<ServiceReference<?>>> listenerRuntimes = setupListeners();
 
@@ -584,7 +591,7 @@ public class RuntimeDTOBuilderTest
                 true,
                 Collections.<String, String>emptyMap());
         Servlet servlet = mock(Servlet.class);
-        ServletRuntime servletHandler = new HttpServiceServletHandler(0, context_0, servletInfo,
servlet);
+        ServletHandler servletHandler = new HttpServiceServletHandler(0, context_0, servletInfo,
servlet);
         when(servlet.getServletInfo()).thenReturn("info_0");
 
         FilterInfo filterInfo = createFilterInfo(0,
@@ -596,7 +603,7 @@ public class RuntimeDTOBuilderTest
                 true,
                 null,
                 Collections.<String, String>emptyMap());
-        FilterRuntime filterHandler = new HttpServiceFilterHandler(0, context_0, filterInfo,
mock(Filter.class));
+        FilterState filterHandler = new HttpServiceFilterHandler(0, context_0, filterInfo,
mock(Filter.class));
 
         ServletInfo resourceInfo = createServletInfo(0,
                 ID_COUNTER.incrementAndGet(),
@@ -606,12 +613,12 @@ public class RuntimeDTOBuilderTest
                 true,
                 Collections.<String, String>emptyMap());
         Servlet resource = mock(Servlet.class);
-        ServletRuntime resourceHandler = new HttpServiceServletHandler(ID_0, context_0, resourceInfo,
resource);
+        ServletHandler resourceHandler = new HttpServiceServletHandler(ID_0, context_0, resourceInfo,
resource);
 
         ContextRuntime contextRuntime = new ContextRuntime(asList(filterHandler),
-                Collections.<ErrorPageRuntime>emptyList(),
+                Collections.<ServletState>emptyList(),
                 null, null,
-                ID_0);
+                null, null, null, null);
         setupRegistry(asList(contextHandler), asList(contextRuntime),
 //                new ServletRegistryRuntime(asList(resourceHandler), asList(servletHandler)),
                 Collections.<Long, Collection<ServiceReference<?>>>emptyMap(),
@@ -635,8 +642,9 @@ public class RuntimeDTOBuilderTest
         ServletContextHelperRuntime contextHandler_0 = setupContext(context_0, "0", ID_0);
         ServletContextHelperRuntime contextHandler_A = setupContext(context_A, "A", ID_A);
 
+        // TODO
         setupRegistry(asList(contextHandler_0, contextHandler_A),
-                asList(ContextRuntime.empty(ID_0), ContextRuntime.empty(ID_A)),
+null, //                asList(ContextRuntime.empty(ID_0), ContextRuntime.empty(ID_A)),
                 Collections.<Long, Collection<ServiceReference<?>>>emptyMap(),
                 FailureRuntime.empty());
 
@@ -665,13 +673,13 @@ public class RuntimeDTOBuilderTest
                 true,
                 Collections.<String, String>emptyMap());
         Servlet servlet = mock(Servlet.class);
-        ServletRuntime servletHandler = new HttpServiceServletHandler(ID_0, context_0, servletInfo,
servlet);
+        ServletHandler servletHandler = new HttpServiceServletHandler(ID_0, context_0, servletInfo,
servlet);
         when(servlet.getServletInfo()).thenReturn("info_0");
 
-        ContextRuntime contextRuntime = new ContextRuntime(Collections.<FilterRuntime>emptyList(),
-                Collections.<ErrorPageRuntime>emptyList(),
+        ContextRuntime contextRuntime = new ContextRuntime(Collections.<FilterState>emptyList(),
+                Collections.<ServletState>emptyList(),
                 null, null,
-                ID_0);
+                null, null, null, null);
         setupRegistry(asList(contextHandler), asList(contextRuntime),
 //                new ServletRegistryRuntime(asList(servletHandler), Collections.<ServletRuntime>emptyList()),
                 Collections.<Long, Collection<ServiceReference<?>>>emptyMap(),



Mime
View raw message