2
* MapServiceServiceTestCase.java
9
import java.util.HashMap;
11
public class MapServiceTestCase extends junit.framework.TestCase {
12
public MapServiceTestCase(java.lang.String name) {
15
public void test1EchoMap() throws Exception {
16
test.wsdl.map.MapService binding;
18
binding = new MapServiceServiceLocator().getMapService();
20
catch (javax.xml.rpc.ServiceException jre) {
21
if(jre.getLinkedCause()!=null)
22
jre.getLinkedCause().printStackTrace();
23
throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
25
assertTrue("binding is null", binding != null);
28
HashMap m = new HashMap();
29
String stringKey = "stringKey";
30
String stringVal = "stringValue";
31
m.put(stringKey, stringVal);
33
Integer intKey = new Integer(77);
34
Double doubleVal = new Double(3.14159);
35
m.put(intKey, doubleVal);
37
Long longKey = new Long("1231231231");
38
Boolean boolVal = new Boolean(true);
39
m.put(longKey, boolVal);
41
String[] stringArrayKey = new String[] {"array1", "array2"};
42
Integer[] intArray = new Integer[] {new Integer(1), new Integer(2)};
43
m.put(stringArrayKey, intArray );
45
Long[] longArrayKey = new Long[] {new Long("1000001"), new Long(2000002)};
46
Boolean[] boolArray = new Boolean[]{ new Boolean(true), new Boolean(false)};
47
m.put(longArrayKey, boolArray);
50
Map outMap = binding.echoMap(m);
54
value = outMap.get(stringKey);
55
assertNotNull("Can not find entry for STRING key", value);
56
assertEquals("The class of the map value does not match", String.class.getName(), value.getClass().getName());
57
assertEquals("The value does not match", stringVal, (String) value);
59
value = outMap.get(intKey);
60
assertNotNull("Can not find entry for INTEGER key", value);
61
assertEquals("The class of the map value does not match", Double.class.getName(), value.getClass().getName());
62
assertEquals("The value does not match", (Double) value, doubleVal);
64
value = outMap.get(longKey);
65
assertNotNull("Can not find entry for LONG key", value);
66
assertEquals("The class of the map value does not match", Boolean.class.getName(), value.getClass().getName());
67
assertEquals("The value does not match", boolVal, (Boolean) value);
69
// This is a pain because a get with the orignal keys wont return entries in the new map
70
java.util.Iterator it = outMap.keySet().iterator();
71
boolean foundInt = false;
72
boolean foundBool = false;
75
Object oKey = it.next();
76
if (oKey.getClass().isArray())
78
Object[] oArrayKey = (Object[]) oKey;
79
Object oValue = outMap.get(oKey);
81
if (String.class.getName().equals(oArrayKey[0].getClass().getName()))
84
String[] sArray = (String[]) oArrayKey;
85
for (int i = 0; i < sArray.length; i++)
87
assertEquals("STRING Array KEY data does not match", stringArrayKey[i], sArray[i]);
91
assertTrue("The Array VALUE does not match", oValue.getClass().isArray());
92
Object[] oArrayValue = (Object[]) oValue;
93
assertEquals("Class of the array does not match epected", Integer.class.getName(), oArrayValue[0].getClass().getName());
94
Integer[] ia = (Integer[]) oValue;
95
for (int i = 0; i < ia.length; i++)
97
assertEquals("INTEGER Array VALUE does not match", intArray[i], ia[i]);
101
else if (Long.class.getName().equals(oArrayKey[0].getClass().getName()))
104
Long[] lArray = (Long[]) oArrayKey;
105
for (int i = 0; i < lArray.length; i++)
107
assertEquals("LONG Array KEY data does not match", longArrayKey[i], lArray[i]);
111
assertTrue("The Array VALUE does not match", oValue.getClass().isArray());
112
Object[] oArrayValue = (Object[]) oValue;
113
assertEquals("Class of the array does not match epected", Boolean.class.getName(), oArrayValue[0].getClass().getName());
114
Boolean[] ba = (Boolean[]) oValue;
115
for (int i = 0; i < ba.length; i++)
117
assertEquals("BOOLEAN Array VALUE does not match", boolArray[i], ba[i]);
124
if (!foundInt || ! foundBool)
126
assertTrue("Unable to find integer or boolean key in returned Map", false);