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