This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push: new a4a7ea4 Added Jolt support #1421 new 5d61dbe Merge pull request #1432 from aldettinger/CAMEL-QUARKUS-1421 a4a7ea4 is described below commit a4a7ea41236a723956febdac4f866d0de0627036 Author: aldettinger <aldettin...@gmail.com> AuthorDate: Mon Jun 29 20:26:25 2020 +0200 Added Jolt support #1421 --- .github/test-categories.yaml | 1 + docs/modules/ROOT/pages/extensions/jolt.adoc | 47 ++++++++ .../pages/list-of-camel-quarkus-extensions.adoc | 4 +- extensions/jolt/deployment/pom.xml | 63 +++++++++++ .../component/jolt/deployment/JoltProcessor.java | 40 +++++++ extensions/jolt/pom.xml | 39 +++++++ extensions/jolt/runtime/pom.xml | 110 ++++++++++++++++++ .../jolt/runtime/src/main/doc/configuration.adoc | 15 +++ .../component/jolt/DeepCopySubstitution.java | 32 ++++++ .../main/resources/META-INF/quarkus-extension.yaml | 29 +++++ .../component/jolt/DeepCopySubstitutionTest.java | 61 ++++++++++ extensions/pom.xml | 1 + integration-tests/jolt/pom.xml | 126 +++++++++++++++++++++ .../quarkus/component/jolt/it/JoltResource.java | 90 +++++++++++++++ .../jolt/src/main/resources/application.properties | 17 +++ .../jolt/src/main/resources/defaultr.json | 4 + .../jolt/src/main/resources/function-spec.json | 9 ++ .../jolt/src/main/resources/removr.json | 3 + .../jolt/src/main/resources/sample-spec.json | 47 ++++++++ .../camel/quarkus/component/jolt/it/JoltIT.java | 24 ++++ .../camel/quarkus/component/jolt/it/JoltTest.java | 61 ++++++++++ .../jolt/src/test/resources/function-input.json | 4 + .../jolt/src/test/resources/function-output.json | 1 + .../jolt/src/test/resources/sample-input.json | 16 +++ .../jolt/src/test/resources/sample-output.json | 1 + integration-tests/pom.xml | 1 + poms/bom/pom.xml | 10 ++ 27 files changed, 855 insertions(+), 1 deletion(-) diff --git a/.github/test-categories.yaml b/.github/test-categories.yaml index ccf686e..9bc482f 100644 --- a/.github/test-categories.yaml +++ b/.github/test-categories.yaml @@ -81,6 +81,7 @@ misc: - braintree - compression - graphql + - jolt - mustache - pdf - qute diff --git a/docs/modules/ROOT/pages/extensions/jolt.adoc b/docs/modules/ROOT/pages/extensions/jolt.adoc new file mode 100644 index 0000000..4f92203 --- /dev/null +++ b/docs/modules/ROOT/pages/extensions/jolt.adoc @@ -0,0 +1,47 @@ +// Do not edit directly! +// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page + +[[jolt]] += JOLT + +[.badges] +[.badge-key]##Since Camel Quarkus##[.badge-version]##1.0.0-CR3## [.badge-key]##JVM##[.badge-supported]##supported## [.badge-key]##Native##[.badge-supported]##supported## + +JSON to JSON transformation using JOLT. + +== What's inside + +* https://camel.apache.org/components/latest/jolt-component.html[JOLT component], URI syntax: `jolt:resourceUri` + +Please refer to the above link for usage and configuration details. + +== Maven coordinates + +[source,xml] +---- +<dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jolt</artifactId> +</dependency> +---- + +Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications. + +== Additional Camel Quarkus configuration + +Beyond standard usages described above, a trick is needed when using jolt specs from classpath resources in native mode. In such a situation, one needs to explicitly embed the resources in the native executable by specifying the `include-patterns` option. + +For instance, the route below would load the jolt spec from a classpath resource named _defaultr.json_: +[source,java] +---- +from("direct:start").to("jolt:defaultr.json"); +---- + +In order to work in native mode the `include-patterns` configuration should be set. For instance, in the `application.properties` file as below : +[source,properties] +---- +quarkus.camel.native.resources.include-patterns = *.json +---- + +More information about selecting resources for inclusion in the native executable could be found at xref:user-guide/native-mode.adoc#embedding-resource-in-native-executable[Embedding resource in native executable]. + diff --git a/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc b/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc index 8144a1f..a4d5562 100644 --- a/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc +++ b/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc @@ -18,7 +18,7 @@ In case you are missing some Camel feature in the list: == Camel Components // components: START -Number of Camel components: 152 in 117 JAR artifacts (0 deprecated) +Number of Camel components: 153 in 118 JAR artifacts (0 deprecated) [width="100%",cols="4,1,1,1,5",options="header"] |=== @@ -188,6 +188,8 @@ Number of Camel components: 152 in 117 JAR artifacts (0 deprecated) | xref:extensions/jms.adoc[JMS] | camel-quarkus-jms | Native + Stable | 1.2.0 | Sent and receive messages to/from a JMS Queue or Topic. +| xref:extensions/jolt.adoc[JOLT] | camel-quarkus-jolt | Native + Stable | 1.0.0-CR3 | JSON to JSON transformation using JOLT. + | xref:extensions/json-validator.adoc[JSON Schema Validator] | camel-quarkus-json-validator | Native + Stable | 1.0.0-CR3 | Validate JSON payloads using NetworkNT JSON Schema. | xref:extensions/kafka.adoc[Kafka] | camel-quarkus-kafka | Native + Stable | 1.0.0-M1 | Sent and receive messages to/from an Apache Kafka broker. diff --git a/extensions/jolt/deployment/pom.xml b/extensions/jolt/deployment/pom.xml new file mode 100644 index 0000000..393d30d --- /dev/null +++ b/extensions/jolt/deployment/pom.xml @@ -0,0 +1,63 @@ +<?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"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jolt-parent</artifactId> + <version>1.1.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-jolt-deployment</artifactId> + <name>Camel Quarkus :: JOLT :: Deployment</name> + + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-core-deployment</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jolt</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <annotationProcessorPaths> + <path> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-extension-processor</artifactId> + <version>${quarkus.version}</version> + </path> + </annotationProcessorPaths> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/extensions/jolt/deployment/src/main/java/org/apache/camel/quarkus/component/jolt/deployment/JoltProcessor.java b/extensions/jolt/deployment/src/main/java/org/apache/camel/quarkus/component/jolt/deployment/JoltProcessor.java new file mode 100644 index 0000000..d572309 --- /dev/null +++ b/extensions/jolt/deployment/src/main/java/org/apache/camel/quarkus/component/jolt/deployment/JoltProcessor.java @@ -0,0 +1,40 @@ +/* + * 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.jolt.deployment; + +import com.bazaarvoice.jolt.chainr.spec.ChainrEntry; +import io.quarkus.deployment.annotations.BuildProducer; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.FeatureBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; + +class JoltProcessor { + + private static final String FEATURE = "camel-jolt"; + + @BuildStep + FeatureBuildItem feature() { + return new FeatureBuildItem(FEATURE); + } + + @BuildStep + void registerReflectiveClasses(BuildProducer<ReflectiveClassBuildItem> producer) { + ChainrEntry.STOCK_TRANSFORMS.values().stream().forEach(c -> { + producer.produce(new ReflectiveClassBuildItem(false, false, c)); + }); + } +} diff --git a/extensions/jolt/pom.xml b/extensions/jolt/pom.xml new file mode 100644 index 0000000..aa99c83 --- /dev/null +++ b/extensions/jolt/pom.xml @@ -0,0 +1,39 @@ +<?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"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-build-parent</artifactId> + <version>1.1.0-SNAPSHOT</version> + <relativePath>../../poms/build-parent/pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-jolt-parent</artifactId> + <name>Camel Quarkus :: JOLT</name> + <packaging>pom</packaging> + + <modules> + <module>deployment</module> + <module>runtime</module> + </modules> +</project> diff --git a/extensions/jolt/runtime/pom.xml b/extensions/jolt/runtime/pom.xml new file mode 100644 index 0000000..43e231f --- /dev/null +++ b/extensions/jolt/runtime/pom.xml @@ -0,0 +1,110 @@ +<?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"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jolt-parent</artifactId> + <version>1.1.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-jolt</artifactId> + <name>Camel Quarkus :: JOLT :: Runtime</name> + <description>JSON to JSON transformation using JOLT.</description> + + <properties> + <firstVersion>1.0.0-CR3</firstVersion> + </properties> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-bom</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-core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-jolt</artifactId> + </dependency> + <dependency> + <groupId>org.graalvm.nativeimage</groupId> + <artifactId>svm</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-api</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <scope>test</scope> + </dependency> + + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-maven-plugin</artifactId> + <executions> + <execution> + <id>update-extension-doc-page</id> + <goals><goal>update-extension-doc-page</goal></goals> + <phase>process-classes</phase> + </execution> + </executions> + </plugin> + <plugin> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-bootstrap-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <annotationProcessorPaths> + <path> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-extension-processor</artifactId> + <version>${quarkus.version}</version> + </path> + </annotationProcessorPaths> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/extensions/jolt/runtime/src/main/doc/configuration.adoc b/extensions/jolt/runtime/src/main/doc/configuration.adoc new file mode 100644 index 0000000..deb88d1 --- /dev/null +++ b/extensions/jolt/runtime/src/main/doc/configuration.adoc @@ -0,0 +1,15 @@ +Beyond standard usages described above, a trick is needed when using jolt specs from classpath resources in native mode. In such a situation, one needs to explicitly embed the resources in the native executable by specifying the `include-patterns` option. + +For instance, the route below would load the jolt spec from a classpath resource named _defaultr.json_: +[source,java] +---- +from("direct:start").to("jolt:defaultr.json"); +---- + +In order to work in native mode the `include-patterns` configuration should be set. For instance, in the `application.properties` file as below : +[source,properties] +---- +quarkus.camel.native.resources.include-patterns = *.json +---- + +More information about selecting resources for inclusion in the native executable could be found at xref:user-guide/native-mode.adoc#embedding-resource-in-native-executable[Embedding resource in native executable]. \ No newline at end of file diff --git a/extensions/jolt/runtime/src/main/java/org/apache/camel/quarkus/component/jolt/DeepCopySubstitution.java b/extensions/jolt/runtime/src/main/java/org/apache/camel/quarkus/component/jolt/DeepCopySubstitution.java new file mode 100644 index 0000000..b774d51 --- /dev/null +++ b/extensions/jolt/runtime/src/main/java/org/apache/camel/quarkus/component/jolt/DeepCopySubstitution.java @@ -0,0 +1,32 @@ +/* + * 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.jolt; + +import com.bazaarvoice.jolt.JsonUtils; +import com.bazaarvoice.jolt.common.DeepCopy; +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; + +@TargetClass(DeepCopy.class) +@Substitute +final class DeepCopySubstitution { + + @Substitute + public static Object simpleDeepCopy(Object toCopy) { + return JsonUtils.cloneJson(toCopy); + } +} diff --git a/extensions/jolt/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/jolt/runtime/src/main/resources/META-INF/quarkus-extension.yaml new file mode 100644 index 0000000..eda16bc --- /dev/null +++ b/extensions/jolt/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -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. +# + +# This is a generated file. Do not edit directly! +# To re-generate, run the following command from the top level directory: +# +# mvn -N cq:update-quarkus-metadata +# +--- +name: "Camel JOLT" +description: "JSON to JSON transformation using JOLT" +metadata: + guide: "https://camel.apache.org/camel-quarkus/latest/extensions/jolt.html" + categories: + - "integration" diff --git a/extensions/jolt/runtime/src/test/java/org/apache/camel/quarkus/component/jolt/DeepCopySubstitutionTest.java b/extensions/jolt/runtime/src/test/java/org/apache/camel/quarkus/component/jolt/DeepCopySubstitutionTest.java new file mode 100644 index 0000000..81401a8 --- /dev/null +++ b/extensions/jolt/runtime/src/test/java/org/apache/camel/quarkus/component/jolt/DeepCopySubstitutionTest.java @@ -0,0 +1,61 @@ +/* + * 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.jolt; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.Objects; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class DeepCopySubstitutionTest { + + @SuppressWarnings("unchecked") + @Test + void nominalSchemaDeepCopyShouldSucceed() { + LinkedHashMap<String, Object> originalLinkedHashMap = new LinkedHashMap<>(); + ArrayList<Integer> originalArrayList = new ArrayList<>(Arrays.asList(new Integer(10))); + + originalLinkedHashMap.put("boolean", new Boolean(true)); + originalLinkedHashMap.put("string", "original"); + originalLinkedHashMap.put("list", originalArrayList); + originalLinkedHashMap.put("null", null); + + Object copiedLinkedHashMapObject = DeepCopySubstitution.simpleDeepCopy(originalLinkedHashMap); + + assertTrue(copiedLinkedHashMapObject instanceof LinkedHashMap); + LinkedHashMap<String, Object> copiedLinkHashMap = (LinkedHashMap<String, Object>) copiedLinkedHashMapObject; + Object copiedArrayListObject = copiedLinkHashMap.get("list"); + assertTrue(copiedArrayListObject instanceof ArrayList); + ArrayList<Integer> copiedArrayList = (ArrayList<Integer>) copiedArrayListObject; + + assertTrue(Objects.deepEquals(originalLinkedHashMap, copiedLinkHashMap)); + + assertNotSame(originalLinkedHashMap, copiedLinkHashMap); + assertNotSame(originalLinkedHashMap.get("boolean"), copiedLinkHashMap.get("boolean")); + assertNotSame(originalLinkedHashMap.get("string"), copiedLinkHashMap.get("string")); + assertNotSame(originalArrayList, copiedArrayList); + assertNotSame(originalArrayList.get(0), copiedArrayList.get(0)); + assertNull(copiedLinkHashMap.get("null")); + } + +} diff --git a/extensions/pom.xml b/extensions/pom.xml index b208a07..e5dc9d2 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -112,6 +112,7 @@ <module>jira</module> <module>jms</module> <module>johnzon</module> + <module>jolt</module> <module>json-validator</module> <module>jsonpath</module> <module>jta</module> diff --git a/integration-tests/jolt/pom.xml b/integration-tests/jolt/pom.xml new file mode 100644 index 0000000..3b4ca10 --- /dev/null +++ b/integration-tests/jolt/pom.xml @@ -0,0 +1,126 @@ +<?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"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-integration-tests</artifactId> + <version>1.1.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>camel-quarkus-integration-test-jolt</artifactId> + <name>Camel Quarkus :: Integration Tests :: JOLT</name> + <description>Integration tests for Camel Quarkus JOLT extension</description> + + <properties> + <!-- mvnd, a.k.a. Maven Daemon: https://github.com/gnodet/mvnd --> + <!-- The following rule tells mvnd to build the listed deployment modules before this module. --> + <!-- This is important because mvnd builds modules in parallel by default. The deployment modules are not --> + <!-- explicit dependencies of this module in the Maven sense, although they are required by the Quarkus Maven plugin. --> + <!-- Please update rule whenever you change the dependencies of this module by running --> + <!-- mvn process-resources -Pformat from the root directory --> + <mvnd.builder.rule>camel-quarkus-jolt-deployment,camel-quarkus-support-policy-deployment</mvnd.builder.rule> + </properties> + + <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-jolt</artifactId> + </dependency> + <dependency> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-resteasy</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> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>io.quarkus</groupId> + <artifactId>quarkus-maven-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>build</goal> + </goals> + </execution> + </executions> + </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> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> + +</project> diff --git a/integration-tests/jolt/src/main/java/org/apache/camel/quarkus/component/jolt/it/JoltResource.java b/integration-tests/jolt/src/main/java/org/apache/camel/quarkus/component/jolt/it/JoltResource.java new file mode 100644 index 0000000..0fb01b9 --- /dev/null +++ b/integration-tests/jolt/src/main/java/org/apache/camel/quarkus/component/jolt/it/JoltResource.java @@ -0,0 +1,90 @@ +/* + * 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.jolt.it; + +import java.util.HashMap; +import java.util.Map; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.PUT; +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.component.jolt.JoltConstants; +import org.jboss.logging.Logger; + +@Path("/jolt") +@ApplicationScoped +public class JoltResource { + + private static final Logger LOG = Logger.getLogger(JoltResource.class); + + @Inject + ProducerTemplate template; + + @Path("/defaultr") + @PUT + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public String defaultr(String value) { + LOG.infof("Calling defaultr with %s", value); + Map<String, String> inbody = new HashMap<>(); + inbody.put("key", value); + Map<?, ?> outBody = template.requestBody("jolt:defaultr.json?transformDsl=Defaultr", inbody, Map.class); + return String.format("%s-%s+%s", outBody.get("a"), outBody.get("b"), outBody.get("key")); + } + + @Path("/removr") + @PUT + @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) + public String removr(String value) { + LOG.infof("Calling removr with %s", value); + Map<String, String> inBody = new HashMap<>(); + inBody.put("keepMe", "Kept"); + inBody.put("key", value); + inBody.put("removeMe", "This should be gone"); + Map<?, ?> outBody = template.requestBody("jolt:removr.json?transformDsl=Removr", inBody, Map.class); + return String.format("%s-%s+%s", outBody.size(), outBody.get("keepMe"), outBody.get("key")); + } + + @Path("/sample") + @PUT + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public String sample(String inputJson) { + LOG.infof("Calling sample with %s", inputJson); + Map<String, String> context = new HashMap<>(); + context.put("contextB", "bb"); + String joltEndpointUri = "jolt:sample-spec.json?inputType=JsonString&outputType=JsonString&allowTemplateFromHeader=true"; + return template.requestBodyAndHeader(joltEndpointUri, inputJson, JoltConstants.JOLT_CONTEXT, context, String.class); + } + + @Path("/function") + @PUT + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public String function(String inputJson) { + LOG.infof("Calling function with %s", inputJson); + String joltEndpointUri = "jolt:function-spec.json?inputType=JsonString&outputType=JsonString"; + return template.requestBody(joltEndpointUri, inputJson, String.class); + } +} diff --git a/integration-tests/jolt/src/main/resources/application.properties b/integration-tests/jolt/src/main/resources/application.properties new file mode 100644 index 0000000..572c04e --- /dev/null +++ b/integration-tests/jolt/src/main/resources/application.properties @@ -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.camel.native.resources.include-patterns=*.json diff --git a/integration-tests/jolt/src/main/resources/defaultr.json b/integration-tests/jolt/src/main/resources/defaultr.json new file mode 100644 index 0000000..d166f55 --- /dev/null +++ b/integration-tests/jolt/src/main/resources/defaultr.json @@ -0,0 +1,4 @@ +{ + "a": "aa", + "b": "bb" +} diff --git a/integration-tests/jolt/src/main/resources/function-spec.json b/integration-tests/jolt/src/main/resources/function-spec.json new file mode 100644 index 0000000..5873277 --- /dev/null +++ b/integration-tests/jolt/src/main/resources/function-spec.json @@ -0,0 +1,9 @@ +[ + { + "operation": "modify-overwrite-beta", + "spec": { + // Divide and Round : decimal point to round to is first param + "aDivCRounded4": "=divideAndRound(4,@(1,a),@(1,c))" + } + } +] diff --git a/integration-tests/jolt/src/main/resources/removr.json b/integration-tests/jolt/src/main/resources/removr.json new file mode 100644 index 0000000..7ab2e7e --- /dev/null +++ b/integration-tests/jolt/src/main/resources/removr.json @@ -0,0 +1,3 @@ +{ + "removeMe": "" +} diff --git a/integration-tests/jolt/src/main/resources/sample-spec.json b/integration-tests/jolt/src/main/resources/sample-spec.json new file mode 100644 index 0000000..32f0acd --- /dev/null +++ b/integration-tests/jolt/src/main/resources/sample-spec.json @@ -0,0 +1,47 @@ +[ + { + // first operation is shift + "operation": "shift", + "spec": { + "rating": { + "primary": { + "value": "Rating", + "max": "RatingRange" + }, + "*": { + "value": "SecondaryRatings.&1.Value", + "max": "SecondaryRatings.&1.Range", + "$": "SecondaryRatings.&.Id" + } + } + } + }, + { + // second operation is to default some values + "operation": "default", + "spec": { + "~z": "zz", + "~a": "aa", + "~id": "id", + "zz": "zz", + "~deleteme": "deleteme" + } + }, + { + // third operation is to remove something + "operation": "remove", + "spec": { + "~deleteme": "" + } + }, + { + "operation": "modify-overwrite-beta", + "spec": { + "b": "^contextB" + } + }, + { + // last operation is to sort the JSON + "operation": "sort" + } +] diff --git a/integration-tests/jolt/src/test/java/org/apache/camel/quarkus/component/jolt/it/JoltIT.java b/integration-tests/jolt/src/test/java/org/apache/camel/quarkus/component/jolt/it/JoltIT.java new file mode 100644 index 0000000..be73f49 --- /dev/null +++ b/integration-tests/jolt/src/test/java/org/apache/camel/quarkus/component/jolt/it/JoltIT.java @@ -0,0 +1,24 @@ +/* + * 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.jolt.it; + +import io.quarkus.test.junit.NativeImageTest; + +@NativeImageTest +class JoltIT extends JoltTest { + +} diff --git a/integration-tests/jolt/src/test/java/org/apache/camel/quarkus/component/jolt/it/JoltTest.java b/integration-tests/jolt/src/test/java/org/apache/camel/quarkus/component/jolt/it/JoltTest.java new file mode 100644 index 0000000..d9f8c94 --- /dev/null +++ b/integration-tests/jolt/src/test/java/org/apache/camel/quarkus/component/jolt/it/JoltTest.java @@ -0,0 +1,61 @@ +/* + * 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.jolt.it; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Paths; + +import io.quarkus.bootstrap.util.IoUtils; +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.http.ContentType; +import org.junit.jupiter.api.Test; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.is; + +@QuarkusTest +class JoltTest { + + @Test + public void defaultrShouldSucceed() { + given().body("myValue").put("/jolt/defaultr").then().statusCode(200).body(is("aa-bb+myValue")); + } + + @Test + public void removrShouldSucceed() { + given().body("myOtherValue").put("/jolt/removr").then().statusCode(200).body(is("2-Kept+myOtherValue")); + } + + @Test + public void sampleShouldSucceed() throws IOException { + File requestBody = new File("src/test/resources/sample-input.json"); + String expectedResponseBody = IoUtils.readFile(Paths.get("src/test/resources/sample-output.json")); + + given().body(requestBody).contentType(ContentType.JSON).put("/jolt/sample").then().statusCode(200) + .body(is(expectedResponseBody)); + } + + @Test + public void functionShouldSucceed() throws IOException { + File requestBody = new File("src/test/resources/function-input.json"); + String expectedResponseBody = IoUtils.readFile(Paths.get("src/test/resources/function-output.json")); + + given().body(requestBody).contentType(ContentType.JSON).put("/jolt/function").then().statusCode(200) + .body(is(expectedResponseBody)); + } +} diff --git a/integration-tests/jolt/src/test/resources/function-input.json b/integration-tests/jolt/src/test/resources/function-input.json new file mode 100644 index 0000000..54780e9 --- /dev/null +++ b/integration-tests/jolt/src/test/resources/function-input.json @@ -0,0 +1,4 @@ +{ + "a": 10, + "c": 3 +} diff --git a/integration-tests/jolt/src/test/resources/function-output.json b/integration-tests/jolt/src/test/resources/function-output.json new file mode 100644 index 0000000..508e633 --- /dev/null +++ b/integration-tests/jolt/src/test/resources/function-output.json @@ -0,0 +1 @@ +{"a":10,"c":3,"aDivCRounded4":3.3333} \ No newline at end of file diff --git a/integration-tests/jolt/src/test/resources/sample-input.json b/integration-tests/jolt/src/test/resources/sample-input.json new file mode 100644 index 0000000..ac1b7e2 --- /dev/null +++ b/integration-tests/jolt/src/test/resources/sample-input.json @@ -0,0 +1,16 @@ +{ + "rating": { + "primary": { + "value": 3, + "max": 5 + }, + "sharpness": { + "value": 5, + "max": 5 + }, + "quality": { + "value": 3, + "max": 7 + } + } +} diff --git a/integration-tests/jolt/src/test/resources/sample-output.json b/integration-tests/jolt/src/test/resources/sample-output.json new file mode 100644 index 0000000..7b7e8fc --- /dev/null +++ b/integration-tests/jolt/src/test/resources/sample-output.json @@ -0,0 +1 @@ +{"~a":"aa","~id":"id","~z":"zz","Rating":3,"RatingRange":5,"SecondaryRatings":{"quality":{"Id":"quality","Range":7,"Value":3},"sharpness":{"Id":"sharpness","Range":5,"Value":5}},"b":"bb","zz":"zz"} \ No newline at end of file diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index ae6820f..3429627 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -99,6 +99,7 @@ <module>jaxb</module> <module>jdbc</module> <module>jira</module> + <module>jolt</module> <module>json-validator</module> <module>jsonpath</module> <module>jta</module> diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml index ab8b4d3..c6e824c 100644 --- a/poms/bom/pom.xml +++ b/poms/bom/pom.xml @@ -775,6 +775,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-jolt</artifactId> + <version>${camel.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-json-validator</artifactId> <version>${camel.version}</version> </dependency> @@ -2122,6 +2127,11 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jolt</artifactId> + <version>${camel-quarkus.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-json-validator</artifactId> <version>${camel-quarkus.version}</version> </dependency>