Search in sources :

Example 6 with SimpleRegistry

use of org.apache.camel.impl.SimpleRegistry in project camel by apache.

the class EndpointHelperTest method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    SimpleRegistry reg = new SimpleRegistry();
    CamelContext context = new DefaultCamelContext(reg);
    foo = context.getEndpoint("mock:foo");
    bar = context.getEndpoint("mock:bar");
    reg.put("foo", foo);
    reg.put("coolbar", bar);
    return context;
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 7 with SimpleRegistry

use of org.apache.camel.impl.SimpleRegistry in project camel by apache.

the class AtomGoodBlogsTest method createCamelContext.

protected CamelContext createCamelContext() throws Exception {
    // First we register a blog service in our bean registry
    SimpleRegistry registry = new SimpleRegistry();
    registry.put("blogService", new BlogService());
    // Then we create the camel context with our bean registry
    context = new DefaultCamelContext(registry);
    // Then we add all the routes we need using the route builder DSL syntax
    context.addRoutes(createMyRoutes());
    return context;
}
Also used : SimpleRegistry(org.apache.camel.impl.SimpleRegistry) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 8 with SimpleRegistry

use of org.apache.camel.impl.SimpleRegistry in project camel by apache.

the class SqsFilterMessagesWithNoDeleteTest method testGetThroughFilter.

@Test
public void testGetThroughFilter() throws Exception {
    final String sqsURI = String.format("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient" + // through filter, it should be deleted!
    "&deleteIfFiltered=false" + "&defaultVisibilityTimeout=1");
    AmazonSQSClientMock clientMock = new AmazonSQSClientMock();
    populateMessages(clientMock);
    SimpleRegistry registry = new SimpleRegistry();
    DefaultCamelContext ctx = new DefaultCamelContext(registry);
    ctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from(sqsURI).setHeader("login", constant(true)).filter(simple("${header.login} == true")).to("mock:result");
        }
    });
    MockEndpoint result = MockEndpoint.resolve(ctx, "mock:result");
    registry.put("amazonSQSClient", clientMock);
    clientMock.setScheduler(ctx.getExecutorServiceManager().newScheduledThreadPool(clientMock, "ClientMock Scheduler", 1));
    result.expectedMessageCount(1);
    ctx.start();
    // the message should get through filter and mock should assert this
    assertIsSatisfied(2000, TimeUnit.MILLISECONDS);
    // however, the message should not be deleted, that is, it should be left on the queue
    String response = ctx.createConsumerTemplate().receiveBody(sqsURI, 5000, String.class);
    assertNull(response);
    ctx.stop();
    clientMock.shutdown();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 9 with SimpleRegistry

use of org.apache.camel.impl.SimpleRegistry in project camel by apache.

the class SqsFilterMessagesWithNoDeleteTest method testDoesNotGetThroughFilter.

@Test
public void testDoesNotGetThroughFilter() throws Exception {
    final String sqsURI = String.format("aws-sqs://MyQueue?amazonSQSClient=#amazonSQSClient" + // note we will NOT delete if this message gets filtered out
    "&deleteIfFiltered=false" + "&defaultVisibilityTimeout=1");
    AmazonSQSClientMock clientMock = new AmazonSQSClientMock();
    populateMessages(clientMock);
    SimpleRegistry registry = new SimpleRegistry();
    DefaultCamelContext ctx = new DefaultCamelContext(registry);
    ctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from(sqsURI).filter(simple("${header.login} == true")).to("mock:result");
        }
    });
    MockEndpoint result = MockEndpoint.resolve(ctx, "mock:result");
    clientMock.setScheduler(ctx.getExecutorServiceManager().newScheduledThreadPool(clientMock, "ClientMock Scheduler", 1));
    registry.put("amazonSQSClient", clientMock);
    result.expectedMessageCount(0);
    ctx.start();
    // we shouldn't get
    assertIsSatisfied(2000, TimeUnit.MILLISECONDS);
    // however, the message should not be deleted, that is, it should be left on the queue
    String response = ctx.createConsumerTemplate().receiveBody(sqsURI, 5000, String.class);
    assertEquals(response, "Message: hello, world!");
    ctx.stop();
    clientMock.shutdown();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 10 with SimpleRegistry

use of org.apache.camel.impl.SimpleRegistry in project camel by apache.

the class XsltCustomErrorListenerTest method testErrorListener.

public void testErrorListener() throws Exception {
    try {
        SimpleRegistry registry = new SimpleRegistry();
        registry.put("myListener", listener);
        RouteBuilder builder = createRouteBuilder();
        CamelContext context = new DefaultCamelContext(registry);
        context.addRoutes(builder);
        context.start();
        fail("Should have thrown an exception due XSLT file not found");
    } catch (FailedToCreateRouteException e) {
    // expected
    }
    assertFalse(listener.isWarning());
    assertTrue("My error listener should been invoked", listener.isError());
    assertTrue("My error listener should been invoked", listener.isFatalError());
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) FailedToCreateRouteException(org.apache.camel.FailedToCreateRouteException) RouteBuilder(org.apache.camel.builder.RouteBuilder) SimpleRegistry(org.apache.camel.impl.SimpleRegistry) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Aggregations

SimpleRegistry (org.apache.camel.impl.SimpleRegistry)64 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)61 CamelContext (org.apache.camel.CamelContext)40 Test (org.junit.Test)31 RouteBuilder (org.apache.camel.builder.RouteBuilder)14 Before (org.junit.Before)8 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)5 EchoRequest (org.opennms.core.rpc.echo.EchoRequest)5 EchoRpcModule (org.opennms.core.rpc.echo.EchoRpcModule)5 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)4 Component (org.apache.camel.Component)4 Exchange (org.apache.camel.Exchange)4 DummyRestConsumerFactory (org.apache.camel.component.rest.DummyRestConsumerFactory)4 DefaultExchange (org.apache.camel.impl.DefaultExchange)4 EchoResponse (org.opennms.core.rpc.echo.EchoResponse)4 HashMap (java.util.HashMap)3 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)3 SjmsComponent (org.apache.camel.component.sjms.SjmsComponent)3 Config (com.hazelcast.config.Config)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2