BillPaymentStatusController { @RequestMapping(value = "/egf/bill/paymentamount", method = GET, produces = APPLICATION_JSON_VALUE) public String getPaymentAmount(@RequestParam final String billNumber, final HttpServletResponse response) { if (LOG.isDebugEnabled()) LOG.debug("Rest API getting payment status for the bill number: " + billNumber); ApplicationThreadLocals.setUserId(2L); BigDecimal paymentAmount; EgBillregister egBillregister = null; RestErrors restErrors; try { egBillregister = expenseBillService.getByBillnumber(billNumber); if (egBillregister == null) { restErrors = new RestErrors(); restErrors.setErrorCode(RestApiConstants.THIRD_PARTY_ERR_CODE_NOT_VALID_BILLNUMBER); restErrors.setErrorMessage(RestApiConstants.THIRD_PARTY_ERR_MSG_NOT_VALID_BILLNUMBER); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return JsonConvertor.convert(restErrors); } paymentAmount = egovCommon.getPaymentAmount(egBillregister.getId()); } catch (final ApplicationException e) { LOG.error(e.getStackTrace()); final RestErrors re = new RestErrors(); re.setErrorCode(e.getMessage()); re.setErrorMessage(e.getMessage()); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return JsonConvertor.convert(re); } response.setStatus(HttpServletResponse.SC_CREATED); return JsonConvertor.convert(paymentAmount); }  @RequestMapping(value = "/egf/bill/paymentamount", method = GET, produces = APPLICATION_JSON_VALUE) String getPaymentAmount(@RequestParam final String billNumber,
            final HttpServletResponse response);  }
@Test public void shouldReturnPaymentAmount() throws Exception { when(expenseBillService.getByBillnumber(Matchers.anyString())).thenReturn(egBillregister); when(egovCommon.getPaymentAmount(Matchers.anyLong())).thenReturn(BigDecimal.valueOf(1000)); responseJson = billPaymentStatusController.getPaymentAmount("1234", response); assertEquals("1000", responseJson); }
@Test public void shouldGetErrorsWhenInvalidBillNumber() { when(expenseBillService.getByBillnumber(null)).thenReturn(null); responseJson = billPaymentStatusController.getPaymentAmount(null, response); final JSONObject jsonObject = new JSONObject(responseJson); assertEquals(RestApiConstants.THIRD_PARTY_ERR_CODE_NOT_VALID_BILLNUMBER, jsonObject.get("errorCode")); }
@Test public void shouldThrowApplicationExceptionWhenBillIdIsNull() throws ApplicationException { when(expenseBillService.getByBillnumber(Matchers.anyString())).thenReturn(egBillregister); when(egovCommon.getPaymentAmount(Matchers.anyLong())).thenThrow(new ApplicationException("")); responseJson = billPaymentStatusController.getPaymentAmount(requestJson, response); final JSONObject jsonObject = new JSONObject(responseJson); assertEquals(StringUtils.EMPTY, jsonObject.get("errorCode")); }