Home

Awesome

Java CI with Maven

Karate Starter

This Getting Started Guide shows how to setup a SpringBoot based REST service and test it using Karate from within IntelliJ, maven, and gradle.

The Rest Service

This is a standard Spring Boot application that exposes two APIs

Hello API

$ curl localhost:8080/api/hello
Hello world!

The fancy version when a name is passed in as a parameter...

$ curl localhost:8080/api/hello?name=Daas
Hello Daas!

Person API

Create a person

$ curl -X POST localhost:8080/api/person -H 'Content-type:application/json' -d '{"firstName": "John", "lastName" : "Doe", "age" : 30}'
42

Get a person by his/her id

$ curl localhost:8080/api/person/42
{"firstName":"John","lastName":"Doe","age":30}

Setting Up Karate

The folder structure for Karate tests is given in the Karate documentation on folder structure, but the summary is that:

A *.feature file has the same syntax as Gherkin/Cucumber and is also described in Karate documentation. The key points are

The karate-config.js file in the /test/java folder contains the environment and global variables used by Karate. This is is basically a javascript function that returns a JSON object. Which means that the file cannot contain any comment statements before the function body.

Logging Configuration

Logging configuration is controlled by the /test/java/logback.xml file as explained in the Karate documentation on logging.

Setting up your Laptop

On Macs, you need to have an entry in your /etc/hosts file that contains an entry with your machine name. For example ...

127.0.0.1	localhost -MY-MACHINE-NAME-

This happens due to the way netty works in Karate. This issue is supposed to be fixed in Karate 1.0 (TODO - check if this is still valid for Karate 1.4 )

Running the tests

This repo contains a mix of unit tests (e.g., PersonServiceTests.java), springboot tests using TestRestTemplate (e.g, GreetingControllerTests.java) and Karate Tests (*.feature file). There is also KarateTests.java which is a springboot tests that invokes all the karate tests.

There is no need to start the application when running the tests - that will happen automatically.

Starting only the application

Developer Instructions

This repo uses github actions to automatically build and test the app whenever code is pushed to master branch. See maven.yml

Release process

See the process to prepare and perform the release, but the steps are ...

References