Util { public static String expandVars(String env) { OrderedProperties ops = new OrderedProperties(); ops.addStringPairs(env); Map<String, String> map = ops.asMap(); StringBuilder resultBuilder = new StringBuilder(); for (Map.Entry<String, String> entry: map.entrySet()) { resultBuilder.append(entry.getKey() + "=" + expandVar(entry.getValue(), ops.asMap()) + "\n"); } return resultBuilder.toString(); }  static Future<T> async(Vertx vertx, Supplier<T> supplier); static Future<Void> waitFor(Vertx vertx, String logContext, String logState, long pollIntervalMs, long timeoutMs, BooleanSupplier completed); static Future<Void> waitFor(Vertx vertx, String logContext, String logState, long pollIntervalMs, long timeoutMs, BooleanSupplier completed,
                                       Predicate<Throwable> failOnError); static Map<String, String> parseMap(String str); static RuntimeException missingSecretException(String namespace, String secretName); static File createFileStore(String prefix, String suffix, byte[] bytes); static byte[] decodeFromSecret(Secret secret, String key); static File createFileTrustStore(String prefix, String suffix, X509Certificate certificate, char[] password); static void printEnvInfo(); static String maskPassword(String key, String value); @SafeVarargs static Map<String, String> mergeLabelsOrAnnotations(Map<String, String> base, Map<String, String>... overrides); static Future<T> kafkaFutureToVertxFuture(Vertx vertx, KafkaFuture<T> kf); static ConfigResource getBrokersConfig(int podId); static ConfigResource getBrokersLogging(int podId); static ConfigResource getBrokersConfig(String podId); static ConfigResource getBrokersLogging(String podId); static String stringHash(String toBeHashed); static String getLoggingDynamicallyUnmodifiableEntries(String loggingConfiguration); static String expandVars(String env); static String expandVar(String value, Map<String, String> env);  }
@Test public void testVarExpansion() { String input = "log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender\n" + "log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout\n" + "log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %p %m (%c) [%t]%n\n" + "mirrormaker.root.logger=INFO\n" + "log4j.rootLogger=${mirrormaker.root.logger}, CONSOLE"; String expectedOutput = "log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender\n" + "log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout\n" + "log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %p %m (%c) [%t]%n\n" + "mirrormaker.root.logger=INFO\n" + "log4j.rootLogger=INFO, CONSOLE\n"; String result = Util.expandVars(input); assertThat(result, is(expectedOutput)); }