You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2016/05/18 10:57:00 UTC

svn commit: r1744389 - in /sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it: ./ src/main/java/org/apache/sling/scripting/thymeleaf/it/ src/main/resources/apps/thymeleaf/page/decoupled/ src/main/resources/apps/thymeleaf/page/link/ s...

Author: olli
Date: Wed May 18 10:57:00 2016
New Revision: 1744389

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

add tests for link builder and decoupled template logic

Added:
    sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/java/org/apache/sling/scripting/thymeleaf/it/Activator.java
    sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/java/org/apache/sling/scripting/thymeleaf/it/FooBarLinkBuilder.java
    sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/apps/thymeleaf/page/decoupled/
    sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/apps/thymeleaf/page/decoupled/html.html
    sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/apps/thymeleaf/page/decoupled/html.th.xml
    sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/apps/thymeleaf/page/link/
    sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/apps/thymeleaf/page/link/html.html
      - copied, changed from r1743496, sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/apps/thymeleaf/page/text/html.html
    sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/test/java/org/apache/sling/scripting/thymeleaf/it/LinkBuilderIT.java
    sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/test/java/org/apache/sling/scripting/thymeleaf/it/ThymeleafDecoupledTemplateLogicIT.java
Modified:
    sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/pom.xml
    sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/content/thymeleaf.json

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=1744389&r1=1744388&r2=1744389&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 Wed May 18 10:57:00 2016
@@ -57,6 +57,19 @@
       <version>1</version>
       <scope>provided</scope>
     </dependency>
+    <!-- OSGi -->
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>osgi.core</artifactId>
+      <version>6.0.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>osgi.cmpn</artifactId>
+      <version>6.0.0</version>
+      <scope>provided</scope>
+    </dependency>
     <!-- Apache Karaf -->
     <dependency>
       <groupId>org.apache.karaf</groupId>
@@ -120,7 +133,7 @@
       <groupId>org.apache.sling</groupId>
       <artifactId>org.apache.sling.scripting.thymeleaf</artifactId>
       <version>0.1.7-SNAPSHOT</version>
-      <scope>test</scope>
+      <scope>provided</scope>
     </dependency>
     <!-- bnd -->
     <dependency>
@@ -194,6 +207,7 @@
         <extensions>true</extensions>
         <configuration>
           <instructions>
+            <Bundle-Activator>org.apache.sling.scripting.thymeleaf.it.Activator</Bundle-Activator>
             <Sling-Initial-Content>
               apps/jsp;path:=/apps/jsp;overwrite:=true;uninstall:=true,
               apps/thymeleaf;path:=/apps/thymeleaf;overwrite:=true;uninstall:=true,

Added: sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/java/org/apache/sling/scripting/thymeleaf/it/Activator.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/java/org/apache/sling/scripting/thymeleaf/it/Activator.java?rev=1744389&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/java/org/apache/sling/scripting/thymeleaf/it/Activator.java (added)
+++ sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/java/org/apache/sling/scripting/thymeleaf/it/Activator.java Wed May 18 10:57:00 2016
@@ -0,0 +1,51 @@
+/*
+ * 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.thymeleaf.it;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.thymeleaf.linkbuilder.ILinkBuilder;
+
+public class Activator implements BundleActivator {
+
+    private ServiceRegistration serviceRegistration;
+
+    @Override
+    public void start(BundleContext bundleContext) throws Exception {
+        final FooBarLinkBuilder linkBuilder = new FooBarLinkBuilder();
+        final Dictionary<String, String> properties = new Hashtable<>();
+        properties.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Scripting Thymeleaf IT FooBarLinkBuilder");
+        properties.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
+        serviceRegistration = bundleContext.registerService(ILinkBuilder.class, linkBuilder, properties);
+    }
+
+    @Override
+    public void stop(BundleContext bundleContext) throws Exception {
+        if (serviceRegistration != null) {
+            serviceRegistration.unregister();
+            serviceRegistration = null;
+        }
+    }
+
+}

Added: sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/java/org/apache/sling/scripting/thymeleaf/it/FooBarLinkBuilder.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/java/org/apache/sling/scripting/thymeleaf/it/FooBarLinkBuilder.java?rev=1744389&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/java/org/apache/sling/scripting/thymeleaf/it/FooBarLinkBuilder.java (added)
+++ sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/java/org/apache/sling/scripting/thymeleaf/it/FooBarLinkBuilder.java Wed May 18 10:57:00 2016
@@ -0,0 +1,49 @@
+/*
+ * 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.thymeleaf.it;
+
+import java.util.Map;
+
+import org.thymeleaf.context.IExpressionContext;
+import org.thymeleaf.linkbuilder.ILinkBuilder;
+
+public class FooBarLinkBuilder implements ILinkBuilder {
+
+    public FooBarLinkBuilder() {
+    }
+
+    @Override
+    public String getName() {
+        return getClass().getSimpleName();
+    }
+
+    @Override
+    public Integer getOrder() {
+        return 0;
+    }
+
+    @Override
+    public String buildLink(final IExpressionContext expressionContext, final String base, final Map<String, Object> parameters) {
+        if ("foo".equals(base)) {
+            return "foobar";
+        }
+        return null;
+    }
+
+}

Added: sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/apps/thymeleaf/page/decoupled/html.html
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/apps/thymeleaf/page/decoupled/html.html?rev=1744389&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/apps/thymeleaf/page/decoupled/html.html (added)
+++ sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/apps/thymeleaf/page/decoupled/html.html Wed May 18 10:57:00 2016
@@ -0,0 +1,26 @@
+<!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>
+  <title id="title">Thymeleaf</title>
+</head>
+<body>
+</body>
+</html>

Added: sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/apps/thymeleaf/page/decoupled/html.th.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/apps/thymeleaf/page/decoupled/html.th.xml?rev=1744389&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/apps/thymeleaf/page/decoupled/html.th.xml (added)
+++ sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/apps/thymeleaf/page/decoupled/html.th.xml Wed May 18 10:57:00 2016
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!--
+    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.
+-->
+<thlogic xmlns:th="http://www.thymeleaf.org">
+  <attr sel="#title" th:text="${resource.getValueMap().get('title')}"></attr>
+</thlogic>

Copied: sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/apps/thymeleaf/page/link/html.html (from r1743496, sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/apps/thymeleaf/page/text/html.html)
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/apps/thymeleaf/page/link/html.html?p2=sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/apps/thymeleaf/page/link/html.html&p1=sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/apps/thymeleaf/page/text/html.html&r1=1743496&r2=1744389&rev=1744389&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/apps/thymeleaf/page/text/html.html (original)
+++ sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/apps/thymeleaf/page/link/html.html Wed May 18 10:57:00 2016
@@ -20,9 +20,10 @@
 <html>
 <head>
   <meta charset="UTF-8"/>
-  <title data-th-text="${resource.getValueMap().get('title')}"></title>
+  <title></title>
 </head>
 <body>
-<span id="name" data-th-text="${resource.name}"></span>
+<a id="foo" href="#" data-th-href="@{foo}">foo</a>
+<a id="bar" href="#" data-th-href="@{bar}">bar</a>
 </body>
 </html>

Modified: sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/content/thymeleaf.json
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/content/thymeleaf.json?rev=1744389&r1=1744388&r2=1744389&view=diff
==============================================================================
--- sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/content/thymeleaf.json (original)
+++ sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/main/resources/content/thymeleaf.json Wed May 18 10:57:00 2016
@@ -3,17 +3,17 @@
     "sling:resourceType": "thymeleaf/page/main",
     "sling:resourceSuperType": "thymeleaf/page",
     "title": "Apache Sling Scripting Thymeleaf",
-    "text": {
+    "adaptto": {
         "jcr:primaryType": "nt:unstructured",
-        "sling:resourceType": "thymeleaf/page/text",
+        "sling:resourceType": "thymeleaf/page/adaptto",
         "sling:resourceSuperType": "thymeleaf/page",
-        "title": "Thymeleaf Text"
+        "title": "Sling Models adaptTo()"
     },
-    "replace": {
+    "decoupled": {
         "jcr:primaryType": "nt:unstructured",
-        "sling:resourceType": "thymeleaf/page/replace",
+        "sling:resourceType": "thymeleaf/page/decoupled",
         "sling:resourceSuperType": "thymeleaf/page",
-        "title": "Thymeleaf Replace"
+        "title": "Thymeleaf Decoupled Template Logic"
     },
     "include": {
         "jcr:primaryType": "nt:unstructured",
@@ -21,10 +21,22 @@
         "sling:resourceSuperType": "thymeleaf/page",
         "title": "Sling Include"
     },
-    "adaptto": {
+    "link": {
         "jcr:primaryType": "nt:unstructured",
-        "sling:resourceType": "thymeleaf/page/adaptto",
+        "sling:resourceType": "thymeleaf/page/link",
         "sling:resourceSuperType": "thymeleaf/page",
-        "title": "Sling Models adaptTo()"
+        "title": "Thymeleaf Link Builder"
+    },
+    "replace": {
+        "jcr:primaryType": "nt:unstructured",
+        "sling:resourceType": "thymeleaf/page/replace",
+        "sling:resourceSuperType": "thymeleaf/page",
+        "title": "Thymeleaf Replace"
+    },
+    "text": {
+        "jcr:primaryType": "nt:unstructured",
+        "sling:resourceType": "thymeleaf/page/text",
+        "sling:resourceSuperType": "thymeleaf/page",
+        "title": "Thymeleaf Text"
     }
 }

Added: sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/test/java/org/apache/sling/scripting/thymeleaf/it/LinkBuilderIT.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/LinkBuilderIT.java?rev=1744389&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/test/java/org/apache/sling/scripting/thymeleaf/it/LinkBuilderIT.java (added)
+++ sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/test/java/org/apache/sling/scripting/thymeleaf/it/LinkBuilderIT.java Wed May 18 10:57:00 2016
@@ -0,0 +1,60 @@
+/*
+ * 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.thymeleaf.it;
+
+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 LinkBuilderIT extends ThymeleafTestSupport {
+
+    private Document document;
+
+    @Before
+    public void setup() throws IOException {
+        final String url = String.format("http://localhost:%s/thymeleaf/link.html", httpPort());
+        document = Jsoup.connect(url).get();
+    }
+
+    @Test
+    public void testFooLink() throws IOException {
+        final Element link = document.getElementById("foo");
+        assertThat(link.attributes().get("href"), is("foobar"));
+    }
+
+    @Test
+    public void testBarLink() throws IOException {
+        final Element link = document.getElementById("bar");
+        assertThat(link.attributes().get("href"), is("bar"));
+    }
+
+}

Added: sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/test/java/org/apache/sling/scripting/thymeleaf/it/ThymeleafDecoupledTemplateLogicIT.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/ThymeleafDecoupledTemplateLogicIT.java?rev=1744389&view=auto
==============================================================================
--- sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/test/java/org/apache/sling/scripting/thymeleaf/it/ThymeleafDecoupledTemplateLogicIT.java (added)
+++ sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf.it/src/test/java/org/apache/sling/scripting/thymeleaf/it/ThymeleafDecoupledTemplateLogicIT.java Wed May 18 10:57:00 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.thymeleaf.it;
+
+import java.io.IOException;
+
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+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 ThymeleafDecoupledTemplateLogicIT extends ThymeleafTestSupport {
+
+    private Document document;
+
+    @Before
+    public void setup() throws IOException {
+        final String url = String.format("http://localhost:%s/thymeleaf/decoupled.html", httpPort());
+        document = Jsoup.connect(url).get();
+    }
+
+    @Test
+    public void testTitle() {
+        assertThat(document.title(), is("Thymeleaf Decoupled Template Logic"));
+    }
+
+}