Search in sources :

Example 71 with CamelExecutionException

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();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) CamelExecutionException(org.apache.camel.CamelExecutionException) ProducerTemplate(org.apache.camel.ProducerTemplate) ClientEntity(org.apache.olingo.client.api.domain.ClientEntity) RouteBuilder(org.apache.camel.builder.RouteBuilder) HttpStatusCode(org.apache.olingo.commons.api.http.HttpStatusCode) Test(org.junit.Test)

Example 72 with CamelExecutionException

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();
    }
}
Also used : SpringCamelContext(org.apache.camel.spring.SpringCamelContext) CamelContext(org.apache.camel.CamelContext) CamelExecutionException(org.apache.camel.CamelExecutionException) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) RouteBuilder(org.apache.camel.builder.RouteBuilder) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) Step(io.syndesis.extension.api.Step) StepAction(io.syndesis.common.model.action.StepAction) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 73 with CamelExecutionException

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);
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 74 with CamelExecutionException

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();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) Exchange(org.apache.camel.Exchange) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) JSONException(net.sf.json.JSONException) CamelExecutionException(org.apache.camel.CamelExecutionException) JSONException(net.sf.json.JSONException) Test(org.junit.Test)

Example 75 with CamelExecutionException

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();
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) Exchange(org.apache.camel.Exchange) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) JSONException(net.sf.json.JSONException) CamelExecutionException(org.apache.camel.CamelExecutionException) JSONException(net.sf.json.JSONException) Test(org.junit.Test)

Aggregations

CamelExecutionException (org.apache.camel.CamelExecutionException)156 RouteBuilder (org.apache.camel.builder.RouteBuilder)69 Test (org.junit.Test)64 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)59 Exchange (org.apache.camel.Exchange)23 CamelContext (org.apache.camel.CamelContext)20 Processor (org.apache.camel.Processor)17 ProducerTemplate (org.apache.camel.ProducerTemplate)17 CamelExchangeException (org.apache.camel.CamelExchangeException)13 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)13 IOException (java.io.IOException)12 Date (java.util.Date)11 StopWatch (org.apache.camel.util.StopWatch)10 ExchangeTimedOutException (org.apache.camel.ExchangeTimedOutException)7 Set (java.util.Set)6 Subject (javax.security.auth.Subject)6 ConstraintViolation (javax.validation.ConstraintViolation)6 FailedLoginException (javax.security.auth.login.FailedLoginException)5 QuartzComponent (org.apache.camel.component.quartz.QuartzComponent)5 File (java.io.File)4