KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.hivemind.Location;
18 import org.apache.tapestry.enhance.EnhancementOperation;
19 import org.apache.tapestry.spec.ComponentSpecification;
20 import org.apache.tapestry.spec.IComponentSpecification;
21 import org.easymock.MockControl;
22
23 /**
24  * Tests for {@link org.apache.tapestry.annotations.ComponentClassAnnotationWorker}.
25  *
26  * @author Howard Lewis Ship
27  * @since 4.0
28  */

29 public class TestComponentClassAnnotationWorker extends BaseAnnotationTestCase
30 {
31     private EnhancementOperation newOp(Class JavaDoc componentClass)
32     {
33         MockControl control = newControl(EnhancementOperation.class);
34         EnhancementOperation op = (EnhancementOperation) control.getMock();
35
36         op.getBaseClass();
37         control.setReturnValue(componentClass);
38
39         return op;
40     }
41
42     private IComponentSpecification attempt(Class JavaDoc baseClass, Location location)
43     {
44         EnhancementOperation op = newOp();
45         IComponentSpecification spec = new ComponentSpecification();
46
47         replayControls();
48
49         new ComponentClassAnnotationWorker().performEnhancement(op, spec, baseClass, location);
50
51         verifyControls();
52
53         return spec;
54     }
55
56     public void testBasic()
57     {
58         Location l = newLocation();
59         IComponentSpecification spec = attempt(BasicComponent.class, l);
60
61         assertEquals(true, spec.getAllowBody());
62         assertEquals(true, spec.getAllowInformalParameters());
63         assertEquals(false, spec.isReservedParameterName("foo"));
64         assertEquals(false, spec.isReservedParameterName("bar"));
65         assertEquals(false, spec.isDeprecated());
66         assertSame(l, spec.getLocation());
67     }
68
69     public void testFormalOnly()
70     {
71         IComponentSpecification spec = attempt(FormalOnlyComponent.class, null);
72
73         assertEquals(false, spec.getAllowBody());
74         assertEquals(false, spec.getAllowInformalParameters());
75         assertEquals(false, spec.isDeprecated());
76     }
77
78     public void testDeprecated()
79     {
80         IComponentSpecification spec = attempt(DeprecatedComponent.class, null);
81
82         assertEquals(true, spec.isDeprecated());
83     }
84
85     public void testReservedParameters()
86     {
87         IComponentSpecification spec = attempt(ReservedParametersComponent.class, null);
88
89         assertEquals(true, spec.isReservedParameterName("foo"));
90         assertEquals(true, spec.isReservedParameterName("bar"));
91     }
92 }
93
Popular Tags