hello there,

the JUnit tests (in org.restlet.test) have hard-wired port numbers which may 
not suit every developer's environment.  this patch introduces a new 
property in the main build.xml, and injects at as a system environment 
variable.

when more than one port is required, the property value is used as a base; 
i.e. second port number is valueOf(property) + 1, etc. 

the only test i was not able to parametrize was the Spring test (and its 
.xml file).


cheers;
rsn
### Eclipse Workspace Patch 1.0
#P org.restlet.test
Index: src/org/restlet/test/TemplateFilterTestCase.java
===================================================================
--- src/org/restlet/test/TemplateFilterTestCase.java    (revision 4104)
+++ src/org/restlet/test/TemplateFilterTestCase.java    (working copy)
@@ -198,7 +198,7 @@
 
             // Create a new component
             final Component component = new Component();
-            component.getServers().add(Protocol.HTTP, 8182);
+            component.getServers().add(Protocol.HTTP, RestletTestSuite.PORT);
             component.getClients().add(Protocol.FILE);
 
             // Create an application filtered with Freemarker
@@ -220,28 +220,28 @@
             freemarkerApplication.getTunnelService().setExtensionsTunnel(true);
             velocityApplication.getTunnelService().setExtensionsTunnel(true);
             final Client client = new Client(Protocol.HTTP);
-            Response response = client.get("http://localhost:8182/freemarker/";
-                    + testFileFm1.getName());
+            Response response = client.get("http://localhost:";
+                    + RestletTestSuite.PORT +"/freemarker/" + 
testFileFm1.getName());
             if (response.isEntityAvailable()) {
                 assertEquals(response.getEntity().getText(),
-                        "Method=GET/Authority=localhost:8182");
+                        "Method=GET/Authority=localhost:" + 
RestletTestSuite.PORT);
             }
-            response = client.get("http://localhost:8182/freemarker/";
-                    + testFileFm2.getName());
+            response = client.get("http://localhost:"; + RestletTestSuite.PORT
+                    + "/freemarker/" + testFileFm2.getName());
             assertTrue(response.getStatus().isSuccess());
             if (response.isEntityAvailable()) {
                 assertEquals(response.getEntity().getText(),
                         "Method=${m}/Authority=${ra}");
             }
 
-            response = client.get("http://localhost:8182/velocity/";
-                    + testFileVl1.getName());
+            response = client.get("http://localhost:"; + RestletTestSuite.PORT
+                    + "/velocity/" + testFileVl1.getName());
             if (response.isEntityAvailable()) {
                 assertEquals(response.getEntity().getText(),
                         "Method=GET/Path=/velocity/testVl1");
             }
