Search in sources :

Example 21 with Language

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

the class CamelTestSupport method assertPredicate.

/**
     * Asserts that the given language name and predicate expression evaluates
     * to the expected value on the message exchange
     */
protected void assertPredicate(String languageName, String expressionText, Exchange exchange, boolean expected) {
    Language language = assertResolveLanguage(languageName);
    Predicate predicate = language.createPredicate(expressionText);
    assertNotNull(predicate, "No Predicate could be created for text: " + expressionText + " language: " + language);
    assertPredicate(predicate, exchange, expected);
}
Also used : Language(org.apache.camel.spi.Language) Predicate(org.apache.camel.Predicate)

Example 22 with Language

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

the class CamelTestSupport method assertExpression.

/**
     * Asserts that the given language name and expression evaluates to the
     * given value on a specific exchange
     */
protected void assertExpression(Exchange exchange, String languageName, String expressionText, Object expectedValue) {
    Language language = assertResolveLanguage(languageName);
    Expression expression = language.createExpression(expressionText);
    assertNotNull(expression, "No Expression could be created for text: " + expressionText + " language: " + language);
    assertExpression(expression, exchange, expectedValue);
}
Also used : Language(org.apache.camel.spi.Language) Expression(org.apache.camel.Expression)

Example 23 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(expression, "No Expression could be created for text: " + expressionText + " language: " + language);
    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(expectedValue.equals(value) || orThisExpectedValue.equals(value), "Expression: " + expression + " on Exchange: " + exchange);
}
Also used : Language(org.apache.camel.spi.Language) Expression(org.apache.camel.Expression)

Example 24 with Language

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

the class CamelTestSupport method assertPredicate.

/**
     * Asserts that the given language name and predicate expression evaluates
     * to the expected value on the message exchange
     */
protected void assertPredicate(String languageName, String expressionText, Exchange exchange, boolean expected) {
    Language language = assertResolveLanguage(languageName);
    Predicate predicate = language.createPredicate(expressionText);
    assertNotNull("No Predicate could be created for text: " + expressionText + " language: " + language, predicate);
    assertPredicate(predicate, exchange, expected);
}
Also used : Language(org.apache.camel.spi.Language) Predicate(org.apache.camel.Predicate)

Example 25 with Language

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

the class CamelTestSupport method assertExpression.

/**
     * Asserts that the given language name and expression evaluates to the
     * given value on a specific exchange
     */
protected void assertExpression(Exchange exchange, String languageName, String expressionText, Object expectedValue) {
    Language language = assertResolveLanguage(languageName);
    Expression expression = language.createExpression(expressionText);
    assertNotNull("No Expression could be created for text: " + expressionText + " language: " + language, expression);
    assertExpression(expression, exchange, expectedValue);
}
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