-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#457] add multiple namespaces prefix bindings
- Loading branch information
1 parent
0d0828b
commit bd74bbb
Showing
7 changed files
with
185 additions
and
6 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
47 changes: 47 additions & 0 deletions
47
jaxb-plugins-parent/tests/namespace/src/main/resources/c.xsd
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,47 @@ | ||
<xsd:schema | ||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" | ||
targetNamespace="c" | ||
xmlns:a="a" | ||
xmlns:c="c" | ||
elementFormDefault="qualified"> | ||
|
||
<xsd:import namespace="a" schemaLocation="a.xsd"/> | ||
|
||
<xsd:element name="c" type="c:CType"/> | ||
|
||
<xsd:complexType name="CType"> | ||
<xsd:complexContent> | ||
<xsd:extension base="a:AType"> | ||
<xsd:sequence> | ||
<xsd:element name="c" type="c:C1Type"/> | ||
<xsd:element name="ca" type="a:AType" minOccurs="0" maxOccurs="unbounded"/> | ||
</xsd:sequence> | ||
</xsd:extension> | ||
</xsd:complexContent> | ||
</xsd:complexType> | ||
|
||
<xsd:complexType name="C1Type"> | ||
<xsd:complexContent> | ||
<xsd:extension base="a:A1Type"> | ||
<xsd:sequence> | ||
<xsd:element name="c1" type="xsd:string"/> | ||
</xsd:sequence> | ||
</xsd:extension> | ||
</xsd:complexContent> | ||
</xsd:complexType> | ||
|
||
<xsd:complexType name="issueHJIII24Mammal"> | ||
<xsd:complexContent> | ||
<xsd:extension base="a:issueHJIII24Animal"> | ||
</xsd:extension> | ||
</xsd:complexContent> | ||
</xsd:complexType> | ||
|
||
<xsd:complexType name="issueHJIII24Dog"> | ||
<xsd:complexContent> | ||
<xsd:extension base="c:issueHJIII24Mammal"> | ||
</xsd:extension> | ||
</xsd:complexContent> | ||
</xsd:complexType> | ||
|
||
</xsd:schema> |
21 changes: 21 additions & 0 deletions
21
jaxb-plugins-parent/tests/namespace/src/test/java/org/jvnet/jaxb/tests/namespace/ATest.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,21 @@ | ||
package org.jvnet.jaxb.tests.namespace; | ||
|
||
import jakarta.xml.bind.annotation.XmlNs; | ||
import jakarta.xml.bind.annotation.XmlSchema; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.jvnet.jaxb.test.namespace.a.AType; | ||
|
||
public class ATest { | ||
|
||
@Test | ||
public void testA() { | ||
AType a = new AType(); | ||
XmlSchema schema = a.getClass().getPackage().getAnnotation(XmlSchema.class); | ||
XmlNs[] namespaces = schema.xmlns(); | ||
Assert.assertNotNull(namespaces); | ||
Assert.assertEquals(1, namespaces.length); | ||
Assert.assertEquals("a", namespaces[0].namespaceURI()); | ||
Assert.assertEquals("a", namespaces[0].prefix()); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
jaxb-plugins-parent/tests/namespace/src/test/java/org/jvnet/jaxb/tests/namespace/BTest.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,29 @@ | ||
package org.jvnet.jaxb.tests.namespace; | ||
|
||
import jakarta.xml.bind.annotation.XmlNs; | ||
import jakarta.xml.bind.annotation.XmlSchema; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.jvnet.jaxb.test.namespace.b.BType; | ||
|
||
import java.util.Arrays; | ||
|
||
public class BTest { | ||
|
||
@Test | ||
public void testB() { | ||
BType b = new BType(); | ||
XmlSchema schema = b.getClass().getPackage().getAnnotation(XmlSchema.class); | ||
XmlNs[] namespaces = schema.xmlns(); | ||
Assert.assertNotNull(namespaces); | ||
Assert.assertEquals(2, namespaces.length); | ||
XmlNs aNs = Arrays.stream(namespaces).filter(ns -> "aprefix".equals(ns.prefix())).findFirst().orElse(null); | ||
Assert.assertNotNull(aNs); | ||
Assert.assertEquals("a", aNs.namespaceURI()); | ||
Assert.assertEquals("aprefix", aNs.prefix()); | ||
XmlNs bNs = Arrays.stream(namespaces).filter(ns -> "b".equals(ns.prefix())).findFirst().orElse(null); | ||
Assert.assertNotNull(bNs); | ||
Assert.assertEquals("b", bNs.namespaceURI()); | ||
Assert.assertEquals("b", bNs.prefix()); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
jaxb-plugins-parent/tests/namespace/src/test/java/org/jvnet/jaxb/tests/namespace/CTest.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,57 @@ | ||
package org.jvnet.jaxb.tests.namespace; | ||
|
||
import jakarta.xml.bind.JAXBContext; | ||
import jakarta.xml.bind.JAXBElement; | ||
import jakarta.xml.bind.JAXBException; | ||
import jakarta.xml.bind.annotation.XmlNs; | ||
import jakarta.xml.bind.annotation.XmlSchema; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.jvnet.jaxb.test.namespace.a.A1Type; | ||
import org.jvnet.jaxb.test.namespace.c.C1Type; | ||
import org.jvnet.jaxb.test.namespace.c.CType; | ||
|
||
import javax.xml.namespace.QName; | ||
import java.io.StringWriter; | ||
import java.util.Arrays; | ||
|
||
public class CTest { | ||
|
||
@Test | ||
public void testC() throws JAXBException { | ||
CType c = new CType(); | ||
XmlSchema schema = c.getClass().getPackage().getAnnotation(XmlSchema.class); | ||
XmlNs[] namespaces = schema.xmlns(); | ||
Assert.assertEquals(3, namespaces.length); | ||
XmlNs aNs = Arrays.stream(namespaces).filter(ns -> "aprefix".equals(ns.prefix())).findFirst().orElse(null); | ||
Assert.assertNotNull(aNs); | ||
Assert.assertEquals("a", aNs.namespaceURI()); | ||
Assert.assertEquals("aprefix", aNs.prefix()); | ||
XmlNs bNs = Arrays.stream(namespaces).filter(ns -> "bprefix".equals(ns.prefix())).findFirst().orElse(null); | ||
Assert.assertNotNull(bNs); | ||
Assert.assertEquals("b", bNs.namespaceURI()); | ||
Assert.assertEquals("bprefix", bNs.prefix()); | ||
XmlNs cNs = Arrays.stream(namespaces).filter(ns -> "creal".equals(ns.prefix())).findFirst().orElse(null); | ||
Assert.assertNotNull(cNs); | ||
Assert.assertEquals("c", cNs.namespaceURI()); | ||
Assert.assertEquals("creal", cNs.prefix()); | ||
|
||
c.setA(new A1Type()); | ||
c.setC(new C1Type()); | ||
|
||
JAXBElement<CType> jaxbElement | ||
= new JAXBElement<>( new QName("c", "cPart"), CType.class, c); | ||
JAXBContext context = JAXBContext.newInstance(CType.class.getPackage().getName()); | ||
StringWriter writer = new StringWriter(); | ||
context.createMarshaller().marshal(jaxbElement, writer); | ||
String marshalled = writer.toString(); | ||
|
||
Assert.assertNotNull(marshalled); | ||
String expectedA = "xmlns:aprefix=\"a\""; | ||
Assert.assertTrue(marshalled.contains(expectedA)); | ||
String expectedB = "xmlns:bprefix=\"b\""; | ||
Assert.assertTrue(marshalled.contains(expectedB)); | ||
String expectedC = "xmlns:creal=\"c\""; | ||
Assert.assertTrue(marshalled.contains(expectedC)); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...s/tests/namespace/RunNamespacePlugin.java → ...b/tests/namespace/RunNamespacePlugin.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