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: */package org.apache.cxf.aegis.type.java5;
019:
020: import java.beans.Introspector;
021: import java.beans.PropertyDescriptor;
022: import java.lang.reflect.Method;
023: import java.util.Collection;
024: import java.util.Map;
025: import java.util.Set;
026:
027: import javax.xml.namespace.QName;
028:
029: import org.apache.cxf.aegis.AbstractAegisTest;
030: import org.apache.cxf.aegis.type.Configuration;
031: import org.apache.cxf.aegis.type.CustomTypeMapping;
032: import org.apache.cxf.aegis.type.Type;
033: import org.apache.cxf.aegis.type.collection.CollectionType;
034: import org.apache.cxf.aegis.type.collection.MapType;
035: import org.apache.cxf.aegis.type.java5.dto.MapDTO;
036: import org.apache.cxf.aegis.type.java5.dto.MapDTOService;
037: import org.junit.Before;
038: import org.junit.Test;
039:
040: public class MapTest extends AbstractAegisTest {
041: private CustomTypeMapping tm;
042: private Java5TypeCreator creator;
043:
044: @Before
045: public void setUp() throws Exception {
046: super .setUp();
047:
048: tm = new CustomTypeMapping();
049: creator = new Java5TypeCreator();
050: creator.setConfiguration(new Configuration());
051: tm.setTypeCreator(creator);
052: }
053:
054: @SuppressWarnings("unchecked")
055: @Test
056: public void testType() throws Exception {
057: Method m = MapService.class.getMethod("getMap", new Class[0]);
058:
059: Type type = creator.createType(m, -1);
060: tm.register(type);
061: assertTrue(type instanceof MapType);
062:
063: MapType mapType = (MapType) type;
064: QName keyName = mapType.getKeyName();
065: assertNotNull(keyName);
066:
067: type = mapType.getKeyType();
068: assertNotNull(type);
069: assertTrue(type.getTypeClass().isAssignableFrom(String.class));
070:
071: type = mapType.getValueType();
072: assertNotNull(type);
073: assertTrue(type.getTypeClass().isAssignableFrom(Integer.class));
074: }
075:
076: @Test
077: public void testRecursiveType() throws Exception {
078: Method m = MapService.class.getMethod("getMapOfCollections",
079: new Class[0]);
080:
081: Type type = creator.createType(m, -1);
082: tm.register(type);
083: assertTrue(type instanceof MapType);
084:
085: MapType mapType = (MapType) type;
086: QName keyName = mapType.getKeyName();
087: assertNotNull(keyName);
088:
089: type = mapType.getKeyType();
090: assertNotNull(type);
091: assertTrue(type instanceof CollectionType);
092: assertEquals(String.class, ((CollectionType) type)
093: .getComponentType().getTypeClass());
094:
095: type = mapType.getValueType();
096: assertNotNull(type);
097: assertTrue(type instanceof CollectionType);
098: assertEquals(Double.class, ((CollectionType) type)
099: .getComponentType().getTypeClass());
100: }
101:
102: @SuppressWarnings("unchecked")
103: @Test
104: public void testPDType() throws Exception {
105: PropertyDescriptor pd = Introspector.getBeanInfo(MapDTO.class,
106: Object.class).getPropertyDescriptors()[0];
107: Type type = creator.createType(pd);
108: tm.register(type);
109: assertTrue(type instanceof MapType);
110:
111: MapType mapType = (MapType) type;
112: QName keyName = mapType.getKeyName();
113: assertNotNull(keyName);
114:
115: type = mapType.getKeyType();
116: assertNotNull(type);
117: assertTrue(type.getTypeClass().isAssignableFrom(String.class));
118:
119: type = mapType.getValueType();
120: assertNotNull(type);
121: assertTrue(type.getTypeClass().isAssignableFrom(Integer.class));
122: }
123:
124: @SuppressWarnings("unchecked")
125: @Test
126: public void testMapDTO() {
127: tm = new CustomTypeMapping();
128: creator = new Java5TypeCreator();
129: creator.setConfiguration(new Configuration());
130: tm.setTypeCreator(creator);
131:
132: Type dto = creator.createType(MapDTO.class);
133: Set deps = dto.getDependencies();
134:
135: Type type = (Type) deps.iterator().next();
136: assertTrue(type instanceof MapType);
137:
138: MapType mapType = (MapType) type;
139:
140: deps = dto.getDependencies();
141: assertEquals(1, deps.size());
142:
143: type = mapType.getKeyType();
144: assertNotNull(type);
145: assertTrue(type.getTypeClass().isAssignableFrom(String.class));
146:
147: type = mapType.getValueType();
148: assertNotNull(type);
149: assertTrue(type.getTypeClass().isAssignableFrom(Integer.class));
150: }
151:
152: @Test
153: public void testMapDTOService() throws Exception {
154: createService(MapDTOService.class, null);
155:
156: invoke("MapDTOService",
157: "/org/apache/cxf/aegis/type/java5/dto/GetDTO.xml");
158: }
159:
160: @Test
161: public void testMapServiceWSDL() throws Exception {
162: createService(MapDTOService.class, null);
163:
164: getWSDLDocument("MapDTOService");
165: }
166:
167: public class MapService {
168: public Map<String, Integer> getMap() {
169: return null;
170: }
171:
172: public void setMap(Map<String, Integer> strings) {
173:
174: }
175:
176: public Map<Collection<String>, Collection<Double>> getMapOfCollections() {
177: return null;
178: }
179: }
180: }
|