Author: olli
Date: Thu Jul  7 13:48:22 2016
New Revision: 1751792

URL: http://svn.apache.org/viewvc?rev=1751792&view=rev
Log:
SLING-5692 Add Integration Tests for Scripting FreeMarker

merge module org.apache.sling.scripting.freemarker.it into 
org.apache.sling.scripting.freemarker

Added:
    
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/
    
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/app/
    
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/app/Page.java
    
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/
    
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/AdaptToModelIT.java
    
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerScriptEngineFactoryIT.java
    
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerTestSupport.java
    
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/SimpleIT.java
    sling/trunk/contrib/scripting/freemarker/src/test/resources/
    sling/trunk/contrib/scripting/freemarker/src/test/resources/apps/
    sling/trunk/contrib/scripting/freemarker/src/test/resources/apps/freemarker/
    
sling/trunk/contrib/scripting/freemarker/src/test/resources/apps/freemarker/page/
    
sling/trunk/contrib/scripting/freemarker/src/test/resources/apps/freemarker/page/adaptto/
    
sling/trunk/contrib/scripting/freemarker/src/test/resources/apps/freemarker/page/adaptto/html.ftl
    
sling/trunk/contrib/scripting/freemarker/src/test/resources/apps/freemarker/page/simple/
    
sling/trunk/contrib/scripting/freemarker/src/test/resources/apps/freemarker/page/simple/html.ftl
    sling/trunk/contrib/scripting/freemarker/src/test/resources/content/
    
sling/trunk/contrib/scripting/freemarker/src/test/resources/content/freemarker.json
Removed:
    sling/trunk/contrib/scripting/org.apache.sling.scripting.freemarker.it/
Modified:
    sling/trunk/contrib/pom.xml
    sling/trunk/contrib/scripting/freemarker/pom.xml

Modified: sling/trunk/contrib/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/pom.xml?rev=1751792&r1=1751791&r2=1751792&view=diff
==============================================================================
--- sling/trunk/contrib/pom.xml (original)
+++ sling/trunk/contrib/pom.xml Thu Jul  7 13:48:22 2016
@@ -136,7 +136,6 @@
 
           <module>scripting/script-console</module>
           <module>scripting/jsp-taglib-atom</module>
-          <module>scripting/freemarker</module>
           <module>scripting/groovy</module>
           <module>scripting/java</module>
           <module>scripting/jst</module>
@@ -146,7 +145,6 @@
           <module>scripting/scala/config</module>
           <module>scripting/scala/samples/hello-world</module>
           <module>scripting/scala/samples/forum</module>
-          <module>scripting/org.apache.sling.scripting.freemarker.it</module>
           <module>scripting/velocity</module>
           <module>scripting/xproc</module>
 
@@ -162,6 +160,7 @@
           <jdk>[1.8,)</jdk>
         </activation>
         <modules>
+          <module>scripting/freemarker</module>
           <module>scripting/org.apache.sling.scripting.thymeleaf</module>
         </modules>
       </profile>

Modified: sling/trunk/contrib/scripting/freemarker/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/freemarker/pom.xml?rev=1751792&r1=1751791&r2=1751792&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/freemarker/pom.xml (original)
+++ sling/trunk/contrib/scripting/freemarker/pom.xml Thu Jul  7 13:48:22 2016
@@ -38,7 +38,8 @@
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
-    <sling.java.version>7</sling.java.version>
+    <sling.java.version>8</sling.java.version>
+    <org.ops4j.pax.exam.version>4.9.1</org.ops4j.pax.exam.version>
   </properties>
 
   <scm>
@@ -50,8 +51,9 @@
   <build>
     <plugins>
       <plugin>
-        <groupId>org.apache.felix</groupId>
-        <artifactId>maven-scr-plugin</artifactId>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>3.3</version>
       </plugin>
       <plugin>
         <groupId>org.apache.felix</groupId>
@@ -94,6 +96,39 @@
           </instructions>
         </configuration>
       </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-failsafe-plugin</artifactId>
+        <version>2.18.1</version>
+        <executions>
+          <execution>
+            <goals>
+              <goal>integration-test</goal>
+              <goal>verify</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <systemProperties>
+            <property>
+              <name>bundle.filename</name>
+              <value>${basedir}/target/${project.build.finalName}.jar</value>
+            </property>
+          </systemProperties>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.servicemix.tooling</groupId>
+        <artifactId>depends-maven-plugin</artifactId>
+        <version>1.2</version>
+        <executions>
+          <execution>
+            <goals>
+              <goal>generate-depends-file</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
     </plugins>
   </build>
 
@@ -113,13 +148,19 @@
   </reporting>
 
   <dependencies>
-    <!-- OSGi -->
+    <!-- javax -->
     <dependency>
-      <groupId>org.osgi</groupId>
-      <artifactId>osgi.core</artifactId>
-      <version>6.0.0</version>
+      <groupId>javax.inject</groupId>
+      <artifactId>javax.inject</artifactId>
+      <version>1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
       <scope>provided</scope>
     </dependency>
+    <!-- OSGi -->
     <dependency>
       <groupId>org.osgi</groupId>
       <artifactId>osgi.annotation</artifactId>
@@ -128,6 +169,18 @@
     </dependency>
     <dependency>
       <groupId>org.osgi</groupId>
+      <artifactId>osgi.cmpn</artifactId>
+      <version>6.0.0</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>osgi.core</artifactId>
+      <version>6.0.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
       <artifactId>org.osgi.service.component.annotations</artifactId>
       <version>1.3.0</version>
       <scope>provided</scope>
@@ -138,35 +191,129 @@
       <version>1.3.0</version>
       <scope>provided</scope>
     </dependency>
+    <!-- Apache Felix -->
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.framework</artifactId>
+      <version>5.4.0</version>
+      <scope>test</scope>
+    </dependency>
     <!-- Apache Sling -->
     <dependency>
       <groupId>org.apache.sling</groupId>
       <artifactId>org.apache.sling.api</artifactId>
-      <version>2.0.8</version>
+      <version>2.11.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.auth.core</artifactId>
+      <version>1.3.12</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.engine</artifactId>
+      <version>2.4.6</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.i18n</artifactId>
+      <version>2.4.6</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.models.api</artifactId>
+      <version>1.2.2</version>
+      <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>org.apache.sling</groupId>
       <artifactId>org.apache.sling.scripting.api</artifactId>
-      <version>2.1.4</version>
+      <version>2.1.8</version>
+      <scope>provided</scope>
     </dependency>
     <dependency>
-      <groupId>javax.servlet</groupId>
-      <artifactId>servlet-api</artifactId>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.scripting.core</artifactId>
+      <version>2.0.36</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.testing.paxexam</artifactId>
+      <version>0.0.1-SNAPSHOT</version>
+      <scope>provided</scope>
     </dependency>
+    <!-- FreeMarker -->
     <dependency>
       <groupId>org.freemarker</groupId>
       <artifactId>freemarker</artifactId>
       <version>2.3.24-incubating</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicemix.specs</groupId>
+      <artifactId>org.apache.servicemix.specs.jaxp-api-1.4</artifactId>
+      <version>2.7.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <!-- jsoup -->
+    <dependency>
+      <groupId>org.jsoup</groupId>
+      <artifactId>jsoup</artifactId>
+      <version>1.9.1</version>
+      <scope>test</scope>
     </dependency>
+    <!-- logging -->
     <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
+      <version>1.7.21</version>
+      <scope>provided</scope>
     </dependency>
-    <!-- Testing -->
+    <!-- testing -->
     <dependency>
-      <groupId>org.apache.sling</groupId>
-      <artifactId>org.apache.sling.commons.testing</artifactId>
-      <version>2.0.6</version>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.servicemix.bundles</groupId>
+      <artifactId>org.apache.servicemix.bundles.hamcrest</artifactId>
+      <version>1.3_1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam</artifactId>
+      <version>${org.ops4j.pax.exam.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <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>
+    <dependency>
+      <groupId>org.ops4j.pax.exam</groupId>
+      <artifactId>pax-exam-junit4</artifactId>
+      <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>

Added: 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/app/Page.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/app/Page.java?rev=1751792&view=auto
==============================================================================
--- 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/app/Page.java
 (added)
+++ 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/app/Page.java
 Thu Jul  7 13:48:22 2016
@@ -0,0 +1,52 @@
+/*
+ * 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.scripting.freemarker.it.app;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.models.annotations.Model;
+import org.apache.sling.models.annotations.injectorspecific.SlingObject;
+
+import static 
org.apache.sling.models.annotations.injectorspecific.InjectionStrategy.OPTIONAL;
+
+@Model(adaptables = {Resource.class, SlingHttpServletRequest.class})
+public class Page {
+
+    @SlingObject
+    protected Resource resource;
+
+    @SlingObject(injectionStrategy = OPTIONAL)
+    protected SlingHttpServletRequest request;
+
+    public Page() {
+    }
+
+    public String getName() {
+        return resource.getName();
+    }
+
+    public String getPath() {
+        return resource.getPath();
+    }
+
+    public String getTitle() {
+        return resource.getValueMap().get("title", String.class);
+    }
+
+}

Added: 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/AdaptToModelIT.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/AdaptToModelIT.java?rev=1751792&view=auto
==============================================================================
--- 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/AdaptToModelIT.java
 (added)
+++ 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/AdaptToModelIT.java
 Thu Jul  7 13:48:22 2016
@@ -0,0 +1,62 @@
+/*
+ * 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.scripting.freemarker.it.tests;
+
+import java.io.IOException;
+
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class AdaptToModelIT extends FreemarkerTestSupport {
+
+    private Document document;
+
+    @Before
+    public void setup() throws IOException {
+        final String url = 
String.format("http://localhost:%s/freemarker/adaptto.html";, httpPort());
+        document = Jsoup.connect(url).get();
+    }
+
+    @Test
+    @Ignore
+    public void testTitle() {
+        assertThat(document.title(), is("Sling Models adaptTo()"));
+    }
+
+    @Test
+    @Ignore
+    public void testPageName() {
+        final Element name = document.getElementById("name");
+        assertThat("adaptto", is(name.text()));
+    }
+
+}

Added: 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerScriptEngineFactoryIT.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerScriptEngineFactoryIT.java?rev=1751792&view=auto
==============================================================================
--- 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerScriptEngineFactoryIT.java
 (added)
+++ 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerScriptEngineFactoryIT.java
 Thu Jul  7 13:48:22 2016
@@ -0,0 +1,62 @@
+/*
+ * 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.scripting.freemarker.it.tests;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.startsWith;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class FreemarkerScriptEngineFactoryIT extends FreemarkerTestSupport {
+
+    @Test
+    public void testScriptEngineFactory() {
+        assertNotNull(scriptEngineFactory);
+    }
+
+    @Test
+    public void testScriptEngineFactoryEngineName() {
+        assertThat("Apache Sling Scripting FreeMarker", 
is(scriptEngineFactory.getEngineName()));
+    }
+
+    @Test
+    public void testScriptEngineFactoryLanguageName() {
+        assertThat("FreeMarker", is(scriptEngineFactory.getLanguageName()));
+    }
+
+    @Test
+    public void testScriptEngineFactoryLanguageVersion() {
+        assertThat(scriptEngineFactory.getLanguageVersion(), 
startsWith("2.3"));
+    }
+
+    @Test
+    public void testScriptEngineFactoryNames() {
+        assertThat(scriptEngineFactory.getNames(), hasItem("freemarker"));
+    }
+
+}

Added: 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerTestSupport.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerTestSupport.java?rev=1751792&view=auto
==============================================================================
--- 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerTestSupport.java
 (added)
+++ 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerTestSupport.java
 Thu Jul  7 13:48:22 2016
@@ -0,0 +1,145 @@
+/*
+ * 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.scripting.freemarker.it.tests;
+
+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.testing.paxexam.SlingOptions;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.ProbeBuilder;
+import org.ops4j.pax.exam.TestProbeBuilder;
+import org.ops4j.pax.exam.util.Filter;
+import org.osgi.framework.Constants;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.http.HttpService;
+
+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.ops4j.pax.exam.CoreOptions.bootDelegationPackage;
+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.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.workingDirectory;
+import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration;
+
+public abstract class FreemarkerTestSupport {
+
+    @Inject
+    protected ServletResolver servletResolver;
+
+    @Inject
+    protected SlingRequestProcessor slingRequestProcessor;
+
+    @Inject
+    protected AuthenticationSupport authenticationSupport;
+
+    @Inject
+    protected HttpService httpService;
+
+    @Inject
+    @Filter(value = "(names=freemarker)")
+    protected ScriptEngineFactory scriptEngineFactory;
+
+    @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 new Option[]{
+            workingDirectory(workingDirectory),
+            launchpad(workingDirectory),
+            // Sling Scripting FreeMarker
+            bundle(file.toURI().toString()),
+            
mavenBundle().groupId("org.apache.servicemix.specs").artifactId("org.apache.servicemix.specs.jaxp-api-1.4").versionAsInProject(),
+            bootDelegationPackage("javax.swing.*"),
+            // testing
+            
mavenBundle().groupId("org.jsoup").artifactId("jsoup").versionAsInProject(),
+            
mavenBundle().groupId("org.apache.servicemix.bundles").artifactId("org.apache.servicemix.bundles.hamcrest").versionAsInProject(),
+            junitBundles()
+        };
+    }
+
+    @ProbeBuilder
+    public TestProbeBuilder probeConfiguration(final TestProbeBuilder 
testProbeBuilder) {
+        testProbeBuilder.setHeader(Constants.EXPORT_PACKAGE, 
"org.apache.sling.scripting.freemarker.it.app");
+        testProbeBuilder.setHeader("Sling-Model-Packages", 
"org.apache.sling.scripting.freemarker.it.app");
+        testProbeBuilder.setHeader("Sling-Initial-Content", String.join(",",
+            
"apps/freemarker;path:=/apps/freemarker;overwrite:=true;uninstall:=true",
+            "content;path:=/content;overwrite:=true;uninstall:=true"
+        ));
+        return testProbeBuilder;
+    }
+
+    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(),
+            slingExtensionModels(),
+            slingScripting(),
+            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(SlingOptions.versionResolver)
+        );
+    }
+
+}

Added: 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/SimpleIT.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/SimpleIT.java?rev=1751792&view=auto
==============================================================================
--- 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/SimpleIT.java
 (added)
+++ 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/SimpleIT.java
 Thu Jul  7 13:48:22 2016
@@ -0,0 +1,59 @@
+/*
+ * 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.scripting.freemarker.it.tests;
+
+import java.io.IOException;
+
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class SimpleIT extends FreemarkerTestSupport {
+
+    private Document document;
+
+    @Before
+    public void setup() throws IOException {
+        final String url = 
String.format("http://localhost:%s/freemarker/simple.html";, httpPort());
+        document = Jsoup.connect(url).get();
+    }
+
+    @Test
+    public void testTitle() {
+        assertThat(document.title(), is("freemarker simple"));
+    }
+
+    @Test
+    public void testPageName() {
+        final Element name = document.getElementById("name");
+        assertThat("simple", is(name.text()));
+    }
+
+}

Added: 
sling/trunk/contrib/scripting/freemarker/src/test/resources/apps/freemarker/page/adaptto/html.ftl
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/freemarker/src/test/resources/apps/freemarker/page/adaptto/html.ftl?rev=1751792&view=auto
==============================================================================
--- 
sling/trunk/contrib/scripting/freemarker/src/test/resources/apps/freemarker/page/adaptto/html.ftl
 (added)
+++ 
sling/trunk/contrib/scripting/freemarker/src/test/resources/apps/freemarker/page/adaptto/html.ftl
 Thu Jul  7 13:48:22 2016
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<!--
+    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.
+-->
+<#assign page = 
request.adaptTo(statics["org.apache.sling.scripting.freemarker.it.app.Page"].class)>
+<html>
+<head>
+  <meta charset="UTF-8"/>
+  <title>${page.title!''?html}</title>
+</head>
+<body>
+<span id="name">${page.name!''?html}</span>
+</body>
+</html>

Added: 
sling/trunk/contrib/scripting/freemarker/src/test/resources/apps/freemarker/page/simple/html.ftl
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/freemarker/src/test/resources/apps/freemarker/page/simple/html.ftl?rev=1751792&view=auto
==============================================================================
--- 
sling/trunk/contrib/scripting/freemarker/src/test/resources/apps/freemarker/page/simple/html.ftl
 (added)
+++ 
sling/trunk/contrib/scripting/freemarker/src/test/resources/apps/freemarker/page/simple/html.ftl
 Thu Jul  7 13:48:22 2016
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<!--
+    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.
+-->
+<html>
+<head>
+  <meta charset="UTF-8"/>
+  <title>${resource.valueMap.title!''?html}</title>
+</head>
+<body>
+<span id="name">${resource.name!''?html}</span>
+</body>
+</html>

Added: 
sling/trunk/contrib/scripting/freemarker/src/test/resources/content/freemarker.json
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/freemarker/src/test/resources/content/freemarker.json?rev=1751792&view=auto
==============================================================================
--- 
sling/trunk/contrib/scripting/freemarker/src/test/resources/content/freemarker.json
 (added)
+++ 
sling/trunk/contrib/scripting/freemarker/src/test/resources/content/freemarker.json
 Thu Jul  7 13:48:22 2016
@@ -0,0 +1,18 @@
+{
+    "jcr:primaryType": "nt:unstructured",
+    "sling:resourceType": "freemarker/page/main",
+    "sling:resourceSuperType": "freemarker/page",
+    "title": "Apache Sling Scripting Freemarker",
+    "simple": {
+        "jcr:primaryType": "nt:unstructured",
+        "sling:resourceType": "freemarker/page/simple",
+        "sling:resourceSuperType": "freemarker/page",
+        "title": "freemarker simple"
+    },
+    "adaptto": {
+        "jcr:primaryType": "nt:unstructured",
+        "sling:resourceType": "freemarker/page/adaptto",
+        "sling:resourceSuperType": "freemarker/page",
+        "title": "Sling Models adaptTo()"
+    }
+}


Reply via email to