1   /*
2    * Copyright 2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */ 
16  package org.apache.commons.betwixt.dotbetwixt;
17  
18  
19  import java.io.StringWriter;
20  
21  
22  import org.apache.commons.betwixt.*;
23  import org.apache.commons.betwixt.io.BeanWriter;
24  
25  /***
26   * @author <a href='http://jakarta.apache.org/commons'>Jakarta Commons Team</a>, <a href='http://www.apache.org'>Apache Software Foundation</a>
27   */
28  public class TestMixedCollections extends AbstractTestCase {
29  
30      public TestMixedCollections(String testName) {
31          super(testName);
32      }
33  
34      public void testNoNameIntrospection() throws Exception {
35          
36          XMLIntrospector xmlIntrospector = new XMLIntrospector();
37          xmlIntrospector.getConfiguration().setWrapCollectionsInElement(false);
38          XMLBeanInfo xmlBeanInfo = xmlIntrospector.introspect(MixedCollectionBean.class);
39          ElementDescriptor elementDescriptor = xmlBeanInfo.getElementDescriptor();
40          ElementDescriptor[] childDescriptors = elementDescriptor.getElementDescriptors();
41          assertEquals("One child", 1, childDescriptors.length);   
42          assertNull("Expected null name", childDescriptors[0].getLocalName());   
43      }
44      
45      public void testNoNameWrite() throws Exception {
46          MixedCollectionBean bean = new MixedCollectionBean();
47          bean.getGubbins().add(new String("Blake"));
48          bean.getGubbins().add(new Integer(7));
49          
50          StringWriter out = new StringWriter();
51          out.write("<?xml version='1.0'?>");
52          BeanWriter writer = new BeanWriter(out);
53          writer.getBindingConfiguration().setMapIDs(false);
54          writer.write(bean);
55          String expected = "<?xml version='1.0'?>" +
56          		"<stuff><String>Blake</String><Integer>7</Integer></stuff>";
57          
58          xmlAssertIsomorphic(parseString(expected), parseString(out));
59      }
60  }