Skip to content

Latest commit

 

History

History
103 lines (74 loc) · 2.39 KB

README.md

File metadata and controls

103 lines (74 loc) · 2.39 KB

Collatz REST API

by Martin Scheelke

   

A very simple REST API/microservice for asynchronous calculation of Collatz series terms - see Collatz Conjecture. The interface returns immediately when it receives an instruction to calculate a Collatz term. The result can then be retrieved by polling the interface.

This project demonstrates the following ideas:

  • Spark Java - a lightweight, drop-in HTTP server.
  • SOLID programming principles.
  • Dependency injection without using a framework such as Spring.
  • Kotlin's tail recursion optimisation - Java and Kotlin are combined in single Gradle project.
  • Simple CI/CD with Docker and CircleCI.
  • Gson for JSON handling.
  • Test Driven Development.
  • RESTAssured for declarative, JUnit driven REST interface tests.
  • Mocking with the Mockito framework

Install and Test Instructions

   

Clone

Clone this repo to your local machine:

https://github.com/martin-scheelke/collatz.git

 

Setup

  • Install the gradle wrapper:
gradle wrapper --gradle-version 6.3

 

Run unit and integration tests with non-thread-safe data store access:

 

  • Edit the properties file at ./collatz/src/main/resources/.properties:
  • Specify the DAO class: Set collatz.data.CollatzDAOImpl
 gradlew clean test --info

 

Run unit and integration tests with thread-safe data store:

 

  • Edit the properties file at ./collatz/src/main/resources/.properties
  • Specify the DAO class: Set collatz.data.ConcurrentCollatzDAOImpl
 gradlew clean test --info

 

Test outputs can be found at ../collatz/build/reports/tests/test/index.html

 

Manually test the REST API

Start the REST service:

gradlew runREST

Example tests with curl:

curl -X PUT http://localhost:4567/collatz/323
curl -X GET http://localhost:4567/collatz/323
curl -X GET http://localhost:4567/collatz
curl -X DELETE http://localhost:4567/collatz/323
curl -X DELETE http://localhost:4567/collatz

 

CircleCi integration

For CI/CT integration with CircleCi - build and test in a docker image - see:   https://app.circleci.com/pipelines/github/martin-scheelke/collatz

 

Code Style