You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2020/09/22 17:08:36 UTC
[camel-k-runtime] branch master updated: quarkus: add integration
tests for knative
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git
The following commit(s) were added to refs/heads/master by this push:
new 3db829e quarkus: add integration tests for knative
3db829e is described below
commit 3db829e04b1957b365eef9ba16c8cb4398b0c1a8
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Tue Sep 22 17:53:39 2020 +0200
quarkus: add integration tests for knative
---
.github/workflows/ci-build.yml | 1 +
...ation.java => KnativeComponentApplication.java} | 4 +-
.../KnativeIT.java => KnativeComponentIT.java} | 4 +-
.../KnativeTest.java => KnativeComponentTest.java} | 24 ++-
.../src/main/resources/application.properties | 2 +-
.../src/main/resources/application.properties | 2 +-
.../src/main/resources/application.properties | 2 +-
.../camel-k-quarkus-itests-runtime-knative/pom.xml | 175 +++++++++++++++++++++
.../camel/k/quarkus/it/KnativeApplication.java | 61 +++++++
.../src/main/resources/application.properties | 2 +-
.../org/apache/camel/k/quarkus/it}/KnativeIT.java | 2 +-
.../apache/camel/k/quarkus/it/KnativeTest.java} | 26 ++-
.../src/test/resources/env.json | 20 +++
.../src/test/resources/routes.properties} | 7 -
.../src/test/resources/routes.yaml | 28 ++++
camel-k-quarkus/camel-k-quarkus-itests/pom.xml | 1 +
.../knative/deployment/DeploymentProcessor.java | 8 +
.../component/knative/spi/KnativeEnvironment.java | 8 +-
.../knative/http/KnativeHttpProducer.java | 32 +++-
19 files changed, 367 insertions(+), 42 deletions(-)
diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml
index 7a0dc49..fef69cd 100644
--- a/.github/workflows/ci-build.yml
+++ b/.github/workflows/ci-build.yml
@@ -112,6 +112,7 @@ jobs:
- :camel-k-quarkus-itests-core
- :camel-k-quarkus-itests-runtime
- :camel-k-quarkus-itests-runtime-kamelet
+ - :camel-k-quarkus-itests-runtime-knative
- :camel-k-quarkus-itests-cron
- :camel-k-quarkus-itests-master
- :camel-k-quarkus-itests-kamelet
diff --git a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/main/java/org/apache/camel/k/quarkus/knative/deployment/Application.java b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/main/java/org/apache/camel/k/quarkus/knative/KnativeComponentApplication.java
similarity index 96%
rename from camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/main/java/org/apache/camel/k/quarkus/knative/deployment/Application.java
rename to camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/main/java/org/apache/camel/k/quarkus/knative/KnativeComponentApplication.java
index 279dcb1..8c8245f 100644
--- a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/main/java/org/apache/camel/k/quarkus/knative/deployment/Application.java
+++ b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/main/java/org/apache/camel/k/quarkus/knative/KnativeComponentApplication.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.k.quarkus.knative.deployment;
+package org.apache.camel.k.quarkus.knative;
import java.util.Locale;
import java.util.Map;
@@ -37,7 +37,7 @@ import org.apache.camel.component.knative.spi.Knative;
@Path("/test")
@ApplicationScoped
-public class Application {
+public class KnativeComponentApplication {
@Inject
CamelContext context;
diff --git a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/test/java/org/apache/camel/k/quarkus/knative/deployment/KnativeIT.java b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/test/java/org/apache/camel/k/quarkus/knative/KnativeComponentIT.java
similarity index 88%
copy from camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/test/java/org/apache/camel/k/quarkus/knative/deployment/KnativeIT.java
copy to camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/test/java/org/apache/camel/k/quarkus/knative/KnativeComponentIT.java
index e48c4f1..23a6d20 100644
--- a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/test/java/org/apache/camel/k/quarkus/knative/deployment/KnativeIT.java
+++ b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/test/java/org/apache/camel/k/quarkus/knative/KnativeComponentIT.java
@@ -14,10 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.k.quarkus.knative.deployment;
+package org.apache.camel.k.quarkus.knative;
import io.quarkus.test.junit.NativeImageTest;
@NativeImageTest
-public class KnativeIT extends KnativeTest {
+public class KnativeComponentIT extends KnativeComponentTest {
}
\ No newline at end of file
diff --git a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/test/java/org/apache/camel/k/quarkus/knative/deployment/KnativeTest.java b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/test/java/org/apache/camel/k/quarkus/knative/KnativeComponentTest.java
similarity index 72%
rename from camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/test/java/org/apache/camel/k/quarkus/knative/deployment/KnativeTest.java
rename to camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/test/java/org/apache/camel/k/quarkus/knative/KnativeComponentTest.java
index 8c6c2f5..5d05eb4 100644
--- a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/test/java/org/apache/camel/k/quarkus/knative/deployment/KnativeTest.java
+++ b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/test/java/org/apache/camel/k/quarkus/knative/KnativeComponentTest.java
@@ -14,9 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.k.quarkus.knative.deployment;
+package org.apache.camel.k.quarkus.knative;
-import java.io.IOException;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
@@ -33,11 +32,12 @@ import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.Matchers.is;
@QuarkusTest
-public class KnativeTest {
+public class KnativeComponentTest {
@Test
- public void inspect() throws IOException {
+ public void inspect() {
JsonPath p = RestAssured.given()
.contentType(MediaType.TEXT_PLAIN)
.accept(MediaType.APPLICATION_JSON)
@@ -56,24 +56,22 @@ public class KnativeTest {
@Test
public void invoke() {
- final CloudEvents ce = CloudEvents.v1_0;
final String payload = "test";
- String result = given()
+ given()
.body(payload)
.header(Exchange.CONTENT_TYPE, "text/plain")
- .header(ce.mandatoryAttribute(CloudEvent.CAMEL_CLOUD_EVENT_VERSION).http(), ce.v1_0.version())
- .header(ce.mandatoryAttribute(CloudEvent.CAMEL_CLOUD_EVENT_TYPE).http(), "org.apache.camel.event")
- .header(ce.mandatoryAttribute(CloudEvent.CAMEL_CLOUD_EVENT_ID).http(), "myEventID")
- .header(ce.mandatoryAttribute(CloudEvent.CAMEL_CLOUD_EVENT_TIME).http(), DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now()))
- .header(ce.mandatoryAttribute(CloudEvent.CAMEL_CLOUD_EVENT_SOURCE).http(), "/somewhere")
+ .header(CloudEvents.v1_0.mandatoryAttribute(CloudEvent.CAMEL_CLOUD_EVENT_VERSION).http(), CloudEvents.v1_0.version())
+ .header(CloudEvents.v1_0.mandatoryAttribute(CloudEvent.CAMEL_CLOUD_EVENT_TYPE).http(), "org.apache.camel.event")
+ .header(CloudEvents.v1_0.mandatoryAttribute(CloudEvent.CAMEL_CLOUD_EVENT_ID).http(), "myEventID")
+ .header(CloudEvents.v1_0.mandatoryAttribute(CloudEvent.CAMEL_CLOUD_EVENT_TIME).http(), DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now()))
+ .header(CloudEvents.v1_0.mandatoryAttribute(CloudEvent.CAMEL_CLOUD_EVENT_SOURCE).http(), "/somewhere")
.when()
.post("/knative")
.then()
.statusCode(200)
+ .body(is(payload.toUpperCase()))
.extract()
.asString();
-
- assertThat(result).isEqualTo(payload.toUpperCase());
}
}
diff --git a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-loader-kotlin/src/main/resources/application.properties b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-loader-kotlin/src/main/resources/application.properties
index 67b30b1..3da273e 100644
--- a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-loader-kotlin/src/main/resources/application.properties
+++ b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-loader-kotlin/src/main/resources/application.properties
@@ -18,7 +18,7 @@
#
# Quarkus
#
-quarkus.log.console.enable = true
+quarkus.log.console.enable = false
quarkus.banner.enabled = false
#
diff --git a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-loader-yaml/src/main/resources/application.properties b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-loader-yaml/src/main/resources/application.properties
index ece4686..3f6864a 100644
--- a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-loader-yaml/src/main/resources/application.properties
+++ b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-loader-yaml/src/main/resources/application.properties
@@ -18,7 +18,7 @@
#
# Quarkus
#
-quarkus.log.console.enable = true
+quarkus.log.console.enable = false
quarkus.banner.enabled = false
#
diff --git a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-kamelet/src/main/resources/application.properties b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-kamelet/src/main/resources/application.properties
index 5b8f41a..3ce5493 100644
--- a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-kamelet/src/main/resources/application.properties
+++ b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-kamelet/src/main/resources/application.properties
@@ -18,6 +18,6 @@
#
# Quarkus
#
-quarkus.log.console.enable = true
+quarkus.log.console.enable = false
quarkus.banner.enabled = false
diff --git a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/pom.xml b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/pom.xml
new file mode 100644
index 0000000..d722f01
--- /dev/null
+++ b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/pom.xml
@@ -0,0 +1,175 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<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/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.apache.camel.k</groupId>
+ <artifactId>camel-k-quarkus-itests</artifactId>
+ <version>1.5.1-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>camel-k-quarkus-itests-runtime-knative</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel.k</groupId>
+ <artifactId>camel-k-runtime-quarkus</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.k</groupId>
+ <artifactId>camel-k-quarkus-knative</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.k</groupId>
+ <artifactId>camel-k-quarkus-loader-yaml</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-direct</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-jsonb</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-resteasy</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-resteasy-jsonb</artifactId>
+ </dependency>
+
+ <!-- test dependencies -->
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-junit5</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.rest-assured</groupId>
+ <artifactId>rest-assured</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>${build-helper-maven-plugin-version}</version>
+ <executions>
+ <execution>
+ <id>reserve-network-port</id>
+ <goals>
+ <goal>reserve-network-port</goal>
+ </goals>
+ <phase>process-resources</phase>
+ <configuration>
+ <portNames>
+ <portName>test.http.port.jvm</portName>
+ <portName>test.http.port.native</portName>
+ </portNames>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-maven-plugin</artifactId>
+ <version>${quarkus-version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>build</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <environmentVariables>
+ <CAMEL_K_ROUTES>file:${project.basedir}/src/test/resources/routes.yaml</CAMEL_K_ROUTES>
+ <CAMEL_K_CONF>${project.basedir}/src/test/resources/routes.properties</CAMEL_K_CONF>
+ <__CAMEL_KNATIVE_CONFIGURATION>file:${project.basedir}/src/test/resources/env.json</__CAMEL_KNATIVE_CONFIGURATION>
+ <CAMEL_KNATIVE_LISTENING_PORT>${test.http.port.jvm}</CAMEL_KNATIVE_LISTENING_PORT>
+ </environmentVariables>
+ <systemProperties>
+ <quarkus.http.test-port>${test.http.port.jvm}</quarkus.http.test-port>
+ <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>native</id>
+ <activation>
+ <property>
+ <name>native</name>
+ </property>
+ </activation>
+ <properties>
+ <quarkus.package.type>native</quarkus.package.type>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ <configuration>
+ <environmentVariables>
+ <CAMEL_K_ROUTES>file:${project.basedir}/src/test/resources/routes.yaml</CAMEL_K_ROUTES>
+ <CAMEL_K_CONF>${project.basedir}/src/test/resources/routes.properties</CAMEL_K_CONF>
+ <__CAMEL_KNATIVE_CONFIGURATION>file:${project.basedir}/src/test/resources/env.json</__CAMEL_KNATIVE_CONFIGURATION>
+ <CAMEL_KNATIVE_LISTENING_PORT>${test.http.port.native}</CAMEL_KNATIVE_LISTENING_PORT>
+ </environmentVariables>
+ <systemProperties>
+ <quarkus.http.test-port>${test.http.port.native}</quarkus.http.test-port>
+ <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
+ </systemProperties>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+</project>
diff --git a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/src/main/java/org/apache/camel/k/quarkus/it/KnativeApplication.java b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/src/main/java/org/apache/camel/k/quarkus/it/KnativeApplication.java
new file mode 100644
index 0000000..e0375fd
--- /dev/null
+++ b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/src/main/java/org/apache/camel/k/quarkus/it/KnativeApplication.java
@@ -0,0 +1,61 @@
+/*
+ * 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.k.quarkus.it;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import io.quarkus.runtime.annotations.RegisterForReflection;
+import org.apache.camel.FluentProducerTemplate;
+import org.apache.camel.component.knative.spi.Knative;
+import org.apache.camel.component.knative.spi.KnativeEnvironment;
+import org.eclipse.microprofile.config.inject.ConfigProperty;
+
+@RegisterForReflection(targets = { String.class })
+@Path("/test")
+@ApplicationScoped
+public class KnativeApplication {
+ @Inject
+ FluentProducerTemplate template;
+
+ @POST
+ @Path("/execute")
+ @Produces(MediaType.TEXT_PLAIN)
+ public String execute(String payload) {
+ return template.to("direct:process").withBody(payload).request(String.class);
+ }
+
+ @javax.enterprise.inject.Produces
+ KnativeEnvironment environment(
+ @ConfigProperty(name = "camel.knative.listening.port") int port) {
+
+ return KnativeEnvironment.on(
+ KnativeEnvironment.serviceBuilder(Knative.Type.endpoint, "process")
+ .withMeta(Knative.CAMEL_ENDPOINT_KIND, Knative.EndpointKind.source)
+ .withMeta(Knative.SERVICE_META_PATH, "/knative")
+ .build(),
+ KnativeEnvironment.serviceBuilder(Knative.Type.endpoint, "process")
+ .withMeta(Knative.CAMEL_ENDPOINT_KIND, Knative.EndpointKind.sink)
+ .withMeta(Knative.SERVICE_META_URL, String.format("http://localhost:%d/knative", port))
+ .build()
+ );
+ }
+}
diff --git a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-kamelet/src/main/resources/application.properties b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/src/main/resources/application.properties
similarity index 96%
copy from camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-kamelet/src/main/resources/application.properties
copy to camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/src/main/resources/application.properties
index 5b8f41a..3ce5493 100644
--- a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-kamelet/src/main/resources/application.properties
+++ b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/src/main/resources/application.properties
@@ -18,6 +18,6 @@
#
# Quarkus
#
-quarkus.log.console.enable = true
+quarkus.log.console.enable = false
quarkus.banner.enabled = false
diff --git a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/test/java/org/apache/camel/k/quarkus/knative/deployment/KnativeIT.java b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/src/test/java/org/apache/camel/k/quarkus/it/KnativeIT.java
similarity index 94%
copy from camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/test/java/org/apache/camel/k/quarkus/knative/deployment/KnativeIT.java
copy to camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/src/test/java/org/apache/camel/k/quarkus/it/KnativeIT.java
index e48c4f1..cfd8081 100644
--- a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/test/java/org/apache/camel/k/quarkus/knative/deployment/KnativeIT.java
+++ b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/src/test/java/org/apache/camel/k/quarkus/it/KnativeIT.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.k.quarkus.knative.deployment;
+package org.apache.camel.k.quarkus.it;
import io.quarkus.test.junit.NativeImageTest;
diff --git a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/test/java/org/apache/camel/k/quarkus/knative/deployment/KnativeIT.java b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/src/test/java/org/apache/camel/k/quarkus/it/KnativeTest.java
similarity index 57%
rename from camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/test/java/org/apache/camel/k/quarkus/knative/deployment/KnativeIT.java
rename to camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/src/test/java/org/apache/camel/k/quarkus/it/KnativeTest.java
index e48c4f1..7e093ca 100644
--- a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-knative/src/test/java/org/apache/camel/k/quarkus/knative/deployment/KnativeIT.java
+++ b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/src/test/java/org/apache/camel/k/quarkus/it/KnativeTest.java
@@ -14,10 +14,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.k.quarkus.knative.deployment;
+package org.apache.camel.k.quarkus.it;
-import io.quarkus.test.junit.NativeImageTest;
+import javax.ws.rs.core.MediaType;
-@NativeImageTest
-public class KnativeIT extends KnativeTest {
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.Matchers.is;
+
+@QuarkusTest
+public class KnativeTest {
+ @Test
+ public void invoke() {
+ final String payload = "hello";
+
+ RestAssured.given()
+ .accept(MediaType.TEXT_PLAIN)
+ .body(payload)
+ .post("/test/execute")
+ .then()
+ .statusCode(200)
+ .body(is(payload.toUpperCase()));
+ }
}
\ No newline at end of file
diff --git a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/src/test/resources/env.json b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/src/test/resources/env.json
new file mode 100644
index 0000000..4c3e66c
--- /dev/null
+++ b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/src/test/resources/env.json
@@ -0,0 +1,20 @@
+{
+ "services": [
+ {
+ "type": "endpoint",
+ "name": "process",
+ "metadata": {
+ "camel.endpoint.kind": "source",
+ "service.path": "/knative"
+ }
+ },
+ {
+ "type": "endpoint",
+ "name": "process",
+ "metadata": {
+ "service.url": "http://localhost:{{env:HTTP_TEST_PORT}}/knative",
+ "camel.endpoint.kind": "sink"
+ }
+ }
+ ]
+}
\ No newline at end of file
diff --git a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-kamelet/src/main/resources/application.properties b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/src/test/resources/routes.properties
similarity index 91%
copy from camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-kamelet/src/main/resources/application.properties
copy to camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/src/test/resources/routes.properties
index 5b8f41a..fa7a54b 100644
--- a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-kamelet/src/main/resources/application.properties
+++ b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/src/test/resources/routes.properties
@@ -14,10 +14,3 @@
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
-
-#
-# Quarkus
-#
-quarkus.log.console.enable = true
-quarkus.banner.enabled = false
-
diff --git a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/src/test/resources/routes.yaml b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/src/test/resources/routes.yaml
new file mode 100644
index 0000000..b402418
--- /dev/null
+++ b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-runtime-knative/src/test/resources/routes.yaml
@@ -0,0 +1,28 @@
+#
+# 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.
+#
+
+- from:
+ uri: "direct:process"
+ steps:
+ - to: "knative:endpoint/process"
+- from:
+ uri: "knative:endpoint/process"
+ steps:
+ - convert-body-to:
+ type: "java.lang.String"
+ - set-body:
+ simple: "${in.body.toUpperCase()}"
\ No newline at end of file
diff --git a/camel-k-quarkus/camel-k-quarkus-itests/pom.xml b/camel-k-quarkus/camel-k-quarkus-itests/pom.xml
index e75e73e..302aed9 100644
--- a/camel-k-quarkus/camel-k-quarkus-itests/pom.xml
+++ b/camel-k-quarkus/camel-k-quarkus-itests/pom.xml
@@ -44,6 +44,7 @@
<module>camel-k-quarkus-itests-polyglot</module>
<module>camel-k-quarkus-itests-runtime</module>
<module>camel-k-quarkus-itests-runtime-kamelet</module>
+ <module>camel-k-quarkus-itests-runtime-knative</module>
</modules>
</project>
diff --git a/camel-k-quarkus/camel-k-quarkus-knative/deployment/src/main/java/org/apache/camel/k/quarkus/knative/deployment/DeploymentProcessor.java b/camel-k-quarkus/camel-k-quarkus-knative/deployment/src/main/java/org/apache/camel/k/quarkus/knative/deployment/DeploymentProcessor.java
index 6237a05..a17d85d 100644
--- a/camel-k-quarkus/camel-k-quarkus-knative/deployment/src/main/java/org/apache/camel/k/quarkus/knative/deployment/DeploymentProcessor.java
+++ b/camel-k-quarkus/camel-k-quarkus-knative/deployment/src/main/java/org/apache/camel/k/quarkus/knative/deployment/DeploymentProcessor.java
@@ -18,6 +18,7 @@ package org.apache.camel.k.quarkus.knative.deployment;
import java.util.List;
+import io.quarkus.arc.deployment.UnremovableBeanBuildItem;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
@@ -35,6 +36,13 @@ import org.apache.camel.quarkus.core.deployment.spi.CamelServiceFilterBuildItem;
public class DeploymentProcessor {
@BuildStep
+ List<UnremovableBeanBuildItem> unremovableBeans() {
+ return List.of(
+ UnremovableBeanBuildItem.beanTypes(KnativeEnvironment.class)
+ );
+ }
+
+ @BuildStep
List<ReflectiveClassBuildItem> reflectiveClasses() {
return List.of(
new ReflectiveClassBuildItem(true, false, KnativeEnvironment.class),
diff --git a/camel-knative/camel-knative-api/src/main/java/org/apache/camel/component/knative/spi/KnativeEnvironment.java b/camel-knative/camel-knative-api/src/main/java/org/apache/camel/component/knative/spi/KnativeEnvironment.java
index 1703fda..a84f604 100644
--- a/camel-knative/camel-knative-api/src/main/java/org/apache/camel/component/knative/spi/KnativeEnvironment.java
+++ b/camel-knative/camel-knative-api/src/main/java/org/apache/camel/component/knative/spi/KnativeEnvironment.java
@@ -202,8 +202,8 @@ public class KnativeEnvironment {
if (urlAsString != null) {
try {
return new URL(urlAsString).getHost();
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
+ } catch (MalformedURLException ignored) {
+ // ignored
}
}
@@ -216,8 +216,8 @@ public class KnativeEnvironment {
if (urlAsString != null) {
try {
return new URL(urlAsString).getPort();
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
+ } catch (MalformedURLException ignored) {
+ // ignored
}
}
diff --git a/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpProducer.java b/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpProducer.java
index f76d1c8..69a602a 100644
--- a/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpProducer.java
+++ b/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpProducer.java
@@ -16,6 +16,8 @@
*/
package org.apache.camel.component.knative.http;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.Map;
import java.util.function.Supplier;
@@ -87,11 +89,12 @@ public class KnativeHttpProducer extends DefaultAsyncProducer {
return true;
}
- Message message = exchange.getMessage();
+ final Message message = exchange.getMessage();
+ final String host = getHost(serviceDefinition);
MultiMap headers = MultiMap.caseInsensitiveMultiMap();
- headers.add(HttpHeaders.HOST, serviceDefinition.getHost());
headers.add(HttpHeaders.CONTENT_LENGTH, Integer.toString(payload.length));
+ headers.add(HttpHeaders.HOST, host);
String contentType = MessageHelper.getContentType(message);
if (contentType != null) {
@@ -104,7 +107,7 @@ public class KnativeHttpProducer extends DefaultAsyncProducer {
}
}
- if (ObjectHelper.isEmpty(serviceDefinition.getHost())) {
+ if (ObjectHelper.isEmpty(host)) {
exchange.setException(new CamelException("HTTP operation failed because host is not defined"));
callback.done(true);
@@ -177,7 +180,7 @@ public class KnativeHttpProducer extends DefaultAsyncProducer {
}
}
- private static String computeUrl(KnativeEnvironment.KnativeServiceDefinition definition) {
+ private String computeUrl(KnativeEnvironment.KnativeServiceDefinition definition) {
String url = definition.getUrl();
if (url == null) {
int port = definition.getPortOrDefault(KnativeHttpTransport.DEFAULT_PORT);
@@ -190,7 +193,26 @@ public class KnativeHttpProducer extends DefaultAsyncProducer {
url = String.format("http://%s:%d%s", definition.getHost(), port, path);
}
- return url;
+ return getEndpoint().getCamelContext().resolvePropertyPlaceholders(url);
+ }
+
+ private String getHost(KnativeEnvironment.KnativeServiceDefinition definition) {
+ if (definition.getHost() != null) {
+ return serviceDefinition.getHost();
+ }
+
+ if (serviceDefinition.getUrl() != null) {
+ String url = serviceDefinition.getUrl();
+ url = getEndpoint().getCamelContext().resolvePropertyPlaceholders(url);
+
+ try {
+ return new URL(url).getHost();
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ throw new IllegalStateException("Unable to determine the Host value");
}
}