Search in sources :

Example 11 with JavaClassSource

use of org.jboss.forge.roaster.model.source.JavaClassSource in project camel by apache.

the class RoasterSimpleRouteBuilderConfigureTest method parse.

@Test
public void parse() throws Exception {
    JavaClassSource clazz = (JavaClassSource) Roaster.parse(new File("src/test/java/org/apache/camel/parser/java/MySimpleRouteBuilder.java"));
    MethodSource<JavaClassSource> method = clazz.getMethod("configure");
    List<ParserResult> list = CamelJavaParserHelper.parseCamelSimpleExpressions(method);
    for (ParserResult simple : list) {
        LOG.info("Simple: " + simple.getElement());
        LOG.info("  Line: " + findLineNumber(simple.getPosition()));
    }
    Assert.assertEquals("${body} > 100", list.get(0).getElement());
    Assert.assertEquals(true, list.get(0).getPredicate());
    Assert.assertEquals(27, findLineNumber(list.get(0).getPosition()));
    Assert.assertEquals("${body} > 200", list.get(1).getElement());
    Assert.assertEquals(true, list.get(1).getPredicate());
    Assert.assertEquals(30, findLineNumber(list.get(1).getPosition()));
}
Also used : ParserResult(org.apache.camel.parser.ParserResult) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) File(java.io.File) Test(org.junit.Test)

Example 12 with JavaClassSource

use of org.jboss.forge.roaster.model.source.JavaClassSource in project camel by apache.

the class RoasterSimpleToFTest method parse.

@Test
public void parse() throws Exception {
    JavaClassSource clazz = (JavaClassSource) Roaster.parse(new File("src/test/java/org/apache/camel/parser/java/MySimpleToFRoute.java"));
    MethodSource<JavaClassSource> method = CamelJavaParserHelper.findConfigureMethod(clazz);
    List<CamelEndpointDetails> details = new ArrayList<>();
    RouteBuilderParser.parseRouteBuilderEndpoints(clazz, ".", "src/test/java/org/apache/camel/parser/java/MySimpleToFRoute.java", details);
    LOG.info("{}", details);
    List<ParserResult> list = CamelJavaParserHelper.parseCamelConsumerUris(method, true, true);
    for (ParserResult result : list) {
        LOG.info("Consumer: " + result.getElement());
    }
    Assert.assertEquals("direct:start", list.get(0).getElement());
    list = CamelJavaParserHelper.parseCamelProducerUris(method, true, true);
    for (ParserResult result : list) {
        LOG.info("Producer: " + result.getElement());
    }
    Assert.assertEquals("toF", list.get(0).getNode());
    Assert.assertEquals("log:a?level={{%s}}", list.get(0).getElement());
    Assert.assertEquals(1, list.size());
    Assert.assertEquals(2, details.size());
    Assert.assertEquals("direct:start", details.get(0).getEndpointUri());
    Assert.assertEquals("log:a?level={{%s}}", details.get(1).getEndpointUri());
}
Also used : CamelEndpointDetails(org.apache.camel.parser.model.CamelEndpointDetails) ParserResult(org.apache.camel.parser.ParserResult) ArrayList(java.util.ArrayList) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) File(java.io.File) Test(org.junit.Test)

Example 13 with JavaClassSource

use of org.jboss.forge.roaster.model.source.JavaClassSource in project camel by apache.

the class RoasterSplitTokenizeTest method parse.

@Test
public void parse() throws Exception {
    JavaClassSource clazz = (JavaClassSource) Roaster.parse(new File("src/test/java/org/apache/camel/parser/java/SplitTokenizeTest.java"));
    MethodSource<JavaClassSource> method = CamelJavaParserHelper.findConfigureMethod(clazz);
    List<CamelEndpointDetails> details = new ArrayList<>();
    RouteBuilderParser.parseRouteBuilderEndpoints(clazz, "src/test/java", "org/apache/camel/parser/SplitTokenizeTest.java", details);
    LOG.info("{}", details);
    List<ParserResult> list = CamelJavaParserHelper.parseCamelConsumerUris(method, true, true);
    for (ParserResult result : list) {
        LOG.info("Consumer: " + result.getElement());
    }
    Assert.assertEquals("direct:a", list.get(0).getElement());
    Assert.assertEquals("direct:b", list.get(1).getElement());
    Assert.assertEquals("direct:c", list.get(2).getElement());
    Assert.assertEquals("direct:d", list.get(3).getElement());
    Assert.assertEquals("direct:e", list.get(4).getElement());
    Assert.assertEquals("direct:f", list.get(5).getElement());
    list = CamelJavaParserHelper.parseCamelProducerUris(method, true, true);
    for (ParserResult result : list) {
        LOG.info("Producer: " + result.getElement());
    }
    Assert.assertEquals("mock:split", list.get(0).getElement());
    Assert.assertEquals("mock:split", list.get(1).getElement());
    Assert.assertEquals("mock:split", list.get(2).getElement());
    Assert.assertEquals("mock:split", list.get(3).getElement());
    Assert.assertEquals("mock:split", list.get(4).getElement());
    Assert.assertEquals("mock:split", list.get(5).getElement());
    Assert.assertEquals(12, details.size());
    Assert.assertEquals("direct:a", details.get(0).getEndpointUri());
    Assert.assertEquals("mock:split", details.get(11).getEndpointUri());
}
Also used : CamelEndpointDetails(org.apache.camel.parser.model.CamelEndpointDetails) ParserResult(org.apache.camel.parser.ParserResult) ArrayList(java.util.ArrayList) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) File(java.io.File) Test(org.junit.Test)

