Search in sources :

Example 61 with ProducerTemplate

use of org.apache.camel.ProducerTemplate in project Activiti by Activiti.

the class SimpleProcessTest method testRunProcess.

@Deployment(resources = { "process/example.bpmn20.xml" })
public void testRunProcess() throws Exception {
    CamelContext ctx = applicationContext.getBean(CamelContext.class);
    ProducerTemplate tpl = ctx.createProducerTemplate();
    service1.expectedBodiesReceived("ala");
    Exchange exchange = ctx.getEndpoint("direct:start").createExchange();
    exchange.getIn().setBody(Collections.singletonMap("var1", "ala"));
    tpl.send("direct:start", exchange);
    String instanceId = (String) exchange.getProperty("PROCESS_ID_PROPERTY");
    tpl.sendBodyAndProperty("direct:receive", null, ActivitiProducer.PROCESS_ID_PROPERTY, instanceId);
    assertProcessEnded(instanceId);
    service1.assertIsSatisfied();
    Map<?, ?> m = service2.getExchanges().get(0).getIn().getBody(Map.class);
    assertEquals("ala", m.get("var1"));
    assertEquals("var2", m.get("var2"));
}
Also used : CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Deployment(org.activiti.engine.test.Deployment)

Example 62 with ProducerTemplate

use of org.apache.camel.ProducerTemplate in project Activiti by Activiti.

the class SimpleSpringProcessTest method testRunProcess.

@Deployment(resources = { "process/example.bpmn20.xml" })
public void testRunProcess() throws Exception {
    CamelContext ctx = applicationContext.getBean(CamelContext.class);
    ProducerTemplate tpl = ctx.createProducerTemplate();
    service1.expectedBodiesReceived("ala");
    Exchange exchange = ctx.getEndpoint("direct:start").createExchange();
    exchange.getIn().setBody(Collections.singletonMap("var1", "ala"));
    tpl.send("direct:start", exchange);
    String instanceId = (String) exchange.getProperty("PROCESS_ID_PROPERTY");
    tpl.sendBodyAndProperty("direct:receive", null, ActivitiProducer.PROCESS_ID_PROPERTY, instanceId);
    assertProcessEnded(instanceId);
    service1.assertIsSatisfied();
    Map<?, ?> m = service2.getExchanges().get(0).getIn().getBody(Map.class);
    assertEquals("ala", m.get("var1"));
    assertEquals("var2", m.get("var2"));
}
Also used : CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Deployment(org.activiti.engine.test.Deployment)

Example 63 with ProducerTemplate

use of org.apache.camel.ProducerTemplate in project chuidiang-ejemplos by chuidiang.

the class RouteTest method testRoute.

@Test
public void testRoute() throws Exception {
    Thread.sleep(3000);
    ProducerTemplate p = context.createProducerTemplate();
    p.sendBody("controlbus:route?routeId=myRoute&action=suspend", null);
    Thread.sleep(3000);
    p.sendBody("controlbus:route?routeId=myRoute&action=resume", null);
    System.in.read();
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) Test(org.junit.Test)

Example 64 with ProducerTemplate

use of org.apache.camel.ProducerTemplate in project chuidiang-ejemplos by chuidiang.

the class RouteBinMain method startControlWindow.

private static void startControlWindow(final CamelContext context) {
    JFrame frame = new JFrame();
    final JCheckBox checkBox = new JCheckBox("Pause");
    frame.getContentPane().add(checkBox);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    checkBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (checkBox.isSelected()) {
                ProducerTemplate p = context.createProducerTemplate();
                p.sendBody("controlbus:route?routeId=myRoute&action=suspend", null);
            } else {
                ProducerTemplate p = context.createProducerTemplate();
                p.sendBody("controlbus:route?routeId=myRoute&action=resume", null);
            }
        }
    });
}
Also used : JCheckBox(javax.swing.JCheckBox) ProducerTemplate(org.apache.camel.ProducerTemplate) ActionListener(java.awt.event.ActionListener) JFrame(javax.swing.JFrame) ActionEvent(java.awt.event.ActionEvent)

Example 65 with ProducerTemplate

use of org.apache.camel.ProducerTemplate in project camel by apache.

the class ProducerTemplateAlreadyExistTest method testShouldBeSingleton.

@Test
public void testShouldBeSingleton() {
    ProducerTemplate lookup = context.getRegistry().lookupByNameAndType("myTemplate", ProducerTemplate.class);
    assertNotNull("Should lookup producer template", lookup);
    ProducerTemplate lookup2 = context.getRegistry().lookupByNameAndType("myTemplate", ProducerTemplate.class);
    assertNotNull("Should lookup producer template", lookup);
    assertSame("Should be same instances (singleton)", lookup, lookup2);
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) Test(org.junit.Test)

Aggregations

ProducerTemplate (org.apache.camel.ProducerTemplate)130 Test (org.junit.Test)58 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)53 CamelContext (org.apache.camel.CamelContext)48 Exchange (org.apache.camel.Exchange)36 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)27 Deployment (org.activiti.engine.test.Deployment)16 RouteBuilder (org.apache.camel.builder.RouteBuilder)16 Processor (org.apache.camel.Processor)8 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 HashMap (java.util.HashMap)7 Task (org.activiti.engine.task.Task)7 Endpoint (org.apache.camel.Endpoint)7 File (java.io.File)6 ArrayList (java.util.ArrayList)5 Message (org.apache.camel.Message)4 List (java.util.List)3 ExecutorService (java.util.concurrent.ExecutorService)3 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)3 ConsumerTemplate (org.apache.camel.ConsumerTemplate)3