Search in sources :

Example 21 with AbstractXmlApplicationContext

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

the class SpringTwoCamelContextDirectEndpointTest method testSpringTwoCamelContextDirectEndpoint.

public void testSpringTwoCamelContextDirectEndpoint() throws Exception {
    AbstractXmlApplicationContext ac = createApplicationContext();
    ac.start();
    CamelContext camel1 = ac.getBean("camel-1", CamelContext.class);
    CamelContext camel2 = ac.getBean("camel-2", CamelContext.class);
    Endpoint start1 = camel1.getEndpoint("direct:start");
    Endpoint start2 = camel2.getEndpoint("direct:start");
    assertNotSame(start1, start2);
    Endpoint foo1 = camel1.getEndpoint("direct:foo");
    Endpoint foo2 = camel2.getEndpoint("direct:foo");
    assertNotSame(foo1, foo2);
    MockEndpoint mock1 = camel1.getEndpoint("mock:a", MockEndpoint.class);
    mock1.expectedBodiesReceived("Hello World");
    MockEndpoint mock2 = camel2.getEndpoint("mock:b", MockEndpoint.class);
    mock2.expectedBodiesReceived("Bye World");
    camel1.createProducerTemplate().sendBody("direct:start", "Hello World");
    camel2.createProducerTemplate().sendBody("direct:start", "Bye World");
    mock1.assertIsSatisfied();
    mock2.assertIsSatisfied();
    ac.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext)

Example 22 with AbstractXmlApplicationContext

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

the class SpringQuartzPersistentStoreRestartAppChangeOptionsTest method testRestartAppChangeTriggerOptions.

@Test
public void testRestartAppChangeTriggerOptions() throws Exception {
    // Test creates application context twice with different simple trigger options in configuration xml.
    // Both times it retrieves back the option, accessing it via trigger (so, using value stored in DB).
    // After that it asserts that two options are not equal.
    // load spring app
    AbstractXmlApplicationContext app = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz/SpringQuartzPersistentStoreRestartAppChangeOptionsTest1.xml");
    app.start();
    CamelContext camel = app.getBean("camelContext", CamelContext.class);
    assertNotNull(camel);
    SimpleTrigger trigger = (SimpleTrigger) getTrigger(camel, "quartzRoute");
    long repeatInterval = trigger.getRepeatInterval();
    app.stop();
    log.info("Restarting ...");
    log.info("Restarting ...");
    log.info("Restarting ...");
    // load spring app
    AbstractXmlApplicationContext app2 = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz/SpringQuartzPersistentStoreRestartAppChangeOptionsTest2.xml");
    app2.start();
    CamelContext camel2 = app2.getBean("camelContext", CamelContext.class);
    assertNotNull(camel2);
    SimpleTrigger trigger2 = (SimpleTrigger) getTrigger(camel2, "quartzRoute");
    long repeatInterval2 = trigger2.getRepeatInterval();
    app2.stop();
    // we're done so let's properly close the application contexts, but close
    // the second app before the first one so that the quartz scheduler running
    // inside it can be properly shutdown
    IOHelper.close(app2, app);
    assertNotEquals(repeatInterval, repeatInterval2);
}
Also used : CamelContext(org.apache.camel.CamelContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext) SimpleTrigger(org.quartz.SimpleTrigger) Test(org.junit.Test)

Example 23 with AbstractXmlApplicationContext

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

the class SpringQuartzPersistentStoreRestartAppTest method testQuartzPersistentStoreRestart.

@Test
public void testQuartzPersistentStoreRestart() throws Exception {
    // load spring app
    AbstractXmlApplicationContext app = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz/SpringQuartzPersistentStoreTest.xml");
    app.start();
    CamelContext camel = app.getBean("camelContext", CamelContext.class);
    assertNotNull(camel);
    MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedMinimumMessageCount(2);
    mock.assertIsSatisfied();
    app.stop();
    log.info("Restarting ...");
    log.info("Restarting ...");
    log.info("Restarting ...");
    // NOTE:
    // To test a restart where the app has crashed, then you can in QuartzEndpoint
    // in the doShutdown method, then remove the following code line
    //  deleteTrigger(getTrigger());
    // then when we restart then there is old stale data which QuartzComponent
    // is supposed to handle and start again
    // load spring app
    AbstractXmlApplicationContext app2 = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz/SpringQuartzPersistentStoreRestartTest.xml");
    app2.start();
    CamelContext camel2 = app2.getBean("camelContext", CamelContext.class);
    assertNotNull(camel2);
    MockEndpoint mock2 = camel2.getEndpoint("mock:result", MockEndpoint.class);
    mock2.expectedMinimumMessageCount(2);
    mock2.assertIsSatisfied();
    app2.stop();
    // we're done so let's properly close the application contexts, but close
    // the second app before the first one so that the quartz scheduler running
    // inside it can be properly shutdown
    IOHelper.close(app2, app);
}
Also used : CamelContext(org.apache.camel.CamelContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext) Test(org.junit.Test)

Example 24 with AbstractXmlApplicationContext

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

the class SpringQuartzPersistentStoreRestartAppChangeOptionsTest method testRestartAppChangeTriggerOptions.

@Test
public void testRestartAppChangeTriggerOptions() throws Exception {
    // Test creates application context twice with different simple trigger options in configuration xml.
    // Both times it retrieves back the option, accessing it via trigger (so, using value stored in DB).
    // After that it asserts that two options are not equal.
    // load spring app
    AbstractXmlApplicationContext app = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz2/SpringQuartzPersistentStoreRestartAppChangeOptionsTest1.xml");
    app.start();
    CamelContext camel = app.getBean("camelContext", CamelContext.class);
    assertNotNull(camel);
    SimpleTrigger trigger = (SimpleTrigger) getTrigger(camel, "quartzRoute");
    long repeatInterval = trigger.getRepeatInterval();
    app.stop();
    log.info("Restarting ...");
    log.info("Restarting ...");
    log.info("Restarting ...");
    // load spring app
    AbstractXmlApplicationContext app2 = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz2/SpringQuartzPersistentStoreRestartAppChangeOptionsTest2.xml");
    app2.start();
    CamelContext camel2 = app2.getBean("camelContext", CamelContext.class);
    assertNotNull(camel2);
    SimpleTrigger trigger2 = (SimpleTrigger) getTrigger(camel2, "quartzRoute");
    long repeatInterval2 = trigger2.getRepeatInterval();
    app2.stop();
    // we're done so let's properly close the application contexts, but close
    // the second app before the first one so that the quartz scheduler running
    // inside it can be properly shutdown
    IOHelper.close(app2, app);
    assertNotEquals(repeatInterval, repeatInterval2);
}
Also used : CamelContext(org.apache.camel.CamelContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext) SimpleTrigger(org.quartz.SimpleTrigger) Test(org.junit.Test)

Example 25 with AbstractXmlApplicationContext

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

the class SpringQuartzPersistentStoreRestartAppTest method testQuartzPersistentStoreRestart.

@Test
public void testQuartzPersistentStoreRestart() throws Exception {
    // load spring app
    AbstractXmlApplicationContext app = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz2/SpringQuartzPersistentStoreTest.xml");
    app.start();
    CamelContext camel = app.getBean("camelContext", CamelContext.class);
    assertNotNull(camel);
    MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedMinimumMessageCount(2);
    mock.assertIsSatisfied();
    app.stop();
    log.info("Restarting ...");
    log.info("Restarting ...");
    log.info("Restarting ...");
    // NOTE:
    // To test a restart where the app has crashed, then you can in QuartzEndpoint
    // in the doShutdown method, then remove the following code line
    //  deleteTrigger(getTrigger());
    // then when we restart then there is old stale data which QuartzComponent
    // is supposed to handle and start again
    // load spring app
    AbstractXmlApplicationContext app2 = new ClassPathXmlApplicationContext("org/apache/camel/component/quartz2/SpringQuartzPersistentStoreRestartTest.xml");
    app2.start();
    CamelContext camel2 = app2.getBean("camelContext", CamelContext.class);
    assertNotNull(camel2);
    MockEndpoint mock2 = camel2.getEndpoint("mock:result", MockEndpoint.class);
    mock2.expectedMinimumMessageCount(2);
    mock2.assertIsSatisfied();
    app2.stop();
    // we're done so let's properly close the application contexts, but close
    // the second app before the first one so that the quartz scheduler running
    // inside it can be properly shutdown
    IOHelper.close(app2, app);
}
Also used : CamelContext(org.apache.camel.CamelContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext) Test(org.junit.Test)

Aggregations

AbstractXmlApplicationContext (org.springframework.context.support.AbstractXmlApplicationContext)28 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)22 CamelContext (org.apache.camel.CamelContext)17 Test (org.junit.Test)11 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)10 Service (org.apache.camel.Service)8 SimpleTrigger (org.quartz.SimpleTrigger)4 Endpoint (org.apache.camel.Endpoint)3 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)3 ProducerTemplate (org.apache.camel.ProducerTemplate)2 CronTrigger (org.quartz.CronTrigger)2 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXException (org.xml.sax.SAXException)1