コード例 #1
0
  @Test
  public void testSQLEndpoint() throws Exception {
    Assert.assertNotNull("DataSource not null", dataSource);

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(
        new RouteBuilder() {
          @Override
          public void configure() throws Exception {
            from("sql:select name from information_schema.users?dataSource=java:jboss/datasources/ExampleDS")
                .to("direct:end");
          }
        });

    camelctx.start();
    try {
      PollingConsumer pollingConsumer = camelctx.getEndpoint("direct:end").createPollingConsumer();
      pollingConsumer.start();

      String result = (String) pollingConsumer.receive().getIn().getBody(Map.class).get("NAME");
      Assert.assertEquals("SA", result);
    } finally {
      camelctx.stop();
    }
  }
コード例 #2
0
  @Test
  public void testSQLEndpointWithCDIContext() throws Exception {
    try {
      deployer.deploy(CAMEL_SQL_CDI_ROUTES_JAR);

      CamelContext camelctx = contextRegistry.getCamelContext("camel-sql-cdi-context");
      Assert.assertNotNull("Camel context not null", camelctx);

      PollingConsumer pollingConsumer = camelctx.getEndpoint("direct:end").createPollingConsumer();
      pollingConsumer.start();

      String result = (String) pollingConsumer.receive().getIn().getBody(Map.class).get("NAME");
      Assert.assertEquals("SA", result);
    } finally {
      deployer.undeploy(CAMEL_SQL_CDI_ROUTES_JAR);
    }
  }