Debian Codegraph @

test/encoding/TestString.java

raw
1 package test.encoding;
2
3 import junit.framework.TestCase;
4 import org.apache.axis.MessageContext;
5 import org.apache.axis.encoding.DeserializationContext;
6 import org.apache.axis.encoding.SerializationContext;
7 import org.apache.axis.encoding.SerializationContext;
8 import org.apache.axis.message.RPCElement;
9 import org.apache.axis.message.RPCParam;
10 import org.apache.axis.message.SOAPEnvelope;
11 import org.apache.axis.server.AxisServer;
12 import org.xml.sax.InputSource;
13
14 import javax.xml.soap.MessageFactory;
15 import javax.xml.soap.SOAPMessage;
16 import java.io.StringReader;
17 import java.io.StringWriter;
18 import java.io.Writer;
19 import java.io.ByteArrayOutputStream;
20 import java.io.OutputStreamWriter;
21 import java.io.ByteArrayInputStream;
22
23 /** Little serialization test with a struct.
24 */
25 public class TestString extends TestCase {
26
27 public static final String myNS = "urn:myNS";
28
29 public TestString(String name) {
30 super(name);
31 }
32
33 private void runtest(String value, String expected) throws Exception {
34 MessageContext msgContext = new MessageContext(new AxisServer());
35 MessageFactory factory = MessageFactory.newInstance();
36 org.apache.axis.Message message = (org.apache.axis.Message) factory.createMessage();
37 message.setMessageContext(msgContext);
38 String requestEncoding = "UTF-8";
39 msgContext.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, requestEncoding);
40 message.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, requestEncoding);
41 RPCParam input = new RPCParam("urn:myNamespace", "testParam", value);
42
43 RPCElement body = new RPCElement("urn:myNamespace", "method1", new Object[]{ input });
44 message.getSOAPBody().addChildElement(body);
45
46 ByteArrayOutputStream baos = new ByteArrayOutputStream();
47 message.writeTo(baos);
48
49 ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
50 DeserializationContext dser = new DeserializationContext(
51 new InputSource(bais), msgContext, org.apache.axis.Message.REQUEST);
52 dser.parse();
53
54 org.apache.axis.message.SOAPEnvelope env = dser.getEnvelope();
55 RPCElement rpcElem = (RPCElement)env.getFirstBody();
56 RPCParam output = rpcElem.getParam("testParam");
57 assertNotNull("No <testParam> param", output);
58
59 String result = (String)output.getObjectValue();
60 assertNotNull("No value for testParam param", result);
61
62 assertEquals("Expected result not received.", expected, result);
63 }
64
65 private void runtest(String value) throws Exception {
66 runtest(value, value);
67 }
68
69 public void testSimpleString() throws Exception {
70 runtest("a simple string");
71 }
72
73 public void testStringWithApostrophes() throws Exception {
74 runtest("this isn't a simple string");
75 }
76
77 public void testStringWithEntities() throws Exception {
78 runtest("&amp;&lt;&gt;&apos;&quot;", "&amp;&lt;&gt;&apos;&quot;");
79 }
80
81 public void testStringWithRawEntities() throws Exception {
82 runtest("&<>'\"", "&<>'\"");
83 }
84
85 public void testStringWithLeadingAndTrailingSpaces() throws Exception {
86 runtest(" centered ");
87 }
88
89 public void testWhitespace() throws Exception {
90 runtest(" \n \t "); // note: \r fails
91 }
92
93 public void testFrenchAccents() throws Exception {
94 runtest("\u00e0\u00e2\u00e4\u00e7\u00e8\u00e9\u00ea\u00eb\u00ee\u00ef\u00f4\u00f6\u00f9\u00fb\u00fc");
95 }
96
97 public void testFrenchAccents2() throws Exception {
98 runtest("Une chaîne avec des caractères accentués");
99 }
100
101 public void testGermanUmlauts() throws Exception {
102 runtest(" Some text \u00df with \u00fc special \u00f6 chars \u00e4.");
103 }
104
105 public void testWelcomeUnicode() throws Exception {
106 // welcome in several languages
107 runtest(
108 "Chinese (trad.) : \u6b61\u8fce ");
109 }
110
111 public void testWelcomeUnicode2() throws Exception {
112 // welcome in several languages
113 runtest(
114 "Greek : \u03ba\u03b1\u03bb\u03ce\u03c2 \u03bf\u03c1\u03af\u03c3\u03b1\u03c4\u03b5");
115 }
116
117 public void testWelcomeUnicode3() throws Exception {
118 // welcome in several languages
119 runtest(
120 "Japanese : \u3088\u3046\u3053\u305d");
121 }
122 }