This is an automated email from the ASF dual-hosted git repository.

nfilotto pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karaf.git


The following commit(s) were added to refs/heads/main by this push:
     new a6789425 Ref #412: Add camel-avro integration-test (#413)
a6789425 is described below

commit a6789425a4630118f838c10e9a7144091ce15716
Author: François de Parscau <[email protected]>
AuthorDate: Wed Jul 10 09:53:53 2024 +0200

    Ref #412: Add camel-avro integration-test (#413)
---
 tests/features/camel-avro/pom.xml                  |  42 ++++++
 .../karaf/camel/test/CamelAvroRouteSupplier.java   |  56 ++++++++
 .../java/org/apache/karaf/camel/test/Value.java    | 153 +++++++++++++++++++++
 .../apache/karaf/camel/itest/CamelAvroITest.java   |  37 +++++
 tests/features/pom.xml                             |   1 +
 5 files changed, 289 insertions(+)

diff --git a/tests/features/camel-avro/pom.xml 
b/tests/features/camel-avro/pom.xml
new file mode 100644
index 00000000..4bac7a15
--- /dev/null
+++ b/tests/features/camel-avro/pom.xml
@@ -0,0 +1,42 @@
+<?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.karaf</groupId>
+        <artifactId>camel-karaf-features-test</artifactId>
+        <version>4.6.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>camel-avro-test</artifactId>
+    <name>Apache Camel :: Karaf :: Tests :: Features :: Avro</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-avro</artifactId>
+            <version>${camel-version}</version>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file
diff --git 
a/tests/features/camel-avro/src/main/java/org/apache/karaf/camel/test/CamelAvroRouteSupplier.java
 
