Search in sources :

Example 16 with Language

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

the class LanguageServiceTest method testNonSingletonLanguage.

public void testNonSingletonLanguage() throws Exception {
    Language tol = context.resolveLanguage("tokenize");
    assertNotNull(tol);
    assertEquals(1, context.getLanguageNames().size());
    // resolve again, should find another instance
    Language tol2 = context.resolveLanguage("tokenize");
    assertNotNull(tol2);
    assertNotSame(tol, tol2);
    assertEquals(1, context.getLanguageNames().size());
    context.stop();
    assertTrue(context.getLanguageNames().isEmpty());
}
Also used : Language(org.apache.camel.spi.Language)

Example 17 with Language

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

the class SqlLanguageTest method testExpression.

@Test
public void testExpression() throws Exception {
    Language language = assertResolveLanguage(getLanguageName());
    Expression expression = language.createExpression("SELECT * FROM org.apache.camel.builder.sql.Person where city = 'London'");
    List<?> value = expression.evaluate(exchange, List.class);
    assertEquals("List size", 2, value.size());
    for (Object person : value) {
        log.info("Found: " + person);
    }
}
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 18 with Language

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

the class JsonPathLanguageTest method testExpressionArray.

@Test
public void testExpressionArray() throws Exception {
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody(new File("src/test/resources/books.json"));
    Language lan = context.resolveLanguage("jsonpath");
    Expression exp = lan.createExpression("$.store.book[*].author");
    List<?> authors = exp.evaluate(exchange, List.class);
    log.debug("Authors {}", authors);
    assertNotNull(authors);
    assertEquals(2, authors.size());
    assertEquals("Nigel Rees", authors.get(0));
    assertEquals("Evelyn Waugh", authors.get(1));
    exp = lan.createExpression("$.store.bicycle.price");
    String price = exp.evaluate(exchange, String.class);
    assertEquals("Got a wrong result", "19.95", price);
}
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 19 with Language

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

the class JsonPathLanguageTest method testPredicate.

@Test
public void testPredicate() throws Exception {
    // Test books.json file
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody(new File("src/test/resources/books.json"));
    Language lan = context.resolveLanguage("jsonpath");
    Predicate pre = lan.createPredicate("$.store.book[?(@.price < 10)]");
    boolean cheap = pre.matches(exchange);
    assertTrue("Should have cheap books", cheap);
    pre = lan.createPredicate("$.store.book[?(@.price > 30)]");
    boolean expensive = pre.matches(exchange);
    assertFalse("Should not have expensive books", expensive);
}
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) File(java.io.File) Predicate(org.apache.camel.Predicate) Test(org.junit.Test)

Example 20 with Language

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

the class LanguageTestCommand method executeTest.

@Override
public Boolean executeTest(ITestConfig config, String language) throws Exception {
    logger.info("Getting Camel language: {}", language);
    Language lan = context.resolveLanguage(language);
    assertNotNull("Cannot get language with name: " + language, lan);
    logger.info("Found Camel language: {} instance: {} with className: {}", language, lan, lan.getClass());
    return true;
}
Also used : Language(org.apache.camel.spi.Language)

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