@Test(expected = CustomException.class) public void initiateTransactionFailTest(){ Transaction txn = Transaction.builder().txnAmount("100") .billId("ORDER0012") .productInfo("Property Tax Payment") .gateway("ABCD123") .build(); TransactionRequest transactionRequest = new TransactionRequest(requestInfo, txn); Mockito.doThrow(new CustomException("INVALID_GATEWAY", "Invalid Gateway")).when(validator).validateCreateTxn(any(TransactionRequest.class)); when(gatewayService.initiateTxn(any(Transaction.class))).thenThrow(new CustomException()); Transaction resp = transactionService.initiateTransaction(transactionRequest); }
public Transaction initiateTransaction(TransactionRequest transactionRequest) { validator.validateCreateTxn(transactionRequest); enrichmentService.enrichCreateTransaction(transactionRequest); RequestInfo requestInfo = transactionRequest.getRequestInfo(); Transaction transaction = transactionRequest.getTransaction(); TransactionDump dump = TransactionDump.builder() .txnId(transaction.getTxnId()) .auditDetails(transaction.getAuditDetails()) .build(); if(validator.skipGateway(transaction)){ transaction.setTxnStatus(Transaction.TxnStatusEnum.SUCCESS); generateReceipt(requestInfo, transaction); } else{ URI uri = gatewayService.initiateTxn(transaction); transaction.setRedirectUrl(uri.toString()); dump.setTxnRequest(uri.toString()); } producer.push(appProperties.getSaveTxnTopic(), new org.egov.pg.models.TransactionRequest (requestInfo, transaction)); producer.push(appProperties.getSaveTxnDumpTopic(), new TransactionDumpRequest(requestInfo, dump)); return transaction; }
TransactionService { public Transaction initiateTransaction(TransactionRequest transactionRequest) { validator.validateCreateTxn(transactionRequest); enrichmentService.enrichCreateTransaction(transactionRequest); RequestInfo requestInfo = transactionRequest.getRequestInfo(); Transaction transaction = transactionRequest.getTransaction(); TransactionDump dump = TransactionDump.builder() .txnId(transaction.getTxnId()) .auditDetails(transaction.getAuditDetails()) .build(); if(validator.skipGateway(transaction)){ transaction.setTxnStatus(Transaction.TxnStatusEnum.SUCCESS); generateReceipt(requestInfo, transaction); } else{ URI uri = gatewayService.initiateTxn(transaction); transaction.setRedirectUrl(uri.toString()); dump.setTxnRequest(uri.toString()); } producer.push(appProperties.getSaveTxnTopic(), new org.egov.pg.models.TransactionRequest (requestInfo, transaction)); producer.push(appProperties.getSaveTxnDumpTopic(), new TransactionDumpRequest(requestInfo, dump)); return transaction; } }
TransactionService { public Transaction initiateTransaction(TransactionRequest transactionRequest) { validator.validateCreateTxn(transactionRequest); enrichmentService.enrichCreateTransaction(transactionRequest); RequestInfo requestInfo = transactionRequest.getRequestInfo(); Transaction transaction = transactionRequest.getTransaction(); TransactionDump dump = TransactionDump.builder() .txnId(transaction.getTxnId()) .auditDetails(transaction.getAuditDetails()) .build(); if(validator.skipGateway(transaction)){ transaction.setTxnStatus(Transaction.TxnStatusEnum.SUCCESS); generateReceipt(requestInfo, transaction); } else{ URI uri = gatewayService.initiateTxn(transaction); transaction.setRedirectUrl(uri.toString()); dump.setTxnRequest(uri.toString()); } producer.push(appProperties.getSaveTxnTopic(), new org.egov.pg.models.TransactionRequest (requestInfo, transaction)); producer.push(appProperties.getSaveTxnDumpTopic(), new TransactionDumpRequest(requestInfo, dump)); return transaction; } @Autowired  TransactionService(TransactionValidator validator, GatewayService gatewayService, Producer producer,
                       TransactionRepository
                               transactionRepository, CollectionService collectionService,
                       EnrichmentService enrichmentService,
                       AppProperties appProperties); }
TransactionService { public Transaction initiateTransaction(TransactionRequest transactionRequest) { validator.validateCreateTxn(transactionRequest); enrichmentService.enrichCreateTransaction(transactionRequest); RequestInfo requestInfo = transactionRequest.getRequestInfo(); Transaction transaction = transactionRequest.getTransaction(); TransactionDump dump = TransactionDump.builder() .txnId(transaction.getTxnId()) .auditDetails(transaction.getAuditDetails()) .build(); if(validator.skipGateway(transaction)){ transaction.setTxnStatus(Transaction.TxnStatusEnum.SUCCESS); generateReceipt(requestInfo, transaction); } else{ URI uri = gatewayService.initiateTxn(transaction); transaction.setRedirectUrl(uri.toString()); dump.setTxnRequest(uri.toString()); } producer.push(appProperties.getSaveTxnTopic(), new org.egov.pg.models.TransactionRequest (requestInfo, transaction)); producer.push(appProperties.getSaveTxnDumpTopic(), new TransactionDumpRequest(requestInfo, dump)); return transaction; } @Autowired  TransactionService(TransactionValidator validator, GatewayService gatewayService, Producer producer,
                       TransactionRepository
                               transactionRepository, CollectionService collectionService,
                       EnrichmentService enrichmentService,
                       AppProperties appProperties); Transaction initiateTransaction(TransactionRequest transactionRequest); List<Transaction> getTransactions(TransactionCriteria transactionCriteria); List<Transaction> updateTransaction(RequestInfo requestInfo, Map<String, String> requestParams); }
TransactionService { public Transaction initiateTransaction(TransactionRequest transactionRequest) { validator.validateCreateTxn(transactionRequest); enrichmentService.enrichCreateTransaction(transactionRequest); RequestInfo requestInfo = transactionRequest.getRequestInfo(); Transaction transaction = transactionRequest.getTransaction(); TransactionDump dump = TransactionDump.builder() .txnId(transaction.getTxnId()) .auditDetails(transaction.getAuditDetails()) .build(); if(validator.skipGateway(transaction)){ transaction.setTxnStatus(Transaction.TxnStatusEnum.SUCCESS); generateReceipt(requestInfo, transaction); } else{ URI uri = gatewayService.initiateTxn(transaction); transaction.setRedirectUrl(uri.toString()); dump.setTxnRequest(uri.toString()); } producer.push(appProperties.getSaveTxnTopic(), new org.egov.pg.models.TransactionRequest (requestInfo, transaction)); producer.push(appProperties.getSaveTxnDumpTopic(), new TransactionDumpRequest(requestInfo, dump)); return transaction; } @Autowired  TransactionService(TransactionValidator validator, GatewayService gatewayService, Producer producer,
                       TransactionRepository
                               transactionRepository, CollectionService collectionService,
                       EnrichmentService enrichmentService,
                       AppProperties appProperties); Transaction initiateTransaction(TransactionRequest transactionRequest); List<Transaction> getTransactions(TransactionCriteria transactionCriteria); List<Transaction> updateTransaction(RequestInfo requestInfo, Map<String, String> requestParams);  }