-            response = client.get("http://localhost:8182/velocity/";
-                    + testFileVl2.getName());
+            response = client.get("http://localhost:"; + RestletTestSuite.PORT
+                    + "/velocity/" + testFileVl2.getName());
             assertTrue(response.getStatus().isSuccess());
             if (response.isEntityAvailable()) {
                 assertEquals(response.getEntity().getText(),
Index: src/org/restlet/test/HeaderTestCase.java
===================================================================
--- src/org/restlet/test/HeaderTestCase.java    (revision 4104)
+++ src/org/restlet/test/HeaderTestCase.java    (working copy)
@@ -65,8 +65,6 @@
 
     private static final String HTTP_HEADERS = "org.restlet.http.headers";
 
-    private static final int PORT = 8182;
-
     /**
      * Name of a test header field
      */
@@ -101,20 +99,21 @@
     private Response getWithParams(Parameter... parameters) {
         final Client client = new Client(Protocol.HTTP);
         final Request request = new Request(Method.GET, "http://localhost:";
-                + PORT);
+                + RestletTestSuite.PORT);
         final Form headers = getHttpHeaders(request);
         for (final Parameter p : parameters) {
             headers.add(p);
         }
 
-        return client.handle(request);
+        Response result = client.handle(request);
+        return result;
     }
 
     @Override
     public void setUp() throws Exception {
         if (this.component == null) {
             this.component = new Component();
-            this.component.getServers().add(Protocol.HTTP, PORT);
+            this.component.getServers().add(Protocol.HTTP, 
RestletTestSuite.PORT);
             this.component.getDefaultHost().attachDefault(
                     new TestHeaderRestlet());
         }
Index: src/org/restlet/test/SpringTestCase.xml
===================================================================
--- src/org/restlet/test/SpringTestCase.xml     (revision 4104)
+++ src/org/restlet/test/SpringTestCase.xml     (working copy)
@@ -18,7 +18,7 @@
    </bean>
    <bean id="server" class="org.restlet.ext.spring.SpringServer">
       <constructor-arg value="http" />
-      <constructor-arg value="8182" />
+      <constructor-arg value="30000" /><!-- FIXME - should be parameterized -->
       <property name="parameters">
          <props>
             <prop key="key1">value1</prop>
Index: src/org/restlet/test/RestletTestSuite.java
===================================================================
--- src/org/restlet/test/RestletTestSuite.java  (revision 4104)
+++ src/org/restlet/test/RestletTestSuite.java  (working copy)
@@ -40,6 +40,9 @@
  * @author Jerome Louvel
  */
 public class RestletTestSuite extends TestSuite {
+    public static final int PORT =
+            Integer.getInteger("org.restlet.test.port", 10080);
+
     /**
      * JUnit constructor.
      * 
Index: src/org/restlet/test/DigestTestCase.java
===================================================================
--- src/org/restlet/test/DigestTestCase.java    (revision 4104)
+++ src/org/restlet/test/DigestTestCase.java    (working copy)
@@ -85,7 +85,7 @@
     @Override
     protected void setUp() throws Exception {
         component = new Component();
-        component.getServers().add(Protocol.HTTP, 8182);
+        component.getServers().add(Protocol.HTTP, RestletTestSuite.PORT);
         component.getDefaultHost().attach(new TestDigestApplication());
         component.start();
     }
@@ -105,7 +105,8 @@
     public void testGet() throws IOException, NoSuchAlgorithmException {
         Client client = new Client(Protocol.HTTP);
         // Test partial Get.
-        Request request = new Request(Method.PUT, "http://localhost:8182/";);
+        Request request = new Request(Method.PUT, "http://localhost:";
+                + RestletTestSuite.PORT + "/");
         StringRepresentation rep = new StringRepresentation("0123456789");
         rep.setDigest(rep.computeDigest(Digest.ALGORITHM_MD5));
         request.setEntity(rep);
Index: src/org/restlet/test/RestartTestCase.java
===================================================================
--- src/org/restlet/test/RestartTestCase.java   (revision 4104)
+++ src/org/restlet/test/RestartTestCase.java   (working copy)
@@ -42,7 +42,8 @@
     public void testRestart() throws Exception {
         final int waitTime = 100;
 
-        final Server connector = new Server(Protocol.HTTP, 8182, null);
+        final Server connector =
+                new Server(Protocol.HTTP, RestletTestSuite.PORT, null);
 
         System.out.print("Starting connector... ");
         connector.start();
Index: src/org/restlet/test/RedirectTestCase.java
===================================================================
--- src/org/restlet/test/RedirectTestCase.java  (revision 4104)
+++ src/org/restlet/test/RedirectTestCase.java  (working copy)
@@ -94,7 +94,7 @@
         originComponent.getDefaultHost().attach("", trace);
 
         // Create the server connectors
-        proxyComponent.getServers().add(Protocol.HTTP, 8182);
+        proxyComponent.getServers().add(Protocol.HTTP, RestletTestSuite.PORT);
         originComponent.getServers().add(Protocol.HTTP, 9090);
 
         // Now, let's start the components!
@@ -104,15 +104,18 @@
 
         // Tests
         final Context context = clientComponent.getContext();
-        String uri = "http://localhost:8182/?foo=bar";;
+        String uri = "http://localhost:"; + RestletTestSuite.PORT + "/?foo=bar";
         testCall(context, Method.GET, uri);
         testCall(context, Method.DELETE, uri);
 
-        uri = "http://localhost:8182/abcd/efgh/ijkl?foo=bar&foo=beer";;
+        uri = "http://localhost:"; + RestletTestSuite.PORT
+                + "/abcd/efgh/ijkl?foo=bar&foo=beer";
         testCall(context, Method.GET, uri);
         testCall(context, Method.DELETE, uri);
 
-        uri = 
"http://localhost:8182/v1/client/kwse/CnJlNUQV9%252BNNqbUf7Lhs2BYEK2Y%253D/user/johnm/uVGYTDK4kK4zsu96VHGeTCzfwso%253D/";;
+        uri = "http://localhost:"; + RestletTestSuite.PORT
+                + "/v1/client/kwse/CnJlNUQV9%252BNNqbUf7Lhs2BYEK2Y%253D"
+                + "/user/johnm/uVGYTDK4kK4zsu96VHGeTCzfwso%253D/";
         testCall(context, Method.GET, uri);
 
         // Stop the components
Index: src/org/restlet/test/engine/UserAgentTunnelFilterTestCase.java
===================================================================
--- src/org/restlet/test/engine/UserAgentTunnelFilterTestCase.java      
(revision 4104)
+++ src/org/restlet/test/engine/UserAgentTunnelFilterTestCase.java      
(working copy)
@@ -38,6 +38,7 @@
 import org.restlet.data.Request;
 import org.restlet.data.Response;
 import org.restlet.data.Status;
+import org.restlet.test.RestletTestSuite;
 
 /**
  * Tests cases for the tunneling of preferences based on user agent.
@@ -45,7 +46,8 @@
 public class UserAgentTunnelFilterTestCase extends TestCase {
 
     /** . */
-    private static final String URL = "http://localhost:8182/test";;
+    private static final String URL = "http://localhost:";
+        + RestletTestSuite.PORT +"/test";
 
     private Application application;
 
Index: src/org/restlet/test/RangeTestCase.java
===================================================================
--- src/org/restlet/test/RangeTestCase.java     (revision 4104)
+++ src/org/restlet/test/RangeTestCase.java     (working copy)
@@ -178,7 +178,7 @@
     @Override
     protected void setUp() throws Exception {
         component = new Component();
-        component.getServers().add(Protocol.HTTP, 8182);
+        component.getServers().add(Protocol.HTTP, RestletTestSuite.PORT);
         component.getClients().add(Protocol.FILE);
         component.getDefaultHost().attach(new TestRangeApplication());
         component.start();
@@ -199,13 +199,14 @@
         Client client = new Client(Protocol.HTTP);
         // Test partial Get.
         Request request = new Request(Method.GET,
-                "http://localhost:8182/testGet";);
+                "http://localhost:"; + RestletTestSuite.PORT + "/testGet");
         Response response = client.handle(request);
         assertEquals(Status.SUCCESS_OK, response.getStatus());
         assertEquals("1234567890", response.getEntity().getText());
         assertEquals(10, response.getEntity().getSize());
 
-        request = new Request(Method.GET, "http://localhost:8182/testGet";);
+        request = new Request(Method.GET, "http://localhost:";
+                + RestletTestSuite.PORT +"/testGet");
         request.setRanges(Arrays.asList(new Range(0, 10)));
         response = client.handle(request);
         assertEquals(Status.SUCCESS_PARTIAL_CONTENT, response.getStatus());
@@ -268,7 +269,7 @@
 
         // PUT on a file that does not exist
         Request request = new Request(Method.PUT,
-                "http://localhost:8182/testPut/essai.txt";);
+                "http://localhost:"; + RestletTestSuite.PORT 
+"/testPut/essai.txt");
         request.setEntity(new StringRepresentation("1234567890"));
         request.setRanges(Arrays.asList(new Range(0, 10)));
         Response response = client.handle(request);
@@ -280,7 +281,7 @@
         // Partial PUT on a file, the provided representation overflowed the
         // existing file
         request = new Request(Method.PUT,
-                "http://localhost:8182/testPut/essai.txt";);
+                "http://localhost:"; + RestletTestSuite.PORT 
+"/testPut/essai.txt");
         request.setEntity(new StringRepresentation("0000000000"));
         request.setRanges(Arrays.asList(new Range(1, 10)));
         response = client.handle(request);
@@ -292,7 +293,7 @@
         // Partial PUT on a file that does not exists, the provided range
         // does not start at the 0 index.
         request = new Request(Method.PUT,
-                "http://localhost:8182/testPut/essai2.txt";);
+                "http://localhost:"; + RestletTestSuite.PORT+ 
"/testPut/essai2.txt");
         request.setEntity(new StringRepresentation("0000000000"));
         request.setRanges(Arrays.asList(new Range(1, 10)));
         response = client.handle(request);
