protected void setUp() throws Exception { super.setUp(); classToTest = new GenericBankValidationTransformer(); classToTest.setReporter(new ErrorReporter()); mockdao = new BankDataAccessMock(new SQLServerDataSource()); classToTest.setDao(mockdao); }
// Test case to check if the account number has enough digits with filetype set to cash public void testTransformer4InvalidFileType2() throws Exception { DonorBankCplxType bank = new DonorBankCplxType(); bank.setBankAccNo("1"); bank.setBankAccName("Test Name"); bank.setBankSort("45-12-34"); GOSHCC goshcc = new GOSHCC(); final DonorCplxType donorCplxType = new DonorCplxType(); donorCplxType.setFirstName("TesterFirst"); donorCplxType.setLastName("TesterLast"); donorCplxType.setPostCode("CR0 6RT"); DonationDetails donationDetails = new DonationDetails(); DirectDebitDonationCplxType directDebitDonationCplxType = new DirectDebitDonationCplxType(); directDebitDonationCplxType.setDonorBankCplxType(bank); donationDetails.setDirectDebitDonationCplxType(directDebitDonationCplxType); donorCplxType.setDonationDetails(donationDetails); goshcc.getDonorCplxType().add(donorCplxType); header.put(MessageHeaderName.FILE_TYPE.getName(), FileType.CASH_TYPE); final GenericMessage<GOSHCC> message = new GenericMessage<GOSHCC>(goshcc, header); Message<GOSHCC> transformedMessage = classToTest.transform(message); ArrayList<String> errorArray = (ArrayList<String>) transformedMessage.getHeaders().get(MessageHeaderName.ERROR_HEADER.getName()); assertNull("No errors expected", errorArray); }
// Case 2 when multiple bankIDs are returned by the dao public void testSetBankID2() throws Exception { List<String> bankIds = new ArrayList<String>(); bankIds.add("7865564"); bankIds.add("7865564"); mockdao.bankIDs = bankIds; DonorBankCplxType bank = new DonorBankCplxType(); bank.setBankAccNo("78908766"); bank.setBankAccName("TesterFirst"); bank.setBankSort("7691382193"); bank.setBankName("Any Bank"); bank.setBankSort("an-ys-or"); bank.setBranchName("Buckingham palace"); GOSHCC goshcc = new GOSHCC(); final DonorCplxType donorCplxType = new DonorCplxType(); donorCplxType.setFirstName("TesterFirst"); donorCplxType.setLastName("TesterLast"); donorCplxType.setPostCode("CR0 6RT"); DonationDetails donationDetails = new DonationDetails(); DirectDebitDonationCplxType directDebitDonationCplxType = new DirectDebitDonationCplxType(); directDebitDonationCplxType.setDonorBankCplxType(bank); donationDetails.setDirectDebitDonationCplxType(directDebitDonationCplxType); donorCplxType.setDonationDetails(donationDetails); goshcc.getDonorCplxType().add(donorCplxType); header.put(MessageHeaderName.FILE_TYPE.getName(), FileType.DD_TYPE); final GenericMessage<GOSHCC> message = new GenericMessage<GOSHCC>(goshcc, header); Message<GOSHCC> transformedMessage = classToTest.transform(message); ArrayList<String> errorArray = (ArrayList<String>) transformedMessage.getHeaders().get(MessageHeaderName.ERROR_HEADER.getName()); assertNotNull("1 error expected", errorArray); assertEquals("No. of errors don't match the expected", 1, errorArray.size()); ArrayList<String> infoArray = (ArrayList<String>) transformedMessage.getHeaders().get(MessageHeaderName.INFO_HEADER.getName()); assertNotNull("1 info expected, none found", infoArray); String infoMsg = "Multiple banks found for the following bank details: an-ys-or, Any Bank and Buckingham palace;"; assertEquals("Info messages dont match", infoMsg, infoArray.get(0)); }
// Case 1 when bankID is returned by the dao public void testSetBankID() throws Exception { List<String> bankIds = new ArrayList<String>(); bankIds.add("7865564"); mockdao.bankIDs = bankIds; DonorBankCplxType bank = new DonorBankCplxType(); bank.setBankAccNo("78908766"); bank.setBankAccName("TesterFirst"); bank.setBankSort("7691382193"); bank.setBankName("Any Bank"); bank.setBankSort("an-ys-or"); bank.setBranchName("Buckingham palace"); GOSHCC goshcc = new GOSHCC(); final DonorCplxType donorCplxType = new DonorCplxType(); donorCplxType.setFirstName("TesterFirst"); donorCplxType.setLastName("TesterLast"); donorCplxType.setPostCode("CR0 6RT"); DonationDetails donationDetails = new DonationDetails(); DirectDebitDonationCplxType directDebitDonationCplxType = new DirectDebitDonationCplxType(); directDebitDonationCplxType.setDonorBankCplxType(bank); donationDetails.setDirectDebitDonationCplxType(directDebitDonationCplxType); donorCplxType.setDonationDetails(donationDetails); goshcc.getDonorCplxType().add(donorCplxType); header.put(MessageHeaderName.FILE_TYPE.getName(), FileType.DD_TYPE); final GenericMessage<GOSHCC> message = new GenericMessage<GOSHCC>(goshcc, header); Message<GOSHCC> transformedMessage = classToTest.transform(message); ArrayList<String> errorArray = (ArrayList<String>) transformedMessage.getHeaders().get(MessageHeaderName.ERROR_HEADER.getName()); assertNull("No errors expected", errorArray); BigInteger bankID = transformedMessage .getPayload() .getDonorCplxType() .get(0) .getDonationDetails() .getDirectDebitDonationCplxType() .getDonorBankCplxType() .getBankID(); assertEquals("bankIDs dont match", BigInteger.valueOf(7865564), bankID); }
// Test case to check if the account number has enough digits and blank sortcode with filetype set // to cash public void testTransformerBlankSort() throws Exception { DonorBankCplxType bank = new DonorBankCplxType(); bank.setBankAccNo("78908"); bank.setBankAccName("Test Name"); bank.setBankSort(" "); GOSHCC goshcc = new GOSHCC(); final DonorCplxType donorCplxType = new DonorCplxType(); donorCplxType.setFirstName("TesterFirst"); donorCplxType.setLastName("TesterLast"); donorCplxType.setPostCode("CR0 6RT"); DonationDetails donationDetails = new DonationDetails(); DirectDebitDonationCplxType directDebitDonationCplxType = new DirectDebitDonationCplxType(); directDebitDonationCplxType.setDonorBankCplxType(bank); donationDetails.setDirectDebitDonationCplxType(directDebitDonationCplxType); donorCplxType.setDonationDetails(donationDetails); goshcc.getDonorCplxType().add(donorCplxType); header.put(MessageHeaderName.FILE_TYPE.getName(), FileType.DD_TYPE); final GenericMessage<GOSHCC> message = new GenericMessage<GOSHCC>(goshcc, header); Message<GOSHCC> transformedMessage = classToTest.transform(message); ArrayList<String> errorArray = (ArrayList<String>) transformedMessage.getHeaders().get(MessageHeaderName.ERROR_HEADER.getName()); assertNotNull("No errors logged, 2 errors expected", errorArray); assertEquals("The number of expected errors dont match", 2, errorArray.size()); String expected = "There was an error for the following donors: [TesterFirst TesterLast of CR0 6RT] : Either Account Number OR Sort Code is empty and could cause and issue in BACS"; assertEquals("Error messages dont match", expected, errorArray.get(0)); expected = "There was an error for the following donors: [TesterFirst TesterLast of CR0 6RT] : The number of digits in the Bank Account Number are fewer than expected"; assertEquals("Error messages dont match", expected, errorArray.get(1)); }