1 15 package org.apache.tapestry.enhance; 16 17 import java.lang.reflect.Modifier ; 18 import java.util.Collections ; 19 20 import org.apache.hivemind.ApplicationRuntimeException; 21 import org.apache.hivemind.ErrorLog; 22 import org.apache.hivemind.Location; 23 import org.apache.hivemind.service.MethodSignature; 24 import org.apache.hivemind.test.HiveMindTestCase; 25 import org.apache.tapestry.BaseComponent; 26 import org.apache.tapestry.IComponent; 27 import org.apache.tapestry.event.PageDetachListener; 28 import org.apache.tapestry.spec.IComponentSpecification; 29 import org.easymock.MockControl; 30 31 37 public class TestAbstractPropertyWorker extends HiveMindTestCase 38 { 39 public void testSuccess() 40 { 41 MockControl opc = newControl(EnhancementOperation.class); 42 EnhancementOperation op = (EnhancementOperation) opc.getMock(); 43 44 op.findUnclaimedAbstractProperties(); 45 opc.setReturnValue(Collections.singletonList("fred")); 46 47 op.getPropertyType("fred"); 48 opc.setReturnValue(String .class); 49 50 op.addField("_$fred", String .class); 51 op.addField("_$fred$defaultValue", String .class); 52 53 op.getAccessorMethodName("fred"); 54 opc.setReturnValue("getFred"); 55 56 op.addMethod( 57 Modifier.PUBLIC, 58 new MethodSignature(String .class, "getFred", null, null), 59 "return _$fred;"); 60 61 op.addMethod(Modifier.PUBLIC, new MethodSignature(void.class, "setFred", new Class [] 62 { String .class }, null), "_$fred = $1;"); 63 64 op.extendMethodImplementation( 65 IComponent.class, 66 EnhanceUtils.FINISH_LOAD_SIGNATURE, 67 "_$fred$defaultValue = _$fred;"); 68 69 op.extendMethodImplementation( 70 PageDetachListener.class, 71 EnhanceUtils.PAGE_DETACHED_SIGNATURE, 72 "_$fred = _$fred$defaultValue;"); 73 74 op.claimProperty("fred"); 75 76 replayControls(); 77 78 new AbstractPropertyWorker().performEnhancement(op, null); 79 80 verifyControls(); 81 } 82 83 public void testFailure() 84 { 85 MockControl opc = newControl(EnhancementOperation.class); 86 EnhancementOperation op = (EnhancementOperation) opc.getMock(); 87 88 MockControl specc = newControl(IComponentSpecification.class); 89 IComponentSpecification spec = (IComponentSpecification) specc.getMock(); 90 91 Location l = fabricateLocation(21); 92 93 ErrorLog log = (ErrorLog) newMock(ErrorLog.class); 94 95 op.findUnclaimedAbstractProperties(); 96 opc.setReturnValue(Collections.singletonList("fred")); 97 98 Throwable ex = new ApplicationRuntimeException("Arbitrary error."); 99 100 op.getPropertyType("fred"); 101 opc.setThrowable(ex); 102 103 op.getBaseClass(); 104 opc.setReturnValue(BaseComponent.class); 105 106 spec.getLocation(); 107 specc.setReturnValue(l); 108 109 log.error(EnhanceMessages.errorAddingProperty("fred", BaseComponent.class, ex), l, ex); 110 111 replayControls(); 112 113 AbstractPropertyWorker w = new AbstractPropertyWorker(); 114 w.setErrorLog(log); 115 116 w.performEnhancement(op, spec); 117 118 verifyControls(); 119 } 120 } | Popular Tags |