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 4194d5251 Ref #503: Add camel-jackson integration test (#505)
4194d5251 is described below
commit 4194d52519783707e16faa88916572549907e4df
Author: Stefan Tataru <[email protected]>
AuthorDate: Fri Sep 27 17:48:43 2024 +0200
Ref #503: Add camel-jackson integration test (#505)
---
tests/features/camel-jackson/pom.xml | 54 +++++++++++
.../camel/test/CamelJacksonRouteSupplier.java | 106 +++++++++++++++++++++
.../karaf/camel/itest/CamelJacksonITest.java | 48 ++++++++++
tests/features/pom.xml | 1 +
4 files changed, 209 insertions(+)
diff --git a/tests/features/camel-jackson/pom.xml
b/tests/features/camel-jackson/pom.xml
new file mode 100644
index 000000000..542e91751
--- /dev/null
+++ b/tests/features/camel-jackson/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-test</artifactId>
+ <name>Apache Camel :: Karaf :: Tests :: Features :: Jackson</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ <version>${jackson2-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>${jackson2-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ <version>${jackson2-version}</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
diff --git
a/tests/features/camel-jackson/src/main/java/org/apache/karaf/camel/test/CamelJacksonRouteSupplier.java
b/tests/features/camel-jackson/src/main/java/org/apache/karaf/camel/test/CamelJacksonRouteSupplier.java
new file mode 100644
index 000000000..508935c09
--- /dev/null
+++
b/tests/features/camel-jackson/src/main/java/org/apache/karaf/camel/test/CamelJacksonRouteSupplier.java
@@ -0,0 +1,106 @@
+/*
+ * 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.assertNull;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.dataformat.JsonLibrary;
+import
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier;
+import org.apache.karaf.camel.itests.CamelRouteSupplier;
+import org.osgi.service.component.annotations.Component;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.json.JsonMapper;
+
+@Component(
+ name = "karaf-camel-jackson-test",
+ immediate = true,
+ service = CamelRouteSupplier.class
+)
+public class CamelJacksonRouteSupplier extends
AbstractCamelSingleFeatureResultMockBasedRouteSupplier {
+
+ public static final String JSON_SAMPLE_NAME = "Jack";
+ public static final int JSON_SAMPLE_AGE = 9;
+
+ @Override
+ protected boolean consumerEnabled() {
+ return false;
+ }
+
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ public static class MyData {
+ private String name;
+ private String nikname;
+ private int age;
+
+ // empty constructor is needed by default
+ public MyData() {};
+
+ // getters and setters
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getNikname() {
+ return nikname;
+ }
+
+ public void setNikname(String nikname) {
+ this.nikname = nikname;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+ }
+
+ @Override
+ protected void configureProducer(RouteBuilder builder, RouteDefinition
producerRoute) {
+ producerRoute.log("Will unmarshal: ${body}")
+ .unmarshal().json(JsonLibrary.Jackson, MyData.class)
+ .log("Unmarshal: ${body}")
+ .process(ex -> {
+ MyData data = ex.getIn().getBody(MyData.class);
+ assertEquals(JSON_SAMPLE_NAME, data.getName());
+ assertNull(data.getNikname());
+ assertEquals(JSON_SAMPLE_AGE, data.getAge());
+ })
+ .log("Will marshal: ${body}")
+ .marshal().json(JsonLibrary.Jackson)
+ .log("Marshal: ${body}")
+ .process(ex -> {
+ String data = ex.getIn().getBody(String.class);
+
+ JsonMapper jsonMapper = new JsonMapper();
+ JsonNode jsonNode = jsonMapper.readTree(data);
+ assertEquals(JSON_SAMPLE_NAME,
jsonNode.get("name").asText());
+ assertNull(jsonNode.get("nikname"));
+ assertEquals(JSON_SAMPLE_AGE, jsonNode.get("age").asInt());
+ }).toF("mock:%s", getResultMockName());
+ }
+}
\ No newline at end of file
diff --git
a/tests/features/camel-jackson/src/test/java/org/apache/karaf/camel/itest/CamelJacksonITest.java
b/tests/features/camel-jackson/src/test/java/org/apache/karaf/camel/itest/CamelJacksonITest.java
new file mode 100644
index 000000000..05ac97d23
--- /dev/null
+++
b/tests/features/camel-jackson/src/test/java/org/apache/karaf/camel/itest/CamelJacksonITest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.apache.karaf.camel.test.CamelJacksonRouteSupplier;
+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 CamelJacksonITest extends
AbstractCamelSingleFeatureResultMockBasedRouteITest {
+
+ private static final String JSON_SAMPLE = "{\"name\":\"%s\",\"age\":%d}"
+ .formatted(CamelJacksonRouteSupplier.JSON_SAMPLE_NAME,
CamelJacksonRouteSupplier.JSON_SAMPLE_AGE);
+
+ @Override
+ public String getBodyToSend() {
+ return JSON_SAMPLE;
+ }
+
+ @Override
+ public void configureMock(MockEndpoint mock) {
+ mock.expectedBodiesReceived(JSON_SAMPLE);
+ }
+
+ @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 2e7c9564d..9a33f3bb3 100644
--- a/tests/features/pom.xml
+++ b/tests/features/pom.xml
@@ -82,6 +82,7 @@
<module>camel-hazelcast</module>
<module>camel-http</module>
<module>camel-influxdb2</module>
+ <module>camel-jackson</module>
<module>camel-jacksonxml</module>
<module>camel-jcache</module>
<module>camel-jetty</module>