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

commit a25ab0f709c6bf1e6ea680f8a55fea645a99c44a
Author: lburgazzoli <lburgazz...@gmail.com>
AuthorDate: Fri May 29 20:14:31 2020 +0200

    Add polyglot tests for quarkus extensions
---
 .github/workflows/pr-build.yml                     |   1 +
 .../camel-k-quarkus-itests-polyglot/pom.xml        | 170 +++++++++++++++++++++
 .../k/itests/polyglot/quarkus/Application.java     |  84 ++++++++++
 .../src/main/resources/application.properties      |  36 +++++
 .../k/itests/polyglot/quarkus/ExtensionIT.java     |  23 +++
 .../k/itests/polyglot/quarkus/ExtensionTest.java   |  59 +++++++
 .../src/test/resources/routes.xml                  |  34 +++++
 .../src/test/resources/routes.yaml                 |  25 +++
 camel-k-quarkus/camel-k-quarkus-itests/pom.xml     |   1 +
 9 files changed, 433 insertions(+)

diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml
index 3ed6e0c..12982e5 100644
--- a/.github/workflows/pr-build.yml
+++ b/.github/workflows/pr-build.yml
@@ -66,6 +66,7 @@ jobs:
           - :camel-k-quarkus-itests-knative
           - :camel-k-quarkus-itests-loader-xml
           - :camel-k-quarkus-itests-loader-yaml
+          - :camel-k-quarkus-itests-polyglot
           - :camel-k-runtime-example-quarkus-xml
           - :camel-k-runtime-example-quarkus-yaml
           - :camel-k-runtime-example-quarkus-knative
diff --git 
a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-polyglot/pom.xml
 
b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-polyglot/pom.xml
new file mode 100644
index 0000000..95299f0
--- /dev/null
+++ 
b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-polyglot/pom.xml
@@ -0,0 +1,170 @@
+<?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.3.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>camel-k-quarkus-itests-polyglot</artifactId>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel.k</groupId>
+            <artifactId>camel-k-quarkus-loader-yaml</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.k</groupId>
+            <artifactId>camel-k-quarkus-loader-xml</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-direct</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-log</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-jackson</artifactId>
+        </dependency>
+
+        <!-- quarkus dependencies -->
+        <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>
+                    <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>
+                
<quarkus.native.additional-build-args>--language:js</quarkus.native.additional-build-args>
+            </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>
+                                    <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-polyglot/src/main/java/org/apache/camel/k/itests/polyglot/quarkus/Application.java
 
