use of org.springframework.binding.message.MessageContext in project head by mifos.
the class CreateSavingsAccountFormBeanTest method validateSelectProductOfferingStepNonEmptyProductIdShouldPass.
@Test
public void validateSelectProductOfferingStepNonEmptyProductIdShouldPass() {
formBean.setProductId(1);
formBean.validateSelectProductOfferingStep(validationContext);
MessageContext messageContext = validationContext.getMessageContext();
Message[] messages = messageContext.getAllMessages();
Assert.assertEquals(0, messages.length);
}
use of org.springframework.binding.message.MessageContext in project head by mifos.
the class CreateSavingsAccountFormBeanTest method validateEnterAccountDetailsStepMandatoryDeposit.
private void validateEnterAccountDetailsStepMandatoryDeposit(String amount, @SuppressWarnings("rawtypes") Map<String, Class> expectedViolations, boolean expectingPass) {
setDepositType(formBean, CreateSavingsAccountFormBean.MANDATORY_DEPOSIT);
formBean.setMandatoryDepositAmount(amount);
formBean.validateEnterAccountDetailsStep(validationContext);
MessageContext messageContext = validationContext.getMessageContext();
Message[] messages = messageContext.getAllMessages();
if (expectingPass) {
Assert.assertEquals(0, messages.length);
return;
} else {
Assert.assertEquals(expectedViolations.size(), messages.length);
for (Message message : messages) {
Assert.assertEquals("mandatoryDepositAmount", message.getSource());
String reason = message.getText().substring(0, message.getText().indexOf("."));
Assert.assertTrue(expectedViolations.containsKey(reason));
verifyErrorMessage(expectedViolations.get(reason), message);
}
}
}
use of org.springframework.binding.message.MessageContext in project head by mifos.
the class ValidationExceptionMessageExtractorTest method testBadNumericResponseException.
private void testBadNumericResponseException(BadNumericResponseException e, String expectedMessage) {
ValidationException parent = new ValidationException("Key");
parent.addChildException(e);
ValidationExceptionMessageExtractor extractor = new ValidationExceptionMessageExtractor();
MessageContext context = new StubMessageContext();
extractor.extract(context, parent);
Message[] messages = context.getAllMessages();
Assert.assertEquals(1, messages.length);
Message m = messages[0];
Assert.assertEquals(expectedMessage, m.getText());
}
use of org.springframework.binding.message.MessageContext in project opennms by OpenNMS.
the class ReportParametersValidator method validateReportParameters.
/**
* <p>validateReportParameters</p>
*
* @param reportCriteria a {@link org.opennms.api.reporting.parameter.ReportParameters} object.
* @param context a {@link org.springframework.binding.validation.ValidationContext} object.
*/
public void validateReportParameters(ReportParameters reportCriteria, ValidationContext context) {
MessageContext messages = context.getMessageContext();
List<ReportDateParm> dateParms = reportCriteria.getDateParms();
for (Iterator<ReportDateParm> dateParmIter = dateParms.iterator(); dateParmIter.hasNext(); ) {
ReportDateParm dateParm = dateParmIter.next();
if (dateParm.getDate() == null) {
messages.addMessage(new MessageBuilder().error().source("date parms").defaultText("cannot have null date field" + dateParm.getDisplayName()).build());
}
}
List<ReportStringParm> stringParms = reportCriteria.getStringParms();
for (Iterator<ReportStringParm> stringParmIter = stringParms.iterator(); stringParmIter.hasNext(); ) {
ReportStringParm stringParm = stringParmIter.next();
if (stringParm.getValue() == "") {
messages.addMessage(new MessageBuilder().error().source("string parms").defaultText("cannot have empty string field" + stringParm.getDisplayName()).build());
}
}
List<ReportIntParm> intParms = reportCriteria.getIntParms();
for (Iterator<ReportIntParm> intParmIter = intParms.iterator(); intParmIter.hasNext(); ) {
ReportIntParm intParm = intParmIter.next();
// TODO add a more sensible check here - I think we probably can have zero int parm
if (intParm.getValue() == 0) {
messages.addMessage(new MessageBuilder().error().source("int parms").defaultText("cannot have zero integer field" + intParm.getDisplayName()).build());
}
}
List<ReportFloatParm> floatParms = reportCriteria.getFloatParms();
for (Iterator<ReportFloatParm> floatParmIter = floatParms.iterator(); floatParmIter.hasNext(); ) {
ReportFloatParm floatParm = floatParmIter.next();
if (floatParm.getValue() == null) {
messages.addMessage(new MessageBuilder().error().source("float parms").defaultText("cannot have null float field" + floatParm.getDisplayName()).build());
}
}
List<ReportDoubleParm> doubleParms = reportCriteria.getDoubleParms();
for (Iterator<ReportDoubleParm> doubleParmIter = doubleParms.iterator(); doubleParmIter.hasNext(); ) {
ReportDoubleParm doubleParm = doubleParmIter.next();
if (doubleParm.getValue() == null) {
messages.addMessage(new MessageBuilder().error().source("double parms").defaultText("cannot have null double field" + doubleParm.getDisplayName()).build());
}
}
}
use of org.springframework.binding.message.MessageContext in project cas by apereo.
the class AuthenticationExceptionHandlerTests method handleUnsatisfiedAuthenticationPolicyExceptionByDefault.
@Test
public void handleUnsatisfiedAuthenticationPolicyExceptionByDefault() {
final AuthenticationExceptionHandler handler = new AuthenticationExceptionHandler();
final MessageContext ctx = mock(MessageContext.class);
final ContextualAuthenticationPolicy<?> policy = new TestContextualAuthenticationPolicy();
final String id = handler.handle(new UnsatisfiedAuthenticationPolicyException(policy), ctx);
assertEquals(id, "UnsatisfiedAuthenticationPolicyException");
final ArgumentCaptor<DefaultMessageResolver> message = ArgumentCaptor.forClass(DefaultMessageResolver.class);
verify(ctx, times(1)).addMessage(message.capture());
assertArrayEquals(new String[] { policy.getCode().get() }, message.getValue().getCodes());
}
Aggregations