📌Aim : To create a service to manage the Customer details. Using this service we should be able to store and retrieve the customer informations.
FRAMEWORK USED : SPRINGBOOT
DATABASE: POSTGRESQL
FRAMEWORK USED FOR UNIT TESTING: JUNIT,MOCKITO
DOCKER TO CONTAINARIZE THE SPRINGBOOT APPLICATION
RDS INSTANCE FOR DEPLOYING PSQL DATABASE
EC2 INSTANCE FOR DEPLOYING THE SPRINGBOOT APPLICATION
Package: COM.ROCKETLANE.SPRING.JPA.POSTGRESQL.MODEL
The data model (Customer) is defined with the fields: ID, FIRSTNAME, LASTNAME, EMAILID, MOBILENO, CITY and ADDRESS.
Package: COM.ROCKETLANE.SPRING.JPA.POSTGRESQL.REPOSITORY
In the repository package, CustomerRepository interface extends JpaRepository .
It provides method for easy retrieval from the database without the need for manual implementation.
Package: COM.ROCKETLANE.SPRING.JPA.POSTGRESQL.CONTROLLER
Customer controller is the controller which exposes REST endpoints for the CRUD Operation.
🚀CREATE- HTTP POST METHOD
One POST method to create a new customer record in the database.
🚀READ- HTTP GET METHOD
Two GET methods to retrieve customer records from the database. One gets all the customer details and the other gets a single record given a customer ID.
🚀UPDATE- HTTP PUT METHOD
One PUT method to update a customer record in the database given the customer id of the record to be updated is given.
DELETE- HTTP DELETE METHOD
One DELETE method to delete a customer record in the database given the customer id of the record to be deleted.
| Method | API |
|---|---|
| CREATE | HTTP POST http://localhost:8080/customers |
| READ | HTTP GET http://localhost:8080/customers/2 |
| UPDATE | HTTP PUT http://localhost:8080/customers/2 |
| DELETE | HTTP DELETE http://localhost:8080/customers/2 |
| Status Code | Details |
|---|---|
| 200 | Success - OK |
| 201 | Success - Created |
| 204 | Sucess - No Content |
| 400 | ClientError - Bad Request |
| 404 | ClientError - Not Found |
| 500 | Server Error - Internal Server Error |
| Testcase | Purpose | Result |
|---|---|---|
| 1. getAllCustomers_success() | To check if all customer record is retrieved and status code is OK | ✔ |
| 2. getAllCustomers_EmptyDatabase() | Checking if NoContent status is sent if the database is empty. | ✔ |
| 3. getCustomerById_success() | Testing if the getCustomerById works correctly and returns success status code if given a valid ID. | ✔ |
| 4. getCustomerbyId_InvalidId() | Testing if the getCustomerById method returns not found status given an incorrect id. | ✔ |
| 5. postCustomer_success() | Checking if a new customer record is created successfully given the valid info | ✔ |
| 6. postCustomer_failure() | Checking if creating a incorrect record results in bad request. | ✔ |
| 7. putCustomer_success() | Checking if put method is working perfectly if given the correct id to be updated. | ✔ |
| 8. putCustomer_recordNotFound() | Checking if not found status is sent if incorrect id is given. | ✔ |
| 9. deleteCustomerbyId_success | Checking if deletion works fine if given a valid ID. | ✔ |
| 10. deleteCustomerbyId_notFound() | Checking if bad request status is sent if given a invalid id | ✔ |