Search in sources :

Example 6 with SpringCamelContext

use of org.apache.camel.spring.SpringCamelContext in project camel by apache.

the class CamelContextAutoStartupTest method testAutoStartupFalse.

public void testAutoStartupFalse() throws Exception {
    ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/CamelContextAutoStartupTestFalse.xml");
    SpringCamelContext camel = ac.getBeansOfType(SpringCamelContext.class).values().iterator().next();
    assertNotNull(camel.getName());
    assertEquals(true, camel.isStarted());
    assertEquals(Boolean.FALSE, camel.isAutoStartup());
    assertEquals(1, camel.getRoutes().size());
    assertEquals(false, camel.getRouteStatus("foo").isStarted());
    // now starting route manually
    camel.startRoute("foo");
    assertEquals(Boolean.FALSE, camel.isAutoStartup());
    assertEquals(1, camel.getRoutes().size());
    assertEquals(true, camel.getRouteStatus("foo").isStarted());
    // and now we can send a message to the route and see that it works
    MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedMessageCount(1);
    ProducerTemplate template = camel.createProducerTemplate();
    template.start();
    template.sendBody("direct:start", "Hello World");
    template.stop();
    mock.assertIsSatisfied();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) SpringCamelContext(org.apache.camel.spring.SpringCamelContext)

Example 7 with SpringCamelContext

use of org.apache.camel.spring.SpringCamelContext in project camel by apache.

the class CamelContextAutoStartupTest method testAutoStartupTrue.

public void testAutoStartupTrue() throws Exception {
    ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/CamelContextAutoStartupTestTrue.xml");
    SpringCamelContext camel = ac.getBeansOfType(SpringCamelContext.class).values().iterator().next();
    assertNotNull(camel.getName());
    assertEquals(true, camel.isStarted());
    assertEquals(Boolean.TRUE, camel.isAutoStartup());
    assertEquals(1, camel.getRoutes().size());
    // send a message to the route and see that it works
    MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedMessageCount(1);
    ProducerTemplate template = camel.createProducerTemplate();
    template.start();
    template.sendBody("direct:start", "Hello World");
    template.stop();
    mock.assertIsSatisfied();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) SpringCamelContext(org.apache.camel.spring.SpringCamelContext)

Example 8 with SpringCamelContext

use of org.apache.camel.spring.SpringCamelContext in project camel by apache.

the class CamelContextFactoryBeanTest method testAutoStartup.

public void testAutoStartup() throws Exception {
    applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/spring/camelContextFactoryBean.xml");
    SpringCamelContext context = applicationContext.getBean("camel4", SpringCamelContext.class);
    assertFalse(context.isAutoStartup());
    // there is 1 route but its not started
    assertEquals(1, context.getRoutes().size());
    context = applicationContext.getBean("camel3", SpringCamelContext.class);
    assertTrue(context.isAutoStartup());
    // there is 1 route but and its started
    assertEquals(1, context.getRoutes().size());
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext)

Example 9 with SpringCamelContext

use of org.apache.camel.spring.SpringCamelContext in project camel by apache.

the class CamelProxyTest method testCamelProxy.

public void testCamelProxy() throws Exception {
    AbstractApplicationContext ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/CamelProxyTest.xml");
    MyProxySender sender = ac.getBean("myProxySender", MyProxySender.class);
    String reply = sender.hello("World");
    assertEquals("Hello World", reply);
    // test sending inOnly message
    MyProxySender anotherSender = ac.getBean("myAnotherProxySender", MyProxySender.class);
    SpringCamelContext context = ac.getBeansOfType(SpringCamelContext.class).values().iterator().next();
    MockEndpoint result = resolveMandatoryEndpoint(context, "mock:result", MockEndpoint.class);
    result.expectedBodiesReceived("Hello my friends!");
    anotherSender.greeting("Hello my friends!");
    result.assertIsSatisfied();
    result.reset();
    // test sending inOnly message with other sender
    MyProxySender myProxySenderWithCamelContextId = ac.getBean("myProxySenderWithCamelContextId", MyProxySender.class);
    result.expectedBodiesReceived("Hello my friends again!");
    myProxySenderWithCamelContextId.greeting("Hello my friends again!");
    result.assertIsSatisfied();
    // we're done so let's properly close the application context
    IOHelper.close(ac);
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) SpringCamelContext(org.apache.camel.spring.SpringCamelContext)

Example 10 with SpringCamelContext

use of org.apache.camel.spring.SpringCamelContext in project camel by apache.

the class RouteAutoStartupPropertiesTest method testAutoStartupFalse.

public void testAutoStartupFalse() throws Exception {
    ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/RouteAutoStartupFalseTest.xml");
    SpringCamelContext camel = ac.getBeansOfType(SpringCamelContext.class).values().iterator().next();
    assertEquals(false, camel.getRouteStatus("foo").isStarted());
    // now starting route manually
    camel.startRoute("foo");
    assertEquals(true, camel.getRouteStatus("foo").isStarted());
    // and now we can send a message to the route and see that it works
    MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedMessageCount(1);
    ProducerTemplate template = camel.createProducerTemplate();
    template.start();
    template.sendBody("direct:start", "Hello World");
    template.stop();
    mock.assertIsSatisfied();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) SpringCamelContext(org.apache.camel.spring.SpringCamelContext)

Aggregations

SpringCamelContext (org.apache.camel.spring.SpringCamelContext)30 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)12 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)5 DoToSpringCamelContextsStrategy (org.apache.camel.test.spring.CamelSpringTestHelper.DoToSpringCamelContextsStrategy)5 Method (java.lang.reflect.Method)4 LinkedList (java.util.LinkedList)4 CamelContext (org.apache.camel.CamelContext)4 ProducerTemplate (org.apache.camel.ProducerTemplate)4 PropertiesComponent (org.apache.camel.component.properties.PropertiesComponent)4 Breakpoint (org.apache.camel.spi.Breakpoint)4 Test (org.junit.Test)3 Properties (java.util.Properties)2 TimeUnit (java.util.concurrent.TimeUnit)2 Route (org.apache.camel.Route)2 DefaultDebugger (org.apache.camel.impl.DefaultDebugger)2 InterceptSendToMockEndpointStrategy (org.apache.camel.impl.InterceptSendToMockEndpointStrategy)2 Debugger (org.apache.camel.spi.Debugger)2 ApplicationContext (org.springframework.context.ApplicationContext)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 Channel (org.apache.camel.Channel)1