Search in sources :

Example 31 with Language

use of org.apache.camel.spi.Language in project camel by apache.

the class JsonPathLanguageTest method testExpressionField.

@Test
public void testExpressionField() throws Exception {
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody(new File("src/test/resources/type.json"));
    Language lan = context.resolveLanguage("jsonpath");
    Expression exp = lan.createExpression("$.kind");
    String kind = exp.evaluate(exchange, String.class);
    assertNotNull(kind);
    assertEquals("full", kind);
    exp = lan.createExpression("$.type");
    String type = exp.evaluate(exchange, String.class);
    assertNotNull(type);
    assertEquals("customer", type);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Language(org.apache.camel.spi.Language) Expression(org.apache.camel.Expression) File(java.io.File) Test(org.junit.Test)

Example 32 with Language

use of org.apache.camel.spi.Language in project camel by apache.

the class SqlLanguageTest method testPredicateWithHeaderVariable.

@Test
public void testPredicateWithHeaderVariable() throws Exception {
    Language language = assertResolveLanguage(getLanguageName());
    assertPredicate(language.createPredicate("SELECT * FROM org.apache.camel.builder.sql.Person where name = :fooHeader"), exchange, true);
}
Also used : Language(org.apache.camel.spi.Language) SqlTest(org.apache.camel.builder.sql.SqlTest) Test(org.junit.Test)

Example 33 with Language

use of org.apache.camel.spi.Language in project camel by apache.

the class SqlLanguageTest method testExpressionWithHeaderVariable.

@Test
public void testExpressionWithHeaderVariable() throws Exception {
    Language language = assertResolveLanguage(getLanguageName());
    Expression expression = language.createExpression("SELECT * FROM org.apache.camel.builder.sql.Person where name = :fooHeader");
    List<?> value = expression.evaluate(exchange, List.class);
    assertEquals("List size", 1, value.size());
    for (Object person : value) {
        log.info("Found: " + person);
        assertEquals("name", "James", ((Person) person).getName());
    }
}
Also used : Language(org.apache.camel.spi.Language) Expression(org.apache.camel.Expression) SqlTest(org.apache.camel.builder.sql.SqlTest) Test(org.junit.Test)

Example 34 with Language

use of org.apache.camel.spi.Language in project camel by apache.

the class SqlLanguageTest method testPredicates.

@Test
public void testPredicates() throws Exception {
    Language language = assertResolveLanguage(getLanguageName());
    assertPredicate(language.createPredicate("SELECT * FROM org.apache.camel.builder.sql.Person where city = 'London'"), exchange, true);
    assertPredicate(language.createPredicate("SELECT * FROM org.apache.camel.builder.sql.Person where city = 'Manchester'"), exchange, false);
}
Also used : Language(org.apache.camel.spi.Language) SqlTest(org.apache.camel.builder.sql.SqlTest) Test(org.junit.Test)

Example 35 with Language

use of org.apache.camel.spi.Language in project camel by apache.

the class FileProcessStrategyFactory method getDefaultCommitRenamer.

private static GenericFileExpressionRenamer<File> getDefaultCommitRenamer(CamelContext context) {
    // use context to lookup language to let it be loose coupled
    Language language = context.resolveLanguage("file");
    Expression expression = language.createExpression("${file:parent}/.camel/${file:onlyname}");
    return new GenericFileExpressionRenamer<File>(expression);
}
Also used : Language(org.apache.camel.spi.Language) Expression(org.apache.camel.Expression)

Aggregations

Language (org.apache.camel.spi.Language)44 Expression (org.apache.camel.Expression)15 Test (org.junit.Test)13 Exchange (org.apache.camel.Exchange)6 CamelContext (org.apache.camel.CamelContext)5 Predicate (org.apache.camel.Predicate)5 NoSuchLanguageException (org.apache.camel.NoSuchLanguageException)4 SqlTest (org.apache.camel.builder.sql.SqlTest)4 DefaultExchange (org.apache.camel.impl.DefaultExchange)4 File (java.io.File)3 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)3 IOException (java.io.IOException)2 NoFactoryAvailableException (org.apache.camel.NoFactoryAvailableException)2 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)2 LanguageResolver (org.apache.camel.spi.LanguageResolver)2 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1