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 2017/01/28 17:29:18 UTC
svn commit: r1780724 - in /axis/axis2/java/core/trunk/modules:
adb-tests/src/test/java/org/apache/axis2/databinding/axis2_5809/
json/test/org/apache/axis2/json/
testutils/src/main/java/org/apache/axis2/testutils/
Author: veithen
Date: Sat Jan 28 17:29:18 2017
New Revision: 1780724
URL: http://svn.apache.org/viewvc?rev=1780724&view=rev
Log:
Make it easier to create clients for services deployed on a test server.
Added:
axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/ClientHelper.java (with props)
Modified:
axis/axis2/java/core/trunk/modules/adb-tests/src/test/java/org/apache/axis2/databinding/axis2_5809/ServiceTest.java
axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/JSONIntegrationTest.java
axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractAxis2Server.java
Modified: axis/axis2/java/core/trunk/modules/adb-tests/src/test/java/org/apache/axis2/databinding/axis2_5809/ServiceTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb-tests/src/test/java/org/apache/axis2/databinding/axis2_5809/ServiceTest.java?rev=1780724&r1=1780723&r2=1780724&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/adb-tests/src/test/java/org/apache/axis2/databinding/axis2_5809/ServiceTest.java (original)
+++ axis/axis2/java/core/trunk/modules/adb-tests/src/test/java/org/apache/axis2/databinding/axis2_5809/ServiceTest.java Sat Jan 28 17:29:18 2017
@@ -23,6 +23,7 @@ import static org.junit.Assert.fail;
import org.apache.axis2.AxisFault;
import org.apache.axis2.testutils.Axis2Server;
+import org.apache.axis2.testutils.ClientHelper;
import org.junit.ClassRule;
import org.junit.Test;
@@ -30,9 +31,12 @@ public class ServiceTest {
@ClassRule
public static Axis2Server server = new Axis2Server("target/repo/AXIS2-5809");
+ @ClassRule
+ public static ClientHelper clientHelper = new ClientHelper(server);
+
@Test
public void testWithNormalResponse() throws Exception {
- EchoServiceStub stub = new EchoServiceStub(server.getConfigurationContext(), server.getEndpoint("EchoService"));
+ EchoServiceStub stub = clientHelper.createStub(EchoServiceStub.class, "EchoService");
for (int i=0; i<500; i++) {
Echo request = new Echo();
request.setContent("test");
@@ -42,7 +46,7 @@ public class ServiceTest {
@Test
public void testWithFault() throws Exception {
- EchoServiceStub stub = new EchoServiceStub(server.getConfigurationContext(), server.getEndpoint("EchoService"));
+ EchoServiceStub stub = clientHelper.createStub(EchoServiceStub.class, "EchoService");
for (int i=0; i<500; i++) {
Echo request = new Echo();
request.setContent("");
Modified: axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/JSONIntegrationTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/JSONIntegrationTest.java?rev=1780724&r1=1780723&r2=1780724&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/JSONIntegrationTest.java (original)
+++ axis/axis2/java/core/trunk/modules/json/test/org/apache/axis2/json/JSONIntegrationTest.java Sat Jan 28 17:29:18 2017
@@ -30,6 +30,7 @@ import org.apache.axis2.Constants;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.testutils.Axis2Server;
+import org.apache.axis2.testutils.ClientHelper;
import org.junit.ClassRule;
import org.junit.Test;
@@ -47,6 +48,9 @@ public class JSONIntegrationTest impleme
@ClassRule
public static Axis2Server server = new Axis2Server("target/repo/json");
+ @ClassRule
+ public static ClientHelper clientHelper = new ClientHelper(server);
+
protected OMElement createEnvelope() throws Exception {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("", "");
@@ -64,15 +68,12 @@ public class JSONIntegrationTest impleme
private void doEchoOM(String messageType, String httpMethod) throws Exception{
OMElement payload = createEnvelope();
- Options options = new Options();
- options.setTo(server.getEndpointReference("EchoXMLService"));
+ ServiceClient sender = clientHelper.createServiceClient("EchoXMLService");
+ Options options = sender.getOptions();
options.setProperty(Constants.Configuration.MESSAGE_TYPE, messageType);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
options.setProperty(Constants.Configuration.HTTP_METHOD, httpMethod);
-// ConfigurationContext clientConfigurationContext = ConfigurationContextFactory.createDefaultConfigurationContext();
- ServiceClient sender = new ServiceClient(server.getConfigurationContext(), null);
options.setAction(null);
- sender.setOptions(options);
OMElement result = sender.sendReceive(payload);
OMElement ele = (OMElement)result.getFirstOMChild();
compareWithCreatedOMText(ele.getText());
Modified: axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractAxis2Server.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractAxis2Server.java?rev=1780724&r1=1780723&r2=1780724&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractAxis2Server.java (original)
+++ axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/AbstractAxis2Server.java Sat Jan 28 17:29:18 2017
@@ -35,6 +35,10 @@ public abstract class AbstractAxis2Serve
this.repositoryPath = repositoryPath;
}
+ final String getRepositoryPath() {
+ return repositoryPath;
+ }
+
public final ConfigurationContext getConfigurationContext() {
if (configurationContext == null) {
throw new IllegalStateException();
Added: axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/ClientHelper.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/ClientHelper.java?rev=1780724&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/ClientHelper.java (added)
+++ axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/ClientHelper.java Sat Jan 28 17:29:18 2017
@@ -0,0 +1,64 @@
+/*
+ * 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.AxisFault;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.client.Stub;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.junit.rules.ExternalResource;
+
+public final class ClientHelper extends ExternalResource {
+ private final AbstractAxis2Server server;
+ private final String repositoryPath;
+ private ConfigurationContext configurationContext;
+
+ public ClientHelper(AbstractAxis2Server server, String repositoryPath) {
+ this.server = server;
+ this.repositoryPath = repositoryPath;
+ }
+
+ public ClientHelper(AbstractAxis2Server server) {
+ this(server, server.getRepositoryPath());
+ }
+
+ @Override
+ protected void before() throws Throwable {
+ configurationContext =
+ ConfigurationContextFactory.createConfigurationContextFromFileSystem(repositoryPath);
+ }
+
+ @Override
+ protected void after() {
+ configurationContext = null;
+ }
+
+ public ServiceClient createServiceClient(String serviceName) throws AxisFault {
+ ServiceClient serviceClient = new ServiceClient(configurationContext, null);
+ serviceClient.getOptions().setTo(server.getEndpointReference(serviceName));
+ return serviceClient;
+ }
+
+ public <T extends Stub> T createStub(Class<T> type, String serviceName) throws Exception {
+ return type
+ .getConstructor(ConfigurationContext.class, String.class)
+ .newInstance(configurationContext, server.getEndpoint(serviceName));
+ }
+}
Propchange: axis/axis2/java/core/trunk/modules/testutils/src/main/java/org/apache/axis2/testutils/ClientHelper.java
------------------------------------------------------------------------------
svn:eol-style = native