use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class ExchangeHelperTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
exchange = new DefaultExchange(new DefaultCamelContext());
exchange.setProperty("foo", 123);
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class ExpressionListComparatorTest method testExpressionListComparator.
public void testExpressionListComparator() {
List<Expression> list = new ArrayList<Expression>();
list.add(new MyFooExpression());
list.add(new MyBarExpression());
ExpressionListComparator comp = new ExpressionListComparator(list);
Exchange e1 = new DefaultExchange(context);
Exchange e2 = new DefaultExchange(context);
int out = comp.compare(e1, e2);
assertEquals(0, out);
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class DefaultValidationErrorHandlerTest method testHandleErrorsResult.
public void testHandleErrorsResult() throws Exception {
DefaultValidationErrorHandler eh = new DefaultValidationErrorHandler();
eh.error(new SAXParseException("foo", createLocator(3, 5)));
eh.error(new SAXParseException("bar", createLocator(9, 12)));
assertEquals(false, eh.isValid());
Exchange exchange = new DefaultExchange(context);
try {
eh.handleErrors(exchange, createScheme(), new SAXResult());
fail("Should have thrown an exception");
} catch (SchemaValidationException e) {
assertEquals(2, e.getErrors().size());
assertEquals(0, e.getFatalErrors().size());
assertEquals(0, e.getWarnings().size());
assertNotNull(e.getSchema());
assertNotNull(e.getExchange());
assertTrue(e.getMessage().startsWith("Validation failed for: org.apache.camel.processor.validation.DefaultValidationErrorHandlerTest"));
assertTrue(e.getMessage().contains("errors: ["));
assertTrue(e.getMessage().contains("org.xml.sax.SAXParseException: foo, Line : 3, Column : 5"));
assertTrue(e.getMessage().contains("org.xml.sax.SAXParseException: bar, Line : 9, Column : 12"));
assertTrue(e.getMessage().contains("Exchange[]"));
}
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class XPathBuilder method evaluate.
/**
* Evaluates the given xpath using the provided body.
* <p/>
* The evaluation uses by default {@link javax.xml.xpath.XPathConstants#NODESET} as the type
* used during xpath evaluation. The output from xpath is then afterwards type converted
* using Camel's type converter to the given type.
* <p/>
* If you want to evaluate xpath using a different type, then call {@link #setResultType(Class)}
* prior to calling this evaluate method.
*
* @param context the camel context
* @param body the body
* @param type the type to return
* @return result of the evaluation
*/
public <T> T evaluate(CamelContext context, Object body, Class<T> type) {
ObjectHelper.notNull(context, "CamelContext");
// create a dummy Exchange to use during evaluation
Exchange dummy = new DefaultExchange(context);
dummy.getIn().setBody(body);
try {
return evaluate(dummy, type);
} finally {
// remove the thread local after usage
exchange.remove();
}
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class PredicateBuilderConcurrentTest method testPredicateBuilderConcurrent.
public void testPredicateBuilderConcurrent() throws Exception {
context.start();
List<Future<Boolean>> futures = new ArrayList<Future<Boolean>>();
ExecutorService pool = Executors.newFixedThreadPool(10);
for (int i = 0; i < 1000; i++) {
final Integer num = i;
Future<Boolean> future = pool.submit(new Callable<Boolean>() {
public Boolean call() throws Exception {
Expression left = ExpressionBuilder.headerExpression("foo");
Expression right;
if (num % 2 == 0) {
right = ExpressionBuilder.constantExpression("ABC");
} else {
right = ExpressionBuilder.constantExpression("DEF");
}
Predicate predicate = PredicateBuilder.isEqualTo(left, right);
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody("Hello World");
exchange.getIn().setHeader("foo", "ABC");
return predicate.matches(exchange);
}
});
futures.add(future);
}
for (int i = 0; i < 1000; i++) {
Boolean result = futures.get(i).get(10, TimeUnit.SECONDS);
if (i % 2 == 0) {
assertEquals("Should be true for #" + i, true, result.booleanValue());
} else {
assertEquals("Should be false for #" + i, false, result.booleanValue());
}
}
pool.shutdownNow();
}
Aggregations