Client facing example : Key Value Client

The Key value client (kvClient) is a project we’re using to validate the client facing aspects of the Contract project. Its treated like a project that is a user of our code that wants to use every possible feature.

Its contracts are held separately in the kvServerContracts repository in order to share them with kvClient project.

Our test examples are written in Spock. Our methods are test framework agnostic.

Maven dependency

To test the client, we require our contract server.

<dependency>
    <groupId>org.seekay</groupId>
    <artifactId>contract-server</artifactId>
    <version>0.0.7</version>
    <scope>test</scope>
</dependency>

Features

The code to setup a server from a git source is identical for each test case.

Create

Exposes a method allowing creation of a key on the KvServer. The contract and unit test for this functionality is below.

{
  "request" : {
    "method" : "POST",
    "path" : "/kv/pair",
    "headers": {
      "Content-Type" : "application/json"
    },
    "body": "{
      "key": "age",
      "value": 27
    }
  },
  "response" : {
    "status" : 201,
    "body" : {
      "key": "age",
      "value": 27
    }
  }
}

Read

Exposes a method allowing the reading of a key from the KvServer. The contract and unit test for this functionality is below.

{
  "request" : {
    "method" : "GET",
    "path" : "/kv/pair/weight"
  },
  "response" : {
    "status" : 200,
    "body" : {
      "key": "weight",
      "value": "220"
    }
  }
}

Update

Exposes a method allowing updating of a key on the KvServer. The contract and unit test for this functionality is below.

{
  "request" : {
    "method" : "PUT",
    "path" : "/kv/pair",
    "headers": {
      "Content-Type" : "application/json"
    },
    "body": "{
        "key": "age",
        "value": 27
    }
  },
  "response" : {
    "status" : 201,
    "body" : {
        "key": "age",
        "value": 27
    }
  }
}

Delete

Exposes a method allowing the deleting of a key from the KvServer. The contract and unit test for this functionality is below.

{
  "request" : {
    "method" : "DELETE",
    "path" : "/kv/pair/blood-pressure"
  },
  "response" : {
    "status" : 204
  }
}