Search in sources :

Example 21 with MessageContext

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);
}
Also used : Message(org.springframework.binding.message.Message) MessageContext(org.springframework.binding.message.MessageContext) Test(org.junit.Test)

Example 22 with MessageContext

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);
        }
    }
}
Also used : Message(org.springframework.binding.message.Message) MessageContext(org.springframework.binding.message.MessageContext)

Example 23 with MessageContext

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());
}
Also used : ValidationException(org.mifos.platform.validations.ValidationException) Message(org.springframework.binding.message.Message) StubMessageContext(org.mifos.ui.validation.StubMessageContext) StubMessageContext(org.mifos.ui.validation.StubMessageContext) MessageContext(org.springframework.binding.message.MessageContext)

Example 24 with MessageContext

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());
        }
    }
}
Also used : ReportDateParm(org.opennms.api.reporting.parameter.ReportDateParm) ReportDoubleParm(org.opennms.api.reporting.parameter.ReportDoubleParm) ReportFloatParm(org.opennms.api.reporting.parameter.ReportFloatParm) MessageBuilder(org.springframework.binding.message.MessageBuilder) ReportStringParm(org.opennms.api.reporting.parameter.ReportStringParm) MessageContext(org.springframework.binding.message.MessageContext) ReportIntParm(org.opennms.api.reporting.parameter.ReportIntParm)

Example 25 with MessageContext

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());
}
Also used : UnsatisfiedAuthenticationPolicyException(org.apereo.cas.ticket.UnsatisfiedAuthenticationPolicyException) DefaultMessageResolver(org.springframework.binding.message.DefaultMessageResolver) MessageContext(org.springframework.binding.message.MessageContext) Test(org.junit.Test)

Aggregations

MessageContext (org.springframework.binding.message.MessageContext)48 Test (org.junit.Test)18 Message (org.springframework.binding.message.Message)16 MessageBuilder (org.springframework.binding.message.MessageBuilder)6 ArrayList (java.util.ArrayList)5 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)4 InvalidTicketException (org.apereo.cas.ticket.InvalidTicketException)4 UnsatisfiedAuthenticationPolicyException (org.apereo.cas.ticket.UnsatisfiedAuthenticationPolicyException)4 LocalDate (org.joda.time.LocalDate)4 BigDecimal (java.math.BigDecimal)3 GeneralSecurityException (java.security.GeneralSecurityException)3 HashMap (java.util.HashMap)3 AccountLockedException (javax.security.auth.login.AccountLockedException)3 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)3 PreventedException (org.apereo.cas.authentication.PreventedException)3 DateTime (org.joda.time.DateTime)3 LoanCreationInstallmentDto (org.mifos.dto.domain.LoanCreationInstallmentDto)2 LoanScheduleDto (org.mifos.dto.screen.LoanScheduleDto)2 QuestionGroupDetail (org.mifos.platform.questionnaire.service.QuestionGroupDetail)2 ErrorEntry (org.mifos.platform.validations.ErrorEntry)2