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