@@ -304,7 +305,7 @@
 
         // Partial PUT on a file, simple range
         request = new Request(Method.PUT,
-                "http://localhost:8182/testPut/essai.txt";);
+                "http://localhost:"; + RestletTestSuite.PORT + 
"/testPut/essai.txt");
         request.setEntity(new StringRepresentation("22"));
         request.setRanges(Arrays.asList(new Range(2, 2)));
         response = client.handle(request);
@@ -316,7 +317,7 @@
         // Partial PUT on a file, the provided representation will be padded
         // at the very end of the file.
         request = new Request(Method.PUT,
-                "http://localhost:8182/testPut/essai.txt";);
+                "http://localhost:"; + RestletTestSuite.PORT + 
"/testPut/essai.txt");
         request.setEntity(new StringRepresentation("888"));
         request.setRanges(Arrays.asList(new Range(8, Range.SIZE_MAX)));
         response = client.handle(request);
@@ -328,7 +329,7 @@
         // Partial PUT on a file that does not exist, the range does not
         // specify the range size.
         request = new Request(Method.PUT,
-                "http://localhost:8182/testPut/essai3.txt";);
+                "http://localhost:"; + RestletTestSuite.PORT + 
"/testPut/essai3.txt");
         request.setEntity(new StringRepresentation("888"));
         request.setRanges(Arrays.asList(new Range(8, Range.SIZE_MAX)));
         response = client.handle(request);
