use of org.apache.camel.CamelExecutionException in project wildfly-camel by wildfly-extras.
the class Olingo4IntegrationTest method testCreateUpdateDelete.
@Test
public void testCreateUpdateDelete() throws Exception {
CamelContext camelctx = createCamelContext();
camelctx.addRoutes(new RouteBuilder() {
public void configure() {
from("direct://create-entity").to("olingo4://create/People");
from("direct://update-entity").to("olingo4://update/People('lewisblack')");
from("direct://delete-entity").to("olingo4://delete/People('lewisblack')");
from("direct://read-deleted-entity").to("olingo4://delete/People('lewisblack')");
from("direct://batch").to("olingo4://batch");
}
});
camelctx.start();
try {
ProducerTemplate template = camelctx.createProducerTemplate();
final ClientEntity clientEntity = createEntity();
ClientEntity entity = template.requestBody("direct://create-entity", clientEntity, ClientEntity.class);
Assert.assertNotNull(entity);
Assert.assertEquals("Lewis", entity.getProperty("FirstName").getValue().toString());
Assert.assertEquals("", entity.getProperty("MiddleName").getValue().toString());
// update
clientEntity.getProperties().add(objFactory.newPrimitiveProperty("MiddleName", objFactory.newPrimitiveValueBuilder().buildString("Lewis")));
HttpStatusCode status = template.requestBody("direct://update-entity", clientEntity, HttpStatusCode.class);
Assert.assertNotNull("Update status", status);
Assert.assertEquals("Update status", HttpStatusCode.NO_CONTENT.getStatusCode(), status.getStatusCode());
LOG.info("Update entity status: {}", status);
// delete
status = template.requestBody("direct://delete-entity", null, HttpStatusCode.class);
Assert.assertNotNull("Delete status", status);
Assert.assertEquals("Delete status", HttpStatusCode.NO_CONTENT.getStatusCode(), status.getStatusCode());
LOG.info("Delete status: {}", status);
// check for delete
try {
template.requestBody("direct://read-deleted-entity", null, HttpStatusCode.class);
} catch (CamelExecutionException e) {
Assert.assertEquals("Resource Not Found [HTTP/1.1 404 Not Found]", e.getCause().getMessage());
}
} finally {
camelctx.stop();
}
}
use of org.apache.camel.CamelExecutionException in project syndesis by syndesisio.
the class LogsAndErrorsTest method testRoute.
@Test
public void testRoute() throws Exception {
final CamelContext context = new SpringCamelContext(applicationContext);
try {
final RouteBuilder routes = newIntegrationRouteBuilder(new io.syndesis.common.model.integration.Step.Builder().id("s1").stepKind(StepKind.endpoint).action(new ConnectorAction.Builder().descriptor(new ConnectorDescriptor.Builder().componentScheme("direct").putConfiguredProperty("name", "expression").build()).build()).build(), new io.syndesis.common.model.integration.Step.Builder().id("s2").stepKind(StepKind.extension).action(new StepAction.Builder().descriptor(new StepDescriptor.Builder().kind(StepAction.Kind.STEP).entrypoint(LogExtension.class.getName()).build()).build()).build(), new io.syndesis.common.model.integration.Step.Builder().id("s3").stepKind(StepKind.extension).action(new StepAction.Builder().descriptor(new StepDescriptor.Builder().kind(StepAction.Kind.STEP).entrypoint(ErrorExtension.class.getName()).build()).build()).build(), new io.syndesis.common.model.integration.Step.Builder().id("s4").stepKind(StepKind.endpoint).action(new ConnectorAction.Builder().descriptor(new ConnectorDescriptor.Builder().componentScheme("mock").putConfiguredProperty("name", "expression").build()).build()).build());
// Set up the camel context
context.addRoutes(routes);
context.start();
// Dump routes as XML for troubleshooting
dumpRoutes(context);
final ProducerTemplate template = context.createProducerTemplate();
final MockEndpoint result = context.getEndpoint("mock:expression", MockEndpoint.class);
result.expectedBodiesReceived("1", "3");
template.sendBody("direct:expression", "1");
try {
template.sendBody("direct:expression", "2");
fail("Expected exception");
} catch (CamelExecutionException e) {
// expected.
}
template.sendBody("direct:expression", "3");
result.assertIsSatisfied();
} finally {
context.stop();
}
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class TransactionalClientDataSourceWithOnExceptionHandledAndRollbackTest method testTransactionRollback.
public void testTransactionRollback() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:error");
mock.expectedMessageCount(1);
try {
template.requestBody("direct:fail", "Hello World", String.class);
fail("Should have thrown exception");
} catch (CamelExecutionException e) {
// expected
}
assertMockEndpointsSatisfied();
int count = jdbc.queryForObject("select count(*) from books", Integer.class);
assertEquals("Number of books", 1, count);
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class XmlJsonExceptionsTest method testSendJsonToXML.
@Test
public void testSendJsonToXML() throws Exception {
String in = "{ \"a\": 123, \"b\": true, \"c\": true2 }";
MockEndpoint mockJSON = getMockEndpoint("mock:xml");
mockJSON.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 XmlJsonExceptionsTest method testMalformedXML.
@Test
public void testMalformedXML() throws Exception {
String in = "<noRoot>abc</noRoot><noRoot>abc</noRoot>";
MockEndpoint mockJSON = getMockEndpoint("mock:json");
mockJSON.expectedMessageCount(0);
MockEndpoint mockException = getMockEndpoint("mock:exception");
mockException.expectedMessageCount(1);
try {
template.requestBody("direct:marshal", 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();
}
Aggregations