use of org.apache.camel.CamelExecutionException in project camel by apache.
the class XmlJsonExceptionsTest method testMalformedJson.
@Test
public void testMalformedJson() throws Exception {
String in = "{ \"a\": 123, \"b\": true, \"c\": true2 }";
MockEndpoint mockXML = getMockEndpoint("mock:xml");
mockXML.expectedMessageCount(0);
MockEndpoint mockException = getMockEndpoint("mock:exception");
mockException.expectedMessageCount(1);
try {
template.requestBody("direct:unmarshal", in);
fail("Exception expected");
} catch (CamelExecutionException e) {
assertEquals("JSONException expected", JSONException.class, e.getCause().getClass());
}
List<Exchange> exchs = mockException.getExchanges();
assertEquals("Only one exchange was expected in mock:exception", 1, exchs.size());
Exception e = (Exception) exchs.get(0).getProperty(Exchange.EXCEPTION_CAUGHT);
assertNotNull("Exception expected", e);
assertEquals("JSONException expected", JSONException.class, e.getClass());
assertMockEndpointsSatisfied();
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class CamelGreeterConsumerTest method testInvokeServers.
@Test
public void testInvokeServers() throws Exception {
assertNotNull(camelContext);
ProducerTemplate template = camelContext.createProducerTemplate();
List<String> params = new ArrayList<String>();
params.add("Willem");
Object result = template.sendBodyAndHeader("cxf://bean:serviceEndpoint", ExchangePattern.InOut, params, CxfConstants.OPERATION_NAME, "greetMe");
assertTrue("Result is a list instance ", result instanceof List);
assertEquals("Get the wrong response", ((List<?>) result).get(0), "HelloWillem");
try {
template.sendBodyAndHeader("cxf://bean:serviceEndpoint", ExchangePattern.InOut, params, CxfConstants.OPERATION_NAME, "pingMe");
fail("Expect exception here.");
} catch (Exception ex) {
assertTrue("Get a wrong exception.", ex instanceof CamelExecutionException);
assertTrue("Get a wrong exception cause. ", ex.getCause() instanceof PingMeFault);
}
template.stop();
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class SpringAopClassLevelCamelBeanTest method testSpringAopException.
public void testSpringAopException() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(0);
try {
template.sendBodyAndHeader("direct:start", "Hello World", "foo", "Damn");
fail("Should have thrown exception");
} catch (CamelExecutionException e) {
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
}
assertMockEndpointsSatisfied();
ExceptionInterceptor ei = context.getRegistry().lookupByNameAndType("exceptionInterceptor", ExceptionInterceptor.class);
IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, ei.getE());
assertEquals("Foo has not expected value ABC but Damn", iae.getMessage());
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class HttpStreamCacheFileTest method testStreamCacheToFileShouldBeDeletedInCaseOfException.
@Test
public void testStreamCacheToFileShouldBeDeletedInCaseOfException() throws Exception {
try {
template.requestBody("direct:start", null, String.class);
fail("Should have thrown an exception");
} catch (CamelExecutionException e) {
HttpOperationFailedException hofe = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
String s = context.getTypeConverter().convertTo(String.class, hofe.getResponseBody());
assertEquals("Response body", responseBody, s);
}
// the temporary files should have been deleted
File file = new File("target/cachedir");
String[] files = file.list();
assertEquals("There should be no files", 0, files.length);
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class SimpleScheduledRoutePolicyTest method testScheduledResumeRoutePolicy.
@Test
public void testScheduledResumeRoutePolicy() throws Exception {
MockEndpoint success = context.getEndpoint("mock:success", MockEndpoint.class);
success.expectedMessageCount(1);
context.getComponent("quartz", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz/myquartz.properties");
context.addRoutes(new RouteBuilder() {
public void configure() {
SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
long startTime = System.currentTimeMillis() + 3000L;
policy.setRouteResumeDate(new Date(startTime));
policy.setRouteResumeRepeatCount(1);
policy.setRouteResumeRepeatInterval(3000);
from("direct:start").routeId("test").routePolicy(policy).to("mock:success");
}
});
context.start();
ServiceHelper.suspendService(context.getRoute("test").getConsumer());
try {
template.sendBody("direct:start", "Ready or not, Here, I come");
fail("Should have thrown an exception");
} catch (CamelExecutionException e) {
LOG.debug("Consumer successfully suspended");
}
Thread.sleep(4000);
template.sendBody("direct:start", "Ready or not, Here, I come");
context.getComponent("quartz", QuartzComponent.class).stop();
success.assertIsSatisfied();
}
Aggregations