This is an automated email from the ASF dual-hosted git repository.
aldettinger 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 4c4b8c4 Added native support for avro dataformat #1180
4c4b8c4 is described below
commit 4c4b8c475d37ef2be10f17d1dcce5db75642d748
Author: aldettinger <[email protected]>
AuthorDate: Mon May 4 13:39:03 2020 +0200
Added native support for avro dataformat #1180
---
.github/test-categories.yaml | 1 +
docs/modules/ROOT/pages/extensions/avro.adoc | 38 ++++++
.../pages/list-of-camel-quarkus-extensions.adoc | 4 +-
.../component/avro/deployment/AvroProcessor.java | 46 -------
.../quarkus/component/avro/it/AvroResource.java | 51 --------
extensions-jvm/pom.xml | 1 -
.../avro/deployment/pom.xml | 5 +
.../component/avro/deployment/AvroProcessor.java | 120 +++++++++++++++++
.../deployment/BuildTimeAvroDataFormatTest.java | 70 ++++++++++
.../src/test/resources/schemas/a-user.avsc | 7 +
.../src/test/resources/schemas/another-user.avsc | 7 +
{extensions-jvm => extensions}/avro/pom.xml | 1 -
.../avro/runtime/pom.xml | 5 +
.../component/avro/AvroDataFormatProducer.java | 55 ++++++++
.../camel/quarkus/component/avro/AvroRecorder.java | 20 ++-
.../component/avro/AvroSchemaSubstitution.java | 57 ++++++++
.../component/avro/BuildTimeAvroDataFormat.java | 24 ++--
.../main/resources/META-INF/quarkus-extension.yaml | 4 +-
.../component/avro/AvroDataFormatProducerTest.java | 57 ++++++++
extensions/pom.xml | 1 +
.../avro}/pom.xml | 40 +++++-
.../quarkus/component/avro/it/AvroResource.java | 83 ++++++++++++
.../camel/quarkus/component/avro/it/AvroRoute.java | 47 +++++++
.../component/avro/it/AvroSchemaLoader.java | 28 ++--
.../camel/quarkus/component/avro/it/Value.java | 143 +++++++++++++++++++++
.../avro/src/main/resources/user.avsc | 7 +
.../camel/quarkus/component/avro/it/AvroIT.java | 16 +--
.../camel/quarkus/component/avro/it/AvroTest.java | 27 +++-
integration-tests/pom.xml | 1 +
pom.xml | 1 +
30 files changed, 803 insertions(+), 164 deletions(-)
diff --git a/.github/test-categories.yaml b/.github/test-categories.yaml
index 2764f18..8c4f400 100644
--- a/.github/test-categories.yaml
+++ b/.github/test-categories.yaml
@@ -38,6 +38,7 @@ database:
- mongodb
- sql
dataformats:
+ - avro
- base64
- bindy
- csv
diff --git a/docs/modules/ROOT/pages/extensions/avro.adoc
b/docs/modules/ROOT/pages/extensions/avro.adoc
new file mode 100644
index 0000000..ec4ea18
--- /dev/null
+++ b/docs/modules/ROOT/pages/extensions/avro.adoc
@@ -0,0 +1,38 @@
+[[avro]]
+= Avro Extension
+
+*Since Camel Quarkus 1.0.0-M6*
+
+The Avro extension provides link:https://avro.apache.org/[Avro schema based
data serialization].
+
+Maven users will need to add the following dependency to their `pom.xml` for
this extension.
+
+[source,xml]
+------------------------------------------------------------
+<dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-avro</artifactId>
+</dependency>
+------------------------------------------------------------
+
+== Usage
+
+The extension provides support for the Camel
https://camel.apache.org/components/latest/dataformats/avro-dataformat.html[Avro
Data Format].
+
+=== Configuration
+
+Beyond standard usages described above, Camel Quarkus adds the possibility to
parse the Avro schema at build time both in JVM and Native mode via the
`@BuildTimeAvroDataFormat` annotation.
+
+For instance below, in the first step the `user.avsc` schema resource is
parsed at build time.
+In the second step, an AvroDataFormat instance using the previously parsed
schema is injected in the `buildTimeAvroDataFormat` field at runtime. At the
end of the day, the injected data format is used
+from the `configure()` method in order to marshal an incoming message.
+[source,java]
+----
+@BuildTimeAvroDataFormat("user.avsc")
+AvroDataFormat buildTimeAvroDataFormat;
+
+@Override
+public void configure() {
+
from("direct:marshalUsingBuildTimeAvroDataFormat").marshal(buildTimeAvroDataFormat);
+}
+----
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 02a909d..caed8ff 100644
--- a/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc
+++ b/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc
@@ -630,8 +630,8 @@ Number of Camel data formats: 26 in 21 JAR artifacts (0
deprecated)
| Data Format | Target +
Level | Since | Description
-| link:https://camel.apache.org/components/latest/avro-dataformat.html[Avro]
(camel-quarkus-avro) | JVM +
- Preview | 1.0.0-M6 | Serialize and deserialize messages using Apache Avro
binary data format.
+| xref:extensions/avro.adoc[Avro] (camel-quarkus-avro) | Native +
+ Stable | 1.0.0-M6 | Serialize and deserialize messages using Apache Avro
binary data format.
|
link:https://camel.apache.org/components/latest/base64-dataformat.html[Base64]
(camel-quarkus-base64) | Native +
Stable | 1.0.0-M1 | Encode and decode data using Base64.
diff --git
a/extensions-jvm/avro/deployment/src/main/java/org/apache/camel/quarkus/component/avro/deployment/AvroProcessor.java
b/extensions-jvm/avro/deployment/src/main/java/org/apache/camel/quarkus/component/avro/deployment/AvroProcessor.java
deleted file mode 100644
index 98a006f..0000000
---
a/extensions-jvm/avro/deployment/src/main/java/org/apache/camel/quarkus/component/avro/deployment/AvroProcessor.java
+++ /dev/null
@@ -1,46 +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.avro.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 AvroProcessor {
-
- private static final Logger LOG = Logger.getLogger(AvroProcessor.class);
- private static final String FEATURE = "camel-avro";
-
- @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/avro/integration-test/src/main/java/org/apache/camel/quarkus/component/avro/it/AvroResource.java
b/extensions-jvm/avro/integration-test/src/main/java/org/apache/camel/quarkus/component/avro/it/AvroResource.java
deleted file mode 100644
index ec520f6..0000000
---
a/extensions-jvm/avro/integration-test/src/main/java/org/apache/camel/quarkus/component/avro/it/AvroResource.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.avro.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("/avro")
-@ApplicationScoped
-public class AvroResource {
-
- private static final Logger LOG = Logger.getLogger(AvroResource.class);
-
- private static final String DATAFORMAT_AVRO = "avro";
- @Inject
- CamelContext context;
-
- @Path("/load/dataformat/avro")
- @GET
- @Produces(MediaType.TEXT_PLAIN)
- public Response loadDataformatAvro() throws Exception {
- /* This is an autogenerated test */
- if (context.resolveDataFormat(DATAFORMAT_AVRO) != null) {
- return Response.ok().build();
- }
- LOG.warnf("Could not load [%s] from the Camel context",
DATAFORMAT_AVRO);
- return Response.status(500, DATAFORMAT_AVRO + " could not be loaded
from the Camel context").build();
- }
-}
diff --git a/extensions-jvm/pom.xml b/extensions-jvm/pom.xml
index 36ca797..86ebd77 100644
--- a/extensions-jvm/pom.xml
+++ b/extensions-jvm/pom.xml
@@ -34,7 +34,6 @@
<modules>
<!-- extensions a..z; do not remove this comment, it is important when
sorting via mvn process-resources -Pformat -->
- <module>avro</module>
<module>avro-rpc</module>
<module>aws2-ddb</module>
<module>aws2-ec2</module>
diff --git a/extensions-jvm/avro/deployment/pom.xml
b/extensions/avro/deployment/pom.xml
similarity index 94%
rename from extensions-jvm/avro/deployment/pom.xml
rename to extensions/avro/deployment/pom.xml
index 84503a4..95905a0 100644
--- a/extensions-jvm/avro/deployment/pom.xml
+++ b/extensions/avro/deployment/pom.xml
@@ -50,6 +50,11 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-avro</artifactId>
</dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-junit5-internal</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git
a/extensions/avro/deployment/src/main/java/org/apache/camel/quarkus/component/avro/deployment/AvroProcessor.java
b/extensions/avro/deployment/src/main/java/org/apache/camel/quarkus/component/avro/deployment/AvroProcessor.java
new file mode 100644
index 0000000..cba07d8
--- /dev/null
+++
b/extensions/avro/deployment/src/main/java/org/apache/camel/quarkus/component/avro/deployment/AvroProcessor.java
@@ -0,0 +1,120 @@
+/*
+ * 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.avro.deployment;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
+import io.quarkus.arc.deployment.AnnotationsTransformerBuildItem;
+import io.quarkus.arc.deployment.BeanArchiveIndexBuildItem;
+import io.quarkus.arc.deployment.BeanContainerBuildItem;
+import io.quarkus.arc.processor.AnnotationsTransformer;
+import io.quarkus.deployment.annotations.BuildProducer;
+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.builditem.ObjectSubstitutionBuildItem;
+import io.quarkus.deployment.builditem.ObjectSubstitutionBuildItem.Holder;
+import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+import org.apache.avro.Schema;
+import org.apache.avro.SchemaParseException;
+import org.apache.avro.generic.GenericContainer;
+import org.apache.camel.quarkus.component.avro.AvroDataFormatProducer;
+import org.apache.camel.quarkus.component.avro.AvroRecorder;
+import org.apache.camel.quarkus.component.avro.AvroSchemaSubstitution;
+import org.apache.camel.quarkus.component.avro.BuildTimeAvroDataFormat;
+import org.jboss.jandex.AnnotationInstance;
+import org.jboss.jandex.DotName;
+import org.jboss.jandex.FieldInfo;
+import org.jboss.jandex.IndexView;
+import org.jboss.logging.Logger;
+
+class AvroProcessor {
+
+ private static final Logger LOG = Logger.getLogger(AvroProcessor.class);
+ private static final String FEATURE = "camel-avro";
+ private static DotName BUILD_TIME_AVRO_DATAFORMAT_ANNOTATION = DotName
+ .createSimple(BuildTimeAvroDataFormat.class.getName());
+
+ @BuildStep
+ FeatureBuildItem feature() {
+ return new FeatureBuildItem(FEATURE);
+ }
+
+ @BuildStep
+ List<ReflectiveClassBuildItem> reflectiveClasses() {
+ List<ReflectiveClassBuildItem> items = new
ArrayList<ReflectiveClassBuildItem>();
+ items.add(new ReflectiveClassBuildItem(false, false,
GenericContainer.class));
+ return items;
+ }
+
+ @BuildStep
+ void additionalBeanClasses(BuildProducer<AdditionalBeanBuildItem>
additionalBeanProducer) {
+ additionalBeanProducer.produce(new
AdditionalBeanBuildItem(AvroDataFormatProducer.class));
+ }
+
+ @BuildStep
+ AnnotationsTransformerBuildItem
markFieldsAnnotatedWithBuildTimeAvroDataFormatAsInjectable() {
+ return new AnnotationsTransformerBuildItem(new
AnnotationsTransformer() {
+
+ public boolean appliesTo(org.jboss.jandex.AnnotationTarget.Kind
kind) {
+ return kind == org.jboss.jandex.AnnotationTarget.Kind.FIELD;
+ }
+
+ @Override
+ public void transform(TransformationContext ctx) {
+ FieldInfo fieldInfo = ctx.getTarget().asField();
+ if
(fieldInfo.annotation(BUILD_TIME_AVRO_DATAFORMAT_ANNOTATION) != null) {
+ ctx.transform().add(Inject.class).done();
+ }
+ }
+ });
+ }
+
+ @BuildStep
+ void
overrideAvroSchemasSerialization(BuildProducer<ObjectSubstitutionBuildItem>
substitutions) {
+ Holder<Schema, byte[]> holder = new Holder(Schema.class, byte[].class,
AvroSchemaSubstitution.class);
+ substitutions.produce(new ObjectSubstitutionBuildItem(holder));
+ }
+
+ @Record(ExecutionTime.STATIC_INIT)
+ @BuildStep
+ void recordAvroSchemasResigtration(BeanArchiveIndexBuildItem
beanArchiveIndex,
+ BeanContainerBuildItem beanContainer, AvroRecorder avroRecorder) {
+ IndexView index = beanArchiveIndex.getIndex();
+ for (AnnotationInstance annotation :
index.getAnnotations(BUILD_TIME_AVRO_DATAFORMAT_ANNOTATION)) {
+ String schemaResourceName = annotation.value().asString();
+ FieldInfo fieldInfo = annotation.target().asField();
+ String injectedFieldId = fieldInfo.declaringClass().name() + "." +
fieldInfo.name();
+ try (InputStream is =
Thread.currentThread().getContextClassLoader().getResourceAsStream(schemaResourceName))
{
+ Schema avroSchema = new Schema.Parser().parse(is);
+
avroRecorder.recordAvroSchemaResigtration(beanContainer.getValue(),
injectedFieldId, avroSchema);
+ LOG.debug("Parsed the avro schema at build time from resource
named " + schemaResourceName);
+ } catch (SchemaParseException | IOException ex) {
+ final String message = "An issue occured while parsing schema
resource on field " + injectedFieldId;
+ throw new RuntimeException(message, ex);
+ }
+ }
+ }
+
+}
diff --git
a/extensions/avro/deployment/src/test/java/org/apache/camel/quarkus/component/avro/deployment/BuildTimeAvroDataFormatTest.java
b/extensions/avro/deployment/src/test/java/org/apache/camel/quarkus/component/avro/deployment/BuildTimeAvroDataFormatTest.java
new file mode 100644
index 0000000..e5d27b7
--- /dev/null
+++
b/extensions/avro/deployment/src/test/java/org/apache/camel/quarkus/component/avro/deployment/BuildTimeAvroDataFormatTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.avro.deployment;
+
+import io.quarkus.test.QuarkusUnitTest;
+import org.apache.avro.Schema;
+import org.apache.camel.dataformat.avro.AvroDataFormat;
+import org.apache.camel.quarkus.component.avro.BuildTimeAvroDataFormat;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class BuildTimeAvroDataFormatTest {
+
+ @RegisterExtension
+ static final QuarkusUnitTest CONFIG = new QuarkusUnitTest()
+ .setArchiveProducer(() ->
ShrinkWrap.create(JavaArchive.class).addAsResource("schemas/a-user.avsc")
+ .addAsResource("schemas/another-user.avsc"));
+
+ @BuildTimeAvroDataFormat("schemas/a-user.avsc")
+ AvroDataFormat aUserBuildTimeAvroDataFormat;
+
+ @BuildTimeAvroDataFormat("schemas/a-user.avsc")
+ AvroDataFormat aUserBuildTimeAvroDataFormatBis;
+
+ @BuildTimeAvroDataFormat("schemas/another-user.avsc")
+ AvroDataFormat anotherUserBuildTimeAvroDataFormat;
+
+ @Test
+ void buildTimeAvroDataFormatAnnotationsShouldBeProcessed() {
+ assertNotNull(aUserBuildTimeAvroDataFormat);
+ Object aUserObjectSchema = aUserBuildTimeAvroDataFormat.getSchema();
+ assertNotNull(aUserObjectSchema);
+ assertTrue(aUserObjectSchema instanceof Schema);
+ Schema aUserSchema = (Schema) aUserObjectSchema;
+ assertEquals("a.user", aUserSchema.getNamespace());
+
+ Object aUserBisObjectSchema =
aUserBuildTimeAvroDataFormatBis.getSchema();
+ assertNotNull(aUserBisObjectSchema);
+ assertNotSame(aUserObjectSchema, aUserBisObjectSchema);
+
+ assertNotNull(anotherUserBuildTimeAvroDataFormat);
+ Object anotherUserObjectSchema =
anotherUserBuildTimeAvroDataFormat.getSchema();
+ assertNotNull(anotherUserObjectSchema);
+ assertTrue(anotherUserObjectSchema instanceof Schema);
+ Schema anotherUserSchema = (Schema) anotherUserObjectSchema;
+ assertEquals("another.user", anotherUserSchema.getNamespace());
+ }
+
+}
diff --git a/extensions/avro/deployment/src/test/resources/schemas/a-user.avsc
b/extensions/avro/deployment/src/test/resources/schemas/a-user.avsc
new file mode 100644
index 0000000..a5c4d47
--- /dev/null
+++ b/extensions/avro/deployment/src/test/resources/schemas/a-user.avsc
@@ -0,0 +1,7 @@
+{"namespace": "a.user",
+ "type": "record",
+ "name": "User",
+ "fields": [
+ {"name": "name", "type": "string"}
+ ]
+}
\ No newline at end of file
diff --git
a/extensions/avro/deployment/src/test/resources/schemas/another-user.avsc
b/extensions/avro/deployment/src/test/resources/schemas/another-user.avsc
new file mode 100644
index 0000000..2cba772
--- /dev/null
+++ b/extensions/avro/deployment/src/test/resources/schemas/another-user.avsc
@@ -0,0 +1,7 @@
+{"namespace": "another.user",
+ "type": "record",
+ "name": "User",
+ "fields": [
+ {"name": "name", "type": "string"}
+ ]
+}
\ No newline at end of file
diff --git a/extensions-jvm/avro/pom.xml b/extensions/avro/pom.xml
similarity index 97%
rename from extensions-jvm/avro/pom.xml
rename to extensions/avro/pom.xml
index e92732d..192898f 100644
--- a/extensions-jvm/avro/pom.xml
+++ b/extensions/avro/pom.xml
@@ -33,6 +33,5 @@
<modules>
<module>deployment</module>
<module>runtime</module>
- <module>integration-test</module>
</modules>
</project>
diff --git a/extensions-jvm/avro/runtime/pom.xml
b/extensions/avro/runtime/pom.xml
similarity index 94%
rename from extensions-jvm/avro/runtime/pom.xml
rename to extensions/avro/runtime/pom.xml
index 66f043c..7df0ade 100644
--- a/extensions-jvm/avro/runtime/pom.xml
+++ b/extensions/avro/runtime/pom.xml
@@ -54,6 +54,11 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-avro</artifactId>
</dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-junit5-mockito</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git
a/extensions/avro/runtime/src/main/java/org/apache/camel/quarkus/component/avro/AvroDataFormatProducer.java
b/extensions/avro/runtime/src/main/java/org/apache/camel/quarkus/component/avro/AvroDataFormatProducer.java
new file mode 100644
index 0000000..f5bf922
--- /dev/null
+++
b/extensions/avro/runtime/src/main/java/org/apache/camel/quarkus/component/avro/AvroDataFormatProducer.java
@@ -0,0 +1,55 @@
+/*
+ * 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.avro;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Singleton;
+
+import org.apache.avro.Schema;
+import org.apache.camel.dataformat.avro.AvroDataFormat;
+
+@Singleton
+public class AvroDataFormatProducer {
+
+ private final Map<String, Schema> schemaRegistry = new HashMap<>();
+
+ public void registerAvroSchema(String injectedFieldId, Schema schema) {
+ schemaRegistry.put(injectedFieldId, schema);
+ }
+
+ @Produces
+ AvroDataFormat produceAvroDataFormat(InjectionPoint injectionPoint) {
+ Member member = injectionPoint.getMember();
+ if (member instanceof Field) {
+ Field field = (Field) member;
+ if (!Modifier.isStatic(member.getModifiers()) &&
field.getAnnotation(BuildTimeAvroDataFormat.class) != null) {
+ String injectedFieldId = member.getDeclaringClass().getName()
+ "." + member.getName();
+ Schema schema = schemaRegistry.get(injectedFieldId);
+ return new AvroDataFormat(schema);
+ }
+ }
+ String message = "AvroDataFormat beans can only be injected into
non-static field annotated with @";
+ throw new IllegalArgumentException(message +
BuildTimeAvroDataFormat.class.getName());
+ }
+}
diff --git
a/extensions-jvm/avro/integration-test/src/test/java/org/apache/camel/quarkus/component/avro/it/AvroTest.java
b/extensions/avro/runtime/src/main/java/org/apache/camel/quarkus/component/avro/AvroRecorder.java
similarity index 65%
copy from
extensions-jvm/avro/integration-test/src/test/java/org/apache/camel/quarkus/component/avro/it/AvroTest.java
copy to
extensions/avro/runtime/src/main/java/org/apache/camel/quarkus/component/avro/AvroRecorder.java
index 78229a0..a3b39d1 100644
---
a/extensions-jvm/avro/integration-test/src/test/java/org/apache/camel/quarkus/component/avro/it/AvroTest.java
+++
b/extensions/avro/runtime/src/main/java/org/apache/camel/quarkus/component/avro/AvroRecorder.java
@@ -14,21 +14,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.quarkus.component.avro.it;
+package org.apache.camel.quarkus.component.avro;
-import io.quarkus.test.junit.QuarkusTest;
-import io.restassured.RestAssured;
-import org.junit.jupiter.api.Test;
+import io.quarkus.arc.runtime.BeanContainer;
+import io.quarkus.runtime.annotations.Recorder;
+import org.apache.avro.Schema;
-@QuarkusTest
-class AvroTest {
+@Recorder
+public class AvroRecorder {
- @Test
- public void loadDataformatAvro() {
- /* A simple autogenerated test */
- RestAssured.get("/avro/load/dataformat/avro")
- .then()
- .statusCode(200);
+ public void recordAvroSchemaResigtration(BeanContainer beanContainer,
String injectedFieldId, Schema schema) {
+
beanContainer.instance(AvroDataFormatProducer.class).registerAvroSchema(injectedFieldId,
schema);
}
}
diff --git
a/extensions/avro/runtime/src/main/java/org/apache/camel/quarkus/component/avro/AvroSchemaSubstitution.java
b/extensions/avro/runtime/src/main/java/org/apache/camel/quarkus/component/avro/AvroSchemaSubstitution.java
new file mode 100644
index 0000000..aac3bfc
--- /dev/null
+++
b/extensions/avro/runtime/src/main/java/org/apache/camel/quarkus/component/avro/AvroSchemaSubstitution.java
@@ -0,0 +1,57 @@
+/*
+ * 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.avro;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import io.quarkus.runtime.ObjectSubstitution;
+import org.apache.avro.Schema;
+
+/**
+ * {@code AvroSchemaSubstitution} offers a way to bypass Quarkus
+ * default serialization. This workaround has been introduced as Quarkus
default
+ * serialization used to failed with {@code org.apache.avro.Schema}.
+ */
+public class AvroSchemaSubstitution implements ObjectSubstitution<Schema,
byte[]> {
+
+ @Override
+ public byte[] serialize(Schema schema) {
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
+ try (ObjectOutputStream out = new ObjectOutputStream(baos)) {
+ out.writeObject(schema);
+ } catch (final IOException ex) {
+ throw new RuntimeException("Could not serialize " +
Schema.class.getName() + " " + schema, ex);
+ }
+ return baos.toByteArray();
+ }
+
+ @Override
+ public Schema deserialize(byte[] schemaBytes) {
+ final InputStream inputStream = new ByteArrayInputStream(schemaBytes);
+ try (ObjectInputStream in = new ObjectInputStream(inputStream)) {
+ return (Schema) in.readObject();
+ } catch (final ClassNotFoundException | IOException ex) {
+ throw new RuntimeException("Could not deserialize " +
Schema.class.getName(), ex);
+ }
+ }
+
+}
diff --git
a/extensions-jvm/avro/integration-test/src/test/java/org/apache/camel/quarkus/component/avro/it/AvroTest.java
b/extensions/avro/runtime/src/main/java/org/apache/camel/quarkus/component/avro/BuildTimeAvroDataFormat.java
similarity index 66%
copy from
extensions-jvm/avro/integration-test/src/test/java/org/apache/camel/quarkus/component/avro/it/AvroTest.java
copy to
extensions/avro/runtime/src/main/java/org/apache/camel/quarkus/component/avro/BuildTimeAvroDataFormat.java
index 78229a0..13bb6e4 100644
---
a/extensions-jvm/avro/integration-test/src/test/java/org/apache/camel/quarkus/component/avro/it/AvroTest.java
+++
b/extensions/avro/runtime/src/main/java/org/apache/camel/quarkus/component/avro/BuildTimeAvroDataFormat.java
@@ -14,21 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.quarkus.component.avro.it;
+package org.apache.camel.quarkus.component.avro;
-import io.quarkus.test.junit.QuarkusTest;
-import io.restassured.RestAssured;
-import org.junit.jupiter.api.Test;
-
-@QuarkusTest
-class AvroTest {
-
- @Test
- public void loadDataformatAvro() {
- /* A simple autogenerated test */
- RestAssured.get("/avro/load/dataformat/avro")
- .then()
- .statusCode(200);
- }
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+@Target({ ElementType.FIELD })
+@Retention(RetentionPolicy.RUNTIME)
+public @interface BuildTimeAvroDataFormat {
+ public String value();
}
diff --git
a/extensions-jvm/avro/runtime/src/main/resources/META-INF/quarkus-extension.yaml
b/extensions/avro/runtime/src/main/resources/META-INF/quarkus-extension.yaml
similarity index 90%
rename from
extensions-jvm/avro/runtime/src/main/resources/META-INF/quarkus-extension.yaml
rename to
extensions/avro/runtime/src/main/resources/META-INF/quarkus-extension.yaml
index 3eea5dc..2e25b4d 100644
---
a/extensions-jvm/avro/runtime/src/main/resources/META-INF/quarkus-extension.yaml
+++ b/extensions/avro/runtime/src/main/resources/META-INF/quarkus-extension.yaml
@@ -24,8 +24,6 @@
name: "Camel Avro"
description: "Serialize and deserialize messages using Apache Avro binary data
format"
metadata:
- unlisted: true
- guide: "https://camel.apache.org/components/latest/avro-dataformat.html"
+ guide: "https://camel.apache.org/camel-quarkus/latest/extensions/avro.html"
categories:
- "integration"
- status: "preview"
diff --git
a/extensions/avro/runtime/src/test/java/org/apache/camel/quarkus/component/avro/AvroDataFormatProducerTest.java
b/extensions/avro/runtime/src/test/java/org/apache/camel/quarkus/component/avro/AvroDataFormatProducerTest.java
new file mode 100644
index 0000000..450ebd0
--- /dev/null
+++
b/extensions/avro/runtime/src/test/java/org/apache/camel/quarkus/component/avro/AvroDataFormatProducerTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.avro;
+
+import java.lang.reflect.Field;
+
+import javax.enterprise.inject.spi.InjectionPoint;
+
+import org.apache.camel.dataformat.avro.AvroDataFormat;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class AvroDataFormatProducerTest {
+
+ private AvroDataFormatProducer instance;
+
+ private InjectionPoint mockInjectionPoint;
+ @SuppressWarnings("unused")
+ private static AvroDataFormat injectedField;
+ private Field injectedFieldMember;
+
+ @BeforeEach
+ public void setup() throws NoSuchFieldException, SecurityException {
+ instance = new AvroDataFormatProducer();
+ injectedFieldMember =
AvroDataFormatProducerTest.class.getDeclaredField("injectedField");
+ mockInjectionPoint = mock(InjectionPoint.class);
+ when(mockInjectionPoint.getMember()).thenReturn(injectedFieldMember);
+ }
+
+ @Test
+ void produceAvroDataFormatFromNonStaticFieldShouldThrow() {
+ IllegalArgumentException iaex =
assertThrows(IllegalArgumentException.class, () -> {
+ instance.produceAvroDataFormat(mockInjectionPoint);
+ });
+ assertNotNull(iaex.getMessage());
+ }
+
+}
diff --git a/extensions/pom.xml b/extensions/pom.xml
index 2f7c009..e81fb31 100644
--- a/extensions/pom.xml
+++ b/extensions/pom.xml
@@ -38,6 +38,7 @@
<module>ahc-ws</module>
<module>amqp</module>
<module>attachments</module>
+ <module>avro</module>
<module>aws-ec2</module>
<module>aws-ecs</module>
<module>aws-eks</module>
diff --git a/extensions-jvm/avro/integration-test/pom.xml
b/integration-tests/avro/pom.xml
similarity index 70%
rename from extensions-jvm/avro/integration-test/pom.xml
rename to integration-tests/avro/pom.xml
index 2cded56..083d2cb 100644
--- a/extensions-jvm/avro/integration-test/pom.xml
+++ b/integration-tests/avro/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>1.1.0-SNAPSHOT</version>
- <relativePath>../../../poms/build-parent-it/pom.xml</relativePath>
</parent>
- <artifactId>camel-quarkus-avro-integration-test</artifactId>
- <name>Camel Quarkus :: Avro :: Integration Test</name>
+ <artifactId>camel-quarkus-integration-test-avro</artifactId>
+ <name>Camel Quarkus :: Integration Tests :: Avro</name>
<description>Integration tests for Camel Quarkus Avro
extension</description>
<properties>
@@ -46,6 +45,10 @@
<artifactId>camel-quarkus-avro</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-direct</artifactId>
+ </dependency>
+ <dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
@@ -78,4 +81,33 @@
</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/avro/src/main/java/org/apache/camel/quarkus/component/avro/it/AvroResource.java
b/integration-tests/avro/src/main/java/org/apache/camel/quarkus/component/avro/it/AvroResource.java
new file mode 100644
index 0000000..1a4662d
--- /dev/null
+++
b/integration-tests/avro/src/main/java/org/apache/camel/quarkus/component/avro/it/AvroResource.java
@@ -0,0 +1,83 @@
+/*
+ * 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.avro.it;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.camel.ProducerTemplate;
+
+import static
org.apache.camel.quarkus.component.avro.it.AvroSchemaLoader.getSchema;
+
+@Path("/avro")
+@ApplicationScoped
+public class AvroResource {
+
+ @Inject
+ ProducerTemplate producerTemplate;
+
+ @Path("/genericMarshalUnmarshalUsingBuildTimeAvroDataFormat/{value}")
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String
genericMarshalUnmarshalUsingBuildTimeAvroDataFormat(@PathParam("value") String
value) {
+ GenericRecord input = new GenericData.Record(getSchema());
+ input.put("name", value);
+ Object marshalled =
producerTemplate.requestBody("direct:marshalUsingBuildTimeAvroDataFormat",
input);
+ GenericRecord output =
producerTemplate.requestBody("direct:unmarshalUsingBuildTimeAvroDataFormat",
marshalled,
+ GenericRecord.class);
+ return output.get("name").toString();
+ }
+
+ @Path("/genericMarshalUnmarshalUsingConfigureTimeAvroDataFormat/{value}")
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String
genericMarshalUsingConfigureTimeAvroDataFormat(@PathParam("value") String
value) {
+ GenericRecord input = new GenericData.Record(getSchema());
+ input.put("name", value);
+ Object marshalled =
producerTemplate.requestBody("direct:marshalUsingConfigureTimeAvroDataFormat",
input);
+ GenericRecord output =
producerTemplate.requestBody("direct:unmarshalUsingConfigureTimeAvroDataFormat",
marshalled,
+ GenericRecord.class);
+ return output.get("name").toString();
+ }
+
+ @Path("/valueMarshalUnmarshalUsingInstanceClassNameAvroDsl/{value}")
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String
valueMarshalUnmarshalUsingInstanceClassNameAvroDsl(@PathParam("value") String
value) {
+ Value input = Value.newBuilder().setValue(value).build();
+ Object marshalled =
producerTemplate.requestBody("direct:marshalUsingAvroDsl", input);
+ Value output =
producerTemplate.requestBody("direct:unmarshalUsingInstanceClassNameAvroDsl",
marshalled, Value.class);
+ return output.getValue().toString();
+ }
+
+ @Path("/valueMarshalUnmarshalUsingSchemaAvroDsl/{value}")
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String valueMarshalUnmarshalUsingSchemaAvroDsl(@PathParam("value")
String value) {
+ Value input = Value.newBuilder().setValue(value).build();
+ Object marshalled =
producerTemplate.requestBody("direct:marshalUsingAvroDsl", input);
+ Value output =
producerTemplate.requestBody("direct:unmarshalUsingSchemaAvroDsl", marshalled,
Value.class);
+ return output.getValue().toString();
+ }
+}
diff --git
a/integration-tests/avro/src/main/java/org/apache/camel/quarkus/component/avro/it/AvroRoute.java
b/integration-tests/avro/src/main/java/org/apache/camel/quarkus/component/avro/it/AvroRoute.java
new file mode 100644
index 0000000..65b32db
--- /dev/null
+++
b/integration-tests/avro/src/main/java/org/apache/camel/quarkus/component/avro/it/AvroRoute.java
@@ -0,0 +1,47 @@
+/*
+ * 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.avro.it;
+
+import javax.enterprise.context.ApplicationScoped;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.dataformat.avro.AvroDataFormat;
+import org.apache.camel.quarkus.component.avro.BuildTimeAvroDataFormat;
+
+import static
org.apache.camel.quarkus.component.avro.it.AvroSchemaLoader.getSchema;
+
+@ApplicationScoped
+public class AvroRoute extends RouteBuilder {
+
+ @BuildTimeAvroDataFormat("user.avsc")
+ AvroDataFormat buildTimeAvroDataFormat;
+
+ @Override
+ public void configure() {
+
+
from("direct:marshalUsingBuildTimeAvroDataFormat").marshal(buildTimeAvroDataFormat);
+
from("direct:unmarshalUsingBuildTimeAvroDataFormat").unmarshal(buildTimeAvroDataFormat);
+
+ AvroDataFormat configureTimeAvroDataFormat = new
AvroDataFormat(getSchema());
+
from("direct:marshalUsingConfigureTimeAvroDataFormat").marshal(configureTimeAvroDataFormat);
+
from("direct:unmarshalUsingConfigureTimeAvroDataFormat").unmarshal(configureTimeAvroDataFormat);
+
+ from("direct:marshalUsingAvroDsl").marshal().avro();
+
from("direct:unmarshalUsingInstanceClassNameAvroDsl").unmarshal().avro(Value.class.getName());
+
from("direct:unmarshalUsingSchemaAvroDsl").unmarshal().avro(Value.SCHEMA$);
+ }
+}
diff --git
a/extensions-jvm/avro/integration-test/src/test/java/org/apache/camel/quarkus/component/avro/it/AvroTest.java
b/integration-tests/avro/src/main/java/org/apache/camel/quarkus/component/avro/it/AvroSchemaLoader.java
similarity index 59%
copy from
extensions-jvm/avro/integration-test/src/test/java/org/apache/camel/quarkus/component/avro/it/AvroTest.java
copy to
integration-tests/avro/src/main/java/org/apache/camel/quarkus/component/avro/it/AvroSchemaLoader.java
index 78229a0..3741d9e 100644
---
a/extensions-jvm/avro/integration-test/src/test/java/org/apache/camel/quarkus/component/avro/it/AvroTest.java
+++
b/integration-tests/avro/src/main/java/org/apache/camel/quarkus/component/avro/it/AvroSchemaLoader.java
@@ -16,19 +16,25 @@
*/
package org.apache.camel.quarkus.component.avro.it;
-import io.quarkus.test.junit.QuarkusTest;
-import io.restassured.RestAssured;
-import org.junit.jupiter.api.Test;
+import java.io.IOException;
+import java.io.InputStream;
-@QuarkusTest
-class AvroTest {
+import org.apache.avro.Schema;
- @Test
- public void loadDataformatAvro() {
- /* A simple autogenerated test */
- RestAssured.get("/avro/load/dataformat/avro")
- .then()
- .statusCode(200);
+public class AvroSchemaLoader {
+
+ private static Schema SCHEMA;
+
+ static {
+ try (InputStream is =
Thread.currentThread().getContextClassLoader().getResourceAsStream("user.avsc"))
{
+ SCHEMA = new Schema.Parser().parse(is);
+ } catch (IOException ioex) {
+ String message = "An issue occured while loading Avro schema
resource";
+ throw new RuntimeException(message, ioex);
+ }
}
+ public static Schema getSchema() {
+ return SCHEMA;
+ }
}
diff --git
a/integration-tests/avro/src/main/java/org/apache/camel/quarkus/component/avro/it/Value.java
b/integration-tests/avro/src/main/java/org/apache/camel/quarkus/component/avro/it/Value.java
new file mode 100644
index 0000000..7b7c943
--- /dev/null
+++
b/integration-tests/avro/src/main/java/org/apache/camel/quarkus/component/avro/it/Value.java
@@ -0,0 +1,143 @@
+/*
+ * 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.
+ */
+// CHECKSTYLE:OFF
+/**
+ * Autogenerated by Avro
+ *
+ * DO NOT EDIT DIRECTLY
+ */
+package org.apache.camel.quarkus.component.avro.it;
+
+import io.quarkus.runtime.annotations.RegisterForReflection;
+import org.apache.avro.Schema;
+
+@SuppressWarnings("all")
+@RegisterForReflection
+public class Value extends org.apache.avro.specific.SpecificRecordBase
implements org.apache.avro.specific.SpecificRecord {
+ public static final org.apache.avro.Schema SCHEMA$ = new
Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Value\",\"namespace\":\"org.apache.camel.quarkus.component.avro.it\",\"fields\":[{\"name\":\"value\",\"type\":\"string\"}]}");
+ @Deprecated public java.lang.CharSequence value;
+ public org.apache.avro.Schema getSchema() { return SCHEMA$; }
+ // Used by DatumWriter. Applications should not call.
+ public java.lang.Object get(int field$) {
+ switch (field$) {
+ case 0: return value;
+ default: throw new org.apache.avro.AvroRuntimeException("Bad index");
+ }
+ }
+ // Used by DatumReader. Applications should not call.
+ @SuppressWarnings(value="unchecked")
+ public void put(int field$, java.lang.Object value$) {
+ switch (field$) {
+ case 0: value = (java.lang.CharSequence)value$; break;
+ default: throw new org.apache.avro.AvroRuntimeException("Bad index");
+ }
+ }
+
+ /**
+ * Gets the value of the 'value' field.
+ */
+ public java.lang.CharSequence getValue() {
+ return value;
+ }
+
+ /**
+ * Sets the value of the 'value' field.
+ * @param value the value to set.
+ */
+ public void setValue(java.lang.CharSequence value) {
+ this.value = value;
+ }
+
+ /** Creates a new Value RecordBuilder */
+ public static Value.Builder newBuilder() {
+ return new Value.Builder();
+ }
+
+ /** Creates a new Value RecordBuilder by copying an existing Builder */
+ public static Value.Builder newBuilder(Value.Builder other) {
+ return new Value.Builder(other);
+ }
+
+ /** Creates a new Value RecordBuilder by copying an existing Value instance
*/
+ public static Value.Builder newBuilder(Value other) {
+ return new Value.Builder(other);
+ }
+
+ /**
+ * RecordBuilder for Value instances.
+ */
+ public static class Builder extends
org.apache.avro.specific.SpecificRecordBuilderBase<Value>
+ implements org.apache.avro.data.RecordBuilder<Value> {
+
+ private java.lang.CharSequence value;
+
+ /** Creates a new Builder */
+ private Builder() {
+ super(Value.SCHEMA$);
+ }
+
+ /** Creates a Builder by copying an existing Builder */
+ private Builder(Value.Builder other) {
+ super(other);
+ }
+
+ /** Creates a Builder by copying an existing Value instance */
+ private Builder(Value other) {
+ super(Value.SCHEMA$);
+ if (isValidValue(fields()[0], other.value)) {
+ this.value = data().deepCopy(fields()[0].schema(), other.value);
+ fieldSetFlags()[0] = true;
+ }
+ }
+
+ /** Gets the value of the 'value' field */
+ public java.lang.CharSequence getValue() {
+ return value;
+ }
+
+ /** Sets the value of the 'value' field */
+ public Value.Builder setValue(java.lang.CharSequence value) {
+ validate(fields()[0], value);
+ this.value = value;
+ fieldSetFlags()[0] = true;
+ return this;
+ }
+
+ /** Checks whether the 'value' field has been set */
+ public boolean hasValue() {
+ return fieldSetFlags()[0];
+ }
+
+ /** Clears the value of the 'value' field */
+ public Value.Builder clearValue() {
+ value = null;
+ fieldSetFlags()[0] = false;
+ return this;
+ }
+
+ @Override
+ public Value build() {
+ try {
+ Value record = new Value();
+ record.value = fieldSetFlags()[0] ? this.value :
(java.lang.CharSequence) defaultValue(fields()[0]);
+ return record;
+ } catch (Exception e) {
+ throw new org.apache.avro.AvroRuntimeException(e);
+ }
+ }
+ }
+}
diff --git a/integration-tests/avro/src/main/resources/user.avsc
b/integration-tests/avro/src/main/resources/user.avsc
new file mode 100644
index 0000000..7df3a77
--- /dev/null
+++ b/integration-tests/avro/src/main/resources/user.avsc
@@ -0,0 +1,7 @@
+{"namespace": "example.avro",
+ "type": "record",
+ "name": "User",
+ "fields": [
+ {"name": "name", "type": "string"}
+ ]
+}
\ No newline at end of file
diff --git
a/extensions-jvm/avro/integration-test/src/test/java/org/apache/camel/quarkus/component/avro/it/AvroTest.java
b/integration-tests/avro/src/test/java/org/apache/camel/quarkus/component/avro/it/AvroIT.java
similarity index 70%
copy from
extensions-jvm/avro/integration-test/src/test/java/org/apache/camel/quarkus/component/avro/it/AvroTest.java
copy to
integration-tests/avro/src/test/java/org/apache/camel/quarkus/component/avro/it/AvroIT.java
index 78229a0..9ad2a4d 100644
---
a/extensions-jvm/avro/integration-test/src/test/java/org/apache/camel/quarkus/component/avro/it/AvroTest.java
+++
b/integration-tests/avro/src/test/java/org/apache/camel/quarkus/component/avro/it/AvroIT.java
@@ -16,19 +16,9 @@
*/
package org.apache.camel.quarkus.component.avro.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 AvroTest {
-
- @Test
- public void loadDataformatAvro() {
- /* A simple autogenerated test */
- RestAssured.get("/avro/load/dataformat/avro")
- .then()
- .statusCode(200);
- }
+@NativeImageTest
+class AvroIT extends AvroTest {
}
diff --git
a/extensions-jvm/avro/integration-test/src/test/java/org/apache/camel/quarkus/component/avro/it/AvroTest.java
b/integration-tests/avro/src/test/java/org/apache/camel/quarkus/component/avro/it/AvroTest.java
similarity index 50%
rename from
extensions-jvm/avro/integration-test/src/test/java/org/apache/camel/quarkus/component/avro/it/AvroTest.java
rename to
integration-tests/avro/src/test/java/org/apache/camel/quarkus/component/avro/it/AvroTest.java
index 78229a0..38ea0c0 100644
---
a/extensions-jvm/avro/integration-test/src/test/java/org/apache/camel/quarkus/component/avro/it/AvroTest.java
+++
b/integration-tests/avro/src/test/java/org/apache/camel/quarkus/component/avro/it/AvroTest.java
@@ -20,15 +20,32 @@ import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;
+import static org.hamcrest.Matchers.is;
+
@QuarkusTest
class AvroTest {
@Test
- public void loadDataformatAvro() {
- /* A simple autogenerated test */
- RestAssured.get("/avro/load/dataformat/avro")
- .then()
- .statusCode(200);
+ void genericMarshalUnmarshalUsingBuildTimeAvroDataFormatShouldSucceed() {
+
RestAssured.get("/avro/genericMarshalUnmarshalUsingBuildTimeAvroDataFormat/jack").then().statusCode(200)
+ .body(is("jack"));
+ }
+
+ @Test
+ void
genericMarshalUnmarshalUsingConfigureTimeAvroDataFormatShouldSucceed() {
+
RestAssured.get("/avro/genericMarshalUnmarshalUsingConfigureTimeAvroDataFormat/elizabeth").then().statusCode(200)
+ .body(is("elizabeth"));
+ }
+
+ @Test
+ void valueMarshalUnmarshalUsingInstanceClassNameAvroDslShouldSucceed() {
+
RestAssured.get("/avro/valueMarshalUnmarshalUsingInstanceClassNameAvroDsl/william").then().statusCode(200)
+ .body(is("william"));
+ }
+
+ @Test
+ void valueMarshalUnmarshalUsingSchemaAvroDslShouldSucceed() {
+
RestAssured.get("/avro/valueMarshalUnmarshalUsingSchemaAvroDsl/hector").then().statusCode(200).body(is("hector"));
}
}
diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml
index 6c762fa..213f573 100644
--- a/integration-tests/pom.xml
+++ b/integration-tests/pom.xml
@@ -55,6 +55,7 @@
<!-- extensions a..z; do not remove this comment, it is important when
sorting via mvn process-resources -Pformat -->
<module>activemq</module>
<module>amqp</module>
+ <module>avro</module>
<module>aws</module>
<module>aws2</module>
<module>azure</module>
diff --git a/pom.xml b/pom.xml
index 629781b..a1c762a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -347,6 +347,7 @@
<header>header.txt</header>
<excludes>
<exclude>**/*.adoc</exclude>
+ <exclude>**/*.avsc</exclude>
<exclude>**/*.csv</exclude>
<exclude>**/*.ftl</exclude>
<exclude>**/*.graphql</exclude>