You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2022/01/25 09:56:59 UTC
[camel-quarkus-examples] 01/02: Make health tests handle newer MP health output format in Camel 3.15.x
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch camel-quarkus-main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus-examples.git
commit eb571ef809ff8c469df63424bcec5479d2d7c71e
Author: James Netherton <ja...@gmail.com>
AuthorDate: Tue Jan 25 08:08:13 2022 +0000
Make health tests handle newer MP health output format in Camel 3.15.x
---
.../src/test/java/org/acme/health/HealthTest.java | 41 +++++++++---
.../org/acme/observability/ObservabilityTest.java | 72 ++++++++++++++++------
2 files changed, 86 insertions(+), 27 deletions(-)
diff --git a/health/src/test/java/org/acme/health/HealthTest.java b/health/src/test/java/org/acme/health/HealthTest.java
index ebda3db..7984a70 100644
--- a/health/src/test/java/org/acme/health/HealthTest.java
+++ b/health/src/test/java/org/acme/health/HealthTest.java
@@ -18,6 +18,8 @@ package org.acme.health;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
+import org.apache.camel.CamelContext;
+import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
@@ -28,13 +30,36 @@ public class HealthTest {
@Test
public void testHealth() throws InterruptedException {
- RestAssured.get("/q/health")
- .then()
- .statusCode(503)
- .body("status", is("DOWN"),
- "checks.status", containsInAnyOrder("DOWN", "UP"),
- "checks.name",
- containsInAnyOrder("camel-readiness-checks", "camel-liveness-checks"),
- "checks.data.context", containsInAnyOrder(null, "UP"));
+ if (isAggregatedHealthResponse()) {
+ RestAssured.get("/q/health")
+ .then()
+ .statusCode(503)
+ .body("status", is("DOWN"),
+ "checks.status", containsInAnyOrder("DOWN", "UP"),
+ "checks.name",
+ containsInAnyOrder("camel-readiness-checks", "camel-liveness-checks"),
+ "checks.data.context", containsInAnyOrder(null, "UP"));
+ } else {
+ RestAssured.get("/q/health")
+ .then()
+ .statusCode(503)
+ .body("status", is("DOWN"),
+ "checks.findAll { it.name == 'toolong' }.status", Matchers.contains("UP"),
+ "checks.findAll { it.name == 'context' }.status", Matchers.contains("UP"),
+ "checks.findAll { it.name == 'camel-routes' }.status", Matchers.contains("UP"),
+ "checks.findAll { it.name == 'camel-consumers' }.status", Matchers.contains("DOWN"));
+ }
+ }
+
+ /**
+ * The JSON structure produced by camel-microprofile-health in Camel >= 3.15 is different to that
+ * produced in previous versions. This check allows the tests to handle both formats.
+ *
+ * TODO: Remove when examples upgraded to >= Camel 3.15
+ */
+ private boolean isAggregatedHealthResponse() {
+ String version = CamelContext.class.getPackage().getImplementationVersion();
+ String[] versionParts = version.split("\\.");
+ return Integer.parseInt(versionParts[1]) < 15;
}
}
diff --git a/observability/src/test/java/org/acme/observability/ObservabilityTest.java b/observability/src/test/java/org/acme/observability/ObservabilityTest.java
index b120c1a..b0f65fe 100644
--- a/observability/src/test/java/org/acme/observability/ObservabilityTest.java
+++ b/observability/src/test/java/org/acme/observability/ObservabilityTest.java
@@ -17,7 +17,9 @@
package org.acme.observability;
import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
import io.restassured.http.ContentType;
+import org.apache.camel.CamelContext;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
@@ -43,25 +45,57 @@ public class ObservabilityTest {
@Test
public void health() {
- // Verify liveness
- given()
- .when().accept(ContentType.JSON)
- .get("/q/health/live")
- .then()
- .statusCode(200)
- .body("status", Matchers.is("UP"),
- "checks.name", containsInAnyOrder("camel-liveness-checks"),
- "checks.data.custom-liveness-check", containsInAnyOrder("UP"));
+ if (isAggregatedHealthResponse()) {
+ // Verify liveness
+ given()
+ .when().accept(ContentType.JSON)
+ .get("/q/health/live")
+ .then()
+ .statusCode(200)
+ .body("status", Matchers.is("UP"),
+ "checks.name", containsInAnyOrder("camel-liveness-checks"),
+ "checks.data.custom-liveness-check", containsInAnyOrder("UP"));
- // Verify readiness
- given()
- .when().accept(ContentType.JSON)
- .get("/q/health/ready")
- .then()
- .statusCode(200)
- .body("status", Matchers.is("UP"),
- "checks.name",
- hasItems("camel-readiness-checks", "Uptime readiness check"),
- "checks.data.custom-readiness-check", containsInAnyOrder("UP"));
+ // Verify readiness
+ given()
+ .when().accept(ContentType.JSON)
+ .get("/q/health/ready")
+ .then()
+ .statusCode(200)
+ .body("status", Matchers.is("UP"),
+ "checks.name",
+ hasItems("camel-readiness-checks", "Uptime readiness check"),
+ "checks.data.custom-readiness-check", containsInAnyOrder("UP"));
+ } else {
+ // Verify liveness
+ RestAssured.get("/q/health/live")
+ .then()
+ .statusCode(200)
+ .body("status", is("UP"),
+ "checks.findAll { it.name == 'custom-liveness-check' }.status", Matchers.contains("UP"));
+
+ // Verify readiness
+ RestAssured.get("/q/health/ready")
+ .then()
+ .statusCode(200)
+ .body("status", is("UP"),
+ "checks.findAll { it.name == 'custom-readiness-check' }.status", Matchers.contains("UP"),
+ "checks.findAll { it.name == 'Uptime readiness check' }.status", Matchers.contains("UP"),
+ "checks.findAll { it.name == 'context' }.status", Matchers.contains("UP"),
+ "checks.findAll { it.name == 'camel-routes' }.status", Matchers.contains("UP"),
+ "checks.findAll { it.name == 'camel-consumers' }.status", Matchers.contains("UP"));
+ }
+ }
+
+ /**
+ * The JSON structure produced by camel-microprofile-health in Camel >= 3.15 is different to that
+ * produced in previous versions. This check allows the tests to handle both formats.
+ *
+ * TODO: Remove when examples upgraded to >= Camel 3.15
+ */
+ private boolean isAggregatedHealthResponse() {
+ String version = CamelContext.class.getPackage().getImplementationVersion();
+ String[] versionParts = version.split("\\.");
+ return Integer.parseInt(versionParts[1]) < 15;
}
}