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.ComponentSpecification; 22 import org.apache.tapestry.spec.IComponentSpecification; 23 import org.apache.tapestry.spec.InjectSpecification; 24 25 32 public class TestSimpleAnnotationWorkers extends BaseAnnotationTestCase 33 { 34 public void testInjectPage() 35 { 36 Location l = newLocation(); 37 IComponentSpecification spec = execute(new InjectPageAnnotationWorker(), "getMyPage", l); 38 39 InjectSpecification is = (InjectSpecification) spec.getInjectSpecifications().get(0); 40 41 assertEquals("myPage", is.getProperty()); 42 assertEquals("page", is.getType()); 43 assertEquals("SomePageName", is.getObject()); 44 assertSame(l, is.getLocation()); 45 } 46 47 public void testInjectMeta() 48 { 49 Location l = newLocation(); 50 IComponentSpecification spec = execute(new InjectMetaAnnotationWorker(), "getMetaFred", l); 51 52 InjectSpecification is = (InjectSpecification) spec.getInjectSpecifications().get(0); 53 54 assertEquals("metaFred", is.getProperty()); 55 assertEquals("meta", is.getType()); 56 assertEquals("fred", is.getObject()); 57 assertSame(l, is.getLocation()); 58 59 } 60 61 public void testInjectScript() 62 { 63 Location l = newLocation(); 64 IComponentSpecification spec = execute(new InjectScriptAnnotationWorker(), "getScript", l); 65 66 InjectSpecification is = (InjectSpecification) spec.getInjectSpecifications().get(0); 67 68 assertEquals("script", is.getProperty()); 69 assertEquals("script", is.getType()); 70 assertEquals("foo.script", is.getObject()); 71 assertSame(l, is.getLocation()); 72 73 } 74 75 private IComponentSpecification execute(MethodAnnotationEnhancementWorker worker, 76 String methodName, Location location) 77 { 78 EnhancementOperation op = newOp(); 79 IComponentSpecification spec = new ComponentSpecification(); 80 81 Method method = findMethod(AnnotatedPage.class, methodName); 82 83 replayControls(); 84 85 worker.performEnhancement(op, spec, method, location); 86 87 verifyControls(); 88 89 return spec; 90 } 91 } 92 | Popular Tags |