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 java.util.ArrayList;
024: import java.util.List;
025:
026: /** Tests the parsing of Generics that are used in the DescriptionBuilderComposite processing. */
027: public class ReturnTypeParsingTests extends TestCase {
028:
029: public void testNonHolderGenric() {
030: String inputString = "java.util.List<org.apache.axis2.jaxws.description.builder.MyReturnTestObject>";
031: MethodDescriptionComposite mdc = new MethodDescriptionComposite();
032: mdc.setReturnType(inputString);
033: assertEquals(
034: "java.util.List<org.apache.axis2.jaxws.description.builder.MyReturnTestObject>",
035: mdc.getReturnType());
036:
037: assertEquals(java.util.List.class, mdc.getReturnTypeClass());
038: }
039:
040: public void testPrimitivesEncoded() {
041: String[] primitivesToTest = { "Z", "B", "C", "D", "F", "I",
042: "J", "S", "V" };
043: Class[] primitiveClasses = { boolean.class, byte.class,
044: char.class, double.class, float.class, int.class,
045: long.class, short.class, void.class };
046:
047: for (int i = 0; i < primitivesToTest.length; i++) {
048: assertNull(DescriptionBuilderUtils
049: .getRawType(primitivesToTest[i]));
050: MethodDescriptionComposite mdc = new MethodDescriptionComposite();
051: mdc.setReturnType(primitivesToTest[i]);
052: assertEquals(primitiveClasses[i], mdc.getReturnTypeClass());
053: }
054: }
055:
056: public void testPrimitives() {
057: String[] primitivesToTest = { "boolean", "byte", "char",
058: "double", "float", "int", "long", "short", "void" };
059: Class[] primitiveClasses = { boolean.class, byte.class,
060: char.class, double.class, float.class, int.class,
061: long.class, short.class, void.class };
062:
063: for (int i = 0; i < primitivesToTest.length; i++) {
064: assertNull(DescriptionBuilderUtils
065: .getRawType(primitivesToTest[i]));
066: MethodDescriptionComposite mdc = new MethodDescriptionComposite();
067: mdc.setReturnType(primitivesToTest[i]);
068: assertEquals(primitiveClasses[i], mdc.getReturnTypeClass());
069: }
070: }
071:
072: public void testPrimitiveArrays() {
073: String[] primitivesToTest = { "boolean[]", "byte[]", "char[]",
074: "double[]", "float[]", "int[]", "long[]", "short[]" };
075: Class[] primitiveClasses = { boolean[].class, byte[].class,
076: char[].class, double[].class, float[].class,
077: int[].class, long[].class, short[].class };
078:
079: for (int i = 0; i < primitivesToTest.length; i++) {
080: MethodDescriptionComposite mdc = new MethodDescriptionComposite();
081: mdc.setReturnType(primitivesToTest[i]);
082: assertEquals(primitiveClasses[i], mdc.getReturnTypeClass());
083: }
084: }
085:
086: public void testPrimitiveMultiDimArrays() {
087: String[] primitivesToTest = { "boolean[][]", "byte[][][]",
088: "char[][][][]", "double[][][][][]",
089: "float[][][][][][]", "int[]", "long[]", "short[]" };
090: Class[] primitiveClasses = { boolean[][].class,
091: byte[][][].class, char[][][][].class,
092: double[][][][][].class, float[][][][][][].class,
093: int[].class, long[].class, short[].class };
094: for (int i = 0; i < primitivesToTest.length; i++) {
095: MethodDescriptionComposite mdc = new MethodDescriptionComposite();
096: mdc.setReturnType(primitivesToTest[i]);
097: assertEquals(primitiveClasses[i], mdc.getReturnTypeClass());
098: }
099: }
100:
101: public void testJavaLangObjectArrays() {
102: MethodDescriptionComposite pdcObject = new MethodDescriptionComposite();
103: pdcObject.setReturnType("java.lang.Object[]");
104: Object[] verifyObject = new Object[5];
105: assertEquals(verifyObject.getClass(), pdcObject
106: .getReturnTypeClass());
107:
108: MethodDescriptionComposite pdcString = new MethodDescriptionComposite();
109: pdcString.setReturnType("java.lang.String[][][]");
110: String[][][] verifyString = new String[5][1][3];
111: assertEquals(verifyString.getClass(), pdcString
112: .getReturnTypeClass());
113:
114: MethodDescriptionComposite pdcInteger = new MethodDescriptionComposite();
115: pdcInteger.setReturnType("java.lang.Integer[][][][]");
116: Integer[][][][] verifyInteger = new Integer[5][1][3][12];
117: assertEquals(verifyInteger.getClass(), pdcInteger
118: .getReturnTypeClass());
119: }
120:
121: public void testMyObjectArray() {
122: MethodDescriptionComposite mdc = new MethodDescriptionComposite();
123: mdc
124: .setReturnType("org.apache.axis2.jaxws.description.builder.MyReturnTestObject[][]");
125: MyReturnTestObject[][] myObject = new MyReturnTestObject[2][3];
126: assertEquals(myObject.getClass(), mdc.getReturnTypeClass());
127: }
128:
129: public void testArrayListOfPrimitiveArray() {
130: MethodDescriptionComposite mdc = new MethodDescriptionComposite();
131: mdc.setReturnType("java.util.ArrayList<byte[]>");
132: assertEquals("java.util.ArrayList<byte[]>", mdc.getReturnType());
133: assertEquals(ArrayList.class, mdc.getReturnTypeClass());
134: }
135:
136: public void testListOfMyObjectArray() {
137: MethodDescriptionComposite mdc = new MethodDescriptionComposite();
138: mdc
139: .setReturnType("java.util.List<org.apache.axis2.jaxws.description.builder.MyReturnTestObject[][]>");
140: assertEquals(
141: "java.util.List<org.apache.axis2.jaxws.description.builder.MyReturnTestObject[][]>",
142: mdc.getReturnType());
143:
144: assertEquals(List.class, mdc.getReturnTypeClass());
145: }
146:
147: public void testGenericArray() {
148: MethodDescriptionComposite mdc = new MethodDescriptionComposite();
149: mdc.setReturnType("java.util.List<java.lang.String[]>[]");
150: assertEquals("java.util.List<java.lang.String[]>[]", mdc
151: .getReturnType());
152: assertEquals(List[].class, mdc.getReturnTypeClass());
153: }
154:
155: public void testGenericArrayMultiDimension() {
156: MethodDescriptionComposite mdc = new MethodDescriptionComposite();
157: mdc
158: .setReturnType("java.util.List<org.apache.axis2.jaxws.description.builder.MyReturnTestObject>[][]");
159: assertEquals(
160: "java.util.List<org.apache.axis2.jaxws.description.builder.MyReturnTestObject>[][]",
161: mdc.getReturnType());
162: assertEquals(List[][].class, mdc.getReturnTypeClass());
163: }
164:
165: public void testWildcardGenericArray() {
166: MethodDescriptionComposite mdc = new MethodDescriptionComposite();
167: mdc.setReturnType("java.util.List<?>[]");
168: assertEquals("java.util.List<?>[]", mdc.getReturnType());
169: assertEquals(List[].class, mdc.getReturnTypeClass());
170: }
171:
172: }
173:
174: class MyReturnTestObject {
175:
176: }
|