KEYCLOAK-18964 MetricsRestServiceTest contains wrong health check message

This commit is contained in:
Martin Bartoš 2021-08-04 10:15:32 +02:00 committed by Marek Posolda
parent 2acb43a627
commit 3c19fae88b

View file

@ -21,15 +21,14 @@ import javax.ws.rs.client.Client;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.keycloak.common.Profile;
import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.testsuite.AbstractKeycloakTest; import org.keycloak.testsuite.AbstractKeycloakTest;
import org.keycloak.testsuite.util.AdminClientUtil; import org.keycloak.testsuite.util.AdminClientUtil;
import org.keycloak.testsuite.util.ContainerAssume; import org.keycloak.testsuite.util.ContainerAssume;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.keycloak.testsuite.util.Matchers.body; import static org.keycloak.testsuite.util.Matchers.body;
import static org.keycloak.testsuite.util.Matchers.statusCodeIs; import static org.keycloak.testsuite.util.Matchers.statusCodeIs;
@ -53,15 +52,11 @@ public class MetricsRestServiceTest extends AbstractKeycloakTest {
@Test @Test
public void testHealthEndpoint() { public void testHealthEndpoint() {
Client client = AdminClientUtil.createResteasyClient(); Client client = AdminClientUtil.createResteasyClient();
final String serverReportedRunningPerMicroProfileHealthSubsystem = "{\"status\":\"UP\",\"checks\":[{"; final String expectedString = "{\"name\" : \"server-state\", \"outcome\" : true, \"data\" : [{ \"value\" : \"running\" }]}";
final String serverReportedRunningPerWildflyHealthSubsystem = "{\"name\" : \"server-state\", \"outcome\" : true, \"data\" : [{ \"value\" : \"running\" }]}";
// Post upgrade to Wildfly 22 expect output of Wildfly subsystem for health for community builds, and output of MicroProfile health subsystem for product builds
final String expectedString = Profile.getName().equals("community") ? serverReportedRunningPerWildflyHealthSubsystem : serverReportedRunningPerMicroProfileHealthSubsystem;
try (Response response = client.target("http://" + MGMT_HOST + ":" + MGMT_PORT + "/health").request().get()) { try (Response response = client.target("http://" + MGMT_HOST + ":" + MGMT_PORT + "/health").request().get()) {
Assert.assertThat(response, statusCodeIs(Status.OK)); assertThat(response, statusCodeIs(Status.OK));
Assert.assertThat(response, body(containsString(expectedString))); assertThat(response, body(containsString(expectedString)));
} finally { } finally {
client.close(); client.close();
} }
@ -72,8 +67,8 @@ public class MetricsRestServiceTest extends AbstractKeycloakTest {
Client client = AdminClientUtil.createResteasyClient(); Client client = AdminClientUtil.createResteasyClient();
try (Response response = client.target("http://" + MGMT_HOST + ":" + MGMT_PORT + "/metrics").request().get()) { try (Response response = client.target("http://" + MGMT_HOST + ":" + MGMT_PORT + "/metrics").request().get()) {
Assert.assertThat(response, statusCodeIs(Status.OK)); assertThat(response, statusCodeIs(Status.OK));
Assert.assertThat(response, body(containsString("base_memory_maxHeap_bytes"))); assertThat(response, body(containsString("base_memory_maxHeap_bytes")));
} finally { } finally {
client.close(); client.close();
} }