For building and running the application you need:
- KMARKET.postman_collection.json file... this file is a Postman Collection v2.1
- POST - http://localhost:8090/api/v1/carts/checkout
- RequestBody Example
- { "products" : ["SR1","CF1","GR1"] }
There are several ways to start the application Locally
For development purposes you can use the Spring Boot Maven plugin like so: in the command line from the root path of the project run:
mvn spring-boot:run -Dspring-boot.run.profiles=develop
This will fire up the application with an H2 on-memory database loaded. When you start the app you can access the h2 db using this url: http://localhost:8090/h2-console the user and pass are the default
to check the status of the application please use this url: http://localhost:8090/actuator/health
to see the API endpoints documentation you please check the swagger ui URL: http://localhost:8090/swagger-ui/#
You can use docker-compose to load the app with a MYSQL db. All the environment variables for docker were place in the .env-sample file. To generate a build and run with docker you need to create a .env file and copy and paste the vars from the .env-sample file into the new .env file
in the command line from the root path of the project run:
docker-compose up
to check the status of the application please use this url: http://localhost:8090/actuator/health
to see the API endpoints documentation you please check the swagger ui URL: http://localhost:8090/swagger-ui.html
if you need to re-run (without delete and stop all the process) the build and deploy new changes you can run in the command line from the root path:
docker-compose up --build
in order to stop the containers you should run in the command line from the root path:
docker-compose down --rmi local
this will stop the containers and remove the images from your computer.
When you use the build using the docker-compose file you will see that for every build you are going to generate a new image... so in order to delete the unused image please use this command:
docker image prune -f
In This case the Integration tests lifts all the spring context, and the tests are in the KmarketApplicationIT File I added one integration test that contains the special conditions required
- The CEO is a big fan of buy-one-get-one-free offers and of green tea. He wants us to add a rule to do this
- The COO, though, likes low prices and wants people buying strawberries to get a price discount for bulk purchases. If you buy 3 or more strawberries, the price should drop to £4.50 per strawberry.
- The CTO is a coffee addict. If you buy 3 or more coffees, the price of all coffees should drop to two thirds of the original price.
Also the Integration tests runs the unit tests. in order to run the integration tests you should run in the command line from the root path:
mvn -DSPRING_PROFILE_ACTIVE=integration-test integration-test verify
[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 8.385 s - in com.fx.kmarket.it.KmarketApplicationIT
In this case the Unit tests are in the CartServiceTest File In order to run Unit Tests with mocks you should run in the command line from the root path:
mvn -DSPRING_PROFILE_ACTIVE=test test
When Finished OK you will see this:
[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0
1. When you run docker-compose up... if you see warnings like this: WARN[0000] The "MYSQL_USER" variable, you should create the .env file
2. we need to improve the Docker Creation for the Release, since we're having SQL issues.
1. In the main branch the offers business logic is handle in an enum
2. In the strategy-offer branch the offers business logic is handle using a strategy pattern.
2. In the functional-implementation branch the offers business logic is handle using java functional features (Work in progress)