You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2015/01/29 11:21:04 UTC

svn commit: r1655576 [2/2] - in /felix/sandbox/http-rfc189/whiteboard/src: main/java/org/apache/felix/http/whiteboard/ main/java/org/apache/felix/http/whiteboard/internal/ main/java/org/apache/felix/http/whiteboard/internal/manager/ main/java/org/apach...

Modified: felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManagerTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManagerTest.java?rev=1655576&r1=1655575&r2=1655576&view=diff
==============================================================================
--- felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManagerTest.java (original)
+++ felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManagerTest.java Thu Jan 29 10:21:03 2015
@@ -18,8 +18,6 @@
  */
 package org.apache.felix.http.whiteboard.internal.manager;
 
-import static org.mockito.Mockito.when;
-
 import java.lang.reflect.Method;
 import java.util.Collection;
 import java.util.Map;
@@ -27,7 +25,6 @@ import java.util.Set;
 
 import junit.framework.TestCase;
 
-import org.apache.felix.http.api.ServletInfo;
 import org.apache.felix.http.whiteboard.internal.manager.HttpContextManager.HttpContextHolder;
 import org.junit.Before;
 import org.junit.Test;
@@ -37,21 +34,28 @@ import org.mockito.runners.MockitoJUnitR
 import org.osgi.framework.Bundle;
 import org.osgi.service.http.HttpContext;
 
