KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > wsdl > map > MapServiceTestCase


1 /**
2  * MapServiceServiceTestCase.java
3  *
4  */

5
6 package test.wsdl.map;
7
8 import java.util.Map JavaDoc;
9 import java.util.HashMap JavaDoc;
10
11 public class MapServiceTestCase extends junit.framework.TestCase {
12     public MapServiceTestCase(java.lang.String JavaDoc name) {
13         super(name);
14     }
15     public void test1EchoMap() throws Exception JavaDoc {
16         test.wsdl.map.MapService binding;
17         try {
18             binding = new MapServiceServiceLocator().getMapService();
19         }
20         catch (javax.xml.rpc.ServiceException JavaDoc 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 JavaDoc m = new HashMap JavaDoc();
29         String JavaDoc stringKey = "stringKey";
30         String JavaDoc stringVal = "stringValue";
31         m.put(stringKey, stringVal);
32
33         Integer JavaDoc intKey = new Integer JavaDoc(77);
34         Double JavaDoc doubleVal = new Double JavaDoc(3.14159);
35         m.put(intKey, doubleVal);
36
37         Long JavaDoc longKey = new Long JavaDoc("1231231231");
38         Boolean JavaDoc boolVal = new Boolean JavaDoc(true);
39         m.put(longKey, boolVal);
40
41         String JavaDoc[] stringArrayKey = new String JavaDoc[] {"array1", "array2"};
42         Integer JavaDoc[] intArray = new Integer JavaDoc[] {new Integer JavaDoc(1), new Integer JavaDoc(2)};
43         m.put(stringArrayKey, intArray );
44
45         Long JavaDoc[] longArrayKey = new Long JavaDoc[] {new Long JavaDoc("1000001"), new Long JavaDoc(2000002)};
46         Boolean JavaDoc[] boolArray = new Boolean JavaDoc[]{ new Boolean JavaDoc(true), new Boolean JavaDoc(false)};
47         m.put(longArrayKey, boolArray);
48
49         // Test operation
50
Map JavaDoc outMap = binding.echoMap(m);
51
52         // Verify return map
53
Object JavaDoc 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 JavaDoc.class.getName(), value.getClass().getName());
57         assertEquals("The value does not match", stringVal, (String JavaDoc) 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 JavaDoc.class.getName(), value.getClass().getName());
62         assertEquals("The value does not match", (Double JavaDoc) 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 JavaDoc.class.getName(), value.getClass().getName());
67         assertEquals("The value does not match", boolVal, (Boolean JavaDoc) 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 JavaDoc it = outMap.keySet().iterator();
71         boolean foundInt = false;
72         boolean foundBool = false;
73         while (it.hasNext())
74         {
75             Object JavaDoc oKey = it.next();
76             if (oKey.getClass().isArray())
77             {
78                 Object JavaDoc[] oArrayKey = (Object JavaDoc[]) oKey;
79                 Object JavaDoc oValue = outMap.get(oKey);
80
81                 if (String JavaDoc.class.getName().equals(oArrayKey[0].getClass().getName()))
82                 {
83                     // Verify Key data
84
String JavaDoc[] sArray = (String JavaDoc[]) 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 JavaDoc[] oArrayValue = (Object JavaDoc[]) oValue;
93                     assertEquals("Class of the array does not match epected", Integer JavaDoc.class.getName(), oArrayValue[0].getClass().getName());
94                     Integer JavaDoc[] ia = (Integer JavaDoc[]) 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 JavaDoc.class.getName().equals(oArrayKey[0].getClass().getName()))
102                 {
103                     // verify Key data
104
Long JavaDoc[] lArray = (Long JavaDoc[]) 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 JavaDoc[] oArrayValue = (Object JavaDoc[]) oValue;
113                     assertEquals("Class of the array does not match epected", Boolean JavaDoc.class.getName(), oArrayValue[0].getClass().getName());
114                     Boolean JavaDoc[] ba = (Boolean JavaDoc[]) 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 }
131
Popular Tags