This is an automated email from the ASF dual-hosted git repository. ppalaga pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 6713eceec44fac7fd05378adb1ddfadfd61d38c7 Author: James Netherton <jamesnether...@gmail.com> AuthorDate: Fri Jun 4 14:32:10 2021 +0100 camel-jackson-protobuf data format native support Fixes #2615 --- .../reference/extensions/jackson-protobuf.adoc | 14 ++-- .../reference/dataformats/protobuf-jackson.adoc | 6 +- .../protobuf/it/JacksonProtobufResource.java | 51 ------------- extensions-jvm/pom.xml | 1 - .../jackson-protobuf/deployment/pom.xml | 4 + .../deployment/JacksonProtobufProcessor.java | 16 ---- .../jackson-protobuf/pom.xml | 1 - .../jackson-protobuf/runtime/pom.xml | 5 ++ .../main/resources/META-INF/quarkus-extension.yaml | 0 extensions/pom.xml | 1 + .../jackson-protobuf}/pom.xml | 54 ++++++++++++- .../protobuf/it/JacksonProtobufResource.java | 89 ++++++++++++++++++++++ .../jackson/protobuf/it/JacksonProtobufRoutes.java | 28 ++++--- .../component/jackson/protobuf/it/Pojo.java | 27 ++++--- .../src/main/resources/application.properties | 17 +++++ .../jackson-protobuf/src/main/resources/pojo.proto | 3 + .../jackson/protobuf/it/JacksonProtobufIT.java | 16 +--- .../jackson/protobuf/it/JacksonProtobufTest.java | 65 ++++++++++++++++ integration-tests/pom.xml | 1 + tooling/scripts/test-categories.yaml | 1 + 20 files changed, 283 insertions(+), 117 deletions(-) diff --git a/docs/modules/ROOT/pages/reference/extensions/jackson-protobuf.adoc b/docs/modules/ROOT/pages/reference/extensions/jackson-protobuf.adoc index 8111afc..11542c4 100644 --- a/docs/modules/ROOT/pages/reference/extensions/jackson-protobuf.adoc +++ b/docs/modules/ROOT/pages/reference/extensions/jackson-protobuf.adoc @@ -3,16 +3,16 @@ = Protobuf Jackson :linkattrs: :cq-artifact-id: camel-quarkus-jackson-protobuf -:cq-native-supported: false -:cq-status: Preview -:cq-status-deprecation: Preview +:cq-native-supported: true +:cq-status: Stable +:cq-status-deprecation: Stable :cq-description: Marshal POJOs to Protobuf and back using Jackson. :cq-deprecated: false :cq-jvm-since: 2.0.0 -:cq-native-since: n/a +:cq-native-since: 2.0.0 [.badges] -[.badge-key]##JVM since##[.badge-supported]##2.0.0## [.badge-key]##Native##[.badge-unsupported]##unsupported## +[.badge-key]##JVM since##[.badge-supported]##2.0.0## [.badge-key]##Native since##[.badge-supported]##2.0.0## Marshal POJOs to Protobuf and back using Jackson. @@ -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-jackson-protobuf[Create a new project with this extension on code.quarkus.io, window="_blank"] + +Or add the coordinates to your existing project: + [source,xml] ---- <dependency> diff --git a/docs/modules/ROOT/partials/reference/dataformats/protobuf-jackson.adoc b/docs/modules/ROOT/partials/reference/dataformats/protobuf-jackson.adoc index 4844544..c4e5d74 100644 --- a/docs/modules/ROOT/partials/reference/dataformats/protobuf-jackson.adoc +++ b/docs/modules/ROOT/partials/reference/dataformats/protobuf-jackson.adoc @@ -2,11 +2,11 @@ // This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page :cq-artifact-id: camel-quarkus-jackson-protobuf :cq-artifact-id-base: jackson-protobuf -:cq-native-supported: false -:cq-status: Preview +:cq-native-supported: true +:cq-status: Stable :cq-deprecated: false :cq-jvm-since: 2.0.0 -:cq-native-since: n/a +:cq-native-since: 2.0.0 :cq-camel-part-name: protobuf-jackson :cq-camel-part-title: Protobuf Jackson :cq-camel-part-description: Marshal POJOs to Protobuf and back using Jackson. diff --git a/extensions-jvm/jackson-protobuf/integration-test/src/main/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufResource.java b/extensions-jvm/jackson-protobuf/integration-test/src/main/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufResource.java deleted file mode 100644 index 31c3575..0000000 --- a/extensions-jvm/jackson-protobuf/integration-test/src/main/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufResource.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.jackson.protobuf.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("/jackson-protobuf") -@ApplicationScoped -public class JacksonProtobufResource { - - private static final Logger LOG = Logger.getLogger(JacksonProtobufResource.class); - - private static final String DATAFORMAT_PROTOBUF_JACKSON = "protobuf-jackson"; - @Inject - CamelContext context; - - @Path("/load/dataformat/protobuf-jackson") - @GET - @Produces(MediaType.TEXT_PLAIN) - public Response loadDataformatProtobufJackson() throws Exception { - /* This is an autogenerated test */ - if (context.resolveDataFormat(DATAFORMAT_PROTOBUF_JACKSON) != null) { - return Response.ok().build(); - } - LOG.warnf("Could not load [%s] from the Camel context", DATAFORMAT_PROTOBUF_JACKSON); - return Response.status(500, DATAFORMAT_PROTOBUF_JACKSON + " could not be loaded from the Camel context").build(); - } -} diff --git a/extensions-jvm/pom.xml b/extensions-jvm/pom.xml index f02ef3e..9467404 100644 --- a/extensions-jvm/pom.xml +++ b/extensions-jvm/pom.xml @@ -78,7 +78,6 @@ <module>iota</module> <module>irc</module> <module>jackson-avro</module> - <module>jackson-protobuf</module> <module>jasypt</module> <module>java-joor-dsl</module> <module>jbpm</module> diff --git a/extensions-jvm/jackson-protobuf/deployment/pom.xml b/extensions/jackson-protobuf/deployment/pom.xml similarity index 93% rename from extensions-jvm/jackson-protobuf/deployment/pom.xml rename to extensions/jackson-protobuf/deployment/pom.xml index 5946c57..94d669e 100644 --- a/extensions-jvm/jackson-protobuf/deployment/pom.xml +++ b/extensions/jackson-protobuf/deployment/pom.xml @@ -36,6 +36,10 @@ </dependency> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jackson-deployment</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-jackson-protobuf</artifactId> </dependency> </dependencies> diff --git a/extensions-jvm/jackson-protobuf/deployment/src/main/java/org/apache/camel/quarkus/component/jackson/protobuf/deployment/JacksonProtobufProcessor.java b/extensions/jackson-protobuf/deployment/src/main/java/org/apache/camel/quarkus/component/jackson/protobuf/deployment/JacksonProtobufProcessor.java similarity index 62% rename from extensions-jvm/jackson-protobuf/deployment/src/main/java/org/apache/camel/quarkus/component/jackson/protobuf/deployment/JacksonProtobufProcessor.java rename to extensions/jackson-protobuf/deployment/src/main/java/org/apache/camel/quarkus/component/jackson/protobuf/deployment/JacksonProtobufProcessor.java index 826aed9..0dd0241 100644 --- a/extensions-jvm/jackson-protobuf/deployment/src/main/java/org/apache/camel/quarkus/component/jackson/protobuf/deployment/JacksonProtobufProcessor.java +++ b/extensions/jackson-protobuf/deployment/src/main/java/org/apache/camel/quarkus/component/jackson/protobuf/deployment/JacksonProtobufProcessor.java @@ -17,30 +17,14 @@ package org.apache.camel.quarkus.component.jackson.protobuf.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 JacksonProtobufProcessor { - private static final Logger LOG = Logger.getLogger(JacksonProtobufProcessor.class); private static final String FEATURE = "camel-jackson-protobuf"; @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/jackson-protobuf/pom.xml b/extensions/jackson-protobuf/pom.xml similarity index 97% rename from extensions-jvm/jackson-protobuf/pom.xml rename to extensions/jackson-protobuf/pom.xml index feab74c..c71a365 100644 --- a/extensions-jvm/jackson-protobuf/pom.xml +++ b/extensions/jackson-protobuf/pom.xml @@ -33,6 +33,5 @@ <modules> <module>deployment</module> <module>runtime</module> - <module>integration-test</module> </modules> </project> diff --git a/extensions-jvm/jackson-protobuf/runtime/pom.xml b/extensions/jackson-protobuf/runtime/pom.xml similarity index 94% rename from extensions-jvm/jackson-protobuf/runtime/pom.xml rename to extensions/jackson-protobuf/runtime/pom.xml index f5089ff..e42265e 100644 --- a/extensions-jvm/jackson-protobuf/runtime/pom.xml +++ b/extensions/jackson-protobuf/runtime/pom.xml @@ -32,6 +32,7 @@ <properties> <camel.quarkus.jvmSince>2.0.0</camel.quarkus.jvmSince> + <camel.quarkus.nativeSince>2.0.0</camel.quarkus.nativeSince> </properties> <dependencyManagement> @@ -52,6 +53,10 @@ <artifactId>camel-quarkus-core</artifactId> </dependency> <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-jackson</artifactId> + </dependency> + <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-jackson-protobuf</artifactId> </dependency> diff --git a/extensions-jvm/jackson-protobuf/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/jackson-protobuf/runtime/src/main/resources/META-INF/quarkus-extension.yaml similarity index 100% rename from extensions-jvm/jackson-protobuf/runtime/src/main/resources/META-INF/quarkus-extension.yaml rename to extensions/jackson-protobuf/runtime/src/main/resources/META-INF/quarkus-extension.yaml diff --git a/extensions/pom.xml b/extensions/pom.xml index 89748e1..858ea1c 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -128,6 +128,7 @@ <module>influxdb</module> <module>ipfs</module> <module>jackson</module> + <module>jackson-protobuf</module> <module>jacksonxml</module> <module>jaxb</module> <module>jdbc</module> diff --git a/extensions-jvm/jackson-protobuf/integration-test/pom.xml b/integration-tests/jackson-protobuf/pom.xml similarity index 63% rename from extensions-jvm/jackson-protobuf/integration-test/pom.xml rename to integration-tests/jackson-protobuf/pom.xml index 58d6572..6fb13e0 100644 --- a/extensions-jvm/jackson-protobuf/integration-test/pom.xml +++ b/integration-tests/jackson-protobuf/pom.xml @@ -21,13 +21,12 @@ <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.apache.camel.quarkus</groupId> - <artifactId>camel-quarkus-build-parent-it</artifactId> + <artifactId>camel-quarkus-integration-tests</artifactId> <version>2.0.0-SNAPSHOT</version> - <relativePath>../../../poms/build-parent-it/pom.xml</relativePath> </parent> - <artifactId>camel-quarkus-jackson-protobuf-integration-test</artifactId> - <name>Camel Quarkus :: Protobuf Jackson :: Integration Test</name> + <artifactId>camel-quarkus-integration-test-jackson-protobuf</artifactId> + <name>Camel Quarkus :: Integration Tests :: Protobuf Jackson</name> <description>Integration tests for Camel Quarkus Protobuf Jackson extension</description> <dependencyManagement> @@ -45,6 +44,10 @@ <dependencies> <dependency> <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-direct</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-jackson-protobuf</artifactId> </dependency> <dependency> @@ -67,6 +70,19 @@ <!-- 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-jackson-protobuf-deployment</artifactId> <version>${project.version}</version> <type>pom</type> @@ -79,4 +95,34 @@ </exclusions> </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> diff --git a/integration-tests/jackson-protobuf/src/main/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufResource.java b/integration-tests/jackson-protobuf/src/main/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufResource.java new file mode 100644 index 0000000..50f1b31 --- /dev/null +++ b/integration-tests/jackson-protobuf/src/main/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufResource.java @@ -0,0 +1,89 @@ +/* + * 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.jackson.protobuf.it; + +import java.io.IOException; +import java.io.InputStream; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.inject.Named; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema; +import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchemaLoader; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.component.jackson.SchemaResolver; +import org.apache.camel.component.jackson.protobuf.JacksonProtobufDataFormat; +import org.apache.camel.util.IOHelper; + +@Path("/jackson-protobuf") +@ApplicationScoped +public class JacksonProtobufResource { + + @Inject + ProducerTemplate producerTemplate; + + @Path("/marshal") + @POST + public Response protobufJacksonMarshal(String message) throws Exception { + Pojo pojo = new Pojo(message); + byte[] result = producerTemplate.requestBody("direct:marshal-pojo", pojo, byte[].class); + return Response.ok(result).build(); + } + + @Path("/unmarshal/{type}") + @POST + @Consumes("application/octet-stream") + public Response protobufJacksonUnMarshal(@PathParam("type") String type, byte[] message) throws Exception { + Response.ResponseBuilder builder = Response.ok(); + String directUri = "direct:unmarshal-" + type; + + if (type.equals("pojo") || type.equals("defined-dataformat")) { + Pojo result = producerTemplate.requestBody(directUri, message, Pojo.class); + builder.entity(result.getText()); + } else if (type.equals("json-node")) { + JsonNode result = producerTemplate.requestBody(directUri, message, JsonNode.class); + builder.entity(result.at("/text").asText()); + } else { + throw new IllegalArgumentException("Unknown unmarshal type: " + type); + } + + return builder.build(); + } + + @Named + public SchemaResolver protobufSchemaResolver() throws IOException { + InputStream resource = JacksonProtobufResource.class.getResourceAsStream("/pojo.proto"); + ProtobufSchema schema = ProtobufSchemaLoader.std.parse(IOHelper.loadText(resource)); + return ex -> schema; + } + + @Named + public JacksonProtobufDataFormat jacksonProtobufDataFormat() { + JacksonProtobufDataFormat dataFormat = new JacksonProtobufDataFormat(); + dataFormat.setAutoDiscoverObjectMapper(true); + dataFormat.setAutoDiscoverSchemaResolver(true); + dataFormat.setUnmarshalType(Pojo.class); + return dataFormat; + } +} diff --git a/extensions-jvm/jackson-protobuf/integration-test/src/test/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufTest.java b/integration-tests/jackson-protobuf/src/main/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufRoutes.java similarity index 52% copy from extensions-jvm/jackson-protobuf/integration-test/src/test/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufTest.java copy to integration-tests/jackson-protobuf/src/main/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufRoutes.java index 84456ed..52ad130 100644 --- a/extensions-jvm/jackson-protobuf/integration-test/src/test/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufTest.java +++ b/integration-tests/jackson-protobuf/src/main/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufRoutes.java @@ -16,19 +16,23 @@ */ package org.apache.camel.quarkus.component.jackson.protobuf.it; -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.RestAssured; -import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.databind.JsonNode; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.dataformat.ProtobufLibrary; -@QuarkusTest -class JacksonProtobufTest { +public class JacksonProtobufRoutes extends RouteBuilder { + @Override + public void configure() throws Exception { + from("direct:marshal-pojo") + .marshal().protobuf(ProtobufLibrary.Jackson, Pojo.class, "protobufSchemaResolver"); - @Test - public void loadDataformatProtobufJackson() { - /* A simple autogenerated test */ - RestAssured.get("/jackson-protobuf/load/dataformat/protobuf-jackson") - .then() - .statusCode(200); - } + from("direct:unmarshal-pojo") + .unmarshal().protobuf(ProtobufLibrary.Jackson, Pojo.class, "protobufSchemaResolver"); + + from("direct:unmarshal-json-node") + .unmarshal().protobuf(ProtobufLibrary.Jackson, JsonNode.class, "protobufSchemaResolver"); + from("direct:unmarshal-defined-dataformat") + .unmarshal("jacksonProtobufDataFormat"); + } } diff --git a/extensions-jvm/jackson-protobuf/integration-test/src/test/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufTest.java b/integration-tests/jackson-protobuf/src/main/java/org/apache/camel/quarkus/component/jackson/protobuf/it/Pojo.java similarity index 69% copy from extensions-jvm/jackson-protobuf/integration-test/src/test/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufTest.java copy to integration-tests/jackson-protobuf/src/main/java/org/apache/camel/quarkus/component/jackson/protobuf/it/Pojo.java index 84456ed..806d6fc 100644 --- a/extensions-jvm/jackson-protobuf/integration-test/src/test/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufTest.java +++ b/integration-tests/jackson-protobuf/src/main/java/org/apache/camel/quarkus/component/jackson/protobuf/it/Pojo.java @@ -16,19 +16,24 @@ */ package org.apache.camel.quarkus.component.jackson.protobuf.it; -import io.quarkus.test.junit.QuarkusTest; -import io.restassured.RestAssured; -import org.junit.jupiter.api.Test; +import io.quarkus.runtime.annotations.RegisterForReflection; -@QuarkusTest -class JacksonProtobufTest { +@RegisterForReflection(fields = false) +public class Pojo { + private String text; - @Test - public void loadDataformatProtobufJackson() { - /* A simple autogenerated test */ - RestAssured.get("/jackson-protobuf/load/dataformat/protobuf-jackson") - .then() - .statusCode(200); + public Pojo() { } + public Pojo(String text) { + this.text = text; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } } diff --git a/integration-tests/jackson-protobuf/src/main/resources/application.properties b/integration-tests/jackson-protobuf/src/main/resources/application.properties new file mode 100644 index 0000000..e865d22 --- /dev/null +++ b/integration-tests/jackson-protobuf/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=*.proto \ No newline at end of file diff --git a/integration-tests/jackson-protobuf/src/main/resources/pojo.proto b/integration-tests/jackson-protobuf/src/main/resources/pojo.proto new file mode 100644 index 0000000..70f8dc7 --- /dev/null +++ b/integration-tests/jackson-protobuf/src/main/resources/pojo.proto @@ -0,0 +1,3 @@ +message Pojo { + required string text = 1; +} diff --git a/extensions-jvm/jackson-protobuf/integration-test/src/test/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufTest.java b/integration-tests/jackson-protobuf/src/test/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufIT.java similarity index 68% rename from extensions-jvm/jackson-protobuf/integration-test/src/test/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufTest.java rename to integration-tests/jackson-protobuf/src/test/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufIT.java index 84456ed..c7b74b2 100644 --- a/extensions-jvm/jackson-protobuf/integration-test/src/test/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufTest.java +++ b/integration-tests/jackson-protobuf/src/test/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufIT.java @@ -16,19 +16,9 @@ */ package org.apache.camel.quarkus.component.jackson.protobuf.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 JacksonProtobufTest { - - @Test - public void loadDataformatProtobufJackson() { - /* A simple autogenerated test */ - RestAssured.get("/jackson-protobuf/load/dataformat/protobuf-jackson") - .then() - .statusCode(200); - } +@NativeImageTest +class JacksonProtobufIT extends JacksonProtobufTest { } diff --git a/integration-tests/jackson-protobuf/src/test/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufTest.java b/integration-tests/jackson-protobuf/src/test/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufTest.java new file mode 100644 index 0000000..146df70 --- /dev/null +++ b/integration-tests/jackson-protobuf/src/test/java/org/apache/camel/quarkus/component/jackson/protobuf/it/JacksonProtobufTest.java @@ -0,0 +1,65 @@ +/* + * 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.jackson.protobuf.it; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.equalTo; + +@QuarkusTest +class JacksonProtobufTest { + + @Test + public void marshalUnmarshal() { + String message = "Hello Camel Quarkus Jackson Protobuf"; + byte[] protobufSerialized = RestAssured.given() + .body(message) + .post("/jackson-protobuf/marshal") + .then() + .statusCode(200) + .header("Content-Length", equalTo(String.valueOf(message.length() + 2))) + .extract() + .body() + .asByteArray(); + + // Unmarshal to pojo + RestAssured.given() + .body(protobufSerialized) + .post("/jackson-protobuf/unmarshal/pojo") + .then() + .statusCode(200) + .body(equalTo(message)); + + // Unmarshal to JsonNode + RestAssured.given() + .body(protobufSerialized) + .post("/jackson-protobuf/unmarshal/json-node") + .then() + .statusCode(200) + .body(equalTo(message)); + + // Unmarshal using a pre-defined dataformat bean + RestAssured.given() + .body(protobufSerialized) + .post("/jackson-protobuf/unmarshal/defined-dataformat") + .then() + .statusCode(200) + .body(equalTo(message)); + } +} diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index fb1d2a8..b54dd92 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -120,6 +120,7 @@ <module>infinispan</module> <module>influxdb</module> <module>ipfs</module> + <module>jackson-protobuf</module> <module>jaxb</module> <module>jdbc</module> <module>jing</module> diff --git a/tooling/scripts/test-categories.yaml b/tooling/scripts/test-categories.yaml index 7deafef..8d34019 100644 --- a/tooling/scripts/test-categories.yaml +++ b/tooling/scripts/test-categories.yaml @@ -35,6 +35,7 @@ group-02: - google-bigquery - google-pubsub - grpc + - jackson-protobuf - oaipmh - pubnub - protobuf