b/tests/features/camel-avro/src/main/java/org/apache/karaf/camel/test/CamelAvroRouteSupplier.java
new file mode 100644
index 00000000..533e8f5c
--- /dev/null
+++ 
b/tests/features/camel-avro/src/main/java/org/apache/karaf/camel/test/CamelAvroRouteSupplier.java
@@ -0,0 +1,56 @@
+/*
+ * 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.karaf.camel.test;
+
+import static org.apache.camel.builder.Builder.constant;
+
+import java.io.IOException;
+import java.util.function.Function;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.dataformat.avro.AvroDataFormat;
+import 
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier;
+import org.osgi.service.component.annotations.Component;
+
+
+@Component(
+        name = "karaf-camel-avro-test",
+        immediate = true,
+        service = CamelAvroRouteSupplier.class
+)
+public class CamelAvroRouteSupplier extends 
AbstractCamelSingleFeatureResultMockBasedRouteSupplier {
+
+    @Override
+    protected Function<RouteBuilder, RouteDefinition> consumerRoute() {
+        try (AvroDataFormat adf = new AvroDataFormat(Value.SCHEMA$)) {
+            Value input = Value.newBuilder().setValue("OK").build();
+            return builder -> builder.from("timer://testTimer?repeatCount=1")
+                    .setBody(constant(input))
+                    .marshal(adf)
+                    .unmarshal(adf)
+                    .log("received message ${body}");
+        } catch (IOException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    @Override
+    protected boolean producerEnabled() {
+        return false;
+    }
+}
+
diff --git 
a/tests/features/camel-avro/src/main/java/org/apache/karaf/camel/test/Value.java
 
b/tests/features/camel-avro/src/main/java/org/apache/karaf/camel/test/Value.java
new file mode 100644
index 00000000..cb771477
--- /dev/null
+++ 
b/tests/features/camel-avro/src/main/java/org/apache/karaf/camel/test/Value.java
@@ -0,0 +1,153 @@
+/*
+ * 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.
+ */
+/**
+ * Autogenerated by Avro
+ *
+ * DO NOT EDIT DIRECTLY
+ */
+package org.apache.karaf.camel.test;
+
+@SuppressWarnings("all")
+public class Value extends org.apache.avro.specific.SpecificRecordBase 
implements org.apache.avro.specific.SpecificRecord {
+    public static final org.apache.avro.Schema SCHEMA$ = 
org.apache.avro.Schema.parse(
+            
"{\"type\":\"record\",\"name\":\"Value\",\"namespace\":\"org.apache.camel.dataformat.avro.example\",\"fields\":[{\"name\":\"value\",\"type\":\"string\"}]}");
+    @Deprecated
+    public CharSequence value;
+
+    public org.apache.avro.Schema getSchema() {
+        return SCHEMA$;
+    }
+
+    // Used by DatumWriter.  Applications should not call.
+    public 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$, Object value$) {
+        switch (field$) {
+            case 0:
+                value = (CharSequence) value$;
+                break;
+            default:
+                throw new org.apache.avro.AvroRuntimeException("Bad index");
+        }
+    }
+
+    /**
+     * Gets the value of the 'value' field.
+     */
+    public CharSequence getValue() {
+        return value;
+    }
+
+    /**
+     * Sets the value of the 'value' field.
+     *
+     * @param value the value to set.
+     */
+    public void setValue(CharSequence value) {
+        this.value = value;
+    }
+
+    /** Creates a new Value RecordBuilder */
+    public static Builder newBuilder() {
+        return new Builder();
+    }
+
+    /** Creates a new Value RecordBuilder by copying an existing Builder */
+    public static Builder newBuilder(
+            Builder other) {
+        return new Builder(other);
+    }
+
+    /** Creates a new Value RecordBuilder by copying an existing Value 
instance */
+    public static Builder newBuilder(
+            Value other) {
+        return new 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 CharSequence value;
+
+        /** Creates a new Builder */
+        private Builder() {
+            super(Value.SCHEMA$);
+        }
+
+        /** Creates a Builder by copying an existing Builder */
+        private Builder(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 CharSequence getValue() {
+            return value;
+        }
+
+        /** Sets the value of the 'value' field */
+        public Builder setValue(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 Builder clearValue() {
+            value = null;
+            fieldSetFlags()[0] = false;
+            return this;
+        }
+
+        @Override
+        public Value build() {
+            try {
+                Value record = new Value();
+                record.value = fieldSetFlags()[0] ? this.value : 
(CharSequence) defaultValue(fields()[0]);
+                return record;
+            } catch (Exception e) {
+                throw new org.apache.avro.AvroRuntimeException(e);
+            }
+        }
+    }
+}
diff --git 
a/tests/features/camel-avro/src/test/java/org/apache/karaf/camel/itest/CamelAvroITest.java
 
b/tests/features/camel-avro/src/test/java/org/apache/karaf/camel/itest/CamelAvroITest.java
new file mode 100644
index 00000000..4e55f583
--- /dev/null
+++ 
b/tests/features/camel-avro/src/test/java/org/apache/karaf/camel/itest/CamelAvroITest.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed 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.karaf.camel.itest;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import 
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteITest;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class CamelAvroITest extends 
AbstractCamelSingleFeatureResultMockBasedRouteITest {
+
+    @Override
+    public void configureMock(MockEndpoint mock) {
+        mock.expectedBodiesReceived("{\"value\": \"OK\"}");
+    }
+
+    @Test
+    public void testResultMock() throws Exception {
+        assertMockEndpointsSatisfied();
+    }
+}
\ No newline at end of file
diff --git a/tests/features/pom.xml b/tests/features/pom.xml
index 2122114a..51327be2 100644
--- a/tests/features/pom.xml
+++ b/tests/features/pom.xml
@@ -43,6 +43,7 @@
         <module>camel-as2</module>
         <module>camel-asn1</module>
         <module>camel-atom</module>
+        <module>camel-avro</module>
         <module>camel-aws2-iam</module>
         <module>camel-aws2-s3</module>
         <module>camel-aws2-ses</module>

Reply via email to