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