1 15 package org.apache.tapestry.pageload; 16 17 import org.apache.hivemind.ApplicationRuntimeException; 18 import org.apache.hivemind.Location; 19 import org.apache.hivemind.test.HiveMindTestCase; 20 import org.apache.tapestry.IBinding; 21 import org.apache.tapestry.IComponent; 22 import org.apache.tapestry.spec.ComponentSpecification; 23 import org.apache.tapestry.spec.IComponentSpecification; 24 import org.apache.tapestry.spec.ParameterSpecification; 25 import org.easymock.MockControl; 26 27 33 public class TestVerifyRequiredParametersVisitor extends HiveMindTestCase 34 { 35 private IComponent newComponent(IComponentSpecification spec) 36 { 37 MockControl control = newControl(IComponent.class); 38 IComponent component = (IComponent) control.getMock(); 39 40 component.getSpecification(); 41 control.setReturnValue(spec); 42 43 return component; 44 } 45 46 private IBinding newBinding() 47 { 48 return (IBinding) newMock(IBinding.class); 49 } 50 51 public void testNotRequired() 52 { 53 ParameterSpecification pspec = new ParameterSpecification(); 54 pspec.setParameterName("fred"); 55 56 ComponentSpecification cspec = new ComponentSpecification(); 57 cspec.addParameter(pspec); 58 59 IComponent component = newComponent(cspec); 60 61 replayControls(); 62 63 VerifyRequiredParametersVisitor visitor = new VerifyRequiredParametersVisitor(); 64 65 visitor.visitComponent(component); 66 67 verifyControls(); 68 } 69 70 public void testRequiredWithAlias() 71 { 72 ParameterSpecification pspec = new ParameterSpecification(); 73 pspec.setParameterName("fred"); 74 pspec.setAliases("barney"); 75 pspec.setRequired(true); 76 77 ComponentSpecification cspec = new ComponentSpecification(); 78 cspec.addParameter(pspec); 79 80 IBinding fredBinding = newBinding(); 81 82 MockControl control = newControl(IComponent.class); 83 IComponent component = (IComponent) control.getMock(); 84 85 component.getSpecification(); 86 control.setReturnValue(cspec); 87 88 91 component.getBinding("fred"); 92 control.setReturnValue(fredBinding); 93 94 replayControls(); 95 96 VerifyRequiredParametersVisitor visitor = new VerifyRequiredParametersVisitor(); 97 98 visitor.visitComponent(component); 99 100 verifyControls(); 101 } 102 103 public void testRequiredNotBound() 104 { 105 ParameterSpecification pspec = new ParameterSpecification(); 106 pspec.setParameterName("fred"); 107 pspec.setRequired(true); 108 109 ComponentSpecification cspec = new ComponentSpecification(); 110 cspec.addParameter(pspec); 111 112 Location l = newLocation(); 113 114 MockControl control = newControl(IComponent.class); 115 IComponent component = (IComponent) control.getMock(); 116 117 component.getSpecification(); 118 control.setReturnValue(cspec); 119 120 component.getBinding("fred"); 121 control.setReturnValue(null); 122 123 component.getExtendedId(); 124 control.setReturnValue("Fred/flintstone"); 125 126 component.getLocation(); 127 control.setReturnValue(l); 128 129 replayControls(); 130 131 VerifyRequiredParametersVisitor visitor = new VerifyRequiredParametersVisitor(); 132 133 try 134 { 135 visitor.visitComponent(component); 136 unreachable(); 137 } 138 catch (ApplicationRuntimeException ex) 139 { 140 assertEquals("Required parameter fred of component Fred/flintstone is not bound.", ex 141 .getMessage()); 142 assertSame(component, ex.getComponent()); 143 assertSame(l, ex.getLocation()); 144 } 145 146 verifyControls(); 147 } 148 } 149 | Popular Tags |