diff --git a/code/src/test/java/com/networknt/oauth/code/handler/HealthTest.java b/code/src/test/java/com/networknt/oauth/code/handler/HealthTest.java new file mode 100644 index 00000000..12feaa98 --- /dev/null +++ b/code/src/test/java/com/networknt/oauth/code/handler/HealthTest.java @@ -0,0 +1,55 @@ +package com.networknt.oauth.code.handler; + +import com.networknt.client.Http2Client; +import com.networknt.exception.ClientException; +import io.undertow.UndertowOptions; +import io.undertow.client.ClientConnection; +import io.undertow.client.ClientRequest; +import io.undertow.client.ClientResponse; +import io.undertow.util.Methods; +import org.junit.Assert; +import org.junit.ClassRule; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.xnio.IoUtils; +import org.xnio.OptionMap; + +import java.net.URI; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicReference; + + +public class HealthTest { + @ClassRule + public static TestServer server = TestServer.getInstance(); + + static final Logger logger = LoggerFactory.getLogger(HealthTest.class); + + @Test + public void testHealthCheck() throws Exception { + final Http2Client client = Http2Client.getInstance(); + final CountDownLatch latch = new CountDownLatch(1); + final ClientConnection connection; + try { + connection = client.connect(new URI("https://localhost:6881"), Http2Client.WORKER, Http2Client.SSL, Http2Client.BUFFER_POOL, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get(); + } catch (Exception e) { + throw new ClientException(e); + } + final AtomicReference reference = new AtomicReference<>(); + try { + ClientRequest request = new ClientRequest().setMethod(Methods.GET).setPath("/health/com.networknt.oauth2-code-1.0.0"); + connection.sendRequest(request, client.createClientCallback(reference, latch)); + latch.await(); + int statusCode = reference.get().getResponseCode(); + String body = reference.get().getAttachment(Http2Client.RESPONSE_BODY); + Assert.assertEquals(statusCode, 200); + Assert.assertEquals("OK", body); + } catch (Exception e) { + logger.error("Exception: ", e); + throw new ClientException(e); + } finally { + IoUtils.safeClose(connection); + } + } +} diff --git a/code/src/test/java/com/networknt/oauth/code/handler/Oauth2CodeGetHandlerTest.java b/code/src/test/java/com/networknt/oauth/code/handler/Oauth2CodeGetHandlerTest.java index b0a4cfa7..c69fe4fb 100644 --- a/code/src/test/java/com/networknt/oauth/code/handler/Oauth2CodeGetHandlerTest.java +++ b/code/src/test/java/com/networknt/oauth/code/handler/Oauth2CodeGetHandlerTest.java @@ -15,6 +15,7 @@ import org.ietf.jgss.GSSName; import org.junit.Assert; import org.junit.ClassRule; +import org.junit.Ignore; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -513,7 +514,8 @@ public Void run() throws Exception { } - //@Test + @Test + @Ignore public void testMarketPlaceClient() throws Exception { final Http2Client client = Http2Client.getInstance(); final CountDownLatch latch = new CountDownLatch(1); diff --git a/code/src/test/resources/config/openapi.yaml b/code/src/test/resources/config/openapi.yaml index bfc7eaf3..308e3f45 100644 --- a/code/src/test/resources/config/openapi.yaml +++ b/code/src/test/resources/config/openapi.yaml @@ -139,3 +139,17 @@ paths: - j_password - response_type - client_id + /health/{serviceId}: + get: + description: Return OK with response code 200 to indicate healthy + operationId: getHealth + parameters: + - name: serviceId + description: 'serviceId for the code service' + in: path + required: true + schema: + type: string + responses: + '200': + description: Successful Operation