Search in sources :

Example 26 with Language

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

the class LanguageTestSupport method assertExpression.

/**
     * Asserts that the expression evaluates to one of the two given values
     */
protected void assertExpression(String expressionText, String expectedValue, String orThisExpectedValue) {
    Language language = assertResolveLanguage(getLanguageName());
    Expression expression = language.createExpression(expressionText);
    assertNotNull("No Expression could be created for text: " + expressionText + " language: " + language, expression);
    Object value;
    if (expectedValue != null) {
        value = expression.evaluate(exchange, expectedValue.getClass());
    } else {
        value = expression.evaluate(exchange, Object.class);
    }
    log.debug("Evaluated expression: " + expression + " on exchange: " + exchange + " result: " + value);
    assertTrue("Expression: " + expression + " on Exchange: " + exchange, expectedValue.equals(value) || orThisExpectedValue.equals(value));
}
Also used : Language(org.apache.camel.spi.Language) Expression(org.apache.camel.Expression)

Example 27 with Language

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

the class AbstractFeatureTest method testLanguage.

protected void testLanguage(String mainFeature, String language) throws Exception {
    LOG.info("Looking up CamelContext(myCamel) in OSGi Service Registry");
    installCamelFeature(mainFeature);
    CamelContext camelContext = getOsgiService(bundleContext, CamelContext.class, "(camel.context.name=myCamel)", 20000);
    assertNotNull("Cannot find CamelContext with name myCamel", camelContext);
    LOG.info("Getting Camel language: {}", language);
    Language lan = camelContext.resolveLanguage(language);
    assertNotNull("Cannot get language with name: " + language, lan);
    LOG.info("Found Camel language: {} instance: {} with className: {}", language, lan, lan.getClass());
}
Also used : CamelContext(org.apache.camel.CamelContext) Language(org.apache.camel.spi.Language)

Example 28 with Language

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

the class CamelTestSupport method assertResolveLanguage.

/**
     * Asserts that the language name can be resolved
     */
protected Language assertResolveLanguage(String languageName) {
    Language language = context.resolveLanguage(languageName);
    assertNotNull(language, "No language found for name: " + languageName);
    return language;
}
Also used : Language(org.apache.camel.spi.Language)

Example 29 with Language

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

the class CamelTestSupport method assertResolveLanguage.

/**
     * Asserts that the language name can be resolved
     */
protected Language assertResolveLanguage(String languageName) {
    Language language = context.resolveLanguage(languageName);
    assertNotNull("No language found for name: " + languageName, language);
    return language;
}
Also used : Language(org.apache.camel.spi.Language)

Example 30 with Language

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

the class JsonPathLanguageTest method testExpressionPojo.

@Test
public void testExpressionPojo() throws Exception {
    Exchange exchange = new DefaultExchange(context);
    Map pojo = new HashMap();
    pojo.put("kind", "full");
    pojo.put("type", "customer");
    exchange.getIn().setBody(pojo);
    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) HashMap(java.util.HashMap) Expression(org.apache.camel.Expression) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

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