KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > xml > dom > DOMBuilderTestCase


1 /*
2  * Copyright 1999-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 package org.apache.cocoon.xml.dom;
17
18 import junit.framework.TestCase;
19
20 import org.w3c.dom.Document JavaDoc;
21 import org.xml.sax.Attributes JavaDoc;
22 import org.xml.sax.SAXException JavaDoc;
23 import org.xml.sax.helpers.AttributesImpl JavaDoc;
24
25
26 /**
27  * JUnit Testcase for {@link DOMBuilder}.
28  *
29  * @version CVS $Id: DOMBuilderTestCase.java 30932 2004-07-29 17:35:38Z vgritsenko $
30  */

31 public class DOMBuilderTestCase extends TestCase {
32
33     /**
34      * Constructor.
35      * @param name
36      */

37     public DOMBuilderTestCase(String JavaDoc name) {
38         super(name);
39     }
40
41     /**
42      * Test if two consecutive "characters" events result in two text nodes
43      * whose concatenation is equal to the concatenation
44      * of the two strings (cfr. bug #26219).
45      *
46      * @throws SAXException
47      */

48     public void testMultipleCharactersEvents() throws SAXException JavaDoc {
49         DOMBuilder builder = new DOMBuilder();
50         Attributes JavaDoc attrs = new AttributesImpl JavaDoc();
51         char c1[] = "ABC".toCharArray();
52         char c2[] = "DEF".toCharArray();
53         builder.startDocument();
54         builder.startElement("", "test", "test", attrs);
55         builder.characters(c1, 0, 3);
56         builder.characters(c2, 0, 3);
57         builder.endElement("", "test", "test");
58         builder.endDocument();
59         Document JavaDoc dom = builder.getDocument();
60         StringBuffer JavaDoc value = new StringBuffer JavaDoc();
61         for (int i = 0 ; i < dom.getDocumentElement().getChildNodes().getLength() ; ++i) {
62             value.append(dom.getDocumentElement().getChildNodes().item(i).getNodeValue());
63         }
64         assertEquals("Content of root element not what expected",
65                 "ABCDEF", value.toString());
66     }
67 }
68
Popular Tags