Search in sources :

Example 11 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 12 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 13 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 14 with SpringCamelContext

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

the class AbstractInfluxDbTest method createCamelContext.

@Override
protected CamelContext createCamelContext() throws Exception {
    applicationContext = new AnnotationConfigApplicationContext(MockedInfluxDbConfiguration.class);
    CamelContext ctx = new SpringCamelContext(applicationContext);
    PropertiesComponent pc = new PropertiesComponent("classpath:influxdb.test.properties");
    ctx.addComponent("properties", pc);
    return ctx;
}
Also used : CamelContext(org.apache.camel.CamelContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent)

Example 15 with SpringCamelContext

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

the class CxfEndpointTest method testSpringCxfEndpoint.

@Test
public void testSpringCxfEndpoint() throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "org/apache/camel/component/cxf/CxfEndpointBeans.xml" });
    CxfComponent cxfComponent = new CxfComponent(new SpringCamelContext(ctx));
    CxfSpringEndpoint endpoint = (CxfSpringEndpoint) cxfComponent.createEndpoint("cxf://bean:serviceEndpoint");
    assertEquals("Got the wrong endpoint address", endpoint.getAddress(), "http://localhost:" + port2 + "/CxfEndpointTest/helloworld");
    assertEquals("Got the wrong endpont service class", endpoint.getServiceClass().getCanonicalName(), "org.apache.camel.component.cxf.HelloService");
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) Test(org.junit.Test)

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