You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/08/07 13:49:16 UTC

[camel] 01/02: CAMEL-19647: added a test case for verifying the HTTP status code for HealthCheck down

This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 96d32f83be8c92f00b1684c6e00d046de48af36d
Author: Nikita Konovalov <nk...@redhat.com>
AuthorDate: Thu Aug 3 14:35:27 2023 +0200

    CAMEL-19647: added a test case for verifying the HTTP status code for HealthCheck down
---
 components/camel-platform-http-main/pom.xml        |  5 ++
 .../http/main/MainHttpFakeHealthCheck.java         | 39 ++++++++++++++
 .../platform/http/main/MainHttpServerTest.java     | 62 ++++++++++++++++++++++
 3 files changed, 106 insertions(+)

diff --git a/components/camel-platform-http-main/pom.xml b/components/camel-platform-http-main/pom.xml
index 14394201c35..1bf0173eb4c 100644
--- a/components/camel-platform-http-main/pom.xml
+++ b/components/camel-platform-http-main/pom.xml
@@ -89,6 +89,11 @@
             <version>${rest-assured-version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-health</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
 </project>
diff --git a/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/MainHttpFakeHealthCheck.java b/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/MainHttpFakeHealthCheck.java
new file mode 100644
index 00000000000..79d36207bdb
--- /dev/null
+++ b/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/MainHttpFakeHealthCheck.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.camel.component.platform.http.main;
+
+import java.util.Map;
+
+import org.apache.camel.health.HealthCheckResultBuilder;
+import org.apache.camel.impl.health.AbstractHealthCheck;
+
+public class MainHttpFakeHealthCheck extends AbstractHealthCheck {
+    protected MainHttpFakeHealthCheck() {
+        super("camel", "consumer:fake");
+    }
+
+    protected void doCall(HealthCheckResultBuilder builder, Map<String, Object> options) {
+        builder.detail("something", "fake");
+        builder.down();
+    }
+
+    @Override
+    public boolean isReadiness() {
+        return true;
+    }
+}
\ No newline at end of file
diff --git a/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/MainHttpServerTest.java b/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/MainHttpServerTest.java
new file mode 100644
index 00000000000..251627cd9c6
--- /dev/null
+++ b/components/camel-platform-http-main/src/test/java/org/apache/camel/component/platform/http/main/MainHttpServerTest.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+package org.apache.camel.component.platform.http.main;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class MainHttpServerTest {
+
+    private CamelContext camelContext;
+
+    @Test
+    public void statusIsNotSatisfied() throws IOException, InterruptedException {
+        MainHttpServer server = new MainHttpServer();
+
+        camelContext = new DefaultCamelContext();
+        server.setCamelContext(camelContext);
+
+        camelContext.getRegistry().bind("fake", new MainHttpFakeHealthCheck());
+
+        server.setHost("0.0.0.0");
+        server.setPort(8080);
+        server.setPath("/");
+
+        server.setHealthCheckEnabled(true);
+        server.start();
+
+        HttpRequest request = HttpRequest.newBuilder()
+                .uri(URI.create("http://localhost:8080/q/health/ready"))
+                .build();
+
+        HttpResponse<String> response = HttpClient.newBuilder().build().send(request, HttpResponse.BodyHandlers.ofString());
+
+        assertEquals(500, response.statusCode());
+
+    }
+
+}
\ No newline at end of file