001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.jaxws.description.builder;
020:
021: import junit.framework.TestCase;
022:
023: import javax.xml.ws.Holder;
024: import java.util.List;
025:
026: /** Tests the parsing of Generics that are used in the DescriptionBuilderComposite processing. */
027: public class ParameterParsingTests extends TestCase {
028:
029: public void testHolder() {
030: String holderInputString = "javax.xml.ws.Holder<java.lang.Object>";
031: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
032: pdc.setParameterType(holderInputString);
033: assertEquals("javax.xml.ws.Holder<java.lang.Object>", pdc
034: .getParameterType());
035:
036: assertTrue(DescriptionBuilderUtils
037: .isHolderType(holderInputString));
038: assertTrue(pdc.isHolderType());
039: String holderResultString = DescriptionBuilderUtils
040: .getRawType(holderInputString);
041: assertEquals("javax.xml.ws.Holder", holderResultString);
042: holderResultString = pdc.getRawType();
043: assertEquals("javax.xml.ws.Holder", holderResultString);
044: javax.xml.ws.Holder validateHolder = new javax.xml.ws.Holder();
045: assertEquals(validateHolder.getClass(), pdc
046: .getParameterTypeClass());
047:
048: String actualTypeResult = DescriptionBuilderUtils
049: .getHolderActualType(holderInputString);
050: assertEquals("java.lang.Object", actualTypeResult);
051: actualTypeResult = pdc.getHolderActualType();
052: assertEquals("java.lang.Object", actualTypeResult);
053: java.lang.Object validateObject = new java.lang.Object();
054: assertEquals(validateObject.getClass(), pdc
055: .getHolderActualTypeClass());
056: }
057:
058: public void testHolderMyObject() {
059: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
060: pdc
061: .setParameterType("javax.xml.ws.Holder<org.apache.axis2.jaxws.description.builder.MyObject>");
062: assertEquals(
063: "javax.xml.ws.Holder<org.apache.axis2.jaxws.description.builder.MyObject>",
064: pdc.getParameterType());
065:
066: assertTrue(pdc.isHolderType());
067: assertEquals("javax.xml.ws.Holder", pdc.getRawType());
068: assertEquals(Holder.class, pdc.getParameterTypeClass());
069:
070: assertEquals(
071: "org.apache.axis2.jaxws.description.builder.MyObject",
072: pdc.getHolderActualType());
073: assertEquals(MyObject.class, pdc.getHolderActualTypeClass());
074: }
075:
076: public void testNonHolderGenric() {
077: String inputString = "java.util.List<org.apache.axis2.jaxws.description.builder.MyObject>";
078: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
079: pdc.setParameterType(inputString);
080: assertEquals(
081: "java.util.List<org.apache.axis2.jaxws.description.builder.MyObject>",
082: pdc.getParameterType());
083:
084: assertFalse(pdc.isHolderType());
085: String genericType = pdc.getRawType();
086: assertEquals("java.util.List", genericType);
087: assertEquals(java.util.List.class, pdc.getParameterTypeClass());
088:
089: // This should be null since the generic is not a Holder type
090: String actualParam = pdc.getHolderActualType();
091: assertNull(actualParam);
092: assertNull(pdc.getHolderActualTypeClass());
093: }
094:
095: public void testHolderGeneric() {
096: String holderInputString = "javax.xml.ws.Holder<java.util.List<java.lang.Object>>";
097: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
098: pdc.setParameterType(holderInputString);
099: assertEquals(
100: "javax.xml.ws.Holder<java.util.List<java.lang.Object>>",
101: pdc.getParameterType());
102:
103: assertTrue(pdc.isHolderType());
104: String holderResultString = pdc.getRawType();
105: assertEquals("javax.xml.ws.Holder", holderResultString);
106: assertEquals(Holder.class, pdc.getParameterTypeClass());
107:
108: String actualTypeResult = pdc.getHolderActualType();
109: assertEquals("java.util.List", actualTypeResult);
110: assertEquals(List.class, pdc.getHolderActualTypeClass());
111: }
112:
113: public void testPrimitivesEncoded() {
114: String[] primitivesToTest = { "Z", "B", "C", "D", "F", "I",
115: "J", "S", "V" };
116: Class[] primitiveClasses = { boolean.class, byte.class,
117: char.class, double.class, float.class, int.class,
118: long.class, short.class, void.class };
119:
120: for (int i = 0; i < primitivesToTest.length; i++) {
121: assertFalse(DescriptionBuilderUtils
122: .isHolderType(primitivesToTest[i]));
123: assertNull(DescriptionBuilderUtils
124: .getRawType(primitivesToTest[i]));
125: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
126: pdc.setParameterType(primitivesToTest[i]);
127: assertEquals(primitiveClasses[i], pdc
128: .getParameterTypeClass());
129: }
130: }
131:
132: public void testPrimitives() {
133: String[] primitivesToTest = { "boolean", "byte", "char",
134: "double", "float", "int", "long", "short", "void" };
135: Class[] primitiveClasses = { boolean.class, byte.class,
136: char.class, double.class, float.class, int.class,
137: long.class, short.class, void.class };
138:
139: for (int i = 0; i < primitivesToTest.length; i++) {
140: assertFalse(DescriptionBuilderUtils
141: .isHolderType(primitivesToTest[i]));
142: assertNull(DescriptionBuilderUtils
143: .getRawType(primitivesToTest[i]));
144: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
145: pdc.setParameterType(primitivesToTest[i]);
146: assertEquals(primitiveClasses[i], pdc
147: .getParameterTypeClass());
148: }
149: }
150:
151: public void testPrimitiveArrays() {
152: String[] primitivesToTest = { "boolean[]", "byte[]", "char[]",
153: "double[]", "float[]", "int[]", "long[]", "short[]" };
154: Class[] primitiveClasses = { boolean[].class, byte[].class,
155: char[].class, double[].class, float[].class,
156: int[].class, long[].class, short[].class };
157:
158: for (int i = 0; i < primitivesToTest.length; i++) {
159: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
160: pdc.setParameterType(primitivesToTest[i]);
161: assertEquals(primitiveClasses[i], pdc
162: .getParameterTypeClass());
163: }
164: }
165:
166: public void testPrimitiveMultiDimArrays() {
167: String[] primitivesToTest = { "boolean[][]", "byte[][][]",
168: "char[][][][]", "double[][][][][]",
169: "float[][][][][][]", "int[]", "long[]", "short[]" };
170: Class[] primitiveClasses = { boolean[][].class,
171: byte[][][].class, char[][][][].class,
172: double[][][][][].class, float[][][][][][].class,
173: int[].class, long[].class, short[].class };
174: for (int i = 0; i < primitivesToTest.length; i++) {
175: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
176: pdc.setParameterType(primitivesToTest[i]);
177: assertEquals(primitiveClasses[i], pdc
178: .getParameterTypeClass());
179: }
180: }
181:
182: public void testJavaLangObjectArrays() {
183: ParameterDescriptionComposite pdcObject = new ParameterDescriptionComposite();
184: pdcObject.setParameterType("java.lang.Object[]");
185: Object[] verifyObject = new Object[5];
186: assertEquals(verifyObject.getClass(), pdcObject
187: .getParameterTypeClass());
188:
189: ParameterDescriptionComposite pdcString = new ParameterDescriptionComposite();
190: pdcString.setParameterType("java.lang.String[][][]");
191: String[][][] verifyString = new String[5][1][3];
192: assertEquals(verifyString.getClass(), pdcString
193: .getParameterTypeClass());
194:
195: ParameterDescriptionComposite pdcInteger = new ParameterDescriptionComposite();
196: pdcInteger.setParameterType("java.lang.Integer[][][][]");
197: Integer[][][][] verifyInteger = new Integer[5][1][3][12];
198: assertEquals(verifyInteger.getClass(), pdcInteger
199: .getParameterTypeClass());
200: }
201:
202: public void testMyObjectArray() {
203: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
204: pdc
205: .setParameterType("org.apache.axis2.jaxws.description.builder.MyObject[][]");
206: MyObject[][] myObject = new MyObject[2][3];
207: assertEquals(myObject.getClass(), pdc.getParameterTypeClass());
208: }
209:
210: public void testHolderOfPrimitiveArray() {
211: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
212: pdc.setParameterType("javax.xml.ws.Holder<byte[]>");
213: assertEquals("javax.xml.ws.Holder<byte[]>", pdc
214: .getParameterType());
215:
216: assertEquals(Holder.class, pdc.getParameterTypeClass());
217: byte[] validateByteArray = new byte[10];
218: assertEquals(validateByteArray.getClass(), pdc
219: .getHolderActualTypeClass());
220: }
221:
222: public void testHolderOfMyObjectArray() {
223: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
224: pdc
225: .setParameterType("javax.xml.ws.Holder<org.apache.axis2.jaxws.description.builder.MyObject[][]>");
226: assertEquals(
227: "javax.xml.ws.Holder<org.apache.axis2.jaxws.description.builder.MyObject[][]>",
228: pdc.getParameterType());
229: assertEquals(Holder.class, pdc.getParameterTypeClass());
230: MyObject[][] validateMyObject = new MyObject[5][10];
231: assertEquals(validateMyObject.getClass(), pdc
232: .getHolderActualTypeClass());
233: }
234:
235: public void testHolderOfStringArray() {
236: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
237: pdc.setParameterType("javax.xml.ws.Holder<java.lang.String[]>");
238: assertEquals("javax.xml.ws.Holder<java.lang.String[]>", pdc
239: .getParameterType());
240: assertEquals(String[].class, pdc.getHolderActualTypeClass());
241: }
242:
243: public void testStringArray() {
244: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
245: pdc.setParameterType("java.lang.String[]");
246: assertEquals("java.lang.String[]", pdc.getParameterType());
247: assertEquals(String[].class, pdc.getParameterTypeClass());
248: }
249:
250: public void testHolderOfGenericArray() {
251: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
252: pdc
253: .setParameterType("javax.xml.ws.Holder<java.util.List<java.lang.String>[]>");
254: assertEquals(
255: "javax.xml.ws.Holder<java.util.List<java.lang.String>[]>",
256: pdc.getParameterType());
257: assertEquals(List[].class, pdc.getHolderActualTypeClass());
258: }
259:
260: public void testHolderOfGenericArrayMultiDimension() {
261: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
262: pdc
263: .setParameterType("javax.xml.ws.Holder<java.util.List<java.lang.String>[][][]>");
264: assertEquals(
265: "javax.xml.ws.Holder<java.util.List<java.lang.String>[][][]>",
266: pdc.getParameterType());
267: assertEquals(List[][][].class, pdc.getHolderActualTypeClass());
268: }
269:
270: public void testHolderOfGenericWildcardArray() {
271: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
272: pdc
273: .setParameterType("javax.xml.ws.Holder<java.util.List<?>[]>");
274: assertEquals("javax.xml.ws.Holder<java.util.List<?>[]>", pdc
275: .getParameterType());
276: assertEquals(List[].class, pdc.getHolderActualTypeClass());
277: }
278:
279: public void testGenericArray() {
280: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
281: pdc.setParameterType("java.util.List<java.lang.String>[]");
282: assertEquals("java.util.List<java.lang.String>[]", pdc
283: .getParameterType());
284: assertEquals(List[].class, pdc.getParameterTypeClass());
285: }
286:
287: public void testGenericArrayMultiDimension() {
288: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
289: pdc.setParameterType("java.util.List<java.lang.String>[][]");
290: assertEquals("java.util.List<java.lang.String>[][]", pdc
291: .getParameterType());
292: assertEquals(List[][].class, pdc.getParameterTypeClass());
293: }
294:
295: public void testGenericWildCardArray() {
296: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
297: pdc.setParameterType("java.util.List<?>[]");
298: assertEquals("java.util.List<?>[]", pdc.getParameterType());
299: assertEquals(List[].class, pdc.getParameterTypeClass());
300: }
301:
302: public void testGenericArrayOfStringArray() {
303: ParameterDescriptionComposite pdc = new ParameterDescriptionComposite();
304: pdc.setParameterType("java.util.List<java.lang.String[]>[]");
305: assertEquals("java.util.List<java.lang.String[]>[]", pdc
306: .getParameterType());
307: assertEquals(List[].class, pdc.getParameterTypeClass());
308: }
309: }
310:
311: class MyObject {
312:
313: }
|