7 Replies Latest reply on Mar 6, 2008 9:31 AM by aloubyansky

    XmlElementWrapper tests

    aloubyansky

      Adrian, I fixed the bug you showed me yesterday. Here is the issue http://jira.jboss.com/jira/browse/JBXB-126

      Adding the test for it, I found that the XML for current XmlElementWrapper tests doesn't look right to me. E.g. for class

      @XmlRootElement
      public class Foo2
      {
       private List<Number> items;
      
       public List<Number> getItems()
       {
       return items;
       }
      
       @XmlElementWrapper(name="bar")
       @XmlElements({
       @XmlElement(name="int", required=false, type=Integer.class),
       @XmlElement(name="float", required=false, type=Float.class),
       @XmlElement(name="x", required=false, type=MyNumber.class)
       })
       public void setItems(List<Number> items)
       {
       this.items = items;
       }
      }


      the xml is
      <foo2>
       <bar>
       <int>1</int>
       </bar>
       <bar>
       <int>2</int>
       </bar>
       <bar>
       <float>1.1</float>
       </bar>
       <bar>
       <x>123456789</x>
       </bar>
      </foo2>


      while I would expect it to be
      <foo2>
       <bar>
       <int>1</int>
       <int>2</int>
       <float>1.1</float>
       <x>123456789</x>
       </bar>
      </foo2>


      In fact, both pass. As well as something like
      <foo2>
       <bar>
       <int>1</int>
       <int>2</int>
       </bar>
       <bar>
       <float>1.1</float>
       </bar>
       <bar>
       <x>123456789</x>
       </bar>
      </foo2>


      Because, I guess, all the particles are added as repeatable. But I don't think this is the way it is supposed to be.

        • 1. Re: XmlElementWrapper tests

          Scott wrote these tests.

          I guess he put the bounds on the wrong part of the model? ;-)

           SequenceBinding seq = new SequenceBinding(schemaBinding);
          ...
           particle = new ParticleBinding(wrapperElement, 1, 1, false);
          


          • 2. Re: XmlElementWrapper tests

            I just found the opposite issue :-)
            http://jira.jboss.com/jira/browse/JBXB-127

            • 3. Re: XmlElementWrapper tests
              starksm64

              No, what is what I wanted, at least in terms of the xml as this models the application/module/x structure of an ear application.xml descriptor.

              • 4. Re: XmlElementWrapper tests
                aloubyansky

                Yes, now I remember...

                • 5. Re: XmlElementWrapper tests
                  aloubyansky

                   

                  "adrian" wrote:
                  http://jira.jboss.com/jira/browse/JBXB-127


                  This looks confusing to me. Which test was it based on?

                  As I understand, what should be repeatable is the item particle. Which is. The collection type might have its own properties. Those should not be repeatable, as I imagine...

                  • 6. Re: XmlElementWrapper tests

                    The testcase is CollectionWithValues.
                    (remove the modification then you'll see it fail)

                    Its not a javabean its a real collection
                    and it doesn't have "items" it has an add() operation. :-)

                    @XmlType()
                    @JBossXmlNoElements
                    @JBossXmlChildren
                    ({
                     @JBossXmlChild(name="array", type=AbstractArrayMetaData.class),
                     @JBossXmlChild(name="collection", type=AbstractCollectionMetaData.class),
                     @JBossXmlChild(name="inject", type=AbstractDependencyValueMetaData.class),
                     @JBossXmlChild(name="list", type=AbstractListMetaData.class),
                     @JBossXmlChild(name="map", type=AbstractMapMetaData.class),
                     @JBossXmlChild(name="null", type=AbstractValueMetaData.class),
                     @JBossXmlChild(name="set", type=AbstractSetMetaData.class),
                     @JBossXmlChild(name="this", type=ThisValueMetaData.class),
                     @JBossXmlChild(name="value", type=StringValueMetaData.class)
                    })
                    @JBossXmlChildWildcard(wrapper=AbstractValueMetaData.class, property="value")
                    public class AbstractCollectionMetaData extends AbstractTypeMetaData
                     implements Collection<MetaDataVisitorNode>, Serializable
                    


                    If you think it is confusing then we could condition it on @JBossXMLNoElements
                    or something that identifies it for this usecase?

                    • 7. Re: XmlElementWrapper tests
                      aloubyansky

                      Yes, I was thinking in terms of a JavaBean. By the item particle I meant the particle for the component. Like this is done in case there is @JBossXmlModelGroup.