Search in sources :

Example 1 with Expression

use of org.apache.camel.Expression 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 2 with Expression

use of org.apache.camel.Expression 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 3 with Expression

use of org.apache.camel.Expression 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)

Example 4 with Expression

use of org.apache.camel.Expression 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 5 with Expression

use of org.apache.camel.Expression in project camel by apache.

the class InputParameter method parseValueExpression.

private void parseValueExpression(Token valueSrcToken) {
    if (SSPTParserConstants.SIMPLE_EXP_TOKEN == valueSrcToken.kind) {
        final Expression exp = ExpressionBuilder.simpleExpression(valueSrcToken.toString());
        this.valueExtractor = new ValueExtractor() {

            @Override
            public Object eval(Exchange exchange, Object container) {
                return exp.evaluate(exchange, Object.class);
            }
        };
    } else if (SSPTParserConstants.PARAMETER_POS_TOKEN == valueSrcToken.kind) {
        //remove leading :#
        final String mapKey = valueSrcToken.toString().substring(2);
        this.valueExtractor = new ValueExtractor() {

            @Override
            public Object eval(Exchange exchange, Object container) {
                return ((Map) container).get(mapKey);
            }
        };
    }
}
Also used : Exchange(org.apache.camel.Exchange) Expression(org.apache.camel.Expression) Map(java.util.Map)

Aggregations

Expression (org.apache.camel.Expression)184 Exchange (org.apache.camel.Exchange)44 Processor (org.apache.camel.Processor)24 Predicate (org.apache.camel.Predicate)22 DefaultExchange (org.apache.camel.impl.DefaultExchange)21 AggregationStrategy (org.apache.camel.processor.aggregate.AggregationStrategy)18 Language (org.apache.camel.spi.Language)16 ArrayList (java.util.ArrayList)15 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)15 AggregateProcessor (org.apache.camel.processor.aggregate.AggregateProcessor)15 BodyInAggregatingStrategy (org.apache.camel.processor.BodyInAggregatingStrategy)14 SendProcessor (org.apache.camel.processor.SendProcessor)14 Test (org.junit.Test)8 SimpleParserException (org.apache.camel.language.simple.types.SimpleParserException)7 File (java.io.File)4 ExecutorService (java.util.concurrent.ExecutorService)4 SimpleIllegalSyntaxException (org.apache.camel.language.simple.types.SimpleIllegalSyntaxException)4 HashMap (java.util.HashMap)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 CamelExchangeException (org.apache.camel.CamelExchangeException)3