Skip to content

Commit

Permalink
quarkus: add integration tests for knative
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Sep 22, 2020
1 parent dcf99c9 commit 556d720
Show file tree
Hide file tree
Showing 18 changed files with 440 additions and 28 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,7 +37,7 @@

@Path("/test")
@ApplicationScoped
public class Application {
public class KnativeComponentApplication {
@Inject
CamelContext context;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.knative;

import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
public class KnativeComponentIT extends KnativeComponentTest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -33,11 +32,12 @@

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)
Expand All @@ -56,24 +56,22 @@ public void inspect() throws IOException {

@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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#
# Quarkus
#
quarkus.log.console.enable = true
quarkus.log.console.enable = false
quarkus.banner.enabled = false

#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#
# Quarkus
#
quarkus.log.console.enable = true
quarkus.log.console.enable = false
quarkus.banner.enabled = false

#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
#
# Quarkus
#
quarkus.log.console.enable = true
quarkus.log.console.enable = false
quarkus.banner.enabled = false

Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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.arc.Unremovable;
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);
}

@Unremovable
@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()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## ---------------------------------------------------------------------------
## 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.
## ---------------------------------------------------------------------------

#
# Quarkus
#
quarkus.log.console.enable = false
quarkus.banner.enabled = false

Loading

0 comments on commit 556d720

Please sign in to comment.