You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2017/02/01 15:31:37 UTC

[3/3] cxf git commit: Get WS-Transfer system tests running on random ports

Get WS-Transfer system tests running on random ports


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/ef13d2b2
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/ef13d2b2
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/ef13d2b2

Branch: refs/heads/master
Commit: ef13d2b2f8f7b67b7351030a3a097377435371c5
Parents: 3450d38
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Wed Feb 1 15:25:41 2017 +0000
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Wed Feb 1 15:30:44 2017 +0000

----------------------------------------------------------------------
 systests/ws-transfer/pom.xml                    |  6 +++
 .../systest/ws/transfer/CreateStudentTest.java  | 21 ++++++----
 .../systest/ws/transfer/CreateTeacherTest.java  | 20 ++++++----
 .../cxf/systest/ws/transfer/DeleteTest.java     | 12 ++++--
 .../apache/cxf/systest/ws/transfer/GetTest.java | 10 +++--
 .../apache/cxf/systest/ws/transfer/PutTest.java | 12 ++++--
 .../cxf/systest/ws/transfer/TestUtils.java      | 42 +++++++++-----------
 7 files changed, 74 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/ef13d2b2/systests/ws-transfer/pom.xml
----------------------------------------------------------------------
diff --git a/systests/ws-transfer/pom.xml b/systests/ws-transfer/pom.xml
index f032f51..93a0e7b 100644
--- a/systests/ws-transfer/pom.xml
+++ b/systests/ws-transfer/pom.xml
@@ -56,6 +56,12 @@
           <version>${project.version}</version>
           <scope>test</scope>
         </dependency>
+        <dependency>
+          <groupId>org.apache.cxf</groupId>
+          <artifactId>cxf-testutils</artifactId>
+          <version>${project.version}</version>
+          <scope>test</scope>
+        </dependency>
     </dependencies>
     
 </project>

http://git-wip-us.apache.org/repos/asf/cxf/blob/ef13d2b2/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/CreateStudentTest.java
----------------------------------------------------------------------
diff --git a/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/CreateStudentTest.java b/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/CreateStudentTest.java
index 2f9feaa..36bacf8 100644
--- a/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/CreateStudentTest.java
+++ b/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/CreateStudentTest.java
@@ -23,6 +23,7 @@ import javax.xml.stream.XMLStreamException;
 import javax.xml.ws.soap.SOAPFaultException;
 import org.w3c.dom.Document;
 import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.testutil.common.TestUtil;
 import org.apache.cxf.ws.transfer.Create;
 import org.apache.cxf.ws.transfer.CreateResponse;
 import org.apache.cxf.ws.transfer.Representation;
