Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
#19 PingController handles now also the HEAD requests
Browse files Browse the repository at this point in the history
  • Loading branch information
achudzik committed Sep 11, 2014
1 parent 29fc03a commit 2cd2bb8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ext {

group = 'com.ofg'
description = 'Microservice default infrastructure Spring configuration'
version = '0.2.1-SNAPSHOT'
version = '0.2.1'
sourceCompatibility = 1.7

task addHashFile << {
Expand Down
7 changes: 6 additions & 1 deletion src/main/groovy/com/ofg/infrastructure/healthcheck/PingController.groovy
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RestController

import static org.springframework.http.MediaType.TEXT_PLAIN_VALUE
import static org.springframework.web.bind.annotation.RequestMethod.GET
import static org.springframework.web.bind.annotation.RequestMethod.HEAD

/**
* {@link RestController} that responds with OK when server is alive
*/
Expand All @@ -16,7 +21,7 @@ import org.springframework.web.bind.annotation.RestController
@Api(value = "ping", description = "PING API")
class PingController {

@RequestMapping(value = "/ping", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE)
@RequestMapping(value = "/ping", method = [GET, HEAD], produces = TEXT_PLAIN_VALUE)
@ApiOperation(value = "Ping server", notes = "Returns OK if server is alive")
String ping() {
return "OK"
Expand Down
18 changes: 18 additions & 0 deletions src/test/groovy/com/ofg/infrastructure/healthcheck/PingControllerMvcSpec.groovy
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.ofg.infrastructure.healthcheck
import com.ofg.infrastructure.base.BaseConfiguration
import com.ofg.infrastructure.base.MvcIntegrationSpec
import org.springframework.boot.test.SpringApplicationContextLoader
import org.springframework.http.HttpMethod
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder

import static org.springframework.http.MediaType.TEXT_PLAIN
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
Expand All @@ -19,4 +21,20 @@ class PingControllerMvcSpec extends MvcIntegrationSpec {
.andExpect(status().isOk())
.andExpect(content().string('OK'))
}

def "should return OK for HEAD requests from run.sh scripts"() {
expect:
mockMvc.perform(head('/ping'))
.andExpect(status().isOk())
}

/**
* Create a {@link org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder} for a HEAD request.
* @param urlTemplate a URL template; the resulting URL will be encoded
* @param urlVariables zero or more URL variables
*/
public static MockHttpServletRequestBuilder head(String urlTemplate, Object... urlVariables) {
return new MockHttpServletRequestBuilder(HttpMethod.HEAD, urlTemplate, urlVariables);
}

}

0 comments on commit 2cd2bb8

Please sign in to comment.