camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From astefanu...@apache.org
Subject camel git commit: Camel CDI test canonical example
Date Thu, 10 Mar 2016 16:30:38 GMT
Repository: camel
Updated Branches:
  refs/heads/master a76ad7923 -> 18fc064d9


Camel CDI test canonical example


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/18fc064d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/18fc064d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/18fc064d

Branch: refs/heads/master
Commit: 18fc064d929f6cdf63aa72e2f9a9b5d577c9df29
Parents: a76ad79
Author: Antonin Stefanutti <antonin@stefanutti.fr>
Authored: Thu Mar 10 17:30:02 2016 +0100
Committer: Antonin Stefanutti <antonin@stefanutti.fr>
Committed: Thu Mar 10 17:30:29 2016 +0100

----------------------------------------------------------------------
 components/camel-test-cdi/pom.xml               | 13 ++++
 .../org/apache/camel/test/cdi/FilterTest.java   | 73 ++++++++++++++++++++
 .../src/test/resources/log4j.properties         | 36 ++++++++++
 docs/user-manual/en/testing.adoc                | 38 +++++++---
 4 files changed, 149 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/18fc064d/components/camel-test-cdi/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-cdi/pom.xml b/components/camel-test-cdi/pom.xml
index 315b163..e686498 100644
--- a/components/camel-test-cdi/pom.xml
+++ b/components/camel-test-cdi/pom.xml
@@ -36,6 +36,8 @@
 
   <dependencies>
 
+    <!-- compile dependencies -->
+
     <dependency>
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-test</artifactId>
@@ -52,6 +54,17 @@
 
     <!-- test dependencies -->
 
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <scope>test</scope>
+    </dependency>
+
   </dependencies>
 
 </project>