@@ -341,7 +342,7 @@
         // Partial PUT on a file, the provided representation will be padded
         // just before the end of the file.
         request = new Request(Method.PUT,
-                "http://localhost:8182/testPut/essai.txt";);
+                "http://localhost:"; + RestletTestSuite.PORT + 
"/testPut/essai.txt");
         request.setEntity(new StringRepresentation("99"));
         request.setRanges(Arrays.asList(new Range(8, Range.SIZE_MAX)));
         response = client.handle(request);
@@ -351,7 +352,7 @@
         assertEquals("10220000998", response.getEntity().getText());
 
         request = new Request(Method.GET,
-                "http://localhost:8182/testPut/essai.txt";);
+                "http://localhost:"; + RestletTestSuite.PORT + 
"/testPut/essai.txt");
         request.setRanges(Arrays.asList(new Range(3, Range.SIZE_MAX)));
         response = client.handle(request);
         assertEquals(Status.SUCCESS_PARTIAL_CONTENT, response.getStatus());
@@ -370,27 +371,27 @@
 
         // Test "range" header.
         Request request = new Request(Method.GET,
-                "http://localhost:8182/test?range=0-500";);
+                "http://localhost:"; + RestletTestSuite.PORT + 
"/test?range=0-500");
         request.setRanges(Arrays.asList(new Range(0, 500)));
         assertEquals(Status.SUCCESS_OK, client.handle(request).getStatus());
 
         request = new Request(Method.GET,
-                "http://localhost:8182/test?range=-500";);
+                "http://localhost:"; + RestletTestSuite.PORT + 
"/test?range=-500");
         request.setRanges(Arrays.asList(new Range(Range.INDEX_LAST, 500)));
         assertEquals(Status.SUCCESS_OK, client.handle(request).getStatus());
 
         request = new Request(Method.GET,
-                "http://localhost:8182/test?range=500-";);
+                "http://localhost:"; + RestletTestSuite.PORT + 
"/test?range=500-");
         request.setRanges(Arrays.asList(new Range(500, Range.SIZE_MAX)));
         assertEquals(Status.SUCCESS_OK, client.handle(request).getStatus());
 
         request = new Request(Method.GET,
-                "http://localhost:8182/test?range=500-1000";);
+                "http://localhost:"; + RestletTestSuite.PORT + 
"/test?range=500-1000");
         request.setRanges(Arrays.asList(new Range(500, 500)));
         assertEquals(Status.SUCCESS_OK, client.handle(request).getStatus());
 
         request = new Request(Method.GET,
-                "http://localhost:8182/test?range=500-1000&range=500-";);
+                "http://localhost:"; + RestletTestSuite.PORT + 
"/test?range=500-1000&range=500-");
         request.setRanges(Arrays.asList(new Range(500, 500), new Range(500,
                 Range.SIZE_MAX)));
         assertEquals(Status.SUCCESS_OK, client.handle(request).getStatus());
Index: src/org/restlet/test/ComponentXmlTestCase.java
===================================================================
--- src/org/restlet/test/ComponentXmlTestCase.java      (revision 4104)
+++ src/org/restlet/test/ComponentXmlTestCase.java      (working copy)
@@ -42,9 +42,9 @@
  */
 public class ComponentXmlTestCase extends TestCase {
 
-    private final int port = 8182;
+    private final int port = RestletTestSuite.PORT;
 
-    private final int port2 = 8183;
+    private final int port2 = port + 1;
 
     public void testComponentXMLConfig() throws Exception {
         final StringBuilder builder = new StringBuilder();
#P restlet.build
Index: build.xml
===================================================================
--- build.xml   (revision 4104)
+++ build.xml   (working copy)
@@ -82,6 +82,7 @@
        </tstamp>
 
        <!-- Svn revision number -->
+       <mkdir dir="temp" />
        <exec executable="svn" output="${temp}/svninfo.xml">
                <arg line="info --xml" />
        </exec>
@@ -1618,6 +1619,7 @@
                       haltonfailure="true"
                       filtertrace="true"
                       showoutput="${verbose}">
+                       <sysproperty key="org.restlet.test.port" 
value="${port-number}" />
                        <classpath>
                                <path location="${mod}/${mod-core-test-id}/src" 
/>
                                <path refid="mod-core-test-path" />
Index: build.properties
===================================================================
--- build.properties    (revision 4104)
+++ build.properties    (working copy)
@@ -58,7 +58,8 @@
 
 # Indicates if the NSIS tool should be run over the
 # distribution files
-nsis: true
+#nsis: true
+nsis: false
 nsis-makensis-path: /usr/bin
 
 # Verbose flag currently used during Java compilation 
@@ -73,3 +74,6 @@
 
 # Indicates if the final packaging phase should be done.
 package: true
+
+# Port number to use for JUnit tests
+port-number: 30000

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to