I generated a code from a XML Schema (i've attached both generated code and schema).
I think that the problem is here:
<element name="Subject" type="saml:SubjectType"/>
<complexType name="SubjectType">
<choice>
<sequence>
<choice>
<element name="choice1" type="string"/>
<element name="choice2" type="string"/>
<element name="choice3" type="string"/>
</choice>
<element ref="saml:SubjectConfirmation" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<element ref="saml:SubjectConfirmation" maxOccurs="unbounded"/>
</choice>
</complexType>
When I create a Subject element and marhsal it, it's ok, but then I try to unmarhsal it, it throws an exception:
org.exolab.castor.xml.MarshalException: Element with name SubjectConfirmation passed to type null in incorrect order; expected element has to be member of the expected choice.{File: [not available]; line: 2; column: 133}
at org.exolab.castor.xml.Unmarshaller.convertSAXExceptionToMarshalException(Unmarshaller.java:755)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:721)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:610)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:801)
at test.saml.Subject.unmarshal(Subject.java:100)
at test.Test.testSubject(Test.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: ValidationException: Element with name SubjectConfirmation passed to type null in incorrect order; expected element has to be member of the expected choice.
at org.exolab.castor.xml.util.XMLClassDescriptorImpl.checkDescriptorForCorrectOrderWithinSequence(XMLClassDescriptorImpl.java:362)
at org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1868)
at org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1995)
at org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1351)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:709)
... 22 more
Caused by: ValidationException: Element with name SubjectConfirmation passed to type null in incorrect order; expected element has to be member of the expected choice.
at org.exolab.castor.xml.util.XMLClassDescriptorImpl.checkDescriptorForCorrectOrderWithinSequence(XMLClassDescriptorImpl.java:362)
at org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1868)
at org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1995)
at org.exolab.castor.xml.UnmarshalHandler.startElement(UnmarshalHandler.java:1351)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:709)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:610)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:801)
at test.saml.Subject.unmarshal(Subject.java:100)
at test.Test.testSubject(Test.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
I've attached the testCase that creates the subject and then marhsal and unmarhsal it.
Regards
Iņaki Iturrate
If you are looking at the odd 70 Jira issues (all of them with more or less complex XML schema fragments), how much time would you want to spend on dreaming up test case code ?