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.Location; 21 import org.apache.hivemind.service.MethodSignature; 22 import org.apache.hivemind.test.HiveMindTestCase; 23 import org.apache.tapestry.html.BasePage; 24 import org.apache.tapestry.spec.InjectSpecification; 25 import org.apache.tapestry.spec.InjectSpecificationImpl; 26 import org.easymock.MockControl; 27 28 34 public class TestInjectPageWorker extends HiveMindTestCase 35 { 36 public void testPrimitivePropertyType() 37 { 38 Location l = newLocation(); 39 40 MockControl opc = newControl(EnhancementOperation.class); 41 EnhancementOperation op = (EnhancementOperation) opc.getMock(); 42 43 op.getPropertyType("somePage"); 44 opc.setReturnValue(int.class); 45 46 replayControls(); 47 48 InjectSpecification is = new InjectSpecificationImpl(); 49 is.setProperty("somePage"); 50 is.setObject("SomePage"); 51 is.setLocation(l); 52 53 try 54 { 55 new InjectPageWorker().performEnhancement(op, is); 56 unreachable(); 57 } 58 catch (ApplicationRuntimeException ex) 59 { 60 assertEquals( 61 "Property somePage is type int, which is not compatible with injection. The property type should be Object, IPage, or a specific page class.", 62 ex.getMessage()); 63 assertSame(l, ex.getLocation()); 64 } 65 66 verifyControls(); 67 } 68 69 72 73 public void testNoPropertyType() 74 { 75 MockControl opc = newControl(EnhancementOperation.class); 76 EnhancementOperation op = (EnhancementOperation) opc.getMock(); 77 78 op.getPropertyType("somePage"); 79 opc.setReturnValue(null); 80 81 op.claimProperty("somePage"); 82 83 op.getAccessorMethodName("somePage"); 84 opc.setReturnValue("getSomePage"); 85 86 MethodSignature sig = new MethodSignature(Object .class, "getSomePage", null, null); 87 88 op.addMethod( 89 Modifier.PUBLIC, 90 sig, 91 "return getPage().getRequestCycle().getPage(\"SomePage\");"); 92 93 replayControls(); 94 95 InjectSpecification is = new InjectSpecificationImpl(); 96 is.setProperty("somePage"); 97 is.setObject("SomePage"); 98 99 new InjectPageWorker().performEnhancement(op, is); 100 101 verifyControls(); 102 } 103 104 public void testExistingPropertyType() 105 { 106 MockControl opc = newControl(EnhancementOperation.class); 107 EnhancementOperation op = (EnhancementOperation) opc.getMock(); 108 109 op.getPropertyType("somePage"); 110 opc.setReturnValue(BasePage.class); 111 112 op.claimProperty("somePage"); 113 114 op.getAccessorMethodName("somePage"); 115 opc.setReturnValue("getSomePage"); 116 117 MethodSignature sig = new MethodSignature(BasePage.class, "getSomePage", null, null); 118 119 122 op 123 .addMethod( 124 Modifier.PUBLIC, 125 sig, 126 "return (org.apache.tapestry.html.BasePage)getPage().getRequestCycle().getPage(\"SomePage\");"); 127 128 replayControls(); 129 130 InjectSpecification is = new InjectSpecificationImpl(); 131 is.setProperty("somePage"); 132 is.setObject("SomePage"); 133 134 new InjectPageWorker().performEnhancement(op, is); 135 136 verifyControls(); 137 } 138 } 139 | Popular Tags |