From 45b23737c779313f3ea9e1353db4cb74ff78ea57 Mon Sep 17 00:00:00 2001 From: Patrick Kuo Date: Wed, 24 Jan 2018 14:41:12 +0000 Subject: [PATCH] Fix broken network management server status endpoint (#397) * add missing Path annotation and test * Address PR issue --- .../webservice/MonitoringWebService.kt | 2 +- .../webservice/MonitoringWebServiceTest.kt | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 network-management/src/test/kotlin/com/r3/corda/networkmanage/doorman/webservice/MonitoringWebServiceTest.kt diff --git a/network-management/src/main/kotlin/com/r3/corda/networkmanage/doorman/webservice/MonitoringWebService.kt b/network-management/src/main/kotlin/com/r3/corda/networkmanage/doorman/webservice/MonitoringWebService.kt index 788b3e04aa..6625c1a38a 100644 --- a/network-management/src/main/kotlin/com/r3/corda/networkmanage/doorman/webservice/MonitoringWebService.kt +++ b/network-management/src/main/kotlin/com/r3/corda/networkmanage/doorman/webservice/MonitoringWebService.kt @@ -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() diff --git a/network-management/src/test/kotlin/com/r3/corda/networkmanage/doorman/webservice/MonitoringWebServiceTest.kt b/network-management/src/test/kotlin/com/r3/corda/networkmanage/doorman/webservice/MonitoringWebServiceTest.kt new file mode 100644 index 0000000000..72e4ff25ac --- /dev/null +++ b/network-management/src/test/kotlin/com/r3/corda/networkmanage/doorman/webservice/MonitoringWebServiceTest.kt @@ -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()) + } + } +} \ No newline at end of file