November 2018
Intermediate to advanced
388 pages
9h 5m
English
Let's refactor the integration test code that we wrote by removing some duplicates and hardcoded string values.
Note that the code for creating the Jersey client and invoking the API is the same for the getToken() and getOrg() functions. Consequently, we will create a new function that takes the URI and headers and an HTTP method type:
private fun execute(resourceUri: String, map: Map<String, String>, httpMethod: String): JSONObject { val client = Client.create() val webResource = client.resource(resourceUri) .accept(MediaType.APPLICATION_JSON) for (entry in map) { webResource.header(entry.key, entry.value) } val response: ClientResponse = webResource .method(httpMethod, ClientResponse::class.java)
Read now
Unlock full access