~hudson-ubuntu/+junk/hudson-dom4j

« back to all changes in this revision

Viewing changes to src/test/org/dom4j/dtd/ExternalEntityDeclTest.java

  • Committer: James Page
  • Date: 2010-11-18 13:20:23 UTC
  • Revision ID: james.page@canonical.com-20101118132023-puz3z975327yu8ib
Initial release of hudson variant

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
 
3
 *
 
4
 * This software is open source.
 
5
 * See the bottom of this file for the licence.
 
6
 */
 
7
 
 
8
package org.dom4j.dtd;
 
9
 
 
10
import junit.textui.TestRunner;
 
11
 
 
12
import org.dom4j.AbstractTestCase;
 
13
 
 
14
/**
 
15
 * Tests the {@link ExternalEntityDecl}functionality. Tests each of the
 
16
 * property access methods and the serialization mechanisms. Correct parsing is
 
17
 * tested by {@link DocTypeTest}.
 
18
 * 
 
19
 * <P>
 
20
 * </p>
 
21
 * 
 
22
 * @author Bryan Thompson
 
23
 * @author Maarten Coene
 
24
 * @version $Revision: 1.3 $
 
25
 * 
 
26
 * @todo The dom4j documentation needs to describe what representation SHOULD be
 
27
 *       generated by {@link ExternalEntityDecl#toString()}.
 
28
 * @todo Test support for NOTATION and NDATA when used as part of an external
 
29
 *       entity declaration. dom4j does not appear to support NOTATION and NDATA
 
30
 *       at this time.
 
31
 */
 
32
public class ExternalEntityDeclTest extends AbstractTestCase {
 
33
    public static void main(String[] args) {
 
34
        TestRunner.run(ExternalEntityDeclTest.class);
 
35
    }
 
36
 
 
37
    // Test case(s)
 
38
    // -------------------------------------------------------------------------
 
39
    public void testToString() {
 
40
        ExternalEntityDecl decl1 = new ExternalEntityDecl("name", null,
 
41
                "systemID");
 
42
        ExternalEntityDecl decl2 = new ExternalEntityDecl("%name", null,
 
43
                "systemID");
 
44
 
 
45
        assertEquals("<!ENTITY name SYSTEM \"systemID\" >", decl1.toString());
 
46
        assertEquals("<!ENTITY % name SYSTEM \"systemID\" >", decl2.toString());
 
47
    }
 
48
 
 
49
    /**
 
50
     * Tests external entity declaration using only the SYSTEM identifier.
 
51
     */
 
52
    public void testSystemId() {
 
53
        String expectedName = "anEntity";
 
54
 
 
55
        String expectedPublicID = null;
 
56
 
 
57
        String expectedSystemID = "http://www.myorg.org/foo";
 
58
 
 
59
        String expectedText = "<!ENTITY anEntity "
 
60
                + "SYSTEM \"http://www.myorg.org/foo\" >";
 
61
 
 
62
        ExternalEntityDecl actual = new ExternalEntityDecl(expectedName,
 
63
                expectedPublicID, expectedSystemID);
 
64
 
 
65
        assertEquals("name is correct", expectedName, actual.getName());
 
66
 
 
67
        assertEquals("publicID is correct", expectedPublicID, actual
 
68
                .getPublicID());
 
69
 
 
70
        assertEquals("systemID is correct", expectedSystemID, actual
 
71
                .getSystemID());
 
72
 
 
73
        assertEquals("toString() is correct", expectedText, actual.toString());
 
74
    }
 
75
 
 
76
    /**
 
77
     * Tests external entity declaration using both SYSTEM and PUBLIC
 
78
     * identifiers.
 
79
     */
 
80
    public void testPublicIdSystemId() {
 
81
        String expectedName = "anEntity";
 
82
 
 
83
        String expectedPublicID = "-//dom4j//DTD sample";
 
84
 
 
85
        String expectedSystemID = "http://www.myorg.org/foo";
 
86
 
 
87
        String expectedText = "<!ENTITY anEntity "
 
88
                + "PUBLIC \"-//dom4j//DTD sample\" "
 
89
                + "\"http://www.myorg.org/foo\" >";
 
90
 
 
91
        ExternalEntityDecl actual = new ExternalEntityDecl(expectedName,
 
92
                expectedPublicID, expectedSystemID);
 
93
 
 
94
        assertEquals("name is correct", expectedName, actual.getName());
 
95
 
 
96
        assertEquals("publicID is correct", expectedPublicID, actual
 
97
                .getPublicID());
 
98
 
 
99
        assertEquals("systemID is correct", expectedSystemID, actual
 
100
                .getSystemID());
 
101
 
 
102
        assertEquals("toString() is correct", expectedText, actual.toString());
 
103
    }
 
104
}
 
105
 
 
106
/*
 
107
 * Redistribution and use of this software and associated documentation
 
108
 * ("Software"), with or without modification, are permitted provided that the
 
109
 * following conditions are met:
 
110
 * 
 
111
 * 1. Redistributions of source code must retain copyright statements and
 
112
 * notices. Redistributions must also contain a copy of this document.
 
113
 * 
 
114
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 
115
 * this list of conditions and the following disclaimer in the documentation
 
116
 * and/or other materials provided with the distribution.
 
117
 * 
 
118
 * 3. The name "DOM4J" must not be used to endorse or promote products derived
 
119
 * from this Software without prior written permission of MetaStuff, Ltd. For
 
120
 * written permission, please contact dom4j-info@metastuff.com.
 
121
 * 
 
122
 * 4. Products derived from this Software may not be called "DOM4J" nor may
 
123
 * "DOM4J" appear in their names without prior written permission of MetaStuff,
 
124
 * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
 
125
 * 
 
126
 * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
 
127
 * 
 
128
 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
 
129
 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
130
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
131
 * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
 
132
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
133
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
134
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
135
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
136
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
137
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
138
 * POSSIBILITY OF SUCH DAMAGE.
 
139
 * 
 
140
 * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
 
141
 */