Author: olli
Date: Sat Mar  4 09:33:55 2017
New Revision: 1785444

URL: http://svn.apache.org/viewvc?rev=1785444&view=rev
Log:
improve test logging and use resource presence

Added:
    sling/trunk/contrib/scripting/freemarker/src/test/resources/exam.properties
    sling/trunk/contrib/scripting/freemarker/src/test/resources/logback.xml
Modified:
    sling/trunk/contrib/scripting/freemarker/pom.xml
    
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

Modified: sling/trunk/contrib/scripting/freemarker/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/freemarker/pom.xml?rev=1785444&r1=1785443&r2=1785444&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/freemarker/pom.xml (original)
+++ sling/trunk/contrib/scripting/freemarker/pom.xml Sat Mar  4 09:33:55 2017
@@ -189,6 +189,12 @@
     </dependency>
     <dependency>
       <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.resource.presence</artifactId>
+      <version>0.0.1-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.sling</groupId>
       <artifactId>org.apache.sling.scripting.api</artifactId>
       <version>2.1.12</version>
       <scope>provided</scope>

Modified: 
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=1785444&r1=1785443&r2=1785444&view=diff
==============================================================================
--- 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/AdaptToModelIT.java
 (original)
+++ 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/AdaptToModelIT.java
 Sat Mar  4 09:33:55 2017
@@ -20,6 +20,9 @@ package org.apache.sling.scripting.freem
 
 import java.io.IOException;
 
+import javax.inject.Inject;
+
+import org.apache.sling.resource.presence.ResourcePresence;
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
@@ -27,12 +30,16 @@ import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.PaxExam;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.exam.util.Filter;
 
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
+import static 
org.ops4j.pax.exam.cm.ConfigurationAdminOptions.factoryConfiguration;
 
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
@@ -40,6 +47,20 @@ public class AdaptToModelIT extends Free
 
     private Document document;
 
+    @Inject
+    @Filter(value = "(path=/apps/freemarker/page/adaptto/html.ftl)")
+    private ResourcePresence resourcePresence;
+
+    @Configuration
+    public Option[] configuration() {
+        return new Option[]{
+            baseConfiguration(),
+            
factoryConfiguration("org.apache.sling.resource.presence.internal.ResourcePresenter")
+                .put("path", "/apps/freemarker/page/adaptto/html.ftl")
+                .asOption(),
+        };
+    }
+
     @Before
     public void setup() throws IOException {
         final String url = 
String.format("http://localhost:%s/freemarker/adaptto.html";, httpPort());

Modified: 
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=1785444&r1=1785443&r2=1785444&view=diff
==============================================================================
--- 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerScriptEngineFactoryIT.java
 (original)
+++ 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerScriptEngineFactoryIT.java
 Sat Mar  4 09:33:55 2017
@@ -20,6 +20,8 @@ package org.apache.sling.scripting.freem
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.PaxExam;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
@@ -34,6 +36,13 @@ import static org.junit.Assert.assertTha
 @ExamReactorStrategy(PerClass.class)
 public class FreemarkerScriptEngineFactoryIT extends FreemarkerTestSupport {
 
+    @Configuration
+    public Option[] configuration() {
+        return new Option[]{
+            baseConfiguration()
+        };
+    }
+
     @Test
     public void testScriptEngineFactory() {
         assertNotNull(scriptEngineFactory);

Modified: 
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=1785444&r1=1785443&r2=1785444&view=diff
==============================================================================
--- 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerTestSupport.java
 (original)
+++ 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/FreemarkerTestSupport.java
 Sat Mar  4 09:33:55 2017
@@ -25,11 +25,11 @@ import org.apache.sling.api.servlets.Ser
 import org.apache.sling.auth.core.AuthenticationSupport;
 import org.apache.sling.engine.SlingRequestProcessor;
 import org.apache.sling.testing.paxexam.TestSupport;
-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.ops4j.pax.exam.util.PathUtils;
 import org.osgi.framework.Constants;
 import org.osgi.service.http.HttpService;
 
@@ -40,6 +40,8 @@ import static org.ops4j.pax.exam.CoreOpt
 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.systemProperty;
+import static 
org.ops4j.pax.exam.cm.ConfigurationAdminOptions.factoryConfiguration;
 
 public abstract class FreemarkerTestSupport extends TestSupport {
 
@@ -59,10 +61,9 @@ public abstract class FreemarkerTestSupp
     @Filter(value = "(names=freemarker)")
     protected ScriptEngineFactory scriptEngineFactory;
 
-    @Configuration
-    public Option[] configuration() {
-        return new Option[]{
-            baseConfiguration(),
+    public Option baseConfiguration() {
+        return composite(
+            super.baseConfiguration(),
             launchpad(),
             // Sling Scripting FreeMarker
             testBundle("bundle.filename"),
@@ -70,10 +71,15 @@ public abstract class FreemarkerTestSupp
             
mavenBundle().groupId("org.apache.servicemix.specs").artifactId("org.apache.servicemix.specs.jaxp-api-1.4").versionAsInProject(),
             bootDelegationPackage("javax.swing.*"),
             // testing
+            
mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.resource.presence").versionAsInProject(),
+            
factoryConfiguration("org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended")
+                .put("user.mapping", new 
String[]{"org.apache.sling.resource.presence=sling-readall"})
+                .asOption(),
             
mavenBundle().groupId("org.jsoup").artifactId("jsoup").versionAsInProject(),
             
mavenBundle().groupId("org.apache.servicemix.bundles").artifactId("org.apache.servicemix.bundles.hamcrest").versionAsInProject(),
-            junitBundles()
-        };
+            junitBundles(),
+            logging()
+        );
     }
 
     @ProbeBuilder
@@ -97,4 +103,15 @@ public abstract class FreemarkerTestSupp
         );
     }
 
+    protected Option logging() {
+        final String filename = 
String.format("file:%s/src/test/resources/logback.xml", PathUtils.getBaseDir());
+        return composite(
+            systemProperty("logback.configurationFile").value(filename),
+            
mavenBundle().groupId("org.slf4j").artifactId("slf4j-api").version("1.7.21"),
+            
mavenBundle().groupId("org.slf4j").artifactId("jcl-over-slf4j").version("1.7.21"),
+            
mavenBundle().groupId("ch.qos.logback").artifactId("logback-core").version("1.1.7"),
+            
mavenBundle().groupId("ch.qos.logback").artifactId("logback-classic").version("1.1.7")
+        );
+    }
+
 }

Modified: 
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=1785444&r1=1785443&r2=1785444&view=diff
==============================================================================
--- 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/SimpleIT.java
 (original)
+++ 
sling/trunk/contrib/scripting/freemarker/src/test/java/org/apache/sling/scripting/freemarker/it/tests/SimpleIT.java
 Sat Mar  4 09:33:55 2017
@@ -20,18 +20,25 @@ package org.apache.sling.scripting.freem
 
 import java.io.IOException;
 
+import javax.inject.Inject;
+
+import org.apache.sling.resource.presence.ResourcePresence;
 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.Configuration;
+import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.PaxExam;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.exam.util.Filter;
 
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
+import static 
org.ops4j.pax.exam.cm.ConfigurationAdminOptions.factoryConfiguration;
 
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
@@ -39,6 +46,20 @@ public class SimpleIT extends Freemarker
 
     private Document document;
 
+    @Inject
+    @Filter(value = "(path=/apps/freemarker/page/simple/html.ftl)")
+    private ResourcePresence resourcePresence;
+
+    @Configuration
+    public Option[] configuration() {
+        return new Option[]{
+            baseConfiguration(),
+            
factoryConfiguration("org.apache.sling.resource.presence.internal.ResourcePresenter")
+                .put("path", "/apps/freemarker/page/simple/html.ftl")
+                .asOption(),
+        };
+    }
+
     @Before
     public void setup() throws IOException {
         final String url = 
String.format("http://localhost:%s/freemarker/simple.html";, httpPort());

Added: 
sling/trunk/contrib/scripting/freemarker/src/test/resources/exam.properties
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/freemarker/src/test/resources/exam.properties?rev=1785444&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/freemarker/src/test/resources/exam.properties 
(added)
+++ sling/trunk/contrib/scripting/freemarker/src/test/resources/exam.properties 
Sat Mar  4 09:33:55 2017
@@ -0,0 +1,19 @@
+#
+#  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.
+#
+pax.exam.logging=none

Added: sling/trunk/contrib/scripting/freemarker/src/test/resources/logback.xml
URL: 
http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/freemarker/src/test/resources/logback.xml?rev=1785444&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/freemarker/src/test/resources/logback.xml 
(added)
+++ sling/trunk/contrib/scripting/freemarker/src/test/resources/logback.xml Sat 
Mar  4 09:33:55 2017
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<configuration>
+  <appender name="file" class="ch.qos.logback.core.FileAppender">
+    <file>target/testing.log</file>
+    <encoder>
+      <pattern>%date %level [%thread] %logger{10} [%file : %line] 
%msg%n</pattern>
+    </encoder>
+  </appender>
+  <root level="info">
+    <appender-ref ref="file"/>
+  </root>
+</configuration>


Reply via email to