@SuppressWarnings("unchecked") @Test public void createVoucherTest() throws JsonParseException, JsonMappingException, IOException, JSONException { final VoucherRequest voucherRequest = getVoucherRequest(); final HttpHeaders headers = getHttpHeaders(); final VoucherResponse voucherResponse = getVoucherResponse(); final ResponseEntity<JSONObject> responseEntity = getResponseEntity(); when(restTemplate.exchange(any(String.class), any(HttpMethod.class), any(HttpEntity.class), any(Class.class))) .thenReturn(responseEntity); when(mapper.readValue(any(String.class), any(Class.class))).thenReturn(voucherResponse); voucherService.createVoucher(voucherRequest, "ap.kurnool", headers); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public String createVoucher(final VoucherRequest voucherRequest, final String tenantId, final HttpHeaders headers) { final String createVoucherUrl = applicationProperties.getHostNameForMonolithic(tenantId) + applicationProperties.getEgfServiceVoucherCreatePath() + "?tenantId=" + tenantId; log.debug("Voucher API Request URL :: " + createVoucherUrl); log.debug("VoucherRequest :: " + voucherRequest); final List<String> cookies = headers.get("cookie"); log.debug("cookies::" + cookies); final List<MediaType> mediaTypes = new ArrayList<MediaType>(); mediaTypes.add(MediaType.ALL); final String cookie = cookies.stream().collect(Collectors.joining(";")); log.debug("Cookie for voucher request header :: " + cookie); final HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set(HttpHeaders.COOKIE, cookie); requestHeaders.setPragma("no-cache"); requestHeaders.setConnection("keep-alive"); requestHeaders.setCacheControl("no-cache"); requestHeaders.setAccept(mediaTypes); requestHeaders.setContentType(MediaType.APPLICATION_JSON); requestHeaders.setAccessControlAllowOrigin(headers.getOrigin()); log.debug("Request Headers for Voucher Request :: " + requestHeaders); final HttpEntity requestEntity = new HttpEntity(voucherRequest, requestHeaders); log.debug("Request Entity ::" + requestEntity); final ResponseEntity<JSONObject> response = restTemplate.exchange(createVoucherUrl, HttpMethod.POST, requestEntity, JSONObject.class); log.debug("Response From Voucher API :: " + response); final JSONObject voucherResponse = response.getBody(); log.debug("VoucherResponse :: " + voucherResponse); try { final VoucherResponse voucherRes = mapper.readValue(voucherResponse.toString(), VoucherResponse.class); final String voucherNumber = voucherRes.getVouchers().get(0).getVoucherNumber(); log.debug("Voucher Number is :: " + voucherNumber); return voucherNumber; } catch (final IOException e) { throw new RuntimeException("Voucher response Deserialization Issue :: " + e.getMessage()); } }
VoucherService { @SuppressWarnings({ "rawtypes", "unchecked" }) public String createVoucher(final VoucherRequest voucherRequest, final String tenantId, final HttpHeaders headers) { final String createVoucherUrl = applicationProperties.getHostNameForMonolithic(tenantId) + applicationProperties.getEgfServiceVoucherCreatePath() + "?tenantId=" + tenantId; log.debug("Voucher API Request URL :: " + createVoucherUrl); log.debug("VoucherRequest :: " + voucherRequest); final List<String> cookies = headers.get("cookie"); log.debug("cookies::" + cookies); final List<MediaType> mediaTypes = new ArrayList<MediaType>(); mediaTypes.add(MediaType.ALL); final String cookie = cookies.stream().collect(Collectors.joining(";")); log.debug("Cookie for voucher request header :: " + cookie); final HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set(HttpHeaders.COOKIE, cookie); requestHeaders.setPragma("no-cache"); requestHeaders.setConnection("keep-alive"); requestHeaders.setCacheControl("no-cache"); requestHeaders.setAccept(mediaTypes); requestHeaders.setContentType(MediaType.APPLICATION_JSON); requestHeaders.setAccessControlAllowOrigin(headers.getOrigin()); log.debug("Request Headers for Voucher Request :: " + requestHeaders); final HttpEntity requestEntity = new HttpEntity(voucherRequest, requestHeaders); log.debug("Request Entity ::" + requestEntity); final ResponseEntity<JSONObject> response = restTemplate.exchange(createVoucherUrl, HttpMethod.POST, requestEntity, JSONObject.class); log.debug("Response From Voucher API :: " + response); final JSONObject voucherResponse = response.getBody(); log.debug("VoucherResponse :: " + voucherResponse); try { final VoucherResponse voucherRes = mapper.readValue(voucherResponse.toString(), VoucherResponse.class); final String voucherNumber = voucherRes.getVouchers().get(0).getVoucherNumber(); log.debug("Voucher Number is :: " + voucherNumber); return voucherNumber; } catch (final IOException e) { throw new RuntimeException("Voucher response Deserialization Issue :: " + e.getMessage()); } } }
VoucherService { @SuppressWarnings({ "rawtypes", "unchecked" }) public String createVoucher(final VoucherRequest voucherRequest, final String tenantId, final HttpHeaders headers) { final String createVoucherUrl = applicationProperties.getHostNameForMonolithic(tenantId) + applicationProperties.getEgfServiceVoucherCreatePath() + "?tenantId=" + tenantId; log.debug("Voucher API Request URL :: " + createVoucherUrl); log.debug("VoucherRequest :: " + voucherRequest); final List<String> cookies = headers.get("cookie"); log.debug("cookies::" + cookies); final List<MediaType> mediaTypes = new ArrayList<MediaType>(); mediaTypes.add(MediaType.ALL); final String cookie = cookies.stream().collect(Collectors.joining(";")); log.debug("Cookie for voucher request header :: " + cookie); final HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set(HttpHeaders.COOKIE, cookie); requestHeaders.setPragma("no-cache"); requestHeaders.setConnection("keep-alive"); requestHeaders.setCacheControl("no-cache"); requestHeaders.setAccept(mediaTypes); requestHeaders.setContentType(MediaType.APPLICATION_JSON); requestHeaders.setAccessControlAllowOrigin(headers.getOrigin()); log.debug("Request Headers for Voucher Request :: " + requestHeaders); final HttpEntity requestEntity = new HttpEntity(voucherRequest, requestHeaders); log.debug("Request Entity ::" + requestEntity); final ResponseEntity<JSONObject> response = restTemplate.exchange(createVoucherUrl, HttpMethod.POST, requestEntity, JSONObject.class); log.debug("Response From Voucher API :: " + response); final JSONObject voucherResponse = response.getBody(); log.debug("VoucherResponse :: " + voucherResponse); try { final VoucherResponse voucherRes = mapper.readValue(voucherResponse.toString(), VoucherResponse.class); final String voucherNumber = voucherRes.getVouchers().get(0).getVoucherNumber(); log.debug("Voucher Number is :: " + voucherNumber); return voucherNumber; } catch (final IOException e) { throw new RuntimeException("Voucher response Deserialization Issue :: " + e.getMessage()); } }  }
VoucherService { @SuppressWarnings({ "rawtypes", "unchecked" }) public String createVoucher(final VoucherRequest voucherRequest, final String tenantId, final HttpHeaders headers) { final String createVoucherUrl = applicationProperties.getHostNameForMonolithic(tenantId) + applicationProperties.getEgfServiceVoucherCreatePath() + "?tenantId=" + tenantId; log.debug("Voucher API Request URL :: " + createVoucherUrl); log.debug("VoucherRequest :: " + voucherRequest); final List<String> cookies = headers.get("cookie"); log.debug("cookies::" + cookies); final List<MediaType> mediaTypes = new ArrayList<MediaType>(); mediaTypes.add(MediaType.ALL); final String cookie = cookies.stream().collect(Collectors.joining(";")); log.debug("Cookie for voucher request header :: " + cookie); final HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set(HttpHeaders.COOKIE, cookie); requestHeaders.setPragma("no-cache"); requestHeaders.setConnection("keep-alive"); requestHeaders.setCacheControl("no-cache"); requestHeaders.setAccept(mediaTypes); requestHeaders.setContentType(MediaType.APPLICATION_JSON); requestHeaders.setAccessControlAllowOrigin(headers.getOrigin()); log.debug("Request Headers for Voucher Request :: " + requestHeaders); final HttpEntity requestEntity = new HttpEntity(voucherRequest, requestHeaders); log.debug("Request Entity ::" + requestEntity); final ResponseEntity<JSONObject> response = restTemplate.exchange(createVoucherUrl, HttpMethod.POST, requestEntity, JSONObject.class); log.debug("Response From Voucher API :: " + response); final JSONObject voucherResponse = response.getBody(); log.debug("VoucherResponse :: " + voucherResponse); try { final VoucherResponse voucherRes = mapper.readValue(voucherResponse.toString(), VoucherResponse.class); final String voucherNumber = voucherRes.getVouchers().get(0).getVoucherNumber(); log.debug("Voucher Number is :: " + voucherNumber); return voucherNumber; } catch (final IOException e) { throw new RuntimeException("Voucher response Deserialization Issue :: " + e.getMessage()); } }  @SuppressWarnings({ "rawtypes", "unchecked" }) String createVoucher(final VoucherRequest voucherRequest, final String tenantId, final HttpHeaders headers); VoucherAccountCodeDetails getGlCodes(final RequestInfo requestInfo, final String tenantId,
            final Long accountId, final BigDecimal amount, final Boolean iscredit, final Boolean isDebit); List<ChartOfAccountContract> getChartOfAccounts(final RequestInfo requestInfo, final String tenantId,
            final Long accountId); List<ChartOfAccountDetailContract> getSubledgerDetails(final RequestInfo requestInfo, final String tenantId,
            final Long accountId); void validateSubLedgerDetails(final List<ChartOfAccountDetailContract> creditableCOA,
            final List<ChartOfAccountDetailContract> debitableCOA); VoucherRequest createRevaluationVoucherRequest(final Revaluation revaluation,
            final List<VoucherAccountCodeDetails> accountCodeDetails, final Long assetId, final Long departmentId,
            final HttpHeaders header); VoucherRequest createDisposalVoucherRequest(final Disposal disposal, final Long assetId,
            final Long departmentId, final List<VoucherAccountCodeDetails> accountCodeDetails,final String functionCode,
            final HttpHeaders header); VoucherRequest createDepreciationVoucherRequest(
            final List<DepreciationInputs> depreciationInputsList, final Long departmentId,final String functionCode,final Long assetId,
           final Long depreciationId,  final List<VoucherAccountCodeDetails> accountCodeDetails, final String tenantId, final HttpHeaders header); void setFinancialParameters(final Voucher voucher, final List<VoucherAccountCodeDetails> accountCodeDetails,
            final String tenantId,final String functionCode); }
VoucherService { @SuppressWarnings({ "rawtypes", "unchecked" }) public String createVoucher(final VoucherRequest voucherRequest, final String tenantId, final HttpHeaders headers) { final String createVoucherUrl = applicationProperties.getHostNameForMonolithic(tenantId) + applicationProperties.getEgfServiceVoucherCreatePath() + "?tenantId=" + tenantId; log.debug("Voucher API Request URL :: " + createVoucherUrl); log.debug("VoucherRequest :: " + voucherRequest); final List<String> cookies = headers.get("cookie"); log.debug("cookies::" + cookies); final List<MediaType> mediaTypes = new ArrayList<MediaType>(); mediaTypes.add(MediaType.ALL); final String cookie = cookies.stream().collect(Collectors.joining(";")); log.debug("Cookie for voucher request header :: " + cookie); final HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set(HttpHeaders.COOKIE, cookie); requestHeaders.setPragma("no-cache"); requestHeaders.setConnection("keep-alive"); requestHeaders.setCacheControl("no-cache"); requestHeaders.setAccept(mediaTypes); requestHeaders.setContentType(MediaType.APPLICATION_JSON); requestHeaders.setAccessControlAllowOrigin(headers.getOrigin()); log.debug("Request Headers for Voucher Request :: " + requestHeaders); final HttpEntity requestEntity = new HttpEntity(voucherRequest, requestHeaders); log.debug("Request Entity ::" + requestEntity); final ResponseEntity<JSONObject> response = restTemplate.exchange(createVoucherUrl, HttpMethod.POST, requestEntity, JSONObject.class); log.debug("Response From Voucher API :: " + response); final JSONObject voucherResponse = response.getBody(); log.debug("VoucherResponse :: " + voucherResponse); try { final VoucherResponse voucherRes = mapper.readValue(voucherResponse.toString(), VoucherResponse.class); final String voucherNumber = voucherRes.getVouchers().get(0).getVoucherNumber(); log.debug("Voucher Number is :: " + voucherNumber); return voucherNumber; } catch (final IOException e) { throw new RuntimeException("Voucher response Deserialization Issue :: " + e.getMessage()); } }  @SuppressWarnings({ "rawtypes", "unchecked" }) String createVoucher(final VoucherRequest voucherRequest, final String tenantId, final HttpHeaders headers); VoucherAccountCodeDetails getGlCodes(final RequestInfo requestInfo, final String tenantId,
            final Long accountId, final BigDecimal amount, final Boolean iscredit, final Boolean isDebit); List<ChartOfAccountContract> getChartOfAccounts(final RequestInfo requestInfo, final String tenantId,
            final Long accountId); List<ChartOfAccountDetailContract> getSubledgerDetails(final RequestInfo requestInfo, final String tenantId,
            final Long accountId); void validateSubLedgerDetails(final List<ChartOfAccountDetailContract> creditableCOA,
            final List<ChartOfAccountDetailContract> debitableCOA); VoucherRequest createRevaluationVoucherRequest(final Revaluation revaluation,
            final List<VoucherAccountCodeDetails> accountCodeDetails, final Long assetId, final Long departmentId,
            final HttpHeaders header); VoucherRequest createDisposalVoucherRequest(final Disposal disposal, final Long assetId,
            final Long departmentId, final List<VoucherAccountCodeDetails> accountCodeDetails,final String functionCode,
            final HttpHeaders header); VoucherRequest createDepreciationVoucherRequest(
            final List<DepreciationInputs> depreciationInputsList, final Long departmentId,final String functionCode,final Long assetId,
           final Long depreciationId,  final List<VoucherAccountCodeDetails> accountCodeDetails, final String tenantId, final HttpHeaders header); void setFinancialParameters(final Voucher voucher, final List<VoucherAccountCodeDetails> accountCodeDetails,
            final String tenantId,final String functionCode);  }