camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/2] camel git commit: CAMEL-9142: added back support for multiple blueprint descriptors in camel-test-blueprint
Date Wed, 16 Sep 2015 14:22:29 GMT
CAMEL-9142: added back support for multiple blueprint descriptors in camel-test-blueprint


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

Branch: refs/heads/camel-2.15.x
Commit: 1dff922da9b8d84b8e31fa67eded1acdf44b86c1
Parents: bd792cc
Author: Scott Cranton <scott@cranton.com>
Authored: Wed Sep 16 08:39:07 2015 -0400
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Sep 16 16:21:49 2015 +0200

----------------------------------------------------------------------
 .../test/blueprint/CamelBlueprintHelper.java    |  2 +-
 .../blueprint/CamelBlueprintTestSupport.java    | 34 ++++++-----
 ...SimpleTransformAnnotationsBlueprintTest.java | 62 ++++++++++++++++++++
 .../blueprint/SimpleTransformBlueprintTest.java | 55 +++++++++++++++++
 .../test/blueprint/simpleTransform-context.xml  | 38 ++++++++++++
 .../simpleTransform-properties-context.xml      | 37 ++++++++++++
 6 files changed, 212 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1dff922d/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java
b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java
index 6862d86..7acc18b 100644
--- a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java
+++ b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java
@@ -352,7 +352,7 @@ public final class CamelBlueprintHelper {
      * @return the bundle descriptors.
      * @throws FileNotFoundException is thrown if a bundle descriptor cannot be found
      */
-    private static Collection<URL> getBlueprintDescriptors(String descriptors) throws
FileNotFoundException, MalformedURLException {
+    protected static Collection<URL> getBlueprintDescriptors(String descriptors) throws
FileNotFoundException, MalformedURLException {
         List<URL> answer = new ArrayList<URL>();
         String descriptor = descriptors;
         if (descriptor != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/1dff922d/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
----------------------------------------------------------------------
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 0361ce8..5f9e5fc 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
@@ -18,6 +18,8 @@ package org.apache.camel.test.blueprint;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
 import java.util.Arrays;
 import java.util.Dictionary;
 import java.util.HashSet;
@@ -60,13 +62,12 @@ public abstract class CamelBlueprintTestSupport extends CamelTestSupport
{
     private static ThreadLocal<BundleContext> threadLocalBundleContext = new ThreadLocal<BundleContext>();
     private volatile BundleContext bundleContext;
     private final Set<ServiceRegistration<?>> services = new LinkedHashSet<ServiceRegistration<?>>();
-    
+
     /**
      * Override this method if you don't want CamelBlueprintTestSupport create the test bundle
      * @return includeTestBundle
      * If the return value is true CamelBlueprintTestSupport creates the test bundle which
includes blueprint configuration files
      * If the return value is false CamelBlueprintTestSupport won't create the test bundle
-     * 
      */
     protected boolean includeTestBundle() {
         return true;
@@ -226,7 +227,6 @@ public abstract class CamelBlueprintTestSupport extends CamelTestSupport
{
      */
     protected boolean expectBlueprintContainerReloadOnConfigAdminUpdate() {
         boolean expectedReload = false;
-        String descriptor = getBlueprintDescriptor();
         DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
         dbf.setNamespaceAware(true);
         try {
@@ -236,18 +236,22 @@ public abstract class CamelBlueprintTestSupport extends CamelTestSupport
{
                     CmNamespaceHandler.BLUEPRINT_CM_NAMESPACE_1_2,
                     CmNamespaceHandler.BLUEPRINT_CM_NAMESPACE_1_3
             ));
-            DocumentBuilder db = dbf.newDocumentBuilder();
-            Document doc = db.parse(getClass().getClassLoader().getResourceAsStream(descriptor));
-            NodeList nl = doc.getDocumentElement().getChildNodes();
-            for (int i = 0; i < nl.getLength(); i++) {
-                Node node = nl.item(i);
-                if (node instanceof Element) {
-                    Element pp = (Element) node;
-                    if (cmNamesaces.contains(pp.getNamespaceURI())) {
-                        String us = pp.getAttribute("update-strategy");
-                        if (us != null && us.equals("reload")) {
-                            expectedReload = true;
-                            break;
+            for (URL descriptor : CamelBlueprintHelper.getBlueprintDescriptors(getBlueprintDescriptor()))
{
+                DocumentBuilder db = dbf.newDocumentBuilder();
+                try (InputStream is = descriptor.openStream()) {
+                    Document doc = db.parse(is);
+                    NodeList nl = doc.getDocumentElement().getChildNodes();
+                    for (int i = 0; i < nl.getLength(); i++) {
+                        Node node = nl.item(i);
+                        if (node instanceof Element) {
+                            Element pp = (Element) node;
+                            if (cmNamesaces.contains(pp.getNamespaceURI())) {
+                                String us = pp.getAttribute("update-strategy");
+                                if (us != null && us.equals("reload")) {
+                                    expectedReload = true;
+                                    break;
+                                }
+                            }
                         }
                     }
                 }

http://git-wip-us.apache.org/repos/asf/camel/blob/1dff922d/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/SimpleTransformAnnotationsBlueprintTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/SimpleTransformAnnotationsBlueprintTest.java
b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/SimpleTransformAnnotationsBlueprintTest.java
new file mode 100644
index 0000000..b03e558
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/SimpleTransformAnnotationsBlueprintTest.java
@@ -0,0 +1,62 @@
+/**
+ * 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.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+/**
+ * Test class that demonstrates the fundamental interactions going on to verify that a route
behaves as it should.
+ */
+public class SimpleTransformAnnotationsBlueprintTest extends CamelBlueprintTestSupport {
+
+    @Produce(uri = "direct:in")
+    private ProducerTemplate producerTemplate;
+
+    @EndpointInject(uri = "mock:out")
+    private MockEndpoint mockOut;
+
+    @Override
+    protected String getBlueprintDescriptor() {
+        return "org/apache/camel/test/blueprint/simpleTransform-context.xml,"
+             + "org/apache/camel/test/blueprint/simpleTransform-properties-context.xml";
+    }
+
+    @Test
+    public void testPayloadIsTransformed() throws InterruptedException {
+        mockOut.setExpectedMessageCount(1);
+        mockOut.message(0).body().isEqualTo("Modified: Cheese");
+
+        producerTemplate.sendBody("Cheese");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testPayloadIsTransformedAgain() throws InterruptedException {
+        mockOut.setExpectedMessageCount(1);
+        mockOut.message(0).body().isEqualTo("Modified: Foo");
+
+        producerTemplate.sendBody("Foo");
+
+        assertMockEndpointsSatisfied();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/1dff922d/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/SimpleTransformBlueprintTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/SimpleTransformBlueprintTest.java
b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/SimpleTransformBlueprintTest.java
new file mode 100644
index 0000000..e65aae0
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/SimpleTransformBlueprintTest.java
@@ -0,0 +1,55 @@
+/**
+ * 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.component.mock.MockEndpoint;
+import org.junit.Test;
+
+/**
+ * Test class that demonstrates the fundamental interactions going on to verify that a route
behaves as it should.
+ */
+public class SimpleTransformBlueprintTest extends CamelBlueprintTestSupport {
+
+    @Override
+    protected String getBlueprintDescriptor() {
+        return "org/apache/camel/test/blueprint/simpleTransform-context.xml,"
+             + "org/apache/camel/test/blueprint/simpleTransform-properties-context.xml";
+    }
+
+    @Test
+    public void testPayloadIsTransformed() throws InterruptedException {
+        MockEndpoint mockOut = getMockEndpoint("mock:out");
+        mockOut.setExpectedMessageCount(1);
+        mockOut.message(0).body().isEqualTo("Modified: Cheese");
+
+        template.sendBody("direct:in", "Cheese");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Test
+    public void testPayloadIsTransformedAgain() throws InterruptedException {
+        MockEndpoint mockOut = getMockEndpoint("mock:out");
+        mockOut.setExpectedMessageCount(1);
+        mockOut.message(0).body().isEqualTo("Modified: Foo");
+
+        template.sendBody("direct:in", "Foo");
+
+        assertMockEndpointsSatisfied();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/1dff922d/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/simpleTransform-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/simpleTransform-context.xml
b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/simpleTransform-context.xml
new file mode 100644
index 0000000..3d6cb1b
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/simpleTransform-context.xml
@@ -0,0 +1,38 @@
+<?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 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
+             http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
+           ">
+
+  <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+    <route>
+      <from uri="direct:in"/>
+      <transform>
+        <simple>{{transform.message}}: ${body}</simple>
+      </transform>
+      <to uri="mock:out"/>
+    </route>
+  </camelContext>
+
+</blueprint>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/1dff922d/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/simpleTransform-properties-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/simpleTransform-properties-context.xml
b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/simpleTransform-properties-context.xml
new file mode 100644
index 0000000..06029a3
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/simpleTransform-properties-context.xml
@@ -0,0 +1,37 @@
+<?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:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xsi:schemaLocation="
+             http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
+             http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd
+           ">
+
+  <cm:property-placeholder persistent-id="org.camelcookbook.testing">
+    <cm:default-properties>
+      <cm:property name="transform.message" value="Modified"/>
+    </cm:default-properties>
+  </cm:property-placeholder>
+
+</blueprint>
+
+


Mime
View raw message