Skip to content

Commit

Permalink
Added /health/group endpoint for custom checks
Browse files Browse the repository at this point in the history
Signed-off-by: Prashanth G <pgunapal@ca.ibm.com>
  • Loading branch information
pgunapal committed Jan 21, 2020
1 parent dcc40d5 commit b0dcb9b
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
11 changes: 11 additions & 0 deletions spec/src/main/asciidoc/protocol-wireformat.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ Aspects regarding the secure access of health check information.
| Custom with given name
| See Appendix B

| /health/group
| GET
| 200, 500, 503
| All custom groups
| See Appendix B

| /health
| GET
| 200, 500, 503
Expand All @@ -215,6 +221,7 @@ The following table gives valid health check responses for all kinds of health c
| /health/live
/health/ready
/health/group/{name}
/health/group
/health
| 200
| Yes
Expand All @@ -224,6 +231,7 @@ The following table gives valid health check responses for all kinds of health c
| /health/live
/health/ready
/health/group/{name}
/health/group
/health
| 200
| Yes
Expand All @@ -233,6 +241,7 @@ The following table gives valid health check responses for all kinds of health c
| /health/live
/health/ready
/health/group/{name}
/health/group
/health
| 503
| Yes
Expand All @@ -242,6 +251,7 @@ The following table gives valid health check responses for all kinds of health c
| /health/live
/health/ready
/health/group/{name}
/health/group
/health
| 503
| Yes
Expand All @@ -251,6 +261,7 @@ The following table gives valid health check responses for all kinds of health c
| /health/live
/health/ready
/health/group/{name}
/health/group
/health
| 500
| No
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICES file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/

package org.eclipse.microprofile.health.tck;

import javax.json.JsonArray;
import javax.json.JsonObject;


import org.eclipse.microprofile.health.tck.deployment.FailedCustom;
import org.eclipse.microprofile.health.tck.deployment.SuccessfulCustom;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.shrinkwrap.api.Archive;
import org.testng.Assert;
import org.testng.annotations.Test;

import static org.eclipse.microprofile.health.tck.DeploymentUtils.createWarFileWithClasses;

/**
* @author Prashanth Gunapalasingam
*/
public class AllCustomFailedTest extends TCKBase {

@Deployment
public static Archive getDeployment() {
return createWarFileWithClasses(AllCustomFailedTest.class.getSimpleName(),
FailedCustom.class, SuccessfulCustom.class);
}

/**
* Verifies the custom health integration with CDI at the scope of a server runtime, by retrieving all the custom checks.
*/
@Test
@RunAsClient
public void testFailureResponsePayload() {
Response response = getUrlAllCustomHealthContents();

// status code
Assert.assertEquals(response.getStatus(),503);

JsonObject json = readJson(response);

// response size
JsonArray checks = json.getJsonArray("checks");
Assert.assertEquals(checks.size(), 2, "Expected two check responses");

for (JsonObject check : checks.getValuesAs(JsonObject.class)) {
String id = check.getString("name");
switch (id) {
case "successful-check":
verifySuccessStatus(check);
break;
case "failed-check":
verifyFailureStatus(check);
break;
default:
Assert.fail("Unexpected response payload structure");
}
}

assertOverallFailure(json);
}

}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017 Contributors to the Eclipse Foundation
* Copyright (c) 2017-2020 Contributors to the Eclipse Foundation
*
* See the NOTICES file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -65,6 +65,10 @@ public void beforeMethod(Method method) {
Response getUrlHealthContents() {
return getUrlContents(this.uri + "/health", false);
}

Response getUrlAllCustomHealthContents() {
return getUrlContents(this.uri + "/health/group", false);
}

Response getUrlCustomHealthContents(String name) {
return getUrlContents(this.uri + "/health/group/" + name , false);
Expand Down

0 comments on commit b0dcb9b

Please sign in to comment.