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/12/24 15:36:00 UTC

svn commit: r1222982 - in /camel/trunk/examples: camel-example-reportincident-wssecurity/src/main/resources/ camel-example-reportincident-wssecurity/src/main/resources/META-INF/spring/ camel-example-reportincident-wssecurity/src/test/java/org/apache/ca...

Author: davsclaus
Date: Sat Dec 24 14:36:00 2011
New Revision: 1222982

URL: http://svn.apache.org/viewvc?rev=1222982&view=rev
Log:
CAMEL-4814: Use dynamic port numbers for testing examples.

Added:
    camel/trunk/examples/camel-example-reportincident-wssecurity/src/main/resources/incident.properties
    camel/trunk/examples/camel-example-reportincident/src/main/resources/incident.properties
Modified:
    camel/trunk/examples/camel-example-reportincident-wssecurity/src/main/resources/META-INF/spring/camel-context.xml
    camel/trunk/examples/camel-example-reportincident-wssecurity/src/test/java/org/apache/camel/example/reportincident/ReportIncidentRoutesTest.java
    camel/trunk/examples/camel-example-reportincident/pom.xml
    camel/trunk/examples/camel-example-reportincident/src/main/java/org/apache/camel/example/reportincident/ReportIncidentRoutes.java
    camel/trunk/examples/camel-example-reportincident/src/main/resources/META-INF/spring/camel-context.xml
    camel/trunk/examples/camel-example-reportincident/src/test/java/org/apache/camel/example/reportincident/ReportIncidentRoutesTest.java

Modified: camel/trunk/examples/camel-example-reportincident-wssecurity/src/main/resources/META-INF/spring/camel-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-reportincident-wssecurity/src/main/resources/META-INF/spring/camel-context.xml?rev=1222982&r1=1222981&r2=1222982&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-reportincident-wssecurity/src/main/resources/META-INF/spring/camel-context.xml (original)
+++ camel/trunk/examples/camel-example-reportincident-wssecurity/src/main/resources/META-INF/spring/camel-context.xml Sat Dec 24 14:36:00 2011
@@ -56,7 +56,7 @@
   -->
 
   <cxf:cxfEndpoint id="reportIncident"
-                   address="http://localhost:9080/camel-example-reportincident/webservices/incident"
+                   address="http://localhost:{{port}}/camel-example-reportincident/webservices/incident"
                    wsdlURL="etc/report_incident.wsdl"
                    serviceClass="org.apache.camel.example.reportincident.ReportIncidentEndpoint">
 
@@ -76,6 +76,8 @@
   <bean id="filenameGenerator" class="org.apache.camel.example.reportincident.FilenameGenerator"/>
 
   <camel:camelContext id="camel">
+    <!-- property which contains port number -->
+    <camel:propertyPlaceholder id="properties" location="classpath:incident.properties,file:target/custom.properties"/>
 
     <camel:route>
       <camel:from uri="cxf:bean:reportIncident"/>

Added: camel/trunk/examples/camel-example-reportincident-wssecurity/src/main/resources/incident.properties
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-reportincident-wssecurity/src/main/resources/incident.properties?rev=1222982&view=auto
==============================================================================
--- camel/trunk/examples/camel-example-reportincident-wssecurity/src/main/resources/incident.properties (added)
+++ camel/trunk/examples/camel-example-reportincident-wssecurity/src/main/resources/incident.properties Sat Dec 24 14:36:00 2011
@@ -0,0 +1,19 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+
+# properties for the application
+port=9081
\ No newline at end of file

Modified: camel/trunk/examples/camel-example-reportincident-wssecurity/src/test/java/org/apache/camel/example/reportincident/ReportIncidentRoutesTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-reportincident-wssecurity/src/test/java/org/apache/camel/example/reportincident/ReportIncidentRoutesTest.java?rev=1222982&r1=1222981&r2=1222982&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-reportincident-wssecurity/src/test/java/org/apache/camel/example/reportincident/ReportIncidentRoutesTest.java (original)
+++ camel/trunk/examples/camel-example-reportincident-wssecurity/src/test/java/org/apache/camel/example/reportincident/ReportIncidentRoutesTest.java Sat Dec 24 14:36:00 2011
@@ -16,18 +16,22 @@
  */
 package org.apache.camel.example.reportincident;
 
+import java.io.File;
+import java.io.FileOutputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelSpringTestSupport;
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.interceptor.LoggingOutInterceptor;
 import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.jvnet.mock_javamail.Mailbox;
 import org.springframework.context.support.AbstractXmlApplicationContext;
