Skip to content

Commit

Permalink
For builder bug in #60 no longer trying to build a default message when
Browse files Browse the repository at this point in the history
the user explicitly specifies a message code. Just echoing the provided
message code as the default message instead.
  • Loading branch information
cduplichien committed May 25, 2014
1 parent ca0e803 commit ae23c88
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected void logError(ValidationEvaluationContext context, ValidationRule rule
errorMessageKey = (errorMessagePrefix != null && !errorMessagePrefix.isEmpty() ? errorMessagePrefix + "." : "") + rule.getType();
}

String defaultError = localizedRulePath + " " + rule.getType();
String defaultError = rule.getMessage() != null && !rule.getMessage().isEmpty() ? rule.getMessage() : localizedRulePath + " " + rule.getType();
String modelMessageKey = getMessageResolver(context, rule, true);
String ruleArg = getMessageResolver(context, rule, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.springjutsu.validation.rules.ValidationEntity;
import org.springjutsu.validation.test.entities.Address;
import org.springjutsu.validation.test.entities.Customer;
import org.springjutsu.validation.util.ValidationRulesUtils;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes=ValidationJavaConfigurationIntegrationTestConfig.class)
Expand All @@ -28,8 +27,7 @@ public void testSimpleCase() {
Customer customer = new Customer();
Errors errors = validationManager.validate(customer);
Assert.assertEquals(1, errors.getErrorCount());
Assert.assertEquals("favoriteColor required", errors.getFieldErrors("favoriteColor").get(0).getDefaultMessage());

Assert.assertEquals("favoriteColor.required", errors.getFieldErrors("favoriteColor").get(0).getDefaultMessage());
}

@Test
Expand All @@ -38,7 +36,7 @@ public void testWithContext()
Customer customer = new Customer();
Errors errors = validationManager.validate(customer, "dave");
Assert.assertEquals(4, errors.getErrorCount());
Assert.assertEquals("errors.required", errors.getFieldErrors("favoriteColor").get(0).getCode());
Assert.assertEquals("favoriteColor.required", errors.getFieldErrors("favoriteColor").get(0).getCode());
Assert.assertEquals("blam", errors.getFieldErrors("firstName").get(0).getCode());
Assert.assertEquals("dizzam", errors.getFieldErrors("lastName").get(0).getCode());
Assert.assertEquals("doh", errors.getFieldErrors("address").get(0).getCode());
Expand All @@ -63,7 +61,7 @@ class ValidationJavaConfigurationIntegrationTestConfig
ValidationEntity personValidation()
{
return Validation.forEntity(Customer.class)
.havingRules(Validation.rule("favoriteColor", "required", new RequiredRuleExecutor()))
.havingRules(Validation.rule("favoriteColor", "favoriteColor.required", new RequiredRuleExecutor()))
.havingValidationContexts(Validation.context("group", "dave")
.havingRules(
Validation.rule("firstName", "required").withMessage("blam"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ testCustom.errors.matches={0} must match {1}
testCustom.errors.minLength={0} must be at least {1} characters long

valuedCustomer.lastName=Most Valuable Last Name

favoriteColor.required=How can you not have a favorite color?

0 comments on commit ae23c88

Please sign in to comment.