Repository: ambari Updated Branches: refs/heads/trunk 3e1a5cb7c -> b027837fa
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/b027837f Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b027837f Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b027837f Branch: refs/heads/trunk Commit: b027837fab2f6552c64aadb41ffb5667a2acdd26 Parents: 3e1a5cb Author: Robert Levas <[email protected]> Authored: Wed Sep 27 08:05:45 2017 -0400 Committer: Robert Levas <[email protected]> Committed: Wed Sep 27 08:05:45 2017 -0400 ---------------------------------------------------------------------- .../kerberos/VariableReplacementHelperTest.java | 35 ++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/b027837f/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 e46294a..d724f03 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 @@ -33,9 +33,9 @@ import org.junit.experimental.categories.Category; import junit.framework.Assert; -@Category({ category.KerberosTest.class}) +@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 {