Example 14 with JavaClassSource

use of org.jboss.forge.roaster.model.source.JavaClassSource in project camel by apache.

the class RoasterCdiConcatRouteBuilderConfigureTest method parse.

@Test
public void parse() throws Exception {
    JavaClassSource clazz = (JavaClassSource) Roaster.parse(new File("src/test/java/org/apache/camel/parser/java/MyCdiConcatRouteBuilder.java"));
    MethodSource<JavaClassSource> method = clazz.getMethod("configure");
    List<ParserResult> list = CamelJavaParserHelper.parseCamelConsumerUris(method, true, true);
    for (ParserResult result : list) {
        LOG.info("Consumer: " + result.getElement());
    }
    Assert.assertEquals("timer:foo?period=4999", list.get(0).getElement());
    list = CamelJavaParserHelper.parseCamelProducerUris(method, true, true);
    for (ParserResult result : list) {
        LOG.info("Producer: " + result.getElement());
    }
    Assert.assertEquals("log:a", list.get(0).getElement());
    Assert.assertEquals("netty4-http:http:someserver:80/hello", list.get(1).getElement());
}
Also used : ParserResult(org.apache.camel.parser.ParserResult) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) File(java.io.File) Test(org.junit.Test)

Example 15 with JavaClassSource

use of org.jboss.forge.roaster.model.source.JavaClassSource in project camel by apache.

the class RoasterCdiRouteBuilderConfigureTest method parse.

@Test
public void parse() throws Exception {
    JavaClassSource clazz = (JavaClassSource) Roaster.parse(new File("src/test/java/org/apache/camel/parser/java/MyCdiRouteBuilder.java"));
    MethodSource<JavaClassSource> method = clazz.getMethod("configure");
    List<ParserResult> list = CamelJavaParserHelper.parseCamelConsumerUris(method, true, true);
    for (ParserResult result : list) {
        LOG.info("Consumer: " + result.getElement());
    }
    Assert.assertEquals("timer:foo?period=4999", list.get(0).getElement());
    list = CamelJavaParserHelper.parseCamelProducerUris(method, true, true);
    for (ParserResult result : list) {
        LOG.info("Producer: " + result.getElement());
    }
    Assert.assertEquals("log:a", list.get(0).getElement());
    Assert.assertEquals("netty4-http:http:someserver:80/hello", list.get(1).getElement());
}
Also used : ParserResult(org.apache.camel.parser.ParserResult) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) File(java.io.File) Test(org.junit.Test)

Aggregations

JavaClassSource (org.jboss.forge.roaster.model.source.JavaClassSource)95 File (java.io.File)37 ArrayList (java.util.ArrayList)28 Test (org.junit.Test)26 ParserResult (org.apache.camel.parser.ParserResult)19 List (java.util.List)15 IOException (java.io.IOException)14 MethodSource (org.jboss.forge.roaster.model.source.MethodSource)12 InputStream (java.io.InputStream)10 Collections (java.util.Collections)10 Roaster (org.jboss.forge.roaster.Roaster)10 BufferedReader (java.io.BufferedReader)8 HashMap (java.util.HashMap)8 Matcher (java.util.regex.Matcher)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)8 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)8 Arrays (java.util.Arrays)7 Map (java.util.Map)7 Import (org.jboss.forge.roaster.model.source.Import)7 ClassTypeResolver (org.kie.soup.project.datamodel.commons.types.ClassTypeResolver)7