You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2026/05/18 08:05:25 UTC

(ws-axiom) branch master updated: Refactor ScenarioTestCase: replace setUp/tearDown with runTest + abstract runScenario(ApplicationContext)

This is an automated email from the ASF dual-hosted git repository.

veithen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ws-axiom.git


The following commit(s) were added to refs/heads/master by this push:
     new 7907f25b0 Refactor ScenarioTestCase: replace setUp/tearDown with runTest + abstract runScenario(ApplicationContext)
7907f25b0 is described below

commit 7907f25b0a7b51d96820a2e03783ac59e1469191
Author: Copilot <19...@users.noreply.github.com>
AuthorDate: Mon May 18 09:04:45 2026 +0100

    Refactor ScenarioTestCase: replace setUp/tearDown with runTest + abstract runScenario(ApplicationContext)
    
    Co-authored-by: Andreas Veithen-Knowles <an...@gmail.com>
---
 .../ts/springws/scenario/ScenarioTestCase.java     | 47 +++++++++++-----------
 .../scenario/broker/BrokerScenarioTest.java        |  3 +-
 .../ts/springws/scenario/jaxb2/JAXB2Test.java      |  3 +-
 .../springws/scenario/jdom/ClientServerTest.java   |  3 +-
 .../scenario/secureecho/SecureEchoTest.java        |  3 +-
 .../scenario/soapaction/SoapActionTest.java        |  3 +-
 .../scenario/validation/ValidationTest.java        |  3 +-
 .../scenario/wsadom/WSAddressingDOMTest.java       |  3 +-
 8 files changed, 38 insertions(+), 30 deletions(-)

diff --git a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/ScenarioTestCase.java b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/ScenarioTestCase.java
index d700a2967..08264646e 100644
--- a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/ScenarioTestCase.java
+++ b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/ScenarioTestCase.java
@@ -26,6 +26,7 @@ import org.eclipse.jetty.server.Connector;
 import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.server.ServerConnector;
 import org.eclipse.jetty.util.thread.QueuedThreadPool;
+import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextInitializer;
 import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.context.support.GenericXmlApplicationContext;
