| 1 |
/** |
| 2 |
* MapServiceServiceTestCase.java |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
package test.wsdl.map; |
| 7 |
|
| 8 |
import java.util.Map; |
| 9 |
import java.util.HashMap; |
| 10 |
|
| 11 |
public class MapServiceTestCase extends junit.framework.TestCase { |
| 12 |
public MapServiceTestCase(java.lang.String name) { |
| 13 |
super(name); |
| 14 |
} |
| 15 |
public void test1EchoMap() throws Exception { |
| 16 |
test.wsdl.map.MapService binding; |
| 17 |
try { |
| 18 |
binding = new MapServiceServiceLocator().getMapService(); |
| 19 |
} |
| 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); |
| 24 |
} |
| 25 |
assertTrue("binding is null", binding != null); |
| 26 |
|
| 27 |
// populate test data |
| 28 |
HashMap m = new HashMap(); |
| 29 |
String stringKey = "stringKey"; |
| 30 |
String stringVal = "stringValue"; |
| 31 |
m.put(stringKey, stringVal); |
| 32 |
|
| 33 |
Integer intKey = new Integer(77); |
| 34 |
Double doubleVal = new Double(3.14159); |
| 35 |
m.put(intKey, doubleVal); |
| 36 |
|
| 37 |
Long longKey = new Long("1231231231"); |
| 38 |
Boolean boolVal = new Boolean(true); |
| 39 |
m.put(longKey, boolVal); |
| 40 |
|
| 41 |
String[] stringArrayKey = new String[] {"array1", "array2"}; |
| 42 |
Integer[] intArray = new Integer[] {new Integer(1), new Integer(2)}; |
| 43 |
m.put(stringArrayKey, intArray ); |
| 44 |
|
| 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); |
| 48 |
|
| 49 |
// Test operation |
| 50 |
Map outMap = binding.echoMap(m); |
| 51 |
|
| 52 |
// Verify return map |
| 53 |
Object value; |
| 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); |
| 58 |
|
| 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); |
| 63 |
|
| 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); |
| 68 |
|
| 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; |
| 73 |
while (it.hasNext()) |
| 74 |
{ |
| 75 |
Object oKey = it.next(); |
| 76 |
if (oKey.getClass().isArray()) |
| 77 |
{ |
| 78 |
Object[] oArrayKey = (Object[]) oKey; |
| 79 |
Object oValue = outMap.get(oKey); |
| 80 |
|
| 81 |
if (String.class.getName().equals(oArrayKey[0].getClass().getName())) |
| 82 |
{ |
| 83 |
// Verify Key data |
| 84 |
String[] sArray = (String[]) oArrayKey; |
| 85 |
for (int i = 0; i < sArray.length; i++) |
| 86 |
{ |
| 87 |
assertEquals("STRING Array KEY data does not match", stringArrayKey[i], sArray[i]); |
| 88 |
} |
| 89 |
|
| 90 |
// verify value data |
| 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++) |
| 96 |
{ |
| 97 |
assertEquals("INTEGER Array VALUE does not match", intArray[i], ia[i]); |
| 98 |
} |
| 99 |
foundInt = true; |
| 100 |
} |
| 101 |
else if (Long.class.getName().equals(oArrayKey[0].getClass().getName())) |
| 102 |
{ |
| 103 |
// verify Key data |
| 104 |
Long[] lArray = (Long[]) oArrayKey; |
| 105 |
for (int i = 0; i < lArray.length; i++) |
| 106 |
{ |
| 107 |
assertEquals("LONG Array KEY data does not match", longArrayKey[i], lArray[i]); |
| 108 |
|
| 109 |
} |
| 110 |
// verify value data |
| 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++) |
| 116 |
{ |
| 117 |
assertEquals("BOOLEAN Array VALUE does not match", boolArray[i], ba[i]); |
| 118 |
} |
| 119 |
foundBool = true; |
| 120 |
} |
| 121 |
|
| 122 |
} |
| 123 |
} |
| 124 |
if (!foundInt || ! foundBool) |
| 125 |
{ |
| 126 |
assertTrue("Unable to find integer or boolean key in returned Map", false); |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
} |