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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karaf.git


The following commit(s) were added to refs/heads/main by this push:
     new 18da10b  CAMEL-16995 - Support filter expression for contexts in 
CamelBlueprintTestSupport (#86)
18da10b is described below

commit 18da10b3285c937298adad79d8072110b7482ef9
Author: Gert Vanthienen <[email protected]>
AuthorDate: Thu Sep 23 10:07:38 2021 +0200

    CAMEL-16995 - Support filter expression for contexts in 
CamelBlueprintTestSupport (#86)
---
 .../test/blueprint/CamelBlueprintTestSupport.java  | 14 ++++++-
 .../test/blueprint/MultipleCamelContextsTest.java  | 48 +++++++++++++++++++++
 .../camel/test/blueprint/multipeCamelContexts.xml  | 49 ++++++++++++++++++++++
 3 files changed, 109 insertions(+), 2 deletions(-)

diff --git 
a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
 
b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
index 213774d..afee488 100644
--- 
a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
+++ 
b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
@@ -532,15 +532,25 @@ public abstract class CamelBlueprintTestSupport extends 
CamelTestSupport {
                     + " has wrong format.", e);
         }
     }
+
+    /**
+     * Gets filter expression for the Camel context you want to test.
+     * Modify this if you have multiple contexts in the OSGi registry and want 
to test a specific one.
+     *
+     * @return filter expression for Camel context.
+     */
+    protected String getCamelContextFilter() {
+        return null;
+    }
     
     @Override
     protected CamelContext createCamelContext() throws Exception {
         CamelContext answer;
         Long timeout = getCamelContextCreationTimeout();
         if (timeout == null) {
-            answer = CamelBlueprintHelper.getOsgiService(bundleContext, 
CamelContext.class);
+            answer = CamelBlueprintHelper.getOsgiService(bundleContext, 
CamelContext.class, getCamelContextFilter());
         } else if (timeout >= 0) {
-            answer = CamelBlueprintHelper.getOsgiService(bundleContext, 
CamelContext.class, timeout);
+            answer = CamelBlueprintHelper.getOsgiService(bundleContext, 
CamelContext.class, getCamelContextFilter(), timeout);
         } else {
             throw new IllegalArgumentException("getCamelContextCreationTimeout 
cannot return a negative value.");
         }
diff --git 
a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/MultipleCamelContextsTest.java
 
b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/MultipleCamelContextsTest.java
new file mode 100644
index 0000000..cf3c568
--- /dev/null
+++ 
b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/MultipleCamelContextsTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.blueprint;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+public class MultipleCamelContextsTest extends CamelBlueprintTestSupport {
+
+    @Override
+    protected String getBlueprintDescriptor() {
+        return "org/apache/camel/test/blueprint/multipeCamelContexts.xml";
+    }
+
+    @Override
+    protected String getCamelContextFilter() {
+        return "(camel.context.name=secondCamelContext)";
+    }
+
+    @Test
+    public void testSecondCamelContext() throws Exception {
+        MockEndpoint result = getMockEndpoint("mock:result");
+        result.expectedMessageCount(1);
+
+        template.sendBody("direct:second", "World");
+
+        assertMockEndpointsSatisfied();
+
+        for (Exchange exchange : result.getExchanges()) {
+            assertStringContains(exchange.getIn().getBody(String.class), "from 
second context");
+        }
+    }
+}
diff --git 
a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/multipeCamelContexts.xml
 
b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/multipeCamelContexts.xml
new file mode 100644
index 0000000..ec9e626
--- /dev/null
+++ 
b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/multipeCamelContexts.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0";
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+           xsi:schemaLocation="
+             http://www.osgi.org/xmlns/blueprint/v1.0.0 
https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd";>
+
+  <camelContext id="firstCamelContext" 
xmlns="http://camel.apache.org/schema/blueprint";>
+
+    <route>
+      <from uri="direct:first"/>
+      <transform>
+        <simple>Hello ${body} from first context</simple>
+      </transform>
+      <to uri="mock:result"/>
+    </route>
+
+  </camelContext>
+
+  <camelContext id="secondCamelContext" 
xmlns="http://camel.apache.org/schema/blueprint";>
+
+    <route>
+      <from uri="direct:second"/>
+      <transform>
+        <simple>Hello ${body} from second context</simple>
+      </transform>
+      <to uri="mock:result"/>
+    </route>
+
+  </camelContext>
+
+</blueprint>

Reply via email to