Search in sources :

Example 16 with AbstractXmlApplicationContext

use of org.springframework.context.support.AbstractXmlApplicationContext in project Activiti by Activiti.

the class SpringAutoDeployTest method testResourceRedeploymentAfterProcessDefinitionChange.

// Updating the bpmn20 file should lead to a new deployment when restarting
// the Spring container
public void testResourceRedeploymentAfterProcessDefinitionChange() throws Exception {
    createAppContext(CTX_PATH);
    assertEquals(1, repositoryService.createDeploymentQuery().count());
    ((AbstractXmlApplicationContext) applicationContext).destroy();
    String filePath = "org/activiti/spring/test/autodeployment/autodeploy.a.bpmn20.xml";
    String originalBpmnFileContent = IoUtil.readFileAsString(filePath);
    String updatedBpmnFileContent = originalBpmnFileContent.replace("flow1", "fromStartToEndFlow");
    assertTrue(updatedBpmnFileContent.length() > originalBpmnFileContent.length());
    IoUtil.writeStringToFile(updatedBpmnFileContent, filePath);
    // Classic produced/consumer problem here:
    // The file is already written in Java, but not yet completely persisted by
    // the OS
    // Constructing the new app context reads the same file which is sometimes
    // not yet fully written to disk
    waitUntilFileIsWritten(filePath, updatedBpmnFileContent.length());
    try {
        applicationContext = new ClassPathXmlApplicationContext(CTX_NO_DROP_PATH);
        repositoryService = (RepositoryService) applicationContext.getBean("repositoryService");
    } finally {
        // Reset file content such that future test are not seeing something funny
        IoUtil.writeStringToFile(originalBpmnFileContent, filePath);
    }
    // Assertions come AFTER the file write! Otherwise the process file is
    // messed up if the assertions fail.
    assertEquals(2, repositoryService.createDeploymentQuery().count());
    assertEquals(6, repositoryService.createProcessDefinitionQuery().count());
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext)

Example 17 with AbstractXmlApplicationContext

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

the class SpringTestHelper method createSpringCamelContext.

public static CamelContext createSpringCamelContext(ContextTestSupport test, String classpathUri) throws Exception {
    test.setUseRouteBuilder(false);
    final AbstractXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(classpathUri);
    test.setCamelContextService(new Service() {

        public void start() throws Exception {
            applicationContext.start();
        }

        public void stop() throws Exception {
            applicationContext.stop();
        }
    });
    return SpringCamelContext.springCamelContext(applicationContext);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Service(org.apache.camel.Service) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext)

Example 18 with AbstractXmlApplicationContext

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

the class SpringMarshalOmitFieldsTest method createCamelContext.

protected CamelContext createCamelContext() throws Exception {
    setUseRouteBuilder(false);
    final AbstractXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/dataformat/xstream/SpringMarshalOmitFieldsTest.xml");
    setCamelContextService(new Service() {

        public void start() throws Exception {
            applicationContext.start();
        }

        public void stop() throws Exception {
            applicationContext.stop();
        }
    });
    return SpringCamelContext.springCamelContext(applicationContext);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Service(org.apache.camel.Service) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext)

Example 19 with AbstractXmlApplicationContext

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

the class RouteRefMultipleCamelContextRefsTest method testSpringTwoCamelContextDirectEndpoint.

public void testSpringTwoCamelContextDirectEndpoint() throws Exception {
    AbstractXmlApplicationContext ac = createApplicationContext();
    ac.start();
    CamelContext camel1 = ac.getBean("myCamel-1", CamelContext.class);
    CamelContext camel2 = ac.getBean("myCamel-2", CamelContext.class);
    Endpoint start1 = camel1.getEndpoint("direct:start");
    Endpoint start2 = camel2.getEndpoint("direct:start");
    assertNotSame(start1, start2);
    MockEndpoint mock1 = camel1.getEndpoint("mock:result", MockEndpoint.class);
    mock1.expectedBodiesReceived("Hello World");
    MockEndpoint mock2 = camel2.getEndpoint("mock:result", 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 20 with AbstractXmlApplicationContext

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

the class SpringRouteNoFromTest method createApplicationContext.

@Override
protected AbstractXmlApplicationContext createApplicationContext() {
    AbstractXmlApplicationContext answer;
    try {
        answer = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/SpringRouteNoFromTest.xml");
        fail("Should have thrown exception");
    } catch (Exception e) {
        IllegalArgumentException iae = (IllegalArgumentException) e.getCause();
        assertEquals("Route myRoute has no inputs: Route(myRoute)[[] -> [To[mock:result]]]", iae.getMessage());
        return null;
    }
    return answer;
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) AbstractXmlApplicationContext(org.springframework.context.support.AbstractXmlApplicationContext)

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