Avoid using fixed TCP port numbers in unit tests.
git-svn-id: https://svn.apache.org/repos/asf/abdera/java/trunk@1452034 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/security/pom.xml b/security/pom.xml
index 86d876e..87ffe3d 100644
--- a/security/pom.xml
+++ b/security/pom.xml
@@ -74,5 +74,10 @@
<artifactId>axiom-api</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.ws.commons.axiom</groupId>
+ <artifactId>axiom-testutils</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/security/src/test/java/org/apache/abdera/test/security/filter/SecurityFilterTest.java b/security/src/test/java/org/apache/abdera/test/security/filter/SecurityFilterTest.java
index d98856e..fb11353 100644
--- a/security/src/test/java/org/apache/abdera/test/security/filter/SecurityFilterTest.java
+++ b/security/src/test/java/org/apache/abdera/test/security/filter/SecurityFilterTest.java
@@ -38,19 +38,22 @@
import org.apache.abdera.security.Signature;
import org.apache.abdera.security.SignatureOptions;
import org.apache.abdera.test.security.DigitalSignatureTest;
+import org.apache.axiom.testutils.PortAllocator;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class SecurityFilterTest {
+ private static int port;
private static JettyServer server;
private static Abdera abdera = Abdera.getInstance();
private static AbderaClient client = new AbderaClient();
@BeforeClass
public static void setUp() throws Exception {
- server = new JettyServer();
+ port = PortAllocator.allocatePort();
+ server = new JettyServer(port);
server.start(CustomProvider.class);
}
@@ -61,7 +64,7 @@
@Test
public void testSignedResponseFilter() throws Exception {
- ClientResponse resp = client.get("http://localhost:9002/");
+ ClientResponse resp = client.get("http://localhost:" + port + "/");
Document<Element> doc = resp.getDocument();
Element root = doc.getRoot();
AbderaSecurity security = new AbderaSecurity(abdera);
@@ -80,13 +83,13 @@
@Test
public void testSignedRequestFilter() throws Exception {
Entry entry = abdera.newEntry();
- entry.setId("http://localhost:9002/feed/entries/1");
+ entry.setId("http://localhost:" + port + "/feed/entries/1");
entry.setTitle("test entry");
entry.setContent("Test Content");
entry.addLink("http://example.org");
entry.setUpdated(new Date());
entry.addAuthor("James");
- ClientResponse resp = client.post("http://localhost:9002/feed", entry);
+ ClientResponse resp = client.post("http://localhost:" + port + "/feed", entry);
assertNotNull(resp);
assertEquals(ResponseType.CLIENT_ERROR, resp.getType());
@@ -112,7 +115,7 @@
// Sign the entry
entry = sig.sign(entry, options);
- resp = client.post("http://localhost:9002/feed", entry);
+ resp = client.post("http://localhost:" + port + "/feed", entry);
assertNotNull(resp);
assertEquals(ResponseType.SUCCESS, resp.getType());
}