You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2021/03/12 07:35:25 UTC

[camel] 07/08: CAMEL-16334 - Having a middle folder for test (unit + testcontainers) components

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 5b27661db43a32473e6f66976b3a3a2dba839626
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Mar 12 07:34:36 2021 +0100

    CAMEL-16334 - Having a middle folder for test (unit + testcontainers) components
---
 .../java/org/apache/camel/test/cdi/FilterTest.java | 73 ++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/docs/components/modules/ROOT/examples/components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java b/docs/components/modules/ROOT/examples/components/camel-test-cdi/src/test/java/org/apache/camel/test/cdi/FilterTest.java
new file mode 100644
index 0000000..4171106
--- /dev/null
+++ b/docs/components/modules/ROOT/examples/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("mock:result")
+    protected MockEndpoint resultEndpoint;
+
+    @Produce("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