BillService { public List<RestErrors> validateBillRegister(final BillRegister billRegister) { final List<RestErrors> errors = new ArrayList<>(); RestErrors restErrors; validateMandatoryFields(billRegister, errors); validateBillDates(billRegister, errors); if (billRegister.getBillAmount() == null) { restErrors = new RestErrors(); restErrors.setErrorCode(RestApiConstants.THIRD_PARTY_ERR_CODE_NO_BILLAMOUNT); restErrors.setErrorMessage(RestApiConstants.THIRD_PARTY_ERR_MSG_NO_BILLAMOUNT); errors.add(restErrors); } if (projectCodeService.findActiveProjectCodeByCode(billRegister.getProjectCode()) == null && StringUtils.isBlank(billRegister.getNameOfWork())) { restErrors = new RestErrors(); restErrors.setErrorCode(RestApiConstants.THIRD_PARTY_ERR_CODE_NO_NAMEOFWORK); restErrors.setErrorMessage(RestApiConstants.THIRD_PARTY_ERR_MSG_NO_NAMEOFWORK); errors.add(restErrors); } if (StringUtils.isNotBlank(billRegister.getNameOfWork()) && !billRegister.getNameOfWork().matches(WorksConstants.ALPHANUMERICWITHALLSPECIALCHAR)) { restErrors = new RestErrors(); restErrors.setErrorCode(RestApiConstants.THIRD_PARTY_ERR_CODE_NOT_VALID_NAME_OF_WORK); restErrors.setErrorMessage(RestApiConstants.THIRD_PARTY_ERR_MSG_NOT_VALID_NAME_OF_WORK); errors.add(restErrors); } if (StringUtils.isNotBlank(billRegister.getSchemeCode()) && schemeService.findByCode(billRegister.getSchemeCode()) == null) { restErrors = new RestErrors(); restErrors.setErrorCode(RestApiConstants.THIRD_PARTY_ERR_CODE_NO_SCHEME); restErrors.setErrorMessage(RestApiConstants.THIRD_PARTY_ERR_MSG_NO_SCHEME); errors.add(restErrors); } if (StringUtils.isNotBlank(billRegister.getSubSchemeCode()) && subSchemeService.findByCode(billRegister.getSubSchemeCode()) == null) { restErrors = new RestErrors(); restErrors.setErrorCode(RestApiConstants.THIRD_PARTY_ERR_CODE_NO_SCHEME); restErrors.setErrorMessage(RestApiConstants.THIRD_PARTY_ERR_MSG_NO_SCHEME); errors.add(restErrors); } if(StringUtils.isNotBlank(billRegister.getFundCode())){ List<Fund> fundCode = fundService.getByIsActive(true); boolean isValidFundCode = false; for(Fund fund : fundCode){ if(fund.getCode().equals(billRegister.getFundCode())){ isValidFundCode = true; } } if(!isValidFundCode){ restErrors = new RestErrors(); restErrors.setErrorCode(RestApiConstants.THIRD_PARTY_ERR_CODE_NOT_VALID_FUND_CODE); restErrors.setErrorMessage(RestApiConstants.THIRD_PARTY_ERR_MSG_NOT_VALID_FUND_CODE); errors.add(restErrors); } } if(StringUtils.isNotBlank(billRegister.getPartyBillNumber())){ Pattern pattern = Pattern.compile("^[a-zA-Z\\d-/]+$", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(billRegister.getPartyBillNumber()); boolean isValidBillNumber = matcher.find(); if (!isValidBillNumber){ restErrors = new RestErrors(); restErrors.setErrorCode(RestApiConstants.THIRD_PARTY_ERR_CODE_NOT_VALID_BILLNUMBER); restErrors.setErrorMessage(RestApiConstants.THIRD_PARTY_ERR_MSG_NOT_VALID_BILLNUMBER); errors.add(restErrors); } } validateBillDetails(billRegister, errors); validateBillPayeeDetails(billRegister, errors); return errors; }  Session getCurrentSession(); List<RestErrors> validateBillRegister(final BillRegister billRegister); void populateBillRegister(final EgBillregister egBillregister, final BillRegister billRegister); void createProjectCode(final BillRegister billRegister); EgBillregister createBill(final EgBillregister egBillregister); List<BillPaymentDetails> getBillAndPaymentDetails(String billNo);  }
@Test public void shouldGiveErrorsIfInvalidPayeeDetails() { billRegister.getBillPayeeDetails().get(0).setGlcode(""); billRegister.getBillPayeeDetails().get(0).setAccountDetailType(""); billRegister.getBillPayeeDetails().get(0).setAccountDetailKey("abcd123"); billRegister.getBillPayeeDetails().get(0).setCreditAmount(null); billRegister.getBillPayeeDetails().get(0).setDebitAmount(null); errors = billService.validateBillRegister(billRegister); assertEquals(5, errors.size()); }
@Test public void shouldValidateBillRegister() { errors = billService.validateBillRegister(billRegister); assertEquals(1, errors.size()); }
@Test public void shouldGiveErrorsIfMandatoryFieldsNotPresent() { billRegister.setProjectCode(""); billRegister.setBillType(""); billRegister.setPayTo(""); billRegister.setDepartmentCode(""); billRegister.setFunctionCode(""); billRegister.setFundCode(""); errors = billService.validateBillRegister(billRegister); assertEquals(6, errors.size()); }
@Test public void shouldGiveErrorsIfBillDatesNotProper() { billRegister.setBillDate(DateUtils.getDate("20-02-2011", "dd-MM-yyyy")); billRegister.setPartyBillDate(DateUtils.getDate("20-02-2099", "dd-MM-yyyy")); when(financialYearHibernateDAO.getFinancialYearByDate(Matchers.any())) .thenThrow(new ApplicationRuntimeException("Financial Year is not active For Posting.")); errors = billService.validateBillRegister(billRegister); assertEquals(3, errors.size()); }
@Test public void shouldGiveErrorForInvalidNameOfWork() { billRegister.setNameOfWork("Building Contruction\n'"); when(projectCodeService.findActiveProjectCodeByCode(Matchers.anyString())).thenReturn(null); errors = billService.validateBillRegister(billRegister); assertEquals(2, errors.size()); }
@Test public void shouldGiveErrorsIfBillDetailsEmpty() { billRegister.getBillDetails().clear(); billRegister.getBillPayeeDetails().clear(); errors = billService.validateBillRegister(billRegister); assertEquals(3, errors.size()); }
@Test public void shouldGiveErrorsIfInvalidGlcode() { when(chartOfAccountsService.getByGlCode(Matchers.anyString())).thenReturn(null); errors = billService.validateBillRegister(billRegister); assertEquals(5, errors.size()); }
@Test public void shouldGiveErrorsIfInvalidDetailGlcode() { chartOfAccount1.setClassification(1l); errors = billService.validateBillRegister(billRegister); assertEquals(3, errors.size()); }
@Test public void shouldGiveErrorsIfAmountNegative() { billRegister.getBillDetails().get(0).setDebitAmount(new BigDecimal(-1000)); billRegister.getBillDetails().get(1).setCreditAmount(new BigDecimal(-1000)); errors = billService.validateBillRegister(billRegister); assertEquals(5, errors.size()); }