1 15 package org.apache.tapestry.annotations; 16 17 import java.lang.reflect.Method ; 18 19 import org.apache.hivemind.Location; 20 import org.apache.tapestry.enhance.EnhancementOperation; 21 import org.apache.tapestry.spec.BindingType; 22 import org.apache.tapestry.spec.ComponentSpecification; 23 import org.apache.tapestry.spec.IBindingSpecification; 24 import org.apache.tapestry.spec.IComponentSpecification; 25 import org.apache.tapestry.spec.IContainedComponent; 26 27 33 public class TestComponentAnnotationWorker extends BaseAnnotationTestCase 34 { 35 private IContainedComponent run(String id, String methodName, Location location) 36 { 37 Method method = findMethod(AnnotatedPage.class, methodName); 38 39 EnhancementOperation op = newOp(); 40 41 replayControls(); 42 43 IComponentSpecification spec = new ComponentSpecification(); 44 45 new ComponentAnnotationWorker().performEnhancement(op, spec, method, location); 46 47 verifyControls(); 48 49 return spec.getComponent(id); 50 } 51 52 public void testSimple() 53 { 54 Location l = newLocation(); 55 56 IContainedComponent cc = run("textField", "getTextField", l); 57 58 assertEquals("TextField", cc.getType()); 59 assertEquals(false, cc.getInheritInformalParameters()); 60 assertEquals(null, cc.getCopyOf()); 61 assertSame(l, cc.getLocation()); 62 assertEquals(true, cc.getBindingNames().isEmpty()); 63 assertEquals("textField", cc.getPropertyName()); 64 } 65 66 public void testExplicitId() 67 { 68 IContainedComponent cc = run("email", "getEmailField", null); 69 70 assertEquals("emailField", cc.getPropertyName()); 71 } 72 73 public void testInheritInformalParameters() 74 { 75 IContainedComponent cc = run("inherit", "getInherit", null); 76 77 assertEquals(true, cc.getInheritInformalParameters()); 78 } 79 80 public void testWithBindings() 81 { 82 Location l = newLocation(); 83 IContainedComponent cc = run("componentWithBindings", "getComponentWithBindings", l); 84 85 IBindingSpecification bs1 = cc.getBinding("condition"); 86 assertSame(l, bs1.getLocation()); 87 assertEquals(BindingType.PREFIXED, bs1.getType()); 88 assertEquals("message", bs1.getValue()); 89 90 IBindingSpecification bs2 = cc.getBinding("element"); 91 assertEquals("div", bs2.getValue()); 92 } 93 94 public void testBindingWhitespaceTrimmed() 95 { 96 Location l = newLocation(); 97 98 IContainedComponent cc = run("whitespace", "getWhitespace", l); 99 100 IBindingSpecification bs1 = cc.getBinding("value"); 101 assertSame(l, bs1.getLocation()); 102 assertEquals(BindingType.PREFIXED, bs1.getType()); 103 assertEquals("email", bs1.getValue()); 104 105 IBindingSpecification bs2 = cc.getBinding("displayName"); 106 assertEquals("message:email-label", bs2.getValue()); 107 } 108 } 109 | Popular Tags |