This is a simple RESTful API for the Grocery List App
This is a Spring Boot application that exposes the necessary REST services for the Grocery List App.
The OpenAPI Specification v3 of the services are described in the file:
open-api-specs/grocery-list-api.yaml
You can copy the content of the file and paste it in the Swagger Editor to see the description of all services in the project.
This is a screenshoot of the Swagger Editor with the specifications
./gradlew build
./gradlew test
You will find a complete report of the result os the tests in:
build/reports/test/index.html
The tests were written in Spock Framework using the language Groovy.
All test are located in:
src/test/groovy/com/rideco/grocery/controllers/ProductsControllerSpec.groovy
here is an example of one of several tests:
def "create a product with NULL name throws BAD_REQUEST response"() {
given: "a request body with null name"
def createProductRequestBody = [
name : null,
description: '1 bottle'
]
when: "create the new product"
def response = mvc.perform(
post("/rest/products")
.contentType(MediaType.APPLICATION_JSON)
.content(toJson(createProductRequestBody))
)
then: "the response is BAD_REQUEST"
response.andExpect(status().isBadRequest())
and: "the error code is VALIDATION_ERROR"
ErrorResponse errorResponse = parseErrorResponse(response.andReturn().response.contentAsString)
errorResponse.errorCode == ErrorResponseCode.VALIDATION_ERROR
}