-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31940 from gnieser/jaxbcontext-excludes
WIP - Add more options to exclude classes from the default JAXBContext
- Loading branch information
Showing
5 changed files
with
108 additions
and
4 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
58 changes: 58 additions & 0 deletions
58
...ons/jaxb/deployment/src/test/java/io/quarkus/jaxb/deployment/AbstractJaxbContextTest.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,58 @@ | ||
package io.quarkus.jaxb.deployment; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.StringWriter; | ||
|
||
import jakarta.enterprise.context.control.ActivateRequestContext; | ||
import jakarta.inject.Inject; | ||
import jakarta.xml.bind.JAXBContext; | ||
import jakarta.xml.bind.JAXBException; | ||
import jakarta.xml.bind.Marshaller; | ||
import jakarta.xml.bind.Unmarshaller; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public abstract class AbstractJaxbContextTest { | ||
|
||
@Inject | ||
JAXBContext jaxbContext; | ||
|
||
@Inject | ||
Marshaller marshaller; | ||
|
||
@Inject | ||
Unmarshaller unmarshaller; | ||
|
||
@Test | ||
@ActivateRequestContext | ||
public void shouldInjectJaxbBeans() { | ||
assertThat(jaxbContext).isNotNull(); | ||
assertThat(marshaller).isNotNull(); | ||
assertThat(unmarshaller).isNotNull(); | ||
} | ||
|
||
@Test | ||
@ActivateRequestContext | ||
public void marshalModelOne() throws JAXBException { | ||
io.quarkus.jaxb.deployment.one.Model model = new io.quarkus.jaxb.deployment.one.Model(); | ||
model.setName1("name1"); | ||
|
||
StringWriter sw = new StringWriter(); | ||
marshaller.marshal(model, sw); | ||
|
||
assertThat(sw.toString()).isEqualTo("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" | ||
+ "<model><name1>name1</name1></model>"); | ||
} | ||
|
||
@Test | ||
@ActivateRequestContext | ||
public void marshalModelTwo() throws JAXBException { | ||
io.quarkus.jaxb.deployment.two.Model model = new io.quarkus.jaxb.deployment.two.Model(); | ||
model.setName2("name2"); | ||
Assertions.assertThatExceptionOfType(JAXBException.class) | ||
.isThrownBy(() -> marshaller.marshal(model, new StringWriter())) | ||
.withMessage("class io.quarkus.jaxb.deployment.two.Model nor any of its super class is known to this context."); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
extensions/jaxb/deployment/src/test/java/io/quarkus/jaxb/deployment/ClassExcludeTest.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,17 @@ | ||
package io.quarkus.jaxb.deployment; | ||
|
||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ClassExcludeTest extends AbstractJaxbContextTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses( | ||
io.quarkus.jaxb.deployment.one.Model.class, | ||
io.quarkus.jaxb.deployment.two.Model.class) | ||
.addPackage("io.quarkus.jaxb.deployment.info")) | ||
.overrideConfigKey("quarkus.jaxb.exclude-classes", "io.quarkus.jaxb.deployment.two.Model"); | ||
} |
17 changes: 17 additions & 0 deletions
17
extensions/jaxb/deployment/src/test/java/io/quarkus/jaxb/deployment/PackageExcludeTest.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,17 @@ | ||
package io.quarkus.jaxb.deployment; | ||
|
||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class PackageExcludeTest extends AbstractJaxbContextTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses( | ||
io.quarkus.jaxb.deployment.one.Model.class, | ||
io.quarkus.jaxb.deployment.two.Model.class) | ||
.addPackage("io.quarkus.jaxb.deployment.info")) | ||
.overrideConfigKey("quarkus.jaxb.exclude-classes", "io.quarkus.jaxb.deployment.two.*"); | ||
} |
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