Skip to content

Commit

Permalink
Added integration test cases, updated unit test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
arpitkhandelwal1984 committed Jul 2, 2018
1 parent 6f826a0 commit ec0dacb
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 33 deletions.
9 changes: 7 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,18 @@ http://<host-name>:8080/swagger-ui.html
````

## Unit test cases
There are multiple unit test cases written to cover the different components of the application. However there is a global application test suite file _**BankOfSpringApplicationTests.java**_ that combines all the test cases in a logical manner to create a complete suite. It can be run from command prompt using the following command -
There are multiple unit test cases written to cover the different components of the application. However there is a global application test suite file _**BankOfSpringApplicationUnitTests.java**_ that combines all the test cases in a logical manner to create a complete suite. It can be run from command prompt using the following command -

````
mvn clean test -Dtest=BankOfSpringApplicationTests
mvn clean test -Dtest=BankOfSpringApplicationUnitTests
````

## Integration test cases
There are multiple integration test cases written to cover the different components of the application. However there is a global application test suite file _**BankOfSpringApplicationTests.java**_ that combines all the test cases in a logical manner to create a complete suite. It can be run from command prompt using the following command -

````
mvn clean test -Dtest=BankOfSpringApplicationTests
````

## Contributors
[Arpit Khandelwal](https://www.linkedin.com/in/arpitkhandelwal1984/)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/bankofspring/dto/CustomerDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
@JsonIgnoreProperties(ignoreUnknown = true)
public class CustomerDto {
private Long customerId;
private String name;
private String ssn;
private String name;
private String address1;
private String address2;
private String city;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/bankofspring/exception/ApiError.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.DatabindContext;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver;
import com.fasterxml.jackson.databind.jsontype.impl.TypeIdResolverBase;
import com.fasterxml.jackson.databind.type.SimpleType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
Expand All @@ -14,6 +18,7 @@
import org.springframework.validation.ObjectError;

import javax.validation.ConstraintViolation;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -148,4 +153,5 @@ public String idFromValueAndType(Object value, Class<?> suggestedType) {
public JsonTypeInfo.Id getMechanism() {
return JsonTypeInfo.Id.CUSTOM;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
@Service
public class CustomerServiceImpl implements CustomerService {
@Autowired
CustomerRepository customerRepository;
private CustomerRepository customerRepository;

@Autowired
ModelMapper mapper;
private ModelMapper mapper;

@Override
public List<Customer> getAllCustomers() {
Expand Down
Binary file added src/main/resources/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.bankofspring;

import com.bankofspring.test.controller.AccountControllerTest;
import com.bankofspring.test.controller.CustomerControllerTest;
import com.bankofspring.integrationtest.controller.AccountControllerTest;
import com.bankofspring.integrationtest.controller.CustomerControllerTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.bankofspring;


import com.bankofspring.unittest.controller.CustomerControllerMockMvcStandaloneTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;


@RunWith(Suite.class)
@Suite.SuiteClasses({
CustomerControllerMockMvcStandaloneTest.class
})
/**
* Created by Arpit Khandelwal.
*/
public class BankOfSpringApplicationUnitTests {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bankofspring.test.controller;
package com.bankofspring.integrationtest.controller;

import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
Expand Down Expand Up @@ -40,8 +40,8 @@ public void setup() {
}

/**
* 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.
* Get all accounts integrationtest.
* All the accounts in the database should be returned as a result of this integrationtest and validation of total 10 accounts should pass.
*
* @throws Exception
*/
Expand All @@ -55,7 +55,7 @@ public void ut1_GetAccounts() throws Exception{
}

/**
* Get Account details test.
* Get Account details integrationtest.
* Fetching the details for account with id 1 should be allowed and valid details should be returned.
*
* @throws Exception
Expand Down Expand Up @@ -91,7 +91,7 @@ public void ut2_GetAccountByNumber() throws Exception {
}

/**
* Get Account by number test for invalid account number.
* Get Account by number integrationtest for invalid account number.
* Trying to get an account's detail with invalid account number should result in a Http 400 error.
*
* @throws Exception
Expand All @@ -107,8 +107,8 @@ public void ut3_GetAccountByNumber_InvalidAccount() throws Exception {
}

/**
* Create Account test.
* Account with details given in the test is created as a result of the test execution.
* Create Account integrationtest.
* Account with details given in the integrationtest is created as a result of the integrationtest execution.
*
* @throws Exception
*/
Expand Down Expand Up @@ -146,7 +146,7 @@ public void ut4_CreateAccount() throws Exception {
}

/**
* Create Account test for Invalid Customer.
* Create Account integrationtest 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.
*
Expand All @@ -166,7 +166,7 @@ public void ut4_CreateAccount_InvalidCustomer() throws Exception {
}

/**
* Deposit Money test.
* Deposit Money integrationtest.
* Account # 1 : Initial amount is $100
* A deposit of $50 should be allowed and resultant balance should be $150.
*
Expand All @@ -186,7 +186,7 @@ public void ut5_DepositMoney() throws Exception {
}

/**
* Withdraw Money test.
* Withdraw Money integrationtest.
* Account # 1 : Amount after ut5 is $150
* A withdrawal of 50 should be allowed and new account balance should be $100.
*
Expand All @@ -206,7 +206,7 @@ public void ut6_WithdrawMoney() throws Exception {
}

/**
* Withdraw Money test for negative scenario.
* Withdraw Money integrationtest 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.
*
Expand All @@ -226,10 +226,10 @@ public void ut7_WithdrawMoney_InsufficientFunds() throws Exception {
}

/**
* Transfer Money test.
* Transfer Money integrationtest.
* Account # 1 : Initial Amount 100
* Account # 2 : Initial Amount 200
* Once the test completes, $50 should be transferred from Account # 1 to Account # 2
* Once the integrationtest completes, $50 should be transferred from Account # 1 to Account # 2
*
* @throws Exception
*/
Expand All @@ -249,10 +249,10 @@ public void ut8_TransferMoney() throws Exception {
}

/**
* Transfer Money test to a non existent recipient.
* Transfer Money integrationtest 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.
* Once the integrationtest completes, an Http 404 error should be returned indicating the recipient doesn't exist.
*
* @throws Exception
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bankofspring.test.controller;
package com.bankofspring.integrationtest.controller;

import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
Expand Down Expand Up @@ -40,8 +40,8 @@ public void setup() {
}

/**
* Get all customers test.
* The test should result in returning the 5 customers which are present in the test database.
* Get all customers integrationtest.
* The integrationtest should result in returning the 5 customers which are present in the integrationtest database.
*
* @throws Exception
*/
Expand All @@ -55,8 +55,8 @@ public void ut1_GetAllCustomers() throws Exception{
}

/**
* Get customer by ssn test.
* The test should result in returning customer's details for SSN:AK01
* Get customer by ssn integrationtest.
* The integrationtest should result in returning customer's details for SSN:AK01
*
* @throws Exception
*/
Expand All @@ -83,8 +83,8 @@ public void ut2_GetCustomerBySsn() throws Exception{
}

/**
* Get customer by invalid ssn test.
* The test should result in returning a Http 404 for a customer with invalid ssn.
* Get customer by invalid ssn integrationtest.
* The integrationtest should result in returning a Http 404 for a customer with invalid ssn.
*
* @throws Exception
*/
Expand All @@ -99,8 +99,8 @@ public void ut3_GetCustomerBySsn_InvalidSsn() throws Exception {
}

/**
* Create customer test.
* The test should result in adding a new customer to the database with SSN:TK01
* Create customer integrationtest.
* The integrationtest should result in adding a new customer to the database with SSN:TK01
*
* @throws Exception
*/
Expand Down Expand Up @@ -130,8 +130,8 @@ public void ut4_CreateCustomer() throws Exception{
}

/**
* Create duplicate customer test.
* Since a customer with SSN:TK01 has already been created in ut4, this test should result in Http 404.
* Create duplicate customer integrationtest.
* Since a customer with SSN:TK01 has already been created in ut4, this integrationtest should result in Http 404.
*
* @throws Exception
*/
Expand Down
Empty file.
Loading

0 comments on commit ec0dacb

Please sign in to comment.