summaryrefslogtreecommitdiffstats
path: root/node-admin/src/test
diff options
context:
space:
mode:
authorHåkon Hallingstad <hakon@yahooinc.com>2022-01-07 14:34:11 +0100
committerHåkon Hallingstad <hakon@yahooinc.com>2022-01-07 15:26:01 +0100
commitf097589d3166ec545813a6bd52084c88974bfb9b (patch)
treeef44833b64eaf7dba392e688d8e50a336bf5908f /node-admin/src/test
parente89d9b57acfca329c7013b5ca4a6099b7bdffae3 (diff)
Adds a new template engine
Diffstat (limited to 'node-admin/src/test')
-rw-r--r--node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/template/TemplateFileTest.java56
-rw-r--r--node-admin/src/test/resources/template1.tmp10
-rw-r--r--node-admin/src/test/resources/template2.tmp4
3 files changed, 70 insertions, 0 deletions
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/template/TemplateFileTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/template/TemplateFileTest.java
new file mode 100644
index 00000000000..60330ecfb39
--- /dev/null
+++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/template/TemplateFileTest.java
@@ -0,0 +1,56 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.hosted.node.admin.task.util.template;
+
+import org.junit.jupiter.api.Test;
+
+import java.nio.file.Path;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * @author hakonhall
+ */
+class TemplateFileTest {
+ @Test
+ void verifyVariableSection() {
+ Form form = getForm("template1.tmp");
+ form.set("varname", "varvalue");
+ assertEquals("variable section 'varvalue'\n" +
+ "end of text\n", form.render());
+ }
+
+ @Test
+ void verifySimpleListSection() {
+ Form form = getForm("template1.tmp");
+ form.set("varname", "varvalue")
+ .add("listname")
+ .set("varname", "different varvalue")
+ .set("varname2", "varvalue2");
+ assertEquals("variable section 'varvalue'\n" +
+ "same variable section 'different varvalue'\n" +
+ "different variable section 'varvalue2'\n" +
+ "between ends\n" +
+ "end of text\n", form.render());
+ }
+
+ @Test
+ void verifyNestedListSection() {
+ Form form = getForm("template2.tmp");
+ Form A0 = form.add("listA");
+ Form A0B0 = A0.add("listB");
+ Form A0B1 = A0.add("listB");
+
+ Form A1 = form.add("listA");
+ Form A1B0 = A1.add("listB");
+ assertEquals("body A\n" +
+ "body B\n" +
+ "body B\n" +
+ "body A\n" +
+ "body B\n",
+ form.render());
+ }
+
+ private Form getForm(String filename) {
+ return TemplateFile.read(Path.of("src/test/resources/" + filename)).instantiate();
+ }
+} \ No newline at end of file
diff --git a/node-admin/src/test/resources/template1.tmp b/node-admin/src/test/resources/template1.tmp
new file mode 100644
index 00000000000..a020dbb0739
--- /dev/null
+++ b/node-admin/src/test/resources/template1.tmp
@@ -0,0 +1,10 @@
+variable section '%{=varname}'
+%{list listname}
+same variable section '%{=varname}'
+different variable section '%{=varname2}'
+%{list innerlistname}
+inner list text
+%{end}
+between ends
+%{end}
+end of text
diff --git a/node-admin/src/test/resources/template2.tmp b/node-admin/src/test/resources/template2.tmp
new file mode 100644
index 00000000000..d36cb4a4a48
--- /dev/null
+++ b/node-admin/src/test/resources/template2.tmp
@@ -0,0 +1,4 @@
+%{list listA}body A
+%{list listB}body B
+%{end}
+%{end}