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 ffb7977a2 Ref #518: Add camel-jackson-protobuf integration test (#519)
ffb7977a2 is described below

commit ffb7977a287850441904309606935ab6ec82b477
Author: Stefan Tataru <stefan.tatar...@gmail.com>
AuthorDate: Fri Oct 4 08:04:44 2024 +0200

    Ref #518: Add camel-jackson-protobuf integration test (#519)
---
 features/src/main/feature/camel-features.xml       |   2 +-
 tests/features/camel-jackson-protobuf/pom.xml      |  54 ++++++++++
 .../test/CamelJacksonProtobufRouteSupplier.java    | 113 +++++++++++++++++++++
 .../camel/itest/CamelJacksonProtobufITest.java     |  39 +++++++
 tests/features/pom.xml                             |   1 +
 5 files changed, 208 insertions(+), 1 deletion(-)

diff --git a/features/src/main/feature/camel-features.xml 
b/features/src/main/feature/camel-features.xml
index c8f7d3243..95bf80bfd 100644
--- a/features/src/main/feature/camel-features.xml
+++ b/features/src/main/feature/camel-features.xml
@@ -1598,7 +1598,7 @@
     </feature>
     <feature name='camel-jackson-protobuf' version='${project.version}' 
start-level='50'>
         <feature version='${camel-osgi-version-range}'>camel-jackson</feature>
-        <bundle 
dependency='true'>mvn:com.fasterxml.jackson.dataformat/jackson-dataformat-protobuf/${auto-detect-version}</bundle>
+        <bundle 
dependency='true'>mvn:com.fasterxml.jackson.dataformat/jackson-dataformat-protobuf/${jackson2-version}</bundle>
         
<bundle>mvn:org.apache.camel.karaf/camel-jackson-protobuf/${project.version}</bundle>
     </feature>
     <feature name='camel-jacksonxml' version='${project.version}' 
