01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: import java.io.StringWriter;
20:
21: import org.apache.commons.betwixt.AbstractTestCase;
22: import org.apache.commons.betwixt.ElementDescriptor;
23: import org.apache.commons.betwixt.XMLBeanInfo;
24: import org.apache.commons.betwixt.XMLIntrospector;
25: import org.apache.commons.betwixt.io.BeanWriter;
26:
27: /**
28: * @author <a href='http://jakarta.apache.org/commons'>Jakarta Commons Team</a>, <a href='http://www.apache.org'>Apache Software Foundation</a>
29: */
30: public class TestMixedCollections extends AbstractTestCase {
31:
32: public TestMixedCollections(String testName) {
33: super (testName);
34: }
35:
36: public void testNoNameIntrospection() throws Exception {
37:
38: XMLIntrospector xmlIntrospector = new XMLIntrospector();
39: xmlIntrospector.getConfiguration().setWrapCollectionsInElement(
40: false);
41: XMLBeanInfo xmlBeanInfo = xmlIntrospector
42: .introspect(MixedCollectionBean.class);
43: ElementDescriptor elementDescriptor = xmlBeanInfo
44: .getElementDescriptor();
45: ElementDescriptor[] childDescriptors = elementDescriptor
46: .getElementDescriptors();
47: assertEquals("One child", 1, childDescriptors.length);
48: assertNull("Expected null name", childDescriptors[0]
49: .getLocalName());
50: }
51:
52: public void testNoNameWrite() throws Exception {
53: MixedCollectionBean bean = new MixedCollectionBean();
54: bean.getGubbins().add(new String("Blake"));
55: bean.getGubbins().add(new Integer(7));
56:
57: StringWriter out = new StringWriter();
58: out.write("<?xml version='1.0'?>");
59: BeanWriter writer = new BeanWriter(out);
60: writer.getBindingConfiguration().setMapIDs(false);
61: writer.write(bean);
62: String expected = "<?xml version='1.0'?>"
63: + "<stuff><String>Blake</String><Integer>7</Integer></stuff>";
64:
65: xmlAssertIsomorphic(parseString(expected), parseString(out));
66: }
67: }
|