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.IParameterSpecification; 24 import org.easymock.MockControl; 25 26 32 public class TestParameterAnnotationWorker extends BaseAnnotationTestCase 33 { 34 private IParameterSpecification attempt(String propertyName, Location location) 35 { 36 return attempt(propertyName, propertyName, location); 37 } 38 39 private IParameterSpecification attempt(String propertyName, String parameterName, 40 Location location) 41 { 42 Method m = findMethod(AnnotatedPage.class, "get" 43 + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1)); 44 45 MockControl opc = newControl(EnhancementOperation.class); 46 EnhancementOperation op = (EnhancementOperation) opc.getMock(); 47 48 op.getPropertyType(propertyName); 49 opc.setReturnValue(m.getReturnType()); 50 51 IComponentSpecification spec = new ComponentSpecification(); 52 53 replayControls(); 54 55 new ParameterAnnotationWorker().performEnhancement(op, spec, m, location); 56 57 verifyControls(); 58 59 return spec.getParameter(parameterName); 60 } 61 62 public void testSimple() 63 { 64 Location l = newLocation(); 65 66 IParameterSpecification ps = attempt("simpleParameter", l); 67 68 assertListsEqual(new Object [] {}, ps.getAliasNames().toArray()); 69 assertEquals(true, ps.getCache()); 70 assertEquals(null, ps.getDefaultBindingType()); 71 assertEquals(null, ps.getDefaultValue()); 72 assertEquals(null, ps.getDescription()); 73 assertSame(l, ps.getLocation()); 74 assertEquals("simpleParameter", ps.getParameterName()); 75 assertEquals("simpleParameter", ps.getPropertyName()); 76 assertEquals("java.lang.String", ps.getType()); 77 } 78 79 public void testRequired() 80 { 81 IParameterSpecification ps = attempt("requiredParameter", null); 82 83 assertEquals(true, ps.isRequired()); 84 } 85 86 public void testDefaultBinding() 87 { 88 IParameterSpecification ps = attempt("beanDefaultParameter", null); 89 90 assertEquals("bean", ps.getDefaultBindingType()); 91 assertEquals("java.lang.Object", ps.getType()); 92 } 93 94 public void testCacheOff() 95 { 96 IParameterSpecification ps = attempt("nonCachedParameter", null); 97 98 assertEquals(false, ps.getCache()); 99 } 100 101 public void testAliases() 102 { 103 IParameterSpecification ps = attempt("aliasedParameter", null); 104 105 assertListsEqual(new String [] 106 { "fred" }, ps.getAliasNames().toArray()); 107 } 108 109 public void testDeprecated() 110 { 111 IParameterSpecification ps = attempt("deprecatedParameter", null); 112 assertEquals(true, ps.isDeprecated()); 113 } 114 115 public void testNamed() 116 { 117 IParameterSpecification ps = attempt("namedParameter", "fred", null); 118 119 assertEquals("fred", ps.getParameterName()); 120 assertEquals("namedParameter", ps.getPropertyName()); 121 } 122 } 123 | Popular Tags |