Checkout Component 3.0 requirements:
-
Design and implement market checkout component with readable API that calculates the total price of a number of items.
-
Checkout mechanism can scan items and return actual price (is stateful)
-
Our goods are priced individually.
-
Some items are multipriced: buy N of them, and they'll cost you Y cents
Item Price Unit Special Price A 40 3 70 B 10 2 15 C 30 4 60 D 25 2 40 -
Client receives receipt containing list of all products with corresponding prices after payment
-
Some items are cheaper when bought together - buy item X with item Y and save Z cents
Item Price A,B 10 A,B,C,D 30 -
Additional Discount of 10% should be added if total order price (including other discounts/special prices) exceeds 600
-
Market can add any type of item or discount at any point in time.
-
Market stores data about quantity of all items sold in all its checkouts and all applied discounts
-
Perform a simple simulation of a market with 3 Checkouts and a single queue of 10 random baskets of items.
I implemented Checkout component using Spring boot and H2 database. Database schema is created on startup and initialized with data declared in file:
data.sql
You can log into database console using link:
localhost:9000/h2Console
Jdbc url, password and login is configured in the file:
application.properties
Running project:
mvn spring-boot:run
After start, application will run simulation and print results on console. You can also invoke simulation using REST API:
localhost:9000/simulation/{numberOfBaskets}/{maxNumberOfItemsInBasket}
I used pitest for mutation testing. You can execute
mvn org.pitest:pitest-maven:mutationCoverage
and check pitest report in directory:
target/pit-reports/