KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > annotations > TestParameterAnnotationWorker


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.annotations;
16
17 import java.lang.reflect.Method JavaDoc;
18
19 import org.apache.hivemind.Location;
20 import org.apache.tapestry.enhance.EnhancementOperation;
21 import org.apache.tapestry.spec.ComponentSpecification;
22 import org.apache.tapestry.spec.IComponentSpecification;
23 import org.apache.tapestry.spec.IParameterSpecification;
24 import org.easymock.MockControl;
25
26 /**
27  * Tests for {@link org.apache.tapestry.annotations.ParameterAnnotationWorker}.
28  *
29  * @author Howard Lewis Ship
30  * @since 4.0
31  */

32 public class TestParameterAnnotationWorker extends BaseAnnotationTestCase
33 {
34     private IParameterSpecification attempt(String JavaDoc propertyName, Location location)
35     {
36         return attempt(propertyName, propertyName, location);
37     }
38
39     private IParameterSpecification attempt(String JavaDoc propertyName, String JavaDoc parameterName,
40             Location location)
41     {
42         Method JavaDoc m = findMethod(AnnotatedPage.class, "get"
43                 + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1));
44
45         MockControl opc = newControl(EnhancementOperation.class);
46         EnhancementOperation op = (EnhancementOperation) opc.getMock();
47
48         op.getPropertyType(propertyName);
49         opc.setReturnValue(m.getReturnType());
50
51         IComponentSpecification spec = new ComponentSpecification();
52
53         replayControls();
54
55         new ParameterAnnotationWorker().performEnhancement(op, spec, m, location);
56
57         verifyControls();
58
59         return spec.getParameter(parameterName);
60     }
61
62     public void testSimple()
63     {
64         Location l = newLocation();
65
66         IParameterSpecification ps = attempt("simpleParameter", l);
67
68         assertListsEqual(new Object JavaDoc[] {}, ps.getAliasNames().toArray());
69         assertEquals(true, ps.getCache());
70         assertEquals(null, ps.getDefaultBindingType());
71         assertEquals(null, ps.getDefaultValue());
72         assertEquals(null, ps.getDescription());
73         assertSame(l, ps.getLocation());
74         assertEquals("simpleParameter", ps.getParameterName());
75         assertEquals("simpleParameter", ps.getPropertyName());
76         assertEquals("java.lang.String", ps.getType());
77     }
78
79     public void testRequired()
80     {
81         IParameterSpecification ps = attempt("requiredParameter", null);
82
83         assertEquals(true, ps.isRequired());
84     }
85
86     public void testDefaultBinding()
87     {
88         IParameterSpecification ps = attempt("beanDefaultParameter", null);
89
90         assertEquals("bean", ps.getDefaultBindingType());
91         assertEquals("java.lang.Object", ps.getType());
92     }
93
94     public void testCacheOff()
95     {
96         IParameterSpecification ps = attempt("nonCachedParameter", null);
97
98         assertEquals(false, ps.getCache());
99     }
100
101     public void testAliases()
102     {
103         IParameterSpecification ps = attempt("aliasedParameter", null);
104
105         assertListsEqual(new String JavaDoc[]
106         { "fred" }, ps.getAliasNames().toArray());
107     }
108
109     public void testDeprecated()
110     {
111         IParameterSpecification ps = attempt("deprecatedParameter", null);
112         assertEquals(true, ps.isDeprecated());
113     }
114
115     public void testNamed()
116     {
117         IParameterSpecification ps = attempt("namedParameter", "fred", null);
118
119         assertEquals("fred", ps.getParameterName());
120         assertEquals("namedParameter", ps.getPropertyName());
121     }
122 }
123
Popular Tags