camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tjsn...@apache.org
Subject svn commit: r1094149 - in /camel/trunk/components/camel-jetty/src/test: java/org/apache/camel/component/jetty/ java/org/apache/camel/component/jetty/manual/ resources/org/apache/camel/component/jetty/
Date Sun, 17 Apr 2011 14:33:43 GMT
Author: tjsnell
Date: Sun Apr 17 14:33:43 2011
New Revision: 1094149

URL: http://svn.apache.org/viewvc?rev=1094149&view=rev
Log:
Camel-3622 patch. Tests ported to use AvailablePortFinder.


Modified:
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/BaseJettyTest.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/manual/JettyManual.java
    camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-https.xml
    camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-noconnection-redelivery.xml
    camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-noconnection.xml

Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/BaseJettyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/BaseJettyTest.java?rev=1094149&r1=1094148&r2=1094149&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/BaseJettyTest.java
(original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/BaseJettyTest.java
Sun Apr 17 14:33:43 2011
@@ -25,7 +25,9 @@ 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.apache.commons.logging.impl.AvalonLogger;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 
@@ -42,7 +44,7 @@ public abstract class BaseJettyTest exte
 
         if (!file.exists()) {
             // start from somewhere in the 23xxx range
-            port = 23000 + new Random().nextInt(900);
+            port = AvailablePortFinder.getNextAvailable(23000);
         } else {
             // read port number from file
             String s = IOConverter.toString(file, null);
@@ -86,7 +88,8 @@ public abstract class BaseJettyTest exte
     }
 
     protected int getNextPort() {
-        return ++port;
+        port = AvailablePortFinder.getNextAvailable(port + 1);
+        return port;
     }
 
     protected int getPort() {

Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java?rev=1094149&r1=1094148&r2=1094149&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java
(original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java
Sun Apr 17 14:33:43 2011
@@ -20,6 +20,7 @@ import java.net.URL;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import javax.annotation.Resource;
 
 import org.apache.camel.EndpointInject;
 import org.apache.camel.Exchange;
@@ -30,12 +31,12 @@ import org.apache.camel.RuntimeCamelExce
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.apache.camel.test.junit4.TestSupport;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
@@ -50,7 +51,7 @@ public class SpringHttpsRouteTest {
     protected String expectedBody = "<hello>world!</hello>";
     protected String pwd = "changeit";
     protected Properties originalValues = new Properties();
-    protected transient Logger log = LoggerFactory.getLogger(TestSupport.class);
+    protected transient Log log = LogFactory.getLog(TestSupport.class);
 
     @EndpointInject(uri = "mock:a")
     MockEndpoint mockEndpoint;
@@ -58,6 +59,8 @@ public class SpringHttpsRouteTest {
     @Produce
     private ProducerTemplate template;
 
+    private Integer port;
+
     @Before
     public void setUp() throws Exception {
         // ensure jsse clients can validate the self signed dummy localhost cert, 
@@ -92,7 +95,7 @@ public class SpringHttpsRouteTest {
         mockEndpoint.reset();
         mockEndpoint.expectedBodiesReceived(expectedBody);
 
-        template.sendBodyAndHeader("https://localhost:9080/test", expectedBody, "Content-Type",
"application/xml");
+        template.sendBodyAndHeader("https://localhost:" + port + "/test", expectedBody, "Content-Type",
"application/xml");
 
         mockEndpoint.assertIsSatisfied();
         List<Exchange> list = mockEndpoint.getReceivedExchanges();
@@ -113,11 +116,19 @@ public class SpringHttpsRouteTest {
     public void testEndpointWithoutHttps() {
         mockEndpoint.reset();
         try {
-            template.sendBodyAndHeader("http://localhost:9080/test", expectedBody, "Content-Type",
"application/xml");
+            template.sendBodyAndHeader("http://localhost:" + port + "/test", expectedBody,
"Content-Type", "application/xml");
             fail("expect exception on access to https endpoint via http");
         } catch (RuntimeCamelException expected) {
         }
         assertTrue("mock endpoint was not called", mockEndpoint.getExchanges().isEmpty());
     }
 
+    public Integer getPort() {
+        return port;
+    }
+
+    @Resource(name = "dynaPort")
+    public void setPort(Integer port) {
+        this.port = port;
+    }
 }

Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/manual/JettyManual.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/manual/JettyManual.java?rev=1094149&r1=1094148&r2=1094149&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/manual/JettyManual.java
(original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/manual/JettyManual.java
Sun Apr 17 14:33:43 2011
@@ -20,6 +20,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -45,7 +46,7 @@ public class JettyManual extends CamelTe
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                from("jetty:http://localhost:9080/myapp/myservice")
+                from("jetty:http://localhost:" + AvailablePortFinder.getNextAvailable() +
"/ myapp / myservice")
                     .process(new Processor() {
                         public void process(Exchange exchange) throws Exception {
                             String body = exchange.getIn().getBody(String.class);

Modified: camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-https.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-https.xml?rev=1094149&r1=1094148&r2=1094149&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-https.xml
(original)
+++ camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-https.xml
Sun Apr 17 14:33:43 2011
@@ -21,17 +21,35 @@
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
-  <bean id="jetty" class="org.apache.camel.component.jetty.JettyHttpComponent">
-    <property name="sslPassword" value="changeit"/>
-    <property name="sslKeyPassword" value="changeit"/>
-    <property name="keystore" value="src/test/resources/jsse/localhost.ks"/>
-  </bean>  
-    
-  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
-    <route>
-      <from uri="jetty:https://localhost:9080/test"/>
-      <to uri="mock:a"/>
-    </route>
-  </camelContext>
+    <bean id="jetty" class="org.apache.camel.component.jetty.JettyHttpComponent">
+        <property name="sslPassword" value="changeit"/>
+        <property name="sslKeyPassword" value="changeit"/>
+        <property name="keystore" value="src/test/resources/jsse/localhost.ks"/>
+    </bean>
+
+
+    <bean id="dynaPort" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
+        <property name="targetClass">
+            <value>org.apache.camel.test.AvailablePortFinder</value>
+        </property>
+        <property name="targetMethod">
+            <value>getNextAvailable</value>
+        </property>
+        <property name="arguments">
+            <list>
+                <value>9000</value>
+            </list>
+        </property>
+    </bean>
+
+
+    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+        <endpoint id="input1" uri="jetty:https://localhost:#{dynaPort}/test"/>
+
+        <route>
+            <from ref="input1"/>
+            <to uri="mock:a"/>
+        </route>
+    </camelContext>
 
 </beans>

Modified: camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-noconnection-redelivery.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-noconnection-redelivery.xml?rev=1094149&r1=1094148&r2=1094149&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-noconnection-redelivery.xml
(original)
+++ camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-noconnection-redelivery.xml
Sun Apr 17 14:33:43 2011
@@ -22,7 +22,24 @@
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
 
+    <bean id="dynaPort" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
+        <property name="targetClass">
+            <value>org.apache.camel.test.AvailablePortFinder</value>
+        </property>
+        <property name="targetMethod">
+            <value>getNextAvailable</value>
+        </property>
+        <property name="arguments">
+            <list>
+                <value>9000</value>
+            </list>
+        </property>
+    </bean>
+
+
     <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+        <endpoint id="httpEndpoint" uri="http://localhost:#{dynaPort}/hi"/>
+        <endpoint id="jettyEndpoint" uri="jetty:http://localhost:#{dynaPort}/hi"/>
 
         <route>
             <from uri="direct:start"/>
@@ -31,11 +48,12 @@
                 <redeliveryPolicy maximumRedeliveries="4" redeliveryDelay="100" maximumRedeliveryDelay="5000"
                                   backOffMultiplier="2" useExponentialBackOff="true"/>
             </onException>
-            <to uri="http://localhost:9221/hi"/>
+            <to ref="httpEndpoint"/>
         </route>
 
         <route id="jetty">
-            <from uri="jetty:http://localhost:9221/hi"/>
+
+            <from ref="jettyEndpoint"/>
             <transform><simple>Bye ${body}</simple></transform>
         </route>
         

Modified: camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-noconnection.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-noconnection.xml?rev=1094149&r1=1094148&r2=1094149&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-noconnection.xml
(original)
+++ camel/trunk/components/camel-jetty/src/test/resources/org/apache/camel/component/jetty/jetty-noconnection.xml
Sun Apr 17 14:33:43 2011
@@ -22,14 +22,32 @@
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
 
+
+    <bean id="dynaPort" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
+        <property name="targetClass">
+            <value>org.apache.camel.test.AvailablePortFinder</value>
+        </property>
+        <property name="targetMethod">
+            <value>getNextAvailable</value>
+        </property>
+        <property name="arguments">
+            <list>
+                <value>5000</value>
+            </list>
+        </property>
+    </bean>
+
     <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+        <endpoint id="httpEndpoint" uri="http://localhost:#{dynaPort}/hi"/>
+        <endpoint id="jettyEndpoint" uri="jetty:http://localhost:#{dynaPort}/hi"/>
+
         <route>
             <from uri="direct:start"/>
-            <to uri="http://localhost:9222/hi"/>
+            <to ref="httpEndpoint"/>
         </route>
 
         <route id="jetty">
-            <from uri="jetty:http://localhost:9222/hi"/>
+            <from ref="jettyEndpoint"/>
             <transform><simple>Bye ${body}</simple></transform>
         </route>
         



Mime
View raw message