Author: olli
Date: Thu Jun 23 14:42:27 2016
New Revision: 1749906

URL: http://svn.apache.org/viewvc?rev=1749906&view=rev
Log:
SLING-5680 Add Integration Tests for Scripting Thymeleaf

use Pax Exam Options instead of Karaf Features

Modified:
    
sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/pom.xml
    
sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/test/java/org/apache/sling/scripting/thymeleaf/it/ThymeleafTestSupport.java

Modified: 
sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/pom.xml?rev=1749906&r1=1749905&r2=1749906&view=diff
==============================================================================
--- 
sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/pom.xml 
(original)
+++ 
sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/pom.xml 
Thu Jun 23 14:42:27 2016
@@ -39,7 +39,6 @@
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
     <sling.java.version>7</sling.java.version>
-    <org.apache.karaf.version>4.0.5</org.apache.karaf.version>
     <org.ops4j.pax.exam.version>4.9.1</org.ops4j.pax.exam.version>
   </properties>
 
@@ -70,19 +69,12 @@
       <version>6.0.0</version>
       <scope>provided</scope>
     </dependency>
-    <!-- Apache Karaf -->
+    <!-- Apache Felix -->
     <dependency>
-      <groupId>org.apache.karaf</groupId>
-      <artifactId>apache-karaf</artifactId>
-      <type>tar.gz</type>
-      <version>${org.apache.karaf.version}</version>
-      <scope>test</scope>
-      <exclusions>
-        <exclusion>
-          <groupId>org.apache.karaf</groupId>
-          <artifactId>org.apache.karaf.client</artifactId>
-        </exclusion>
-      </exclusions>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.framework</artifactId>
+      <version>5.4.0</version>
+      <scope>test</scope>
     </dependency>
     <!-- Apache Sling -->
     <dependency>
@@ -95,33 +87,19 @@
       <groupId>org.apache.sling</groupId>
       <artifactId>org.apache.sling.auth.core</artifactId>
       <version>1.3.12</version>
-      <scope>test</scope>
+      <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.apache.sling</groupId>
       <artifactId>org.apache.sling.engine</artifactId>
       <version>2.4.6</version>
-      <scope>test</scope>
+      <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.apache.sling</groupId>
       <artifactId>org.apache.sling.jcr.api</artifactId>
       <version>2.3.0</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.sling</groupId>
-      <artifactId>org.apache.sling.launchpad.karaf-features</artifactId>
-      <version>0.1.1-SNAPSHOT</version>
-      <type>xml</type>
-      <classifier>features</classifier>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.sling</groupId>
-      
<artifactId>org.apache.sling.launchpad.karaf-integration-tests</artifactId>
-      <version>0.1.1-SNAPSHOT</version>
-      <scope>test</scope>
+      <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.apache.sling</groupId>
@@ -135,18 +113,10 @@
       <version>0.1.7-SNAPSHOT</version>
       <scope>provided</scope>
     </dependency>
-    <!-- bnd -->
     <dependency>
-      <groupId>biz.aQute.bnd</groupId>
-      <artifactId>biz.aQute.bndlib</artifactId>
-      <version>2.4.1</version>
-      <scope>test</scope>
-    </dependency>
-    <!-- javassist -->
-    <dependency>
-      <groupId>org.javassist</groupId>
-      <artifactId>javassist</artifactId>
-      <version>3.20.0-GA</version>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.testing.paxexam</artifactId>
+      <version>0.0.1-SNAPSHOT</version>
       <scope>test</scope>
     </dependency>
     <!-- jsoup -->
@@ -182,7 +152,13 @@
     </dependency>
     <dependency>
       <groupId>org.ops4j.pax.exam</groupId>
