incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r881358 - in /sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/sling: AdapterManagerTestHelper.java SlingTestHelper.java
Date Tue, 17 Nov 2009 16:26:26 GMT
Author: cziegeler
Date: Tue Nov 17 16:26:26 2009
New Revision: 881358

URL: http://svn.apache.org/viewvc?rev=881358&view=rev
Log:
SLING-1166 : Use reflection for adapter manager.

Modified:
    sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/sling/AdapterManagerTestHelper.java
    sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/sling/SlingTestHelper.java

Modified: sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/sling/AdapterManagerTestHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/sling/AdapterManagerTestHelper.java?rev=881358&r1=881357&r2=881358&view=diff
==============================================================================
--- sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/sling/AdapterManagerTestHelper.java
(original)
+++ sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/sling/AdapterManagerTestHelper.java
Tue Nov 17 16:26:26 2009
@@ -29,6 +29,7 @@
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.ComponentContext;
 
 
 /**
@@ -50,7 +51,9 @@
             adapterMgr = new AdapterManagerImpl();
 
             mockContext = new MockComponentContext(new MockBundle(14));
-            adapterMgr.activate(mockContext);
+            try {
+                adapterMgr.getClass().getMethod("activate", ComponentContext.class).invoke(adapterMgr,
mockContext);
+            } catch (Exception ignore ) {}
         }
     }
 
@@ -64,7 +67,9 @@
         ref.setProperty(Constants.SERVICE_ID, 1L);
         ref.setProperty(AdapterFactory.ADAPTABLE_CLASSES, adaptableClasses);
         ref.setProperty(AdapterFactory.ADAPTER_CLASSES, adapterClasses);
-        adapterMgr.bindAdapterFactory(ref);
+        try {
+            adapterMgr.getClass().getMethod("bindAdapterFactory", ServiceReference.class).invoke(adapterMgr,
ref);
+        } catch (Exception ignore ) {}
 
         registeredFactories.add(ref);
     }
@@ -72,7 +77,9 @@
     public static void resetAdapterFactories() {
         if (adapterMgr != null) {
             for (ServiceReference ref : registeredFactories) {
-                adapterMgr.unbindAdapterFactory(ref);
+                try {
+                    adapterMgr.getClass().getMethod("unbindAdapterFactory", ServiceReference.class).invoke(adapterMgr,
ref);
+                } catch (Exception ignore ) {}
             }
         }
     }

Modified: sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/sling/SlingTestHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/sling/SlingTestHelper.java?rev=881358&r1=881357&r2=881358&view=diff
==============================================================================
--- sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/sling/SlingTestHelper.java
(original)
+++ sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/sling/SlingTestHelper.java
Tue Nov 17 16:26:26 2009
@@ -16,10 +16,9 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.commons.testing;
+package org.apache.sling.commons.testing.sling;
 
 import java.io.IOException;
-import java.lang.reflect.Field;
 
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
@@ -28,51 +27,17 @@
 import javax.jcr.Session;
 
 import org.apache.sling.api.adapter.AdapterFactory;
-import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.commons.testing.sling.AdapterManagerTestHelper;
-import org.apache.sling.jcr.api.SlingRepository;
-import org.apache.sling.jcr.resource.JcrResourceResolverFactory;
-import org.apache.sling.jcr.resource.internal.JcrResourceResolverFactoryImpl;
-import org.apache.sling.jcr.resource.internal.helper.Mapping;
 
 /**
  * <code>SlingTestHelper</code> provides various helper methods for accessing
  * standard sling features in a test environment without the OSGi service framework
  * available. This includes:
- * 
- * - access to a {@link JcrResourceResolverFactory} and a jcr-based {@link ResourceResolver}
+ *
  * - register standard sling node types
  * - simple adaptable manager implementation (requires {@link AdapterManagerTestHelper})
  */
 public class SlingTestHelper {
-    
-    public static JcrResourceResolverFactory 
-            getJcrResourceResolverFactory(SlingRepository repository) throws Exception {
-        
-        JcrResourceResolverFactoryImpl resFac = new JcrResourceResolverFactoryImpl();
-
-        // set all fields that are normally resolved by OSGi SCR via reflection
-        
-        Field repoField = resFac.getClass().getDeclaredField("repository");
-        repoField.setAccessible(true);
-        repoField.set(resFac, repository);
-
-        Field mappingsField = resFac.getClass().getDeclaredField("mappings");
-        mappingsField.setAccessible(true);
-        mappingsField.set(resFac, new Mapping[] { Mapping.DIRECT });
-
-        Field searchPathField = resFac.getClass().getDeclaredField("searchPath");
-        searchPathField.setAccessible(true);
-        searchPathField.set(resFac, new String[] { "/apps", "/libs" });
-
-        return resFac;
-    }
-
-    public static ResourceResolver getResourceResolver(SlingRepository repository, Session
session) throws Exception {
-        JcrResourceResolverFactory factory = getJcrResourceResolverFactory(repository);
-        return factory.getResourceResolver(session);
-    }
-    
+
     public static void registerSlingNodeTypes(Session adminSession) throws IOException, RepositoryException
{
         Class<SlingTestHelper> clazz = SlingTestHelper.class;
         org.apache.sling.commons.testing.jcr.RepositoryUtil.registerNodeType(adminSession,
@@ -82,12 +47,12 @@
         org.apache.sling.commons.testing.jcr.RepositoryUtil.registerNodeType(adminSession,
                 clazz.getResourceAsStream("/SLING-INF/nodetypes/vanitypath.cnd"));
     }
-    
+
     public static void registerAdapterFactory(AdapterFactory adapterFactory,
             String[] adaptableClasses, String[] adapterClasses) {
         AdapterManagerTestHelper.registerAdapterFactory(adapterFactory, adaptableClasses,
adapterClasses);
     }
-    
+
     public static void resetAdapterFactories() {
         AdapterManagerTestHelper.resetAdapterFactories();
     }
@@ -95,15 +60,15 @@
     public static void printJCR(Session session) throws RepositoryException {
         printJCR(session.getRootNode(), new String[] {});
     }
-    
+
     public static void printJCR(Node node) throws RepositoryException {
         printJCR(node, new String[] {});
     }
-    
+
     public static void printJCR(Session session, String path, String... props) throws RepositoryException
{
         printJCR((Node) session.getItem(path), props);
     }
-    
+
     public static void printJCR(Node node, String... props) throws RepositoryException {
         System.out.println(node.getPath());
         if (props != null) {
@@ -122,5 +87,5 @@
             }
         }
     }
-    
+
 }



Mime
View raw message