Skip to content

A REST API with H2 database memory, unit test with Junit and Jacoco report

Notifications You must be signed in to change notification settings

LauroSilveira/appzara

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rest API APPZARA

This is a microservice rest for ZARA recruitment.

About this project

About

Business rules

Given a day and time, a database search is carried out to bring up the price with the tariff to be applied. If more than one element is found, some rules will apply:

  • If the result finds two rates that coincide, the one with the highest value will apply.

Architecture

Architecture-hexagonal.png

APPLICATION

Layer that implements the UseCase and contains the business rule

BOOTSTRAP

This module is responsible for instantiating the other modules of the application. As the name suggests, it is the bootstrap.

DOMAIN

Module containing the application entities.

INFRASTRUCTURE

Infrastructure layer that connects to database and other services.

Technologies

  • Java 21
  • Spring boot 3.2.3
  • Spring Data
  • Database H2 Memory
  • Mapstruct
  • Junit
  • Mockito
  • Jacoco Reporter

How to Run

Clone the repository:

git clone clone https://github.com/LauroSilveira/appzara.git

Get in the appzara folder:

cd appzara/appzara

how to execute the Spring context put following command in your prompt:

mvn spring-boot:run

And how to stop:

ctrl c

In the Infrastructure module there is a PriceController with a GET endpoint with the following parameters:

  • startDate (mandatory): date must be int the format yyyy-MM-dd-HH.mm.ss e.g. 2020-06-16-21.00.00
  • productId (mandatory): id of product e.g. 35455
  • brandId (mandatory): id of brand e.g: 1 (ZARA)

Lets see some examples of request

Request to day 14 of 2020 at 10:00 hrs

curl --location 'http://localhost:8080/price/startDate/2020-06-14-10.00.00/productId/35455/brandId/1'

The response will be:

{
  "brandId": 1,
  "productId": "35455",
  "priority": 1,
  "rate": 4,
  "startDate": "2020-06-15T16:00:00",
  "endDate": "2020-12-31T23:59:59",
  "amount": 38.95
}

Request to day 14 of 2020 at 16:00 hrs

curl --location 'http://localhost:8080/price/startDate/2020-06-14-16.00.00/productId/35455/brandId/1'

The response will be:

{
  "brandId": 1,
  "productId": "35455",
  "priority": 1,
  "rate": 4,
  "startDate": "2020-06-15T16:00:00",
  "endDate": "2020-12-31T23:59:59",
  "amount": 38.95
}

Request to day 14 of 2020 at 21:00 hrs

curl --location 'http://localhost:8080/price/startDate/2020-06-14-21.00.00/productId/35455/brandId/1'

The response will be:

{
    "brandId": 1,
    "productId": "35455",
    "priority": 1,
    "rate": 4,
    "startDate": "2020-06-15T16:00:00",
    "endDate": "2020-12-31T23:59:59",
    "amount": 38.95
}

Request to day 15 of 2020 at 21:00 hrs

curl --location 'http://localhost:8080/price/startDate/2020-06-15-21.00.00/productId/35455/brandId/1'

The response will be:

{
  "brandId": 1,
  "productId": "35455",
  "priority": 1,
  "rate": 3,
  "startDate": "2020-06-15T00:00:00",
  "endDate": "2020-06-15T11:00:00",
  "amount": 30.50
}

Request to day 16 of 2020 at 21:00 hrs

curl --location 'http://localhost:8080/price/startDate/2020-06-16-21.00.00/productId/35455/brandId/1'

The response will be:

{
    "brandId": 1,
    "productId": "35455",
    "priority": 1,
    "rate": 3,
    "startDate": "2020-06-15T00:00:00",
    "endDate": "2020-06-15T11:00:00",
    "amount": 30.50
}

How to run Tests

This project has jacoco-report with we are able to see coverage after execute tests. There is unit tests and integration test. The integration test has the annotation @ActiveProfile("test") with you want to execute it. To execute all test just run:

mvn test

After execute tests jacoco-report will generate an index.html file with coverage. The directory of this file is appzara/bootstrap/target/site/jacoco-aggregate/index.html.

directory_index_jacoco.png

Open it in your default browser to see the coverage of each module

coverage-updated.png

Contributors

@LauroSilveira

About

A REST API with H2 database memory, unit test with Junit and Jacoco report

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages