| 1 |
package test.encoding; |
| 2 |
|
| 3 |
import junit.framework.TestCase; |
| 4 |
import org.apache.axis.Constants; |
| 5 |
import org.apache.axis.Message; |
| 6 |
import org.apache.axis.MessageContext; |
| 7 |
import org.apache.axis.server.AxisServer; |
| 8 |
import org.custommonkey.xmlunit.XMLTestCase; |
| 9 |
|
| 10 |
/** |
| 11 |
* Test deserialization of SOAP responses |
| 12 |
*/ |
| 13 |
public class TestOutputter extends XMLTestCase { |
| 14 |
|
| 15 |
private String header; |
| 16 |
private String footer; |
| 17 |
private AxisServer server = new AxisServer(); |
| 18 |
|
| 19 |
public TestOutputter(String name) { |
| 20 |
this(name, Constants.URI_DEFAULT_SCHEMA_XSI, |
| 21 |
Constants.URI_DEFAULT_SCHEMA_XSD); |
| 22 |
} |
| 23 |
|
| 24 |
public TestOutputter(String name, String NS_XSI, String NS_XSD) { |
| 25 |
super(name); |
| 26 |
|
| 27 |
header = |
| 28 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + |
| 29 |
"<soap:Envelope " + |
| 30 |
"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " + |
| 31 |
"xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" " + |
| 32 |
"xmlns:xsi=\"" + NS_XSI + "\" " + |
| 33 |
"xmlns:xsd=\"" + NS_XSD + "\">\n" + |
| 34 |
"<soap:Body>\n" + |
| 35 |
"<methodResult xmlns=\"http://tempuri.org/\">\n"; |
| 36 |
|
| 37 |
footer = |
| 38 |
"</methodResult>\n" + |
| 39 |
"</soap:Body>\n" + |
| 40 |
"</soap:Envelope>"; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Verify that a given XML deserialized produces the expected result |
| 45 |
*/ |
| 46 |
protected void roundtrip(String data) |
| 47 |
throws Exception |
| 48 |
{ |
| 49 |
Message message = new Message(header + data + footer); |
| 50 |
message.setMessageContext(new MessageContext(server)); |
| 51 |
|
| 52 |
message.getSOAPEnvelope(); |
| 53 |
|
| 54 |
assertXMLEqual(header+data+footer, message.getSOAPPartAsString()); |
| 55 |
} |
| 56 |
|
| 57 |
public void testString() throws Exception { |
| 58 |
roundtrip("<result xsi:type=\"xsd:string\">abc</result>"); |
| 59 |
} |
| 60 |
|
| 61 |
public void testEscapedText() throws Exception { |
| 62 |
roundtrip("<abc><&></abc>"); |
| 63 |
} |
| 64 |
|
| 65 |
public void testEscapedAttributes() throws Exception { |
| 66 |
roundtrip("<abc foo=\"<&>\"/>"); |
| 67 |
// roundtrip("<abc foo=\"<&>\"/>"); |
| 68 |
} |
| 69 |
|
| 70 |
public static void main(String [] args) throws Exception |
| 71 |
{ |
| 72 |
TestOutputter tester = new TestOutputter("test"); |
| 73 |
tester.testString(); |
| 74 |
} |
| 75 |
} |