Search in sources :

Example 41 with DefaultCamelContext

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

the class RouteStartupOrderSuspendResumeNoAutoStartupTest method testRouteStartupOrderSuspendResumeNoAutoStartup.

public void testRouteStartupOrderSuspendResumeNoAutoStartup() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    context.suspend();
    context.resume();
    // route C should still be stopped after we have resumed
    assertEquals(true, context.getRouteStatus("C").isStopped());
    // assert correct order
    DefaultCamelContext dcc = (DefaultCamelContext) context;
    List<RouteStartupOrder> order = dcc.getRouteStartupOrder();
    assertEquals(3, order.size());
    assertEquals("direct://foo", order.get(0).getRoute().getEndpoint().getEndpointUri());
    assertEquals("direct://start", order.get(1).getRoute().getEndpoint().getEndpointUri());
    assertEquals("direct://bar", order.get(2).getRoute().getEndpoint().getEndpointUri());
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) RouteStartupOrder(org.apache.camel.spi.RouteStartupOrder) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 42 with DefaultCamelContext

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

the class RouteStartupOrderWithDefaultTest method testRouteStartupOrder.

public void testRouteStartupOrder() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    template.sendBody("direct:start", "Hello World");
    assertMockEndpointsSatisfied();
    // assert correct order
    DefaultCamelContext dcc = (DefaultCamelContext) context;
    List<RouteStartupOrder> order = dcc.getRouteStartupOrder();
    assertEquals(5, order.size());
    assertEquals("seda://foo", order.get(0).getRoute().getEndpoint().getEndpointUri());
    assertEquals("direct://start", order.get(1).getRoute().getEndpoint().getEndpointUri());
    assertEquals("seda://bar", order.get(2).getRoute().getEndpoint().getEndpointUri());
    assertEquals("direct://bar", order.get(3).getRoute().getEndpoint().getEndpointUri());
    // the one with no startup order should be last
    assertEquals("direct://default", order.get(4).getRoute().getEndpoint().getEndpointUri());
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) RouteStartupOrder(org.apache.camel.spi.RouteStartupOrder) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 43 with DefaultCamelContext

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

the class AsyncEndpointEventNotifierTest method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    DefaultCamelContext context = new DefaultCamelContext(createRegistry());
    context.getManagementStrategy().addEventNotifier(new EventNotifierSupport() {

        public void notify(EventObject event) throws Exception {
            try {
                ExchangeSentEvent sent = (ExchangeSentEvent) event;
                time.set(sent.getTimeTaken());
            } finally {
                latch.countDown();
            }
        }

        public boolean isEnabled(EventObject event) {
            // we only want the async endpoint
            if (event instanceof ExchangeSentEvent) {
                ExchangeSentEvent sent = (ExchangeSentEvent) event;
                return sent.getEndpoint().getEndpointUri().startsWith("async");
            }
            return false;
        }

        @Override
        protected void doStart() throws Exception {
        }

        @Override
        protected void doStop() throws Exception {
        }
    });
    return context;
}
Also used : ExchangeSentEvent(org.apache.camel.management.event.ExchangeSentEvent) EventNotifierSupport(org.apache.camel.support.EventNotifierSupport) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) EventObject(java.util.EventObject)

Example 44 with DefaultCamelContext

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

the class ContainerTest method testNoContainerSet.

public void testNoContainerSet() throws Exception {
    MyContainer myContainer = new MyContainer();
    CamelContext camel1 = new DefaultCamelContext();
    CamelContext camel2 = new DefaultCamelContext();
    camel1.start();
    camel2.start();
    assertEquals(0, myContainer.names.size());
    camel1.stop();
    camel2.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 45 with DefaultCamelContext

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

the class ContainerTest method testContainerSet.

public void testContainerSet() throws Exception {
    MyContainer myContainer = new MyContainer();
    CamelContext camel1 = new DefaultCamelContext();
    CamelContext camel2 = new DefaultCamelContext();
    // Must call start to make contexts 'managed'
    camel1.start();
    camel2.start();
    assertEquals(0, myContainer.names.size());
    Container.Instance.set(myContainer);
    // after we set, then we should manage the 2 pending contexts
    assertEquals(2, myContainer.names.size());
    CamelContext camel3 = new DefaultCamelContext();
    camel3.start();
    assertEquals(3, myContainer.names.size());
    assertEquals(camel1.getName(), myContainer.names.get(0));
    assertEquals(camel2.getName(), myContainer.names.get(1));
    assertEquals(camel3.getName(), myContainer.names.get(2));
    camel1.stop();
    camel2.stop();
    camel3.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Aggregations

DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)474 CamelContext (org.apache.camel.CamelContext)206 Test (org.junit.Test)183 DefaultExchange (org.apache.camel.impl.DefaultExchange)128 RouteBuilder (org.apache.camel.builder.RouteBuilder)101 Exchange (org.apache.camel.Exchange)91 Before (org.junit.Before)70 SimpleRegistry (org.apache.camel.impl.SimpleRegistry)61 RegisteredDelivery (org.jsmpp.bean.RegisteredDelivery)39 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)38 ESMClass (org.jsmpp.bean.ESMClass)30 ProducerTemplate (org.apache.camel.ProducerTemplate)27 CountDownLatch (java.util.concurrent.CountDownLatch)15 Endpoint (org.apache.camel.Endpoint)13 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)13 Processor (org.apache.camel.Processor)12 RouteStartupOrder (org.apache.camel.spi.RouteStartupOrder)12 Address (org.jsmpp.bean.Address)11 SubmitMultiResult (org.jsmpp.bean.SubmitMultiResult)11 Date (java.util.Date)10