|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2008 the original author or authors. |
| 2 | + * Copyright 2002-2010 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
19 | 19 | import java.util.HashMap;
|
20 | 20 | import java.util.List;
|
21 | 21 | import java.util.Map;
|
22 |
| - |
23 | 22 | import javax.servlet.http.HttpServletRequest;
|
24 | 23 | import javax.servlet.jsp.JspException;
|
25 | 24 | import javax.servlet.jsp.PageContext;
|
@@ -399,8 +398,39 @@ public void testOmittedPathMatchesObjectErrorsOnly() throws Exception {
|
399 | 398 | assertNotNull(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE));
|
400 | 399 | this.tag.doEndTag();
|
401 | 400 | String output = getOutput();
|
402 |
| - assertBlockTagContains(output, "object error"); |
403 |
| - assertFalse(output.indexOf("field error") != -1); |
| 401 | + assertTrue(output.contains("id=\"testBean.errors\"")); |
| 402 | + assertTrue(output.contains("object error")); |
| 403 | + assertFalse(output.contains("field error")); |
| 404 | + } |
| 405 | + |
| 406 | + public void testSpecificPathMatchesSpecificFieldOnly() throws Exception { |
| 407 | + this.tag.setPath("name"); |
| 408 | + Errors errors = new BeanPropertyBindingResult(new TestBean(), "COMMAND_NAME"); |
| 409 | + errors.reject("some.code", "object error"); |
| 410 | + errors.rejectValue("name", "some.code", "field error"); |
| 411 | + exposeBindingResult(errors); |
| 412 | + this.tag.doStartTag(); |
| 413 | + assertNotNull(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE)); |
| 414 | + this.tag.doEndTag(); |
| 415 | + String output = getOutput(); |
| 416 | + assertTrue(output.contains("id=\"name.errors\"")); |
| 417 | + assertFalse(output.contains("object error")); |
| 418 | + assertTrue(output.contains("field error")); |
| 419 | + } |
| 420 | + |
| 421 | + public void testStarMatchesAllErrors() throws Exception { |
| 422 | + this.tag.setPath("*"); |
| 423 | + Errors errors = new BeanPropertyBindingResult(new TestBean(), "COMMAND_NAME"); |
| 424 | + errors.reject("some.code", "object error"); |
| 425 | + errors.rejectValue("name", "some.code", "field error"); |
| 426 | + exposeBindingResult(errors); |
| 427 | + this.tag.doStartTag(); |
| 428 | + assertNotNull(getPageContext().getAttribute(ErrorsTag.MESSAGES_ATTRIBUTE)); |
| 429 | + this.tag.doEndTag(); |
| 430 | + String output = getOutput(); |
| 431 | + assertTrue(output.contains("id=\"testBean.errors\"")); |
| 432 | + assertTrue(output.contains("object error")); |
| 433 | + assertTrue(output.contains("field error")); |
404 | 434 | }
|
405 | 435 |
|
406 | 436 | protected void exposeBindingResult(Errors errors) {
|
|
0 commit comments