[java-shib-attribute] 01/02: Add sandbox for testing ThymeLeaf

Rod Widdowson rdw at steadingsoftware.com
Sun Jan 21 16:21:00 UTC 2024


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch dev/IDP-226
in repository java-shib-attribute.

View the commit online:
http://git.shibboleth.net/view/?p=java-shib-attribute.git;a=commit;h=c0fad335524072701ed4a990c7e587bd20431fca

commit c0fad335524072701ed4a990c7e587bd20431fca
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Jan 19 14:49:05 2024 +0000

    Add sandbox for testing ThymeLeaf
---
 shib-attribute-resolver-impl/pom.xml               |  5 +++
 .../resolver/dc/impl/ThymeLeafSandbox.java         | 49 ++++++++++++++++++++++
 .../src/test/resources/logback-test.xml            |  1 +
 3 files changed, 55 insertions(+)

diff --git a/shib-attribute-resolver-impl/pom.xml b/shib-attribute-resolver-impl/pom.xml
index 4b169015d..40cefbd47 100644
--- a/shib-attribute-resolver-impl/pom.xml
+++ b/shib-attribute-resolver-impl/pom.xml
@@ -63,6 +63,11 @@
             <artifactId>shib-velocity</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.thymeleaf</groupId>
+            <artifactId>thymeleaf</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>io.dropwizard.metrics</groupId>
             <artifactId>metrics-core</artifactId>
diff --git a/shib-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/dc/impl/ThymeLeafSandbox.java b/shib-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/dc/impl/ThymeLeafSandbox.java
new file mode 100644
index 000000000..f8ed4bedd
--- /dev/null
+++ b/shib-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/dc/impl/ThymeLeafSandbox.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed 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 net.shibboleth.idp.attribute.resolver.dc.impl;
+import static org.testng.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.testng.annotations.Test;
+import org.thymeleaf.TemplateEngine;
+import org.thymeleaf.TemplateSpec;
+import org.thymeleaf.context.Context;
+import org.thymeleaf.templatemode.TemplateMode;
+import org.thymeleaf.templateresolver.StringTemplateResolver;
+
+public class ThymeLeafSandbox {
+
+	@Test public void testEngine() {
+		final String templateStr = "Nibble a happy [(${warthog})] says [(${thing.thing1})] or [( ${thing.thing2})]";
+		final Map<String, Object> map = new HashMap<>(2);
+		map.put("warthog","warthog");
+		var obj = new MyObject();
+		map.put("thing", obj);
+
+		final Context ctx = new Context(null, map);
+		final TemplateEngine engine = new TemplateEngine();
+		engine.setTemplateResolver(new StringTemplateResolver());
+		final TemplateSpec spec = new TemplateSpec(templateStr, TemplateMode.TEXT);
+
+		final String output = engine.process(spec, ctx);
+		assertEquals(output, "Nibble a happy " + map.get("warthog") + " says " + obj.getThing1() + " or " +  obj.getThing2());
+	}
+
+	private class MyObject {
+		public String getThing1() { return "Thing1"; }
+		public String getThing2() { return "Thing2"; }
+	}
+}
diff --git a/shib-attribute-resolver-impl/src/test/resources/logback-test.xml b/shib-attribute-resolver-impl/src/test/resources/logback-test.xml
index b36b5fe54..5d018a020 100644
--- a/shib-attribute-resolver-impl/src/test/resources/logback-test.xml
+++ b/shib-attribute-resolver-impl/src/test/resources/logback-test.xml
@@ -4,6 +4,7 @@
     <logger name="net.shibboleth.idp.attribute" level="DEBUG"/>
 
     <logger name="net.shibboleth.idp.saml" level="DEBUG"/>
+    <logger name="org.thymeleaf" level="DEBUG"/>
     
     <logger name="org.apache.hc" level="WARN"/>
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list