https://github.com/laurosilveira/appzara
A REST API with H2 database memory, unit test with Junit and Jacoco report
https://github.com/laurosilveira/appzara
h2-database jacoco-report junit5 rest-api spring-boot
Last synced: 2 months ago
JSON representation
A REST API with H2 database memory, unit test with Junit and Jacoco report
- Host: GitHub
- URL: https://github.com/laurosilveira/appzara
- Owner: LauroSilveira
- Created: 2023-09-03T20:42:17.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-18T10:34:01.000Z (over 2 years ago)
- Last Synced: 2024-10-06T01:22:51.175Z (almost 2 years ago)
- Topics: h2-database, jacoco-report, junit5, rest-api, spring-boot
- Language: Java
- Homepage:
- Size: 2.18 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rest API APPZARA
This is a microservice rest for ZARA recruitment.
## About this project
* [About](#about)
* [Architecture](#architecture)
* [Technologies](#technologies)
* [How to run](#how-to-run)
* [How to run tests](#how-to-run-tests)
* [Contributors](#contributors)
# 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

#### 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:
```json lines
{
"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:
```json lines
{
"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:
```json lines
{
"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:
```json lines
{
"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:
```json lines
{
"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`.

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

## Contributors
[@LauroSilveira](https://github.com/LauroSilveira)