Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4F0CD11481 for ; Fri, 27 Jun 2014 16:29:19 +0000 (UTC) Received: (qmail 11729 invoked by uid 500); 27 Jun 2014 16:29:19 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 11671 invoked by uid 500); 27 Jun 2014 16:29:19 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 11662 invoked by uid 99); 27 Jun 2014 16:29:19 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Jun 2014 16:29:19 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id DB01498F2EB; Fri, 27 Jun 2014 16:29:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Fri, 27 Jun 2014 16:29:20 -0000 Message-Id: In-Reply-To: <8c2478d144654f44927b605660a9732e@git.apache.org> References: <8c2478d144654f44927b605660a9732e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [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 Authored: Fri Jun 27 15:25:24 2014 +0200 Committer: Claus Ibsen 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 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"); } }; }