You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by rl...@apache.org on 2017/10/02 20:39:23 UTC
[12/50] [abbrv] ambari git commit: AMBARI-22066. Update unit tests to
test recursive variable replacements using VariableReplacementHelper (rlevas)
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/branch-feature-AMBARI-20859
Commit: b027837fab2f6552c64aadb41ffb5667a2acdd26
Parents: 3e1a5cb
Author: Robert Levas <rl...@hortonworks.com>
Authored: Wed Sep 27 08:05:45 2017 -0400
Committer: Robert Levas <rl...@hortonworks.com>
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 {