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 2011/06/12 13:22:00 UTC

svn commit: r1134914 - in /camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc: ./ javabody/

Author: davsclaus
Date: Sun Jun 12 11:21:59 2011
New Revision: 1134914

URL: http://svn.apache.org/viewvc?rev=1134914&view=rev
Log:
Use dynamic assigned ports in unit test.

Added:
    camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/BaseAhcTest.java
Modified:
    camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcBridgeEndpointTest.java
    camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcComponentClientConfigTest.java
    camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduce500Test.java
    camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceClientConfigTest.java
    camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetHeadersTest.java
    camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetNoSlashInUriTest.java
    camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetTest.java
    camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceNoThrowExceptionOnFailureTest.java
    camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostHeadersTest.java
    camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostTest.java
    camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceTransferExceptionTest.java
    camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/javabody/AhcProduceJavaBodyTest.java

Modified: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcBridgeEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcBridgeEndpointTest.java?rev=1134914&r1=1134913&r2=1134914&view=diff
==============================================================================
--- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcBridgeEndpointTest.java (original)
+++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcBridgeEndpointTest.java Sun Jun 12 11:21:59 2011
@@ -22,22 +22,24 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
-public class AhcBridgeEndpointTest extends CamelTestSupport {
+public class AhcBridgeEndpointTest extends BaseAhcTest {
+
+    private int port1;
+    private int port2;
 
     @Test
     public void testBridgeEndpoint() throws Exception {
-        String response = template.requestBodyAndHeader("http://localhost:9080/test/hello",
+        String response = template.requestBodyAndHeader("http://localhost:" + port1 +"/test/hello",
                 new ByteArrayInputStream("This is a test".getBytes()), "Content-Type", "application/xml", String.class);
         assertEquals("Get a wrong response", "/", response);
 
-        response = template.requestBody("http://localhost:9081/hello/world", "hello", String.class);
+        response = template.requestBody("http://localhost:" + port2 + "/hello/world", "hello", String.class);
         assertEquals("Get a wrong response", "/hello/world", response);
 
         try {
-            template.requestBody("http://localhost:9080/hello/world", "hello", String.class);
+            template.requestBody("http://localhost:" + port1 + "/hello/world", "hello", String.class);
             fail("Expect exception here!");
         } catch (Exception ex) {
             assertTrue("We should get a RuntimeCamelException", ex instanceof RuntimeCamelException);
@@ -49,6 +51,9 @@ public class AhcBridgeEndpointTest exten
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
+                port1 = getPort();
+                port2 = getNextPort();
+
                 Processor serviceProc = new Processor() {
                     public void process(Exchange exchange) throws Exception {
                         // get the request URL and copy it to the request body
@@ -57,10 +62,10 @@ public class AhcBridgeEndpointTest exten
                     }
                 };
 
-                from("jetty:http://localhost:9080/test/hello")
-                        .to("ahc:http://localhost:9081?throwExceptionOnFailure=false&bridgeEndpoint=true");
+                from("jetty:http://localhost:" + port1 + "/test/hello")
+                        .to("ahc:http://localhost:" + port2 + "?throwExceptionOnFailure=false&bridgeEndpoint=true");
 
-                from("jetty:http://localhost:9081?matchOnUriPrefix=true")
+                from("jetty:http://localhost:" + port2 + "?matchOnUriPrefix=true")
                         .process(serviceProc);
             }
         };

Modified: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcComponentClientConfigTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcComponentClientConfigTest.java?rev=1134914&r1=1134913&r2=1134914&view=diff
==============================================================================
--- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcComponentClientConfigTest.java (original)
+++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcComponentClientConfigTest.java Sun Jun 12 11:21:59 2011
@@ -17,14 +17,12 @@
 package org.apache.camel.component.ahc;
 
 import com.ning.http.client.AsyncHttpClientConfig;
-import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
-public class AhcComponentClientConfigTest extends CamelTestSupport {
+public class AhcComponentClientConfigTest extends BaseAhcTest {
 
     public void configureComponent() {
         // START SNIPPET: e1
@@ -41,12 +39,6 @@ public class AhcComponentClientConfigTes
         // END SNIPPET: e1
     }
 
-    @Override
-    protected CamelContext createCamelContext() throws Exception {
-        CamelContext context = super.createCamelContext();
-        return context;
-    }
-
     @Test
     public void testAhcComponentClientConfig() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
@@ -64,19 +56,19 @@ public class AhcComponentClientConfigTes
                 configureComponent();
 
                 from("direct:start")
-                    .to("ahc:http://localhost:9080/foo")
+                    .to("ahc:http://localhost:{{port}}/foo")
                     .to("mock:result");
 
-                from("jetty:http://localhost:9080/foo")
+                from("jetty:http://localhost:{{port}}/foo")
                         .process(new Processor() {
                             public void process(Exchange exchange) throws Exception {
                                 // redirect to test the client config worked as we told it to follow redirects
                                 exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, "301");
-                                exchange.getOut().setHeader("Location", "http://localhost:9080/bar");
+                                exchange.getOut().setHeader("Location", "http://localhost:" + getPort() + "/bar");
                             }
                         });
 
-                from("jetty:http://localhost:9080/bar")
+                from("jetty:http://localhost:{{port}}/bar")
                         .transform(constant("Bye World"));
             }
         };

Modified: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduce500Test.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduce500Test.java?rev=1134914&r1=1134913&r2=1134914&view=diff
==============================================================================
--- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduce500Test.java (original)
+++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduce500Test.java Sun Jun 12 11:21:59 2011
@@ -20,10 +20,9 @@ import org.apache.camel.CamelExecutionEx
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
-public class AhcProduce500Test extends CamelTestSupport {
+public class AhcProduce500Test extends BaseAhcTest {
 
     @Test
     public void testAhcProduce() throws Exception {
@@ -51,10 +50,10 @@ public class AhcProduce500Test extends C
             @Override
             public void configure() throws Exception {
                 from("direct:start")
-                    .to("ahc:http://localhost:9080/foo")
+                    .to("ahc:http://localhost:{{port}}/foo")
                     .to("mock:result");
 
-                from("jetty:http://localhost:9080/foo")
+                from("jetty:http://localhost:{{port}}/foo")
                         .process(new Processor() {
                             public void process(Exchange exchange) throws Exception {
                                 exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 500);

Modified: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceClientConfigTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceClientConfigTest.java?rev=1134914&r1=1134913&r2=1134914&view=diff
==============================================================================
--- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceClientConfigTest.java (original)
+++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceClientConfigTest.java Sun Jun 12 11:21:59 2011
@@ -21,10 +21,9 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.JndiRegistry;
-import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
-public class AhcProduceClientConfigTest extends CamelTestSupport {
+public class AhcProduceClientConfigTest extends BaseAhcTest {
 
     @Override
     protected JndiRegistry createRegistry() throws Exception {
@@ -51,19 +50,19 @@ public class AhcProduceClientConfigTest 
             @Override
             public void configure() throws Exception {
                 from("direct:start")
-                    .to("ahc:http://localhost:9080/foo?clientConfig=#myConfig")
+                    .to("ahc:http://localhost:{{port}}/foo?clientConfig=#myConfig")
                     .to("mock:result");
 
-                from("jetty:http://localhost:9080/foo")
+                from("jetty:http://localhost:{{port}}/foo")
                         .process(new Processor() {
                             public void process(Exchange exchange) throws Exception {
                                 // redirect to test the client config worked as we told it to follow redirects
                                 exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, "301");
-                                exchange.getOut().setHeader("Location", "http://localhost:9080/bar");
+                                exchange.getOut().setHeader("Location", "http://localhost:" + getPort() + "/bar");
                             }
                         });
 
-                from("jetty:http://localhost:9080/bar")
+                from("jetty:http://localhost:{{port}}/bar")
                         .transform(constant("Bye World"));
             }
         };

Modified: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetHeadersTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetHeadersTest.java?rev=1134914&r1=1134913&r2=1134914&view=diff
==============================================================================
--- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetHeadersTest.java (original)
+++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetHeadersTest.java Sun Jun 12 11:21:59 2011
@@ -21,10 +21,9 @@ import java.util.Map;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
-public class AhcProduceGetHeadersTest extends CamelTestSupport {
+public class AhcProduceGetHeadersTest extends BaseAhcTest {
 
     @Test
     public void testAhcProduce() throws Exception {
@@ -49,10 +48,10 @@ public class AhcProduceGetHeadersTest ex
             @Override
             public void configure() throws Exception {
                 from("direct:start")
-                    .to("ahc:http://localhost:9080/foo")
+                    .to("ahc:http://localhost:{{port}}/foo")
                     .to("mock:result");
 
-                from("jetty:http://localhost:9080/foo")
+                from("jetty:http://localhost:{{port}}/foo")
                         .transform(constant("Bye World"));
             }
         };

Modified: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetNoSlashInUriTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetNoSlashInUriTest.java?rev=1134914&r1=1134913&r2=1134914&view=diff
==============================================================================
--- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetNoSlashInUriTest.java (original)
+++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetNoSlashInUriTest.java Sun Jun 12 11:21:59 2011
@@ -17,10 +17,9 @@
 package org.apache.camel.component.ahc;
 
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
-public class AhcProduceGetNoSlashInUriTest extends CamelTestSupport {
+public class AhcProduceGetNoSlashInUriTest extends BaseAhcTest {
 
     @Test
     public void testAhcProduce() throws Exception {
@@ -38,10 +37,10 @@ public class AhcProduceGetNoSlashInUriTe
             public void configure() throws Exception {
                 from("direct:start")
                     // no // slash in uri should still work
-                    .to("ahc:http:localhost:9080/foo")
+                    .to("ahc:http:localhost:{{port}}/foo")
                     .to("mock:result");
 
-                from("jetty:http://localhost:9080/foo")
+                from("jetty:http://localhost:{{port}}/foo")
                         .transform(constant("Bye World"));
             }
         };

Modified: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetTest.java?rev=1134914&r1=1134913&r2=1134914&view=diff
==============================================================================
--- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetTest.java (original)
+++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetTest.java Sun Jun 12 11:21:59 2011
@@ -18,10 +18,9 @@ package org.apache.camel.component.ahc;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
-public class AhcProduceGetTest extends CamelTestSupport {
+public class AhcProduceGetTest extends BaseAhcTest {
 
     @Test
     public void testAhcProduce() throws Exception {
@@ -43,7 +42,7 @@ public class AhcProduceGetTest extends C
 
     @Test
     public void testAhcProduceDirectly() throws Exception {
-        Object out = template.requestBody("ahc:http://localhost:9080/foo", null, String.class);
+        Object out = template.requestBody("ahc:http://localhost:{{port}}/foo", null, String.class);
         assertEquals("Bye World", out);
     }
 
@@ -62,10 +61,10 @@ public class AhcProduceGetTest extends C
             @Override
             public void configure() throws Exception {
                 from("direct:start")
-                    .to("ahc:http://localhost:9080/foo")
+                    .to("ahc:http://localhost:{{port}}/foo")
                     .to("mock:result");
 
-                from("jetty:http://localhost:9080/foo")
+                from("jetty:http://localhost:{{port}}/foo")
                         .transform(constant("Bye World"));
             }
         };

Modified: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceNoThrowExceptionOnFailureTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceNoThrowExceptionOnFailureTest.java?rev=1134914&r1=1134913&r2=1134914&view=diff
==============================================================================
--- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceNoThrowExceptionOnFailureTest.java (original)
+++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceNoThrowExceptionOnFailureTest.java Sun Jun 12 11:21:59 2011
@@ -19,10 +19,9 @@ package org.apache.camel.component.ahc;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
-public class AhcProduceNoThrowExceptionOnFailureTest extends CamelTestSupport {
+public class AhcProduceNoThrowExceptionOnFailureTest extends BaseAhcTest {
 
     @Test
     public void testAhcProduce() throws Exception {
@@ -40,10 +39,10 @@ public class AhcProduceNoThrowExceptionO
             @Override
             public void configure() throws Exception {
                 from("direct:start")
-                    .to("ahc:http://localhost:9080/foo?throwExceptionOnFailure=false")
+                    .to("ahc:http://localhost:{{port}}/foo?throwExceptionOnFailure=false")
                     .to("mock:result");
 
-                from("jetty:http://localhost:9080/foo")
+                from("jetty:http://localhost:{{port}}/foo")
                         .process(new Processor() {
                             public void process(Exchange exchange) throws Exception {
                                 exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 500);

Modified: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostHeadersTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostHeadersTest.java?rev=1134914&r1=1134913&r2=1134914&view=diff
==============================================================================
--- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostHeadersTest.java (original)
+++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostHeadersTest.java Sun Jun 12 11:21:59 2011
@@ -21,10 +21,9 @@ import java.util.Map;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
-public class AhcProducePostHeadersTest extends CamelTestSupport {
+public class AhcProducePostHeadersTest extends BaseAhcTest {
 
     @Test
     public void testAhcProduce() throws Exception {
@@ -49,10 +48,10 @@ public class AhcProducePostHeadersTest e
             @Override
             public void configure() throws Exception {
                 from("direct:start")
-                    .to("ahc:http://localhost:9080/foo")
+                    .to("ahc:http://localhost:{{port}}/foo")
                     .to("mock:result");
 
-                from("jetty:http://localhost:9080/foo")
+                from("jetty:http://localhost:{{port}}/foo")
                         .transform(simple("Bye ${body}"));
             }
         };

Modified: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostTest.java?rev=1134914&r1=1134913&r2=1134914&view=diff
==============================================================================
--- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostTest.java (original)
+++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostTest.java Sun Jun 12 11:21:59 2011
@@ -18,10 +18,9 @@ package org.apache.camel.component.ahc;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
-public class AhcProducePostTest extends CamelTestSupport {
+public class AhcProducePostTest extends BaseAhcTest {
 
     @Test
     public void testAhcProduce() throws Exception {
@@ -43,7 +42,7 @@ public class AhcProducePostTest extends 
 
     @Test
     public void testAhcProduceDirectly() throws Exception {
-        Object out = template.requestBody("ahc:http://localhost:9080/foo", "World", String.class);
+        Object out = template.requestBody("ahc:http://localhost:{{port}}/foo", "World", String.class);
         assertEquals("Bye World", out);
     }
 
@@ -62,10 +61,10 @@ public class AhcProducePostTest extends 
             @Override
             public void configure() throws Exception {
                 from("direct:start")
-                    .to("ahc:http://localhost:9080/foo")
+                    .to("ahc:http://localhost:{{port}}/foo")
                     .to("mock:result");
 
-                from("jetty:http://localhost:9080/foo")
+                from("jetty:http://localhost:{{port}}/foo")
                         .transform(simple("Bye ${body}"));
             }
         };

Modified: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceTransferExceptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceTransferExceptionTest.java?rev=1134914&r1=1134913&r2=1134914&view=diff
==============================================================================
--- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceTransferExceptionTest.java (original)
+++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceTransferExceptionTest.java Sun Jun 12 11:21:59 2011
@@ -18,10 +18,9 @@ package org.apache.camel.component.ahc;
 
 import org.apache.camel.CamelExecutionException;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
 
-public class AhcProduceTransferExceptionTest extends CamelTestSupport {
+public class AhcProduceTransferExceptionTest extends BaseAhcTest {
 
     @Test
     public void testAhcProduce() throws Exception {
@@ -45,10 +44,10 @@ public class AhcProduceTransferException
             @Override
             public void configure() throws Exception {
                 from("direct:start")
-                    .to("ahc:http://localhost:9080/foo?transferException=true")
+                    .to("ahc:http://localhost:{{port}}/foo?transferException=true")
                     .to("mock:result");
 
-                from("jetty:http://localhost:9080/foo?transferException=true")
+                from("jetty:http://localhost:{{port}}/foo?transferException=true")
                     .throwException(new MyOrderException("123"));
             }
         };

Added: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/BaseAhcTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/BaseAhcTest.java?rev=1134914&view=auto
==============================================================================
--- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/BaseAhcTest.java (added)
+++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/BaseAhcTest.java Sun Jun 12 11:21:59 2011
@@ -0,0 +1,97 @@
+/**
+ * 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.ahc;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.Properties;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.properties.PropertiesComponent;
+import org.apache.camel.converter.IOConverter;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+/**
+ *
+ */
+public class BaseAhcTest extends CamelTestSupport {
+    private static volatile int port;
+
+    @BeforeClass
+    public static void initPort() throws Exception {
+        File file = new File("./target/ahcport.txt");
+        file = file.getAbsoluteFile();
+
+        if (!file.exists()) {
+            // start from somewhere in the 24xxx range
+            port = AvailablePortFinder.getNextAvailable(24000);
+        } else {
+            // read port number from file
+            String s = IOConverter.toString(file, null);
+            port = Integer.parseInt(s);
+            // use next port
+            port++;
+        }
+    }
+
+    @AfterClass
+    public static void savePort() throws Exception {
+        File file = new File("./target/ahcport.txt");
+        file = file.getAbsoluteFile();
+
+        // save to file, do not append
+        FileOutputStream fos = new FileOutputStream(file, false);
+        try {
+            fos.write(String.valueOf(port).getBytes());
+        } finally {
+            fos.close();
+        }
+    }
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+        context.addComponent("properties", new PropertiesComponent("ref:prop"));
+        return context;
+    }
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+
+        Properties prop = new Properties();
+        prop.setProperty("port", "" + getPort());
+        jndi.bind("prop", prop);
+
+        return jndi;
+    }
+
+    protected int getNextPort() {
+        port = AvailablePortFinder.getNextAvailable(port + 1);
+        return port;
+    }
+
+    protected int getPort() {
+        return port;
+    }
+
+}
+

Modified: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/javabody/AhcProduceJavaBodyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/javabody/AhcProduceJavaBodyTest.java?rev=1134914&r1=1134913&r2=1134914&view=diff
==============================================================================
--- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/javabody/AhcProduceJavaBodyTest.java (original)
+++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/javabody/AhcProduceJavaBodyTest.java Sun Jun 12 11:21:59 2011
@@ -20,13 +20,13 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.ahc.AhcConstants;
-import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.component.ahc.BaseAhcTest;
 import org.junit.Test;
 
 /**
  *
  */
-public class AhcProduceJavaBodyTest extends CamelTestSupport {
+public class AhcProduceJavaBodyTest extends BaseAhcTest {
 
     @Override
     public boolean isUseRouteBuilder() {
@@ -38,7 +38,7 @@ public class AhcProduceJavaBodyTest exte
         context.addRoutes(new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("jetty:http://localhost:9080/myapp/myservice")
+                from("jetty:http://localhost:{{port}}/myapp/myservice")
                         .process(new Processor() {
                             public void process(Exchange exchange) throws Exception {
                                 MyCoolBean cool = exchange.getIn().getBody(MyCoolBean.class);
@@ -58,7 +58,7 @@ public class AhcProduceJavaBodyTest exte
 
         MyCoolBean cool = new MyCoolBean(123, "Camel");
 
-        String reply = template.requestBodyAndHeader("ahc:http:localhost:9080/myapp/myservice", cool,
+        String reply = template.requestBodyAndHeader("ahc:http:localhost:{{port}}/myapp/myservice", cool,
                 Exchange.CONTENT_TYPE, AhcConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT, String.class);
 
         assertEquals("OK", reply);
@@ -69,7 +69,7 @@ public class AhcProduceJavaBodyTest exte
         context.addRoutes(new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("jetty:http://localhost:9080/myapp/myservice")
+                from("jetty:http://localhost:{{port}}/myapp/myservice")
                         .process(new Processor() {
                             public void process(Exchange exchange) throws Exception {
                                 MyCoolBean cool = exchange.getIn().getBody(MyCoolBean.class);
@@ -89,7 +89,7 @@ public class AhcProduceJavaBodyTest exte
 
         MyCoolBean cool = new MyCoolBean(123, "Camel");
 
-        MyCoolBean reply = template.requestBodyAndHeader("ahc:http://localhost:9080/myapp/myservice", cool,
+        MyCoolBean reply = template.requestBodyAndHeader("ahc:http://localhost:{{port}}/myapp/myservice", cool,
                 Exchange.CONTENT_TYPE, AhcConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT, MyCoolBean.class);
 
         assertEquals(456, reply.getId());
@@ -101,7 +101,7 @@ public class AhcProduceJavaBodyTest exte
         context.addRoutes(new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("jetty:http://localhost:9080/myapp/myservice")
+                from("jetty:http://localhost:{{port}}/myapp/myservice")
                         .process(new Processor() {
                             public void process(Exchange exchange) throws Exception {
                                 String body = exchange.getIn().getBody(String.class);
@@ -117,7 +117,7 @@ public class AhcProduceJavaBodyTest exte
         });
         context.start();
 
-        MyCoolBean reply = template.requestBody("ahc:http://localhost:9080/myapp/myservice", "Hello World", MyCoolBean.class);
+        MyCoolBean reply = template.requestBody("ahc:http://localhost:{{port}}/myapp/myservice", "Hello World", MyCoolBean.class);
 
         assertEquals(456, reply.getId());
         assertEquals("Camel rocks", reply.getName());