use of org.apache.commons.text.StringSubstitutor in project dropwizard by dropwizard.
the class SubstitutingSourceProviderTest method shouldSubstituteWithDefaultValue.
@Test
void shouldSubstituteWithDefaultValue() throws IOException {
StringLookup dummyLookup = (x) -> null;
SubstitutingSourceProvider provider = new SubstitutingSourceProvider(new DummySourceProvider(), new StringSubstitutor(dummyLookup));
assertThat(provider.open("foo: ${bar:-default}")).hasSameContentAs(new ByteArrayInputStream("foo: default".getBytes(StandardCharsets.UTF_8)));
}
use of org.apache.commons.text.StringSubstitutor in project dropwizard by dropwizard.
the class SubstitutingSourceProviderTest method shouldSubstituteOnlyExistingVariables.
@Test
void shouldSubstituteOnlyExistingVariables() throws IOException {
StringLookup dummyLookup = (x) -> null;
SubstitutingSourceProvider provider = new SubstitutingSourceProvider(new DummySourceProvider(), new StringSubstitutor(dummyLookup));
assertThat(provider.open("foo: ${bar}")).hasSameContentAs(new ByteArrayInputStream("foo: ${bar}".getBytes(StandardCharsets.UTF_8)));
}
use of org.apache.commons.text.StringSubstitutor in project dropwizard by dropwizard.
the class DefaultLoggingFactoryTest method testConfigure.
@Test
void testConfigure(@TempDir Path tempDir) throws Exception {
final StringSubstitutor substitutor = new StringSubstitutor(Maps.of("new_app", tempDir.resolve("example-new-app").toFile().getAbsolutePath(), "new_app_not_additive", tempDir.resolve("example-new-app-not-additive").toFile().getAbsolutePath(), "default", tempDir.resolve("example").toFile().getAbsolutePath()));
DefaultLoggingFactory config = null;
try {
config = factory.build(new SubstitutingSourceProvider(configurationSourceProvider, substitutor), "yaml/logging_advanced.yml");
config.configure(new MetricRegistry(), "test-logger");
LoggerFactory.getLogger("com.example.app").debug("Application debug log");
LoggerFactory.getLogger("com.example.app").info("Application log");
LoggerFactory.getLogger("com.example.newApp").debug("New application debug log");
LoggerFactory.getLogger("com.example.newApp").info("New application info log");
LoggerFactory.getLogger("com.example.legacyApp").debug("Legacy application debug log");
LoggerFactory.getLogger("com.example.legacyApp").info("Legacy application info log");
LoggerFactory.getLogger("com.example.notAdditive").debug("Not additive application debug log");
LoggerFactory.getLogger("com.example.notAdditive").info("Not additive application info log");
config.stop();
config.reset();
assertThat(Files.readAllLines(tempDir.resolve("example.log"))).containsOnly("INFO com.example.app: Application log", "DEBUG com.example.newApp: New application debug log", "INFO com.example.newApp: New application info log", "DEBUG com.example.legacyApp: Legacy application debug log", "INFO com.example.legacyApp: Legacy application info log");
assertThat(Files.readAllLines(tempDir.resolve("example-new-app.log"))).containsOnly("DEBUG com.example.newApp: New application debug log", "INFO com.example.newApp: New application info log");
assertThat(Files.readAllLines(tempDir.resolve("example-new-app-not-additive.log"))).containsOnly("DEBUG com.example.notAdditive: Not additive application debug log", "INFO com.example.notAdditive: Not additive application info log");
} finally {
if (config != null) {
config.reset();
}
}
}
use of org.apache.commons.text.StringSubstitutor in project dropwizard by dropwizard.
the class TcpSocketAppenderFactoryTest method testTestTcpLogging.
@Test
void testTestTcpLogging() throws Exception {
try (ServerSocket serverSocket = createServerSocket();
TcpServer tcpServer = new TcpServer(serverSocket)) {
Future<List<String>> receivedMessages = tcpServer.receive();
DefaultLoggingFactory loggingFactory = yamlConfigurationFactory.build(new SubstitutingSourceProvider(new ResourceConfigurationSourceProvider(), new StringSubstitutor(Collections.singletonMap("tcp.server.port", serverSocket.getLocalPort()))), "yaml/logging-tcp.yml");
loggingFactory.configure(new MetricRegistry(), "tcp-test");
List<String> loggedMessages = generateLogs(LoggerFactory.getLogger("com.example.app"));
loggingFactory.reset();
assertThat(receivedMessages.get(1, TimeUnit.MINUTES)).hasSize(100).allSatisfy(s -> assertThat(s).startsWith("INFO")).extracting(s -> s.substring(s.lastIndexOf("com.example.app: ") + "com.example.app: ".length())).containsExactlyElementsOf(loggedMessages);
}
}
use of org.apache.commons.text.StringSubstitutor in project OpenRefine by OpenRefine.
the class DBExtensionTestUtils method getJDBCUrl.
public static String getJDBCUrl(DatabaseConfiguration dbConfig) {
Map<String, Object> substitutes = new HashMap<String, Object>();
substitutes.put("dbType", dbConfig.getDatabaseType());
substitutes.put("host", dbConfig.getDatabaseHost());
substitutes.put("port", "" + dbConfig.getDatabasePort());
substitutes.put("dbName", dbConfig.getDatabaseName());
substitutes.put("useSSL", dbConfig.isUseSSL());
String urlTemplate = "jdbc:${dbType}://${host}:${port}/${dbName}?useSSL=${useSSL}";
StringSubstitutor strSub = new StringSubstitutor(substitutes);
return strSub.replace(urlTemplate);
}
Aggregations