This is an automated email from the ASF dual-hosted git repository. nfilotto pushed a commit to branch 1748/ognl-language-native-support in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit af2620686fc87342be20682c550f220d225e7018 Author: Nicolas Filotto <nfilo...@talend.com> AuthorDate: Thu Jan 26 19:50:04 2023 +0100 Ref #1748: OGNL language native support --- docs/modules/ROOT/examples/languages/ognl.yml | 6 +- .../ROOT/pages/reference/extensions/ognl.adoc | 14 ++-- .../component/ognl/deployment/OgnlProcessor.java | 47 ------------ extensions-jvm/pom.xml | 1 - .../ognl/deployment/pom.xml | 0 .../component/ognl/deployment/OgnlProcessor.java | 62 ++++++++++++++++ {extensions-jvm => extensions}/ognl/pom.xml | 2 +- .../ognl/runtime/pom.xml | 1 + .../main/resources/META-INF/quarkus-extension.yaml | 3 +- extensions/pom.xml | 1 + .../quarkus/component/ognl/it/OgnlResource.java | 51 ------------- integration-tests-jvm/pom.xml | 1 - .../ognl/pom.xml | 78 ++++++++++++++++++++ .../quarkus/component/ognl/it/OgnlResource.java | 77 ++++++++++++++++++++ .../camel/quarkus/component/ognl/it/OgnlRoute.java | 50 +++++++++++++ .../quarkus/component/ognl/it/model/Animal.java | 50 +++++++++---- .../ognl/src/main/resources/hello.txt | 1 + .../ognl/src/main/resources/predicate.txt | 1 + .../camel/quarkus/component/ognl/it/OgnlIT.java | 17 +---- .../camel/quarkus/component/ognl/it/OgnlTest.java | 84 ++++++++++++++++++++++ integration-tests/pom.xml | 1 + tooling/scripts/test-categories.yaml | 1 + 22 files changed, 412 insertions(+), 137 deletions(-) diff --git a/docs/modules/ROOT/examples/languages/ognl.yml b/docs/modules/ROOT/examples/languages/ognl.yml index 03b735e1d3..1e48806e3e 100644 --- a/docs/modules/ROOT/examples/languages/ognl.yml +++ b/docs/modules/ROOT/examples/languages/ognl.yml @@ -2,11 +2,11 @@ # This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page cqArtifactId: camel-quarkus-ognl cqArtifactIdBase: ognl -cqNativeSupported: false -cqStatus: Preview +cqNativeSupported: true +cqStatus: Stable cqDeprecated: false cqJvmSince: 1.0.0 -cqNativeSince: n/a +cqNativeSince: 2.17.0 cqCamelPartName: ognl cqCamelPartTitle: OGNL cqCamelPartDescription: Evaluates an OGNL expression (Apache Commons OGNL). diff --git a/docs/modules/ROOT/pages/reference/extensions/ognl.adoc b/docs/modules/ROOT/pages/reference/extensions/ognl.adoc index 1e30e79a10..c62c8f1f7a 100644 --- a/docs/modules/ROOT/pages/reference/extensions/ognl.adoc +++ b/docs/modules/ROOT/pages/reference/extensions/ognl.adoc @@ -5,17 +5,17 @@ :page-aliases: extensions/ognl.adoc :linkattrs: :cq-artifact-id: camel-quarkus-ognl -:cq-native-supported: false -:cq-status: Preview -:cq-status-deprecation: Preview +:cq-native-supported: true +:cq-status: Stable +:cq-status-deprecation: Stable :cq-description: Evaluate an OGNL expression using Apache Commons OGNL :cq-deprecated: false :cq-jvm-since: 1.0.0 -:cq-native-since: n/a +:cq-native-since: 2.17.0 ifeval::[{doc-show-badges} == true] [.badges] -[.badge-key]##JVM since##[.badge-supported]##1.0.0## [.badge-key]##Native##[.badge-unsupported]##unsupported## +[.badge-key]##JVM since##[.badge-supported]##1.0.0## [.badge-key]##Native since##[.badge-supported]##2.17.0## endif::[] Evaluate an OGNL expression using Apache Commons OGNL @@ -30,6 +30,10 @@ Please refer to the above link for usage and configuration details. [id="extensions-ognl-maven-coordinates"] == Maven coordinates +https://{link-quarkus-code-generator}/?extension-search=camel-quarkus-ognl[Create a new project with this extension on {link-quarkus-code-generator}, window="_blank"] + +Or add the coordinates to your existing project: + [source,xml] ---- <dependency> diff --git a/extensions-jvm/ognl/deployment/src/main/java/org/apache/camel/quarkus/component/ognl/deployment/OgnlProcessor.java b/extensions-jvm/ognl/deployment/src/main/java/org/apache/camel/quarkus/component/ognl/deployment/OgnlProcessor.java deleted file mode 100644 index a63294a4cc..0000000000 --- a/extensions-jvm/ognl/deployment/src/main/java/org/apache/camel/quarkus/component/ognl/deployment/OgnlProcessor.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.ognl.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 OgnlProcessor { - private static final Logger LOG = Logger.getLogger(OgnlProcessor.class); - - private static final String FEATURE = "camel-ognl"; - - @BuildStep - 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 - } - -} diff --git a/extensions-jvm/pom.xml b/extensions-jvm/pom.xml index 5053e11a2b..1f629815fe 100644 --- a/extensions-jvm/pom.xml +++ b/extensions-jvm/pom.xml @@ -93,7 +93,6 @@ <module>management</module> <module>milo</module> <module>mvel</module> - <module>ognl</module> <module>printer</module> <module>pulsar</module> <module>quickfix</module> diff --git a/extensions-jvm/ognl/deployment/pom.xml b/extensions/ognl/deployment/pom.xml similarity index 100% rename from extensions-jvm/ognl/deployment/pom.xml rename to extensions/ognl/deployment/pom.xml diff --git a/extensions/ognl/deployment/src/main/java/org/apache/camel/quarkus/component/ognl/deployment/OgnlProcessor.java b/extensions/ognl/deployment/src/main/java/org/apache/camel/quarkus/component/ognl/deployment/OgnlProcessor.java new file mode 100644 index 0000000000..ab80b5c569 --- /dev/null +++ b/extensions/ognl/deployment/src/main/java/org/apache/camel/quarkus/component/ognl/deployment/OgnlProcessor.java @@ -0,0 +1,62 @@ +/* + * 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.ognl.deployment; + +import java.lang.reflect.Method; +import java.util.HashSet; +import java.util.Set; + +import io.quarkus.deployment.annotations.BuildProducer; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.CombinedIndexBuildItem; +import io.quarkus.deployment.builditem.FeatureBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; +import io.quarkus.deployment.pkg.steps.NativeBuild; +import org.apache.camel.language.ognl.RootObject; +import org.jboss.jandex.ClassInfo; +import org.jboss.jandex.DotName; +import org.jboss.jandex.IndexView; + +class OgnlProcessor { + private static final String FEATURE = "camel-ognl"; + + @BuildStep + FeatureBuildItem feature() { + return new FeatureBuildItem(FEATURE); + } + + @BuildStep(onlyIf = NativeBuild.class) + void registerReflectiveClasses(CombinedIndexBuildItem combinedIndexBuildItem, + BuildProducer<ReflectiveClassBuildItem> reflectiveClass) { + IndexView view = combinedIndexBuildItem.getIndex(); + Set<Class<?>> types = new HashSet<>(); + types.add(RootObject.class); + for (Method method : RootObject.class.getMethods()) { + if (!method.getDeclaringClass().equals(Object.class)) { + Class<?> returnType = method.getReturnType(); + if (types.add(returnType) && returnType.getPackageName().equals("org.apache.camel")) { + reflectiveClass.produce( + new ReflectiveClassBuildItem( + false, true, false, + view.getAllKnownImplementors(returnType).stream().map(ClassInfo::name) + .map(DotName::toString).toArray(String[]::new))); + } + } + } + reflectiveClass.produce(new ReflectiveClassBuildItem(false, true, false, types.toArray(new Class<?>[0]))); + } +} diff --git a/extensions-jvm/ognl/pom.xml b/extensions/ognl/pom.xml similarity index 96% rename from extensions-jvm/ognl/pom.xml rename to extensions/ognl/pom.xml index 26c39023e6..e08f791b5e 100644 --- a/extensions-jvm/ognl/pom.xml +++ b/extensions/ognl/pom.xml @@ -21,7 +21,7 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-extensions-jvm</artifactId> + <artifactId>camel-quarkus-extensions</artifactId> <version>2.17.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> diff --git a/extensions-jvm/ognl/runtime/pom.xml b/extensions/ognl/runtime/pom.xml similarity index 98% rename from extensions-jvm/ognl/runtime/pom.xml rename to extensions/ognl/runtime/pom.xml index 1058e30197..a7cbdd5c64 100644 --- a/extensions-jvm/ognl/runtime/pom.xml +++ b/extensions/ognl/runtime/pom.xml @@ -32,6 +32,7 @@ <properties> <camel.quarkus.jvmSince>1.0.0</camel.quarkus.jvmSince> + <camel.quarkus.nativeSince>2.17.0</camel.quarkus.nativeSince> </properties> <dependencies> diff --git a/extensions-jvm/ognl/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/ognl/runtime/src/main/resources/META-INF/quarkus-extension.yaml similarity index 97% rename from extensions-jvm/ognl/runtime/src/main/resources/META-INF/quarkus-extension.yaml rename to extensions/ognl/runtime/src/main/resources/META-INF/quarkus-extension.yaml index 85e15257db..0a4e9a4222 100644 --- a/extensions-jvm/ognl/runtime/src/main/resources/META-INF/quarkus-extension.yaml +++ b/extensions/ognl/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -24,9 +24,8 @@ name: "Camel OGNL" description: "Evaluate an OGNL expression using Apache Commons OGNL" metadata: - unlisted: true guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/ognl.html" categories: - "integration" status: - - "preview" + - "stable" diff --git a/extensions/pom.xml b/extensions/pom.xml index fdce02e667..10452a5f5e 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -185,6 +185,7 @@ <module>netty-http</module> <module>nitrite</module> <module>oaipmh</module> + <module>ognl</module> <module>olingo4</module> <module>openapi-java</module> <module>openstack</module> diff --git a/integration-tests-jvm/ognl/src/main/java/org/apache/camel/quarkus/component/ognl/it/OgnlResource.java b/integration-tests-jvm/ognl/src/main/java/org/apache/camel/quarkus/component/ognl/it/OgnlResource.java deleted file mode 100644 index 678a72c6e0..0000000000 --- a/integration-tests-jvm/ognl/src/main/java/org/apache/camel/quarkus/component/ognl/it/OgnlResource.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.ognl.it; - -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -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; - -@Path("/ognl") -@ApplicationScoped -public class OgnlResource { - - private static final Logger LOG = Logger.getLogger(OgnlResource.class); - - private static final String LANGUAGE_OGNL = "ognl"; - @Inject - CamelContext context; - - @Path("/load/language/ognl") - @GET - @Produces(MediaType.TEXT_PLAIN) - public Response loadLanguageOgnl() throws Exception { - /* This is an autogenerated test */ - if (context.resolveLanguage(LANGUAGE_OGNL) != null) { - return Response.ok().build(); - } - LOG.warnf("Could not load [%s] from the Camel context", LANGUAGE_OGNL); - return Response.status(500, LANGUAGE_OGNL + " could not be loaded from the Camel context").build(); - } -} diff --git a/integration-tests-jvm/pom.xml b/integration-tests-jvm/pom.xml index 8780201fb1..6b4792f2ad 100644 --- a/integration-tests-jvm/pom.xml +++ b/integration-tests-jvm/pom.xml @@ -92,7 +92,6 @@ <module>management</module> <module>milo</module> <module>mvel</module> - <module>ognl</module> <module>printer</module> <module>pulsar</module> <module>quickfix</module> diff --git a/integration-tests-jvm/ognl/pom.xml b/integration-tests/ognl/pom.xml similarity index 51% rename from integration-tests-jvm/ognl/pom.xml rename to integration-tests/ognl/pom.xml index 0eceb6e748..b5e02c4d97 100644 --- a/integration-tests-jvm/ognl/pom.xml +++ b/integration-tests/ognl/pom.xml @@ -31,6 +31,18 @@ <description>Integration tests for Camel Quarkus OGNL extension</description> <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-direct</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-kamelet</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-bean</artifactId> + </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-ognl</artifactId> @@ -63,6 +75,45 @@ </activation> <dependencies> <!-- 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-bean-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-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-kamelet-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-ognl-deployment</artifactId> @@ -78,6 +129,33 @@ </dependency> </dependencies> </profile> + <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> diff --git a/integration-tests/ognl/src/main/java/org/apache/camel/quarkus/component/ognl/it/OgnlResource.java b/integration-tests/ognl/src/main/java/org/apache/camel/quarkus/component/ognl/it/OgnlResource.java new file mode 100644 index 0000000000..7d724521f9 --- /dev/null +++ b/integration-tests/ognl/src/main/java/org/apache/camel/quarkus/component/ognl/it/OgnlResource.java @@ -0,0 +1,77 @@ +/* + * 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.ognl.it; + +import java.util.Map; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.apache.camel.ProducerTemplate; +import org.apache.camel.quarkus.component.ognl.it.model.Animal; + +@Path("/ognl") +@ApplicationScoped +public class OgnlResource { + + @Inject + ProducerTemplate producerTemplate; + + @POST + @Path("/hello") + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public String hello(String message) { + return producerTemplate.requestBody("direct:ognlHello", message, String.class); + } + + @GET + @Path("/hi") + public String hi() { + return producerTemplate.requestBody("direct:ognlHi", null, String.class); + } + + @POST + @Path("/predicate") + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public String predicate(String message) { + return producerTemplate.requestBody("direct:predicate", Integer.valueOf(message), String.class); + } + + @GET + @Path("/invokeMethod") + @Produces(MediaType.TEXT_PLAIN) + public String invokeMethod() { + Animal animal = new Animal("Tony the Tiger", 12); + return producerTemplate.requestBody("direct:invokeMethod", animal, String.class); + } + + @GET + @Path("/ognlExpressions") + @Produces(MediaType.TEXT_PLAIN) + public String ognlExpressions() { + return producerTemplate.requestBodyAndHeaders("direct:ognlExpressions", "<hello id='m123'>world!</hello>", + Map.of("foo", "abc", "bar", 123), String.class); + } +} diff --git a/integration-tests/ognl/src/main/java/org/apache/camel/quarkus/component/ognl/it/OgnlRoute.java b/integration-tests/ognl/src/main/java/org/apache/camel/quarkus/component/ognl/it/OgnlRoute.java new file mode 100644 index 0000000000..10cd1808ae --- /dev/null +++ b/integration-tests/ognl/src/main/java/org/apache/camel/quarkus/component/ognl/it/OgnlRoute.java @@ -0,0 +1,50 @@ +/* + * 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.ognl.it; + +import org.apache.camel.builder.RouteBuilder; + +public class OgnlRoute extends RouteBuilder { + @Override + public void configure() { + routeTemplate("whereTo") + .templateParameter("bar") + .templateBean("myBar", "ognl", "\"Hi\"") + .from("kamelet:source") + .to("bean:{{myBar}}?method=toString") + .setBody().ognl("request.body + \" {{bar}}\""); + + from("direct:ognlHi") + .kamelet("whereTo?bar=John"); + + from("direct:ognlHello") + .transform().ognl("resource:classpath:hello.txt"); + + from("direct:invokeMethod") + .transform().ognl("request.body.name + \"/\" + request.body.isDangerous()"); + from("direct:ognlExpressions") + .setBody() + .ognl("exchange.getIn().body + \"/\" + getRequest().body + \"/\" + request.body + \"/\" + getRequest().headers['foo'] + \"/\" + getRequest().headers.foo + \"/\" + request.headers.foo"); + + from("direct:predicate") + .choice() + .when().ognl("resource:classpath:predicate.txt") + .setBody().constant("High").endChoice() + .otherwise() + .setBody().constant("Low").endChoice(); + } +} diff --git a/integration-tests-jvm/ognl/src/test/java/org/apache/camel/quarkus/component/ognl/it/OgnlTest.java b/integration-tests/ognl/src/main/java/org/apache/camel/quarkus/component/ognl/it/model/Animal.java similarity index 50% copy from integration-tests-jvm/ognl/src/test/java/org/apache/camel/quarkus/component/ognl/it/OgnlTest.java copy to integration-tests/ognl/src/main/java/org/apache/camel/quarkus/component/ognl/it/model/Animal.java index 152c4151a0..90cb4fe5e8 100644 --- a/integration-tests-jvm/ognl/src/test/java/org/apache/camel/quarkus/component/ognl/it/OgnlTest.java +++ b/integration-tests/ognl/src/main/java/org/apache/camel/quarkus/component/ognl/it/model/Animal.java @@ -14,21 +14,47 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.camel.quarkus.component.ognl.it; +package org.apache.camel.quarkus.component.ognl.it.model; -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.RestAssured; -import org.junit.jupiter.api.Test; +import io.quarkus.runtime.annotations.RegisterForReflection; -@QuarkusTest -class OgnlTest { +@RegisterForReflection +public class Animal { + private String name; + private int age; + private Animal friend; - @Test - public void loadLanguageOgnl() { - /* A simple autogenerated test */ - RestAssured.get("/ognl/load/language/ognl") - .then() - .statusCode(200); + public Animal(String name, int age) { + this.name = name; + this.age = age; } + public String getName() { + return name; + } + + public int getAge() { + return age; + } + + public Animal getFriend() { + return friend; + } + + public void setFriend(Animal friend) { + this.friend = friend; + } + + public boolean isDangerous() { + return name.contains("Tiger"); + } + + @Override + public String toString() { + return name; + } + + public static String getClassName() { + return "Animal"; + } } diff --git a/integration-tests/ognl/src/main/resources/hello.txt b/integration-tests/ognl/src/main/resources/hello.txt new file mode 100644 index 0000000000..f95c0f99ca --- /dev/null +++ b/integration-tests/ognl/src/main/resources/hello.txt @@ -0,0 +1 @@ +"Hello " + request.body + " from OGNL!" \ No newline at end of file diff --git a/integration-tests/ognl/src/main/resources/predicate.txt b/integration-tests/ognl/src/main/resources/predicate.txt new file mode 100644 index 0000000000..b83d411cdf --- /dev/null +++ b/integration-tests/ognl/src/main/resources/predicate.txt @@ -0,0 +1 @@ +request.body / 2 > 10 \ No newline at end of file diff --git a/integration-tests-jvm/ognl/src/test/java/org/apache/camel/quarkus/component/ognl/it/OgnlTest.java b/integration-tests/ognl/src/test/java/org/apache/camel/quarkus/component/ognl/it/OgnlIT.java similarity index 71% rename from integration-tests-jvm/ognl/src/test/java/org/apache/camel/quarkus/component/ognl/it/OgnlTest.java rename to integration-tests/ognl/src/test/java/org/apache/camel/quarkus/component/ognl/it/OgnlIT.java index 152c4151a0..550445f7c5 100644 --- a/integration-tests-jvm/ognl/src/test/java/org/apache/camel/quarkus/component/ognl/it/OgnlTest.java +++ b/integration-tests/ognl/src/test/java/org/apache/camel/quarkus/component/ognl/it/OgnlIT.java @@ -16,19 +16,8 @@ */ package org.apache.camel.quarkus.component.ognl.it; -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.RestAssured; -import org.junit.jupiter.api.Test; - -@QuarkusTest -class OgnlTest { - - @Test - public void loadLanguageOgnl() { - /* A simple autogenerated test */ - RestAssured.get("/ognl/load/language/ognl") - .then() - .statusCode(200); - } +import io.quarkus.test.junit.QuarkusIntegrationTest; +@QuarkusIntegrationTest +public class OgnlIT extends OgnlTest { } diff --git a/integration-tests/ognl/src/test/java/org/apache/camel/quarkus/component/ognl/it/OgnlTest.java b/integration-tests/ognl/src/test/java/org/apache/camel/quarkus/component/ognl/it/OgnlTest.java new file mode 100644 index 0000000000..262ff25495 --- /dev/null +++ b/integration-tests/ognl/src/test/java/org/apache/camel/quarkus/component/ognl/it/OgnlTest.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.quarkus.component.ognl.it; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import org.hamcrest.CoreMatchers; +import org.junit.jupiter.api.Test; + +@QuarkusTest +class OgnlTest { + + @Test + void ognlHello() { + RestAssured.given() + .body("Jack Smith") + .post("/ognl/hello") + .then() + .statusCode(200) + .body(CoreMatchers.is("Hello Jack Smith from OGNL!")); + } + + @Test + void ognlHi() { + RestAssured.given() + .get("/ognl/hi") + .then() + .statusCode(200) + .body(CoreMatchers.is("Hi John")); + } + + @Test + void ognlHigh() { + RestAssured.given() + .body("45") + .post("/ognl/predicate") + .then() + .statusCode(200) + .body(CoreMatchers.is("High")); + } + + @Test + void ognlLow() { + RestAssured.given() + .body("13") + .post("/ognl/predicate") + .then() + .statusCode(200) + .body(CoreMatchers.is("Low")); + } + + @Test + void invokeMethod() { + RestAssured.given() + .get("/ognl/invokeMethod") + .then() + .statusCode(200) + .body(CoreMatchers.is("Tony the Tiger/true")); + } + + @Test + void ognlExpressions() { + RestAssured.given() + .get("/ognl/ognlExpressions") + .then() + .statusCode(200) + .body(CoreMatchers.is( + "<hello id='m123'>world!</hello>/<hello id='m123'>world!</hello>/<hello id='m123'>world!</hello>/abc/abc/abc")); + } +} diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index cd44de181a..236544d36a 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -168,6 +168,7 @@ <module>netty</module> <module>nitrite</module> <module>oaipmh</module> + <module>ognl</module> <module>olingo4</module> <module>openapi-java</module> <module>openstack</module> diff --git a/tooling/scripts/test-categories.yaml b/tooling/scripts/test-categories.yaml index d165cdb740..7c0aa56811 100644 --- a/tooling/scripts/test-categories.yaml +++ b/tooling/scripts/test-categories.yaml @@ -115,6 +115,7 @@ group-07: - geocoder - jslt - lumberjack + - ognl - olingo4 - optaplanner - pg-replication-slot