Skip to content

Commit

Permalink
Switch to Quarkus as runtime #359 (refactor knative sources test)
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Nov 9, 2020
1 parent 00d401e commit 88560b7
Show file tree
Hide file tree
Showing 36 changed files with 1,734 additions and 281 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ jobs:
- :camel-k-itests-kamelet
- :camel-k-itests-knative
- :camel-k-itests-knative-sinkbinding
- :camel-k-itests-knative-source-js
- :camel-k-itests-knative-source-xml
- :camel-k-itests-knative-source-yaml
- :camel-k-itests-loader-xml
- :camel-k-itests-loader-yaml
- :camel-k-itests-loader-js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>camel-k-itests-knative-source</artifactId>
<artifactId>camel-k-itests-knative-source-groovy</artifactId>

<dependencies>
<dependency>
Expand All @@ -36,32 +36,10 @@
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-knative</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-loader-yaml</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-loader-groovy</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-loader-xml</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-loader-js</artifactId>
</dependency>
<!--
<dependency>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-loader-kotlin</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-loader-java</artifactId>
</dependency>
-->

<!-- camel quarkus -->
<dependency>
Expand All @@ -72,14 +50,6 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-log</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-platform-http</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-seda</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
Expand Down Expand Up @@ -138,19 +108,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-loader-yaml</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel.k</groupId>
<artifactId>camel-k-loader-groovy</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
package org.apache.camel.k.quarkus.it.knative.source;

import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import javax.enterprise.context.ApplicationScoped;
Expand Down Expand Up @@ -46,6 +50,16 @@ public class KnativeSourceApplication {
@Inject
CamelContext context;

private BlockingQueue<String> queue = new LinkedBlockingQueue<>();


@POST
@Path("/toUpper")
@Produces(MediaType.TEXT_PLAIN)
public void toUpper(String data) throws InterruptedException {
queue.offer(data.toUpperCase(Locale.US));
}

@GET
@Path("/inspect/endpoint-uris")
@Produces(MediaType.APPLICATION_JSON)
Expand All @@ -66,14 +80,13 @@ public JsonArray endpointUris() {
@POST
@Path("/send")
@Produces(MediaType.TEXT_PLAIN)
public String send(String data) {
public String send(String data) throws InterruptedException {
context.createFluentProducerTemplate()
.to("direct:start")
.withHeader("MyHeader", data)
.send();

return context.createConsumerTemplate()
.receiveBody("seda:answer", String.class);
return queue.poll(10, TimeUnit.SECONDS);
}

@Unremovable
Expand All @@ -83,7 +96,7 @@ KnativeEnvironment environment(

return KnativeEnvironment.on(
KnativeEnvironment.serviceBuilder(Knative.Type.endpoint, "sink")
.withUrl("http://localhost:" + port)
.withUrl("http://localhost:" + port + "/test/toUpper")
.withMeta(Knative.CAMEL_ENDPOINT_KIND, Knative.EndpointKind.sink)
.build()
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## ---------------------------------------------------------------------------
## 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

#
# Camel K
#
camel.k.sources[0].location = file:src/test/resources/source.groovy
camel.k.sources[0].interceptors[0] = knative-source

Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.k.quarkus.it.knative.source.support;
package org.apache.camel.k.quarkus.it.knative.source;

import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.ws.rs.core.MediaType;

import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;

import static io.restassured.RestAssured.given;
import static org.apache.camel.util.CollectionHelper.mapOf;
import static org.assertj.core.api.Assertions.assertThat;

public final class KnativeSourceTestSupport {
private KnativeSourceTestSupport() {
}

public static void validateEndpointUris() {
@QuarkusTestResource(KnativeSourceGroovyTest.Resource.class)
@QuarkusTest
public class KnativeSourceGroovyTest {
@Test
public void validateEndpointUris() {
List<String> p = given()
.accept(MediaType.APPLICATION_JSON)
.get("/test/inspect/endpoint-uris")
Expand All @@ -45,7 +47,8 @@ public static void validateEndpointUris() {
assertThat(p).contains("knative://endpoint/sink");
}

public static void validateBehavior() {
@Test
public void validateBehavior() {
final String body = "test";

String result = given()
Expand All @@ -61,22 +64,16 @@ public static void validateBehavior() {
assertThat(result).isEqualTo(body.toUpperCase(Locale.US));
}

public static class Profile implements QuarkusTestProfile {
private final String file;

public Profile(String file) {
this.file = file;
public static class Resource implements QuarkusTestResourceLifecycleManager {
@Override
public Map<String, String> start() {
return Map.of(
"kamel.k.sink.port",
System.getProperty("camel.k.test.knative.listenting.port"));
}

@Override
public Map<String, String> getConfigOverrides() {
String res = System.getProperty("camel.k.test.dir.resources", "./src/test/resources");

return mapOf(
"camel.k.sources[0].location", "file:" + res + "/listener.groovy",
"camel.k.sources[1].location", "file:" + res + "/sources/" + file,
"camel.k.sources[1].interceptors[0]", "knative-source"
);
public void stop() {
}
}
}
Loading

0 comments on commit 88560b7

Please sign in to comment.