-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase JAXB extension test coverage
Fixes #3896
- Loading branch information
1 parent
198dc71
commit ffd0c48
Showing
25 changed files
with
1,695 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
=== Native mode `ObjectFactory` instantiation of non-JAXB annotated classes | ||
|
||
When performing JAXB marshal operations with a custom `ObjectFactory` to instantiate POJO classes that do not have JAXB annotations, | ||
you must register those POJO classes for reflection in order for them to be instantiated in native mode. E.g via the `@RegisterForReflection` | ||
annotation or configuration property `quarkus.camel.native.reflection.include-patterns`. | ||
|
||
Refer to the xref:user-guide/native-mode.adoc#reflection[Native mode] user guide for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...ation-tests/jaxb/src/main/java/org/apache/camel/quarkus/component/jaxb/it/JaxbHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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.jaxb.it; | ||
|
||
import javax.json.Json; | ||
import javax.json.JsonObject; | ||
|
||
import org.apache.camel.quarkus.component.jaxb.it.model.Person; | ||
|
||
public final class JaxbHelper { | ||
|
||
private JaxbHelper() { | ||
// Utility class | ||
} | ||
|
||
public static JsonObject personToJson(Person person) { | ||
return Json.createObjectBuilder() | ||
.add("firstName", person.getFirstName()) | ||
.add("lastName", person.getLastName()) | ||
.add("age", person.getAge()) | ||
.build(); | ||
} | ||
} |
130 changes: 130 additions & 0 deletions
130
...on-tests/jaxb/src/main/java/org/apache/camel/quarkus/component/jaxb/it/JaxbProducers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* 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.jaxb.it; | ||
|
||
import java.util.Map; | ||
|
||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
import javax.xml.bind.Marshaller; | ||
import javax.xml.namespace.QName; | ||
|
||
import org.apache.camel.converter.jaxb.JaxbDataFormat; | ||
import org.apache.camel.quarkus.component.jaxb.it.model.namespaced.NamespacedPerson; | ||
import org.apache.camel.quarkus.component.jaxb.it.model.partial.PartClassPerson; | ||
import org.apache.camel.quarkus.component.jaxb.it.model.pojo.PojoPerson; | ||
import org.apache.camel.quarkus.component.jaxb.it.model.simple.SimplePerson; | ||
import org.apache.camel.quarkus.component.jaxb.it.writer.CustomXmlStreamWriter; | ||
|
||
public class JaxbProducers { | ||
|
||
@Singleton | ||
@Named("jaxbDefault") | ||
public JaxbDataFormat defaultJaxbDataFormat() { | ||
JaxbDataFormat dataFormat = new JaxbDataFormat(); | ||
dataFormat.setContextPath(SimplePerson.class.getPackageName()); | ||
dataFormat.setFragment(true); | ||
dataFormat.setIgnoreJAXBElement(false); | ||
dataFormat.setPrettyPrint(false); | ||
dataFormat.setSchema("classpath:person.xsd"); | ||
dataFormat.setSchemaSeverityLevel(2); | ||
return dataFormat; | ||
} | ||
|
||
@Singleton | ||
@Named("jaxbWithNamespacePrefix") | ||
public JaxbDataFormat jaxbDataFormatWithNamespacePrefix() { | ||
JaxbDataFormat dataFormat = new JaxbDataFormat(); | ||
dataFormat.setContextPath(NamespacedPerson.class.getPackageName()); | ||
dataFormat.setNamespacePrefix(Map.of("https://example.com/a", "test")); | ||
return dataFormat; | ||
} | ||
|
||
@Singleton | ||
@Named("jaxbWithEncoding") | ||
public JaxbDataFormat jaxbDataFormatWithCustomCharset() { | ||
JaxbDataFormat dataFormat = new JaxbDataFormat(); | ||
dataFormat.setContextPath(SimplePerson.class.getPackageName()); | ||
dataFormat.setEncoding("ISO-8859-1"); | ||
dataFormat.setFilterNonXmlChars(true); | ||
return dataFormat; | ||
} | ||
|
||
@Singleton | ||
@Named("jaxbWithMustBeJAXBElementFalse") | ||
public JaxbDataFormat jaxbDataFormatWithMustBeJAXBElementFalse() { | ||
JaxbDataFormat dataFormat = new JaxbDataFormat(); | ||
dataFormat.setMustBeJAXBElement(false); | ||
return dataFormat; | ||
} | ||
|
||
@Singleton | ||
@Named("jaxbWithPartClass") | ||
public JaxbDataFormat jaxbWithPartClass() { | ||
JaxbDataFormat dataFormat = new JaxbDataFormat(); | ||
dataFormat.setContextPath(PartClassPerson.class.getPackageName()); | ||
dataFormat.setPartClass(PartClassPerson.class); | ||
dataFormat.setPartNamespace(new QName(PartClassPerson.NAMESPACE, "person")); | ||
return dataFormat; | ||
} | ||
|
||
@Singleton | ||
@Named("jaxbWithIgnoreElement") | ||
public JaxbDataFormat jaxbWithIgnoreElement() { | ||
JaxbDataFormat dataFormat = new JaxbDataFormat(); | ||
dataFormat.setContextPath(PartClassPerson.class.getPackageName()); | ||
dataFormat.setIgnoreJAXBElement(false); | ||
dataFormat.setPartClass(PartClassPerson.class); | ||
dataFormat.setPartNamespace(new QName(PartClassPerson.NAMESPACE, "person")); | ||
return dataFormat; | ||
} | ||
|
||
@Singleton | ||
@Named("jaxbWithCustomProperties") | ||
public JaxbDataFormat jaxbWithCustomProperties() { | ||
String packages = String.format("%s:%s", | ||
SimplePerson.class.getPackageName(), | ||
NamespacedPerson.class.getPackageName()); | ||
JaxbDataFormat dataFormat = new JaxbDataFormat(packages); | ||
dataFormat.setJaxbProviderProperties(Map.of(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE)); | ||
return dataFormat; | ||
} | ||
|
||
@Singleton | ||
@Named("jaxbWithCustomStreamWriter") | ||
public JaxbDataFormat jaxbWithCustomStreamWriter() { | ||
JaxbDataFormat dataFormat = new JaxbDataFormat(SimplePerson.class.getPackageName()); | ||
dataFormat.setXmlStreamWriterWrapper(new CustomXmlStreamWriter()); | ||
return dataFormat; | ||
} | ||
|
||
@Singleton | ||
@Named("jaxbWithoutObjectFactory") | ||
public JaxbDataFormat jaxbWithoutObjectFactory() { | ||
JaxbDataFormat dataFormat = new JaxbDataFormat(PojoPerson.class.getPackageName()); | ||
dataFormat.setObjectFactory(false); | ||
return dataFormat; | ||
} | ||
|
||
@Singleton | ||
@Named("jaxbWithNoNamespaceSchemaLocation") | ||
public JaxbDataFormat jaxbWithNoNamespaceSchemaLocation() { | ||
JaxbDataFormat dataFormat = new JaxbDataFormat(SimplePerson.class.getPackageName()); | ||
dataFormat.setNoNamespaceSchemaLocation("person-no-namespace.xsd"); | ||
return dataFormat; | ||
} | ||
} |
Oops, something went wrong.