KickJava   Java API By Example, From Geeks To Geeks.

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


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.InjectSpecification;
24
25 /**
26  * Test for the "simple" annotation workers, that collect basic information and update the component
27  * specification. {@link org.apache.tapestry.annotations.InjectPageAnnotationWorker}.
28  *
29  * @author Howard Lewis Ship
30  * @since 4.0
31  */

32 public class TestSimpleAnnotationWorkers extends BaseAnnotationTestCase
33 {
34     public void testInjectPage()
35     {
36         Location l = newLocation();
37         IComponentSpecification spec = execute(new InjectPageAnnotationWorker(), "getMyPage", l);
38
39         InjectSpecification is = (InjectSpecification) spec.getInjectSpecifications().get(0);
40
41         assertEquals("myPage", is.getProperty());
42         assertEquals("page", is.getType());
43         assertEquals("SomePageName", is.getObject());
44         assertSame(l, is.getLocation());
45     }
46
47     public void testInjectMeta()
48     {
49         Location l = newLocation();
50         IComponentSpecification spec = execute(new InjectMetaAnnotationWorker(), "getMetaFred", l);
51
52         InjectSpecification is = (InjectSpecification) spec.getInjectSpecifications().get(0);
53
54         assertEquals("metaFred", is.getProperty());
55         assertEquals("meta", is.getType());
56         assertEquals("fred", is.getObject());
57         assertSame(l, is.getLocation());
58
59     }
60
61     public void testInjectScript()
62     {
63         Location l = newLocation();
64         IComponentSpecification spec = execute(new InjectScriptAnnotationWorker(), "getScript", l);
65
66         InjectSpecification is = (InjectSpecification) spec.getInjectSpecifications().get(0);
67
68         assertEquals("script", is.getProperty());
69         assertEquals("script", is.getType());
70         assertEquals("foo.script", is.getObject());
71         assertSame(l, is.getLocation());
72
73     }
74
75     private IComponentSpecification execute(MethodAnnotationEnhancementWorker worker,
76             String JavaDoc methodName, Location location)
77     {
78         EnhancementOperation op = newOp();
79         IComponentSpecification spec = new ComponentSpecification();
80
81         Method JavaDoc method = findMethod(AnnotatedPage.class, methodName);
82
83         replayControls();
84
85         worker.performEnhancement(op, spec, method, location);
86
87         verifyControls();
88
89         return spec;
90     }
91 }
92
Popular Tags