This is a Spring Boot 2.1.0 REST API with Swagger Documentation that uses Transactions and H2 as Database.
The main focus of this application is:
- Maintain Accounts and Transfer money between then.
The relationship between Account and Transfer was mapped with 2 @ManyToOne
annotations at the source
and target
accounts inside the Transfer.
There is a requirement, that the system need to be able to handle simultaneous transfer requests.
In order to process the simultaneous transfers, the system make use of transactions.
I just used the Optimistic Lock JPA feature, that controls the object version
to avoid invalid states in a distributed system.
As we are dealing with financial information, I used another JPA Feature called Auditing
, that maintain createadAt
and updatedAt
fields at the entities.
The application make use of RuntimeException
s for business flux control, that affects also the API responses.
There is a difference between the Requests and the Responses that is handled by the Controllers
and the Service
layer. There are some data that sometimes we don't want or we can't expose for external world.
Because of this, the application have different objects that comes in and out.
To convert the Objects, I have created a Functional Interface that can be implemented with the necessary objects.
There is data.sql
file that inserts 2 example accounts and 1 example transfer between them.
The software was built using the following tools/platforms:
- Linux Mint 19 - The Operational System that I use
- IntelliJ IDEA - The Java IDE I Love S2
- Java 8 - THE PROGRAMMING LANGUAGE
- Spring Boot 2.1.0 - The framework I use every day for building nice applications
- H2 Database - Database that can be used as a library
- Lombok - Framework used to reduce boilerplate code
- SpringFox - Library used to generate Swagger Documentation and UI
- Maven - Just Maven!
- JUnit - Used for tests
- AssertJ - assertThat() like a PRO
- Mockito - Mocking dependencies
- Jacoco - Test Coverage Library
In order to run the application, you need to have installed at your environment:
First, you have to generate the jar
with mvn
:
$ mvn clean install
You are ready to run with the command:
$ mvn springboot:run
The program will start embedded tomcat at port 8080, so you can now navigate to Swagger UI
Swagger Documentation could be reached HERE and can be imported to Postman, for example.
I tried to focus on the application CORE BUSINESS, so not all the classes were not tested on purpose.
- Test Coverage is 100% of Tested Classes
- The Coverage is measured by Jacoco library that gives a HTML report that can be reached at
target/site/jacoco/index.html
Exceptions
were not tested.PaymentChallengeApplication
was nos testedJpaConfiguration
andSwaggerConfig
were not testedmodel
package was not tested, but theAccount
class was, because of the business logic methodsDTOs
inside ofrequest
andresponse
packages were not tested@NotSameAccount
annotation was not tested