Exemplo n.º 1
0
 public String componentParameterJsonSchema(String componentName) throws Exception {
   // favor using pre generated schema if component has that
   String json = context.getComponentParameterJsonSchema(componentName);
   if (json == null) {
     // okay this requires having the component on the classpath and being instantiated
     Component component = context.getComponent(componentName);
     if (component != null) {
       ComponentConfiguration configuration = component.createComponentConfiguration();
       json = configuration.createParameterJsonSchema();
     }
   }
   return json;
 }
  @Test
  public void testComponentConfiguration() throws Exception {
    TimerComponent comp = context.getComponent("timer", TimerComponent.class);
    EndpointConfiguration conf = comp.createConfiguration("timer:foo?period=2000");

    assertEquals("2000", conf.getParameter("period"));

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

    assertTrue(json.contains("\"timerName\": { \"type\": \"java.lang.String\" }"));
    assertTrue(json.contains("\"delay\": { \"type\": \"long\" }"));
  }
  @Test
  public void testComponentConfiguration() throws Exception {
    TestComponent comp = context.getComponent("test", TestComponent.class);
    EndpointConfiguration conf = comp.createConfiguration("test:my:foo?timeout=1000");

    assertEquals("1000", conf.getParameter("timeout"));

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

    assertTrue(json.contains("\"retainFirst\": { \"type\": \"int\" }"));
    assertTrue(json.contains("\"timeout\": { \"type\": \"long\" }"));
  }
  @Test
  public void testComponentConfiguration() throws Exception {
    DirectComponent comp = context.getComponent("direct", DirectComponent.class);
    EndpointConfiguration conf = comp.createConfiguration("direct:foo?block=true");

    assertEquals("true", conf.getParameter("block"));

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

    assertTrue(json.contains("\"timeout\": { \"type\": \"long\" }"));
    assertTrue(json.contains("\"block\": { \"type\": \"boolean\" }"));
  }
  @Test
  public void testComponentConfiguration() throws Exception {
    SqlComponent comp = context.getComponent("sql", SqlComponent.class);
    EndpointConfiguration conf =
        comp.createConfiguration(
            "sql:select?dataSourceRef=jdbc/myDataSource&allowNamedParameters=true&consumer.delay=5000");

    assertEquals("jdbc/myDataSource", conf.getParameter("dataSourceRef"));
    assertEquals("true", conf.getParameter("allowNamedParameters"));

    ComponentConfiguration compConf = comp.createComponentConfiguration();
    String json = compConf.createParameterJsonSchema();
    assertNotNull(json);
  }
  @Test
  public void testComponentConfiguration() throws Exception {
    NettyHttpComponent comp = context.getComponent("netty4-http", NettyHttpComponent.class);
    EndpointConfiguration conf =
        comp.createConfiguration(
            "netty4-http:tcp://localhost:5150?sync=true"
                + "&httpMethodRestrict=POST&traceEnabled=true");

    assertEquals("true", conf.getParameter("traceEnabled"));
    assertEquals("POST", conf.getParameter("httpMethodRestrict"));

    ComponentConfiguration compConf = comp.createComponentConfiguration();
    String json = compConf.createParameterJsonSchema();
    assertNotNull(json);
  }
  @Test
  public void testComponentConfiguration() throws Exception {
    NettyComponent comp = context.getComponent("netty4", NettyComponent.class);
    EndpointConfiguration conf =
        comp.createConfiguration(
            "netty4:tcp://localhost:5150?sync=true"
                + "&maximumPoolSize=32&ssl=true&passphrase=#password");

    assertEquals("true", conf.getParameter("sync"));
    assertEquals("32", conf.getParameter("maximumPoolSize"));

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

    assertTrue(json.contains("\"producerPoolMinEvictableIdle\": { \"type\": \"integer\" }"));
    assertTrue(json.contains("\"allowDefaultCodec\": { \"type\": \"boolean\" }"));
  }
  @Test
  public void testComponentConfiguration() throws Exception {
    DataSetComponent comp = context.getComponent("dataset", DataSetComponent.class);
    EndpointConfiguration conf =
        comp.createConfiguration(
            "dataset:foo?minRate=3&produceDelay=33&consumeDelay=333&preloadSize=3333&initialDelay=33333&disableDataSetIndex=true");

    assertEquals(
        "Unexpected endpoint configuration value for minRate", "3", conf.getParameter("minRate"));
    assertEquals(
        "Unexpected endpoint configuration value for produceDelay",
        "33",
        conf.getParameter("produceDelay"));
    assertEquals(
        "Unexpected endpoint configuration value for consumeDelay",
        "333",
        conf.getParameter("consumeDelay"));
    assertEquals(
        "Unexpected endpoint configuration value for preloadSize",
        "3333",
        conf.getParameter("preloadSize"));
    assertEquals(
        "Unexpected endpoint configuration value for initialDelay",
        "33333",
        conf.getParameter("initialDelay"));
    assertEquals(
        "Unexpected endpoint configuration value for disableDataSetIndex",
        "true",
        conf.getParameter("disableDataSetIndex"));

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

    assertTrue(
        json.contains(
            "\"name\": { \"kind\": \"path\", \"group\": \"common\", \"required\": \"true\", \"type\""));
    assertTrue(
        json.contains(
            "\"kind\": \"parameter\", \"group\": \"consumer\", \"label\": \"consumer\", \"type\": \"integer\""));
    assertTrue(
        json.contains(
            "\"retainFirst\": { \"kind\": \"parameter\", \"group\": \"producer\", \"label\": \"producer\", \"type\": \"integer"));
  }
  @Test
  public void testComponentConfiguration() throws Exception {
    DataSetComponent comp = context.getComponent("dataset", DataSetComponent.class);
    EndpointConfiguration conf = comp.createConfiguration("dataset:foo?minRate=3");

    assertEquals("3", conf.getParameter("minRate"));

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

    assertTrue(json.contains("\"preloadSize\": { \"kind\": \"parameter\", \"type\": \"integer\""));
    assertTrue(json.contains("\"minRate\": { \"kind\": \"parameter\", \"type\": \"integer\""));
    assertTrue(
        json.contains(
            "\"exchangePattern\": { \"kind\": \"parameter\", \"label\": \"advanced\", \"type\": \"string\", \"javaType\": \"org.apache.camel.ExchangePattern\""
                + ", \"enum\": [ \"InOnly\", \"RobustInOnly\", \"InOut\", \"InOptionalOut\", \"OutOnly\", \"RobustOutOnly\", \"OutIn\", \"OutOptionalIn\" ]"));
    assertTrue(json.contains("\"InOut\""));
  }