http://git-wip-us.apache.org/repos/asf/camel/blob/18fc064d/components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java
b/components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java
new file mode 100644
index 0000000..045fc54
--- /dev/null
+++ b/components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java
@@ -0,0 +1,73 @@
+/**
+ * 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.test.cdi;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+// START SNIPPET: example
+// tag::example[]
+@RunWith(CamelCdiRunner.class)
+public class FilterTest {
+
+    @EndpointInject(uri = "mock:result")
+    protected MockEndpoint resultEndpoint;
+
+    @Produce(uri = "direct:start")
+    protected ProducerTemplate template;
+
+    @Before
+    public void before() {
+        resultEndpoint.reset();
+    }
+
+    @Test
+    public void testSendMatchingMessage() throws Exception {
+        String expectedBody = "<matched/>";
+
+        resultEndpoint.expectedBodiesReceived(expectedBody);
+
+        template.sendBodyAndHeader(expectedBody, "foo", "bar");
+
+        resultEndpoint.assertIsSatisfied();
+    }
+
+    @Test
+    public void testSendNotMatchingMessage() throws Exception {
+        resultEndpoint.expectedMessageCount(0);
+
+        template.sendBodyAndHeader("<notMatched/>", "foo", "notMatchedHeaderValue");
+
+        resultEndpoint.assertIsSatisfied();
+    }
+
+    static class ContextConfig extends RouteBuilder {
+
+        @Override
+        public void configure() {
+            from("direct:start").filter(header("foo").isEqualTo("bar")).to("mock:result");
+        }
+    }
+}
+// end::example[]
+// END SNIPPET: example

http://git-wip-us.apache.org/repos/asf/camel/blob/18fc064d/components/camel-test-cdi/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-test-cdi/src/test/resources/log4j.properties b/components/camel-test-cdi/src/test/resources/log4j.properties
new file mode 100644
index 0000000..b9387cc
--- /dev/null
+++ b/components/camel-test-cdi/src/test/resources/log4j.properties
@@ -0,0 +1,36 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+
+#
+# The logging properties used for eclipse testing, We want to see debug output on the console.
+#
+log4j.rootLogger=INFO, file
+
+#log4j.logger.org.jboss.weld=DEBUG
+#log4j.logger.org.apache.camel=DEBUG
+#log4j.logger.org.apache.camel.cdi=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d %-5p %c{1} - %m %n
+log4j.appender.file.file=target/camel-test-cdi.log

http://git-wip-us.apache.org/repos/asf/camel/blob/18fc064d/docs/user-manual/en/testing.adoc
----------------------------------------------------------------------
diff --git a/docs/user-manual/en/testing.adoc b/docs/user-manual/en/testing.adoc
index 6f417d4..f1ca22c 100644
--- a/docs/user-manual/en/testing.adoc
+++ b/docs/user-manual/en/testing.adoc
@@ -38,11 +38,11 @@ The following mechanisms are supported
 |Name |Component |Description
 |link:camel-test.html[Camel Test] |camel-test |Is a standalone Java
 library letting you easily create Camel test cases using a single Java
-class for all your configuration and routing without using
+class for all your configuration and routing without using link:cdi.html[CDI],
 link:spring.html[Spring] or link:guice.html[Guice] for
 link:dependency-injection.html[Dependency Injection] which does not
-require an in-depth knowledge of Spring + Spring Test or Guice.
- Supports JUnit 3.x (deprecated) and JUnit 4.x based tests.
+require an in-depth knowledge of CDI, Spring + Spring Test or Guice.
+Supports JUnit 3.x (deprecated) and JUnit 4.x based tests.
 
 |link:camel-test-cdi.html[CDI Testing] |camel-test-cdi | Provides a JUnit 4
 runner that bootstraps a test environment using CDI so that you don't have
@@ -60,7 +60,7 @@ Test. The  plain JUnit 3.x/4.x based tests work very similar to the
 test support classes in `camel-test`. Also supports Spring Test based
 tests that use the declarative style of test configuration and injection
 common in Spring Test. The Spring Test based tests provide feature
-parity with the plain JUnit 3.x/4.x based testing approach.  Notice
+parity with the plain JUnit 3.x/4.x based testing approach. Notice
 `camel-test-spring` is a new component in *Camel 2.10* onwards. For
 older Camel release use `camel-test` which has built-in
 link:spring-testing.html[Spring Testing].
@@ -73,12 +73,13 @@ configurations
 dependency inject your test classes
 
 |Camel TestNG |camel-testng |Supports plain TestNG based tests with or
-without link:spring.html[Spring] or link:guice.html[Guice] for link:dependency-injection.html[Dependency
-Injection] which does not require an in-depth knowledge of Spring +
-Spring Test or Guice. Also from *Camel 2.10* onwards, this component
-supports Spring Test based tests that use the declarative style of test
-configuration and injection common in Spring Test and described in more
-detail under link:spring-testing.html[Spring Testing].
+without link:cdi.html[CDI], link:spring.html[Spring] or link:guice.html[Guice]
+for link:dependency-injection.html[Dependency Injection] which does not
+require an in-depth knowledge of CDI, Spring + Spring Test or Guice.
+Also from *Camel 2.10* onwards, this component supports Spring Test based tests
+that use the declarative style of test configuration and injection common
+in Spring Test and described in more detail under
+link:spring-testing.html[Spring Testing].
 |=======================================================================
 
 In all approaches the test classes look pretty much the same in that
@@ -98,9 +99,24 @@ include::../../../components/camel-test/src/test/java/org/apache/camel/test/patt
 ----
 
 Notice how it derives from the Camel helper class `CamelTestSupport` but
-has no Spring or Guice dependency injection configuration but instead
+has no CDI, Spring or Guice dependency injection configuration but instead
 overrides the `createRouteBuilder()` method.
 
+[[Testing-CdiTestExample]]
+CDI Test Example
+++++++++++++++++
+
+Here is the link:cdi-testing.html[CDI Testing]
+link:../../../components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java[example]:
+
+[source,java]
+----
+include::../../../components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java[tags=example]
+----
+
+You can find more testing patterns illustrated in the `camel-example-cdi-test` example
+and the test classes that come with it.
+
 [[Testing-SpringTestwithXMLConfigExample]]
 Spring Test with XML Config Example
 +++++++++++++++++++++++++++++++++++


Mime
View raw message