@@ -34,11 +35,15 @@ import org.junit.Test;
 
 public class CreateStudentTest {
     
+    static final String PORT = TestUtil.getPortNumber(CreateStudentTest.class);
+    static final String PORT2 = TestUtil.getPortNumber(CreateStudentTest.class, 2);
+    
+    static final String RESOURCE_STUDENTS_URL = "http://localhost:" + PORT + "/ResourceStudents";
     
     @BeforeClass
     public static void beforeClass() {
-        TestUtils.createStudentsServers();
-        TestUtils.createTeachersServers();
+        TestUtils.createStudentsServers(PORT, PORT2);
+        TestUtils.createTeachersServers(PORT2);
     }
     
     @AfterClass
@@ -55,10 +60,10 @@ public class CreateStudentTest {
         request.setRepresentation(new Representation());
         request.getRepresentation().setAny(createStudentXML.getDocumentElement());
         
-        ResourceFactory rf = TestUtils.createResourceFactoryClient();
+        ResourceFactory rf = TestUtils.createResourceFactoryClient(PORT);
         CreateResponse response = rf.create(request);
         
-        Assert.assertEquals(TestUtils.RESOURCE_STUDENTS_URL,
+        Assert.assertEquals(RESOURCE_STUDENTS_URL,
             response.getResourceCreated().getAddress().getValue());
     }
 
@@ -70,10 +75,10 @@ public class CreateStudentTest {
         request.setRepresentation(new Representation());
         request.getRepresentation().setAny(createStudentPartialXML.getDocumentElement());
         
-        ResourceFactory rf = TestUtils.createResourceFactoryClient();
+        ResourceFactory rf = TestUtils.createResourceFactoryClient(PORT);
         CreateResponse response = rf.create(request);
         
-        Assert.assertEquals(TestUtils.RESOURCE_STUDENTS_URL,
+        Assert.assertEquals(RESOURCE_STUDENTS_URL,
             response.getResourceCreated().getAddress().getValue());
     }
     
@@ -85,7 +90,7 @@ public class CreateStudentTest {
         request.setRepresentation(new Representation());
         request.getRepresentation().setAny(createStudentWrongXML.getDocumentElement());
         
-        ResourceFactory rf = TestUtils.createResourceFactoryClient();
+        ResourceFactory rf = TestUtils.createResourceFactoryClient(PORT);
         rf.create(request);
     }
     
@@ -97,7 +102,7 @@ public class CreateStudentTest {
         request.setRepresentation(new Representation());
         request.getRepresentation().setAny(randomXML.getDocumentElement());
         
-        ResourceFactory rf = TestUtils.createResourceFactoryClient();
+        ResourceFactory rf = TestUtils.createResourceFactoryClient(PORT);
         rf.create(request);
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/ef13d2b2/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/CreateTeacherTest.java
----------------------------------------------------------------------
diff --git a/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/CreateTeacherTest.java b/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/CreateTeacherTest.java
index 9a67b9a..02e4296 100644
--- a/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/CreateTeacherTest.java
+++ b/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/CreateTeacherTest.java
@@ -23,6 +23,7 @@ import javax.xml.stream.XMLStreamException;
 import javax.xml.ws.soap.SOAPFaultException;
 import org.w3c.dom.Document;
 import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.testutil.common.TestUtil;
 import org.apache.cxf.ws.transfer.Create;
 import org.apache.cxf.ws.transfer.CreateResponse;
 import org.apache.cxf.ws.transfer.Representation;
@@ -34,10 +35,15 @@ import org.junit.Test;
 
 public class CreateTeacherTest {
     
+    static final String PORT = TestUtil.getPortNumber(CreateStudentTest.class);
+    static final String PORT2 = TestUtil.getPortNumber(CreateStudentTest.class, 2);
+    
+    static final String RESOURCE_TEACHERS_URL = "http://localhost:" + PORT2 + "/ResourceTeachers";
+    
     @BeforeClass
     public static void beforeClass() {
-        TestUtils.createStudentsServers();
-        TestUtils.createTeachersServers();
+        TestUtils.createStudentsServers(PORT, PORT2);
+        TestUtils.createTeachersServers(PORT2);
     }
     
     @AfterClass
@@ -54,10 +60,10 @@ public class CreateTeacherTest {
         request.setRepresentation(new Representation());
         request.getRepresentation().setAny(createTeacherXML.getDocumentElement());
         
-        ResourceFactory rf = TestUtils.createResourceFactoryClient();
+        ResourceFactory rf = TestUtils.createResourceFactoryClient(PORT);
         CreateResponse response = rf.create(request);
         
-        Assert.assertEquals(TestUtils.RESOURCE_TEACHERS_URL,
+        Assert.assertEquals(RESOURCE_TEACHERS_URL,
             response.getResourceCreated().getAddress().getValue());
     }
 
@@ -69,10 +75,10 @@ public class CreateTeacherTest {
         request.setRepresentation(new Representation());
         request.getRepresentation().setAny(createTeacherPartialXML.getDocumentElement());
         
-        ResourceFactory rf = TestUtils.createResourceFactoryClient();
+        ResourceFactory rf = TestUtils.createResourceFactoryClient(PORT);
         CreateResponse response = rf.create(request);
         
-        Assert.assertEquals(TestUtils.RESOURCE_TEACHERS_URL,
+        Assert.assertEquals(RESOURCE_TEACHERS_URL,
             response.getResourceCreated().getAddress().getValue());
     }
     
@@ -84,7 +90,7 @@ public class CreateTeacherTest {
         request.setRepresentation(new Representation());
         request.getRepresentation().setAny(createTeacherWrongXML.getDocumentElement());
         
-        ResourceFactory rf = TestUtils.createResourceFactoryClient();
+        ResourceFactory rf = TestUtils.createResourceFactoryClient(PORT);
         rf.create(request);
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/ef13d2b2/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/DeleteTest.java
----------------------------------------------------------------------
diff --git a/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/DeleteTest.java b/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/DeleteTest.java
index b25a944..57fcbd1 100644
--- a/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/DeleteTest.java
+++ b/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/DeleteTest.java
@@ -23,6 +23,7 @@ import javax.xml.stream.XMLStreamException;
 import javax.xml.ws.soap.SOAPFaultException;
 import org.w3c.dom.Document;
 import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.testutil.common.TestUtil;
 import org.apache.cxf.ws.transfer.Create;
 import org.apache.cxf.ws.transfer.CreateResponse;
 import org.apache.cxf.ws.transfer.Delete;
@@ -36,10 +37,13 @@ import org.junit.Test;
 
 public class DeleteTest {
     
+    static final String PORT = TestUtil.getPortNumber(CreateStudentTest.class);
+    static final String PORT2 = TestUtil.getPortNumber(CreateStudentTest.class, 2);
+    
     @Before
     public void before() {
-        TestUtils.createStudentsServers();
-        TestUtils.createTeachersServers();
+        TestUtils.createStudentsServers(PORT, PORT2);
+        TestUtils.createTeachersServers(PORT2);
     }
     
     @After
@@ -101,7 +105,7 @@ public class DeleteTest {
         request.setRepresentation(new Representation());
         request.getRepresentation().setAny(createStudentXML.getDocumentElement());
         
-        ResourceFactory rf = TestUtils.createResourceFactoryClient();
+        ResourceFactory rf = TestUtils.createResourceFactoryClient(PORT);
         return rf.create(request);
     }
     
@@ -112,7 +116,7 @@ public class DeleteTest {
         request.setRepresentation(new Representation());
         request.getRepresentation().setAny(createTeacherXML.getDocumentElement());
         
-        ResourceFactory rf = TestUtils.createResourceFactoryClient();
+        ResourceFactory rf = TestUtils.createResourceFactoryClient(PORT);
         return rf.create(request);
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/ef13d2b2/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/GetTest.java
----------------------------------------------------------------------
diff --git a/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/GetTest.java b/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/GetTest.java
index 65fdce7..5e10099 100644
--- a/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/GetTest.java
+++ b/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/GetTest.java
@@ -24,6 +24,7 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
 import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.testutil.common.TestUtil;
 import org.apache.cxf.ws.addressing.EndpointReferenceType;
 import org.apache.cxf.ws.transfer.Create;
 import org.apache.cxf.ws.transfer.Get;
@@ -38,16 +39,19 @@ import org.junit.Test;
 
 public class GetTest {
     
+    static final String PORT = TestUtil.getPortNumber(CreateStudentTest.class);
+    static final String PORT2 = TestUtil.getPortNumber(CreateStudentTest.class, 2);
+    
     private static EndpointReferenceType studentRef;
     
     private static EndpointReferenceType teacherRef;
     
     @BeforeClass
     public static void beforeClass() throws XMLStreamException {
-        TestUtils.createStudentsServers();
-        TestUtils.createTeachersServers();
+        TestUtils.createStudentsServers(PORT, PORT2);
+        TestUtils.createTeachersServers(PORT2);
 
-        ResourceFactory rf = TestUtils.createResourceFactoryClient();
+        ResourceFactory rf = TestUtils.createResourceFactoryClient(PORT);
         
         Document createStudentXML = StaxUtils.read(
                 GetTest.class.getResourceAsStream("/xml/createStudent.xml"));

http://git-wip-us.apache.org/repos/asf/cxf/blob/ef13d2b2/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/PutTest.java
----------------------------------------------------------------------
diff --git a/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/PutTest.java b/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/PutTest.java
index ec906b6..2195e93 100644
--- a/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/PutTest.java
+++ b/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/PutTest.java
@@ -23,6 +23,7 @@ import javax.xml.stream.XMLStreamException;
 import javax.xml.ws.soap.SOAPFaultException;
 import org.w3c.dom.Document;
 import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.testutil.common.TestUtil;
 import org.apache.cxf.ws.transfer.Create;
 import org.apache.cxf.ws.transfer.CreateResponse;
 import org.apache.cxf.ws.transfer.Put;
@@ -35,10 +36,13 @@ import org.junit.Test;
 
 public class PutTest {
     
+    static final String PORT = TestUtil.getPortNumber(CreateStudentTest.class);
+    static final String PORT2 = TestUtil.getPortNumber(CreateStudentTest.class, 2);
+    
     @Before
     public void before() {
-        TestUtils.createStudentsServers();
-        TestUtils.createTeachersServers();
+        TestUtils.createStudentsServers(PORT, PORT2);
+        TestUtils.createTeachersServers(PORT2);
     }
     
     @After
@@ -112,7 +116,7 @@ public class PutTest {
         request.setRepresentation(new Representation());
         request.getRepresentation().setAny(createStudentXML.getDocumentElement());
         
-        ResourceFactory rf = TestUtils.createResourceFactoryClient();
+        ResourceFactory rf = TestUtils.createResourceFactoryClient(PORT);
         return rf.create(request);
     }
     
@@ -123,7 +127,7 @@ public class PutTest {
         request.setRepresentation(new Representation());
         request.getRepresentation().setAny(createTeacherXML.getDocumentElement());
         
-        ResourceFactory rf = TestUtils.createResourceFactoryClient();
+        ResourceFactory rf = TestUtils.createResourceFactoryClient(PORT);
         return rf.create(request);
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/ef13d2b2/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/TestUtils.java
----------------------------------------------------------------------
diff --git a/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/TestUtils.java b/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/TestUtils.java
index 90645d3..e194d99 100644
--- a/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/TestUtils.java
+++ b/systests/ws-transfer/src/test/java/org/apache/cxf/systest/ws/transfer/TestUtils.java
@@ -47,12 +47,6 @@ import org.apache.cxf.ws.transfer.validationtransformation.XSLTResourceTransform
  */
 public final class TestUtils {
     
-    public static final String RESOURCE_STUDENTS_URL = "http://localhost:8080/ResourceStudents";
-    
-    public static final String RESOURCE_FACTORY_URL = "http://localhost:8080/ResourceFactory";
-    
-    public static final String RESOURCE_TEACHERS_URL = "http://localhost:8081/ResourceTeachers";
-    
     private static Server resourceFactoryServer;
     
     private static Server studentsResourceServer;
@@ -65,10 +59,10 @@ public final class TestUtils {
         
     }
     
-    protected static ResourceFactory createResourceFactoryClient() {
+    protected static ResourceFactory createResourceFactoryClient(String port) {
         JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
         factory.setServiceClass(org.apache.cxf.ws.transfer.resourcefactory.ResourceFactory.class);
-        factory.setAddress(RESOURCE_FACTORY_URL);
+        factory.setAddress("http://localhost:" + port + "/ResourceFactory");
         return (ResourceFactory) factory.create();
     }
     
@@ -86,14 +80,14 @@ public final class TestUtils {
         return proxy;
     }
     
-    protected static void createStudentsServers() {
+    protected static void createStudentsServers(String port, String port2) {
         UIDManager.reset();
         ResourceManager studentsResourceManager = new MemoryResourceManager();
-        resourceFactoryServer = createResourceFactory(studentsResourceManager);
-        studentsResourceServer = createStudentsResource(studentsResourceManager);
+        resourceFactoryServer = createResourceFactory(studentsResourceManager, port, port2);
+        studentsResourceServer = createStudentsResource(studentsResourceManager, port);
     }
     
-    protected static void createTeachersServers() {
+    protected static void createTeachersServers(String port) {
         ResourceManager teachersResourceManager = new MemoryResourceManager();
         ResourceRemote resource = new ResourceRemote();
         resource.setManager(teachersResourceManager);
@@ -102,8 +96,8 @@ public final class TestUtils {
                 new XSLTResourceTransformer(
                         new StreamSource(TestUtils.class.getResourceAsStream("/xslt/teacherDefaultValues.xsl")),
                         new TeacherResourceValidator())));
-        teachersResourceFactoryServer = createTeachersResourceFactoryEndpoint(resource);
-        teachersResourceServer = createTeacherResourceEndpoint(resource);
+        teachersResourceFactoryServer = createTeachersResourceFactoryEndpoint(resource, port);
+        teachersResourceServer = createTeacherResourceEndpoint(resource, port);
     }
     
     protected static void destroyStudentsServers() {
@@ -116,10 +110,12 @@ public final class TestUtils {
         teachersResourceServer.destroy();
     }
     
-    private static Server createResourceFactory(ResourceManager resourceManager) {
+    private static Server createResourceFactory(ResourceManager resourceManager, String port, String port2) {
         ResourceFactoryImpl resourceFactory = new ResourceFactoryImpl();
         resourceFactory.setResourceResolver(
-                new MyResourceResolver(RESOURCE_STUDENTS_URL, resourceManager, RESOURCE_TEACHERS_URL));
+                new MyResourceResolver("http://localhost:" + port + "/ResourceStudents", 
+                                       resourceManager, 
+                                       "http://localhost:" + port2 + "/ResourceTeachers"));
         resourceFactory.getResourceTypeIdentifiers().add(
                 new XSDResourceTypeIdentifier(
                         new StreamSource(TestUtils.class.getResourceAsStream("/schema/studentCreate.xsd")),
@@ -134,12 +130,12 @@ public final class TestUtils {
         JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
         factory.setServiceClass(org.apache.cxf.ws.transfer.resourcefactory.ResourceFactory.class);
         factory.setServiceBean(resourceFactory);
-        factory.setAddress(RESOURCE_FACTORY_URL);
+        factory.setAddress("http://localhost:" + port + "/ResourceFactory");
         
         return factory.create();
     }
     
-    private static Server createStudentsResource(ResourceManager resourceManager) {
+    private static Server createStudentsResource(ResourceManager resourceManager, String port) {
         ResourceLocal resourceLocal = new ResourceLocal();
         resourceLocal.setManager(resourceManager);
         resourceLocal.getResourceTypeIdentifiers().add(
@@ -151,23 +147,23 @@ public final class TestUtils {
         JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
         factory.setServiceClass(Resource.class);
         factory.setServiceBean(resourceLocal);
-        factory.setAddress(RESOURCE_STUDENTS_URL);
+        factory.setAddress("http://localhost:" + port + "/ResourceStudents");
         return factory.create();
     }
     
-    private static Server createTeachersResourceFactoryEndpoint(ResourceRemote resource) {
+    private static Server createTeachersResourceFactoryEndpoint(ResourceRemote resource, String port) {
         JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
         factory.setServiceClass(ResourceFactory.class);
         factory.setServiceBean(resource);
-        factory.setAddress(RESOURCE_TEACHERS_URL + TransferConstants.RESOURCE_REMOTE_SUFFIX);
+        factory.setAddress("http://localhost:" + port + "/ResourceTeachers" + TransferConstants.RESOURCE_REMOTE_SUFFIX);
         return factory.create();
     }
     
-    private static Server createTeacherResourceEndpoint(ResourceRemote resource) {
+    private static Server createTeacherResourceEndpoint(ResourceRemote resource, String port) {
         JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
         factory.setServiceClass(Resource.class);
         factory.setServiceBean(resource);
-        factory.setAddress(RESOURCE_TEACHERS_URL);
+        factory.setAddress("http://localhost:" + port + "/ResourceTeachers");
         return factory.create();
     }