Skip to content

Commit

Permalink
MP Health test development
Browse files Browse the repository at this point in the history
	refactoring
	negative scenario for MIME types
	multiple deployment / deployment with subdeployments scenario
	new health version test
	JavaDoc
  • Loading branch information
istraka committed Dec 11, 2019
1 parent 0867991 commit 2d8d489
Show file tree
Hide file tree
Showing 11 changed files with 500 additions and 17 deletions.
14 changes: 13 additions & 1 deletion microprofile-health/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jboss.eap.qe</groupId>
<artifactId>microprofile-test-suite</artifactId>
Expand Down Expand Up @@ -39,5 +38,18 @@
<artifactId>wildfly-arquillian-container-managed</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<artifactId>tooling-server-configuration</artifactId>
<groupId>org.jboss.eap.qe</groupId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.extras.creaper</groupId>
<artifactId>creaper-commands</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.jboss.eap.qe.microprofile.health;

import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.Liveness;
import org.eclipse.microprofile.health.Readiness;

@Liveness
@Readiness
public class SimplifiedHealthCheck implements HealthCheck {
@Override
public HealthCheckResponse call() {
return HealthCheckResponse.up("simplified");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,24 @@

@RunAsClient
@RunWith(Arquillian.class)
public class MicroProfileHealthDeprecatedTest {
public class HealthDeprecatedTest {

@ContainerResource
ManagementClient managementClient;

@Deployment(testable = false)
public static Archive<?> deployment() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "MicroProfileHealthDeprecatedTest.war")
WebArchive war = ShrinkWrap.create(WebArchive.class, HealthDeprecatedTest.class.getSimpleName() + ".war")
.addClasses(DeprecatedHealthCheck.class)
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
return war;
}

/**
* @tpTestDetails backward compatibility scenario - test for deprecated however still supported annotation.
* @tpPassCrit Overall and the health check status is up.
* @tpSince EAP 7.3.0.CD19
*/
@Test
public void testDeprecatedHealthCheck() {
final String healthURL = "http://" + managementClient.getMgmtAddress() + ":" + managementClient.getMgmtPort()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,26 @@

@RunAsClient
@RunWith(Arquillian.class)
public class MicroProfileHealthNullTest {
public class HealthNullTest {

@ContainerResource
ManagementClient managementClient;

@Deployment(testable = false)
public static Archive<?> deployment() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "MicroProfileHealthNullTest.war")
WebArchive war = ShrinkWrap.create(WebArchive.class, HealthTest.class.getSimpleName() + ".war")
.addClasses(NullLivenessHealthCheck.class)
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
return war;
}

/**
* @tpTestDetails Negative scenario - health check returns null.
* @tpPassCrit Overall and the health check status is down.
* @tpSince EAP 7.3.0.CD19
*/
@Test
public void testDeprecatedHealthCheck() {
public void testNullHealthCheck() {
final String healthURL = "http://" + managementClient.getMgmtAddress() + ":" + managementClient.getMgmtPort()
+ "/health";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

@RunAsClient
@RunWith(Arquillian.class)
public class MicroProfileHealth21Test {
public class HealthTest {

@ContainerResource
ManagementClient managementClient;
Expand All @@ -39,28 +39,37 @@ public void composeHealthEndpointURL() {

@Deployment(testable = false)
public static Archive<?> deployment() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "MicroProfileHealth21Test.war")
.addClasses(DeprecatedHealthCheck.class, BothHealthCheck.class, LivenessHealthCheck.class,
ReadinessHealthCheck.class)
WebArchive war = ShrinkWrap.create(WebArchive.class, HealthTest.class.getSimpleName() + ".war")
.addClasses(BothHealthCheck.class, LivenessHealthCheck.class, ReadinessHealthCheck.class)
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
return war;
}

/**
* @tpTestDetails Customer scenario where health check contains customer data.
* @tpPassCrit Overall and the health check status is up and checks contains expected data.
* @tpSince EAP 7.3.0.CD19
*/
@Test
public void testHealthEndpoint() {
get(healthURL).then()
.contentType(ContentType.JSON)
.header("Content-Type", containsString("application/json"))
.body("status", is("UP"),
"checks", hasSize(5), // BothHealthCheck contains both annotations: @Liveness and @Readiness
"checks", hasSize(4), // BothHealthCheck contains both annotations: @Liveness and @Readiness
"checks.status", hasItems("UP"),
"checks.status", not(hasItems("DOWN")),
"checks.name", containsInAnyOrder("deprecated-health", "both", "live", "ready", "both"),
"checks.data", hasSize(5),
"checks.name", containsInAnyOrder("both", "live", "ready", "both"),
"checks.data", hasSize(4),
"checks.data[0].key", is("value"),
"checks.data[0..4].key", hasItems("value"));
"checks.data[0..3].key", hasItems("value"));
}

/**
* @tpTestDetails Customer scenario where health check contains customer data.
* @tpPassCrit Overall and the health check status is up and checks contains expected data.
* @tpSince EAP 7.3.0.CD19
*/
@Test
public void testLivenessEndpoint() {
get(healthURL + "/live").then()
Expand All @@ -74,6 +83,11 @@ public void testLivenessEndpoint() {
"checks.data[0..1].key", hasItems("value"));
}

/**
* @tpTestDetails Customer scenario where health check contains customer data.
* @tpPassCrit Overall and the health check status is up and checks contains expected data.
* @tpSince EAP 7.3.0.CD19
*/
@Test
public void testReadinessEndpoint() {
get(healthURL + "/ready").then()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package org.jboss.eap.qe.microprofile.health;

import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ContainerResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import io.restassured.RestAssured;
import io.restassured.http.ContentType;

@RunAsClient
@RunWith(Arquillian.class)
public class MimeTypeHealthTest {

@ContainerResource
ManagementClient managementClient;

String healthURL;

@Before
public void composeHealthEndpointURL() {
healthURL = "http://" + managementClient.getMgmtAddress() + ":" + managementClient.getMgmtPort() + "/health";
}

@Deployment(testable = false)
public static Archive<?> deployment() {
WebArchive war = ShrinkWrap.create(WebArchive.class, MimeTypeHealthTest.class.getSimpleName() + ".war")
.addClasses(BothHealthCheck.class, LivenessHealthCheck.class, ReadinessHealthCheck.class)
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
return war;
}

/**
* @tpTestDetails Negative scenario where health check contains customer data. Request accepts invalid MIME type
* @tpPassCrit Overall and the health check status is up and checks contains expected data.
* @tpSince EAP 7.3.0.CD19
*/
@Test
public void testHealthXJSON() {
test("application/x-json");
}

/**
* @tpTestDetails Negative scenario where health check contains customer data. Request accepts invalid MIME type
* @tpPassCrit Overall and the health check status is up and checks contains expected data.
* @tpSince EAP 7.3.0.CD19
*/
@Test
public void testHealthJSONP() {
test("application/json-p");
}

/**
* @tpTestDetails Negative scenario where health check contains customer data. Request accepts invalid MIME type
* @tpPassCrit Overall and the health check status is up and checks contains expected data.
* @tpSince EAP 7.3.0.CD19
*/
@Test
public void testHealtTextPlain() {
test("text/plain");
}

/**
* @tpTestDetails Negative scenario where health check contains customer data. Request accepts invalid MIME type
* @tpPassCrit Overall and the health check status is up and checks contains expected data.
* @tpSince EAP 7.3.0.CD19
*/
@Test
public void testHealtTextCSV() {
test("text/csv");
}

/**
* @tpTestDetails Negative scenario where health check contains customer data. Request accepts invalid MIME type
* @tpPassCrit Overall and the health check status is up and checks contains expected data.
* @tpSince EAP 7.3.0.CD19
*/
@Test
public void testHealtModelVML() {
test("model/vml");
}

/**
* @tpTestDetails Negative scenario where health check contains customer data. Request accepts invalid MIME type
* @tpPassCrit Overall and the health check status is up and checks contains expected data.
* @tpSince EAP 7.3.0.CD19
*/
@Test
public void testHealtTextJSON() {
test("text/json");
}

private void test(String mimeType) {
testHealthEndpoint(mimeType);
testLiveEndpoint(mimeType);
testReadyEndpoint(mimeType);
}

private void testHealthEndpoint(String mimeType) {
RestAssured.given()
.baseUri(healthURL)
.accept(mimeType)
.get()
.then()
.contentType(ContentType.JSON)
.header("Content-Type", containsString("application/json"))
.body("status", is("UP"),
"checks", hasSize(4), // BothHealthCheck contains both annotations: @Liveness and @Readiness
"checks.status", hasItems("UP"),
"checks.status", not(hasItems("DOWN")),
"checks.name", containsInAnyOrder("both", "live", "ready", "both"),
"checks.data", hasSize(4),
"checks.data[0].key", is("value"),
"checks.data[0..3].key", hasItems("value"));
}

private void testLiveEndpoint(String mimeType) {
RestAssured.given()
.baseUri(healthURL + "/live")
.accept(mimeType)
.get()
.then()
.contentType(ContentType.JSON)
.header("Content-Type", containsString("application/json"))
.body("status", is("UP"),
"checks", hasSize(2),
"checks.status", hasItems("UP"),
"checks.name", containsInAnyOrder("both", "live"),
"checks.data", hasSize(2),
"checks.data[0..1].key", hasItems("value"));
}

private void testReadyEndpoint(String mimeType) {
RestAssured.given()
.baseUri(healthURL + "/ready")
.accept(mimeType)
.get()
.then()
.contentType(ContentType.JSON)
.header("Content-Type", containsString("application/json"))
.body("status", is("UP"),
"checks", hasSize(2),
"checks.status", hasItems("UP"),
"checks.name", containsInAnyOrder("both", "ready"),
"checks.data", hasSize(2),
"checks.data[0..1].key", hasItems("value"));
}
}
Loading

0 comments on commit 2d8d489

Please sign in to comment.