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 2014/06/27 18:29:20 UTC

[3/8] git commit: CAMEL-7354: camel-spark component.

CAMEL-7354: camel-spark component.


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

Branch: refs/heads/master
Commit: 4529963331433ee678c284351a16ee899e57fa83
Parents: 95a5871
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Jun 27 15:25:24 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Jun 27 15:25:24 2014 +0200

----------------------------------------------------------------------
 .../camel/component/spark/SparkComponent.java   | 17 ++++++++
 .../camel/component/spark/BaseSparkTest.java    | 46 ++++++++++++++++++++
 .../camel/component/spark/CamelSparkTest.java   |  9 ++--
 3 files changed, 67 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/45299633/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkComponent.java b/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkComponent.java
index b133735..db3b6b1 100644
--- a/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkComponent.java
+++ b/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkComponent.java
@@ -21,13 +21,24 @@ import java.util.Map;
 import org.apache.camel.Endpoint;
 import org.apache.camel.impl.UriEndpointComponent;
 import spark.Spark;
+import spark.SparkBase;
 
 public class SparkComponent extends UriEndpointComponent {
 
+    private int port = SparkBase.SPARK_DEFAULT_PORT;
+
     public SparkComponent() {
         super(SparkEndpoint.class);
     }
 
+    public int getPort() {
+        return port;
+    }
+
+    public void setPort(int port) {
+        this.port = port;
+    }
+
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
         SparkEndpoint answer = new SparkEndpoint(uri, this);
@@ -45,6 +56,12 @@ public class SparkComponent extends UriEndpointComponent {
     }
 
     @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+        Spark.setPort(getPort());
+    }
+
+    @Override
     protected void doShutdown() throws Exception {
         super.doShutdown();
         Spark.stop();

http://git-wip-us.apache.org/repos/asf/camel/blob/45299633/components/camel-spark/src/test/java/org/apache/camel/component/spark/BaseSparkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark/src/test/java/org/apache/camel/component/spark/BaseSparkTest.java b/components/camel-spark/src/test/java/org/apache/camel/component/spark/BaseSparkTest.java
new file mode 100644
index 0000000..ab5f0e7
--- /dev/null
+++ b/components/camel-spark/src/test/java/org/apache/camel/component/spark/BaseSparkTest.java
@@ -0,0 +1,46 @@
+/**
+ * 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.spark;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+
+public abstract class BaseSparkTest extends CamelTestSupport {
+
+    protected int port;
+
+    public int getPort() {
+        return port;
+    }
+
+    @Override
+    public void setUp() throws Exception {
+        port = AvailablePortFinder.getNextAvailable(24500);
+        super.setUp();
+    }
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+
+        SparkComponent spark = context.getComponent("spark", SparkComponent.class);
+        spark.setPort(port);
+
+        return context;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/45299633/components/camel-spark/src/test/java/org/apache/camel/component/spark/CamelSparkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark/src/test/java/org/apache/camel/component/spark/CamelSparkTest.java b/components/camel-spark/src/test/java/org/apache/camel/component/spark/CamelSparkTest.java
index a6cc760..71279cf 100644
--- a/components/camel-spark/src/test/java/org/apache/camel/component/spark/CamelSparkTest.java
+++ b/components/camel-spark/src/test/java/org/apache/camel/component/spark/CamelSparkTest.java
@@ -17,16 +17,15 @@
 package org.apache.camel.component.spark;
 
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
-public class CamelSparkTest extends CamelTestSupport {
+public class CamelSparkTest extends BaseSparkTest {
 
     @Test
     public void testSparkGet() throws Exception {
         getMockEndpoint("mock:foo").expectedMessageCount(1);
 
-        String out = template.requestBody("http://0.0.0.0:4567/hello", null, String.class);
+        String out = template.requestBody("http://0.0.0.0:" + getPort() + "/hello", null, String.class);
         assertEquals("Bye World", out);
 
         assertMockEndpointsSatisfied();
@@ -38,8 +37,8 @@ public class CamelSparkTest extends CamelTestSupport {
             @Override
             public void configure() throws Exception {
                 from("spark:get:hello")
-                    .to("mock:foo")
-                    .transform().constant("Bye World");
+                        .to("mock:foo")
+                        .transform().constant("Bye World");
             }
         };
     }