KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > enhance > TestInjectScriptWorker


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.enhance;
16
17 import java.lang.reflect.Modifier JavaDoc;
18
19 import org.apache.hivemind.Location;
20 import org.apache.hivemind.Resource;
21 import org.apache.hivemind.service.MethodSignature;
22 import org.apache.hivemind.test.AggregateArgumentsMatcher;
23 import org.apache.hivemind.test.ArgumentMatcher;
24 import org.apache.hivemind.test.HiveMindTestCase;
25 import org.apache.tapestry.IScript;
26 import org.apache.tapestry.engine.IScriptSource;
27 import org.apache.tapestry.spec.InjectSpecificationImpl;
28 import org.easymock.MockControl;
29
30 /**
31  * Tests for {@link org.apache.tapestry.enhance.InjectScriptWorker}.
32  *
33  * @author Howard M. Lewis Ship
34  * @since 4.0
35  */

36 public class TestInjectScriptWorker extends HiveMindTestCase
37 {
38     public void testSuccess()
39     {
40         MockControl opc = newControl(EnhancementOperation.class);
41         EnhancementOperation op = (EnhancementOperation) opc.getMock();
42
43         Location componentSpecLocation = fabricateLocation(22);
44         final Resource scriptResource = componentSpecLocation.getResource().getRelativeResource(
45                 "bar.script");
46
47         final Location injectSpecLocation = newLocation();
48
49         final IScriptSource source = (IScriptSource) newMock(IScriptSource.class);
50
51         op.claimProperty("foo");
52
53         op.getPropertyType("foo");
54         opc.setReturnValue(IScript.class);
55
56         op.getAccessorMethodName("foo");
57         opc.setReturnValue("getFoo");
58
59         op.addInjectedField("_$script", DeferredScript.class, new DeferredScriptImpl(scriptResource,
60                 source, injectSpecLocation));
61         opc.setMatcher(new AggregateArgumentsMatcher(new ArgumentMatcher[]
62         { null, null, new ArgumentMatcher()
63         {
64
65             public boolean compareArguments(Object JavaDoc expected, Object JavaDoc actual)
66             {
67                 DeferredScriptImpl ds = (DeferredScriptImpl) actual;
68
69                 return ds._location == injectSpecLocation && ds._scriptSource == source
70                         && ds._scriptResource.equals(scriptResource);
71             }
72
73         }
74
75         }));
76         opc.setReturnValue("_script");
77
78         MethodSignature sig = new MethodSignature(IScript.class, "getFoo", null, null);
79
80         op.addMethod(Modifier.PUBLIC, sig, "return _script.getScript();");
81
82         replayControls();
83
84         InjectSpecificationImpl is = new InjectSpecificationImpl();
85         is.setProperty("foo");
86         is.setObject("bar.script");
87         is.setLocation(injectSpecLocation);
88
89         InjectScriptWorker worker = new InjectScriptWorker();
90         worker.setSource(source);
91
92         worker.performEnhancement(op, is);
93
94         verifyControls();
95     }
96 }
97
Popular Tags