You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/10/14 12:24:41 UTC
[1/6] camel git commit: Fixed camel-router-parser to only parse when
its starting from a Camel route via from/route
Repository: camel
Updated Branches:
refs/heads/master a7507237d -> ce6a9532a
Fixed camel-router-parser to only parse when its starting from a Camel route via from/route
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/77f4a7e4
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/77f4a7e4
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/77f4a7e4
Branch: refs/heads/master
Commit: 77f4a7e4d5e8cc9aa8ce4bea7c2e8ee78385c64f
Parents: 4393783
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Oct 14 14:05:56 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Oct 14 14:09:42 2017 +0200
----------------------------------------------------------------------
.../helper/CamelJavaTreeParserHelper.java | 30 +++++++++++++++++++-
.../parser/java/MyJavaDslRouteBuilder.java | 3 ++
.../camel/parser/java/RoasterJavaDslTest.java | 17 +++++------
3 files changed, 41 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/77f4a7e4/tooling/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaTreeParserHelper.java
----------------------------------------------------------------------
diff --git a/tooling/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaTreeParserHelper.java b/tooling/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaTreeParserHelper.java
index 774831f..bce6f44 100644
--- a/tooling/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaTreeParserHelper.java
+++ b/tooling/camel-route-parser/src/main/java/org/apache/camel/parser/helper/CamelJavaTreeParserHelper.java
@@ -36,6 +36,7 @@ import org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.BooleanLiteral;
import org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.Expression;
import org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.ExpressionStatement;
import org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.ITypeBinding;
import org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.InfixExpression;
import org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.MemberValuePair;
import org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.MethodDeclaration;
@@ -83,7 +84,10 @@ public final class CamelJavaTreeParserHelper {
if (statement instanceof ExpressionStatement) {
ExpressionStatement es = (ExpressionStatement) statement;
Expression exp = es.getExpression();
- parseExpression(nodeFactory, fullyQualifiedFileName, clazz, configureMethod, block, exp, route);
+ boolean valid = isFromCamelRoute(exp);
+ if (valid) {
+ parseExpression(nodeFactory, fullyQualifiedFileName, clazz, configureMethod, block, exp, route);
+ }
}
}
}
@@ -146,6 +150,30 @@ public final class CamelJavaTreeParserHelper {
return answer;
}
+ private boolean isFromCamelRoute(Expression exp) {
+ String rootMethodName = null;
+
+ // find out if this is from a Camel route (eg from, route etc.)
+ Expression sub = exp;
+ while (sub instanceof MethodInvocation) {
+ sub = ((MethodInvocation) sub).getExpression();
+ if (sub instanceof MethodInvocation) {
+ Expression parent = ((MethodInvocation) sub).getExpression();
+ if (parent == null) {
+ break;
+ }
+ }
+ }
+ if (sub instanceof MethodInvocation) {
+ rootMethodName = ((MethodInvocation) sub).getName().getIdentifier();
+ } else if (sub instanceof SimpleName) {
+ rootMethodName = ((SimpleName) sub).getIdentifier();
+ }
+
+ // a route starts either via from or route
+ return "from".equals(rootMethodName) || "route".equals(rootMethodName);
+ }
+
private boolean hasOutput(String name) {
String json = camelCatalog.modelJSonSchema(name);
List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("model", json, false);
http://git-wip-us.apache.org/repos/asf/camel/blob/77f4a7e4/tooling/camel-route-parser/src/test/java/org/apache/camel/parser/java/MyJavaDslRouteBuilder.java
----------------------------------------------------------------------
diff --git a/tooling/camel-route-parser/src/test/java/org/apache/camel/parser/java/MyJavaDslRouteBuilder.java b/tooling/camel-route-parser/src/test/java/org/apache/camel/parser/java/MyJavaDslRouteBuilder.java
index 078c70b..b63def8 100644
--- a/tooling/camel-route-parser/src/test/java/org/apache/camel/parser/java/MyJavaDslRouteBuilder.java
+++ b/tooling/camel-route-parser/src/test/java/org/apache/camel/parser/java/MyJavaDslRouteBuilder.java
@@ -22,6 +22,9 @@ public class MyJavaDslRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
+ // setProperty is also a model name but this should not be parsed as part of a Camel route
+ System.setProperty("ENV", "src/test/resources/");
+
from("direct:start").routeId("bar")
.log("I was here")
.setHeader("foo", constant("123"))
http://git-wip-us.apache.org/repos/asf/camel/blob/77f4a7e4/tooling/camel-route-parser/src/test/java/org/apache/camel/parser/java/RoasterJavaDslTest.java
----------------------------------------------------------------------
diff --git a/tooling/camel-route-parser/src/test/java/org/apache/camel/parser/java/RoasterJavaDslTest.java b/tooling/camel-route-parser/src/test/java/org/apache/camel/parser/java/RoasterJavaDslTest.java
index c6bc96b..268022a 100644
--- a/tooling/camel-route-parser/src/test/java/org/apache/camel/parser/java/RoasterJavaDslTest.java
+++ b/tooling/camel-route-parser/src/test/java/org/apache/camel/parser/java/RoasterJavaDslTest.java
@@ -53,14 +53,15 @@ public class RoasterJavaDslTest extends CamelTestSupport {
String tree = details.dump(0);
LOG.info("\n" + tree);
- assertTrue(tree.contains("25\tfrom"));
- assertTrue(tree.contains("27\t setHeader"));
- assertTrue(tree.contains("28\t choice"));
- assertTrue(tree.contains("30\t to"));
- assertTrue(tree.contains("31\t toD"));
- assertTrue(tree.contains("33\t toD"));
- assertTrue(tree.contains("35\t log"));
- assertTrue(tree.contains("37\t to"));
+ assertTrue(tree.contains("28\tfrom"));
+ assertTrue(tree.contains("29\t log"));
+ assertTrue(tree.contains("30\t setHeader"));
+ assertTrue(tree.contains("31\t choice"));
+ assertTrue(tree.contains("33\t to"));
+ assertTrue(tree.contains("34\t toD"));
+ assertTrue(tree.contains("36\t toD"));
+ assertTrue(tree.contains("38\t log"));
+ assertTrue(tree.contains("40\t to"));
}
@Test
[4/6] camel git commit: Fixed typo
Posted by da...@apache.org.
Fixed typo
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9bd1e299
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9bd1e299
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9bd1e299
Branch: refs/heads/master
Commit: 9bd1e2991d1b66e984ede34eb06ef74e4e5cba42
Parents: f5851a3
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Oct 13 10:30:03 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Oct 14 14:09:42 2017 +0200
----------------------------------------------------------------------
.../velocity/VelocityLetterWithParserTest.java | 31 ++++++++++++++++++++
.../velocity/VelocityLetterWithPaserTest.java | 31 --------------------
2 files changed, 31 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/9bd1e299/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityLetterWithParserTest.java
----------------------------------------------------------------------
diff --git a/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityLetterWithParserTest.java b/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityLetterWithParserTest.java
new file mode 100644
index 0000000..b557ddc
--- /dev/null
+++ b/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityLetterWithParserTest.java
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.velocity;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class VelocityLetterWithParserTest extends VelocityLetterTest {
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ from("direct:a").
+ to("velocity:org/apache/camel/component/velocity/letterWithParser.vm?propertiesFile=org/apache/camel/component/velocity/velocity.properties").to("mock:result");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/9bd1e299/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityLetterWithPaserTest.java
----------------------------------------------------------------------
diff --git a/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityLetterWithPaserTest.java b/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityLetterWithPaserTest.java
deleted file mode 100644
index 760a206..0000000
--- a/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityLetterWithPaserTest.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.velocity;
-
-import org.apache.camel.builder.RouteBuilder;
-
-public class VelocityLetterWithPaserTest extends VelocityLetterTest {
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- public void configure() throws Exception {
- from("direct:a").
- to("velocity:org/apache/camel/component/velocity/letterWithParser.vm?propertiesFile=org/apache/camel/component/velocity/velocity.properties").to("mock:result");
- }
- };
- }
-
-}
[2/6] camel git commit: Allow to turn on dumping route coverage
globally via JVM system property.
Posted by da...@apache.org.
Allow to turn on dumping route coverage globally via JVM system property.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f5851a37
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f5851a37
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f5851a37
Branch: refs/heads/master
Commit: f5851a37693a93a2936702e47354d1f65c8ab501
Parents: a750723
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Oct 13 10:24:40 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Oct 14 14:09:42 2017 +0200
----------------------------------------------------------------------
.../test/spring/CamelAnnotationsHandler.java | 3 ++-
.../spring/CamelSpringTestContextLoader.java | 3 ++-
.../camel/test/spring/EnableRouteCoverage.java | 2 ++
.../camel/test/junit4/CamelTestSupport.java | 19 +++++++++++++++----
4 files changed, 21 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f5851a37/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelAnnotationsHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelAnnotationsHandler.java b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelAnnotationsHandler.java
index 071891f..70f768a 100644
--- a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelAnnotationsHandler.java
+++ b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelAnnotationsHandler.java
@@ -33,6 +33,7 @@ import org.apache.camel.spi.Breakpoint;
import org.apache.camel.spi.Debugger;
import org.apache.camel.spi.EventNotifier;
import org.apache.camel.spring.SpringCamelContext;
+import org.apache.camel.test.junit4.CamelTestSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ConfigurableApplicationContext;
@@ -79,7 +80,7 @@ public final class CamelAnnotationsHandler {
*/
public static void handleRouteCoverage(ConfigurableApplicationContext context, Class<?> testClass, Function testMethod) throws Exception {
if (testClass.isAnnotationPresent(EnableRouteCoverage.class)) {
- System.setProperty("CamelTestRouteCoverage", "true");
+ System.setProperty(CamelTestSupport.ROUTE_COVERAGE_ENABLED, "true");
CamelSpringTestHelper.doToSpringCamelContexts(context, new CamelSpringTestHelper.DoToSpringCamelContextsStrategy() {
http://git-wip-us.apache.org/repos/asf/camel/blob/f5851a37/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
----------------------------------------------------------------------
diff --git a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
index 434f188..049bc7c 100644
--- a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
+++ b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestContextLoader.java
@@ -35,6 +35,7 @@ import org.apache.camel.spi.Debugger;
import org.apache.camel.spi.EventNotifier;
import org.apache.camel.spring.SpringCamelContext;
import org.apache.camel.test.ExcludingPackageScanClassResolver;
+import org.apache.camel.test.junit4.CamelTestSupport;
import org.apache.camel.test.spring.CamelSpringTestHelper.DoToSpringCamelContextsStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -283,7 +284,7 @@ public class CamelSpringTestContextLoader extends AbstractContextLoader {
*/
private void handleRouteCoverage(GenericApplicationContext context, Class<?> testClass) throws Exception {
if (testClass.isAnnotationPresent(EnableRouteCoverage.class)) {
- System.setProperty("CamelTestRouteCoverage", "true");
+ System.setProperty(CamelTestSupport.ROUTE_COVERAGE_ENABLED, "true");
CamelSpringTestHelper.doToSpringCamelContexts(context, new DoToSpringCamelContextsStrategy() {
http://git-wip-us.apache.org/repos/asf/camel/blob/f5851a37/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/EnableRouteCoverage.java
----------------------------------------------------------------------
diff --git a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/EnableRouteCoverage.java b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/EnableRouteCoverage.java
index 13c8514..44523da 100644
--- a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/EnableRouteCoverage.java
+++ b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/EnableRouteCoverage.java
@@ -29,6 +29,8 @@ import java.lang.annotation.Target;
* <p/>
* This allows tooling or manual inspection of the stats, so you can generate a route trace diagram of which EIPs
* have been in use and which have not. Similar concepts as a code coverage report.
+ * <p/>
+ * You can also turn on route coverage globally via setting JVM system property <tt>CamelTestRouteCoverage=true</tt>.
*/
@Documented
@Inherited
http://git-wip-us.apache.org/repos/asf/camel/blob/f5851a37/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java b/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
index 2206822..9157d55 100644
--- a/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
+++ b/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
@@ -91,6 +91,12 @@ import org.slf4j.LoggerFactory;
* @version
*/
public abstract class CamelTestSupport extends TestSupport {
+
+ /**
+ * JVM system property which can be set to true to turn on dumping route coverage statistics.
+ */
+ public static final String ROUTE_COVERAGE_ENABLED = "CamelTestRouteCoverage";
+
private static final Logger LOG = LoggerFactory.getLogger(CamelTestSupport.class);
private static final ThreadLocal<Boolean> INIT = new ThreadLocal<Boolean>();
private static ThreadLocal<ModelCamelContext> threadCamelContext = new ThreadLocal<ModelCamelContext>();
@@ -128,6 +134,8 @@ public abstract class CamelTestSupport extends TestSupport {
* <p/>
* This allows tooling or manual inspection of the stats, so you can generate a route trace diagram of which EIPs
* have been in use and which have not. Similar concepts as a code coverage report.
+ * <p/>
+ * You can also turn on route coverage globally via setting JVM system property <tt>CamelTestRouteCoverage=true</tt>.
*
* @return <tt>true</tt> to write route coverage status in an xml file in the <tt>target/camel-route-coverage</tt> directory after the test has finished.
*/
@@ -284,7 +292,7 @@ public abstract class CamelTestSupport extends TestSupport {
private void doSetUp() throws Exception {
log.debug("setUp test");
// jmx is enabled if we have configured to use it, or if dump route coverage is enabled (it requires JMX)
- boolean jmx = useJmx() || isDumpRouteCoverage();
+ boolean jmx = useJmx() || isRouteCoverageEnabled();
if (jmx) {
enableJMX();
} else {
@@ -382,6 +390,10 @@ public abstract class CamelTestSupport extends TestSupport {
}
}
+ private boolean isRouteCoverageEnabled() {
+ return System.getProperty(ROUTE_COVERAGE_ENABLED, "false").equalsIgnoreCase("true") || isDumpRouteCoverage();
+ }
+
@After
public void tearDown() throws Exception {
long time = watch.stop();
@@ -391,8 +403,7 @@ public abstract class CamelTestSupport extends TestSupport {
log.info("Took: " + TimeUtils.printDuration(time) + " (" + time + " millis)");
// if we should dump route stats, then write that to a file
- boolean coverage = System.getProperty("CamelTestRouteCoverage", "false").equalsIgnoreCase("true") || isDumpRouteCoverage();
- if (coverage) {
+ if (isRouteCoverageEnabled()) {
String className = this.getClass().getSimpleName();
String dir = "target/camel-route-coverage";
String name = className + "-" + getTestMethodName() + ".xml";
@@ -411,7 +422,7 @@ public abstract class CamelTestSupport extends TestSupport {
file.mkdirs();
file = new File(dir, name);
- log.info("Dumping route coverage to file: " + file);
+ log.info("Dumping route coverage to file: {}", file);
InputStream is = new ByteArrayInputStream(combined.getBytes());
OutputStream os = new FileOutputStream(file, false);
IOHelper.copyAndCloseInput(is, os);
[3/6] camel git commit: Camel route coverage maven plugin to support
anonymous routes.
Posted by da...@apache.org.
Camel route coverage maven plugin to support anonymous routes.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4393783e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4393783e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4393783e
Branch: refs/heads/master
Commit: 4393783e59a00d3a64b95cd7a42db0487ef6595f
Parents: 9bd1e29
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Oct 14 13:47:20 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Oct 14 14:09:42 2017 +0200
----------------------------------------------------------------------
.../velocity/VelocityContentCacheTest.java | 3 +-
.../VelocitySomeValuesNotInExchangeTest.java | 4 +-
.../parser/helper/RouteCoverageHelper.java | 53 +++++++-
.../apache/camel/maven/RouteCoverageMojo.java | 129 +++++++++++++++++--
.../camel/maven/model/RouteCoverageNode.java | 42 ++++++
5 files changed, 219 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4393783e/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityContentCacheTest.java
----------------------------------------------------------------------
diff --git a/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityContentCacheTest.java b/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityContentCacheTest.java
index 060571a..5fb55ce 100644
--- a/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityContentCacheTest.java
+++ b/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityContentCacheTest.java
@@ -59,9 +59,10 @@ public class VelocityContentCacheTest extends CamelTestSupport {
template.sendBodyAndHeader("file://target/test-classes/org/apache/camel/component/velocity?fileExist=Override", "Bye $headers.name", Exchange.FILE_NAME, "hello.vm");
mock.reset();
- mock.expectedBodiesReceived("Bye Paris");
+ mock.expectedBodiesReceived("Bye Paris", "Bye World");
template.sendBodyAndHeader("direct:a", "Body", "name", "Paris");
+ template.sendBodyAndHeader("direct:a", "Body", "name", "World");
mock.assertIsSatisfied();
}
http://git-wip-us.apache.org/repos/asf/camel/blob/4393783e/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocitySomeValuesNotInExchangeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocitySomeValuesNotInExchangeTest.java b/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocitySomeValuesNotInExchangeTest.java
index 7ff09bd..3ba0819 100644
--- a/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocitySomeValuesNotInExchangeTest.java
+++ b/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocitySomeValuesNotInExchangeTest.java
@@ -61,7 +61,9 @@ public class VelocitySomeValuesNotInExchangeTest extends CamelTestSupport {
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
- from("direct:a").to("velocity:org/apache/camel/component/velocity/someValuesNotInExchange.vm").to("mock:result");
+ from("direct:a")
+ .to("velocity:org/apache/camel/component/velocity/someValuesNotInExchange.vm")
+ .to("mock:result");
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/4393783e/tooling/camel-route-parser/src/main/java/org/apache/camel/parser/helper/RouteCoverageHelper.java
----------------------------------------------------------------------
diff --git a/tooling/camel-route-parser/src/main/java/org/apache/camel/parser/helper/RouteCoverageHelper.java b/tooling/camel-route-parser/src/main/java/org/apache/camel/parser/helper/RouteCoverageHelper.java
index 2bc4bf8..45c61ed 100644
--- a/tooling/camel-route-parser/src/main/java/org/apache/camel/parser/helper/RouteCoverageHelper.java
+++ b/tooling/camel-route-parser/src/main/java/org/apache/camel/parser/helper/RouteCoverageHelper.java
@@ -19,7 +19,9 @@ package org.apache.camel.parser.helper;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.w3c.dom.Document;
@@ -39,9 +41,19 @@ public final class RouteCoverageHelper {
private RouteCoverageHelper() {
}
+ /**
+ * Parses the dumped route coverage data and creates a line by line coverage data
+ *
+ * @param directory the directory with the dumped route coverage data
+ * @param routeId the route id to gather, must not be null.
+ * @return line by line coverage data
+ */
public static List<CoverageData> parseDumpRouteCoverageByRouteId(String directory, String routeId) throws Exception {
List<CoverageData> answer = new ArrayList<>();
+ if (routeId == null) {
+ return answer;
+ }
File[] files = new File(directory).listFiles(f -> f.getName().endsWith(".xml"));
if (files == null) {
return answer;
@@ -58,8 +70,7 @@ public final class RouteCoverageHelper {
String id = route.getAttributes().getNamedItem("id").getNodeValue();
// must be the target route
if (routeId.equals(id)) {
- // parse each route and build a Map<String, Integer> with the no of messages processed
- // where String is the EIP name
+ // parse each route and build a List<CoverageData> for line by line coverage data
AtomicInteger counter = new AtomicInteger();
parseRouteData(catalog, route, answer, counter);
}
@@ -70,6 +81,44 @@ public final class RouteCoverageHelper {
return answer;
}
+ public static Map<String, List<CoverageData>> parseDumpRouteCoverageByClassAndTestMethod(String directory) throws Exception {
+ Map<String, List<CoverageData>> answer = new LinkedHashMap();
+
+ File[] files = new File(directory).listFiles(f -> f.getName().endsWith(".xml"));
+ if (files == null) {
+ return answer;
+ }
+
+ CamelCatalog catalog = new DefaultCamelCatalog(true);
+
+ for (File file : files) {
+ try (FileInputStream fis = new FileInputStream(file)) {
+ Document dom = XmlLineNumberParser.parseXml(fis);
+ NodeList routes = dom.getElementsByTagName("route");
+ for (int i = 0; i < routes.getLength(); i++) {
+ Node route = routes.item(i);
+ // parse each route and build a List<CoverageData> for line by line coverage data
+ AtomicInteger counter = new AtomicInteger();
+ List<CoverageData> data = new ArrayList<>();
+ parseRouteData(catalog, route, data, counter);
+ // create a key which is based on the file name without extension
+ String key = file.getName();
+ // strip .xml extension
+ key = key.substring(0, key.length() - 4);
+ // is there existing data
+ List<CoverageData> existing = answer.get(key);
+ if (existing != null) {
+ existing.addAll(data);
+ } else {
+ answer.put(key, data);
+ }
+ }
+ }
+ }
+
+ return answer;
+ }
+
private static void parseRouteData(CamelCatalog catalog, Node node, List<CoverageData> data, AtomicInteger counter) {
// must be a known EIP model
String key = node.getNodeName();
http://git-wip-us.apache.org/repos/asf/camel/blob/4393783e/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RouteCoverageMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RouteCoverageMojo.java b/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RouteCoverageMojo.java
index 6f89638..8168ea7 100644
--- a/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RouteCoverageMojo.java
+++ b/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RouteCoverageMojo.java
@@ -23,12 +23,16 @@ import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
+import edu.emory.mathcs.backport.java.util.Collections;
import org.apache.camel.maven.helper.EndpointHelper;
import org.apache.camel.maven.model.RouteCoverageNode;
import org.apache.camel.parser.RouteBuilderParser;
@@ -36,6 +40,7 @@ import org.apache.camel.parser.XmlRouteParser;
import org.apache.camel.parser.helper.RouteCoverageHelper;
import org.apache.camel.parser.model.CamelNodeDetails;
import org.apache.camel.parser.model.CoverageData;
+import org.apache.camel.util.FileUtil;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -94,6 +99,17 @@ public class RouteCoverageMojo extends AbstractExecMojo {
*/
private String excludes;
+ /**
+ * Whether to allow anonymous routes (routes without any route id assigned).
+ * By using route id's then its safer to match the route cover data with the route source code.
+ * Anonymous routes are less safe to use for route coverage as its harder to know
+ * exactly which route that was tested corresponds to which of the routes from the source code.
+ *
+ * @parameter property="camel.anonymousRoutes"
+ * default-value="false"
+ */
+ private boolean anonymousRoutes = false;
+
// CHECKSTYLE:OFF
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
@@ -168,14 +184,17 @@ public class RouteCoverageMojo extends AbstractExecMojo {
// skip any routes which has no route id assigned
long anonymous = routeTrees.stream().filter(t -> t.getRouteId() == null).count();
- if (anonymous > 0) {
+ if (!anonymousRoutes && anonymous > 0) {
getLog().warn("Discovered " + anonymous + " anonymous routes. Add route ids to these routes for route coverage support");
}
final AtomicInteger notCovered = new AtomicInteger();
- routeTrees = routeTrees.stream().filter(t -> t.getRouteId() != null).collect(Collectors.toList());
- for (CamelNodeDetails t : routeTrees) {
+ List<CamelNodeDetails> routeIdTrees = routeTrees.stream().filter(t -> t.getRouteId() != null).collect(Collectors.toList());
+ List<CamelNodeDetails> anonymousRouteTrees = routeTrees.stream().filter(t -> t.getRouteId() == null).collect(Collectors.toList());
+
+ // favor strict matching on route ids
+ for (CamelNodeDetails t : routeIdTrees) {
String routeId = t.getRouteId();
String fileName = asRelativeFile(t.getFileName());
@@ -186,7 +205,7 @@ public class RouteCoverageMojo extends AbstractExecMojo {
getLog().warn("No route coverage data found for route: " + routeId
+ ". Make sure to enable route coverage in your unit tests and assign unique route ids to your routes. Also remember to run unit tests first.");
} else {
- List<RouteCoverageNode> coverage = gatherRouteCoverageSummary(t, coverageData);
+ List<RouteCoverageNode> coverage = gatherRouteCoverageSummary(Collections.singletonList(t), coverageData);
String out = templateCoverageData(fileName, routeId, coverage, notCovered);
getLog().info("Route coverage summary:\n\n" + out);
getLog().info("");
@@ -197,10 +216,100 @@ public class RouteCoverageMojo extends AbstractExecMojo {
}
}
+ if (anonymousRoutes && !anonymousRouteTrees.isEmpty()) {
+ // grab dump data for the route
+ try {
+ Map<String, List<CoverageData>> datas = RouteCoverageHelper.parseDumpRouteCoverageByClassAndTestMethod("target/camel-route-coverage");
+ if (datas.isEmpty()) {
+ getLog().warn("No route coverage data found"
+ + ". Make sure to enable route coverage in your unit tests. Also remember to run unit tests first.");
+ } else {
+ Map<String, List<CamelNodeDetails>> routes = groupAnonymousRoutesByClassName(anonymousRouteTrees);
+ // attempt to match anonymous routes via the unit test class
+ for (Map.Entry<String, List<CamelNodeDetails>> t : routes.entrySet()) {
+ List<RouteCoverageNode> coverage = new ArrayList<>();
+ String className = t.getKey();
+
+ // we may have multiple tests in the same test class that tests different parts of the same
+ // routes so merge their coverage reports into a single coverage
+ for (Map.Entry<String, List<CoverageData>> entry : datas.entrySet()) {
+ String key = entry.getKey();
+ String dataClassName = key.substring(0, key.indexOf('-'));
+ if (dataClassName.equals(className)) {
+ List<RouteCoverageNode> result = gatherRouteCoverageSummary(t.getValue(), entry.getValue());
+ // merge them together
+ mergeCoverageData(coverage, result);
+ }
+ }
+
+ if (!coverage.isEmpty()) {
+ String out = templateCoverageData(className, null, coverage, notCovered);
+ getLog().info("Route coverage summary:\n\n" + out);
+ getLog().info("");
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw new MojoExecutionException("Error during gathering route coverage data", e);
+ }
+ }
+
if (failOnError && notCovered.get() > 0) {
throw new MojoExecutionException("There are " + notCovered.get() + " route(s) not fully covered!");
}
}
+
+ private Map<String, List<CamelNodeDetails>> groupAnonymousRoutesByClassName(List<CamelNodeDetails> anonymousRouteTrees) {
+ Map<String, List<CamelNodeDetails>> answer = new LinkedHashMap<>();
+
+ for (CamelNodeDetails t : anonymousRouteTrees) {
+ String fileName = asRelativeFile(t.getFileName());
+ String className = FileUtil.stripExt(FileUtil.stripPath(fileName));
+ List<CamelNodeDetails> list = answer.computeIfAbsent(className, k -> new ArrayList<>());
+ list.add(t);
+ }
+
+ return answer;
+ }
+
+ private void mergeCoverageData(List<RouteCoverageNode> coverage, List<RouteCoverageNode> result) {
+ List<RouteCoverageNode> toBeAdded = new ArrayList<>();
+
+ ListIterator<RouteCoverageNode> it = null;
+ for (RouteCoverageNode node : result) {
+ // do we have an existing
+ it = positionToLineNumber(it, coverage, node.getLineNumber());
+ RouteCoverageNode existing = it.hasNext() ? it.next() : null;
+ if (existing != null) {
+ int count = existing.getCount() + node.getCount();
+ existing.setCount(count);
+ } else {
+ // its a new node
+ toBeAdded.add(node);
+ }
+ }
+
+ if (!toBeAdded.isEmpty()) {
+ coverage.addAll(toBeAdded);
+ }
+ }
+
+ private ListIterator<RouteCoverageNode> positionToLineNumber(ListIterator<RouteCoverageNode> it, List<RouteCoverageNode> coverage, int lineNumber) {
+ // restart
+ if (it == null || !it.hasNext()) {
+ it = coverage.listIterator();
+ }
+ while (it.hasNext()) {
+ RouteCoverageNode node = it.next();
+ if (node.getLineNumber() == lineNumber) {
+ // go back
+ it.previous();
+ return it;
+ }
+ }
+ return it;
+ }
+
// CHECKSTYLE:ON
@SuppressWarnings("unchecked")
@@ -213,7 +322,9 @@ public class RouteCoverageMojo extends AbstractExecMojo {
} else {
sw.println("File:\t" + fileName);
}
- sw.println("RouteId:\t" + routeId);
+ if (routeId != null) {
+ sw.println("RouteId:\t" + routeId);
+ }
sw.println();
sw.println(String.format("%8s %8s %s", "Line #", "Count", "Route"));
sw.println(String.format("%8s %8s %s", "------", "-----", "-----"));
@@ -241,12 +352,14 @@ public class RouteCoverageMojo extends AbstractExecMojo {
return bos.toString();
}
- private static List<RouteCoverageNode> gatherRouteCoverageSummary(CamelNodeDetails route, List<CoverageData> coverageData) {
+ private static List<RouteCoverageNode> gatherRouteCoverageSummary(List<CamelNodeDetails> route, List<CoverageData> coverageData) {
List<RouteCoverageNode> answer = new ArrayList<>();
Iterator<CoverageData> it = coverageData.iterator();
- AtomicInteger level = new AtomicInteger();
- gatherRouteCoverageSummary(route, it, level, answer);
+ for (CamelNodeDetails r : route) {
+ AtomicInteger level = new AtomicInteger();
+ gatherRouteCoverageSummary(r, it, level, answer);
+ }
return answer;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/4393783e/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/model/RouteCoverageNode.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/model/RouteCoverageNode.java b/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/model/RouteCoverageNode.java
index cb6aba6..9656c56 100644
--- a/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/model/RouteCoverageNode.java
+++ b/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/model/RouteCoverageNode.java
@@ -74,4 +74,46 @@ public final class RouteCoverageNode {
this.level = level;
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ RouteCoverageNode that = (RouteCoverageNode) o;
+
+ if (lineNumber != that.lineNumber) {
+ return false;
+ }
+ if (level != that.level) {
+ return false;
+ }
+ if (!className.equals(that.className)) {
+ return false;
+ }
+ return name.equals(that.name);
+ }
+
+ @Override
+ public int hashCode() {
+ int result = className.hashCode();
+ result = 31 * result + name.hashCode();
+ result = 31 * result + lineNumber;
+ result = 31 * result + level;
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "RouteCoverageNode["
+ + "lineNumber=" + lineNumber
+ + ", count=" + count
+ + ", name='" + name + '\''
+ + ", level=" + level
+ + ", className='" + className + '\''
+ + ']';
+ }
}
[5/6] camel git commit: Polished
Posted by da...@apache.org.
Polished
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/189e5cf7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/189e5cf7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/189e5cf7
Branch: refs/heads/master
Commit: 189e5cf7296e8c550401e62dbede8510ba2fe53a
Parents: 77f4a7e
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Oct 14 14:09:29 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Oct 14 14:09:43 2017 +0200
----------------------------------------------------------------------
.../src/main/java/org/apache/camel/maven/RouteCoverageMojo.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/189e5cf7/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RouteCoverageMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RouteCoverageMojo.java b/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RouteCoverageMojo.java
index 8168ea7..4864bba 100644
--- a/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RouteCoverageMojo.java
+++ b/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RouteCoverageMojo.java
@@ -323,7 +323,7 @@ public class RouteCoverageMojo extends AbstractExecMojo {
sw.println("File:\t" + fileName);
}
if (routeId != null) {
- sw.println("RouteId:\t" + routeId);
+ sw.println("Route:\t" + routeId);
}
sw.println();
sw.println(String.format("%8s %8s %s", "Line #", "Count", "Route"));
[6/6] camel git commit: CAMEL-11909: camel-catalog-maven - Cannot
load out of the box components
Posted by da...@apache.org.
CAMEL-11909: camel-catalog-maven - Cannot load out of the box components
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ce6a9532
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ce6a9532
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ce6a9532
Branch: refs/heads/master
Commit: ce6a9532afac57ad5e6823beb3a6311394be6e3f
Parents: 189e5cf
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Oct 14 14:24:08 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Oct 14 14:24:08 2017 +0200
----------------------------------------------------------------------
.../java/org/apache/camel/catalog/maven/MavenVersionManager.java | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ce6a9532/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/MavenVersionManager.java
----------------------------------------------------------------------
diff --git a/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/MavenVersionManager.java b/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/MavenVersionManager.java
index 39fe059..ed27a4f 100644
--- a/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/MavenVersionManager.java
+++ b/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/MavenVersionManager.java
@@ -158,6 +158,9 @@ public class MavenVersionManager implements VersionManager {
if (is == null && version != null) {
is = doGetResourceAsStream(name, version);
}
+ if (is == null) {
+ is = MavenVersionManager.class.getClassLoader().getResourceAsStream(name);
+ }
return is;
}