Search in sources :

Example 1 with ExplicitCamelContextNameStrategy

use of org.apache.camel.impl.ExplicitCamelContextNameStrategy in project camel by apache.

the class ContextListCommandTest method testEndpointStats.

@Test
public void testEndpointStats() throws Exception {
    CamelContext context = new DefaultCamelContext();
    context.setNameStrategy(new ExplicitCamelContextNameStrategy("foobar"));
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").to("mock:result");
        }
    });
    context.start();
    context.createProducerTemplate().sendBody("direct:start", "Hello World");
    CamelController controller = new DummyCamelController(context);
    OutputStream os = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(os);
    EndpointStatisticCommand command = new EndpointStatisticCommand("foobar", false, null);
    command.execute(controller, ps, null);
    String out = os.toString();
    assertNotNull(out);
    LOG.info("\n\n{}\n", out);
    assertTrue(out.contains("direct://start"));
    assertTrue(out.contains("mock://result"));
    context.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) PrintStream(java.io.PrintStream) ExplicitCamelContextNameStrategy(org.apache.camel.impl.ExplicitCamelContextNameStrategy) RouteBuilder(org.apache.camel.builder.RouteBuilder) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 2 with ExplicitCamelContextNameStrategy

use of org.apache.camel.impl.ExplicitCamelContextNameStrategy in project camel by apache.

the class ContextListCommandTest method testContextList.

@Test
public void testContextList() 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);
    ContextListCommand command = new ContextListCommand();
    command.execute(controller, ps, null);
    String out = os.toString();
    assertNotNull(out);
    LOG.info("\n\n{}\n", out);
    // should contain a table with the context
    assertTrue(out.contains("foobar"));
    assertTrue(out.contains("Started"));
    context.stop();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) PrintStream(java.io.PrintStream) ExplicitCamelContextNameStrategy(org.apache.camel.impl.ExplicitCamelContextNameStrategy) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 3 with ExplicitCamelContextNameStrategy

use of org.apache.camel.impl.ExplicitCamelContextNameStrategy in project camel by apache.

the class ValidatorListCommandTest method doTest.

private String doTest(boolean verbose) throws Exception {
    CamelContext context = new DefaultCamelContext();
    EndpointValidatorDefinition evd = new EndpointValidatorDefinition();
    evd.setType("xml:foo");
    evd.setUri("direct:validator");
    context.getValidators().add(evd);
    PredicateValidatorDefinition pvd = new PredicateValidatorDefinition();
    pvd.setType(this.getClass());
    pvd.setExpression(new ExpressionDefinition(ExpressionBuilder.bodyExpression()));
    context.getValidators().add(pvd);
    CustomValidatorDefinition cvd = new CustomValidatorDefinition();
    cvd.setType("custom");
    cvd.setClassName(MyValidator.class.getName());
    context.getValidators().add(cvd);
    context.setNameStrategy(new ExplicitCamelContextNameStrategy("foobar"));
    context.start();
    CamelController controller = new DummyCamelController(context);
    OutputStream os = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(os);
    ValidatorListCommand command = new ValidatorListCommand(null, false, verbose, false);
    command.execute(controller, ps, null);
    String out = os.toString();
    assertNotNull(out);
    LOG.info("\n\n{}\n", out);
    context.stop();
    return out;
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) PrintStream(java.io.PrintStream) ExplicitCamelContextNameStrategy(org.apache.camel.impl.ExplicitCamelContextNameStrategy) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) PredicateValidatorDefinition(org.apache.camel.model.validator.PredicateValidatorDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) EndpointValidatorDefinition(org.apache.camel.model.validator.EndpointValidatorDefinition) CustomValidatorDefinition(org.apache.camel.model.validator.CustomValidatorDefinition) ExpressionDefinition(org.apache.camel.model.language.ExpressionDefinition)

Example 4 with ExplicitCamelContextNameStrategy

use of org.apache.camel.impl.ExplicitCamelContextNameStrategy in project camel by apache.

the class TransformerListCommandTest method doTest.

private String doTest(boolean verbose) throws Exception {
    CamelContext context = new DefaultCamelContext();
    EndpointTransformerDefinition etd = new EndpointTransformerDefinition();
    etd.setFromType("xml:foo");
    etd.setToType("json:bar");
    etd.setUri("direct:transformer");
    context.getTransformers().add(etd);
    DataFormatTransformerDefinition dftd = new DataFormatTransformerDefinition();
    dftd.setFromType(this.getClass());
    dftd.setToType("xml:test");
    dftd.setDataFormatType(new StringDataFormat());
    context.getTransformers().add(dftd);
    CustomTransformerDefinition ctd = new CustomTransformerDefinition();
    ctd.setScheme("custom");
    ctd.setClassName(MyTransformer.class.getName());
    context.getTransformers().add(ctd);
    context.setNameStrategy(new ExplicitCamelContextNameStrategy("foobar"));
    context.start();
    CamelController controller = new DummyCamelController(context);
    OutputStream os = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(os);
    TransformerListCommand command = new TransformerListCommand(null, false, verbose, false);
    command.execute(controller, ps, null);
    String out = os.toString();
    assertNotNull(out);
    LOG.info("\n\n{}\n", out);
    context.stop();
    return out;
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) PrintStream(java.io.PrintStream) ExplicitCamelContextNameStrategy(org.apache.camel.impl.ExplicitCamelContextNameStrategy) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EndpointTransformerDefinition(org.apache.camel.model.transformer.EndpointTransformerDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DataFormatTransformerDefinition(org.apache.camel.model.transformer.DataFormatTransformerDefinition) CustomTransformerDefinition(org.apache.camel.model.transformer.CustomTransformerDefinition) StringDataFormat(org.apache.camel.model.dataformat.StringDataFormat)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 OutputStream (java.io.OutputStream)4 PrintStream (java.io.PrintStream)4 CamelContext (org.apache.camel.CamelContext)4 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)4 ExplicitCamelContextNameStrategy (org.apache.camel.impl.ExplicitCamelContextNameStrategy)4 Test (org.junit.Test)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 StringDataFormat (org.apache.camel.model.dataformat.StringDataFormat)1 ExpressionDefinition (org.apache.camel.model.language.ExpressionDefinition)1 CustomTransformerDefinition (org.apache.camel.model.transformer.CustomTransformerDefinition)1 DataFormatTransformerDefinition (org.apache.camel.model.transformer.DataFormatTransformerDefinition)1 EndpointTransformerDefinition (org.apache.camel.model.transformer.EndpointTransformerDefinition)1 CustomValidatorDefinition (org.apache.camel.model.validator.CustomValidatorDefinition)1 EndpointValidatorDefinition (org.apache.camel.model.validator.EndpointValidatorDefinition)1 PredicateValidatorDefinition (org.apache.camel.model.validator.PredicateValidatorDefinition)1