Search in sources :

Example 1 with StrLookup

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}");
}
Also used : StrSubstitutor(org.apache.commons.lang3.text.StrSubstitutor) StrLookup(org.apache.commons.lang3.text.StrLookup) Test(org.junit.Test)

Example 2 with StrLookup

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");
}
Also used : StrSubstitutor(org.apache.commons.lang3.text.StrSubstitutor) StrLookup(org.apache.commons.lang3.text.StrLookup) Test(org.junit.Test)

Example 3 with StrLookup

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");
    }
}
Also used : StrSubstitutor(org.apache.commons.lang3.text.StrSubstitutor) StrLookup(org.apache.commons.lang3.text.StrLookup) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with StrLookup

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;
}
Also used : StrSubstitutor(org.apache.commons.lang3.text.StrSubstitutor) StrLookup(org.apache.commons.lang3.text.StrLookup)

Example 5 with StrLookup

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;
}
Also used : StrSubstitutor(org.apache.commons.lang3.text.StrSubstitutor) StrLookup(org.apache.commons.lang3.text.StrLookup)

Aggregations

StrSubstitutor (org.apache.commons.lang3.text.StrSubstitutor)7 StrLookup (org.apache.commons.lang3.text.StrLookup)5 Test (org.junit.Test)3 IOException (java.io.IOException)1 Realm (org.apache.catalina.Realm)1 Activate (org.apache.felix.scr.annotations.Activate)1 KiWiConfiguration (org.apache.marmotta.kiwi.config.KiWiConfiguration)1 KiWiDialect (org.apache.marmotta.kiwi.persistence.KiWiDialect)1 H2Dialect (org.apache.marmotta.kiwi.persistence.h2.H2Dialect)1 MySQLDialect (org.apache.marmotta.kiwi.persistence.mysql.MySQLDialect)1 PostgreSQLDialect (org.apache.marmotta.kiwi.persistence.pgsql.PostgreSQLDialect)1 KiWiStore (org.apache.marmotta.kiwi.sail.KiWiStore)1 KiWiSparqlSail (org.apache.marmotta.kiwi.sparql.sail.KiWiSparqlSail)1 Filter (org.apache.xbean.finder.filter.Filter)1 ObjectRecipe (org.apache.xbean.recipe.ObjectRecipe)1 SailRepository (org.openrdf.repository.sail.SailRepository)1 BundleContext (org.osgi.framework.BundleContext)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1