@@ -39,16 +43,28 @@ import org.springframework.context.suppo
 public class ReportIncidentRoutesTest extends CamelSpringTestSupport {
 
     // should be the same address as we have in our route
-    private static final String URL = "http://localhost:9080/camel-example-reportincident/webservices/incident";
+    private static final String URL = "http://localhost:{{port}}/camel-example-reportincident/webservices/incident";
 
     protected CamelContext camel;
+    
+    @BeforeClass
+    public static void setupFreePort() throws Exception {
+        // find a free port number from 9100 onwards, and write that in the custom.properties file
+        // which we will use for the unit tests, to avoid port number in use problems
+        int port = AvailablePortFinder.getNextAvailable(9100);
+        String s = "port=" + port;
+        File custom = new File("target/custom.properties");
+        FileOutputStream fos = new FileOutputStream(custom);
+        fos.write(s.getBytes());
+        fos.close();
+    }
 
     @Override
     protected AbstractXmlApplicationContext createApplicationContext() {
         return new ClassPathXmlApplicationContext("/META-INF/spring/camel-context.xml");
     }
 
-    protected static ReportIncidentEndpoint createCXFClient() {
+    protected static ReportIncidentEndpoint createCXFClient(String url) {
         List<Interceptor<? extends Message>> outInterceptors = new ArrayList<Interceptor<? extends Message>>();
 
         // Define WSS4j properties for flow outgoing
@@ -71,7 +87,7 @@ public class ReportIncidentRoutesTest ex
         JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
         factory.setOutInterceptors(outInterceptors);
         factory.setServiceClass(ReportIncidentEndpoint.class);
-        factory.setAddress(URL);
+        factory.setAddress(url);
         return (ReportIncidentEndpoint) factory.create();
     }
 
@@ -94,7 +110,8 @@ public class ReportIncidentRoutesTest ex
         input.setPhone("0011 22 33 44");
 
         // create the webservice client and send the request
-        ReportIncidentEndpoint client = createCXFClient();
+        String url = context.resolvePropertyPlaceholders(URL);
+        ReportIncidentEndpoint client = createCXFClient(url);
         OutputReportIncident out = client.reportIncident(input);
 
         // assert we got a OK back

Modified: camel/trunk/examples/camel-example-reportincident/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-reportincident/pom.xml?rev=1222982&r1=1222981&r2=1222982&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-reportincident/pom.xml (original)
+++ camel/trunk/examples/camel-example-reportincident/pom.xml Sat Dec 24 14:36:00 2011
@@ -104,6 +104,12 @@
 			<version>${cxf-version}</version>
 		</dependency>
 
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-test</artifactId>
+      <scope>test</scope>
+    </dependency>
+
 		<dependency>
 			<groupId>junit</groupId>
 			<artifactId>junit</artifactId>

Modified: camel/trunk/examples/camel-example-reportincident/src/main/java/org/apache/camel/example/reportincident/ReportIncidentRoutes.java
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-reportincident/src/main/java/org/apache/camel/example/reportincident/ReportIncidentRoutes.java?rev=1222982&r1=1222981&r2=1222982&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-reportincident/src/main/java/org/apache/camel/example/reportincident/ReportIncidentRoutes.java (original)
+++ camel/trunk/examples/camel-example-reportincident/src/main/java/org/apache/camel/example/reportincident/ReportIncidentRoutes.java Sat Dec 24 14:36:00 2011
@@ -41,11 +41,11 @@ public class ReportIncidentRoutes extend
 
         // endpoint to our CXF webservice  
         // We should use the related path to publish the service, when using the ServletTransport
-        // so we need to configure set the bus which is configured to use the ServletTranspot
+        // so we need to configure set the bus which is configured to use the ServletTransport
         String cxfEndpointAddress = "cxf:/incident?bus=#cxf&";
         // Using the full http address for stand alone running
         if (!usingServletTransport) {
-            cxfEndpointAddress = "cxf://http://localhost:9080/camel-example-reportincident/webservices/incident?";
+            cxfEndpointAddress = "cxf://http://localhost:{{port}}/camel-example-reportincident/webservices/incident?";
         }
         String cxfEndpoint = cxfEndpointAddress
                 + "serviceClass=org.apache.camel.example.reportincident.ReportIncidentEndpoint"

Modified: camel/trunk/examples/camel-example-reportincident/src/main/resources/META-INF/spring/camel-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-reportincident/src/main/resources/META-INF/spring/camel-context.xml?rev=1222982&r1=1222981&r2=1222982&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-reportincident/src/main/resources/META-INF/spring/camel-context.xml (original)
+++ camel/trunk/examples/camel-example-reportincident/src/main/resources/META-INF/spring/camel-context.xml Sat Dec 24 14:36:00 2011
@@ -25,21 +25,28 @@
          http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
          http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd">
 
+  <!-- this is Spring XML example of the Camel route in the ReportIncidentRoutes class -->
+  <!-- this is for demonstration purpose, to show how you can use Camel with XML DSL -->
+
   <!-- Needed Apache CXF imports -->
   <import resource="classpath:META-INF/cxf/cxf.xml"/>
   
   <cxf:cxfEndpoint id="reportIncident"
-                   address="http://localhost:9080/camel-example-reportincident/webservices/incident"
+                   address="http://localhost:{{port}}/camel-example-reportincident/webservices/incident"
                    wsdlURL="etc/report_incident.wsdl"
                    serviceClass="org.apache.camel.example.reportincident.ReportIncidentEndpoint"/>
 
   <bean id="myBean" class="org.apache.camel.example.reportincident.MyBean"/>
+
   <bean id="filenameGenerator" class="org.apache.camel.example.reportincident.FilenameGenerator"/>
 
   <!-- this CamelContext contains the equivalent route from the Java DSL, but in XML
        so end users can see how to implement the route in both Java and XML -->
   <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
 
+    <!-- property which contains port number -->
+    <camel:propertyPlaceholder id="properties" location="classpath:incident.properties,file:target/custom.properties"/>
+
     <route>
       <from uri="cxf:bean:reportIncident"/>
       <convertBodyTo type="org.apache.camel.example.reportincident.InputReportIncident"/>

Added: camel/trunk/examples/camel-example-reportincident/src/main/resources/incident.properties
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-reportincident/src/main/resources/incident.properties?rev=1222982&view=auto
==============================================================================
--- camel/trunk/examples/camel-example-reportincident/src/main/resources/incident.properties (added)
+++ camel/trunk/examples/camel-example-reportincident/src/main/resources/incident.properties Sat Dec 24 14:36:00 2011
@@ -0,0 +1,19 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+
+# properties for the application
+port=9080
\ No newline at end of file

Modified: camel/trunk/examples/camel-example-reportincident/src/test/java/org/apache/camel/example/reportincident/ReportIncidentRoutesTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-reportincident/src/test/java/org/apache/camel/example/reportincident/ReportIncidentRoutesTest.java?rev=1222982&r1=1222981&r2=1222982&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-reportincident/src/test/java/org/apache/camel/example/reportincident/ReportIncidentRoutesTest.java (original)
+++ camel/trunk/examples/camel-example-reportincident/src/test/java/org/apache/camel/example/reportincident/ReportIncidentRoutesTest.java Sat Dec 24 14:36:00 2011
@@ -16,9 +16,15 @@
  */
 package org.apache.camel.example.reportincident;
 
+import java.io.File;
+import java.io.FileOutputStream;
+
 import org.apache.camel.CamelContext;
+import org.apache.camel.component.properties.PropertiesComponent;
 import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.test.AvailablePortFinder;
 import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.jvnet.mock_javamail.Mailbox;
 
@@ -30,12 +36,28 @@ import static org.junit.Assert.assertEqu
 public class ReportIncidentRoutesTest {
 
     // should be the same address as we have in our route
-    private static final String URL = "http://localhost:9080/camel-example-reportincident/webservices/incident";
+    private static final String URL = "http://localhost:{{port}}/camel-example-reportincident/webservices/incident";
 
     protected CamelContext camel;
 
+    @BeforeClass
+    public static void setupFreePort() throws Exception {
+        // find a free port number from 9100 onwards, and write that in the custom.properties file
+        // which we will use for the unit tests, to avoid port number in use problems
+        int port = AvailablePortFinder.getNextAvailable(9100);
+        String s = "port=" + port;
+        File custom = new File("target/custom.properties");
+        FileOutputStream fos = new FileOutputStream(custom);
+        fos.write(s.getBytes());
+        fos.close();
+    }
+
     protected void startCamel() throws Exception {
         camel = new DefaultCamelContext();
+
+        // add properties component
+        camel.addComponent("properties", new PropertiesComponent("classpath:incident.properties,file:target/custom.properties"));
+
         ReportIncidentRoutes routes = new ReportIncidentRoutes();
         routes.setUsingServletTransport(false);
         camel.addRoutes(routes);
@@ -46,16 +68,16 @@ public class ReportIncidentRoutesTest {
         camel.stop();
     }
 
-    protected static ReportIncidentEndpoint createCXFClient() {
+    protected static ReportIncidentEndpoint createCXFClient(String url) {
         // we use CXF to create a client for us as its easier than JAXWS and works
         JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
         factory.setServiceClass(ReportIncidentEndpoint.class);
-        factory.setAddress(URL);
+        factory.setAddress(url);
         return (ReportIncidentEndpoint) factory.create();
     }
 
     @Test
-    public void testRendportIncident() throws Exception {
+    public void testReportIncident() throws Exception {
         // start camel
         startCamel();
 
@@ -83,7 +105,8 @@ public class ReportIncidentRoutesTest {
         input.setPhone("0045 2962 7576");
 
         // create the webservice client and send the request
-        ReportIncidentEndpoint client = createCXFClient();
+        String url = camel.resolvePropertyPlaceholders(URL);
+        ReportIncidentEndpoint client = createCXFClient(url);
         OutputReportIncident out = client.reportIncident(input);
 
         // assert we got a OK back