Skip to content

Spring Boot project that exposes a REST API documented with OpenAPI, using H2 database for deployment and testing.

License

Notifications You must be signed in to change notification settings

david-rojo/pvp-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PVP Manager

This is a Java 8 project that exposes a REST API documented with OpenAPI, developed with SpringBoot 2.3.1 using H2 database for persistency with an initial load of data. It implements the following scenario.

It has been done following the MVC design pattern and using Spring Tool Suite 4

H2 database

For primary key of the PRICES table has been chosen three fields: BRAND_ID, PRODUCT_ID and PRICE_LIST. This decision has been done thinking that cannot be a row in the table that has the same values for these fields.

Data types for each field:

FIELD DATA TYPE
BRAND_ID INTEGER
PRICE_LIST INTEGER
PRODUCT_ID INTEGER
PRIORITY INTEGER
START_DATE TIMESTAMP
END_DATE TIMESTAMP
PRICE DOUBLE
CURR VARCHAR(255)

Deployment

Once that the repository has been cloned:

$ git clone https://github.com/david-rojo/pvp-manager.git

import the project in your IDE and to execute it, right click of the mouse in spring-boot-pvpmanager folder in Package Explorer window and select Run as > Spring Boot App

The project is deployed and ready to verify that implements the requested scenario. You can access to its exposed API here: http://localhost:8080/pvp-manager-api.html

PVP MANAGER OPEN API

To verify the scenario, you can test in the OpenAPI User Interface, the get method in pvp group writing manually all the values or you can simply click in the following links that use the same data that is used in each test:

  • Test1: has to return priceList 1

  • Test2: has to return priceList 2

  • Test3: has to return priceList 1

  • Test4: has to return priceList 3

  • Test5: has to return priceList 4

Implementation of the controller can be examinated in PvpApiController class

Additional work

Going beyond the scope of the scenario, a full CRUD set of operations has been implemented for the application in order to manage PRICES table:

  • Add a new price.
  • Update an existing price.
  • Delete an existing price by ID.
  • Get all prices in the table.

Implemention can be examinated in PriceApiController class

Access to h2 console

When the project is deployed, also is available h2 console: http://localhost:8080/h2-console in order to connect there and verify that the database initially has the requested content.

H2 CONSOLE

This data can be used to login:

Driver Class:	org.h2.Driver
JDBC URL:	jdbc:h2:mem:pvpmanagerdb;DB_CLOSE_ON_EXIT=FALSE
User Name:	sa
Password:	password

Once we are logged, we can check the content of PRICES table executing this query:

SELECT * FROM PRICES 

PRICES TABLE CONTENT

Executing JUnit tests

To run the requested tests we can do it executing this command from spring-boot-pvpmanager folder:

$ mvn test 

Note: mvn has to be installed in order to execute the command

Near of the end of the execution log, we can find this line:

[INFO] Results:
[INFO] 
[INFO] Tests run: 12, Failures: 0, Errors: 0, Skipped: 0
[INFO] 

Detail of each test can be found previously of this text above.

Five tests has been requested in the scenario, testing the rest endpoint, but the project contains also additional tests to check that select operations to database works fine.

JUnitTests classes:

About

Spring Boot project that exposes a REST API documented with OpenAPI, using H2 database for deployment and testing.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages