[java-shib-attribute] branch dev/IDP-2226 updated: Add test of getting a template from the classpath

Rod Widdowson rdw at steadingsoftware.com
Tue Jan 30 15:22:32 UTC 2024


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

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

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

The following commit(s) were added to refs/heads/dev/IDP-2226 by this push:
     new aa01ff430 Add test of getting a template from the classpath
aa01ff430 is described below

commit aa01ff4306dd4eb7d85cb60ee853c94aa06216b3
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Jan 30 15:21:46 2024 +0000

    Add test of getting a template from the classpath
---
 .../attribute/resolver/dc/impl/ThymeLeafSandbox.java | 20 ++++++++++++++++++++
 .../idp/attribute/resolver/impl/dc/TestTemplate.tl   |  1 +
 2 files changed, 21 insertions(+)

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
index b494598b3..7e6d9e6ab 100644
--- 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
@@ -35,9 +35,12 @@ import org.thymeleaf.standard.StandardDialect;
 import org.thymeleaf.standard.inline.AbstractStandardInliner;
 import org.thymeleaf.standard.processor.StandardInliningTextProcessor;
 import org.thymeleaf.templatemode.TemplateMode;
+import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;
 import org.thymeleaf.templateresolver.StringTemplateResolver;
+import org.thymeleaf.templateresolver.WebApplicationTemplateResolver;
 
 import net.shibboleth.shared.collection.CollectionSupport;
+import net.shibboleth.shared.xml.ClasspathResolver;
 
 public class ThymeLeafSandbox {
 
@@ -153,4 +156,21 @@ public class ThymeLeafSandbox {
 	                new SandboxTemplateBoundariesProcessor(TemplateMode.TEXT));
 	    }
 	}
+
+	@Test
+	public void testClassPathNameLookup() {
+	    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 ClassLoaderTemplateResolver());
+
+        final TemplateSpec spec = new TemplateSpec("/net/shibboleth/idp/attribute/resolver/impl/dc/TestTemplate.tl", TemplateMode.TEXT);
+
+        final String output = engine.process(spec, ctx);
+        assertEquals(output, "Nibble a happy " + map.get("warthog") + " says " + obj.getThing1() + " or " +  obj.getThing2());
+    }
+
 }
diff --git a/shib-attribute-resolver-impl/src/test/resources/net/shibboleth/idp/attribute/resolver/impl/dc/TestTemplate.tl b/shib-attribute-resolver-impl/src/test/resources/net/shibboleth/idp/attribute/resolver/impl/dc/TestTemplate.tl
new file mode 100644
index 000000000..f5bb60e34
--- /dev/null
+++ b/shib-attribute-resolver-impl/src/test/resources/net/shibboleth/idp/attribute/resolver/impl/dc/TestTemplate.tl
@@ -0,0 +1 @@
+Nibble a happy [[${warthog}]] says [[${thing.thing1}]] or [[${thing.thing2}]]
\ No newline at end of file

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


More information about the commits mailing list