This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.scripting.thymeleaf-1.1.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-thymeleaf.git
commit 62ac2799ee96563af1a85dfffc92edef598601ae Author: Oliver Lietz <[email protected]> AuthorDate: Wed Jul 6 09:32:43 2016 +0000 SLING-5680 Add Integration Tests for Scripting Thymeleaf merge module org.apache.sling.scripting.thymeleaf.it into org.apache.sling.scripting.thymeleaf git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/scripting/org.apache.sling.scripting.thymeleaf@1751643 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 140 +++++++++++++++++- .../scripting/thymeleaf/it/app/Activator.java | 55 ++++++++ .../thymeleaf/it/app/FooBarLinkBuilder.java | 49 +++++++ .../sling/scripting/thymeleaf/it/app/Page.java | 52 +++++++ .../thymeleaf/it/tests/AdaptToModelIT.java | 59 ++++++++ .../thymeleaf/it/tests/LinkBuilderIT.java | 60 ++++++++ .../thymeleaf/it/tests/SlingIncludeIT.java | 68 +++++++++ .../thymeleaf/it/tests/TemplateEngineIT.java | 59 ++++++++ .../tests/ThymeleafDecoupledTemplateLogicIT.java | 52 +++++++ .../thymeleaf/it/tests/ThymeleafReplaceIT.java | 52 +++++++ .../it/tests/ThymeleafScriptEngineFactoryIT.java | 62 ++++++++ .../thymeleaf/it/tests/ThymeleafTestSupport.java | 156 +++++++++++++++++++++ .../thymeleaf/it/tests/ThymeleafTextIT.java | 59 ++++++++ src/test/resources/apps/jsp/page/resource/html.jsp | 22 +++ src/test/resources/apps/thymeleaf/ROOT.json | 6 + .../apps/thymeleaf/page/adaptto/html.html | 28 ++++ .../apps/thymeleaf/page/decoupled/html.html | 26 ++++ .../apps/thymeleaf/page/decoupled/html.th.xml | 22 +++ .../apps/thymeleaf/page/fragments/head.html | 27 ++++ .../apps/thymeleaf/page/include/html.html | 37 +++++ .../resources/apps/thymeleaf/page/link/html.html | 29 ++++ .../resources/apps/thymeleaf/page/main/html.html | 29 ++++ .../apps/thymeleaf/page/replace/html.html | 26 ++++ .../resources/apps/thymeleaf/page/text/html.html | 28 ++++ src/test/resources/content/thymeleaf.json | 42 ++++++ 25 files changed, 1238 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 2724483..a487a9e 100644 --- a/pom.xml +++ b/pom.xml @@ -38,12 +38,13 @@ <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.thymeleaf.version>3.0.0.RELEASE</org.thymeleaf.version> <org.attoparser.version>2.0.0.RELEASE</org.attoparser.version> <org.unbescape.version>1.1.3.RELEASE</org.unbescape.version> <ognl.version>3.1.3</ognl.version> <com.fasterxml.jackson.version>2.6.3</com.fasterxml.jackson.version> + <org.ops4j.pax.exam.version>4.9.1</org.ops4j.pax.exam.version> </properties> <scm> @@ -55,6 +56,12 @@ <dependencies> <!-- javax --> <dependency> + <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> @@ -62,14 +69,20 @@ <!-- OSGi --> <dependency> <groupId>org.osgi</groupId> - <artifactId>osgi.core</artifactId> - <version>6.0.0</version> + <artifactId>osgi.annotation</artifactId> + <version>6.0.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.osgi</groupId> - <artifactId>osgi.annotation</artifactId> - <version>6.0.1</version> + <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> @@ -91,6 +104,13 @@ <version>2.5</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> @@ -100,6 +120,30 @@ </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.8</version> <scope>provided</scope> @@ -112,8 +156,8 @@ </dependency> <dependency> <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.i18n</artifactId> - <version>2.4.6</version> + <artifactId>org.apache.sling.testing.paxexam</artifactId> + <version>0.0.1-SNAPSHOT</version> <scope>provided</scope> </dependency> <!-- Thymeleaf --> @@ -147,6 +191,13 @@ <version>3.20.0-GA</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> @@ -154,6 +205,48 @@ <version>1.7.21</version> <scope>provided</scope> </dependency> + <!-- testing --> + <dependency> + <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> <build> @@ -198,6 +291,39 @@ </filters> </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> diff --git a/src/test/java/org/apache/sling/scripting/thymeleaf/it/app/Activator.java b/src/test/java/org/apache/sling/scripting/thymeleaf/it/app/Activator.java new file mode 100644 index 0000000..eaf47db --- /dev/null +++ b/src/test/java/org/apache/sling/scripting/thymeleaf/it/app/Activator.java @@ -0,0 +1,55 @@ +/* + * 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.app; + +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 linkBuilderRegistration; + + @Override + public void start(final BundleContext bundleContext) throws Exception { + registerLinkBuilder(bundleContext); + } + + @Override + public void stop(final BundleContext bundleContext) throws Exception { + if (linkBuilderRegistration != null) { + linkBuilderRegistration.unregister(); + linkBuilderRegistration = null; + } + } + + private void registerLinkBuilder(final BundleContext bundleContext) { + 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"); + linkBuilderRegistration = bundleContext.registerService(ILinkBuilder.class, linkBuilder, properties); + } + +} diff --git a/src/test/java/org/apache/sling/scripting/thymeleaf/it/app/FooBarLinkBuilder.java b/src/test/java/org/apache/sling/scripting/thymeleaf/it/app/FooBarLinkBuilder.java new file mode 100644 index 0000000..c7f2b8c --- /dev/null +++ b/src/test/java/org/apache/sling/scripting/thymeleaf/it/app/FooBarLinkBuilder.java @@ -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.app; + +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; + } + +} diff --git a/src/test/java/org/apache/sling/scripting/thymeleaf/it/app/Page.java b/src/test/java/org/apache/sling/scripting/thymeleaf/it/app/Page.java new file mode 100644 index 0000000..5c7417d --- /dev/null +++ b/src/test/java/org/apache/sling/scripting/thymeleaf/it/app/Page.java @@ -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.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); + } + +} diff --git a/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/AdaptToModelIT.java b/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/AdaptToModelIT.java new file mode 100644 index 0000000..8424ad4 --- /dev/null +++ b/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/AdaptToModelIT.java @@ -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.thymeleaf.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 AdaptToModelIT extends ThymeleafTestSupport { + + private Document document; + + @Before + public void setup() throws IOException { + final String url = String.format("http://localhost:%s/thymeleaf/adaptto.html", httpPort()); + document = Jsoup.connect(url).get(); + } + + @Test + public void testTitle() { + assertThat(document.title(), is("Sling Models adaptTo()")); + } + + @Test + public void testPageName() { + final Element name = document.getElementById("name"); + assertThat("adaptto", is(name.text())); + } + +} diff --git a/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/LinkBuilderIT.java b/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/LinkBuilderIT.java new file mode 100644 index 0000000..d8cb750 --- /dev/null +++ b/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/LinkBuilderIT.java @@ -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.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 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")); + } + +} diff --git a/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/SlingIncludeIT.java b/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/SlingIncludeIT.java new file mode 100644 index 0000000..d245d43 --- /dev/null +++ b/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/SlingIncludeIT.java @@ -0,0 +1,68 @@ +/* + * 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.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 SlingIncludeIT extends ThymeleafTestSupport { + + private Document document; + + @Before + public void setup() throws IOException { + final String url = String.format("http://localhost:%s/thymeleaf/include.html", httpPort()); + document = Jsoup.connect(url).get(); + } + + @Test + public void testJspIncludeSimple() { + final Element simple = document.getElementById("simple"); + assertThat("/content/thymeleaf/include", is(simple.text())); + } + + @Test + public void testJspIncludeWrap() { + final Element wrap = document.getElementById("wrap"); + assertThat(1, is(wrap.children().size())); + assertThat("/content/thymeleaf/include", is(wrap.child(0).text())); + } + + @Test + public void testJspIncludeUnwrap() { + final Element unwrap = document.getElementById("unwrap"); + assertThat(0, is(unwrap.children().size())); + assertThat("/content/thymeleaf/include", is(unwrap.text())); + } + +} diff --git a/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/TemplateEngineIT.java b/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/TemplateEngineIT.java new file mode 100644 index 0000000..dbd84b4 --- /dev/null +++ b/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/TemplateEngineIT.java @@ -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.thymeleaf.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.is; +import static org.hamcrest.Matchers.greaterThan; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; + +@RunWith(PaxExam.class) +@ExamReactorStrategy(PerClass.class) +public class TemplateEngineIT extends ThymeleafTestSupport { + + @Test + public void testTemplateEngine() { + assertNotNull(templateEngine); + } + + @Test + public void testTemplateResolvers() { + final int size = templateEngine.getConfiguration().getTemplateResolvers().size(); + assertThat(size, is(greaterThan(0))); + } + + @Test + public void testMessageResolvers() { + final int size = templateEngine.getConfiguration().getMessageResolvers().size(); + assertThat(size, is(greaterThan(0))); + } + + @Test + public void testDialects() { + final int size = templateEngine.getConfiguration().getDialects().size(); + assertThat(size, is(greaterThan(0))); + } + +} diff --git a/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/ThymeleafDecoupledTemplateLogicIT.java b/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/ThymeleafDecoupledTemplateLogicIT.java new file mode 100644 index 0000000..0184522 --- /dev/null +++ b/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/ThymeleafDecoupledTemplateLogicIT.java @@ -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.tests; + +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")); + } + +} diff --git a/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/ThymeleafReplaceIT.java b/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/ThymeleafReplaceIT.java new file mode 100644 index 0000000..adc010a --- /dev/null +++ b/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/ThymeleafReplaceIT.java @@ -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.tests; + +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 ThymeleafReplaceIT extends ThymeleafTestSupport { + + private Document document; + + @Before + public void setup() throws IOException { + final String url = String.format("http://localhost:%s/thymeleaf/replace.html", httpPort()); + document = Jsoup.connect(url).get(); + } + + @Test + public void testTitle() { + assertThat(document.title(), is("Head Title")); + } + +} diff --git a/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/ThymeleafScriptEngineFactoryIT.java b/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/ThymeleafScriptEngineFactoryIT.java new file mode 100644 index 0000000..4b16c7a --- /dev/null +++ b/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/ThymeleafScriptEngineFactoryIT.java @@ -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.thymeleaf.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 ThymeleafScriptEngineFactoryIT extends ThymeleafTestSupport { + + @Test + public void testScriptEngineFactory() { + assertNotNull(scriptEngineFactory); + } + + @Test + public void testScriptEngineFactoryEngineName() { + assertThat("Apache Sling Scripting Thymeleaf", is(scriptEngineFactory.getEngineName())); + } + + @Test + public void testScriptEngineFactoryLanguageName() { + assertThat("Thymeleaf", is(scriptEngineFactory.getLanguageName())); + } + + @Test + public void testScriptEngineFactoryLanguageVersion() { + assertThat(scriptEngineFactory.getLanguageVersion(), startsWith("3.0")); + } + + @Test + public void testScriptEngineFactoryNames() { + assertThat(scriptEngineFactory.getNames(), hasItem("thymeleaf")); + } + +} diff --git a/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/ThymeleafTestSupport.java b/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/ThymeleafTestSupport.java new file mode 100644 index 0000000..6ff98a3 --- /dev/null +++ b/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/ThymeleafTestSupport.java @@ -0,0 +1,156 @@ +/* + * 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.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.scripting.thymeleaf.it.app.Activator; +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 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.CoreOptions.workingDirectory; +import static org.ops4j.pax.exam.cm.ConfigurationAdminOptions.newConfiguration; + +public abstract class ThymeleafTestSupport { + + @Inject + protected ServletResolver servletResolver; + + @Inject + protected SlingRequestProcessor slingRequestProcessor; + + @Inject + 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 new Option[]{ + keepCaches(), + workingDirectory(workingDirectory), + launchpad(workingDirectory), + // Sling Scripting Thymeleaf + bundle(file.toURI().toString()), + 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(), + junitBundles() + }; + } + + @ProbeBuilder + public TestProbeBuilder probeConfiguration(final TestProbeBuilder testProbeBuilder) { + testProbeBuilder.setHeader(Constants.BUNDLE_ACTIVATOR, Activator.class.getName()); + testProbeBuilder.setHeader(Constants.EXPORT_PACKAGE, "org.apache.sling.scripting.thymeleaf.it.app"); + testProbeBuilder.setHeader("Sling-Model-Packages", "org.apache.sling.scripting.thymeleaf.it.app"); + testProbeBuilder.setHeader("Sling-Initial-Content", String.join(",", + "apps/jsp;path:=/apps/jsp;overwrite:=true;uninstall:=true", + "apps/thymeleaf;path:=/apps/thymeleaf;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(), + 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(SlingOptions.versionResolver) + ); + } + +} diff --git a/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/ThymeleafTextIT.java b/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/ThymeleafTextIT.java new file mode 100644 index 0000000..dc827bc --- /dev/null +++ b/src/test/java/org/apache/sling/scripting/thymeleaf/it/tests/ThymeleafTextIT.java @@ -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.thymeleaf.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 ThymeleafTextIT extends ThymeleafTestSupport { + + private Document document; + + @Before + public void setup() throws IOException { + final String url = String.format("http://localhost:%s/thymeleaf/text.html", httpPort()); + document = Jsoup.connect(url).get(); + } + + @Test + public void testTitle() { + assertThat(document.title(), is("Thymeleaf Text")); + } + + @Test + public void testResourceName() { + final Element name = document.getElementById("name"); + assertThat("text", is(name.text())); + } + +} diff --git a/src/test/resources/apps/jsp/page/resource/html.jsp b/src/test/resources/apps/jsp/page/resource/html.jsp new file mode 100644 index 0000000..197eefa --- /dev/null +++ b/src/test/resources/apps/jsp/page/resource/html.jsp @@ -0,0 +1,22 @@ +<%-- + 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. +--%><%@page session="false" %><% +%><%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling" %><% +%><sling:defineObjects/><% +%><%= resource.getPath() %><% +%> \ No newline at end of file diff --git a/src/test/resources/apps/thymeleaf/ROOT.json b/src/test/resources/apps/thymeleaf/ROOT.json new file mode 100644 index 0000000..5832d7c --- /dev/null +++ b/src/test/resources/apps/thymeleaf/ROOT.json @@ -0,0 +1,6 @@ +{ + "jcr:primaryType": "sling:Folder", + "sling:scripting": [ + "html=thymeleaf" + ] +} diff --git a/src/test/resources/apps/thymeleaf/page/adaptto/html.html b/src/test/resources/apps/thymeleaf/page/adaptto/html.html new file mode 100644 index 0000000..40ae135 --- /dev/null +++ b/src/test/resources/apps/thymeleaf/page/adaptto/html.html @@ -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 data-th-with="page=${request.adaptTo(@org.apache.sling.scripting.thymeleaf.it.app.Page@class)}"> +<head> + <meta charset="UTF-8"/> + <title data-th-text="${page.title}">Thymeleaf With with Sling Model</title> +</head> +<body> +<span id="name" data-th-text="${page.name}"></span> +</body> +</html> diff --git a/src/test/resources/apps/thymeleaf/page/decoupled/html.html b/src/test/resources/apps/thymeleaf/page/decoupled/html.html new file mode 100644 index 0000000..90779c9 --- /dev/null +++ b/src/test/resources/apps/thymeleaf/page/decoupled/html.html @@ -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> diff --git a/src/test/resources/apps/thymeleaf/page/decoupled/html.th.xml b/src/test/resources/apps/thymeleaf/page/decoupled/html.th.xml new file mode 100644 index 0000000..453c28d --- /dev/null +++ b/src/test/resources/apps/thymeleaf/page/decoupled/html.th.xml @@ -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> diff --git a/src/test/resources/apps/thymeleaf/page/fragments/head.html b/src/test/resources/apps/thymeleaf/page/fragments/head.html new file mode 100644 index 0000000..e256136 --- /dev/null +++ b/src/test/resources/apps/thymeleaf/page/fragments/head.html @@ -0,0 +1,27 @@ +<!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 data-th-fragment="default"> + <meta charset="UTF-8"/> + <title>Head Title</title> +</head> +<body> +</body> +</html> diff --git a/src/test/resources/apps/thymeleaf/page/include/html.html b/src/test/resources/apps/thymeleaf/page/include/html.html new file mode 100644 index 0000000..96c2ace --- /dev/null +++ b/src/test/resources/apps/thymeleaf/page/include/html.html @@ -0,0 +1,37 @@ +<!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>Sling Include (with JSP)</title> +</head> +<body> +<!-- simple include with resource type --> +<span id="simple" data-sling-include="${resource}" data-sling-resourceType="'jsp/page/resource'"></span> +<!-- include (keeping container element) --> +<div id="wrap"> + <span data-sling-include="${resource}" data-sling-resourceType="'jsp/page/resource'" data-sling-unwrap="false"></span> +</div> +<!-- include (unwrapping) --> +<div id="unwrap"> + <span data-sling-include="${resource}" data-sling-resourceType="'jsp/page/resource'" data-sling-unwrap="true"></span> +</div> +</body> +</html> diff --git a/src/test/resources/apps/thymeleaf/page/link/html.html b/src/test/resources/apps/thymeleaf/page/link/html.html new file mode 100644 index 0000000..e9171f3 --- /dev/null +++ b/src/test/resources/apps/thymeleaf/page/link/html.html @@ -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. +--> +<html> +<head> + <meta charset="UTF-8"/> + <title></title> +</head> +<body> +<a id="foo" href="#" data-th-href="@{foo}">foo</a> +<a id="bar" href="#" data-th-href="@{bar}">bar</a> +</body> +</html> diff --git a/src/test/resources/apps/thymeleaf/page/main/html.html b/src/test/resources/apps/thymeleaf/page/main/html.html new file mode 100644 index 0000000..35937bc --- /dev/null +++ b/src/test/resources/apps/thymeleaf/page/main/html.html @@ -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. +--> +<html data-th-with="page=${request.adaptTo(@org.apache.sling.scripting.thymeleaf.it.app.Page@class)}"> +<head> + <meta charset="UTF-8"/> + <title data-th-text="${page.title}">Page Title</title> +</head> +<body> +<p data-th-text="${page.name}">Page Name</p> +<p data-th-text="${page.path}">Page Path</p> +</body> +</html> diff --git a/src/test/resources/apps/thymeleaf/page/replace/html.html b/src/test/resources/apps/thymeleaf/page/replace/html.html new file mode 100644 index 0000000..1c9ea89 --- /dev/null +++ b/src/test/resources/apps/thymeleaf/page/replace/html.html @@ -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 data-th-replace="/apps/thymeleaf/page/fragments/head.html::default"> + <title>Thymeleaf Replace</title> +</head> +<body> +</body> +</html> diff --git a/src/test/resources/apps/thymeleaf/page/text/html.html b/src/test/resources/apps/thymeleaf/page/text/html.html new file mode 100644 index 0000000..b177352 --- /dev/null +++ b/src/test/resources/apps/thymeleaf/page/text/html.html @@ -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 data-th-text="${resource.getValueMap().get('title')}"></title> +</head> +<body> +<span id="name" data-th-text="${resource.name}"></span> +</body> +</html> diff --git a/src/test/resources/content/thymeleaf.json b/src/test/resources/content/thymeleaf.json new file mode 100644 index 0000000..b79a222 --- /dev/null +++ b/src/test/resources/content/thymeleaf.json @@ -0,0 +1,42 @@ +{ + "jcr:primaryType": "nt:unstructured", + "sling:resourceType": "thymeleaf/page/main", + "sling:resourceSuperType": "thymeleaf/page", + "title": "Apache Sling Scripting Thymeleaf", + "adaptto": { + "jcr:primaryType": "nt:unstructured", + "sling:resourceType": "thymeleaf/page/adaptto", + "sling:resourceSuperType": "thymeleaf/page", + "title": "Sling Models adaptTo()" + }, + "decoupled": { + "jcr:primaryType": "nt:unstructured", + "sling:resourceType": "thymeleaf/page/decoupled", + "sling:resourceSuperType": "thymeleaf/page", + "title": "Thymeleaf Decoupled Template Logic" + }, + "include": { + "jcr:primaryType": "nt:unstructured", + "sling:resourceType": "thymeleaf/page/include", + "sling:resourceSuperType": "thymeleaf/page", + "title": "Sling Include" + }, + "link": { + "jcr:primaryType": "nt:unstructured", + "sling:resourceType": "thymeleaf/page/link", + "sling:resourceSuperType": "thymeleaf/page", + "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" + } +} -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
