This is an automated email from the ASF dual-hosted git repository.

cziegeler pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-resolver.git


The following commit(s) were added to refs/heads/master by this push:
     new b058246  SLING-7536 : Refactor implementation
b058246 is described below

commit b058246d7d11cbcdf9bfe2300b0a5ea891a65baf
Author: Carsten Ziegeler <czieg...@adobe.com>
AuthorDate: Wed Mar 7 15:39:30 2018 +0100

    SLING-7536 : Refactor implementation
---
 .../servlets/resolver/internal/ServletMounter.java |  5 +-
 ...etResolverTest.java => ServletMounterTest.java} | 65 +++++++---------------
 .../internal/SlingServletResolverTest.java         | 40 +------------
 3 files changed, 24 insertions(+), 86 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/servlets/resolver/internal/ServletMounter.java 
b/src/main/java/org/apache/sling/servlets/resolver/internal/ServletMounter.java
index d62b3c9..094b40b 100644
--- 
a/src/main/java/org/apache/sling/servlets/resolver/internal/ServletMounter.java
+++ 
b/src/main/java/org/apache/sling/servlets/resolver/internal/ServletMounter.java
@@ -74,9 +74,8 @@ import org.slf4j.LoggerFactory;
            service = {})
 public class ServletMounter {
 
-
     /** Logger */
-    public final Logger logger = LoggerFactory.getLogger(this.getClass());
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
     private static final String REF_SERVLET = "Servlet";
 
@@ -102,7 +101,7 @@ public class ServletMounter {
      * Activate this component.
      */
     @Activate
-    private void activate(final BundleContext context,
+    protected void activate(final BundleContext context,
             final SlingServletResolver.Config config)
     throws LoginException {
         final Collection<PendingServlet> refs;
diff --git 
a/src/test/java/org/apache/sling/servlets/resolver/internal/SlingServletResolverTest.java
 
b/src/test/java/org/apache/sling/servlets/resolver/internal/ServletMounterTest.java
similarity index 77%
copy from 
src/test/java/org/apache/sling/servlets/resolver/internal/SlingServletResolverTest.java
copy to 
src/test/java/org/apache/sling/servlets/resolver/internal/ServletMounterTest.java
index b83d7f7..223bf22 100644
--- 
a/src/test/java/org/apache/sling/servlets/resolver/internal/SlingServletResolverTest.java
+++ 
b/src/test/java/org/apache/sling/servlets/resolver/internal/ServletMounterTest.java
@@ -18,12 +18,14 @@
  */
 package org.apache.sling.servlets.resolver.internal;
 
-import static junit.framework.TestCase.assertTrue;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.Dictionary;
 import java.util.List;
 import java.util.Map;
 
@@ -42,20 +44,22 @@ import 
org.apache.sling.commons.testing.osgi.MockServiceReference;
 import org.apache.sling.commons.testing.sling.MockResource;
 import org.apache.sling.commons.testing.sling.MockResourceResolver;
 import org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest;
-import org.apache.sling.servlets.resolver.internal.resolution.ResolutionCache;
 import 
org.apache.sling.servlets.resolver.internal.resource.MockServletResource;
+import 
org.apache.sling.servlets.resolver.internal.resource.ServletResourceProvider;
+import 
org.apache.sling.servlets.resolver.internal.resource.ServletResourceProviderFactory;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
 
-public class SlingServletResolverTest {
+public class ServletMounterTest {
 
     private Servlet servlet;
 
-    private SlingServletResolver servletResolver;
+    private ServletMounter mounter;
 
     public static final String SERVLET_PATH = "/mock";
 
@@ -120,19 +124,14 @@ public class SlingServletResolverTest {
         };
 
         servlet = new MockSlingRequestHandlerServlet();
-        servletResolver = new SlingServletResolver();
+        mounter = new ServletMounter();
 
-        Class<?> resolverClass = servletResolver.getClass();
+        final Class<?> mounterClass = mounter.getClass();
 
         // set resource resolver factory
-        final Field resolverField = 
resolverClass.getDeclaredField("resourceResolverFactory");
+        final Field resolverField = 
mounterClass.getDeclaredField("resourceResolverFactory");
         resolverField.setAccessible(true);
-        resolverField.set(servletResolver, factory);
-
-        // set cache
-        final Field cacheField = 
resolverClass.getDeclaredField("resolutionCache");
-        cacheField.setAccessible(true);
-        cacheField.set(servletResolver, new ResolutionCache());
+        resolverField.set(mounter, factory);
 
         final Bundle bundle = Mockito.mock(Bundle.class);
         Mockito.when(bundle.getBundleId()).thenReturn(1L);
@@ -150,8 +149,8 @@ public class SlingServletResolverTest {
             ServletResolverConstants.SLING_SERVLET_EXTENSIONS,
             SERVLET_EXTENSION);
 
-//        servletResolver.bindServlet(SlingServletResolverTest.this.servlet, 
serviceReference);
-        servletResolver.activate(bundleContext, new 
SlingServletResolver.Config() {
+        mounter.bindServlet(ServletMounterTest.this.servlet, serviceReference);
+        mounter.activate(bundleContext, new SlingServletResolver.Config() {
 
             @Override
             public Class<? extends Annotation> annotationType() {
@@ -198,48 +197,26 @@ public class SlingServletResolverTest {
         mockResourceResolver.addChildren(parent, childRes);
     }
 
-    protected String getRequestWorkspaceName() {
-        return "fromRequest";
-    }
-
-    @Test public void testAcceptsRequest() {
-        MockSlingHttpServletRequest secureRequest = new 
MockSlingHttpServletRequest(
-            SERVLET_PATH, null, SERVLET_EXTENSION, null, null);
-        secureRequest.setResourceResolver(mockResourceResolver);
-        secureRequest.setSecure(true);
-        Servlet result = servletResolver.resolveServlet(secureRequest);
-        assertEquals("Did not resolve to correct servlet", servlet, result);
-    }
 
-    @Test public void testIgnoreRequest() {
-        MockSlingHttpServletRequest insecureRequest = new 
MockSlingHttpServletRequest(
-            SERVLET_PATH, null, SERVLET_EXTENSION, null, null);
-        insecureRequest.setResourceResolver(mockResourceResolver);
-        insecureRequest.setSecure(false);
-        Servlet result = servletResolver.resolveServlet(insecureRequest);
-        assertTrue("Did not ignore unwanted request",
-            result.getClass() != MockSlingRequestHandlerServlet.class);
-    }
-/*
     @Test public void testCreateServiceRegistrationProperties() throws 
Throwable {
         MockServiceReference msr = new MockServiceReference(null);
 
         msr.setProperty(ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES, 
"sample");
         msr.setProperty(ServletResolverConstants.SLING_SERVLET_METHODS, "GET");
 
-        Field srpf = 
SlingServletResolver.class.getDeclaredField("servletResourceProviderFactory");
+        Field srpf = 
ServletMounter.class.getDeclaredField("servletResourceProviderFactory");
         srpf.setAccessible(true);
-        ServletResourceProviderFactory factory = 
(ServletResourceProviderFactory) srpf.get(servletResolver);
+        ServletResourceProviderFactory factory = 
(ServletResourceProviderFactory) srpf.get(mounter);
 
         ServletResourceProvider servlet = factory.create(msr, null);
 
-        Method createServiceProperties = 
SlingServletResolver.class.getDeclaredMethod("createServiceProperties", 
ServiceReference.class, ServletResourceProvider.class, String.class);
+        Method createServiceProperties = 
ServletMounter.class.getDeclaredMethod("createServiceProperties", 
ServiceReference.class, ServletResourceProvider.class, String.class);
         createServiceProperties.setAccessible(true);
 
         // no ranking
         assertNull(msr.getProperty(Constants.SERVICE_RANKING));
         @SuppressWarnings("unchecked")
-        final Dictionary<String, Object> p1 = (Dictionary<String, Object>) 
createServiceProperties.invoke(servletResolver, msr, servlet, "/a");
+        final Dictionary<String, Object> p1 = (Dictionary<String, Object>) 
createServiceProperties.invoke(mounter, msr, servlet, "/a");
         assertNull(p1.get(Constants.SERVICE_RANKING));
 
         // illegal type of ranking
@@ -247,7 +224,7 @@ public class SlingServletResolverTest {
         msr.setProperty(Constants.SERVICE_RANKING, nonIntValue);
         assertEquals(nonIntValue, msr.getProperty(Constants.SERVICE_RANKING));
         @SuppressWarnings("unchecked")
-        final Dictionary<String, Object> p2 = (Dictionary<String, Object>) 
createServiceProperties.invoke(servletResolver, msr, servlet, "/a");
+        final Dictionary<String, Object> p2 = (Dictionary<String, Object>) 
createServiceProperties.invoke(mounter, msr, servlet, "/a");
         assertNull(p2.get(Constants.SERVICE_RANKING));
 
         // illegal type of ranking
@@ -255,10 +232,10 @@ public class SlingServletResolverTest {
         msr.setProperty(Constants.SERVICE_RANKING, intValue);
         assertEquals(intValue, msr.getProperty(Constants.SERVICE_RANKING));
         @SuppressWarnings("unchecked")
-        final Dictionary<String, Object> p3 = (Dictionary<String, Object>) 
createServiceProperties.invoke(servletResolver, msr, servlet, "/a");
+        final Dictionary<String, Object> p3 = (Dictionary<String, Object>) 
createServiceProperties.invoke(mounter, msr, servlet, "/a");
         assertEquals(intValue, p3.get(Constants.SERVICE_RANKING));
     }
-*/
+
     /**
      * This sample servlet will only handle secure requests.
      *
diff --git 
a/src/test/java/org/apache/sling/servlets/resolver/internal/SlingServletResolverTest.java
 
b/src/test/java/org/apache/sling/servlets/resolver/internal/SlingServletResolverTest.java
index b83d7f7..20c71b3 100644
--- 
a/src/test/java/org/apache/sling/servlets/resolver/internal/SlingServletResolverTest.java
+++ 
b/src/test/java/org/apache/sling/servlets/resolver/internal/SlingServletResolverTest.java
@@ -220,45 +220,7 @@ public class SlingServletResolverTest {
         assertTrue("Did not ignore unwanted request",
             result.getClass() != MockSlingRequestHandlerServlet.class);
     }
-/*
-    @Test public void testCreateServiceRegistrationProperties() throws 
Throwable {
-        MockServiceReference msr = new MockServiceReference(null);
-
-        msr.setProperty(ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES, 
"sample");
-        msr.setProperty(ServletResolverConstants.SLING_SERVLET_METHODS, "GET");
-
-        Field srpf = 
SlingServletResolver.class.getDeclaredField("servletResourceProviderFactory");
-        srpf.setAccessible(true);
-        ServletResourceProviderFactory factory = 
(ServletResourceProviderFactory) srpf.get(servletResolver);
-
-        ServletResourceProvider servlet = factory.create(msr, null);
-
-        Method createServiceProperties = 
SlingServletResolver.class.getDeclaredMethod("createServiceProperties", 
ServiceReference.class, ServletResourceProvider.class, String.class);
-        createServiceProperties.setAccessible(true);
-
-        // no ranking
-        assertNull(msr.getProperty(Constants.SERVICE_RANKING));
-        @SuppressWarnings("unchecked")
-        final Dictionary<String, Object> p1 = (Dictionary<String, Object>) 
createServiceProperties.invoke(servletResolver, msr, servlet, "/a");
-        assertNull(p1.get(Constants.SERVICE_RANKING));
-
-        // illegal type of ranking
-        Object nonIntValue = "Some Non Integer Value";
-        msr.setProperty(Constants.SERVICE_RANKING, nonIntValue);
-        assertEquals(nonIntValue, msr.getProperty(Constants.SERVICE_RANKING));
-        @SuppressWarnings("unchecked")
-        final Dictionary<String, Object> p2 = (Dictionary<String, Object>) 
createServiceProperties.invoke(servletResolver, msr, servlet, "/a");
-        assertNull(p2.get(Constants.SERVICE_RANKING));
-
-        // illegal type of ranking
-        Object intValue = Integer.valueOf(123);
-        msr.setProperty(Constants.SERVICE_RANKING, intValue);
-        assertEquals(intValue, msr.getProperty(Constants.SERVICE_RANKING));
-        @SuppressWarnings("unchecked")
-        final Dictionary<String, Object> p3 = (Dictionary<String, Object>) 
createServiceProperties.invoke(servletResolver, msr, servlet, "/a");
-        assertEquals(intValue, p3.get(Constants.SERVICE_RANKING));
-    }
-*/
+
     /**
      * This sample servlet will only handle secure requests.
      *

-- 
To stop receiving notification emails like this one, please contact
cziege...@apache.org.

Reply via email to