{
SchemaBinding schema = JBossXBBuilder.build(RootWithChoiceCollectionXmlType.class);
ElementBinding e = schema.getElement(new QName("root"));
assertNotNull(e);
TypeBinding type = e.getType();
TermBinding t = type.getParticle().getTerm();
assertNull(type.getSimpleType());
assertTrue(t instanceof SequenceBinding || t instanceof UnorderedSequenceBinding);
ModelGroupBinding s = (ModelGroupBinding) t;
Collection<ParticleBinding> particles = s.getParticles();
assertEquals(1, particles.size());
ParticleBinding p = particles.iterator().next();
t = p.getTerm();
assertTrue(t.isElement());
assertEquals(0, p.getMinOccurs());
assertEquals(1, p.getMaxOccurs());
assertFalse(p.getMaxOccursUnbounded());
e = (ElementBinding)t;
assertEquals(new QName("choices"), e.getQName());
type = e.getType();
assertEquals(1, type.getAttributes().size());
assertNotNull(type.getAttribute(new QName("a")));
assertNotNull(type.getSimpleType());
t = type.getParticle().getTerm();
assertTrue(t instanceof SequenceBinding || t instanceof UnorderedSequenceBinding);
particles = ((ModelGroupBinding)t).getParticles();
assertEquals(2, particles.size());
Iterator<ParticleBinding> i = particles.iterator();
ParticleBinding choiceParticle;
ParticleBinding elementParticle;
if(t instanceof SequenceBinding)
{
elementParticle = i.next();
choiceParticle = i.next();
}
else
{
p = i.next();
if (p.getTerm().isElement())
{
elementParticle = p;
choiceParticle = i.next();
}
else
{
choiceParticle = p;
elementParticle = i.next();
}
}
t = elementParticle.getTerm();
assertTrue(t.isElement());
assertEquals(0, elementParticle.getMinOccurs());
assertEquals(1, elementParticle.getMaxOccurs());
assertFalse(elementParticle.getMaxOccursUnbounded());
assertEquals(new QName("e"), ((ElementBinding)t).getQName());
t = choiceParticle.getTerm();
assertTrue(t instanceof ChoiceBinding);
assertEquals(1, choiceParticle.getMaxOccurs());
assertTrue(choiceParticle.getMaxOccursUnbounded());
ChoiceBinding c = (ChoiceBinding) t;
particles = c.getParticles();
assertEquals(2, particles.size());
Iterator<ParticleBinding> choiceIter = particles.iterator();
t = choiceIter.next().getTerm();
assertTrue(t.isElement());
assertEquals(new QName("a"), ((ElementBinding)t).getQName());
t = choiceIter.next().getTerm();
assertTrue(t.isElement());
assertEquals(new QName("b"), ((ElementBinding)t).getQName());
}