1 15 package org.apache.tapestry.enhance; 16 17 import java.lang.reflect.Modifier ; 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 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 expected, Object 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 |