Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test language() DSL method & Language component native support #2996

Merged
merged 3 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ The grouped module may then be preferred in a CI job that validates pull request
E.g. for `https://github.com/apache/camel-quarkus/tree/main/integration-test-groups/azure[integration-test-groups/azure]` there is `https://github.com/apache/camel-quarkus/tree/main/integration-tests/azure-grouped[integration-tests/azure-grouped]`.
* Grouped modules dynamically pull all sources from their associated isolated test modules to their `target/[test-]classes` directories respectively.
* `application.properties` files and service descriptors are concatenated using a Groovy script.
* The dependencies in the grouped `pom.xml` need to be updated manually via `mvn process-resources -Pformat -N`.
* The dependencies in the grouped `pom.xml` need to be updated manually via `mvn process-resources -Pformat -N`
run from the root directory of the source tree.

== Coverage

Expand Down
19 changes: 14 additions & 5 deletions docs/modules/ROOT/pages/reference/extensions/language.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
= Language
:linkattrs:
:cq-artifact-id: camel-quarkus-language
:cq-native-supported: false
:cq-status: Preview
:cq-status-deprecation: Preview
:cq-native-supported: true
:cq-status: Stable
:cq-status-deprecation: Stable
:cq-description: Execute scripts in any of the languages supported by Camel.
:cq-deprecated: false
:cq-jvm-since: 1.1.0
:cq-native-since: n/a
:cq-native-since: 2.2.0