-      <artifactId>pax-exam-container-karaf</artifactId>
+      <artifactId>pax-exam-cm</artifactId>
+      <version>${org.ops4j.pax.exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-container-forked</artifactId>
       <version>${org.ops4j.pax.exam.version}</version>
       <scope>test</scope>
     </dependency>
@@ -192,6 +168,12 @@
       <version>${org.ops4j.pax.exam.version}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-link-mvn</artifactId>
+      <version>${org.ops4j.pax.exam.version}</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>

Modified: 
sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/test/java/org/apache/sling/scripting/thymeleaf/it/ThymeleafTestSupport.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/test/java/org/apache/sling/scripting/thymeleaf/it/ThymeleafTestSupport.java?rev=1749906&r1=1749905&r2=1749906&view=diff
==============================================================================
--- 
sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/test/java/org/apache/sling/scripting/thymeleaf/it/ThymeleafTestSupport.java
 (original)
+++ 
sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/test/java/org/apache/sling/scripting/thymeleaf/it/ThymeleafTestSupport.java
 Thu Jun 23 14:42:27 2016
@@ -19,24 +19,41 @@
 package org.apache.sling.scripting.thymeleaf.it;
 
 import java.io.File;
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.Dictionary;
 
 import javax.inject.Inject;
 import javax.script.ScriptEngineFactory;
 
+import org.apache.sling.api.servlets.ServletResolver;
 import org.apache.sling.auth.core.AuthenticationSupport;
 import org.apache.sling.engine.SlingRequestProcessor;
-import org.apache.sling.launchpad.karaf.testing.KarafTestSupport;
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.OptionUtils;
 import org.ops4j.pax.exam.util.Filter;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.http.HttpService;
 import org.thymeleaf.ITemplateEngine;
 
+import static org.apache.sling.testing.paxexam.SlingOptions.slingExtensionI18n;
+import static 
org.apache.sling.testing.paxexam.SlingOptions.slingExtensionModels;
+import static org.apache.sling.testing.paxexam.SlingOptions.slingJcrOak;
+import static org.apache.sling.testing.paxexam.SlingOptions.slingLaunchpadOak;
+import static org.apache.sling.testing.paxexam.SlingOptions.slingScripting;
+import static org.apache.sling.testing.paxexam.SlingOptions.slingScriptingJsp;
 import static org.ops4j.pax.exam.CoreOptions.bundle;
+import static org.ops4j.pax.exam.CoreOptions.composite;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.keepCaches;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
-import static 
org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
+import static org.ops4j.pax.exam.CoreOptions.workingDirectory;
+import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration;
 
-public abstract class ThymeleafTestSupport extends KarafTestSupport {
+public abstract class ThymeleafTestSupport {
+
+    @Inject
+    protected ServletResolver servletResolver;
 
     @Inject
     protected SlingRequestProcessor slingRequestProcessor;
@@ -45,30 +62,78 @@ public abstract class ThymeleafTestSuppo
     protected AuthenticationSupport authenticationSupport;
 
     @Inject
+    protected HttpService httpService;
+
+    @Inject
     @Filter(value = "(names=thymeleaf)")
     protected ScriptEngineFactory scriptEngineFactory;
 
     @Inject
     protected ITemplateEngine templateEngine;
 
+    @Inject
+    protected ConfigurationAdmin configurationAdmin;
+
+    protected static synchronized int findFreePort() {
+        try {
+            final ServerSocket serverSocket = new ServerSocket(0);
+            final int port = serverSocket.getLocalPort();
+            serverSocket.close();
+            return port;
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    protected int httpPort() throws IOException {
+        final Dictionary<String, Object> properties = 
configurationAdmin.getConfiguration("org.apache.felix.http").getProperties();
+        return 
Integer.parseInt(properties.get("org.osgi.service.http.port").toString());
+    }
+
     @Configuration
     public Option[] configuration() {
+        final String workingDirectory = String.format("target/paxexam/%s", 
getClass().getSimpleName());
         final String filename = System.getProperty("bundle.filename");
         final File file = new File(filename);
-        return OptionUtils.combine(baseConfiguration(),
-            editConfigurationFilePut("etc/org.ops4j.pax.logging.cfg", 
"log4j.rootLogger", "ERROR, out, sift, osgi:*"),
+        return new Option[]{
+            keepCaches(),
+            workingDirectory(workingDirectory),
+            launchpad(workingDirectory),
+            // test app bundle
             bundle(file.toURI().toString()),
-            addSlingFeatures(
-                "sling-launchpad-oak-tar",
-                "sling-scripting",
-                "sling-extension-i18n",
-                "sling-extension-models",
-                "sling-scripting-jsp"
-            ),
+            // Thymeleaf
             
mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.scripting.thymeleaf").versionAsInProject(),
             
mavenBundle().groupId("org.javassist").artifactId("javassist").versionAsInProject(),
+            // testing
             
mavenBundle().groupId("org.jsoup").artifactId("jsoup").versionAsInProject(),
-            
mavenBundle().groupId("org.apache.servicemix.bundles").artifactId("org.apache.servicemix.bundles.hamcrest").versionAsInProject()
+            
mavenBundle().groupId("org.apache.servicemix.bundles").artifactId("org.apache.servicemix.bundles.hamcrest").versionAsInProject(),
+            junitBundles()
+        };
+    }
+
+    protected static Option launchpad(final String workingDirectory) {
+        final int httpPort = findFreePort();
+        final String slingHome = String.format("%s/sling", workingDirectory);
+        final String repositoryHome = String.format("%s/repository", 
slingHome);
+        final String localIndexDir = String.format("%s/index", repositoryHome);
+        return composite(
+            slingJcrOak(), // TODO if slingJcrOak() is called elsewhere, 
ResourceResolverFactory will not be created
+            slingLaunchpadOak(),
+            slingExtensionI18n(),
+            slingExtensionModels(),
+            slingScripting(),
+            slingScriptingJsp(),
+            newConfiguration("org.apache.felix.http")
+                .put("org.osgi.service.http.port", httpPort)
+                .asOption(),
+            
newConfiguration("org.apache.jackrabbit.oak.plugins.segment.SegmentNodeStoreService")
+                .put("repository.home", repositoryHome)
+                .put("name", "Default NodeStore")
+                .asOption(),
+            
newConfiguration("org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProviderService")
+                .put("localIndexDir", localIndexDir)
+                .asOption(),
+            
mavenBundle().groupId("org.apache.jackrabbit").artifactId("oak-segment").version("1.5.3")
         );
     }
 


Reply via email to