@Before public void setup() { configTransformer = new ConfigTransformer(Collections.singletonMap("test", new TestConfigProvider())); }
@Test public void testReplaceMultipleVariablesInValue() throws Exception { ConfigTransformerResult result = configTransformer.transform(Collections.singletonMap(MY_KEY, "hello, ${test:testPath:testKey}; goodbye, ${test:testPath:testKeyWithTTL}!!!")); Map<String, String> data = result.data(); assertEquals("hello, testResult; goodbye, testResultWithTTL!!!", data.get(MY_KEY)); }
List<ConfigVariable> vars = getVars(config.getValue(), DEFAULT_PATTERN); for (ConfigVariable var : vars) { Map<String, Set<String>> keysByPath = keysByProvider.computeIfAbsent(var.providerName, k -> new HashMap<>()); data.put(config.getKey(), replace(lookupsByProvider, config.getValue(), DEFAULT_PATTERN));
@Test public void testNoReplacement() throws Exception { ConfigTransformerResult result = configTransformer.transform(Collections.singletonMap(MY_KEY, "${test:testPath:missingKey}")); Map<String, String> data = result.data(); assertEquals("${test:testPath:missingKey}", data.get(MY_KEY)); }
public WorkerConfigTransformer(Worker worker, Map<String, ConfigProvider> configProviders) { this.worker = worker; this.configTransformer = new ConfigTransformer(configProviders); }
@Test public void testSingleLevelOfIndirection() throws Exception { ConfigTransformerResult result = configTransformer.transform(Collections.singletonMap(MY_KEY, "${test:testPath:testIndirection}")); Map<String, String> data = result.data(); assertEquals("${test:testPath:testResult}", data.get(MY_KEY)); }
@Test public void testReplaceVariableWithTTL() throws Exception { ConfigTransformerResult result = configTransformer.transform(Collections.singletonMap(MY_KEY, "${test:testPath:testKeyWithTTL}")); Map<String, String> data = result.data(); Map<String, Long> ttls = result.ttls(); assertEquals(TEST_RESULT_WITH_TTL, data.get(MY_KEY)); assertEquals(1L, ttls.get(TEST_PATH).longValue()); }
@Test public void testReplaceVariableNoPath() throws Exception { ConfigTransformerResult result = configTransformer.transform(Collections.singletonMap(MY_KEY, "${test:testKey}")); Map<String, String> data = result.data(); Map<String, Long> ttls = result.ttls(); assertEquals(TEST_RESULT_NO_PATH, data.get(MY_KEY)); assertTrue(ttls.isEmpty()); }
@Test public void testNullConfigValue() throws Exception { ConfigTransformerResult result = configTransformer.transform(Collections.singletonMap(MY_KEY, null)); Map<String, String> data = result.data(); Map<String, Long> ttls = result.ttls(); assertNull(data.get(MY_KEY)); assertTrue(ttls.isEmpty()); }
@Test public void testReplaceVariable() throws Exception { ConfigTransformerResult result = configTransformer.transform(Collections.singletonMap(MY_KEY, "${test:testPath:testKey}")); Map<String, String> data = result.data(); Map<String, Long> ttls = result.ttls(); assertEquals(TEST_RESULT, data.get(MY_KEY)); assertTrue(ttls.isEmpty()); }
public Map<String, String> transform(String connectorName, Map<String, String> configs) { if (configs == null) return null; ConfigTransformerResult result = configTransformer.transform(configs); if (connectorName != null) { scheduleReload(connectorName, result.ttls()); } return result.data(); }