+import static org.mockito.Mockito.*;
+
 @RunWith(MockitoJUnitRunner.class)
 public class HttpContextManagerTest
 {
+
     private static final String SAMPLE_CONTEXT_ID = "some.context.id";
 
     private static final long BUNDLE_1_ID = 1L;
+
     private static final String BUNDLE_1_ALIAS = "/bundle1";
 
     private static final long BUNDLE_2_ID = 2L;
+
     private static final String BUNDLE_2_ALIAS = "/bundle2";
 
     @Mock
     private HttpContext sampleContext;
+
     @Mock
     private Bundle bundle1;
+
     @Mock
     private Bundle bundle2;
 
@@ -71,9 +75,7 @@ public class HttpContextManagerTest
         TestCase.assertSame(sampleContext, h1.getContext());
         TestCase.assertTrue(h1.getMappings().isEmpty());
 
-        ServletInfo servletInfo = new ServletInfo();
-
-        ServletMapping sm = new ServletMapping(bundle1, null, servletInfo);
+        ServletMapping sm = new ServletMapping(bundle1, null, "");
         h1.addMapping(sm);
         TestCase.assertSame(sampleContext, sm.getContext());
         TestCase.assertEquals(1, h1.getMappings().size());
@@ -136,10 +138,7 @@ public class HttpContextManagerTest
         hcm.addHttpContext(bundle1, SAMPLE_CONTEXT_ID, sampleContext);
 
         // Servlet 1 gets the context
-        ServletInfo servletInfo = new ServletInfo();
-        servletInfo.patterns = new String[] { BUNDLE_1_ALIAS };
-
-        final ServletMapping bundle1Servlet = new ServletMapping(bundle1, null, servletInfo);
+        final ServletMapping bundle1Servlet = new ServletMapping(bundle1, null, BUNDLE_1_ALIAS);
         HttpContext ctx1 = hcm.getHttpContext(bundle1, SAMPLE_CONTEXT_ID, bundle1Servlet);
         TestCase.assertNotNull(ctx1);
         TestCase.assertSame(ctx1, bundle1Servlet.getContext());
@@ -178,10 +177,7 @@ public class HttpContextManagerTest
         hcm.addHttpContext(bundle1, SAMPLE_CONTEXT_ID, sampleContext);
 
         // Servlet 2 is an orphan
-        ServletInfo servletInfo = new ServletInfo();
-        servletInfo.patterns = new String[] { BUNDLE_2_ALIAS };
-
-        final ServletMapping bundle2Servlet = new ServletMapping(bundle2, null, servletInfo);
+        final ServletMapping bundle2Servlet = new ServletMapping(bundle2, null, BUNDLE_2_ALIAS);
         HttpContext ctx2 = hcm.getHttpContext(bundle2, SAMPLE_CONTEXT_ID, bundle2Servlet);
         TestCase.assertNull(ctx2);
         TestCase.assertNull(bundle2Servlet.getContext());
@@ -221,10 +217,7 @@ public class HttpContextManagerTest
         hcm.addHttpContext(null, SAMPLE_CONTEXT_ID, sampleContext);
 
         // Servlet 1 gets the context
-        ServletInfo servletInfo = new ServletInfo();
-        servletInfo.patterns = new String[] { BUNDLE_1_ALIAS };
-
-        final ServletMapping bundle1Servlet = new ServletMapping(bundle1, null, servletInfo);
+        final ServletMapping bundle1Servlet = new ServletMapping(bundle1, null, BUNDLE_1_ALIAS);
         HttpContext ctx1 = hcm.getHttpContext(bundle1, SAMPLE_CONTEXT_ID, bundle1Servlet);
         TestCase.assertNotNull(ctx1);
         TestCase.assertSame(ctx1, bundle1Servlet.getContext());
@@ -241,10 +234,7 @@ public class HttpContextManagerTest
         TestCase.assertTrue(hcm.getOrphanMappings().isEmpty());
 
         // Servlet 2 gets the context
-        servletInfo = new ServletInfo();
-        servletInfo.patterns = new String[] { BUNDLE_2_ALIAS };
-
-        final ServletMapping bundle2Servlet = new ServletMapping(bundle2, null, servletInfo);
+        final ServletMapping bundle2Servlet = new ServletMapping(bundle2, null, BUNDLE_2_ALIAS);
         HttpContext ctx2 = hcm.getHttpContext(bundle2, SAMPLE_CONTEXT_ID, bundle2Servlet);
         TestCase.assertNotNull(ctx2);
         TestCase.assertSame(ctx2, bundle2Servlet.getContext());
@@ -325,16 +315,11 @@ public class HttpContextManagerTest
 
     static String createId(Bundle bundle, String contextId)
     {
-        return createId(bundle, contextId, false);
-    }
-
-    static String createId(Bundle bundle, String contextId, boolean isContextHelper)
-    {
         try
         {
-            Method m = HttpContextManager.class.getDeclaredMethod("createId", Bundle.class, String.class, Boolean.TYPE);
+            Method m = HttpContextManager.class.getDeclaredMethod("createId", Bundle.class, String.class);
             m.setAccessible(true);
-            return (String) m.invoke(null, bundle, contextId, isContextHelper);
+            return (String) m.invoke(null, bundle, contextId);
         }
         catch (Throwable t)
         {

Propchange: felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManagerTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/ServletMappingTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/ServletMappingTest.java?rev=1655576&r1=1655575&r2=1655576&view=diff
==============================================================================
--- felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/ServletMappingTest.java (original)
+++ felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/ServletMappingTest.java Thu Jan 29 10:21:03 2015
@@ -19,9 +19,9 @@
 package org.apache.felix.http.whiteboard.internal.manager;
 
 import static org.mockito.Mockito.when;
+
 import junit.framework.TestCase;
 
-import org.apache.felix.http.api.ServletInfo;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -34,15 +34,22 @@ import org.osgi.service.http.HttpContext
 @RunWith(MockitoJUnitRunner.class)
 public class ServletMappingTest
 {
+
+    private static final String SAMPLE_CONTEXT_ID = "some.context.id";
+
     private static final long BUNDLE_ID = 1L;
+
     private static final String SERVLET_ALIAS = "/bundle";
 
     @Mock
     private HttpContext sampleContext;
+
     @Mock
     private Bundle bundle;
+
     @Mock
     private ExtenderManagerTest.ExtServlet servlet;
+
     private ExtenderManagerTest.MockExtHttpService httpService;
 
     @Before
@@ -60,15 +67,12 @@ public class ServletMappingTest
     }
 
     @Test
-    public void test_with_context() throws Exception
+    public void test_with_context()
     {
-        ServletInfo servletInfo = new ServletInfo();
-        servletInfo.context = sampleContext;
-        servletInfo.patterns = new String[] { SERVLET_ALIAS };
-
-        ServletMapping sm = new ServletMapping(bundle, servlet, servletInfo);
+        ServletMapping sm = new ServletMapping(bundle, servlet, SERVLET_ALIAS);
         TestCase.assertSame(bundle, sm.getBundle());
         TestCase.assertSame(servlet, sm.getServlet());
+        TestCase.assertEquals(SERVLET_ALIAS, sm.getAlias());
 
         TestCase.assertNull(sm.getContext());
         TestCase.assertNotNull(sm.getInitParams());
@@ -99,13 +103,12 @@ public class ServletMappingTest
     }
 
     @Test
-    public void test_context_delayed() throws Exception
+    public void test_context_delayed()
     {
-        ServletInfo servletInfo = new ServletInfo();
-        servletInfo.context = sampleContext;
-        servletInfo.patterns = new String[] { SERVLET_ALIAS };
-
-        ServletMapping sm = new ServletMapping(bundle, servlet, servletInfo);
+        ServletMapping sm = new ServletMapping(bundle, servlet, SERVLET_ALIAS);
+        TestCase.assertSame(bundle, sm.getBundle());
+        TestCase.assertSame(servlet, sm.getServlet());
+        TestCase.assertEquals(SERVLET_ALIAS, sm.getAlias());
 
         TestCase.assertNull(sm.getContext());
         TestCase.assertNotNull(sm.getInitParams());
@@ -129,13 +132,12 @@ public class ServletMappingTest
     }
 
     @Test
-    public void test_unset_context() throws Exception
+    public void test_unset_context()
     {
-        ServletInfo servletInfo = new ServletInfo();
-        servletInfo.context = sampleContext;
-        servletInfo.patterns = new String[] { SERVLET_ALIAS };
-
-        ServletMapping sm = new ServletMapping(bundle, servlet, servletInfo);
+        ServletMapping sm = new ServletMapping(bundle, servlet, SERVLET_ALIAS);
+        TestCase.assertSame(bundle, sm.getBundle());
+        TestCase.assertSame(servlet, sm.getServlet());
+        TestCase.assertEquals(SERVLET_ALIAS, sm.getAlias());
 
         TestCase.assertNull(sm.getContext());
         TestCase.assertNotNull(sm.getInitParams());

Propchange: felix/sandbox/http-rfc189/whiteboard/src/test/java/org/apache/felix/http/whiteboard/internal/manager/ServletMappingTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain