Java 类org.apache.camel.impl.DefaultCamelContext 实例源码

项目:syndesis-verifier    文件:BaseVerifier.java   
@PostConstruct
public void start() throws Exception {
    camel = new DefaultCamelContext();
    camel.start();

    final Component component = camel.getComponent(getConnectorAction(), true, false);
    if (component == null) {
        log.error("Component {} does not exist", getConnectorAction());
    } else {
        verifier = component.getExtension(verifierExtensionClass).orElse(null);
        if (verifier == null) {
            log.warn("Component {} does not support verifier extension", getConnectorAction());
        }

    }
}
项目:syndesis    文件:ActionDefinitionEndpointTest.java   
@Test
public void shouldMetadata() throws Exception {
    final CamelContext context = new DefaultCamelContext();
    context.addComponent("petstore", new PetstoreComponent(PAYLOAD));

    try {
        context.start();

        final PetstoreAdapter adapter = new PetstoreAdapter(PAYLOAD, PROPERTIES, INPUT, OUTPUT);
        final ActionDefinitionEndpoint endpoint = new ActionDefinitionEndpoint(context, "petstore", adapter);
        final SyndesisMetadata<?> metadata = endpoint.definition("dog-food", Collections.emptyMap());

        assertThat(metadata.properties).isSameAs(PROPERTIES);
        assertThat(metadata.inputSchema).isSameAs(INPUT);
        assertThat(metadata.outputSchema).isSameAs(OUTPUT);
    } finally {
        context.stop();
    }
}
项目:connectors    文件:SalesforcePingCheck.java   
public void ping() throws Exception {
    // need to create Camel
    CamelContext camel = new DefaultCamelContext();

    // get the connector to use
    Component mention = camel.getComponent("salesforce-upsert-contact-connector");
    Optional<ComponentVerifierExtension> ext = mention.getExtension(ComponentVerifierExtension.class);

    // the connector must support ping check if its verifiable
    if (ext.isPresent()) {
        ComponentVerifierExtension verifier = ext.get();

        Map<String, Object> parameters = loadParameters();
        ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters);

        System.out.println("=============================================");
        System.out.println("");
        System.out.println("Ping check result: " + result.getStatus());
        System.out.println("");
        System.out.println("=============================================");

    } else {
        System.out.println("Component does not support ping check");
    }
}
项目:connectors    文件:TwitterPingCheck.java   
public void ping() throws Exception {
    // need to create Camel
    CamelContext camel = new DefaultCamelContext();

    // get the connector to use
    Component mention = camel.getComponent("twitter-mention-connector");
    Optional<ComponentVerifierExtension> ext = mention.getExtension(ComponentVerifierExtension.class);

    // the connector must support ping check if its verifiable
    if (ext.isPresent()) {
        ComponentVerifierExtension verifier = ext.get();
        Map<String, Object> parameters = loadParameters();
        ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters);

        System.out.println("=============================================");
        System.out.println("");
        System.out.println("Ping check result: " + result.getStatus());
        System.out.println("");
        System.out.println("=============================================");

    } else {
        System.out.println("Component does not support ping check");
    }
}
项目:connectors    文件:HttpPingCheck.java   
public void ping() throws Exception {
    // need to create Camel
    CamelContext camel = new DefaultCamelContext();

    // get the connector to use
    Component get = camel.getComponent("http-get-connector");
    Optional<ComponentVerifierExtension> ext = get.getExtension(ComponentVerifierExtension.class);

    // the connector must support ping check if its verifiable
    if (ext.isPresent()) {
        ComponentVerifierExtension verifier = ext.get();

        Map<String, Object> parameters = loadParameters();
        ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters);

        System.out.println("=============================================");
        System.out.println("");
        System.out.println("Ping check result: " + result.getStatus());
        System.out.println("");
        System.out.println("=============================================");

    } else {
        System.out.println("Component does not support ping check");
    }
}
项目:bitbreeds-webrtc    文件:ProcessSignalsTest.java   
@Test
public void testSDPParseOffer() throws Exception {
    Exchange ex = new DefaultExchange(new DefaultCamelContext());
    ex.getIn().setBody(offerSdp);
    processor.process(ex);
    assertEquals(ex.getIn().getBody().getClass(),Offer.class);

    Offer offer = (Offer)ex.getIn().getBody();

    MediaDescription mediaDescription = (MediaDescription) offer.getSdp().getMediaDescriptions(true).get(0);

    String icePwd = mediaDescription.getAttribute("ice-pwd");
    String iceUfrag = mediaDescription.getAttribute("ice-ufrag");
    String fingerprint = offer.getSdp().getAttribute("fingerprint");

    assertEquals(icePwd,"c490fef46f74bdbe64edd636bc49a259");
    assertEquals(iceUfrag,"64dc2277");
    assertEquals(fingerprint,"sha-256 99:45:B1:94:7E:97:AE:F2:A5:75:86:89:B5:AD:06:BB:63:02:FA:05:04:B2:83:1B:52:C9:EF:0E:61:8F:38:73");
}
项目:Camel    文件:SjmsBatchEndpointTest.java   
@Override
protected CamelContext createCamelContext() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    registry.put("aggStrategy", AggregationStrategies.groupedExchange());

    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
    connectionFactory.setBrokerURL(broker.getTcpConnectorUri());

    SjmsComponent sjmsComponent = new SjmsComponent();
    sjmsComponent.setConnectionFactory(connectionFactory);

    SjmsBatchComponent sjmsBatchComponent = new SjmsBatchComponent();
    sjmsBatchComponent.setConnectionFactory(connectionFactory);

    CamelContext context = new DefaultCamelContext(registry);
    context.addComponent("sjms-batch", sjmsBatchComponent);
    context.addComponent("sjms", sjmsComponent);

    return context;
}
项目:Camel    文件:XmlSignatureTest.java   
public Exchange doSignatureRouteTest(RouteBuilder builder, Exchange e, Map<String, Object> headers) throws Exception {
    CamelContext context = new DefaultCamelContext();
    try {
        context.addRoutes(builder);
        context.start();

        MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class);
        mock.setExpectedMessageCount(1);

        ProducerTemplate template = context.createProducerTemplate();
        if (e != null) {
            template.send("direct:in", e);
        } else {
            template.sendBodyAndHeaders("direct:in", payload, headers);
        }
        assertMockEndpointsSatisfied();
        return mock.getReceivedExchanges().get(0);
    } finally {
        context.stop();
    }
}
项目:Camel    文件:QuartzTwoCamelContextRestartTest.java   
@Before
public void setUp() throws Exception {
    camel1 = new DefaultCamelContext();
    camel1.setName("camel-1");
    camel1.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("quartz2://myGroup/myTimerName?cron=0/1+*+*+*+*+?").to("log:one", "mock:one");
        }
    });
    camel1.start();

    camel2 = new DefaultCamelContext();
    camel2.setName("camel-2");
    camel2.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("quartz2://myOtherGroup/myOtherTimerName?cron=0/1+*+*+*+*+?").to("log:two", "mock:two");
        }
    });
    camel2.start();
}
项目:Camel    文件:SmppDataSmCommandTest.java   
@Test
public void execute() throws Exception {
    Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
    exchange.getIn().setHeader(SmppConstants.COMMAND, "DataSm");
    exchange.getIn().setHeader(SmppConstants.SERVICE_TYPE, "XXX");
    exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_TON, TypeOfNumber.NATIONAL.value());
    exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_NPI, NumberingPlanIndicator.NATIONAL.value());
    exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR, "1818");
    exchange.getIn().setHeader(SmppConstants.DEST_ADDR_TON, TypeOfNumber.INTERNATIONAL.value());
    exchange.getIn().setHeader(SmppConstants.DEST_ADDR_NPI, NumberingPlanIndicator.INTERNET.value());
    exchange.getIn().setHeader(SmppConstants.DEST_ADDR, "1919");
    exchange.getIn().setHeader(SmppConstants.REGISTERED_DELIVERY, new RegisteredDelivery(SMSCDeliveryReceipt.FAILURE).value());
    expect(session.dataShortMessage(eq("XXX"), eq(TypeOfNumber.NATIONAL), eq(NumberingPlanIndicator.NATIONAL), eq("1818"),
            eq(TypeOfNumber.INTERNATIONAL), eq(NumberingPlanIndicator.INTERNET), eq("1919"), eq(new ESMClass()),
            eq(new RegisteredDelivery((byte) 2)), eq(DataCodings.newInstance((byte) 0))))
        .andReturn(new DataSmResult(new MessageId("1"), null));

    replay(session);

    command.execute(exchange);

    verify(session);

    assertEquals("1", exchange.getOut().getHeader(SmppConstants.ID));
    assertNull(exchange.getOut().getHeader(SmppConstants.OPTIONAL_PARAMETERS));
}
项目:Camel    文件:QuartzNameCollisionTest.java   
/**
 * Make sure a resume doesn't trigger a dupe name error.
 */
@Test
public void testRestart() throws Exception {
    DefaultCamelContext camel = new DefaultCamelContext();

    camel.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("quartz2://myGroup/myTimerName?cron=0/1+*+*+*+*+?").to("log:one", "mock:one");
        }
    });

    // traverse a litany of states
    camel.start();
    Thread.sleep(100);
    camel.suspend();
    Thread.sleep(100);
    camel.resume();
    Thread.sleep(100);
    camel.stop();
    Thread.sleep(100);
    camel.start();
    Thread.sleep(100);
    camel.stop();
}
项目:Camel    文件:RouteServicesStartupOrderTest.java   
public void testRouteServiceStartupOrder() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);

    template.sendBody("direct:start", "Hello World");

    assertMockEndpointsSatisfied();

    // assert correct order
    DefaultCamelContext dcc = (DefaultCamelContext) context;
    List<RouteStartupOrder> order = dcc.getRouteStartupOrder();

    assertEquals(4, order.size());
    assertEquals("seda://foo", order.get(0).getRoute().getEndpoint().getEndpointUri());
    assertEquals("direct://start", order.get(1).getRoute().getEndpoint().getEndpointUri());
    assertEquals("seda://bar", order.get(2).getRoute().getEndpoint().getEndpointUri());
    assertEquals("direct://bar", order.get(3).getRoute().getEndpoint().getEndpointUri());

    // assert route service was started in order as well
    assertEquals("2143", startOrder);
}
项目:Camel    文件:SignatureTests.java   
public Exchange doSignatureRouteTest(RouteBuilder builder, Exchange e, Map<String, Object> headers) throws Exception {
    CamelContext context = new DefaultCamelContext();
    try {
        context.addRoutes(builder);
        context.start();

        MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class);
        mock.setExpectedMessageCount(1);

        ProducerTemplate template = context.createProducerTemplate();
        if (e != null) {
            template.send("direct:in", e);
        } else {
            template.sendBodyAndHeaders("direct:in", payload, headers);
        }
        assertMockEndpointsSatisfied();
        return mock.getReceivedExchanges().get(0);
    } finally {
        context.stop();
    }
}
项目:Camel    文件:ManagedStreamCachingStrategyTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            DefaultCamelContext dcc = (DefaultCamelContext) context;
            dcc.setName("myCamel");

            context.setStreamCaching(true);
            context.getStreamCachingStrategy().setSpoolDirectory("target/cachedir/#name#/");

            from("direct:start").routeId("foo")
                .convertBodyTo(int.class)
                .to("mock:a");
        }
    };
}
项目:Camel    文件:SjmsBatchConsumerTest.java   
@Override
public CamelContext createCamelContext() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    registry.put("testStrategy", new ListAggregationStrategy());
    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(broker.getTcpConnectorUri());

    SjmsComponent sjmsComponent = new SjmsComponent();
    sjmsComponent.setConnectionFactory(connectionFactory);

    SjmsBatchComponent sjmsBatchComponent = new SjmsBatchComponent();
    sjmsBatchComponent.setConnectionFactory(connectionFactory);

    CamelContext context = new DefaultCamelContext(registry);
    context.addComponent("sjms", sjmsComponent);
    context.addComponent("sjms-batch", sjmsBatchComponent);
    return context;
}
项目:wildfly-swarm-camel    文件:CXFWSProducerIntegrationTest.java   
@Test
public void testCxfProducer() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").to("cxf://" + getEndpointAddress("/") + "?serviceClass=" + Endpoint.class.getName());
        }
    });

    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        String result = producer.requestBody("direct:start", "Kermit", String.class);
        Assert.assertEquals("Hello Kermit", result);
    } finally {
        camelctx.stop();
    }
}
项目:Camel    文件:RouteStartupOrderTest.java   
public void testRouteStartupOrder() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);

    template.sendBody("direct:start", "Hello World");

    assertMockEndpointsSatisfied();

    // assert correct order
    DefaultCamelContext dcc = (DefaultCamelContext) context;
    List<RouteStartupOrder> order = dcc.getRouteStartupOrder();

    assertEquals(4, order.size());
    assertEquals("seda://foo", order.get(0).getRoute().getEndpoint().getEndpointUri());
    assertEquals("direct://start", order.get(1).getRoute().getEndpoint().getEndpointUri());
    assertEquals("seda://bar", order.get(2).getRoute().getEndpoint().getEndpointUri());
    assertEquals("direct://bar", order.get(3).getRoute().getEndpoint().getEndpointUri());
}
项目:Camel    文件:UriConfigurationTest.java   
@Test
public void testComponentConfiguration() throws Exception {
    CamelContext context = new DefaultCamelContext();

    BeanstalkComponent comp = context.getComponent("beanstalk", BeanstalkComponent.class);
    EndpointConfiguration conf = comp.createConfiguration("beanstalk:tube?command=put");

    assertEquals("put", conf.getParameter("command"));

    ComponentConfiguration compConf = comp.createComponentConfiguration();
    String json = compConf.createParameterJsonSchema();
    assertNotNull(json);

    assertTrue(json.contains("\"command\": { \"kind\": \"parameter\", \"group\": \"common\", \"type\": \"string\""));
    assertTrue(json.contains("\"jobTimeToRun\": { \"kind\": \"parameter\", \"group\": \"common\", \"type\": \"integer\""));
    assertTrue(json.contains("\"awaitJob\": { \"kind\": \"parameter\", \"group\": \"consumer\", \"label\": \"consumer\", \"type\": \"boolean\""));
}
项目:Camel    文件:ProcessBuilder.java   
protected void populateRoutes() throws Exception {
    ObjectHelper.notNull(entityManagerFactory, "entityManagerFactory", this);
    ObjectHelper.notNull(getTransactionTemplate(), "transactionTemplate", this);

    // add the monitoring service - should there be an easier way??
    if (engine == null) {
        engine = new ActivityMonitorEngine(entityManagerFactory, getTransactionTemplate(), getProcessRules());
    }
    CamelContext camelContext = getContext();
    if (camelContext instanceof DefaultCamelContext) {
        DefaultCamelContext defaultCamelContext = (DefaultCamelContext) camelContext;
        defaultCamelContext.addService(engine);
    }

    // create the routes for the activities
    for (ActivityBuilder builder : activityBuilders) {
        from(builder.getEndpoint()).process(builder.getProcessor());
    }

    super.populateRoutes();
}
项目:Camel    文件:QuartzNameCollisionTest.java   
@Test
public void testDupeNameMultiContext() throws Exception {
    camel1 = new DefaultCamelContext();
    camel1.setName("camel-1");
    camel1.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("quartz2://myGroup/myTimerName?cron=0/1+*+*+*+*+?").to("log:one", "mock:one");
        }
    });
    camel1.start();

    camel2 = new DefaultCamelContext();
    camel2.setName("camel-2");
    camel2.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("quartz2://myGroup/myTimerName=0/2+*+*+*+*+?").to("log:two", "mock:two");
        }
    });
    camel2.start();
}
项目:Camel    文件:JmsTestSupport.java   
@Override
public void tearDown() throws Exception {
    super.tearDown();
    DefaultCamelContext dcc = (DefaultCamelContext)context;
    while (!dcc.isStopped()) {
        log.info("Waiting on the Camel Context to stop");
    }
    log.info("Closing JMS Session");
    if (getSession() != null) {
        getSession().close();
        setSession(null);
    }
    log.info("Closing JMS Connection");
    if (connection != null) {
        connection.stop();
        connection = null;
    }
    log.info("Stopping the ActiveMQ Broker");
    if (broker != null) {
        broker.stop();
        broker = null;
    }
}
项目:wildfly-swarm    文件:JAXRSProducerTest.java   
@Test
public void testJaxrsProducer() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .setHeader(Exchange.HTTP_METHOD, constant("GET")).
            to("cxfrs://" + getEndpointAddress("/") + "?resourceClasses=" + GreetingService.class.getName());
        }
    });

    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        String result = producer.requestBodyAndHeader("direct:start", "mybody", "name", "Kermit", String.class);
        Assert.assertEquals("Hello Kermit", result);
    } finally {
        camelctx.stop();
    }
}
项目:Camel    文件:MessageHelperTest.java   
public void testMessageDump() throws Exception {
    JAXBContext jaxb = JAXBContext.newInstance(MessageDump.class);
    Unmarshaller unmarshaller = jaxb.createUnmarshaller();

    CamelContext context = new DefaultCamelContext();
    context.start();

    message = new DefaultExchange(context).getIn();

    // xml message body
    message.setBody("Hello World");
    message.setHeader("foo", 123);

    String out = MessageHelper.dumpAsXml(message, true);

    MessageDump dump = (MessageDump) unmarshaller.unmarshal(new StringReader(out));
    assertNotNull(dump);

    assertEquals("java.lang.String", dump.getBody().getType());
    assertEquals("Hello World", dump.getBody().getValue());

    assertEquals(1, dump.getHeaders().size());
    assertEquals("foo", dump.getHeaders().get(0).getKey());
    assertEquals("java.lang.Integer", dump.getHeaders().get(0).getType());
    assertEquals("123", dump.getHeaders().get(0).getValue());
}
项目:Camel    文件:CatalogCommandTest.java   
@Test
public void testComponentInfo() throws Exception {
    CamelContext context = new DefaultCamelContext();
    context.setNameStrategy(new ExplicitCamelContextNameStrategy("foobar"));
    context.start();

    CamelController controller = new DummyCamelController(context);

    OutputStream os = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(os);

    CatalogComponentInfoCommand command = new CatalogComponentInfoCommand("hdfs", true, "consumer");
    command.execute(controller, ps, null);

    String out = os.toString();
    assertNotNull(out);
    LOG.info("\n\n{}\n", out);

    context.stop();
}
项目:Camel    文件:ResourceHelperTest.java   
public void testLoadFileWithSpace() throws Exception {
    CamelContext context = new DefaultCamelContext();
    context.start();

    createDirectory("target/my space");
    FileUtil.copyFile(new File("src/test/resources/log4j.properties"), new File("target/my space/log4j.properties"));

    InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(context, "file:target/my%20space/log4j.properties");
    assertNotNull(is);

    String text = context.getTypeConverter().convertTo(String.class, is);
    assertNotNull(text);
    assertTrue(text.contains("log4j"));
    is.close();

    context.stop();
}
项目:Camel    文件:SmppReplaceSmCommandTest.java   
@Test
public void execute() throws Exception {
    Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
    exchange.getIn().setHeader(SmppConstants.COMMAND, "ReplaceSm");
    exchange.getIn().setHeader(SmppConstants.ID, "1");
    exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_TON, TypeOfNumber.NATIONAL.value());
    exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_NPI, NumberingPlanIndicator.NATIONAL.value());
    exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR, "1818");
    exchange.getIn().setHeader(SmppConstants.SCHEDULE_DELIVERY_TIME, new Date(1111111));
    exchange.getIn().setHeader(SmppConstants.VALIDITY_PERIOD, new Date(2222222));
    exchange.getIn().setHeader(SmppConstants.REGISTERED_DELIVERY, new RegisteredDelivery(SMSCDeliveryReceipt.FAILURE).value());
    exchange.getIn().setBody("new short message body");
    session.replaceShortMessage(eq("1"), eq(TypeOfNumber.NATIONAL), eq(NumberingPlanIndicator.NATIONAL), eq("1818"), eq("-300101001831100+"), eq("-300101003702200+"),
            eq(new RegisteredDelivery(SMSCDeliveryReceipt.FAILURE)), eq((byte) 0), aryEq("new short message body".getBytes()));

    replay(session);

    command.execute(exchange);

    verify(session);

    assertEquals("1", exchange.getOut().getHeader(SmppConstants.ID));
}
项目:Camel    文件:QuartzNameCollisionTest.java   
@Test
public void testDupeNameMultiContext() throws Exception {
    camel1 = new DefaultCamelContext();
    camel1.setName("camel-1");
    camel1.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("quartz://myGroup/myTimerName?cron=0/1+*+*+*+*+?").to("log:one", "mock:one");
        }
    });
    camel1.start();

    camel2 = new DefaultCamelContext();
    QuartzComponent component2 = new QuartzComponent(camel2);
    component2.createEndpoint("quartz://myGroup/myTimerName");
}
项目:Camel    文件:RouteStartupOrderWithDefaultTest.java   
public void testRouteStartupOrder() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);

    template.sendBody("direct:start", "Hello World");

    assertMockEndpointsSatisfied();

    // assert correct order
    DefaultCamelContext dcc = (DefaultCamelContext) context;
    List<RouteStartupOrder> order = dcc.getRouteStartupOrder();

    assertEquals(5, order.size());
    assertEquals("seda://foo", order.get(0).getRoute().getEndpoint().getEndpointUri());
    assertEquals("direct://start", order.get(1).getRoute().getEndpoint().getEndpointUri());
    assertEquals("seda://bar", order.get(2).getRoute().getEndpoint().getEndpointUri());
    assertEquals("direct://bar", order.get(3).getRoute().getEndpoint().getEndpointUri());
    // the one with no startup order should be last
    assertEquals("direct://default", order.get(4).getRoute().getEndpoint().getEndpointUri());
}
项目:Camel    文件:RouteStartupOrderSuspendResumeNoAutoStartupTest.java   
public void testRouteStartupOrderSuspendResumeNoAutoStartup() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);

    template.sendBody("direct:start", "Hello World");

    assertMockEndpointsSatisfied();

    context.suspend();
    context.resume();

    // route C should still be stopped after we have resumed
    assertEquals(true, context.getRouteStatus("C").isStopped());

    // assert correct order
    DefaultCamelContext dcc = (DefaultCamelContext) context;
    List<RouteStartupOrder> order = dcc.getRouteStartupOrder();

    assertEquals(3, order.size());
    assertEquals("direct://foo", order.get(0).getRoute().getEndpoint().getEndpointUri());
    assertEquals("direct://start", order.get(1).getRoute().getEndpoint().getEndpointUri());
    assertEquals("direct://bar", order.get(2).getRoute().getEndpoint().getEndpointUri());
}
项目:drinkwater-java    文件:CamelContextFactory.java   
private static DefaultCamelContext createCamelContext(String prefix, String name, Registry registry) {
    DefaultCamelContext ctx = createWithRegistry(registry);
    ctx.setName(prefix + name);
    ctx.disableJMX();
    ctx.setStreamCaching(true);
    return ctx;
}
项目:drinkwater-java    文件:CamelContextFactory.java   
private static DefaultCamelContext createWithRegistry(Registry registry) {
    if (registry == null) {
        return new DefaultCamelContext();
    }

    return new DefaultCamelContext(registry);
}
项目:syndesis    文件:Application.java   
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
@Bean(name = "verifier-context", initMethod = "start", destroyMethod = "stop")
public static CamelContext verifierContext() {
    CamelContext context = new DefaultCamelContext();
    context.setNameStrategy(new ExplicitCamelContextNameStrategy("verifier-context"));
    context.disableJMX();

    return context;
}
项目:connectors    文件:SqlStoredStartConnectorComponentTest.java   
@Test
public void camelConnectorTest() throws Exception {

    BasicDataSource ds = new BasicDataSource();
    ds.setUsername(properties.getProperty("sql-stored-start-connector.user"));
    ds.setPassword(properties.getProperty("sql-stored-start-connector.password"));
    ds.setUrl(     properties.getProperty("sql-stored-start-connector.url"));

    SimpleRegistry registry = new SimpleRegistry();
    registry.put("dataSource", ds);
    CamelContext context = new DefaultCamelContext(registry);

    CountDownLatch latch = new CountDownLatch(1);

    final Result result = new Result();

    try {
        context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("sql-stored-start-connector:DEMO_OUT( OUT INTEGER c)")
                .process(new Processor() {
                    @Override
                    public void process(Exchange exchange)
                            throws Exception {
                        String jsonBean = (String) exchange.getIn().getBody();
                        result.setResult(jsonBean);
                        latch.countDown();
                    }
                }).to("stream:out");
            }
        });
        context.start();
        latch.await(5l,TimeUnit.SECONDS);
        Assert.assertEquals("{\"c\":60}", result.getJsonBean());
    } finally {
        context.stop();
    }
}
项目:sponge    文件:CamelProducerOverriddenActionTest.java   
@Test
public void testCamelProducerOverridenAction() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    Engine engine = DefaultEngine.builder().knowledgeBase("camelkb", "examples/camel/camel_producer_overridden_action.py").build();
    registry.put("spongeEngine", engine);
    CamelContext camel = new DefaultCamelContext(registry);

    camel.addRoutes(new RouteBuilder() {

        @Override
        public void configure() {
            // @formatter:off
            from("direct:start").routeId("spongeProducer")
                .to("sponge:spongeEngine");
            // @formatter:on
        }
    });

    camel.start();

    try {
        ProducerTemplate producerTemplate = camel.createProducerTemplate();
        producerTemplate.sendBody("direct:start", "Send me to the Sponge");

        await().pollDelay(2, TimeUnit.SECONDS).atMost(60, TimeUnit.SECONDS)
                .until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "sentCamelMessage_camelEvent").get());

        assertFalse(engine.getOperations().getVariable(AtomicBoolean.class, "sentCamelMessage_spongeProducer").get());
        assertFalse(engine.isError());
    } finally {
        camel.stop();
    }
}
项目:sponge    文件:SimpleCamelNoSpringTest.java   
@Test
public void testCamelProducer() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    Engine engine = DefaultEngine.builder().knowledgeBase("camelkb", "examples/camel/camel_producer.py").build();
    registry.put("spongeEngine", engine);
    CamelContext camel = new DefaultCamelContext(registry);

    camel.addRoutes(new RouteBuilder() {

        @Override
        public void configure() {
            // @formatter:off
            from("direct:start").routeId("spongeProducer")
                .to("sponge:spongeEngine");
            // @formatter:on
        }
    });

    camel.start();

    try {
        ProducerTemplate producerTemplate = camel.createProducerTemplate();
        producerTemplate.sendBody("direct:start", "Send me to the Sponge");

        await().atMost(10, TimeUnit.SECONDS)
                .until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "sentCamelMessage").get());
    } finally {
        camel.stop();
    }
}
项目:sponge    文件:SimpleCamelNoSpringTest.java   
@Test
public void testCamelConsumer() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    Engine engine = DefaultEngine.builder().knowledgeBase("camelkb", "examples/camel/camel_consumer.py").build();
    registry.put("spongeEngine", engine);
    CamelContext camel = new DefaultCamelContext(registry);

    camel.addRoutes(new RouteBuilder() {

        @Override
        public void configure() {
            // @formatter:off
            from("sponge:spongeEngine").routeId("spongeConsumer")
                .log("${body}")
                .process(exchange -> engine.getOperations().getVariable(AtomicBoolean.class, "receivedCamelMessage").set(true))
                .to("stream:out");
            // @formatter:on
        }
    });

    camel.start();

    try {
        engine.getOperations().event("spongeEvent").set("message", "Send me to Camel").send();

        await().atMost(60, TimeUnit.SECONDS)
                .until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "receivedCamelMessage").get());
        assertFalse(engine.isError());
    } finally {
        camel.stop();
    }
}
项目:bitbreeds-webrtc    文件:ProcessSignalsTest.java   
@Test
public void testCandidateParsing() throws Exception {
    Exchange ex = new DefaultExchange(new DefaultCamelContext());
    ex.getIn().setBody(candidate);
    processor.process(ex);
    assertEquals(ex.getIn().getBody().getClass(),IceCandidate.class);
}
项目:bitbreeds-webrtc    文件:ProcessSignalsTest.java   
@Test
public void testSDPParsing() throws Exception {
    Exchange ex = new DefaultExchange(new DefaultCamelContext());
    ex.getIn().setBody(offerSdp);
    processor.process(ex);
    assertEquals(ex.getIn().getBody().getClass(),Offer.class);
}
项目:bitbreeds-webrtc    文件:ProcessSignalsTest.java   
@Test
public void testSDPParseAnswer() throws Exception {
    Exchange ex = new DefaultExchange(new DefaultCamelContext());
    ex.getIn().setBody(answerSdp);
    processor.process(ex);
    assertEquals(ex.getIn().getBody().getClass(),Answer.class);
}