[.badges]
[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native##[.badge-unsupported]##unsupported##
[.badge-key]##JVM since##[.badge-supported]##1.1.0## [.badge-key]##Native since##[.badge-supported]##2.2.0##

Execute scripts in any of the languages supported by Camel.

Expand All @@ -24,6 +24,10 @@ Please refer to the above link for usage and configuration details.

== Maven coordinates

https://code.quarkus.io/?extension-search=camel-quarkus-language[Create a new project with this extension on code.quarkus.io, window="_blank"]

Or add the coordinates to your existing project:

[source,xml]
----
<dependency>
Expand All @@ -33,3 +37,8 @@ Please refer to the above link for usage and configuration details.
----

Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.

== allowContextMapAll option in native mode

The `allowContextMapAll` option is not supported in native mode as it requires reflective access to security sensitive camel core classes such as
`CamelContext` & `Exchange`. This is considered a security risk and thus access to the feature is not provided by default.
6 changes: 3 additions & 3 deletions docs/modules/ROOT/partials/reference/components/language.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
:cq-artifact-id: camel-quarkus-language
:cq-artifact-id-base: language
:cq-native-supported: false
:cq-status: Preview
:cq-native-supported: true
:cq-status: Stable
:cq-deprecated: false
:cq-jvm-since: 1.1.0
:cq-native-since: n/a
:cq-native-since: 2.2.0
:cq-camel-part-name: language
:cq-camel-part-title: Language
:cq-camel-part-description: Execute scripts in any of the languages supported by Camel.
Expand Down
1 change: 0 additions & 1 deletion extensions-jvm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
<module>jt400</module>
<module>kamelet-reify</module>
<module>kotlin-dsl</module>
<module>language</module>
<module>ldap</module>
<module>ldif</module>
<module>lucene</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
package org.apache.camel.quarkus.component.language.deployment;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.pkg.steps.NativeBuild;
import org.apache.camel.quarkus.core.JvmOnlyRecorder;
import org.jboss.logging.Logger;

class LanguageProcessor {
Expand All @@ -33,14 +29,4 @@ class LanguageProcessor {
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

/**
* Remove this once this extension starts supporting the native mode.
*/
@BuildStep(onlyIf = NativeBuild.class)
@Record(value = ExecutionTime.RUNTIME_INIT)
void warnJvmInNative(JvmOnlyRecorder recorder) {
JvmOnlyRecorder.warnJvmInNative(LOG, FEATURE); // warn at build time
recorder.warnJvmInNative(FEATURE); // warn at runtime
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@
<modules>
<module>deployment</module>
<module>runtime</module>
<module>integration-test</module>
</modules>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

<properties>
<camel.quarkus.jvmSince>1.1.0</camel.quarkus.jvmSince>
<camel.quarkus.nativeSince>2.2.0</camel.quarkus.nativeSince>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
name: "Camel Language"
description: "Execute scripts in any of the languages supported by Camel"
metadata:
unlisted: true
guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/language.html"
categories:
- "integration"
status:
- "preview"
- "stable"
1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<module>kotlin</module>
<module>kubernetes</module>
<module>kudu</module>
<module>language</module>
<module>leveldb</module>
<module>log</module>
<module>lra</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public void configure() {

from("direct:bodyIs-simple").filter().simple("${body} is 'java.nio.ByteBuffer'").setBody(constant("BYTE_BUFFER"));

from("direct:languageSimple")
.transform().language("simple", "Hello ${body} from language().simple()");

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,11 @@ public void byteBufferBodyShouldPassThroughBodyIsFilter() {
.body(is("BYTE_BUFFER"));
}

@Test
public void languageSimple() {
given().body("Frankenstein").when().post("/core-languages/route/languageSimple/String").then()
.statusCode(200)
.body(is("Hello Frankenstein from language().simple()"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,24 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-build-parent-it</artifactId>
<artifactId>camel-quarkus-integration-tests-foundation</artifactId>
<version>2.2.0-SNAPSHOT</version>
<relativePath>../../../poms/build-parent-it/pom.xml</relativePath>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-language-integration-test</artifactId>
<name>Camel Quarkus :: Language :: Integration Test</name>
<artifactId>camel-quarkus-integration-test-language</artifactId>
<name>Camel Quarkus :: Integration Tests :: Language</name>
<description>Integration tests for Camel Quarkus Language extension</description>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-bom-test</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-language</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-direct</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
Expand All @@ -65,6 +57,19 @@
</dependency>

<!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory -->
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-direct-deployment</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.quarkus</groupId>
<artifactId>camel-quarkus-language-deployment</artifactId>
Expand All @@ -80,4 +85,34 @@
</dependency>
</dependencies>

<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>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,27 @@

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Consumes;
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 javax.ws.rs.core.Response;

import org.apache.camel.CamelContext;
import org.jboss.logging.Logger;
import org.apache.camel.ProducerTemplate;

@Path("/language")
@ApplicationScoped
public class LanguageResource {

private static final Logger LOG = Logger.getLogger(LanguageResource.class);

private static final String COMPONENT_LANGUAGE = "language";
@Inject
CamelContext context;
ProducerTemplate template;

@Path("/load/component/language")
@GET
@Path("/route/{route}")
@POST
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public Response loadComponentLanguage() throws Exception {
/* This is an autogenerated test */
if (context.getComponent(COMPONENT_LANGUAGE) != null) {
return Response.ok().build();
}
LOG.warnf("Could not load [%s] from the Camel context", COMPONENT_LANGUAGE);
return Response.status(500, COMPONENT_LANGUAGE + " could not be loaded from the Camel context").build();
public String route(String body, @PathParam("route") String route) {
return template.requestBody("direct:" + route, body, String.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.quarkus.component.language.it;

import org.apache.camel.builder.RouteBuilder;

public class LanguageRoutes extends RouteBuilder {

@Override
public void configure() throws Exception {
from("direct:languageSimpleScript")
.to("language://simple:Hello ${body} from simple language script");
from("direct:languageSimpleResource")
.to("language://simple:resource:hello.simple.txt");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## ---------------------------------------------------------------------------
## 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.native.resources.includes = hello.simple.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello ${body} from simple language resource
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,9 @@
*/
package org.apache.camel.quarkus.component.language.it;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;
import io.quarkus.test.junit.NativeImageTest;

@QuarkusTest
class LanguageTest {

@Test
public void loadComponentLanguage() {
/* A simple autogenerated test */
RestAssured.get("/language/load/component/language")
.then()
.statusCode(200);
}
@NativeImageTest
class LanguageIT extends LanguageTest {

}