Search in sources :

Example 51 with ClassPathXmlApplicationContext

use of org.springframework.context.support.ClassPathXmlApplicationContext 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 52 with ClassPathXmlApplicationContext

use of org.springframework.context.support.ClassPathXmlApplicationContext in project camel by apache.

the class CamelContextFactoryBeanTest method testClassPathRouteLoadingUsingNamespaces.

public void testClassPathRouteLoadingUsingNamespaces() throws Exception {
    applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/spring/camelContextFactoryBean.xml");
    CamelContext context = applicationContext.getBean("camel3", CamelContext.class);
    assertValidContext(context);
}
Also used : CamelContext(org.apache.camel.CamelContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext)

Example 53 with ClassPathXmlApplicationContext

use of org.springframework.context.support.ClassPathXmlApplicationContext in project camel by apache.

the class CamelContextFactoryBeanTest method testRouteBuilderRef.

public void testRouteBuilderRef() throws Exception {
    applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/spring/camelContextRouteBuilderRef.xml");
    CamelContext context = applicationContext.getBean("camel5", CamelContext.class);
    assertNotNull("No context found!", context);
    assertValidContext(context);
}
Also used : CamelContext(org.apache.camel.CamelContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext)

Example 54 with ClassPathXmlApplicationContext

use of org.springframework.context.support.ClassPathXmlApplicationContext 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 55 with ClassPathXmlApplicationContext

use of org.springframework.context.support.ClassPathXmlApplicationContext 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)

Aggregations

ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)561 Test (org.junit.Test)265 ApplicationContext (org.springframework.context.ApplicationContext)167 Before (org.junit.Before)53 ConfigurableMessenger (org.springframework.scripting.ConfigurableMessenger)33 ITestBean (org.springframework.tests.sample.beans.ITestBean)30 Messenger (org.springframework.scripting.Messenger)29 CamelContext (org.apache.camel.CamelContext)25 Refreshable (org.springframework.aop.target.dynamic.Refreshable)23 AbstractXmlApplicationContext (org.springframework.context.support.AbstractXmlApplicationContext)22 DataSource (javax.sql.DataSource)18 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)16 AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)16 Bus (org.apache.cxf.Bus)14 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)14 ArrayList (java.util.ArrayList)13 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)12 DemoService (com.alibaba.dubbo.config.spring.api.DemoService)11 IOException (java.io.IOException)10 ProducerTemplate (org.apache.camel.ProducerTemplate)10