Search in sources :

Example 16 with ParserResult

use of org.apache.camel.parser.ParserResult in project camel by apache.

the class RoasterEndpointInjectTest 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 = CamelJavaParserHelper.findConfigureMethod(clazz);
    List<CamelEndpointDetails> details = new ArrayList<>();
    RouteBuilderParser.parseRouteBuilderEndpoints(clazz, ".", "src/test/java/org/apache/camel/parser/java/MyCdiRouteBuilder.java", details);
    LOG.info("{}", details);
    Assert.assertEquals("timer:foo?period=4999", details.get(0).getEndpointUri());
    Assert.assertEquals("28", details.get(0).getLineNumber());
    Assert.assertEquals("log:a", details.get(1).getEndpointUri());
    Assert.assertEquals("32", details.get(1).getLineNumber());
    Assert.assertEquals("netty4-http:http:someserver:80/hello", details.get(2).getEndpointUri());
    Assert.assertEquals("36", details.get(2).getLineNumber());
    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(2, list.size());
    Assert.assertEquals(5, details.size());
    Assert.assertEquals("log:a", details.get(3).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 17 with ParserResult

use of org.apache.camel.parser.ParserResult in project camel by apache.

the class RoasterMethodCallRouteBuilderConfigureTest method parse.

@Test
public void parse() throws Exception {
    JavaClassSource clazz = (JavaClassSource) Roaster.parse(new File("src/test/java/org/apache/camel/parser/java/MyMethodCallRouteBuilder.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", list.get(0).getElement());
    list = CamelJavaParserHelper.parseCamelProducerUris(method, true, true);
    for (ParserResult result : list) {
        LOG.info("Producer: " + result.getElement());
    }
    Assert.assertEquals("file:output?fileExist={{whatToDoWhenExists}}", list.get(0).getElement());
    Assert.assertEquals("log:b", 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 18 with ParserResult

use of org.apache.camel.parser.ParserResult in project camel by apache.

the class RoasterSimpleToDTest method parse.

@Test
public void parse() throws Exception {
    JavaClassSource clazz = (JavaClassSource) Roaster.parse(new File("src/test/java/org/apache/camel/parser/java/MySimpleToDRoute.java"));
    MethodSource<JavaClassSource> method = CamelJavaParserHelper.findConfigureMethod(clazz);
    List<CamelEndpointDetails> details = new ArrayList<>();
    RouteBuilderParser.parseRouteBuilderEndpoints(clazz, ".", "src/test/java/org/apache/camel/parser/java/MySimpleToDRoute.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("toD", list.get(0).getNode());
    Assert.assertEquals("log:a", list.get(0).getElement());
    Assert.assertEquals("to", list.get(1).getNode());
    Assert.assertEquals("log:b", list.get(1).getElement());
    Assert.assertEquals("to", list.get(2).getNode());
    Assert.assertEquals("log:c", list.get(2).getElement());
    Assert.assertEquals(3, list.size());
    Assert.assertEquals(4, details.size());
    Assert.assertEquals("direct:start", details.get(0).getEndpointUri());
    Assert.assertEquals("log:a", details.get(1).getEndpointUri());
    Assert.assertEquals("log:b", details.get(2).getEndpointUri());
    Assert.assertEquals("log:c", details.get(3).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 19 with ParserResult

use of org.apache.camel.parser.ParserResult in project camel by apache.

the class RoasterMyLocalAddRouteBuilderTest method parse.

@Test
public void parse() throws Exception {
    JavaClassSource clazz = (JavaClassSource) Roaster.parse(new File("src/test/java/org/apache/camel/parser/java/MyLocalAddRouteBuilderTest.java"));
    MethodSource<JavaClassSource> method = CamelJavaParserHelper.findConfigureMethod(clazz);
    Assert.assertNull(method);
    List<MethodSource<JavaClassSource>> methods = CamelJavaParserHelper.findInlinedConfigureMethods(clazz);
    Assert.assertEquals(1, methods.size());
    method = methods.get(0);
    List<ParserResult> list = CamelJavaParserHelper.parseCamelConsumerUris(method, true, true);
    for (ParserResult result : list) {
        LOG.info("Consumer: " + result.getElement());
    }
    list = CamelJavaParserHelper.parseCamelProducerUris(method, true, true);
    for (ParserResult result : list) {
        LOG.info("Producer: " + result.getElement());
    }
}
Also used : ParserResult(org.apache.camel.parser.ParserResult) MethodSource(org.jboss.forge.roaster.model.source.MethodSource) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource) File(java.io.File) Test(org.junit.Test)

Example 20 with ParserResult

use of org.apache.camel.parser.ParserResult in project camel by apache.

the class RoasterNewLineRouteBuilderConfigureTest method parse.

@Test
public void parse() throws Exception {
    JavaClassSource clazz = (JavaClassSource) Roaster.parse(new File("src/test/java/org/apache/camel/parser/java/MyNewLineRouteBuilder.java"));
    MethodSource<JavaClassSource> method = clazz.getMethod("configure");
    List<ParserResult> list = CamelJavaParserHelper.parseCamelConsumerUris(method, true, false);
    for (ParserResult result : list) {
        LOG.info("Consumer: " + result.getElement());
    }
    Assert.assertEquals("timer:foo", list.get(0).getElement());
    list = CamelJavaParserHelper.parseCamelProducerUris(method, true, false);
    for (ParserResult result : list) {
        LOG.info("Producer: " + result.getElement());
    }
    Assert.assertEquals("file:output?fileExist=Append&chmod=777&allowNullBody=true", list.get(0).getElement());
    Assert.assertEquals("log:b", 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

ParserResult (org.apache.camel.parser.ParserResult)23 File (java.io.File)19 JavaClassSource (org.jboss.forge.roaster.model.source.JavaClassSource)19 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)9 CamelEndpointDetails (org.apache.camel.parser.model.CamelEndpointDetails)5 Expression (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.Expression)4 InfixExpression (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.InfixExpression)4 ParenthesizedExpression (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.ParenthesizedExpression)4 List (java.util.List)2 Block (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.Block)2 ExpressionStatement (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.ExpressionStatement)2 MethodDeclaration (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.MethodDeclaration)2 StatementFieldSource (org.apache.camel.parser.roaster.StatementFieldSource)1 ASTNode (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.ASTNode)1 MemberValuePair (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.MemberValuePair)1 MethodInvocation (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.MethodInvocation)1 NormalAnnotation (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.NormalAnnotation)1 SimpleName (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.SimpleName)1 SingleMemberAnnotation (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.SingleMemberAnnotation)1