1
/* Copyright 2003, 2004 Elliotte Rusty Harold
3
This library is free software; you can redistribute it and/or modify
4
it under the terms of version 2.1 of the GNU Lesser General Public
5
License as published by the Free Software Foundation.
7
This library is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU Lesser General Public License for more details.
12
You should have received a copy of the GNU Lesser General Public
13
License along with this library; if not, write to the
14
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
15
Boston, MA 02111-1307 USA
17
You can contact Elliotte Rusty Harold by sending e-mail to
18
elharo@metalab.unc.edu. Please include the word "XOM" in the
19
subject line. The XOM home page is located at http://www.xom.nu/
24
import nu.xom.Attribute;
25
import nu.xom.Comment;
26
import nu.xom.DocType;
27
import nu.xom.Document;
28
import nu.xom.Element;
30
import nu.xom.ProcessingInstruction;
36
* Tests for subclasses of XOM classes.
37
* This makes sure XOM is sufficiently polymorphic.
40
* @author Elliotte Rusty Harold
44
public class SubclassTest extends XOMTestCase {
50
public SubclassTest(String name) {
55
protected void setUp() {
56
root = new Element("root");
57
doc = new Document(new ElementSubclass("root"));
61
public void testAttributeClassInCopy() {
62
root.addAttribute(new AttributeSubclass("name", "value"));
63
assertTrue(root.getAttribute(0) instanceof AttributeSubclass);
64
Element copy = (Element) root.copy();
65
assertTrue(copy.getAttribute(0) instanceof AttributeSubclass);
69
private class AttributeSubclass extends Attribute {
71
AttributeSubclass(String name, String value) {
76
return new AttributeSubclass(this.getQualifiedName(), this.getValue());
82
public void testTextClassInCopy() {
83
root.appendChild(new TextSubclass("value"));
84
assertTrue(root.getChild(0) instanceof TextSubclass);
85
Element copy = (Element) root.copy();
86
assertTrue(copy.getChild(0) instanceof TextSubclass);
90
private class TextSubclass extends Text {
92
TextSubclass(String value) {
97
return new TextSubclass(this.getValue());
102
public void testElementClassInCopy() {
103
root.appendChild(new ElementSubclass("child"));
104
assertTrue(root.getChild(0) instanceof ElementSubclass);
105
Element copy = (Element) root.copy();
106
assertTrue(copy.getChild(0) instanceof ElementSubclass);
110
private class ElementSubclass extends Element {
112
ElementSubclass(String name) {
116
protected Element shallowCopy() {
117
return new ElementSubclass(this.getQualifiedName());
123
public void testCommentClassInCopy() {
124
root.appendChild(new CommentSubclass("value"));
125
assertTrue(root.getChild(0) instanceof CommentSubclass);
126
Element copy = (Element) root.copy();
127
assertTrue(copy.getChild(0) instanceof CommentSubclass);
131
private class CommentSubclass extends Comment {
133
CommentSubclass(String value) {
138
return new CommentSubclass(this.getValue());
144
private class DocTypeSubclass extends DocType {
146
DocTypeSubclass(String name) {
151
return new DocTypeSubclass(this.getRootElementName());
156
public void testProcessingInstructionClassInCopy() {
157
root.appendChild(new ProcessingInstructionSubclass("target", "value"));
158
assertTrue(root.getChild(0) instanceof ProcessingInstructionSubclass);
159
Element copy = (Element) root.copy();
160
assertTrue(copy.getChild(0) instanceof ProcessingInstructionSubclass);
164
private class ProcessingInstructionSubclass extends ProcessingInstruction {
166
ProcessingInstructionSubclass(String target, String data) {
171
return new ProcessingInstructionSubclass(this.getTarget(), this.getValue());
177
public void testProcessingInstructionClassInDocCopy() {
178
doc.insertChild(new ProcessingInstructionSubclass("target", "value"), 0);
179
assertTrue(doc.getChild(0) instanceof ProcessingInstructionSubclass);
180
Document copy = (Document) doc.copy();
181
assertTrue(copy.getChild(0) instanceof ProcessingInstructionSubclass);
185
public void testCommentClassInDocCopy() {
186
doc.insertChild(new CommentSubclass("target"), 0);
187
assertTrue(doc.getChild(0) instanceof CommentSubclass);
188
Document copy = (Document) doc.copy();
189
assertTrue(copy.getChild(0) instanceof CommentSubclass);
193
public void testElementClassInDocCopy() {
194
assertTrue(doc.getChild(0) instanceof ElementSubclass);
195
Document copy = (Document) doc.copy();
196
assertTrue(copy.getChild(0) instanceof ElementSubclass);
200
public void testDocTypeClassInDocCopy() {
201
doc.insertChild(new DocTypeSubclass("root"), 0);
202
assertTrue(doc.getChild(0) instanceof DocTypeSubclass);
203
Document copy = (Document) doc.copy();
204
assertTrue(copy.getChild(0) instanceof DocTypeSubclass);