Demo Spring Boot application exposing a REST API to enable performing of CRUD operations on an entity.
The application stores the created entity in memory.
Build Spring Boot application with Java 17:
mvn clean install
Start Docker containers:
docker-compose up -d
Start Spring Boot application:
java -jar target/springboot-rest-1.0.0.jar
In a terminal window use curl to submit a POST REST request to the application to create an item:
curl -i -X POST localhost:9001/v1/items -H "Content-Type: application/json" -d '{"name": "test-item"}'
A response should be returned with the 201 CREATED status code and the new item id in the Location header:
HTTP/1.1 201
Location: 653d06f08faa89580090466e
The Spring Boot application should log the successful item persistence:
Item created with id: 653d06f08faa89580090466e
Get the item that has been created using curl:
curl -i -X GET localhost:9001/v1/items/653d06f08faa89580090466e
A response should be returned with the 200 SUCCESS status code and the item in the response body:
HTTP/1.1 200
Content-Type: application/json
{"id":"653d06f08faa89580090466e","name":"test-item"}
In a terminal window use curl to submit a PUT REST request to the application to update the item:
curl -i -X PUT localhost:9001/v1/items/653d06f08faa89580090466e -H "Content-Type: application/json" -d '{"name": "test-item-update"}'
A response should be returned with the 204 NO CONTENT status code:
HTTP/1.1 204
The Spring Boot application should log the successful update of the item:
Item updated with id: 653d06f08faa89580090466e - name: test-item-update
Get all items that have been created using curl:
curl -i -X GET localhost:9001/v1/items
Delete the item using curl:
curl -i -X DELETE localhost:9001/v1/items/653d06f08faa89580090466e
The Spring Boot application should log the successful deletion of the item:
Deleted item with id: 653d06f08faa89580090466e
Stop containers:
docker-compose down
Demonstrates spinning up the application in a docker container and hitting this via the REST API to create, retrieve, update, and delete an item.
For more on the component tests see: https://github.com/lydtechconsulting/component-test-framework
Build Spring Boot application jar:
mvn clean install
Build Docker container:
docker build -t ct/springboot-rest:latest .
Run tests:
mvn test -Pcomponent
Run tests leaving containers up:
mvn test -Pcomponent -Dcontainers.stayup
Manual clean up (if left containers up):
docker rm -f $(docker ps -aq)
Manual clean up (if left containers up):
docker rm -f $(docker ps -aq)
Further docker clean up if network/other issues:
docker system prune
docker volume prune