KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > wsdl > marrays > MArrayTestsServiceTestCase


1 /**
2  * MArrayTestsServiceTestCase.java
3  *
4  * This file was auto-generated from WSDL
5  * by the Apache Axis Wsdl2java emitter.
6  */

7
8 package test.wsdl.marrays;
9
10 import java.util.HashMap JavaDoc;
11 import java.util.Map JavaDoc;
12
13 public class MArrayTestsServiceTestCase extends junit.framework.TestCase {
14     test.wsdl.marrays.MArrayTests binding;
15
16     public MArrayTestsServiceTestCase(String JavaDoc name) {
17         super(name);
18     }
19
20     protected void setUp() throws Exception JavaDoc {
21         super.setUp();
22         binding = new MArrayTestsServiceLocator().getMArrayTests();
23         assertTrue("binding is null", binding != null);
24     }
25
26     public void testMArrayTestsWSDL() throws Exception JavaDoc {
27         javax.xml.rpc.ServiceFactory JavaDoc serviceFactory = javax.xml.rpc.ServiceFactory.newInstance();
28         java.net.URL JavaDoc url = new java.net.URL JavaDoc(new test.wsdl.marrays.MArrayTestsServiceLocator().getMArrayTestsAddress() + "?WSDL");
29         javax.xml.rpc.Service JavaDoc service = serviceFactory.createService(url, new test.wsdl.marrays.MArrayTestsServiceLocator().getServiceName());
30         assertTrue(service != null);
31     }
32
33     public void testMArrayTest1() throws Exception JavaDoc {
34         // In each case below, the elements of the array are either nill, -1 or
35
// i + 10j + 100k
36
// The remote service adds 1000 to each element that is i + 10j + 100k
37
// Test 1: 3-Dim array of values. This could be serialized
38
// as a multi-dimensional array.
39
int[][][] in = new int[3][3][3];
40         int[][][] rc;
41         fill(in);
42         rc = binding.testIntArray(in);
43         assertTrue("Test 1 Failed", validate(in, rc));
44     }
45
46     public void testMArrayTest2() throws Exception JavaDoc {
47         // Test 2: 3-Dim array of values (but one dimension has different lengths or nil).
48
int[][][] in = new int[3][3][];
49         for (int i=0; i<3; i++) {
50             for(int j=1; j<3; j++) {
51                 in[i][j] = new int[i+j];
52             }
53         }
54         int[][][] rc;
55         fill(in);
56         rc = binding.testIntArray(in);
57         assertTrue("Test 2 Failed", validate(in, rc));
58     }
59
60     public void testMArrayTest3() throws Exception JavaDoc {
61         // Test 1F: 3-Dim array of values. This could be serialized
62
// as a multi-dimensional array.
63
Foo[][][] in = new Foo[3][3][3];
64         Foo[][][] rc;
65         fillFoo(in);
66         rc = binding.testFooArray(in);
67         assertTrue("Test 1F Failed", validateFoo(in, rc));
68     }
69
70     public void testMArrayTest4() throws Exception JavaDoc {
71         // Test 2F: 3-Dim array of values (but one dimension has different lengths or nil).
72
Foo[][][] in = new Foo[3][3][];
73         for (int i=0; i<3; i++) {
74             for(int j=1; j<3; j++) {
75                 in[i][j] = new Foo[i+j];
76             }
77         }
78         Foo[][][] rc;
79         fillFoo(in);
80         rc = binding.testFooArray(in);
81         assertTrue("Test 2F Failed", validateFoo(in, rc));
82     }
83
84     public void testMArrayTest5() throws Exception JavaDoc {
85         // Test 3F: Some of the Foo elements are multi-referenced.
86
Foo[][][] in = new Foo[3][3][3];
87         Foo[][][] rc;
88         fillFoo(in);
89         
90         // Diagonals are set to same Foo
91
in[0][0][0] = new Foo();
92         in[0][0][0].setValue(-1);
93         in[1][1][1] = in[0][0][0];
94         in[2][2][2] = in[0][0][0];
95         
96         rc = binding.testFooArray(in);
97         assertTrue("Test 3F Failed (a)", validateFoo(in, rc));
98         assertTrue("Test 3F Failed (b)", rc[0][0][0] == rc[1][1][1]);
99         assertTrue("Test 3F Failed (c)", rc[0][0][0] == rc[2][2][2]);
100     }
101
102     public void testMArrayTest6() throws Exception JavaDoc {
103         // Test 3G: Combination of Foo and DerivedFoo.
104
Foo[][][] in = new Foo[3][3][3];
105         Foo[][][] rc;
106         fillFoo(in);
107         
108         // Diagonals are set to same Foo
109
in[0][0][0] = new DerivedFoo();
110         in[0][0][0].setValue(-1);
111         ((DerivedFoo)in[0][0][0]).setValue2(7);
112         in[1][1][1] = in[0][0][0];
113         in[2][2][2] = in[0][0][0];
114         
115         rc = binding.testFooArray(in);
116         assertTrue("Test 3G Failed (a)", validateFoo(in, rc));
117         assertTrue("Test 3G Failed (b)", rc[0][0][0] == rc[1][1][1]);
118         assertTrue("Test 3G Failed (c)", rc[0][0][0] == rc[2][2][2]);
119         assertTrue("Test 3G Failed (d)", ((DerivedFoo)rc[2][2][2]).getValue2() == 7);
120     }
121     
122         // This test is no longer valid if Axis treats arrays as always single-ref
123
/*
124         try {
125         // Test 4F: Foo arrays are multi-referenced.
126         Foo[][][] in = new Foo[3][3][3];
127         Foo[][][] rc;
128         fillFoo(in);
129         
130         // Same Foo array
131         Foo[] fooArray = new Foo[3];
132         fooArray[0] = new Foo();
133         fooArray[0].setValue(-1);
134         fooArray[1] = new Foo();
135         fooArray[1].setValue(-1);
136         fooArray[2] = new Foo();
137         fooArray[2].setValue(-1);
138         in[0][0] = fooArray;
139         in[1][1] = fooArray;
140         in[2][2] = fooArray;
141         
142         rc = binding.testFooArray(in);
143         assertTrue("Test 4F Failed (a)", validateFoo(in, rc));
144         assertTrue("Test 4F Failed (b)", rc[0][0] == rc[1][1]);
145         assertTrue("Test 4F Failed (c)", rc[0][0] == rc[2][2]);
146         } catch (java.rmi.RemoteException re) {
147         throw new junit.framework.AssertionFailedError("Remote Exception caught: " + re );
148         }
149         */

150
151     public void testMArrayTest7() throws Exception JavaDoc {
152         // Test 3F: Some of the Foo elements are multi-referenced.
153
HashMap JavaDoc map = new HashMap JavaDoc();
154         Foo[] array = new Foo[1];
155         array[0] = new Foo();
156         array[0].setValue(123);
157         map.put("hello", array);
158         
159         Map JavaDoc rc;
160         
161         rc = binding.testMapFooArray(map);
162         assertTrue("Test Map Failed (a)", rc != null);
163         assertTrue("Test Map Failed (b)", rc.get("hello").getClass().isArray());
164         Foo[] rcArray = (Foo[]) rc.get("hello");
165         assertTrue("Test Map Failed (c)", rcArray.length == 1 && rcArray[0].getValue() == 123);
166     }
167
168     public void fill(int[][][] array) {
169         for (int i=0; i < array.length; i++) {
170             int[][] array2 = array[i];
171                 if (array2 != null)
172                     for (int j=0; j < array2.length; j++) {
173                         int[] array3 = array2[j];
174                         if (array3 != null)
175                             for (int k=0; k <array3.length; k++) {
176                                 array3[k] = i + 10*j + 100*k;
177                             }
178                     }
179         }
180     }
181     public boolean validate(int[][][] orig, int[][][] rc) {
182         for (int i=0; i < orig.length; i++) {
183             int[][] array2 = orig[i];
184                 if (array2 != null)
185                     for (int j=0; j < array2.length; j++) {
186                         int[] array3 = array2[j];
187                         if (array3 != null)
188                             for (int k=0; k <array3.length; k++) {
189                                 if ((array3[k] == -1 && rc[i][j][k] == -1) ||
190                                     (array3[k]+1000 == rc[i][j][k]))
191                                     ; // Okay
192
else
193                                     return false;
194                             }
195                     }
196         }
197         return true;
198     }
199     public void fillFoo(Foo[][][] array) {
200         for (int i=0; i < array.length; i++) {
201             Foo[][] array2 = array[i];
202                 if (array2 != null)
203                     for (int j=0; j < array2.length; j++) {
204                         Foo[] array3 = array2[j];
205                         if (array3 != null)
206                             for (int k=0; k <array3.length; k++) {
207                                 if (array3[k] == null)
208                                     array3[k] = new Foo();
209                                 array3[k].setValue(i + 10*j + 100*k);
210                             }
211                     }
212         }
213     }
214     public boolean validateFoo(Foo[][][] orig, Foo[][][] rc) {
215         for (int i=0; i < orig.length; i++) {
216             Foo[][] array2 = orig[i];
217                 if (array2 != null)
218                     for (int j=0; j < array2.length; j++) {
219                         Foo[] array3 = array2[j];
220                         if (array3 != null)
221
222                             for (int k=0; k <array3.length; k++) {
223                                 if ((array3[k].getValue() == -1 && rc[i][j][k].getValue() == -1) ||
224                                     (array3[k].getValue()+1000 == rc[i][j][k].getValue()))
225                                     ; // Okay
226
else
227                                     return false;
228                             }
229                     }
230         }
231         return true;
232     }
233 }
234
235
Popular Tags