@@ -39,15 +40,12 @@ public abstract class ScenarioTestCase extends SpringWSTestCase {
     @Inject
     private ScenarioConfig config;
 
-    private Server server;
-    protected GenericXmlApplicationContext context;
-
     @Override
-    public void setUp() throws Exception {
+    public final void runTest() throws Throwable {
         // Set up a custom thread pool to improve thread names (for logging purposes)
         QueuedThreadPool threadPool = new QueuedThreadPool();
         threadPool.setName("jetty");
-        server = new Server(threadPool);
+        Server server = new Server(threadPool);
 
         ServerConnector connector = new ServerConnector(server);
         connector.setPort(0);
@@ -71,24 +69,27 @@ public abstract class ScenarioTestCase extends SpringWSTestCase {
         server.setHandler(handler);
         server.start();
 
-        context = new GenericXmlApplicationContext();
-        MockPropertySource propertySource = new MockPropertySource("client-properties");
-        propertySource.setProperty("port", connector.getLocalPort());
-        context.getEnvironment()
-                .getPropertySources()
-                .replace(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, propertySource);
-        configureContext(
-                context, config.getClientMessageFactoryConfigurator(), new ClassPathResource("client.xml", getClass()));
-
-        context.refresh();
+        GenericXmlApplicationContext context = new GenericXmlApplicationContext();
+        try {
+            MockPropertySource propertySource = new MockPropertySource("client-properties");
+            propertySource.setProperty("port", connector.getLocalPort());
+            context.getEnvironment()
+                    .getPropertySources()
+                    .replace(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, propertySource);
+            configureContext(
+                    context,
+                    config.getClientMessageFactoryConfigurator(),
+                    new ClassPathResource("client.xml", getClass()));
+            context.refresh();
+            try {
+                runScenario(context);
+            } finally {
+                context.close();
+            }
+        } finally {
+            server.stop();
+        }
     }
 
-    @Override
-    public void tearDown() throws Exception {
-        context.close();
-        context = null;
-
-        server.stop();
-        server = null;
-    }
+    protected abstract void runScenario(ApplicationContext context) throws Throwable;
 }
diff --git a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/broker/BrokerScenarioTest.java b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/broker/BrokerScenarioTest.java
index 2e0b57b9b..6636410c4 100644
--- a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/broker/BrokerScenarioTest.java
+++ b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/broker/BrokerScenarioTest.java
@@ -24,6 +24,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import java.util.Locale;
 import javax.xml.transform.Source;
 import org.apache.axiom.ts.springws.scenario.ScenarioTestCase;
+import org.springframework.context.ApplicationContext;
 import org.springframework.ws.server.endpoint.annotation.XPathParam;
 import org.springframework.ws.soap.client.SoapFaultClientException;
 
@@ -41,7 +42,7 @@ import org.springframework.ws.soap.client.SoapFaultClientException;
  */
 public class BrokerScenarioTest extends ScenarioTestCase {
     @Override
-    public void runTest() throws Throwable {
+    protected void runScenario(ApplicationContext context) throws Throwable {
         BrokerClient client = context.getBean(BrokerClient.class);
 
         Order order = new Order();
diff --git a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/jaxb2/JAXB2Test.java b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/jaxb2/JAXB2Test.java
index 365e2901c..cc1a27ef8 100644
--- a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/jaxb2/JAXB2Test.java
+++ b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/jaxb2/JAXB2Test.java
@@ -22,11 +22,12 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.within;
 
 import org.apache.axiom.ts.springws.scenario.ScenarioTestCase;
+import org.springframework.context.ApplicationContext;
 import org.springframework.ws.client.core.WebServiceTemplate;
 
 public class JAXB2Test extends ScenarioTestCase {
     @Override
-    public void runTest() throws Throwable {
+    protected void runScenario(ApplicationContext context) throws Throwable {
         GetQuoteRequest request = new GetQuoteRequest();
         request.setSymbol("GOOG");
         GetQuoteResponse response =
diff --git a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/jdom/ClientServerTest.java b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/jdom/ClientServerTest.java
index 3747ffa82..ebb87ac73 100644
--- a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/jdom/ClientServerTest.java
+++ b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/jdom/ClientServerTest.java
@@ -25,11 +25,12 @@ import org.apache.axiom.ts.springws.scenario.ScenarioTestCase;
 import org.jdom2.input.SAXBuilder;
 import org.jdom2.transform.JDOMResult;
 import org.jdom2.transform.JDOMSource;
+import org.springframework.context.ApplicationContext;
 import org.springframework.ws.client.core.WebServiceTemplate;
 
 public class ClientServerTest extends ScenarioTestCase {
     @Override
-    public void runTest() throws Throwable {
+    protected void runScenario(ApplicationContext context) throws Throwable {
         JDOMSource source = new JDOMSource(new SAXBuilder()
                 .build(ClientServerTest.class.getResourceAsStream("request.xml"))
                 .getRootElement());
diff --git a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/secureecho/SecureEchoTest.java b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/secureecho/SecureEchoTest.java
index ecec8b5d9..488e850e4 100644
--- a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/secureecho/SecureEchoTest.java
+++ b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/secureecho/SecureEchoTest.java
@@ -25,6 +25,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.dom.DOMSource;
 import org.apache.axiom.ts.springws.scenario.ScenarioTestCase;
+import org.springframework.context.ApplicationContext;
 import org.springframework.ws.client.core.WebServiceTemplate;
 import org.springframework.ws.soap.client.core.SoapActionCallback;
 import org.w3c.dom.Document;
@@ -32,7 +33,7 @@ import org.w3c.dom.Element;
 
 public class SecureEchoTest extends ScenarioTestCase {
     @Override
-    public void runTest() throws Throwable {
+    protected void runScenario(ApplicationContext context) throws Throwable {
         DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
         Document requestDocument = documentBuilder.newDocument();
         Element request = requestDocument.createElementNS("urn:test", "p:Echo");
diff --git a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/soapaction/SoapActionTest.java b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/soapaction/SoapActionTest.java
index cfcb1e72a..0a0580fe6 100644
--- a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/soapaction/SoapActionTest.java
+++ b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/soapaction/SoapActionTest.java
@@ -25,6 +25,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.dom.DOMSource;
 import org.apache.axiom.ts.springws.scenario.ScenarioTestCase;
+import org.springframework.context.ApplicationContext;
 import org.springframework.ws.client.core.WebServiceTemplate;
 import org.springframework.ws.soap.client.core.SoapActionCallback;
 import org.w3c.dom.Document;
@@ -32,7 +33,7 @@ import org.w3c.dom.Element;
 
 public class SoapActionTest extends ScenarioTestCase {
     @Override
-    public void runTest() throws Throwable {
+    protected void runScenario(ApplicationContext context) throws Throwable {
         DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
         Document requestDocument = documentBuilder.newDocument();
         Element request = requestDocument.createElementNS("urn:test", "p:Echo");
diff --git a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/validation/ValidationTest.java b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/validation/ValidationTest.java
index aa55d10c8..e8e8f6a1f 100644
--- a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/validation/ValidationTest.java
+++ b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/validation/ValidationTest.java
@@ -25,12 +25,13 @@ import static org.assertj.core.api.Assertions.within;
 import java.util.Iterator;
 import javax.xml.namespace.QName;
 import org.apache.axiom.ts.springws.scenario.ScenarioTestCase;
+import org.springframework.context.ApplicationContext;
 import org.springframework.ws.soap.SoapFaultDetailElement;
 import org.springframework.ws.soap.client.SoapFaultClientException;
 
 public class ValidationTest extends ScenarioTestCase {
     @Override
-    public void runTest() throws Throwable {
+    protected void runScenario(ApplicationContext context) throws Throwable {
         StockQuoteClient client = context.getBean(StockQuoteClient.class);
 
         assertThat(client.getQuote("GOOG")).isCloseTo(105.37, within(0.001));
diff --git a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/wsadom/WSAddressingDOMTest.java b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/wsadom/WSAddressingDOMTest.java
index 4c27cd28c..703efd39f 100644
--- a/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/wsadom/WSAddressingDOMTest.java
+++ b/testing/spring-ws-testsuite/src/main/java/org/apache/axiom/ts/springws/scenario/wsadom/WSAddressingDOMTest.java
@@ -25,6 +25,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.dom.DOMSource;
 import org.apache.axiom.ts.springws.scenario.ScenarioTestCase;
+import org.springframework.context.ApplicationContext;
 import org.springframework.ws.client.core.WebServiceTemplate;
 import org.springframework.ws.soap.addressing.client.ActionCallback;
 import org.w3c.dom.Document;
@@ -32,7 +33,7 @@ import org.w3c.dom.Element;
 
 public class WSAddressingDOMTest extends ScenarioTestCase {
     @Override
-    public void runTest() throws Throwable {
+    protected void runScenario(ApplicationContext context) throws Throwable {
         DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
         Document requestDocument = documentBuilder.newDocument();
         Element request = requestDocument.createElementNS("urn:test", "p:testRequest");