start-level='50'>
diff --git a/tests/features/camel-jackson-protobuf/pom.xml 
b/tests/features/camel-jackson-protobuf/pom.xml
new file mode 100644
index 000000000..8843422b8
--- /dev/null
+++ b/tests/features/camel-jackson-protobuf/pom.xml
@@ -0,0 +1,54 @@
+<?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.8.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>camel-jackson-protobuf-test</artifactId>
+    <name>Apache Camel :: Karaf :: Tests :: Features :: Jackson Protobuf</name>
+
+       <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-jackson</artifactId>
+            <version>${camel-version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+            <version>${jackson2-version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.dataformat</groupId>
+            <artifactId>jackson-dataformat-protobuf</artifactId>
+            <version>${jackson2-version}</version>
+        </dependency>
+    </dependencies>
+</project>
\ No newline at end of file
diff --git 
a/tests/features/camel-jackson-protobuf/src/main/java/org/apache/karaf/camel/test/CamelJacksonProtobufRouteSupplier.java
 
b/tests/features/camel-jackson-protobuf/src/main/java/org/apache/karaf/camel/test/CamelJacksonProtobufRouteSupplier.java
new file mode 100644
index 000000000..81ba857b9
--- /dev/null
+++ 
b/tests/features/camel-jackson-protobuf/src/main/java/org/apache/karaf/camel/test/CamelJacksonProtobufRouteSupplier.java
@@ -0,0 +1,113 @@
+/*
+ * 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.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.dataformat.protobuf.ProtobufMapper;
+import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jackson.SchemaResolver;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.dataformat.ProtobufDataFormat;
+import org.apache.camel.model.dataformat.ProtobufLibrary;
+import 
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier;
+import org.apache.karaf.camel.itests.CamelRouteSupplier;
+import org.osgi.service.component.annotations.Component;
+
+@Component(
+        name = "karaf-camel-jackson-protobuf-test",
+        immediate = true,
+        service = CamelRouteSupplier.class
+)
+public class CamelJacksonProtobufRouteSupplier extends 
AbstractCamelSingleFeatureResultMockBasedRouteSupplier {
+
+    public static final String PROTOBUF_BEAN = "protobufBean";
+    public static final String PROTOBUF_SAMPLE_NAME = "Jack Proto";
+    public static final int PROTOBUF_SAMPLE_AGE = 9;
+
+    @Override
+    protected boolean consumerEnabled() {
+        return false;
+    }
+
+    @Override
+    public void configure(CamelContext context) {
+        ProtobufDataFormat protobuf = new ProtobufDataFormat();
+        protobuf.setLibrary(ProtobufLibrary.Jackson);
+        protobuf.setUnmarshalType(JsonNode.class);
+        protobuf.setAutoDiscoverSchemaResolver(Boolean.TRUE.toString());
+        context.getRegistry().bind(PROTOBUF_BEAN, protobuf);
+
+        try {
+            ProtobufSchema schema = new 
ProtobufMapper().generateSchemaFor(MyData.class);
+            SchemaResolver resolver = ex -> schema;
+            context.getRegistry().bind("schema-resolver", 
SchemaResolver.class, resolver);
+        } catch (JsonMappingException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    protected void configureProducer(RouteBuilder builder, RouteDefinition 
producerRoute) {
+        producerRoute.setBody(ex -> new MyData(PROTOBUF_SAMPLE_NAME, 
PROTOBUF_SAMPLE_AGE))
+                .log("Will marshal: ${body}")
+                .marshal(PROTOBUF_BEAN)
+                .log("Marshal: ${body}")
+                .process(ex -> {
+                    byte[] protobufData = ex.getIn().getBody(byte[].class);
+                    assertNotNull(protobufData);
+                    assertTrue(protobufData.length > 0);
+                })
+                .toF("mock:%s", getResultMockName())
+                .log("Will unmarshal: ${body}")
+                .unmarshal(PROTOBUF_BEAN)
+                .log("Unmarshal: ${body}")
+                .process(ex -> {
+                    JsonNode data = ex.getIn().getBody(JsonNode.class);
+                    assertEquals(PROTOBUF_SAMPLE_NAME, 
data.get("name").asText());
+                    assertEquals(PROTOBUF_SAMPLE_AGE, data.get("age").asInt());
+                })
+                .toF("mock:%s", getResultMockName());
+    }
+
+    public static class MyData {
+
+        private final String name;
+
+        private final int age;
+
+        public MyData(String name, int age) {
+            this.name = name;
+            this.age = age;
+        }
+
+        // getters are needed for marshall
+
+        public String getName() {
+            return name;
+        }
+
+        public int getAge() {
+            return age;
+        }
+    }
+}
\ No newline at end of file
diff --git 
a/tests/features/camel-jackson-protobuf/src/test/java/org/apache/karaf/camel/itest/CamelJacksonProtobufITest.java
 
b/tests/features/camel-jackson-protobuf/src/test/java/org/apache/karaf/camel/itest/CamelJacksonProtobufITest.java
new file mode 100644
index 000000000..31d6df74c
--- /dev/null
+++ 
b/tests/features/camel-jackson-protobuf/src/test/java/org/apache/karaf/camel/itest/CamelJacksonProtobufITest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.apache.karaf.camel.itests.CamelKarafTestHint;
+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;
+
+@CamelKarafTestHint
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class CamelJacksonProtobufITest extends 
AbstractCamelSingleFeatureResultMockBasedRouteITest {
+
+    @Override
+    public void configureMock(MockEndpoint mock) {
+        mock.expectedMessageCount(2);
+    }
+
+    @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 608d66c25..c4486ec65 100644
--- a/tests/features/pom.xml
+++ b/tests/features/pom.xml
@@ -84,6 +84,7 @@
         <module>camel-influxdb2</module>
         <module>camel-jackson</module>
         <module>camel-jackson-avro</module>
+        <module>camel-jackson-protobuf</module>
         <module>camel-jacksonxml</module>
         <module>camel-jcache</module>
         <module>camel-jetty</module>

Reply via email to