KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > dotbetwixt > TestDotBetwixtNamespace


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
17
18 package org.apache.commons.betwixt.dotbetwixt;
19
20 import java.io.StringWriter JavaDoc;
21
22 import org.apache.commons.betwixt.AbstractTestCase;
23 import org.apache.commons.betwixt.io.BeanWriter;
24
25 /**
26  * @author <a HREF='http://jakarta.apache.org/'>Jakarta Commons Team</a>
27  * @version $Revision: 1.2 $
28  */

29 public class TestDotBetwixtNamespace extends AbstractTestCase {
30
31     public TestDotBetwixtNamespace(String JavaDoc name) {
32         super(name);
33     }
34     
35     
36     public void testWriteSimpleDotBetwixtWithNamespaces() throws Exception JavaDoc {
37         PersonWithNamespace bean = new PersonWithNamespace("Robert", "Burrell", "Donkin");
38         StringWriter JavaDoc out = new StringWriter JavaDoc();
39         out.write("<?xml version='1.0'?>");
40         BeanWriter writer = new BeanWriter(out);
41         writer.getBindingConfiguration().setMapIDs(false);
42         writer.getXMLIntrospector().getConfiguration().getPrefixMapper()
43             .setPrefix("http://jakarta.apache.org/commons/betwixt/PersonWithNamespaceExample", "pn");
44         writer.write(bean);
45         
46         String JavaDoc xml = out.getBuffer().toString();
47         
48         String JavaDoc expected = "<?xml version='1.0'?>" +
49                         "<pn:person " +
50                         "xmlns:pn='http://jakarta.apache.org/commons/betwixt/PersonWithNamespaceExample' " +
51                         "pn:middle='Burrell'>" +
52                         "<forename>Robert</forename>" +
53                         "<pn:surname>Donkin</pn:surname></pn:person>";
54                         
55         xmlAssertIsomorphicContent(parseString(xml), parseString(expected));
56     }
57 }
58
Popular Tags