You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ke...@apache.org on 2009/02/18 09:27:41 UTC
svn commit: r745429 - in /webservices/axis2/trunk/java/modules/kernel:
test-resources/wsdl/httpMessagesSerialization.wsdl
test/org/apache/axis2/description/HttpMessagesSerializationTest.java
Author: keithc
Date: Wed Feb 18 08:27:41 2009
New Revision: 745429
URL: http://svn.apache.org/viewvc?rev=745429&view=rev
Log:
Adding test case given in AXIS2-4082
Added:
webservices/axis2/trunk/java/modules/kernel/test-resources/wsdl/httpMessagesSerialization.wsdl
webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/description/HttpMessagesSerializationTest.java
Added: webservices/axis2/trunk/java/modules/kernel/test-resources/wsdl/httpMessagesSerialization.wsdl
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test-resources/wsdl/httpMessagesSerialization.wsdl?rev=745429&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test-resources/wsdl/httpMessagesSerialization.wsdl (added)
+++ webservices/axis2/trunk/java/modules/kernel/test-resources/wsdl/httpMessagesSerialization.wsdl Wed Feb 18 08:27:41 2009
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="utf-8"?>
+<wsdl:definitions targetNamespace="http://www.example.org"
+ xmlns:tns="http://www.example.org"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
+ xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/">
+
+ <wsdl:types>
+ <xsd:schema elementFormDefault="qualified"
+ targetNamespace="http://www.example.org">
+ <xsd:element name="getFoo" type="xsd:string"/>
+ <xsd:element name="getFooResponse" type="xsd:string"/>
+ </xsd:schema>
+ </wsdl:types>
+
+ <wsdl:message name="getFooIn">
+ <wsdl:part name="input" element="tns:getFoo" />
+ </wsdl:message>
+ <wsdl:message name="getFooOut">
+ <wsdl:part name="output" element="tns:getFooResponse" />
+ </wsdl:message>
+
+ <wsdl:message name="getBarIn">
+ <wsdl:part name="input" type="xsd:string" />
+ </wsdl:message>
+ <wsdl:message name="getBarOut">
+ <wsdl:part name="output" type="xsd:string" />
+ </wsdl:message>
+
+ <wsdl:portType name="FooPortType">
+ <wsdl:operation name="getFoo">
+ <wsdl:input message="tns:getFooIn" />
+ <wsdl:output message="tns:getFooOut" />
+ </wsdl:operation>
+ <wsdl:operation name="getBar">
+ <wsdl:input message="tns:getBarIn" />
+ <wsdl:output message="tns:getBarOut" />
+ </wsdl:operation>
+ </wsdl:portType>
+
+ <wsdl:binding name="FooHttpGetBinding" type="tns:FooPortType">
+ <http:binding verb="GET" />
+ <wsdl:operation name="getFoo">
+ <http:operation location="getFoo" />
+ <wsdl:input>
+ <http:urlEncoded/>
+ </wsdl:input>
+ <wsdl:output>
+ <mime:mimeXml part="output" />
+ </wsdl:output>
+ </wsdl:operation>
+ <wsdl:operation name="getBar">
+ <http:operation location="getBar" />
+ <wsdl:input>
+ <mime:content part="input" type="application/x-www-form-urlencoded" />
+ </wsdl:input>
+ <wsdl:output>
+ <mime:content part="output" type="image/jpeg" />
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+
+ <wsdl:binding name="FooHttpPostBinding" type="tns:FooPortType">
+ <http:binding verb="POST" />
+ <wsdl:operation name="getFoo">
+ <http:operation location="getFoo" />
+ <wsdl:input>
+ <mime:content part="input" type="text/xml" />
+ </wsdl:input>
+ <wsdl:output>
+ <mime:mimeXml part="output" />
+ </wsdl:output>
+ </wsdl:operation>
+ <wsdl:operation name="getBar">
+ <http:operation location="getBar" />
+ <wsdl:input>
+ <mime:content part="input" type="application/x-www-form-urlencoded" />
+ </wsdl:input>
+ <wsdl:output>
+ <mime:content part="output" type="text/xml" />
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+
+ <wsdl:service name="FooService">
+ <wsdl:port name="FooHttpGetPort" binding="tns:FooHttpGetBinding">
+ <http:address location="http://www.example.org/" />
+ </wsdl:port>
+ <wsdl:port name="FooHttpPostPort" binding="tns:FooHttpPostBinding">
+ <http:address location="http://www.example.org/" />
+ </wsdl:port>
+ </wsdl:service>
+
+</wsdl:definitions>
\ No newline at end of file
Added: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/description/HttpMessagesSerializationTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/description/HttpMessagesSerializationTest.java?rev=745429&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/description/HttpMessagesSerializationTest.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/description/HttpMessagesSerializationTest.java Wed Feb 18 08:27:41 2009
@@ -0,0 +1,185 @@
+package org.apache.axis2.description;
+
+import java.io.InputStream;
+import java.util.Enumeration;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.axis2.AbstractTestCase;
+
+/**
+ * This class tests that AxisBindingOperation and AxisBindingMessage objects
+ * include information about the message serialization format when the HTTP
+ * binding is used. The test cases verify the following serialization mappings:
+ * <ul>
+ * <li><http:urlEncoded/> : application/x-www-form-urlencoded
+ * <li><mime:mimeXml/> : text/xml
+ * <li><mime:content type="ABC"/> : ABC
+ * </ul>
+ */
+public class HttpMessagesSerializationTest extends AbstractTestCase {
+
+ public static final String HTTP_MESSAGE_SERIALIZATION_WSDL_PATH =
+ "wsdl/httpMessagesSerialization.wsdl";
+
+ private AxisBindingOperation bindingOperation;
+ private TestConfig testConfig;
+
+ public HttpMessagesSerializationTest(String testName_) {
+ super(testName_);
+ }
+
+ public String getName() {
+ TestConfig testConfig = getTestConfig();
+ return super.getName() + ". Expected Input Serialization: " +
+ testConfig.getInputSerialization() +
+ " ; Expected Output Serialization: " +
+ testConfig.getOutputSerialization();
+ }
+
+ public static Test suite() {
+
+ final String targetNamespace = "http://www.example.org";
+ final QName serviceName = new QName(targetNamespace, "FooService");
+ final String httpGetPortName = "FooHttpGetPort";
+ final String httpPostPortName = "FooHttpPostPort";
+ final QName fooOperationName = new QName(targetNamespace, "getFoo");
+ final QName barOperationName = new QName(targetNamespace, "getBar");
+
+ final String contentTypeTextXml = "text/xml";
+ final String contentTypeUrlEncoded = "application/x-www-form-urlencoded";
+ final String contentTypeImageJpeg = "image/jpeg";
+
+ final String wsdlPath = HTTP_MESSAGE_SERIALIZATION_WSDL_PATH;
+
+ TestConfig[] testConfigs = new TestConfig[] {
+ new TestConfig(wsdlPath, serviceName, httpGetPortName,
+ fooOperationName, contentTypeUrlEncoded, contentTypeTextXml),
+ new TestConfig(wsdlPath, serviceName, httpGetPortName,
+ barOperationName, contentTypeUrlEncoded, contentTypeImageJpeg),
+ new TestConfig(wsdlPath, serviceName, httpPostPortName,
+ fooOperationName, contentTypeTextXml, contentTypeTextXml),
+ new TestConfig(wsdlPath, serviceName, httpPostPortName,
+ barOperationName, contentTypeUrlEncoded, contentTypeTextXml)};
+
+ String className = HttpMessagesSerializationTest.class.getName();
+ TestSuite suite = new TestSuite(className);
+ for (int i = 0; i < testConfigs.length; i++) {
+ // Have JUnit create a TestCase instance for every test method of
+ // this class.
+ TestSuite testCases = new TestSuite(
+ HttpMessagesSerializationTest.class, testConfigs[i].toString());
+
+ // Loop through the TestCase instances and inject them with the test
+ // data.
+ Enumeration tests = testCases.tests();
+ while (tests.hasMoreElements()) {
+ HttpMessagesSerializationTest test =
+ (HttpMessagesSerializationTest) tests.nextElement();
+ test.setTestConfig(testConfigs[i]);
+ }
+
+ suite.addTest(testCases);
+ }
+ return suite;
+ }
+
+ public void setUp() throws Exception {
+ TestConfig testConfig = getTestConfig();
+ InputStream contentTypeWsdlIn = getTestResource(testConfig.getWsdlPath());
+ // Populate AxisService (WSDL port)
+ WSDL11ToAxisServiceBuilder wsdl11Builder = new WSDL11ToAxisServiceBuilder(
+ contentTypeWsdlIn, testConfig.getServiceName(),
+ testConfig.getPortName());
+ AxisService service = wsdl11Builder.populateService();
+
+ // Get Binding Operation
+ AxisEndpoint endpoint = service.getEndpoint(testConfig.getPortName());
+ AxisBinding binding = endpoint.getBinding();
+ bindingOperation = (AxisBindingOperation) binding.getChild(testConfig.getOperationName());
+ }
+
+ // Input Serialization Format @ AxisBindingOperation
+ public void testOperationInputSerialization() throws Exception {
+ TestConfig testConfig = getTestConfig();
+ String actualInputSerialization = (String) bindingOperation.getProperty(
+ WSDL2Constants.ATTR_WHTTP_INPUT_SERIALIZATION);
+ assertEquals("Input Serialization Format for the '" +
+ testConfig.getOperationName() + "' operation is Incorrect",
+ testConfig.getInputSerialization(), actualInputSerialization);
+ }
+
+ // Output Serialization Format @ AxisBindingOperation
+ public void testOperationOutputSerialization() throws Exception {
+ TestConfig testConfig = getTestConfig();
+ String actualOutputSerialization = (String) bindingOperation.getProperty(
+ WSDL2Constants.ATTR_WHTTP_OUTPUT_SERIALIZATION);
+ assertEquals("Output Serialization Format for the '" +
+ testConfig.getOperationName() + "' operation is Incorrect",
+ testConfig.getOutputSerialization(), actualOutputSerialization);
+ }
+
+ public TestConfig getTestConfig() {
+ return testConfig;
+ }
+
+ public void setTestConfig(TestConfig testConfig_) {
+ testConfig = testConfig_;
+ }
+
+ private final static class TestConfig {
+
+ private final String wsdlPath;
+ private final QName serviceName;
+ private final String portName;
+ private final QName operationName;
+ private final String inputSerialization;
+ private final String outputSerialization;
+
+ TestConfig(String wsdlPath, QName serviceName, String portName,
+ QName operationName, String inputSerialization,
+ String outputSerialization) {
+ this.wsdlPath = wsdlPath;
+ this.serviceName = serviceName;
+ this.portName = portName;
+ this.operationName = operationName;
+ this.inputSerialization = inputSerialization;
+ this.outputSerialization = outputSerialization;
+ }
+
+ public String getWsdlPath() {
+ return wsdlPath;
+ }
+
+ public QName getServiceName() {
+ return serviceName;
+ }
+
+ public String getPortName() {
+ return portName;
+ }
+
+ public QName getOperationName() {
+ return operationName;
+ }
+
+ public String getInputSerialization() {
+ return inputSerialization;
+ }
+
+ public String getOutputSerialization() {
+ return outputSerialization;
+ }
+
+ public String toString() {
+ return "serviceName:" + serviceName + " portName:" + portName +
+ " operationName:" + operationName +
+ " expectedInputSerialization:" + inputSerialization +
+ " expectedOutputSerialization:" + outputSerialization;
+ }
+ }
+
+}