01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.tools.common.model;
19:
20: import org.junit.Assert;
21: import org.junit.Test;
22:
23: public class JavaClassTest extends Assert {
24: @Test
25: public void testGetterSetter() throws Exception {
26: JavaField field = new JavaField(
27: "arg0",
28: "org.apache.cxf.tools.fortest.withannotation.doc.TestDataBean",
29: "http://doc.withannotation.fortest.tools.cxf.apache.org/");
30: JavaClass clz = new JavaClass();
31: clz
32: .setFullClassName("org.apache.cxf.tools.fortest.withannotation.doc.jaxws.EchoDataBean");
33: JavaMethod getter = clz.appendGetter(field);
34: assertEquals("getArg0", getter.getName());
35: assertEquals(
36: "org.apache.cxf.tools.fortest.withannotation.doc.TestDataBean",
37: getter.getReturn().getClassName());
38: assertEquals("arg0", getter.getReturn().getName());
39:
40: JavaMethod setter = clz.appendSetter(field);
41: assertEquals("setArg0", setter.getName());
42: assertEquals("void", setter.getReturn().getClassName());
43: assertEquals("arg0", getter.getReturn().getName());
44: assertEquals(
45: "org.apache.cxf.tools.fortest.withannotation.doc.TestDataBean",
46: setter.getParameters().get(0).getClassName());
47: }
48:
49: @Test
50: public void testGetterSetterStringArray() {
51: JavaField field = new JavaField("array", "String[]",
52: "http://doc.withannotation.fortest.tools.cxf.apache.org/");
53:
54: JavaClass clz = new JavaClass();
55: clz
56: .setFullClassName("org.apache.cxf.tools.fortest.withannotation.doc.jaxws.SayHi");
57: JavaMethod getter = clz.appendGetter(field);
58: assertEquals("getArray", getter.getName());
59: assertEquals("String[]", getter.getReturn().getClassName());
60: assertEquals("array", getter.getReturn().getName());
61: assertEquals("return this.array;", getter.getJavaCodeBlock()
62: .getExpressions().get(0).toString());
63:
64: JavaMethod setter = clz.appendSetter(field);
65: assertEquals("setArray", setter.getName());
66: assertEquals("void", setter.getReturn().getClassName());
67: assertEquals("array", getter.getReturn().getName());
68: assertEquals("String[]", setter.getParameters().get(0)
69: .getClassName());
70: assertEquals("this.array = newArray;", setter
71: .getJavaCodeBlock().getExpressions().get(0).toString());
72:
73: field = new JavaField("return", "String[]",
74: "http://doc.withannotation.fortest.tools.cxf.apache.org/");
75: clz = new JavaClass();
76: clz
77: .setFullClassName("org.apache.cxf.tools.fortest.withannotation.doc.jaxws.SayHiResponse");
78: getter = clz.appendGetter(field);
79: assertEquals("get_return", getter.getName());
80: assertEquals("String[]", getter.getReturn().getClassName());
81: assertEquals("_return", getter.getReturn().getName());
82:
83: setter = clz.appendSetter(field);
84: assertEquals("set_return", setter.getName());
85: assertEquals("void", setter.getReturn().getClassName());
86: assertEquals("_return", getter.getReturn().getName());
87: assertEquals("String[]", setter.getParameters().get(0)
88: .getClassName());
89: }
90: }
|