use of org.springframework.validation.BindException in project cas by apereo.
the class AuthenticationViaFormActionTests method verifyFailedAuthenticationWithNoService.
@Test
public void verifyFailedAuthenticationWithNoService() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockRequestContext context = new MockRequestContext();
request.addParameter(USERNAME_PARAM, TEST);
request.addParameter(PASSWORD_PARAM, "test2");
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
final Credential c = CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword();
putCredentialInRequestScope(context, c);
context.getRequestScope().put("org.springframework.validation.BindException.credentials", new BindException(c, "credential"));
assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, this.action.execute(context).getId());
}
use of org.springframework.validation.BindException in project head by mifos.
the class SavingsProductFormValidator method validate.
@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
@Override
public void validate(Object target, Errors errors) {
SavingsProductFormBean formBean = (SavingsProductFormBean) target;
if (formBean.getGeneralDetails().getName().trim().isEmpty()) {
errors.reject("NotEmpty.generalDetails.name");
}
if (formBean.getGeneralDetails().getDescription().length() > 200) {
errors.reject("Size.generalDetails.description");
}
if (formBean.getGeneralDetails().getShortName().trim().isEmpty()) {
errors.reject("NotEmpty.generalDetails.shortName");
}
if (formBean.getGeneralDetails().getSelectedCategory().trim().isEmpty()) {
errors.reject("NotEmpty.generalDetails.selectedCategory");
}
if (null == formBean.getGeneralDetails().getStartDateDay() || 1 > formBean.getGeneralDetails().getStartDateDay() || 31 < formBean.getGeneralDetails().getStartDateDay()) {
errors.reject("Min.generalDetails.startDateDay");
}
if (null == formBean.getGeneralDetails().getStartDateMonth() || 1 > formBean.getGeneralDetails().getStartDateMonth() || 12 < formBean.getGeneralDetails().getStartDateMonth()) {
errors.reject("Min.generalDetails.startDateMonth");
}
if (null == formBean.getGeneralDetails().getStartDateAsDateTime() || !(formBean.getGeneralDetails().getStartDateYear().length() == 4)) {
errors.reject("Min.generalDetails.startDate");
} else {
MutableDateTime nextYear = new MutableDateTime();
nextYear.setDate(new Date().getTime());
nextYear.addYears(1);
if (formBean.getGeneralDetails().getStartDateAsDateTime() != null && formBean.getGeneralDetails().getStartDateAsDateTime().compareTo(nextYear) > 0) {
errors.reject("Min.generalDetails.startDate");
}
}
if ((null != formBean.getGeneralDetails().getEndDateDay() || null != formBean.getGeneralDetails().getEndDateMonth() || null != formBean.getGeneralDetails().getEndDateMonth()) && formBean.getGeneralDetails().getEndDateAsDateTime() == null) {
errors.reject("Min.generalDetails.endDate");
}
if (formBean.getGeneralDetails().getStartDateAsDateTime() != null && formBean.getGeneralDetails().getEndDateAsDateTime() != null && formBean.getGeneralDetails().getStartDateAsDateTime().compareTo(formBean.getGeneralDetails().getEndDateAsDateTime()) > 0) {
errors.reject("Min.generalDetails.endDate");
}
if (formBean.getGeneralDetails().getSelectedApplicableFor().trim().isEmpty()) {
errors.reject("NotEmpty.generalDetails.selectedApplicableFor");
}
if (formBean.getSelectedDepositType().trim().isEmpty()) {
errors.reject("NotEmpty.savingsProduct.selectedDepositType");
} else if (formBean.isMandatory() && (null == formBean.getAmountForDeposit() || formBean.getAmountForDeposit() <= 0)) {
errors.reject("Min.savingsProduct.amountForDesposit");
}
if (formBean.isGroupSavingAccount() && formBean.getSelectedGroupSavingsApproach().trim().isEmpty()) {
errors.reject("NotEmpty.savingsProduct.selectedGroupSavingsApproach");
}
if (!formBean.isInterestRateZero()) {
if (null == formBean.getInterestRate() || formBean.getInterestRate().doubleValue() < 1.0 || formBean.getInterestRate().doubleValue() > 100.0 || errorProcessor.getRejectedValue("interestRate") != null) {
if (errorProcessor.getTarget() == null) {
errors.reject("NotNull.savingsProduct.interestRate");
} else {
BindException bindException = new BindException(errorProcessor.getTarget(), errorProcessor.getObjectName());
bindException.addError(new FieldError(errorProcessor.getObjectName(), "interestRate", errorProcessor.getRejectedValue("interestRate"), true, new String[] { "NotNull.savingsProduct.interestRate" }, null, null));
errors.addAllErrors(bindException);
}
}
if (formBean.getSelectedInterestCalculation().trim().isEmpty()) {
errors.reject("NotEmpty.savingsProduct.selectedInterestCalculation");
}
if (null == formBean.getInterestCalculationFrequency() || formBean.getInterestCalculationFrequency() < 1 || errorProcessor.getRejectedValue("interestCalculationFrequency") != null) {
if (errorProcessor.getTarget() == null) {
errors.reject("NotNull.savingsProduct.interestCalculationFrequency");
} else {
BindException bindException = new BindException(errorProcessor.getTarget(), errorProcessor.getObjectName());
bindException.addError(new FieldError(errorProcessor.getObjectName(), "interestCalculationFrequency", errorProcessor.getRejectedValue("interestCalculationFrequency"), true, new String[] { "NotNull.savingsProduct.interestCalculationFrequency" }, null, null));
errors.addAllErrors(bindException);
}
}
if (null == formBean.getInterestPostingMonthlyFrequency() || formBean.getInterestPostingMonthlyFrequency() < 1 || errorProcessor.getRejectedValue("interestPostingMonthlyFrequency") != null) {
if (errorProcessor.getTarget() == null) {
errors.reject("Min.savingsProduct.interestPostingMonthlyFrequency");
} else {
BindException bindException = new BindException(errorProcessor.getTarget(), errorProcessor.getObjectName());
bindException.addError(new FieldError(errorProcessor.getObjectName(), "interestPostingMonthlyFrequency", errorProcessor.getRejectedValue("interestPostingMonthlyFrequency"), true, new String[] { "Min.savingsProduct.interestPostingMonthlyFrequency" }, null, null));
errors.addAllErrors(bindException);
}
}
}
BigDecimal minBalanceForInterestCalculation;
try {
minBalanceForInterestCalculation = BigDecimal.valueOf(Double.valueOf(formBean.getMinBalanceRequiredForInterestCalculation()));
} catch (NumberFormatException e) {
minBalanceForInterestCalculation = new BigDecimal("-1");
}
if (minBalanceForInterestCalculation.compareTo(BigDecimal.ZERO) < 0) {
errors.reject("Min.savingsProduct.balanceRequiredForInterestCalculation");
}
if (formBean.getSelectedPrincipalGlCode().trim().isEmpty()) {
errors.reject("NotEmpty.savingsProduct.selectedPrincipalGlCode");
}
if (formBean.getSelectedInterestGlCode().trim().isEmpty()) {
errors.reject("NotEmpty.savingsProduct.selectedInterestGlCode");
}
Short digsAfterDec = configurationServiceFacade.getAccountingConfiguration().getDigitsAfterDecimal();
Short digsBeforeDec = configurationServiceFacade.getAccountingConfiguration().getDigitsBeforeDecimal();
Double maxWithdrawalObj = formBean.getMaxWithdrawalAmount();
String maxWithdrawalString;
if (maxWithdrawalObj == null) {
maxWithdrawalString = "";
} else {
maxWithdrawalString = maxWithdrawalObj.toString();
}
int dot = maxWithdrawalString.lastIndexOf('.');
int max = digsAfterDec + digsBeforeDec + dot;
int withdrawalLength = maxWithdrawalString.length();
if (maxWithdrawalString.lastIndexOf(0, dot) > digsBeforeDec) {
errors.reject("MaxDigitsBefore.savingProduct.withdrawal", new String[] { digsBeforeDec.toString() }, null);
}
if (maxWithdrawalString.lastIndexOf(dot, withdrawalLength) > digsAfterDec) {
errors.reject("MaxDigitsAfter.savingProduct.withdrawal", new String[] { digsAfterDec.toString() }, null);
}
if (withdrawalLength > max) {
errors.reject("MaxDigitsNumber.savingProduct.withdrawal", new String[] { String.valueOf(max) }, null);
}
Double amountForDepositObj = formBean.getAmountForDeposit();
String amountForDepositString;
if (amountForDepositObj == null) {
amountForDepositString = "";
} else {
amountForDepositString = amountForDepositObj.toString();
}
int depositLength = amountForDepositString.length();
if (amountForDepositString.lastIndexOf(0, dot) > digsBeforeDec) {
errors.reject("MaxDigitsBefore.savingProduct.deposit", new String[] { digsBeforeDec.toString() }, null);
}
if (amountForDepositString.lastIndexOf(dot, depositLength) > digsAfterDec) {
errors.reject("MaxDigitsAfter.savingProduct.deposit", new String[] { digsAfterDec.toString() }, null);
}
if (depositLength > max) {
errors.reject("MaxDigitsNumber.savingProduct.deposit", new String[] { String.valueOf(max) }, null);
}
}
use of org.springframework.validation.BindException in project opennms by OpenNMS.
the class DefaultStatisticsReportServiceTest method testNullCommandObjectId.
@Test
public void testNullCommandObjectId() {
StatisticsReportCommand command = new StatisticsReportCommand();
BindException errors = new BindException(command, "");
ThrowableAnticipator ta = new ThrowableAnticipator();
ta.anticipate(new IllegalArgumentException("id property on command object cannot be null"));
m_mocks.replayAll();
try {
m_service.getReport(command, errors);
} catch (Throwable t) {
ta.throwableReceived(t);
}
ta.verifyAnticipated();
}
use of org.springframework.validation.BindException in project opennms by OpenNMS.
the class DefaultStatisticsReportServiceTest method testDatumWithNonExistentResource.
@Test
public void testDatumWithNonExistentResource() {
StatisticsReport report = new StatisticsReport();
report.setId(1);
StatisticsReportData datum = new StatisticsReportData();
ResourceReference resourceRef = new ResourceReference();
resourceRef.setId(1);
resourceRef.setResourceId("node[1].interfaceSnmp[en0]");
datum.setId(1);
datum.setResource(resourceRef);
datum.setReport(report);
datum.setValue(0.1d);
report.addData(datum);
StatisticsReportCommand command = new StatisticsReportCommand();
command.setId(report.getId());
BindException errors = new BindException(command, "");
expect(m_statisticsReportDao.load(report.getId())).andReturn(report);
m_statisticsReportDao.initialize(report);
m_statisticsReportDao.initialize(report.getData());
expect(m_resourceDao.getResourceById(ResourceId.fromString(resourceRef.getResourceId()))).andReturn(null);
m_mocks.replayAll();
StatisticsReportModel model = m_service.getReport(command, errors);
assertNotNull("model should not be null", model);
assertNotNull("model.getData() should not be null", model.getData());
SortedSet<Datum> data = model.getData();
assertEquals("data size", 1, data.size());
Datum d = data.first();
assertNotNull("first datum should not be null", d);
assertNull("first datum resource should be null", d.getResource());
}
use of org.springframework.validation.BindException in project opennms by OpenNMS.
the class DefaultDistributedPollerServiceTest method testDeleteLocationMonitorNullCommand.
public void testDeleteLocationMonitorNullCommand() {
ThrowableAnticipator ta = new ThrowableAnticipator();
ta.anticipate(new IllegalStateException("command argument cannot be null"));
LocationMonitorIdCommand command = new LocationMonitorIdCommand();
BindException errors = new BindException(command, "command");
replayMocks();
try {
m_distributedPollerService.deleteLocationMonitor(null, errors);
} catch (Throwable t) {
ta.throwableReceived(t);
}
ta.verifyAnticipated();
verifyMocks();
}
Aggregations