You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2011/12/30 10:12:29 UTC

svn commit: r1225777 - in /camel/trunk/tests/camel-itest/src/test: java/org/apache/camel/itest/http/ resources/org/apache/camel/itest/http/

Author: ningjiang
Date: Fri Dec 30 09:12:28 2011
New Revision: 1225777

URL: http://svn.apache.org/viewvc?rev=1225777&view=rev
Log:
CAMEL-4837  use dynamic port numbers with http itest

Modified:
    camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/Http4EndpointTest.java
    camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/Http4MaxConnectionPerHostTest.java
    camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpTestServer.java
    camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/Http4EndpointTest-context.xml
    camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/Http4MaxConnectionPerHostTest-context.xml

Modified: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/Http4EndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/Http4EndpointTest.java?rev=1225777&r1=1225776&r2=1225777&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/Http4EndpointTest.java (original)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/Http4EndpointTest.java Fri Dec 30 09:12:28 2011
@@ -30,8 +30,8 @@ import org.apache.http.entity.StringEnti
 import org.apache.http.protocol.HTTP;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.test.context.ContextConfiguration;
@@ -39,6 +39,7 @@ import org.springframework.test.context.
 
 @ContextConfiguration
 public class Http4EndpointTest extends AbstractJUnit4SpringContextTests {
+    protected static HttpTestServer localServer;
 
     @Autowired
     protected CamelContext camelContext;
@@ -49,10 +50,10 @@ public class Http4EndpointTest extends A
     @EndpointInject(uri = "mock:result")
     protected MockEndpoint mock;
 
-    protected HttpTestServer localServer;
+    
 
-    @Before
-    public void setUp() throws Exception {
+    @BeforeClass
+    public static void setUp() throws Exception {
         localServer = new HttpTestServer(null, null);
         localServer.register("/", new HttpRequestHandler() {
             public void handle(HttpRequest request, HttpResponse response,
@@ -64,8 +65,8 @@ public class Http4EndpointTest extends A
         localServer.start();
     }
 
-    @After
-    public void tearDown() throws Exception {
+    @AfterClass
+    public static void tearDown() throws Exception {
         if (localServer != null) {
             localServer.stop();
         }

Modified: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/Http4MaxConnectionPerHostTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/Http4MaxConnectionPerHostTest.java?rev=1225777&r1=1225776&r2=1225777&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/Http4MaxConnectionPerHostTest.java (original)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/Http4MaxConnectionPerHostTest.java Fri Dec 30 09:12:28 2011
@@ -30,8 +30,8 @@ import org.apache.http.entity.StringEnti
 import org.apache.http.protocol.HTTP;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
-import org.junit.After;
-import org.junit.Before;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.test.context.ContextConfiguration;
@@ -40,6 +40,7 @@ import org.springframework.test.context.
 @ContextConfiguration
 public class Http4MaxConnectionPerHostTest extends
         AbstractJUnit4SpringContextTests {
+    protected static HttpTestServer localServer;
 
     @Autowired
     protected CamelContext camelContext;
@@ -50,10 +51,8 @@ public class Http4MaxConnectionPerHostTe
     @EndpointInject(uri = "mock:result")
     protected MockEndpoint mock;
 
-    protected HttpTestServer localServer;
-
-    @Before
-    public void setUp() throws Exception {
+    @BeforeClass
+    public static void setUp() throws Exception {
         localServer = new HttpTestServer(null, null);
         localServer.register("/", new HttpRequestHandler() {
             public void handle(HttpRequest request, HttpResponse response,
@@ -65,8 +64,8 @@ public class Http4MaxConnectionPerHostTe
         localServer.start();
     }
 
-    @After
-    public void tearDown() throws Exception {
+    @AfterClass
+    public static void tearDown() throws Exception {
         if (localServer != null) {
             localServer.stop();
         }

Modified: camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpTestServer.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpTestServer.java?rev=1225777&r1=1225776&r2=1225777&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpTestServer.java (original)
+++ camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/http/HttpTestServer.java Fri Dec 30 09:12:28 2011
@@ -29,6 +29,7 @@ import java.util.concurrent.atomic.Atomi
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLServerSocketFactory;
 
+import org.apache.camel.test.AvailablePortFinder;
 import org.apache.http.ConnectionReuseStrategy;
 import org.apache.http.HttpResponseFactory;
 import org.apache.http.HttpResponseInterceptor;
@@ -62,7 +63,9 @@ import org.apache.http.protocol.Response
  * @author muellerc
  */
 public class HttpTestServer {
-
+    
+    public static final int PORT = AvailablePortFinder.getNextAvailable(18080);
+    
     /**
      * The local address to bind to.
      * The host is an IP number rather than "localhost" to avoid surprises
@@ -70,7 +73,7 @@ public class HttpTestServer {
      * The port is 0 to let the system pick one.
      */
     public static final InetSocketAddress TEST_SERVER_ADDR =
-        new InetSocketAddress("localhost", 18080);
+        new InetSocketAddress("localhost", PORT);
 
     /** The request handler registry. */
     private final HttpRequestHandlerRegistry handlerRegistry;
@@ -91,6 +94,12 @@ public class HttpTestServer {
 
     /** The number of connections this accepted. */
     private final AtomicInteger acceptedConnections = new AtomicInteger(0);
+    
+    static {
+        //set them as system properties so Spring can use the property placeholder
+        //things to set them into the URL's in the spring contexts 
+        System.setProperty("HttpTestServer.Port", Integer.toString(PORT));
+    }
 
     /**
      * Creates a new test server.

Modified: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/Http4EndpointTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/Http4EndpointTest-context.xml?rev=1225777&r1=1225776&r2=1225777&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/Http4EndpointTest-context.xml (original)
+++ camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/Http4EndpointTest-context.xml Fri Dec 30 09:12:28 2011
@@ -24,8 +24,10 @@
     ">
 
     <!-- START SNIPPET: e1 -->
+    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
+    
     <bean id="httpEndpoint" class="org.apache.camel.component.http4.HttpEndpoint">
-        <property name="httpUri" value="http://127.0.0.1:18080/"/>
+        <property name="httpUri" value="http://127.0.0.1:${HttpTestServer.Port}/"/>
         <property name="clientParams" ref="clientParams"/>
         <property name="clientConnectionManager" ref="clientConnectionManager"/>
     </bean>

Modified: camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/Http4MaxConnectionPerHostTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/Http4MaxConnectionPerHostTest-context.xml?rev=1225777&r1=1225776&r2=1225777&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/Http4MaxConnectionPerHostTest-context.xml (original)
+++ camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/http/Http4MaxConnectionPerHostTest-context.xml Fri Dec 30 09:12:28 2011
@@ -24,6 +24,7 @@
     ">
 
     <!-- START SNIPPET: e1 -->
+    <bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent"/>
     <bean id="httpComponent" class="org.apache.camel.component.http4.HttpComponent">
         <property name="camelContext" ref="camel"/>
         <property name="clientConnectionManager" ref="clientConnectionManager"/>
@@ -65,7 +66,7 @@
     <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring" trace="true">
         <route>
             <from uri="direct:start"/>
-            <to uri="http://127.0.0.1:18080/"/>
+            <to uri="http://127.0.0.1:{{HttpTestServer.Port}}/"/>
             <to uri="mock:result"/>
         </route>
     </camelContext>