diff --git a/src/test/java/com/bankofspring/test/controller/AccountControllerTest.java b/src/test/java/com/bankofspring/test/controller/AccountControllerTest.java index d1e0c38..a22534c 100644 --- a/src/test/java/com/bankofspring/test/controller/AccountControllerTest.java +++ b/src/test/java/com/bankofspring/test/controller/AccountControllerTest.java @@ -39,6 +39,12 @@ public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); } + /** + * Get all accounts test. + * All the accounts in the database should be returned as a result of this test and validation of total 10 accounts should pass. + * + * @throws Exception + */ @Test public void ut1_GetAccounts() throws Exception{ mockMvc @@ -48,6 +54,12 @@ public void ut1_GetAccounts() throws Exception{ .andDo(print()); } + /** + * Get Account details test. + * Fetching the details for account with id 1 should be allowed and valid details should be returned. + * + * @throws Exception + */ @Test public void ut2_GetAccountByNumber() throws Exception { mockMvc @@ -78,6 +90,12 @@ public void ut2_GetAccountByNumber() throws Exception { .andDo(print()); } + /** + * Get Account by number test for invalid account number. + * Trying to get an account's detail with invalid account number should result in a Http 400 error. + * + * @throws Exception + */ @Test public void ut3_GetAccountByNumber_InvalidAccount() throws Exception { mockMvc @@ -88,6 +106,12 @@ public void ut3_GetAccountByNumber_InvalidAccount() throws Exception { .andDo(print()); } + /** + * Create Account test. + * Account with details given in the test is created as a result of the test execution. + * + * @throws Exception + */ @Test public void ut4_CreateAccount() throws Exception { mockMvc @@ -121,6 +145,13 @@ public void ut4_CreateAccount() throws Exception { .andDo(print()); } + /** + * Create Account test for Invalid Customer. + * Trying to create an account for a customer with id 100 should be disallowed. + * A Http 400 should be thrown with message indicating that customer id 100 doesn't yet exist. + * + * @throws Exception + */ @Test public void ut4_CreateAccount_InvalidCustomer() throws Exception { mockMvc @@ -133,4 +164,109 @@ public void ut4_CreateAccount_InvalidCustomer() throws Exception { .andExpect(jsonPath("$.apierror.message").value("Customer was not found for parameters {customerId=100}")) .andDo(print()); } + + /** + * Deposit Money test. + * Account # 1 : Initial amount is $100 + * A deposit of $50 should be allowed and resultant balance should be $150. + * + * @throws Exception + */ + @Test + public void ut5_DepositMoney() throws Exception { + mockMvc + .perform(MockMvcRequestBuilders.post("/v1/account/deposit") + .contentType(MediaType.APPLICATION_JSON) + .content("{\"accountNumber\":\"1\", \"depositAmt\":\"50\"}") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.accountNumber").value(1)) + .andExpect(jsonPath("$.balance").value(150)) + .andDo(print()); + } + + /** + * Withdraw Money test. + * Account # 1 : Amount after ut5 is $150 + * A withdrawal of 50 should be allowed and new account balance should be $100. + * + * @throws Exception + */ + @Test + public void ut6_WithdrawMoney() throws Exception { + mockMvc + .perform(MockMvcRequestBuilders.post("/v1/account/withdraw") + .contentType(MediaType.APPLICATION_JSON) + .content("{\"accountNumber\":\"1\", \"withdrawlAmt\":\"50\"}") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.accountNumber").value(1)) + .andExpect(jsonPath("$.balance").value(100)) + .andDo(print()); + } + + /** + * Withdraw Money test for negative scenario. + * Account # 1 : Amount after ut6 is $100 + * A withdrawal of $200 should raise a InsufficientFund Exception and send a Http 400 response. + * + * @throws Exception + */ + @Test + public void ut7_WithdrawMoney_InsufficientFunds() throws Exception { + mockMvc + .perform(MockMvcRequestBuilders.post("/v1/account/withdraw") + .contentType(MediaType.APPLICATION_JSON) + .content("{\"accountNumber\":\"1\", \"withdrawlAmt\":\"200\"}") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isBadRequest()) + .andExpect(jsonPath("$.apierror.status").value("BAD_REQUEST")) + .andExpect(jsonPath("$.apierror.message").value("Insufficient funds in account number - 1. Cannot allow withdrawal of $200.")) + .andDo(print()); + } + + /** + * Transfer Money test. + * Account # 1 : Initial Amount 100 + * Account # 2 : Initial Amount 200 + * Once the test completes, $50 should be transferred from Account # 1 to Account # 2 + * + * @throws Exception + */ + @Test + public void ut8_TransferMoney() throws Exception { + mockMvc + .perform(MockMvcRequestBuilders.post("/v1/account/transfer") + .contentType(MediaType.APPLICATION_JSON) + .content("{\"debitAccountNumber\":\"1\", \"creditAccountNumber\":\"2\", \"amount\":\"50\"}") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.[0].accountNumber").value(1)) + .andExpect(jsonPath("$.[1].accountNumber").value(2)) + .andExpect(jsonPath("$.[0].balance").value(50)) + .andExpect(jsonPath("$.[1].balance").value(250)) + .andDo(print()); + } + + /** + * Transfer Money test to a non existent recipient. + * Account # 1 : Initial Amount 100 + * Account # 2 : doesn't exist + * Once the test completes, an Http 404 error should be returned indicating the recipient doesn't exist. + * + * @throws Exception + */ + @Test + public void ut9_TransferMoney_InvalidRecipient() throws Exception { + mockMvc + .perform(MockMvcRequestBuilders.post("/v1/account/transfer") + .contentType(MediaType.APPLICATION_JSON) + .content("{\"debitAccountNumber\":\"1\", \"creditAccountNumber\":\"20\", \"amount\":\"50\"}") + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isNotFound()) + .andExpect(jsonPath("$.apierror.status").value("NOT_FOUND")) + .andExpect(jsonPath("$.apierror.message").value("Account was not found for parameters {accountNumber=20}")) + .andDo(print()); + } + } diff --git a/src/test/java/com/bankofspring/test/controller/CustomerControllerTest.java b/src/test/java/com/bankofspring/test/controller/CustomerControllerTest.java index d1511d3..d8bb63d 100644 --- a/src/test/java/com/bankofspring/test/controller/CustomerControllerTest.java +++ b/src/test/java/com/bankofspring/test/controller/CustomerControllerTest.java @@ -39,6 +39,12 @@ public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); } + /** + * Get all customers test. + * The test should result in returning the 5 customers which are present in the test database. + * + * @throws Exception + */ @Test public void ut1_GetAllCustomers() throws Exception{ mockMvc @@ -48,6 +54,12 @@ public void ut1_GetAllCustomers() throws Exception{ .andDo(print()); } + /** + * Get customer by ssn test. + * The test should result in returning customer's details for SSN:AK01 + * + * @throws Exception + */ @Test public void ut2_GetCustomerBySsn() throws Exception{ mockMvc @@ -70,6 +82,12 @@ public void ut2_GetCustomerBySsn() throws Exception{ .andDo(print()); } + /** + * Get customer by invalid ssn test. + * The test should result in returning a Http 404 for a customer with invalid ssn. + * + * @throws Exception + */ @Test public void ut3_GetCustomerBySsn_InvalidSsn() throws Exception { mockMvc @@ -80,6 +98,12 @@ public void ut3_GetCustomerBySsn_InvalidSsn() throws Exception { .andDo(print()); } + /** + * Create customer test. + * The test should result in adding a new customer to the database with SSN:TK01 + * + * @throws Exception + */ @Test public void ut4_CreateCustomer() throws Exception{ mockMvc @@ -105,7 +129,12 @@ public void ut4_CreateCustomer() throws Exception{ .andDo(print()); } - + /** + * Create duplicate customer test. + * Since a customer with SSN:TK01 has already been created in ut4, this test should result in Http 404. + * + * @throws Exception + */ @Test public void ut5_CreateCustomer_Duplicate() throws Exception { mockMvc