Repository: ambari Updated Branches: refs/heads/branch-2.6 3b8b8d366 -> 45f1e6be5
AMBARI-22066. Update unit tests to test recursive variable replacements using VariableReplacementHelper (rlevas) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/45f1e6be Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/45f1e6be Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/45f1e6be Branch: refs/heads/branch-2.6 Commit: 45f1e6be51e6b6c838245bc6a464fcb6fee36769 Parents: 3b8b8d3 Author: Robert Levas <[email protected]> Authored: Wed Sep 27 08:06:41 2017 -0400 Committer: Robert Levas <[email protected]> Committed: Wed Sep 27 08:06:41 2017 -0400 ---------------------------------------------------------------------- .../kerberos/VariableReplacementHelperTest.java | 33 +++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/45f1e6be/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/VariableReplacementHelperTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/VariableReplacementHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/VariableReplacementHelperTest.java index 159ad69..e1575ec 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/VariableReplacementHelperTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/VariableReplacementHelperTest.java @@ -35,7 +35,7 @@ import java.util.Map; @Category({category.KerberosTest.class}) public class VariableReplacementHelperTest { - VariableReplacementHelper helper = new VariableReplacementHelper(); + private VariableReplacementHelper helper = new VariableReplacementHelper(); @Test public void testReplaceVariables() throws AmbariException { @@ -136,6 +136,37 @@ public class VariableReplacementHelperTest { // This is expected... } } + @Test + public void testReplaceVariablesRecursive() throws AmbariException { + Map<String, Map<String, String>> configurations = new HashMap<String, Map<String, String>>() { + { + put("", new HashMap<String, String>()); + + put("data", new HashMap<String, String>() {{ + put("data_host1.example.com", "host 1 data"); + put("data_host2.example.com", "host 2 data"); + put("data_host3.example.com", "host 3 data"); + }}); + } + }; + + configurations.get("").put("h", "host"); + + // Shows ${h} was replaced + assertEquals("${data/data_${host}}", helper.replaceVariables("${data/data_${${h}}}", configurations)); + + // data_host.example.com does not exist in the data configuration + configurations.get("").put("host", "host.example.com"); + + // Shows ${host} was replaced + assertEquals("${data/data_host.example.com}", helper.replaceVariables("${data/data_${${h}}}", configurations)); + + + for (int i = 1; i <= 3; i++) { + configurations.get("").put("host", String.format("host%d.example.com", i)); + assertEquals(String.format("host %d data", i), helper.replaceVariables("${data/data_${${h}}}", configurations)); + } + } @Test public void testReplaceComplicatedVariables() throws AmbariException {
