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/29 14:01:13 UTC
svn commit: r1141062 - in
/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty:
InterfacesTest.java MultiPartFormWithCustomFilterTest.java
Author: davsclaus
Date: Wed Jun 29 12:01:12 2011
New Revision: 1141062
URL: http://svn.apache.org/viewvc?rev=1141062&view=rev
Log:
Using dynamic ports for unit test
Modified:
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/InterfacesTest.java
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiPartFormWithCustomFilterTest.java
Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/InterfacesTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/InterfacesTest.java?rev=1141062&r1=1141061&r2=1141062&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/InterfacesTest.java (original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/InterfacesTest.java Wed Jun 29 12:01:12 2011
@@ -24,13 +24,17 @@ import java.net.URL;
import java.util.Enumeration;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
-public class InterfacesTest extends CamelTestSupport {
+public class InterfacesTest extends BaseJettyTest {
private static boolean isMacOS = System.getProperty("os.name").startsWith("Mac");
private String remoteInterfaceAddress;
+ private int port1;
+ private int port2;
+ private int port3;
+ private int port4;
+
public InterfacesTest() throws IOException {
// Retrieve an address of some remote network interface
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
@@ -57,20 +61,20 @@ public class InterfacesTest extends Came
int expectedMessages = (remoteInterfaceAddress != null) ? 3 : 2;
getMockEndpoint("mock:endpoint").expectedMessageCount(expectedMessages);
- URL localUrl = new URL("http://localhost:4567/testRoute");
+ URL localUrl = new URL("http://localhost:" + port1 + "/testRoute");
String localResponse = context.getTypeConverter().convertTo(String.class, localUrl.openStream());
assertEquals("local", localResponse);
if (!isMacOS) {
- localUrl = new URL("http://127.0.0.1:4568/testRoute");
+ localUrl = new URL("http://127.0.0.1:" + port2 + "/testRoute");
} else {
- localUrl = new URL("http://localhost:4568/testRoute");
+ localUrl = new URL("http://localhost:" + port2 + "/testRoute");
}
localResponse = context.getTypeConverter().convertTo(String.class, localUrl.openStream());
assertEquals("local-differentPort", localResponse);
if (remoteInterfaceAddress != null) {
- URL url = new URL("http://" + remoteInterfaceAddress + ":4560/testRoute");
+ URL url = new URL("http://" + remoteInterfaceAddress + ":" + port3 + "/testRoute");
String remoteResponse = context.getTypeConverter().convertTo(String.class, url.openStream());
assertEquals("remote", remoteResponse);
}
@@ -83,12 +87,12 @@ public class InterfacesTest extends Came
int expectedMessages = (remoteInterfaceAddress != null) ? 2 : 1;
getMockEndpoint("mock:endpoint").expectedMessageCount(expectedMessages);
- URL localUrl = new URL("http://localhost:4569/allInterfaces");
+ URL localUrl = new URL("http://localhost:" + port4 + "/allInterfaces");
String localResponse = context.getTypeConverter().convertTo(String.class, localUrl.openStream());
assertEquals("allInterfaces", localResponse);
if (remoteInterfaceAddress != null) {
- URL url = new URL("http://" + remoteInterfaceAddress + ":4569/allInterfaces");
+ URL url = new URL("http://" + remoteInterfaceAddress + ":" + port4 + "/allInterfaces");
String remoteResponse = context.getTypeConverter().convertTo(String.class, url.openStream());
assertEquals("allInterfaces", remoteResponse);
}
@@ -102,21 +106,26 @@ public class InterfacesTest extends Came
@Override
public void configure() throws Exception {
- from("jetty:http://localhost:4567/testRoute")
+ port1 = getPort();
+ port2 = getNextPort();
+ port3 = getNextPort();
+ port4 = getNextPort();
+
+ from("jetty:http://localhost:" + port1 + "/testRoute")
.setBody().constant("local")
.to("mock:endpoint");
- from("jetty:http://localhost:4568/testRoute")
+ from("jetty:http://localhost:" + port2 + "/testRoute")
.setBody().constant("local-differentPort")
.to("mock:endpoint");
if (remoteInterfaceAddress != null) {
- from("jetty:http://" + remoteInterfaceAddress + ":4560/testRoute")
+ from("jetty:http://" + remoteInterfaceAddress + ":" + port3 + "/testRoute")
.setBody().constant("remote")
.to("mock:endpoint");
}
- from("jetty:http://0.0.0.0:4569/allInterfaces")
+ from("jetty:http://0.0.0.0:" + port4 + "/allInterfaces")
.setBody().constant("allInterfaces")
.to("mock:endpoint");
Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiPartFormWithCustomFilterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiPartFormWithCustomFilterTest.java?rev=1141062&r1=1141061&r2=1141062&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiPartFormWithCustomFilterTest.java (original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiPartFormWithCustomFilterTest.java Wed Jun 29 12:01:12 2011
@@ -41,7 +41,7 @@ import org.apache.commons.httpclient.met
import org.eclipse.jetty.servlets.MultiPartFilter;
import org.junit.Test;
-public class MultiPartFormWithCustomFilterTest extends CamelTestSupport {
+public class MultiPartFormWithCustomFilterTest extends BaseJettyTest {
private static class MyMultipartFilter extends MultiPartFilter {
@Override
@@ -57,7 +57,7 @@ public class MultiPartFormWithCustomFilt
public void testSendMultiPartForm() throws Exception {
HttpClient httpclient = new HttpClient();
File file = new File("src/main/resources/META-INF/NOTICE.txt");
- PostMethod httppost = new PostMethod("http://localhost:9080/test");
+ PostMethod httppost = new PostMethod("http://localhost:" + getPort() + "/test");
Part[] parts = {
new StringPart("comment", "A binary file of some kind"),
new FilePart(file.getName(), file)
@@ -81,7 +81,7 @@ public class MultiPartFormWithCustomFilt
File file = new File("src/main/resources/META-INF/NOTICE.txt");
- PostMethod httppost = new PostMethod("http://localhost:9080/test2");
+ PostMethod httppost = new PostMethod("http://localhost:" + getPort() + "/test2");
Part[] parts = {
new StringPart("comment", "A binary file of some kind"),
new FilePart(file.getName(), file)
@@ -112,7 +112,7 @@ public class MultiPartFormWithCustomFilt
// The option works rightly from Camel 2.4.0
getContext().getProperties().put("CamelJettyTempDir", "target");
- from("jetty://http://localhost:9080/test?multipartFilterRef=myMultipartFilter").process(new Processor() {
+ from("jetty://http://localhost:{{port}}/test?multipartFilterRef=myMultipartFilter").process(new Processor() {
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn();
assertEquals("Get a wrong attachement size", 1, in.getAttachments().size());
@@ -136,7 +136,7 @@ public class MultiPartFormWithCustomFilt
// END SNIPPET: e1
// Test to ensure that setting a multipartFilterRef overrides the enableMultipartFilter=false parameter
- from("jetty://http://localhost:9080/test2?multipartFilterRef=myMultipartFilter&enableMultipartFilter=false").process(new Processor() {
+ from("jetty://http://localhost:{{port}}/test2?multipartFilterRef=myMultipartFilter&enableMultipartFilter=false").process(new Processor() {
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn();
assertEquals("Get a wrong attachement size", 1, in.getAttachments().size());