use of org.apache.camel.CamelExecutionException in project camel by apache.
the class SslContextParametersMailRouteTest method testSendAndReceiveMailsWithCustomTrustStore.
@Test
public void testSendAndReceiveMailsWithCustomTrustStore() throws Exception {
context.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:in").to("smtps://" + smtpHost + "?username=" + username + "&password=" + password + "&sslContextParameters=#sslContextParameters");
}
});
context.start();
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("To", email);
headers.put("From", email);
headers.put("Reply-to", email);
headers.put("Subject", "SSL/TLS Test");
try {
template.sendBodyAndHeaders("direct:in", "Test Email Body", headers);
fail("Should have thrown exception");
} catch (CamelExecutionException e) {
assertTrue(e.getCause().getCause() instanceof SSLHandshakeException);
assertTrue(e.getCause().getCause().getMessage().contains("unable to find valid certification path to requested target"));
}
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class ServiceNowTableTest method testIncidentWorkflow.
@Test
public void testIncidentWorkflow() throws Exception {
Incident incident = null;
String sysId;
String number;
MockEndpoint mock = getMockEndpoint("mock:servicenow");
// ************************
// Create incident
// ************************
{
mock.reset();
mock.expectedMessageCount(1);
incident = new Incident();
incident.setDescription("my incident");
incident.setShortDescription("An incident");
incident.setSeverity(1);
incident.setImpact(1);
template().sendBodyAndHeaders("direct:servicenow", incident, kvBuilder().put(ServiceNowConstants.RESOURCE, "table").put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_CREATE).put(ServiceNowParams.PARAM_TABLE_NAME, "incident").build());
mock.assertIsSatisfied();
incident = mock.getExchanges().get(0).getIn().getBody(Incident.class);
sysId = incident.getId();
number = incident.getNumber();
LOGGER.info("****************************************************");
LOGGER.info(" Incident created");
LOGGER.info(" sysid = {}", sysId);
LOGGER.info(" number = {}", number);
LOGGER.info("****************************************************");
}
// ************************
// Search for the incident
// ************************
{
LOGGER.info("Search the record {}", sysId);
mock.reset();
mock.expectedMessageCount(1);
template().sendBodyAndHeaders("direct:servicenow", null, kvBuilder().put(ServiceNowConstants.RESOURCE, "table").put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE).put(ServiceNowParams.PARAM_TABLE_NAME, "incident").put(ServiceNowParams.SYSPARM_QUERY, "number=" + number).build());
mock.assertIsSatisfied();
List<Incident> incidents = mock.getExchanges().get(0).getIn().getBody(List.class);
assertEquals(1, incidents.size());
assertEquals(number, incidents.get(0).getNumber());
assertEquals(sysId, incidents.get(0).getId());
}
// ************************
// Modify the incident
// ************************
{
LOGGER.info("Update the record {}", sysId);
mock.reset();
mock.expectedMessageCount(1);
incident = new Incident();
incident.setDescription("my incident");
incident.setShortDescription("The incident");
incident.setSeverity(2);
incident.setImpact(3);
template().sendBodyAndHeaders("direct:servicenow", incident, kvBuilder().put(ServiceNowConstants.RESOURCE, "table").put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_MODIFY).put(ServiceNowParams.PARAM_TABLE_NAME, "incident").put(ServiceNowParams.PARAM_SYS_ID, sysId).build());
mock.assertIsSatisfied();
incident = mock.getExchanges().get(0).getIn().getBody(Incident.class);
assertEquals(number, incident.getNumber());
assertEquals(2, incident.getSeverity());
assertEquals(3, incident.getImpact());
assertEquals("The incident", incident.getShortDescription());
}
// ************************
// Retrieve it via query
// ************************
{
LOGGER.info("Retrieve the record {}", sysId);
mock.reset();
mock.expectedMessageCount(1);
template().sendBodyAndHeaders("direct:servicenow", null, kvBuilder().put(ServiceNowConstants.RESOURCE, "table").put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE).put(ServiceNowParams.PARAM_TABLE_NAME, "incident").put(ServiceNowParams.SYSPARM_QUERY, "number=" + number).build());
mock.assertIsSatisfied();
List<Incident> incidents = mock.getExchanges().get(0).getIn().getBody(List.class);
assertEquals(1, incidents.size());
assertEquals(number, incidents.get(0).getNumber());
assertEquals(sysId, incidents.get(0).getId());
assertEquals(2, incidents.get(0).getSeverity());
assertEquals(3, incidents.get(0).getImpact());
assertEquals("The incident", incidents.get(0).getShortDescription());
}
// ************************
// Retrieve by sys id
// ************************
{
LOGGER.info("Search the record {}", sysId);
mock.reset();
mock.expectedMessageCount(1);
template().sendBodyAndHeaders("direct:servicenow", null, kvBuilder().put(ServiceNowConstants.RESOURCE, "table").put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE).put(ServiceNowParams.PARAM_TABLE_NAME, "incident").put(ServiceNowParams.PARAM_SYS_ID, sysId).build());
mock.assertIsSatisfied();
incident = mock.getExchanges().get(0).getIn().getBody(Incident.class);
assertEquals(2, incident.getSeverity());
assertEquals(3, incident.getImpact());
assertEquals("The incident", incident.getShortDescription());
assertEquals(number, incident.getNumber());
}
// ************************
// Delete it
// ************************
{
LOGGER.info("Delete the record {}", sysId);
mock.reset();
mock.expectedMessageCount(1);
template().sendBodyAndHeaders("direct:servicenow", null, kvBuilder().put(ServiceNowConstants.RESOURCE, "table").put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_DELETE).put(ServiceNowParams.PARAM_TABLE_NAME, "incident").put(ServiceNowParams.PARAM_SYS_ID, sysId).build());
mock.assertIsSatisfied();
}
// ************************
// Retrieve by id, should fail
// ************************
{
LOGGER.info("Find the record {}, should fail", sysId);
try {
template().sendBodyAndHeaders("direct:servicenow", null, kvBuilder().put(ServiceNowConstants.RESOURCE, "table").put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE).put(ServiceNowParams.PARAM_SYS_ID, sysId).put(ServiceNowParams.PARAM_TABLE_NAME, "incident").build());
fail("Record " + number + " should have been deleted");
} catch (CamelExecutionException e) {
assertTrue(e.getCause() instanceof ServiceNowException);
// we are good
}
}
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class RabbitMQReConnectionIntTest method testSendEndReceive.
@Test
public void testSendEndReceive() throws Exception {
int nbMessages = 50;
int failedMessages = 0;
for (int i = 0; i < nbMessages; i++) {
try {
directProducer.sendBodyAndHeader("Message #" + i, RabbitMQConstants.ROUTING_KEY, "rk3");
} catch (CamelExecutionException e) {
log.debug("Can not send message", e);
failedMessages++;
}
Thread.sleep(500L);
}
producingMockEndpoint.expectedMessageCount(nbMessages - failedMessages);
consumingMockEndpoint.expectedMessageCount(nbMessages - failedMessages);
assertMockEndpointsSatisfied(5, TimeUnit.SECONDS);
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class RestApiIntegrationTest method testStatus400.
@Test
public void testStatus400() throws Exception {
// get test merchandise
// note that the header value overrides sObjectFields in endpoint
final Merchandise__c merchandise = template().requestBodyAndHeader("direct:getSObject", testId, "sObjectFields", "Description__c,Price__c", Merchandise__c.class);
assertNotNull(merchandise);
assertNotNull(merchandise.getPrice__c());
assertNull(merchandise.getTotal_Inventory__c());
merchandise.clearBaseFields();
// required field Total_Inventory__c is missing
CreateSObjectResult result = null;
try {
result = template().requestBody("direct:createSObject", merchandise, CreateSObjectResult.class);
fail("Expected SalesforceException with statusCode 400");
} catch (final CamelExecutionException e) {
assertTrue(e.getCause() instanceof SalesforceException);
assertTrue(e.getCause().getCause() instanceof SalesforceException);
final SalesforceException cause = (SalesforceException) e.getCause().getCause();
assertEquals(400, cause.getStatusCode());
assertEquals(1, cause.getErrors().size());
assertEquals("[Total_Inventory__c]", cause.getErrors().get(0).getFields().toString());
} finally {
// delete the clone if created
if (result != null) {
template().requestBody("direct:deleteSObject", result.getId());
}
}
}
use of org.apache.camel.CamelExecutionException in project camel by apache.
the class RestApiIntegrationTest method testStatus300.
@Test
public void testStatus300() throws Exception {
// get test merchandise
// note that the header value overrides sObjectFields in endpoint
final Merchandise__c merchandise = template().requestBodyAndHeader("direct:getSObject", testId, "sObjectFields", "Name,Description__c,Price__c,Total_Inventory__c", Merchandise__c.class);
assertNotNull(merchandise);
assertNotNull(merchandise.getName());
assertNotNull(merchandise.getPrice__c());
assertNotNull(merchandise.getTotal_Inventory__c());
CreateSObjectResult result = null;
try {
merchandise.clearBaseFields();
result = template().requestBody("direct:createSObject", merchandise, CreateSObjectResult.class);
assertNotNull(result);
assertNotNull(result.getId());
// note that the request SObject overrides settings on the endpoint for LineItem__c
try {
template().requestBody("direct:getSObjectWithId", merchandise, Merchandise__c.class);
fail("Expected SalesforceException with statusCode 300");
} catch (final CamelExecutionException e) {
assertTrue(e.getCause() instanceof SalesforceException);
assertTrue(e.getCause().getCause() instanceof SalesforceMultipleChoicesException);
final SalesforceMultipleChoicesException cause = (SalesforceMultipleChoicesException) e.getCause().getCause();
assertEquals(300, cause.getStatusCode());
final List<String> choices = cause.getChoices();
assertNotNull(choices);
assertFalse(choices.isEmpty());
}
} finally {
// delete the test clone
if (result != null) {
template().requestBody("direct:deleteSObject", result.getId());
}
}
}
Aggregations