1 15 package org.apache.tapestry.form; 16 17 import org.apache.tapestry.IBinding; 18 import org.apache.tapestry.IForm; 19 import org.apache.tapestry.IMarkupWriter; 20 import org.apache.tapestry.IRequestCycle; 21 import org.apache.tapestry.form.translator.Translator; 22 import org.apache.tapestry.spec.ComponentSpecification; 23 import org.apache.tapestry.valid.IValidationDelegate; 24 import org.apache.tapestry.valid.ValidatorException; 25 import org.easymock.MockControl; 26 27 33 public class TestTextArea extends BaseFormComponentTest 34 { 35 public void testRewind() 36 { 37 MockControl translatorc = newControl(Translator.class); 38 Translator translator = (Translator) translatorc.getMock(); 39 40 MockControl supportc = newControl(ValidatableFieldSupport.class); 41 ValidatableFieldSupport support = (ValidatableFieldSupport) supportc.getMock(); 42 43 TextArea component = (TextArea) newInstance(TextArea.class, new Object [] 44 { "translator", translator, "validatableFieldSupport", support, "name", "barney" }); 45 46 MockControl cyclec = newControl(IRequestCycle.class); 47 IRequestCycle cycle = (IRequestCycle) cyclec.getMock(); 48 49 IMarkupWriter writer = newWriter(); 50 51 trainGetParameter(cyclec, cycle, "barney", "value"); 52 53 support.bind(component, writer, cycle, "value"); 54 55 replayControls(); 56 57 component.rewindFormComponent(writer, cycle); 58 59 verifyControls(); 60 } 61 62 public void testWriteValue() 63 { 64 TextArea component = (TextArea) newInstance(TextArea.class); 65 66 component.writeValue("The value should have changed."); 67 68 assertEquals("The value should have changed.", component.getValue()); 69 } 70 71 public void testReadValue() 72 { 73 TextArea component = (TextArea) newInstance(TextArea.class, new Object [] 74 { "value", "This is a test." }); 75 76 Object value = component.readValue(); 77 78 assertEquals("This is a test.", value); 79 } 80 81 public void testWasPrerendered() 82 { 83 TextArea component = (TextArea) newInstance(TextArea.class); 84 85 MockControl cyclec = newControl(IRequestCycle.class); 86 IRequestCycle cycle = (IRequestCycle) cyclec.getMock(); 87 88 MockControl formc = newControl(IForm.class); 89 IForm form = (IForm) formc.getMock(); 90 91 IMarkupWriter writer = newWriter(); 92 93 trainGetForm(cyclec, cycle, form); 94 95 trainWasPrerendered(formc, form, writer, component, true); 96 97 replayControls(); 98 99 component.render(writer, cycle); 100 101 verifyControls(); 102 } 103 104 public void testRewindNotForm() 105 { 106 TextArea component = (TextArea) newInstance(TextArea.class); 107 108 MockControl cyclec = newControl(IRequestCycle.class); 109 IRequestCycle cycle = (IRequestCycle) cyclec.getMock(); 110 111 MockControl formc = newControl(IForm.class); 112 IForm form = (IForm) formc.getMock(); 113 114 IMarkupWriter writer = newWriter(); 115 116 IValidationDelegate delegate = newDelegate(); 117 118 trainGetForm(cyclec, cycle, form); 119 trainWasPrerendered(formc, form, writer, component, false); 120 trainGetDelegate(formc, form, delegate); 121 122 delegate.setFormComponent(component); 123 124 trainGetElementId(formc, form, component, "barney"); 125 trainIsRewinding(formc, form, false); 126 trainIsRewinding(cyclec, cycle, true); 127 128 replayControls(); 129 130 component.render(writer, cycle); 131 132 verifyControls(); 133 } 134 135 public void testRender() 136 { 137 MockControl translatorc = newControl(Translator.class); 138 Translator translator = (Translator) translatorc.getMock(); 139 140 MockControl supportc = newControl(ValidatableFieldSupport.class); 141 ValidatableFieldSupport support = (ValidatableFieldSupport) supportc.getMock(); 142 143 TextArea component = (TextArea) newInstance( 144 TextArea.class, 145 new Object [] 146 { "value", "text area value", "translator", translator, "validatableFieldSupport", 147 support }); 148 149 MockControl cyclec = newControl(IRequestCycle.class); 150 IRequestCycle cycle = (IRequestCycle) cyclec.getMock(); 151 152 MockControl formc = newControl(IForm.class); 153 IForm form = (IForm) formc.getMock(); 154 155 IMarkupWriter writer = newBufferWriter(); 156 157 MockDelegate delegate = new MockDelegate(); 158 159 trainGetForm(cyclec, cycle, form); 160 trainWasPrerendered(formc, form, writer, component, false); 161 trainGetDelegate(formc, form, delegate); 162 163 delegate.setFormComponent(component); 164 165 trainGetElementId(formc, form, component, "fred"); 166 trainIsRewinding(formc, form, false); 167 trainIsRewinding(cyclec, cycle, false); 168 169 support.render(component, writer, cycle); 170 171 replayControls(); 172 173 component.render(writer, cycle); 174 175 verifyControls(); 176 } 177 178 public void testRenderValue() 179 { 180 MockControl translatorc = newControl(Translator.class); 181 Translator translator = (Translator) translatorc.getMock(); 182 183 MockControl validatableFieldSupportc = newControl(ValidatableFieldSupport.class); 184 ValidatableFieldSupport validatableFieldSupport = (ValidatableFieldSupport) validatableFieldSupportc 185 .getMock(); 186 187 MockControl cyclec = newControl(IRequestCycle.class); 188 IRequestCycle cycle = (IRequestCycle) cyclec.getMock(); 189 190 MockControl formc = newControl(IForm.class); 191 IForm form = (IForm) formc.getMock(); 192 193 IMarkupWriter writer = newBufferWriter(); 194 195 MockDelegate delegate = new MockDelegate(); 196 197 TextArea component = (TextArea) newInstance(TextArea.class, new Object [] 198 { "name", "fred", "translator", translator, "validatableFieldSupport", 199 validatableFieldSupport, "form", form }); 200 201 delegate.setFormComponent(component); 202 203 trainGetDelegate(formc, form, delegate); 204 trainGetDelegate(formc, form, delegate); 205 trainGetDelegate(formc, form, delegate); 206 207 validatableFieldSupport.renderContributions(component, writer, cycle); 208 209 replayControls(); 210 211 component.render(writer, cycle, "text area value"); 212 213 verifyControls(); 214 215 assertBuffer("<span class=\"prefix\"><textarea name=\"fred\" class=\"validation-delegate\">text area value</textarea></span>"); 216 } 217 218 public void testRenderDisabled() 219 { 220 MockControl translatorc = newControl(Translator.class); 221 Translator translator = (Translator) translatorc.getMock(); 222 223 MockControl validatableFieldSupportc = newControl(ValidatableFieldSupport.class); 224 ValidatableFieldSupport validatableFieldSupport = (ValidatableFieldSupport) validatableFieldSupportc 225 .getMock(); 226 227 MockControl cyclec = newControl(IRequestCycle.class); 228 IRequestCycle cycle = (IRequestCycle) cyclec.getMock(); 229 230 MockControl formc = newControl(IForm.class); 231 IForm form = (IForm) formc.getMock(); 232 233 IMarkupWriter writer = newBufferWriter(); 234 235 MockDelegate delegate = new MockDelegate(); 236 237 TextArea component = (TextArea) newInstance(TextArea.class, new Object [] 238 { "name", "fred", "translator", translator, "validatableFieldSupport", 239 validatableFieldSupport, "form", form, "disabled", Boolean.TRUE }); 240 241 delegate.setFormComponent(component); 242 243 trainGetDelegate(formc, form, delegate); 244 trainGetDelegate(formc, form, delegate); 245 trainGetDelegate(formc, form, delegate); 246 247 validatableFieldSupport.renderContributions(component, writer, cycle); 248 249 replayControls(); 250 251 component.render(writer, cycle, "text area value"); 252 253 verifyControls(); 254 255 assertBuffer("<span class=\"prefix\"><textarea name=\"fred\" disabled=\"disabled\" class=\"validation-delegate\">text area value</textarea></span>"); 256 } 257 258 public void testRenderWithInformalParameters() 259 { 260 MockControl translatorc = newControl(Translator.class); 261 Translator translator = (Translator) translatorc.getMock(); 262 263 MockControl validatableFieldSupportc = newControl(ValidatableFieldSupport.class); 264 ValidatableFieldSupport validatableFieldSupport = (ValidatableFieldSupport) validatableFieldSupportc 265 .getMock(); 266 267 MockControl cyclec = newControl(IRequestCycle.class); 268 IRequestCycle cycle = (IRequestCycle) cyclec.getMock(); 269 270 MockControl formc = newControl(IForm.class); 271 IForm form = (IForm) formc.getMock(); 272 273 IMarkupWriter writer = newBufferWriter(); 274 275 MockDelegate delegate = new MockDelegate(); 276 277 IBinding binding = newBinding("informal-value"); 278 279 TextArea component = (TextArea) newInstance(TextArea.class, new Object [] 280 { "name", "fred", "translator", translator, "validatableFieldSupport", 281 validatableFieldSupport, "form", form, "specification", 282 new ComponentSpecification() }); 283 284 component.setBinding("informal", binding); 285 286 delegate.setFormComponent(component); 287 288 trainGetDelegate(formc, form, delegate); 289 trainGetDelegate(formc, form, delegate); 290 trainGetDelegate(formc, form, delegate); 291 292 validatableFieldSupport.renderContributions(component, writer, cycle); 293 294 replayControls(); 295 296 component.render(writer, cycle, "text area value"); 297 298 verifyControls(); 299 300 assertBuffer("<span class=\"prefix\"><textarea name=\"fred\" class=\"validation-delegate\" informal=\"informal-value\">text area value</textarea></span>"); 301 } 302 303 public void testRenderNullValue() 304 { 305 MockControl translatorc = newControl(Translator.class); 306 Translator translator = (Translator) translatorc.getMock(); 307 308 MockControl validatableFieldSupportc = newControl(ValidatableFieldSupport.class); 309 ValidatableFieldSupport validatableFieldSupport = (ValidatableFieldSupport) validatableFieldSupportc 310 .getMock(); 311 312 MockControl cyclec = newControl(IRequestCycle.class); 313 IRequestCycle cycle = (IRequestCycle) cyclec.getMock(); 314 315 MockControl formc = newControl(IForm.class); 316 IForm form = (IForm) formc.getMock(); 317 318 IMarkupWriter writer = newBufferWriter(); 319 320 MockDelegate delegate = new MockDelegate(); 321 322 TextArea component = (TextArea) newInstance(TextArea.class, new Object [] 323 { "name", "fred", "translator", translator, "validatableFieldSupport", 324 validatableFieldSupport, "form", form }); 325 326 delegate.setFormComponent(component); 327 328 trainGetDelegate(formc, form, delegate); 329 trainGetDelegate(formc, form, delegate); 330 trainGetDelegate(formc, form, delegate); 331 332 validatableFieldSupport.renderContributions(component, writer, cycle); 333 334 replayControls(); 335 336 component.render(writer, cycle, null); 337 338 verifyControls(); 339 340 assertBuffer("<span class=\"prefix\"><textarea name=\"fred\" class=\"validation-delegate\"></textarea></span>"); 341 } 342 } 343 | Popular Tags |