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 bi...@apache.org on 2020/04/14 20:03:15 UTC

[axis-axis2-java-core] 28/31: Merge r1819246 to the 1.7 branch.

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

billblough pushed a commit to branch 1_7
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-core.git

commit ac992cbd5d23c95922fecba190dd1e0560f17232
Author: Andreas Veithen <ve...@apache.org>
AuthorDate: Sun Jan 6 17:46:56 2019 +0000

    Merge r1819246 to the 1.7 branch.
---
 modules/integration/pom.xml                        |  6 ++++
 .../apache/axis2/engine/map/MapServiceTest.java    | 40 ++++++++--------------
 .../axis2/testutils/AbstractAxis2Server.java       | 12 ++++---
 .../org/apache/axis2/testutils/Axis2Server.java    |  4 +--
 .../apache/axis2/testutils/AxisServiceFactory.java | 26 ++++++++++++++
 .../org/apache/axis2/testutils/JettyServer.java    |  4 +--
 .../axis2/testutils/SimpleAxisServiceFactory.java  | 35 +++++++++++++++++++
 7 files changed, 94 insertions(+), 33 deletions(-)

diff --git a/modules/integration/pom.xml b/modules/integration/pom.xml
index 8f1a53c..1daa1a0 100644
--- a/modules/integration/pom.xml
+++ b/modules/integration/pom.xml
@@ -133,6 +133,12 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.axis2</groupId>
+            <artifactId>axis2-testutils</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>log4j</groupId>
             <artifactId>log4j</artifactId>
             <scope>test</scope>
diff --git a/modules/integration/test/org/apache/axis2/engine/map/MapServiceTest.java b/modules/integration/test/org/apache/axis2/engine/map/MapServiceTest.java
index cfd1a30..91854e8 100644
--- a/modules/integration/test/org/apache/axis2/engine/map/MapServiceTest.java
+++ b/modules/integration/test/org/apache/axis2/engine/map/MapServiceTest.java
@@ -19,8 +19,10 @@
 
 package org.apache.axis2.engine.map;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
 import javax.xml.stream.XMLStreamException;
-import junit.framework.TestCase;
 
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
@@ -31,33 +33,19 @@ import org.apache.axis2.AxisFault;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.client.Options;
 import org.apache.axis2.client.ServiceClient;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.engine.AxisServer;
+import org.apache.axis2.testutils.Axis2Server;
+import org.apache.axis2.testutils.SimpleAxisServiceFactory;
+import org.junit.ClassRule;
+import org.junit.Test;
 
 /**
  * The Class MapServiceTest.
  */
-public class MapServiceTest extends TestCase {
-    private AxisServer server;
+public class MapServiceTest {
+    @ClassRule
+    public static Axis2Server server = new Axis2Server(null,
+            new SimpleAxisServiceFactory(MapService.class));
     
-    /** The service. */
-    protected AxisService service;
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see junit.framework.TestCase#setUp()
-     */
-    protected void setUp() throws Exception {
-        server = new AxisServer();
-        server.deployService(MapService.class.getName());
-    }   
-
-    @Override
-    protected void tearDown() throws Exception {
-        server.stop();
-    }
-
     /**
      * Test string generics map service.
      * 
@@ -66,9 +54,10 @@ public class MapServiceTest extends TestCase {
      * @throws AxisFault
      *             the axis fault
      */
+    @Test
     public void testStringGenericsMapService() throws XMLStreamException,
             AxisFault {
-        String epr = "http://localhost:6060/axis2/services/MapService/stringGenericsMapService";
+        String epr = server.getEndpoint("MapService") + "/stringGenericsMapService";
         Options options = new Options();
         options.setTo(new EndpointReference(epr));
         ServiceClient sender = new ServiceClient();
@@ -94,10 +83,11 @@ public class MapServiceTest extends TestCase {
      * @throws AxisFault
      *             the axis fault
      */
+    @Test
     public void testStringGenericsTreeMapService() throws XMLStreamException,
             AxisFault {
 
-        String epr = "http://localhost:6060/axis2/services/MapService/stringGenericsTreeMapService";
+        String epr = server.getEndpoint("MapService") + "/stringGenericsTreeMapService";
         Options options = new Options();
         options.setTo(new EndpointReference(epr));
         ServiceClient sender = new ServiceClient();
diff --git a/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractAxis2Server.java b/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractAxis2Server.java
index d34c443..a5cd120 100644
--- a/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractAxis2Server.java
+++ b/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractAxis2Server.java
@@ -24,17 +24,17 @@ import org.apache.axis2.AxisFault;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.engine.AxisConfiguration;
 import org.junit.rules.ExternalResource;
 
 public abstract class AbstractAxis2Server extends ExternalResource {
     private final String repositoryPath;
+    private final AxisServiceFactory[] serviceFactories;
     private ConfigurationContext configurationContext;
 
-    public AbstractAxis2Server(String repositoryPath) {
-        if (repositoryPath == null || repositoryPath.trim().length() == 0) {
-            throw new IllegalArgumentException("Axis2 repository must not be null or empty");
-        }
+    public AbstractAxis2Server(String repositoryPath, AxisServiceFactory... serviceFactories) {
         this.repositoryPath = repositoryPath;
+        this.serviceFactories = serviceFactories;
     }
 
     final String getRepositoryPath() {
@@ -52,6 +52,10 @@ public abstract class AbstractAxis2Server extends ExternalResource {
     protected void before() throws Throwable {
         configurationContext =
                 ConfigurationContextFactory.createConfigurationContextFromFileSystem(repositoryPath);
+        AxisConfiguration axisConfiguration = configurationContext.getAxisConfiguration();
+        for (AxisServiceFactory serviceFactory : serviceFactories) {
+            axisConfiguration.addService(serviceFactory.createService(axisConfiguration));
+        }
         startServer(configurationContext);
     }
 
diff --git a/modules/testutils/src/main/java/org/apache/axis2/testutils/Axis2Server.java b/modules/testutils/src/main/java/org/apache/axis2/testutils/Axis2Server.java
index 24f2308..4d95c3a 100644
--- a/modules/testutils/src/main/java/org/apache/axis2/testutils/Axis2Server.java
+++ b/modules/testutils/src/main/java/org/apache/axis2/testutils/Axis2Server.java
@@ -29,8 +29,8 @@ public class Axis2Server extends AbstractAxis2Server {
     private int port = -1;
     private SimpleHTTPServer server;
 
-    public Axis2Server(String repositoryPath) {
-        super(repositoryPath);
+    public Axis2Server(String repositoryPath, AxisServiceFactory... axisServiceFactories) {
+        super(repositoryPath, axisServiceFactories);
     }
 
     @Override
diff --git a/modules/testutils/src/main/java/org/apache/axis2/testutils/AxisServiceFactory.java b/modules/testutils/src/main/java/org/apache/axis2/testutils/AxisServiceFactory.java
new file mode 100644
index 0000000..e388340
--- /dev/null
+++ b/modules/testutils/src/main/java/org/apache/axis2/testutils/AxisServiceFactory.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis2.testutils;
+
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.AxisConfiguration;
+
+public interface AxisServiceFactory {
+    AxisService createService(AxisConfiguration axisConfiguration) throws Exception;
+}
diff --git a/modules/testutils/src/main/java/org/apache/axis2/testutils/JettyServer.java b/modules/testutils/src/main/java/org/apache/axis2/testutils/JettyServer.java
index 6cd51fc..52cd3a4 100644
--- a/modules/testutils/src/main/java/org/apache/axis2/testutils/JettyServer.java
+++ b/modules/testutils/src/main/java/org/apache/axis2/testutils/JettyServer.java
@@ -85,8 +85,8 @@ public class JettyServer extends AbstractAxis2Server {
      * @param secure
      *            Whether to enable HTTPS.
      */
-    public JettyServer(String repositoryPath, boolean secure) {
-        super(repositoryPath);
+    public JettyServer(String repositoryPath, boolean secure, AxisServiceFactory... axisServiceFactories) {
+        super(repositoryPath, axisServiceFactories);
         this.secure = secure;
     }
     
diff --git a/modules/testutils/src/main/java/org/apache/axis2/testutils/SimpleAxisServiceFactory.java b/modules/testutils/src/main/java/org/apache/axis2/testutils/SimpleAxisServiceFactory.java
new file mode 100644
index 0000000..67822b0
--- /dev/null
+++ b/modules/testutils/src/main/java/org/apache/axis2/testutils/SimpleAxisServiceFactory.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis2.testutils;
+
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.AxisConfiguration;
+
+public class SimpleAxisServiceFactory implements AxisServiceFactory {
+    private final Class<?> implClass;
+
+    public SimpleAxisServiceFactory(Class<?> implClass) {
+        this.implClass = implClass;
+    }
+
+    @Override
+    public AxisService createService(AxisConfiguration axisConfiguration) throws Exception {
+        return AxisService.createService(implClass.getName(), axisConfiguration);
+    }
+}