b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-polyglot/src/main/java/org/apache/camel/k/itests/polyglot/quarkus/Application.java
new file mode 100644
index 0000000..a85dcc5
--- /dev/null
+++ 
b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-polyglot/src/main/java/org/apache/camel/k/itests/polyglot/quarkus/Application.java
@@ -0,0 +1,84 @@
+/*
+ * 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.itests.polyglot.quarkus;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.json.Json;
+import javax.json.JsonArrayBuilder;
+import javax.json.JsonObject;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Consume;
+import org.apache.camel.k.Runtime;
+import org.apache.camel.k.Source;
+import org.apache.camel.k.SourceLoader;
+import org.apache.camel.k.Sources;
+
+@Path("/test")
+@ApplicationScoped
+public class Application {
+    @Inject
+    CamelContext context;
+
+    @POST
+    @Path("/load-routes/{loaderName}/{name}")
+    @Consume(MediaType.APPLICATION_OCTET_STREAM)
+    @Produces(MediaType.APPLICATION_JSON)
+    public JsonObject loadRoutes(@PathParam("loaderName") String loaderName, 
@PathParam("name") String name, byte[] code) throws Exception {
+        final SourceLoader loader = 
context.getRegistry().lookupByNameAndType(loaderName, SourceLoader.class);
+        final Runtime runtime = Runtime.on(context);
+        final Source source = Sources.fromBytes(name, loaderName, null, code);
+        final SourceLoader.Result result = loader.load(Runtime.on(context), 
source);
+
+        result.builder().ifPresent(runtime::addRoutes);
+        result.configuration().ifPresent(runtime::addConfiguration);
+
+        return Json.createObjectBuilder()
+            .add("components", extractComponents())
+            .add("routes", extractRoutes())
+            .add("endpoints", extractEndpoints())
+            .build();
+    }
+
+
+    private JsonArrayBuilder extractComponents() {
+        JsonArrayBuilder answer = Json.createArrayBuilder();
+        context.getComponentNames().forEach(answer::add);
+
+        return answer;
+    }
+
+    private JsonArrayBuilder extractRoutes() {
+        JsonArrayBuilder answer = Json.createArrayBuilder();
+        context.getRoutes().forEach(r -> answer.add(r.getId()));
+
+        return answer;
+    }
+
+    private JsonArrayBuilder extractEndpoints() {
+        JsonArrayBuilder answer = Json.createArrayBuilder();
+        context.getEndpoints().forEach(e -> answer.add(e.getEndpointUri()));
+
+        return answer;
+    }
+}
diff --git 
a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-polyglot/src/main/resources/application.properties
 
b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-polyglot/src/main/resources/application.properties
new file mode 100644
index 0000000..2958915
--- /dev/null
+++ 
b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-polyglot/src/main/resources/application.properties
@@ -0,0 +1,36 @@
+## ---------------------------------------------------------------------------
+## 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.file.enable    = false
+quarkus.log.console.enable = true
+quarkus.banner.enabled     = false
+
+#
+# Quarkus :: Camel
+#
+quarkus.camel.main.routes-discovery.enabled = false
+
+#
+# Camel
+#
+camel.context.name = camel-k-quarkus-ctx
+
+#
+# Integration
+#
diff --git 
a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-polyglot/src/test/java/org/apache/camel/k/itests/polyglot/quarkus/ExtensionIT.java
 
b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-polyglot/src/test/java/org/apache/camel/k/itests/polyglot/quarkus/ExtensionIT.java
new file mode 100644
index 0000000..083853a
--- /dev/null
+++ 
b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-polyglot/src/test/java/org/apache/camel/k/itests/polyglot/quarkus/ExtensionIT.java
@@ -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.itests.polyglot.quarkus;
+
+import io.quarkus.test.junit.NativeImageTest;
+
+@NativeImageTest
+public class ExtensionIT extends ExtensionTest {
+}
\ No newline at end of file
diff --git 
a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-polyglot/src/test/java/org/apache/camel/k/itests/polyglot/quarkus/ExtensionTest.java
 
b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-polyglot/src/test/java/org/apache/camel/k/itests/polyglot/quarkus/ExtensionTest.java
new file mode 100644
index 0000000..e1bd54f
--- /dev/null
+++ 
b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-polyglot/src/test/java/org/apache/camel/k/itests/polyglot/quarkus/ExtensionTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.itests.polyglot.quarkus;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+
+import javax.ws.rs.core.MediaType;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.RestAssured;
+import io.restassured.path.json.JsonPath;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@QuarkusTest
+public class ExtensionTest {
+    @ParameterizedTest
+    @ValueSource(strings = { "yaml", "xml" })
+    public void loadRoute(String loaderName) throws IOException {
+        final byte[] code;
+
+        try (InputStream is = 
ExtensionTest.class.getResourceAsStream("/routes." + loaderName)) {
+            code = is.readAllBytes();
+        }
+
+        JsonPath p = RestAssured.given()
+            .contentType(MediaType.APPLICATION_OCTET_STREAM)
+            .accept(MediaType.APPLICATION_JSON)
+            .body(code)
+            .post("/test/load-routes/{loaderName}/MyRoute", 
Map.of("loaderName", loaderName))
+            .then()
+                .statusCode(200)
+            .extract()
+                .body()
+                .jsonPath();
+
+        assertThat(p.getList("components", String.class)).contains("direct", 
"log");
+        assertThat(p.getList("routes", String.class)).contains(loaderName);
+        assertThat(p.getList("endpoints", String.class)).contains("direct://" 
+ loaderName, "log://" + loaderName);
+    }
+}
diff --git 
a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-polyglot/src/test/resources/routes.xml
 
b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-polyglot/src/test/resources/routes.xml
new file mode 100644
index 0000000..2bb35d9
--- /dev/null
+++ 
b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-polyglot/src/test/resources/routes.xml
@@ -0,0 +1,34 @@
+<?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.
+
+-->
+<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+        xmlns="http://camel.apache.org/schema/spring";
+        xsi:schemaLocation="
+            http://camel.apache.org/schema/spring
+            http://camel.apache.org/schema/spring/camel-spring.xsd";>
+
+    <route id="xml">
+        <from uri="direct:xml"/>
+        <marshal>
+            <json/>
+        </marshal>
+        <to uri="log:xml"/>
+    </route>
+
+</routes>
\ No newline at end of file
diff --git 
a/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-polyglot/src/test/resources/routes.yaml
 
b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-polyglot/src/test/resources/routes.yaml
new file mode 100644
index 0000000..709e1e0
--- /dev/null
+++ 
b/camel-k-quarkus/camel-k-quarkus-itests/camel-k-quarkus-itests-polyglot/src/test/resources/routes.yaml
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+
+- route:
+    id: yaml
+    from:
+      uri: 'direct:yaml'
+      steps:
+        - marshal:
+            json: {}
+        - to: 'log:yaml'
\ 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 fb317cf..f412017 100644
--- a/camel-k-quarkus/camel-k-quarkus-itests/pom.xml
+++ b/camel-k-quarkus/camel-k-quarkus-itests/pom.xml
@@ -35,6 +35,7 @@
         <module>camel-k-quarkus-itests-loader-js</module>
         <module>camel-k-quarkus-itests-loader-xml</module>
         <module>camel-k-quarkus-itests-loader-yaml</module>
+        <module>camel-k-quarkus-itests-polyglot</module>
     </modules>
 
 </project>

Reply via email to