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 5a22facd5 Ref #514: Add jaxb integration test (#515)
5a22facd5 is described below
commit 5a22facd569ef2b2336c6cf45a19aa4a3e14e830
Author: Stefan Tataru <[email protected]>
AuthorDate: Thu Oct 10 18:02:39 2024 +0200
Ref #514: Add jaxb integration test (#515)
---
core/camel-xml-jaxp/pom.xml | 1 +
features/src/main/feature/camel-features.xml | 8 +-
pom.xml | 1 +
tests/features/camel-jackson/pom.xml | 10 --
.../camel/test/CamelJacksonRouteSupplier.java | 24 ++---
tests/features/camel-jacksonxml/pom.xml | 15 ---
.../camel/test/CamelJacksonxmlRouteSupplier.java | 24 ++---
.../features/{camel-jackson => camel-jaxb}/pom.xml | 24 ++---
.../karaf/camel/test/CamelJaxbRouteSupplier.java | 102 +++++++++++++++++++++
.../apache/karaf/camel/itest/CamelJaxbITest.java | 46 ++++++++++
tests/features/pom.xml | 1 +
11 files changed, 177 insertions(+), 79 deletions(-)
diff --git a/core/camel-xml-jaxp/pom.xml b/core/camel-xml-jaxp/pom.xml
index f3590831d..c494936ae 100644
--- a/core/camel-xml-jaxp/pom.xml
+++ b/core/camel-xml-jaxp/pom.xml
@@ -39,6 +39,7 @@
<camel.osgi.import>
*
</camel.osgi.import>
+
<camel.osgi.spi.consumer>javax.xml.stream.XMLInputFactory#newInstance()</camel.osgi.spi.consumer>
</properties>
<dependencies>
diff --git a/features/src/main/feature/camel-features.xml
b/features/src/main/feature/camel-features.xml
index 95bf80bfd..8df27b5ff 100644
--- a/features/src/main/feature/camel-features.xml
+++ b/features/src/main/feature/camel-features.xml
@@ -62,9 +62,10 @@
<feature name="jaxb-runtime" version="${jaxb-core-version}">
<feature version="[4,5)">jakarta-xml-bind</feature>
- <bundle
dependency="true">mvn:com.sun.xml.bind/jaxb-core/${jaxb-core-version}</bundle>
- <bundle
dependency="true">mvn:com.sun.xml.bind/jaxb-impl/${jaxb-impl-version}</bundle>
- <bundle
dependency="true">mvn:com.sun.xml.bind/jaxb-osgi/${jaxb-osgi-version}</bundle>
+ <bundle
dependency="true">mvn:com.sun.istack/istack-commons-runtime/${auto-detect-version}</bundle>
+ <bundle
dependency="true">mvn:org.glassfish.jaxb/jaxb-core/${glassfish-jaxb-runtime-version}</bundle>
+ <bundle
dependency='true'>mvn:org.glassfish.jaxb/jaxb-runtime/${glassfish-jaxb-runtime-version}</bundle>
+
<bundle>mvn:org.glassfish.hk2/osgi-resource-locator/${osgi-resource-locator-version}</bundle>
</feature>
<feature name="activation-runtime" version="${angus-activation-version}">
@@ -1618,6 +1619,7 @@
<bundle>mvn:org.apache.camel.karaf/camel-javascript/${project.version}</bundle>
</feature>
<feature name='camel-jaxb' version='${project.version}' start-level='50'>
+ <feature prerequisite="true">spifly</feature>
<feature version='${camel-osgi-version-range}'>camel-core</feature>
<bundle>mvn:org.apache.camel.karaf/camel-jaxb/${project.version}</bundle>
</feature>
diff --git a/pom.xml b/pom.xml
index 12f90507a..593833fc9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -730,6 +730,7 @@
<Provide-Capability>${camel.osgi.provide.capability}</Provide-Capability>
<Require-Capability>${camel.osgi.require.capability}</Require-Capability>
<Export-Service>${camel.osgi.export.service}</Export-Service>
+ <SPI-Consumer>${camel.osgi.spi.consumer}</SPI-Consumer>
<_failok>${camel.osgi.failok}</_failok>
<_versionpolicy>[$(version;==;$(@)),$(version;+;$(@)))</_versionpolicy>
<_removeheaders>Ignore-Package,Include-Resource,Private-Package,Embed-Dependency
diff --git a/tests/features/camel-jackson/pom.xml
b/tests/features/camel-jackson/pom.xml
index 542e91751..a0a91ef5e 100644
--- a/tests/features/camel-jackson/pom.xml
+++ b/tests/features/camel-jackson/pom.xml
@@ -35,16 +35,6 @@
<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>
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
index 508935c09..30050eb09 100644
---
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
@@ -26,8 +26,6 @@ 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",
@@ -47,7 +45,7 @@ public class CamelJacksonRouteSupplier extends
AbstractCamelSingleFeatureResultM
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class MyData {
private String name;
- private String nikname;
+ private String nickname;
private int age;
// empty constructor is needed by default
@@ -62,12 +60,12 @@ public class CamelJacksonRouteSupplier extends
AbstractCamelSingleFeatureResultM
this.name = name;
}
- public String getNikname() {
- return nikname;
+ public String getNickname() {
+ return nickname;
}
- public void setNikname(String nikname) {
- this.nikname = nikname;
+ public void setNickname(String nickname) {
+ this.nickname = nickname;
}
public int getAge() {
@@ -87,20 +85,12 @@ public class CamelJacksonRouteSupplier extends
AbstractCamelSingleFeatureResultM
.process(ex -> {
MyData data = ex.getIn().getBody(MyData.class);
assertEquals(JSON_SAMPLE_NAME, data.getName());
- assertNull(data.getNikname());
+ assertNull(data.getNickname());
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());
+ .toF("mock:%s", getResultMockName());
}
}
\ No newline at end of file
diff --git a/tests/features/camel-jacksonxml/pom.xml
b/tests/features/camel-jacksonxml/pom.xml
index 83449eb7a..df20aa3a3 100644
--- a/tests/features/camel-jacksonxml/pom.xml
+++ b/tests/features/camel-jacksonxml/pom.xml
@@ -35,25 +35,10 @@
<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>
- <dependency>
- <groupId>com.fasterxml.jackson.dataformat</groupId>
- <artifactId>jackson-dataformat-xml</artifactId>
- <version>${jackson2-version}</version>
- </dependency>
</dependencies>
</project>
\ No newline at end of file
diff --git
a/tests/features/camel-jacksonxml/src/main/java/org/apache/karaf/camel/test/CamelJacksonxmlRouteSupplier.java
b/tests/features/camel-jacksonxml/src/main/java/org/apache/karaf/camel/test/CamelJacksonxmlRouteSupplier.java
index 6178a02b9..3790798a3 100644
---
a/tests/features/camel-jacksonxml/src/main/java/org/apache/karaf/camel/test/CamelJacksonxmlRouteSupplier.java
+++
b/tests/features/camel-jacksonxml/src/main/java/org/apache/karaf/camel/test/CamelJacksonxmlRouteSupplier.java
@@ -25,8 +25,6 @@ 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.dataformat.xml.XmlMapper;
@Component(
name = "karaf-camel-jacksonxml-test",
@@ -46,7 +44,7 @@ public class CamelJacksonxmlRouteSupplier extends
AbstractCamelSingleFeatureResu
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class MyData {
private String name;
- private String nikname;
+ private String nickname;
private int age;
// empty constructor is needed by default
@@ -62,12 +60,12 @@ public class CamelJacksonxmlRouteSupplier extends
AbstractCamelSingleFeatureResu
this.name = name;
}
- public String getNikname() {
- return nikname;
+ public String getNickname() {
+ return nickname;
}
- public void setNikname(String nikname) {
- this.nikname = nikname;
+ public void setNickname(String nickname) {
+ this.nickname = nickname;
}
public int getAge() {
@@ -87,20 +85,12 @@ public class CamelJacksonxmlRouteSupplier extends
AbstractCamelSingleFeatureResu
.process(ex -> {
MyData data = ex.getIn().getBody(MyData.class);
assertEquals(XML_SAMPLE_NAME, data.getName());
- assertNull(data.getNikname());
+ assertNull(data.getNickname());
assertEquals(XML_SAMPLE_AGE, data.getAge());
})
.log("Will marshal: ${body}")
.marshal().jacksonXml()
.log("Marshal: ${body}")
- .process(ex -> {
- String data = ex.getIn().getBody(String.class);
-
- XmlMapper xmlMapper = new XmlMapper();
- JsonNode jsonNode = xmlMapper.readTree(data);
- assertEquals(XML_SAMPLE_NAME, jsonNode.get("name").asText());
- assertNull(jsonNode.get("nikname"));
- assertEquals(XML_SAMPLE_AGE, jsonNode.get("age").asInt());
- }).toF("mock:%s", getResultMockName());
+ .toF("mock:%s", getResultMockName());
}
}
\ No newline at end of file
diff --git a/tests/features/camel-jackson/pom.xml
b/tests/features/camel-jaxb/pom.xml
similarity index 67%
copy from tests/features/camel-jackson/pom.xml
copy to tests/features/camel-jaxb/pom.xml
index 542e91751..fc60896ff 100644
--- a/tests/features/camel-jackson/pom.xml
+++ b/tests/features/camel-jaxb/pom.xml
@@ -27,28 +27,18 @@
<version>4.8.0-SNAPSHOT</version>
</parent>
- <artifactId>camel-jackson-test</artifactId>
- <name>Apache Camel :: Karaf :: Tests :: Features :: Jackson</name>
-
- <dependencies>
+ <artifactId>camel-jaxb-test</artifactId>
+ <name>Apache Camel :: Karaf :: Tests :: Features :: Jaxb</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>
+ <groupId>jakarta.xml.bind</groupId>
+ <artifactId>jakarta.xml.bind-api</artifactId>
+ <version>${jakarta-xml-bind-api-version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
diff --git
a/tests/features/camel-jaxb/src/main/java/org/apache/karaf/camel/test/CamelJaxbRouteSupplier.java
b/tests/features/camel-jaxb/src/main/java/org/apache/karaf/camel/test/CamelJaxbRouteSupplier.java
new file mode 100644
index 000000000..640352f1c
--- /dev/null
+++
b/tests/features/camel-jaxb/src/main/java/org/apache/karaf/camel/test/CamelJaxbRouteSupplier.java
@@ -0,0 +1,102 @@
+/*
+ * 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.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.dataformat.JaxbDataFormat;
+import
org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier;
+import org.apache.karaf.camel.itests.CamelRouteSupplier;
+import org.osgi.service.component.annotations.Component;
+
+import jakarta.xml.bind.annotation.XmlAccessType;
+import jakarta.xml.bind.annotation.XmlAccessorType;
+import jakarta.xml.bind.annotation.XmlElement;
+import jakarta.xml.bind.annotation.XmlRootElement;
+
+@Component(
+ name = "karaf-camel-jaxb-test",
+ immediate = true,
+ service = CamelRouteSupplier.class
+)
+public class CamelJaxbRouteSupplier extends
AbstractCamelSingleFeatureResultMockBasedRouteSupplier {
+
+ public static final String JAXB_BEAN = "jaxbBean";
+ public static final String XML_SAMPLE_NAME = "Jax";
+ public static final int XML_SAMPLE_AGE = 33;
+
+ @Override
+ protected boolean consumerEnabled() {
+ return false;
+ }
+
+ @Override
+ public void configure(CamelContext context) {
+ JaxbDataFormat jaxb = new JaxbDataFormat();
+ jaxb.setContextPath(MyData.class.getName()); //
org.apache.karaf.camel.test.CamelJaxbRouteSupplier$MyData
+ jaxb.setContextPathIsClassName(Boolean.TRUE.toString());
+ jaxb.setPrettyPrint(Boolean.FALSE.toString());
+ jaxb.setFragment(Boolean.TRUE.toString()); // don't generate the XML
declaration header
+
+ context.getRegistry().bind(JAXB_BEAN, jaxb);
+ }
+
+ @Override
+ protected void configureProducer(RouteBuilder builder, RouteDefinition
producerRoute) {
+ producerRoute.log("Will unmarshal: ${body}")
+ .unmarshal(JAXB_BEAN)
+ .log("Unmarshal: ${body}")
+ .process(ex -> {
+ MyData data = ex.getIn().getBody(MyData.class);
+ assertEquals(XML_SAMPLE_NAME, data.getName());
+ assertNull(data.getNickname());
+ assertEquals(XML_SAMPLE_AGE, data.getAge());
+ }).log("Will marshal: ${body}")
+ .marshal(JAXB_BEAN)
+ .log("Marshal: ${body}")
+ .toF("mock:%s", getResultMockName());
+ }
+
+ @XmlRootElement(name = "MyData")
+ @XmlAccessorType(XmlAccessType.FIELD)
+ public static class MyData {
+
+ @XmlElement(required = true)
+ private String name;
+
+ @XmlElement(required = false)
+ private String nickname;
+
+ @XmlElement(required = true)
+ private int age;
+
+ public String getName() {
+ return name;
+ }
+
+ public String getNickname() {
+ return nickname;
+ }
+
+ public int getAge() {
+ return age;
+ }
+ }
+}
\ No newline at end of file
diff --git
a/tests/features/camel-jaxb/src/test/java/org/apache/karaf/camel/itest/CamelJaxbITest.java
b/tests/features/camel-jaxb/src/test/java/org/apache/karaf/camel/itest/CamelJaxbITest.java
new file mode 100644
index 000000000..28ef0afb0
--- /dev/null
+++
b/tests/features/camel-jaxb/src/test/java/org/apache/karaf/camel/itest/CamelJaxbITest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.test.CamelJaxbRouteSupplier;
+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 CamelJaxbITest extends
AbstractCamelSingleFeatureResultMockBasedRouteITest {
+
+ private static final String XML_SAMPLE =
"<MyData><name>%s</name><age>%d</age></MyData>"
+ .formatted(CamelJaxbRouteSupplier.XML_SAMPLE_NAME,
CamelJaxbRouteSupplier.XML_SAMPLE_AGE);
+
+ @Override
+ public String getBodyToSend() {
+ return XML_SAMPLE;
+ }
+
+ @Override
+ public void configureMock(MockEndpoint mock) {
+ mock.expectedBodiesReceived(XML_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 c4486ec65..78bed9dac 100644
--- a/tests/features/pom.xml
+++ b/tests/features/pom.xml
@@ -86,6 +86,7 @@
<module>camel-jackson-avro</module>
<module>camel-jackson-protobuf</module>
<module>camel-jacksonxml</module>
+ <module>camel-jaxb</module>
<module>camel-jcache</module>
<module>camel-jetty</module>
<module>camel-jms</module>