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));
}
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());
}
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;
}
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;
}
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);
}
Aggregations