You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by ve...@apache.org on 2019/01/06 13:49:48 UTC
svn commit: r1850551 - in /axis/axis2/java/core/trunk/modules:
integration/test/org/apache/axis2/engine/PausingHandlerExecutionTest.java
testutils/src/main/java/org/apache/axis2/testutils/AbstractConfigurationContextRule.java
Author: veithen
Date: Sun Jan 6 13:49:48 2019
New Revision: 1850551
URL: http://svn.apache.org/viewvc?rev=1850551&view=rev
Log:
Refactor PausingHandlerExecutionTest to use Axis2Server.
Modified:
axis/axis2/java/core/trunk/modules/integration/test/org/apache/axis2/engine/PausingHandlerExecutionTest.java
axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractConfigurationContextRule.java
Modified: axis/axis2/java/core/trunk/modules/integration/test/org/apache/axis2/engine/PausingHandlerExecutionTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/integration/test/org/apache/axis2/engine/PausingHandlerExecutionTest.java?rev=1850551&r1=1850550&r2=1850551&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/integration/test/org/apache/axis2/engine/PausingHandlerExecutionTest.java (original)
+++ axis/axis2/java/core/trunk/modules/integration/test/org/apache/axis2/engine/PausingHandlerExecutionTest.java Sun Jan 6 13:49:48 2019
@@ -19,6 +19,9 @@
package org.apache.axis2.engine;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -31,13 +34,11 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
import org.apache.axiom.om.OMElement;
import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.ConfigurationContext;
@@ -48,58 +49,44 @@ import org.apache.axis2.engine.util.Test
import org.apache.axis2.handlers.AbstractHandler;
import org.apache.axis2.integration.TestingUtils;
import org.apache.axis2.integration.UtilServer;
-import org.apache.axis2.integration.UtilServerBasedTestCase;
import org.apache.axis2.phaseresolver.PhaseMetadata;
+import org.apache.axis2.testutils.Axis2Server;
import org.apache.axis2.util.Utils;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+public class PausingHandlerExecutionTest implements TestConstants {
+ @ClassRule
+ public static final Axis2Server server = new Axis2Server(TestingUtils.prefixBaseDirectory(Constants.TESTING_REPOSITORY));
-public class PausingHandlerExecutionTest extends UtilServerBasedTestCase implements TestConstants {
- private static boolean initDone = false;
private static ArrayList testResults;
- private AxisService testService;
private static TestHandler middleGlobalInHandler;
- private TestHandler firstOperationInHandler;
- private TestHandler middleOperationInHandler;
- private TestHandler middleOperationOutHandler;
-
- public PausingHandlerExecutionTest() {
- super(PausingHandlerExecutionTest.class.getName());
- }
- public PausingHandlerExecutionTest(String testName) {
- super(testName);
- }
-
- public static Test suite() {
- return getTestSetup(new TestSuite(PausingHandlerExecutionTest.class));
- }
-
- protected void setUp() throws Exception {
- //org.apache.log4j.BasicConfigurator.configure();
+ @BeforeClass
+ public static void setUp() throws Exception {
+ AxisConfiguration axisConfiguration = server.getConfigurationContext().getAxisConfiguration();
testResults = new ArrayList();
- if (!initDone) {
- initDone = true;
- List globalInPhases =
- UtilServer.getConfigurationContext().getAxisConfiguration().getInFlowPhases();
- for (int i = 0; i < globalInPhases.size(); i++) {
- Phase globalInPhase = (Phase)globalInPhases.get(i);
- if (PhaseMetadata.PHASE_PRE_DISPATCH.equals(globalInPhase.getPhaseName())) {
- System.out.println("Adding handlers to globalInPhase name [" +
- globalInPhase.getPhaseName() + "] ...");
- globalInPhase.addHandler(new TestHandler("In1"));
- middleGlobalInHandler = new TestHandler("In2");
- globalInPhase.addHandler(middleGlobalInHandler);
- globalInPhase.addHandler(new TestHandler("In3"));
- System.out.println("...done adding handlers to globalInPhase name [" +
- globalInPhase.getPhaseName() + "] ...");
- }
+ List globalInPhases = axisConfiguration.getInFlowPhases();
+ for (int i = 0; i < globalInPhases.size(); i++) {
+ Phase globalInPhase = (Phase)globalInPhases.get(i);
+ if (PhaseMetadata.PHASE_PRE_DISPATCH.equals(globalInPhase.getPhaseName())) {
+ System.out.println("Adding handlers to globalInPhase name [" +
+ globalInPhase.getPhaseName() + "] ...");
+ globalInPhase.addHandler(new TestHandler("In1"));
+ middleGlobalInHandler = new TestHandler("In2");
+ globalInPhase.addHandler(middleGlobalInHandler);
+ globalInPhase.addHandler(new TestHandler("In3"));
+ System.out.println("...done adding handlers to globalInPhase name [" +
+ globalInPhase.getPhaseName() + "] ...");
}
}
- testService = Utils.createSimpleService(serviceName, Echo.class.getName(),
- operationName);
- UtilServer.deployService(testService);
+ AxisService testService = Utils.createSimpleService(serviceName, Echo.class.getName(),
+ operationName);
+ axisConfiguration.addService(testService);
AxisOperation operation = testService.getOperation(operationName);
ArrayList operationSpecificPhases = new ArrayList();
@@ -111,9 +98,9 @@ public class PausingHandlerExecutionTest
Phase operationSpecificPhase = (Phase)phaseList.get(i);
if (PhaseMetadata.PHASE_POLICY_DETERMINATION
.equals(operationSpecificPhase.getPhaseName())) {
- firstOperationInHandler = new TestHandler("In4");
+ TestHandler firstOperationInHandler = new TestHandler("In4");
operationSpecificPhase.addHandler(firstOperationInHandler);
- middleOperationInHandler = new TestHandler("In5");
+ TestHandler middleOperationInHandler = new TestHandler("In5");
operationSpecificPhase.addHandler(middleOperationInHandler);
operationSpecificPhase.addHandler(new TestHandler("In6"));
}
@@ -129,21 +116,16 @@ public class PausingHandlerExecutionTest
if (PhaseMetadata.PHASE_POLICY_DETERMINATION
.equals(operationSpecificPhase.getPhaseName())) {
operationSpecificPhase.addHandler(new TestHandler("Out1"));
- middleOperationOutHandler = new TestHandler("Out2");
+ TestHandler middleOperationOutHandler = new TestHandler("Out2");
operationSpecificPhase.addHandler(middleOperationOutHandler);
operationSpecificPhase.addHandler(new TestHandler("Out3"));
}
}
}
- protected void tearDown() throws Exception {
- UtilServer.unDeployService(serviceName);
- UtilServer.unDeployClientService();
- }
-
private ServiceClient createClient() throws Exception {
Options options = new Options();
- options.setTo(targetEPR);
+ options.setTo(new EndpointReference("http://127.0.0.1:" + server.getPort() + "/axis2/services/EchoXMLService/echoOMElement"));
options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
options.setAction(operationName.getLocalPart());
@@ -164,6 +146,7 @@ public class PausingHandlerExecutionTest
TestingUtils.compareWithCreatedOMElement(result);
}
+ @Test
public void testSuccessfulInvocation() throws Exception {
System.out.println("Starting testSuccessfulInvocation");
middleGlobalInHandler.shouldPause(true);
@@ -198,7 +181,7 @@ public class PausingHandlerExecutionTest
}
- private class TestHandler extends AbstractHandler {
+ private static class TestHandler extends AbstractHandler {
private String handlerName;
private boolean shouldFail = false;
private boolean shouldPause = false;
@@ -360,7 +343,7 @@ public class PausingHandlerExecutionTest
}
- private class Worker extends Thread {
+ private static class Worker extends Thread {
private byte[] serializedMessageContext = null;
private ConfigurationContext configurationContext = null;
private File theFile = null;
Modified: axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractConfigurationContextRule.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractConfigurationContextRule.java?rev=1850551&r1=1850550&r2=1850551&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractConfigurationContextRule.java (original)
+++ axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractConfigurationContextRule.java Sun Jan 6 13:49:48 2019
@@ -18,6 +18,8 @@
*/
package org.apache.axis2.testutils;
+import java.io.File;
+
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.junit.rules.ExternalResource;
@@ -43,8 +45,25 @@ public abstract class AbstractConfigurat
@Override
protected void before() throws Throwable {
+ String axis2xml;
+ if (repositoryPath == null) {
+ axis2xml = null;
+ } else {
+ File repo = new File(repositoryPath);
+ File axis2xmlFile = new File(repo, "axis2.xml");
+ if (axis2xmlFile.exists()) {
+ axis2xml = axis2xmlFile.getAbsolutePath();
+ } else {
+ axis2xmlFile = new File(new File(repo, "conf"), "axis2.xml");
+ if (axis2xmlFile.exists()) {
+ axis2xml = axis2xmlFile.getAbsolutePath();
+ } else {
+ axis2xml = null;
+ }
+ }
+ }
configurationContext =
- ConfigurationContextFactory.createConfigurationContextFromFileSystem(repositoryPath);
+ ConfigurationContextFactory.createConfigurationContextFromFileSystem(repositoryPath, axis2xml);
}
@Override