incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1519731 - in /sling/whiteboard/bdelacretaz/sling-junit-launchpad: pom.xml src/main/java/org/apache/sling/junit/launchpad/rules/SlingLaunchpadRule.java src/test/java/org/apache/sling/junit/launchpad/rules/RegisterServiceTest.java
Date Tue, 03 Sep 2013 15:55:47 GMT
Author: bdelacretaz
Date: Tue Sep  3 15:55:47 2013
New Revision: 1519731

URL: http://svn.apache.org/r1519731
Log:
sling-junit-launchpad - forgot to commit this, work in progress

Added:
    sling/whiteboard/bdelacretaz/sling-junit-launchpad/src/test/java/org/apache/sling/junit/launchpad/rules/RegisterServiceTest.java
Modified:
    sling/whiteboard/bdelacretaz/sling-junit-launchpad/pom.xml
    sling/whiteboard/bdelacretaz/sling-junit-launchpad/src/main/java/org/apache/sling/junit/launchpad/rules/SlingLaunchpadRule.java

Modified: sling/whiteboard/bdelacretaz/sling-junit-launchpad/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/sling-junit-launchpad/pom.xml?rev=1519731&r1=1519730&r2=1519731&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/sling-junit-launchpad/pom.xml (original)
+++ sling/whiteboard/bdelacretaz/sling-junit-launchpad/pom.xml Tue Sep  3 15:55:47 2013
@@ -13,6 +13,10 @@
   <name>Apache Sling Launchpad Rule for JUnit</name>
   <dependencies>
     <dependency>
+        <groupId>org.osgi</groupId>
+        <artifactId>org.osgi.core</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.apache.sling</groupId>
       <artifactId>org.apache.sling.launchpad</artifactId>
       <version>7-SNAPSHOT</version>

Modified: sling/whiteboard/bdelacretaz/sling-junit-launchpad/src/main/java/org/apache/sling/junit/launchpad/rules/SlingLaunchpadRule.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/sling-junit-launchpad/src/main/java/org/apache/sling/junit/launchpad/rules/SlingLaunchpadRule.java?rev=1519731&r1=1519730&r2=1519731&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/sling-junit-launchpad/src/main/java/org/apache/sling/junit/launchpad/rules/SlingLaunchpadRule.java
(original)
+++ sling/whiteboard/bdelacretaz/sling-junit-launchpad/src/main/java/org/apache/sling/junit/launchpad/rules/SlingLaunchpadRule.java
Tue Sep  3 15:55:47 2013
@@ -16,6 +16,10 @@
  */
 package org.apache.sling.junit.launchpad.rules;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.sling.launchpad.app.Main;
 import org.apache.sling.testing.tools.http.RequestBuilder;
@@ -23,6 +27,7 @@ import org.apache.sling.testing.tools.ht
 import org.junit.rules.ExternalResource;
 import org.junit.runner.Description;
 import org.junit.runners.model.Statement;
+import org.osgi.framework.BundleContext;
 
 public class SlingLaunchpadRule extends ExternalResource {
 
@@ -54,7 +59,19 @@ public class SlingLaunchpadRule extends 
         // TODO for now we start Sling only once per VM, should be configurable.
         // TODO cleanup remains of old Sling instances?
         if(requestBuilder == null) {
-            final String [] args = { "-p", String.valueOf(port) };
+            final String [] args = {
+                    "-p", String.valueOf(port),
+                    
+                    // bootdelegate the org.osgi packages so that we can
+                    // access the BundleContext exported by launchpad-support-bundle
+                    // from the test code which runs outside of the OSGi framework
+                    // "-D", "org.osgi.framework.bootdelegation=org.osgi.*"
+            };
+
+            
+            // TODO optionally use sling.launchpad.log.level
+            
+            // Start the Sling launchpad
             Main.main(args);
             requestExecutor = new RequestExecutor(new DefaultHttpClient());
             requestBuilder = new RequestBuilder("http://127.0.0.1:" + port);
@@ -66,6 +83,16 @@ public class SlingLaunchpadRule extends 
         // Nothing to do, Sling is stopped by a shutdown hook
     }
     
+    public BundleContext bundleContext() throws Exception {
+        final String propName = "org.apache.sling.launchpad.testsupport.BundleContext";
+        final Object o = System.getProperties().get(propName);
+        assertNotNull("Expecting " + propName + " to be set", o);
+        assertTrue("Expecting " + o + " to be a BundleContext", o instanceof BundleContext);
+        final BundleContext c = (BundleContext)o;
+        assertEquals("foo", c.getBundle().getSymbolicName());
+        return c;
+    }
+    
     public RequestBuilder builder() {
         return requestBuilder;
     }

Added: sling/whiteboard/bdelacretaz/sling-junit-launchpad/src/test/java/org/apache/sling/junit/launchpad/rules/RegisterServiceTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/sling-junit-launchpad/src/test/java/org/apache/sling/junit/launchpad/rules/RegisterServiceTest.java?rev=1519731&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/sling-junit-launchpad/src/test/java/org/apache/sling/junit/launchpad/rules/RegisterServiceTest.java
(added)
+++ sling/whiteboard/bdelacretaz/sling-junit-launchpad/src/test/java/org/apache/sling/junit/launchpad/rules/RegisterServiceTest.java
Tue Sep  3 15:55:47 2013
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.junit.launchpad.rules;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+/** Try registering a service with the embedded OSGi framework
+ *  of our Sling launchpad instance
+ */
+public class RegisterServiceTest {
+
+    @Rule
+    public final SlingLaunchpadRule sling = new SlingLaunchpadRule();
+
+    @Test
+    public void testBundleContext() throws Exception {
+        sling.bundleContext();
+    }
+    
+    @Test
+    public void testServiceRegistration() throws Exception {
+    }
+}
\ No newline at end of file



Mime
View raw message