use of org.apache.commons.lang3.text.StrLookup in project dropwizard by dropwizard.
the class SubstitutingSourceProviderTest method shouldSubstituteOnlyExistingVariables.
@Test
public void shouldSubstituteOnlyExistingVariables() throws IOException {
StrLookup<?> dummyLookup = new StrLookup<Object>() {
@Override
public String lookup(String key) {
return null;
}
};
SubstitutingSourceProvider provider = new SubstitutingSourceProvider(new DummySourceProvider(), new StrSubstitutor(dummyLookup));
String results = new String(ByteStreams.toByteArray(provider.open("foo: ${bar}")), StandardCharsets.UTF_8);
assertThat(results).isEqualTo("foo: ${bar}");
}
use of org.apache.commons.lang3.text.StrLookup in project dropwizard by dropwizard.
the class SubstitutingSourceProviderTest method shouldSubstituteWithDefaultValue.
@Test
public void shouldSubstituteWithDefaultValue() throws IOException {
StrLookup<?> dummyLookup = new StrLookup<Object>() {
@Override
public String lookup(String key) {
return null;
}
};
SubstitutingSourceProvider provider = new SubstitutingSourceProvider(new DummySourceProvider(), new StrSubstitutor(dummyLookup));
String results = new String(ByteStreams.toByteArray(provider.open("foo: ${bar:-default}")), StandardCharsets.UTF_8);
assertThat(results).isEqualTo("foo: default");
}
use of org.apache.commons.lang3.text.StrLookup in project dropwizard by dropwizard.
the class SubstitutingSourceProviderTest method shouldSubstituteCorrectly.
@Test
public void shouldSubstituteCorrectly() throws IOException {
StrLookup<?> dummyLookup = new StrLookup<Object>() {
@Override
public String lookup(String key) {
return "baz";
}
};
DummySourceProvider dummyProvider = new DummySourceProvider();
SubstitutingSourceProvider provider = new SubstitutingSourceProvider(dummyProvider, new StrSubstitutor(dummyLookup));
String results = new String(ByteStreams.toByteArray(provider.open("foo: ${bar}")), StandardCharsets.UTF_8);
assertThat(results).isEqualTo("foo: baz");
// ensure that opened streams are closed
try {
dummyProvider.lastStream.read();
failBecauseExceptionWasNotThrown(IOException.class);
} catch (IOException e) {
assertThat(e).hasMessage("Stream closed");
}
}
use of org.apache.commons.lang3.text.StrLookup in project jirm by agentgt.
the class SqlWriterStrategy method replacePropertyPaths.
public String replacePropertyPaths(final SqlObjectDefinition<?> definition, final String sql) {
StrLookup<String> lookup = new StrLookup<String>() {
@Override
public String lookup(String key) {
Optional<String> p = parameterPathToSql(definition, key);
check.state(p.isPresent(), "Invalid object path: {}", key);
return p.get();
}
};
StrSubstitutor s = new StrSubstitutor(lookup, "{{", "}}", '$');
String result = s.replace(sql);
return result;
}
use of org.apache.commons.lang3.text.StrLookup in project jirm by agentgt.
the class SqlWriterStrategy method replaceProperties.
public String replaceProperties(final SqlObjectDefinition<?> definition, final String sql) {
StrLookup<String> lookup = new StrLookup<String>() {
@Override
public String lookup(String key) {
Optional<String> sqlName = definition.parameterNameToSql(key);
check.state(sqlName.isPresent(), "Property: {} not found in object.", key);
return sqlName.get();
}
};
StrSubstitutor s = new StrSubstitutor(lookup, "{{", "}}", '$');
String result = s.replace(sql);
return result;
}
Aggregations