Fix broken network management server status endpoint (#397)

* add missing Path annotation and test

* Address PR issue
This commit is contained in:
Patrick Kuo 2018-01-24 14:41:12 +00:00 committed by GitHub
parent 55385613ac
commit 45b23737c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -8,9 +8,9 @@ import javax.ws.rs.Produces
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.Response
@Path("/status")
class MonitoringWebService(private val serverStatus: NetworkManagementServerStatus) {
@GET
@Path("status")
@Produces(MediaType.APPLICATION_JSON)
fun status(): Response {
return Response.ok(ObjectMapper().writeValueAsString(serverStatus)).build()

View File

@ -0,0 +1,24 @@
package com.r3.corda.networkmanage.doorman.webservice
import com.r3.corda.networkmanage.doorman.NetworkManagementServerStatus
import com.r3.corda.networkmanage.doorman.NetworkManagementWebServer
import net.corda.core.internal.openHttpConnection
import net.corda.core.utilities.NetworkHostAndPort
import org.codehaus.jackson.map.ObjectMapper
import org.junit.Test
import java.net.URL
import kotlin.test.assertEquals
class MonitoringWebServiceTest {
@Test
fun `get server status`() {
val status = NetworkManagementServerStatus()
val jsonStatus = ObjectMapper().writeValueAsString(status)
NetworkManagementWebServer(NetworkHostAndPort("localhost", 0), MonitoringWebService(status)).use {
it.start()
val conn = URL("http://${it.hostAndPort}/status").openHttpConnection()
assertEquals(200, conn.responseCode)
assertEquals(jsonStatus, conn.inputStream.bufferedReader().readLine())
}
}
}