1 15 package org.apache.tapestry.enhance; 16 17 import java.lang.reflect.Modifier ; 18 19 import org.apache.hivemind.ApplicationRuntimeException; 20 import org.apache.hivemind.ErrorLog; 21 import org.apache.hivemind.Location; 22 import org.apache.hivemind.service.MethodSignature; 23 import org.apache.hivemind.test.HiveMindTestCase; 24 import org.apache.tapestry.BaseComponent; 25 import org.apache.tapestry.spec.IComponentSpecification; 26 import org.easymock.MockControl; 27 28 34 public class TestInjectSpecificationWorker extends HiveMindTestCase 35 { 36 private IComponentSpecification newSpec() 37 { 38 return (IComponentSpecification) newMock(IComponentSpecification.class); 39 } 40 41 public void testSuccess() throws Exception 42 { 43 MockControl control = newControl(EnhancementOperation.class); 44 EnhancementOperation op = (EnhancementOperation) control.getMock(); 45 46 IComponentSpecification spec = newSpec(); 47 48 op.claimProperty("specification"); 49 50 op.addInjectedField("_$specification", IComponentSpecification.class, spec); 51 control.setReturnValue("_$specification"); 52 53 op.getAccessorMethodName("specification"); 54 control.setReturnValue("getSpecification"); 55 56 op.addMethod(Modifier.PUBLIC, new MethodSignature(IComponentSpecification.class, 57 "getSpecification", null, null), "return _$specification;"); 58 59 replayControls(); 60 61 new InjectSpecificationWorker().performEnhancement(op, spec); 62 63 verifyControls(); 64 } 65 66 public void testFailure() 67 { 68 Location l = fabricateLocation(11); 69 70 MockControl control = newControl(EnhancementOperation.class); 71 EnhancementOperation op = (EnhancementOperation) control.getMock(); 72 73 ErrorLog log = (ErrorLog) newMock(ErrorLog.class); 74 75 Throwable ex = new ApplicationRuntimeException(EnhanceMessages 76 .claimedProperty("specification")); 77 78 MockControl specc = newControl(IComponentSpecification.class); 79 IComponentSpecification spec = (IComponentSpecification) specc.getMock(); 80 81 op.claimProperty("specification"); 82 control.setThrowable(ex); 83 84 op.getBaseClass(); 85 control.setReturnValue(BaseComponent.class); 86 87 spec.getLocation(); 88 specc.setReturnValue(l); 89 90 log.error( 91 EnhanceMessages.errorAddingProperty("specification", BaseComponent.class, ex), 92 l, 93 ex); 94 95 replayControls(); 96 97 InjectSpecificationWorker w = new InjectSpecificationWorker(); 98 w.setErrorLog(log); 99 100 w.performEnhancement(op, spec); 101 102 verifyControls(); 103 } 104 } | Popular Tags |