KickJava   Java API By Example, From Geeks To Geeks.

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


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.BindingType;
22 import org.apache.tapestry.spec.ComponentSpecification;
23 import org.apache.tapestry.spec.IBindingSpecification;
24 import org.apache.tapestry.spec.IComponentSpecification;
25 import org.apache.tapestry.spec.IContainedComponent;
26
27 /**
28  * Tests for {@link org.apache.tapestry.annotations.ComponentAnnotationWorker}
29  *
30  * @author Howard Lewis Ship
31  * @since 4.0
32  */

33 public class TestComponentAnnotationWorker extends BaseAnnotationTestCase
34 {
35     private IContainedComponent run(String JavaDoc id, String JavaDoc methodName, Location location)
36     {
37         Method JavaDoc method = findMethod(AnnotatedPage.class, methodName);
38
39         EnhancementOperation op = newOp();
40
41         replayControls();
42
43         IComponentSpecification spec = new ComponentSpecification();
44
45         new ComponentAnnotationWorker().performEnhancement(op, spec, method, location);
46
47         verifyControls();
48
49         return spec.getComponent(id);
50     }
51
52     public void testSimple()
53     {
54         Location l = newLocation();
55
56         IContainedComponent cc = run("textField", "getTextField", l);
57
58         assertEquals("TextField", cc.getType());
59         assertEquals(false, cc.getInheritInformalParameters());
60         assertEquals(null, cc.getCopyOf());
61         assertSame(l, cc.getLocation());
62         assertEquals(true, cc.getBindingNames().isEmpty());
63         assertEquals("textField", cc.getPropertyName());
64     }
65
66     public void testExplicitId()
67     {
68         IContainedComponent cc = run("email", "getEmailField", null);
69
70         assertEquals("emailField", cc.getPropertyName());
71     }
72
73     public void testInheritInformalParameters()
74     {
75         IContainedComponent cc = run("inherit", "getInherit", null);
76
77         assertEquals(true, cc.getInheritInformalParameters());
78     }
79
80     public void testWithBindings()
81     {
82         Location l = newLocation();
83         IContainedComponent cc = run("componentWithBindings", "getComponentWithBindings", l);
84
85         IBindingSpecification bs1 = cc.getBinding("condition");
86         assertSame(l, bs1.getLocation());
87         assertEquals(BindingType.PREFIXED, bs1.getType());
88         assertEquals("message", bs1.getValue());
89
90         IBindingSpecification bs2 = cc.getBinding("element");
91         assertEquals("div", bs2.getValue());
92     }
93
94     public void testBindingWhitespaceTrimmed()
95     {
96         Location l = newLocation();
97
98         IContainedComponent cc = run("whitespace", "getWhitespace", l);
99
100         IBindingSpecification bs1 = cc.getBinding("value");
101         assertSame(l, bs1.getLocation());
102         assertEquals(BindingType.PREFIXED, bs1.getType());
103         assertEquals("email", bs1.getValue());
104
105         IBindingSpecification bs2 = cc.getBinding("displayName");
106         assertEquals("message:email-label", bs2.getValue());
107     }
108 }
109
Popular Tags