1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }