InternalEntityDeclTest xref

    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 InternalEntityDecl}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 InternalEntityDecl#toString()}.
    28   */
    29  public class InternalEntityDeclTest extends AbstractTestCase {
    30      public static void main(String[] args) {
    31          TestRunner.run(InternalEntityDeclTest.class);
    32      }
    33
    34      // Test case(s)
    35      // -------------------------------------------------------------------------
    36      public void testToString() {
    37          InternalEntityDecl decl1 = new InternalEntityDecl("name", "value");
    38          InternalEntityDecl decl2 = new InternalEntityDecl("%name", "value");
    39
    40          assertEquals("<!ENTITY name \"value\">", decl1.toString());
    41          assertEquals("<!ENTITY % name \"value\">", decl2.toString());
    42      }
    43
    44      /***
    45       * Tests parameter entity declaration, such as
    46       *
    47       * <pre>
    48       *
    49       *
    50       *   &lt;!ENTITY % boolean &quot;( true | false )&quot;&gt;
    51       *
    52       *
    53       * </pre>
    54       *
    55       * Note: There is a required whitespace between the "%" and the name of the
    56       * entity. This whitespace is required in the declaration and is not allowed
    57       * when writing a reference to the entity, e.g., "%boolean;" is a legal
    58       * reference but not "% boolean;".
    59       *
    60       * <p>
    61       * Note: The "%" is part of the parameter entity name as reported by the SAX
    62       * API. See <a href="http://tinyurl.com/6xe9y">LexicalHandler </a>, which
    63       * states:
    64       *
    65       * <pre>
    66       *
    67       *
    68       *   General entities are reported with their regular names,
    69       *   parameter entities have '%' prepended to their names, and the
    70       *   external DTD subset has the pseudo-entity name &quot;[dtd]&quot;.
    71       *
    72       *
    73       * </pre>
    74       *
    75       * </p>
    76       */
    77      public void testParameterEntity() {
    78          String expectedName = "%boolean";
    79
    80          String expectedValue = "( true | false )";
    81
    82          String expectedText = "<!ENTITY % boolean \"( true | false )\">";
    83
    84          InternalEntityDecl actual = new InternalEntityDecl(expectedName,
    85                  expectedValue);
    86
    87          assertEquals("name is correct", expectedName, actual.getName());
    88
    89          assertEquals("value is correct", expectedValue, actual.getValue());
    90
    91          assertEquals("toString() is correct", expectedText, actual.toString());
    92      }
    93
    94      /***
    95       * Tests general entity declaration, such as:
    96       *
    97       * <pre>
    98       *
    99       *
    100      *   &lt;!ENTITY foo &quot;bar&quot;&gt;
    101      *
    102      *
    103      * </pre>
    104      */
    105     public void testGeneralEntity() {
    106         String expectedName = "foo";
    107
    108         String expectedValue = "bar";
    109
    110         String expectedText = "<!ENTITY foo \"bar\">";
    111
    112         InternalEntityDecl actual = new InternalEntityDecl(expectedName,
    113                 expectedValue);
    114
    115         assertEquals("name is correct", expectedName, actual.getName());
    116
    117         assertEquals("value is correct", expectedValue, actual.getValue());
    118
    119         assertEquals("toString() is correct", expectedText, actual.toString());
    120     }
    121 }
    122
    123 /*
    124  * Redistribution and use of this software and associated documentation
    125  * ("Software"), with or without modification, are permitted provided that the
    126  * following conditions are met:
    127  *
    128  * 1. Redistributions of source code must retain copyright statements and
    129  * notices. Redistributions must also contain a copy of this document.
    130  *
    131  * 2. Redistributions in binary form must reproduce the above copyright notice,
    132  * this list of conditions and the following disclaimer in the documentation
    133  * and/or other materials provided with the distribution.
    134  *
    135  * 3. The name "DOM4J" must not be used to endorse or promote products derived
    136  * from this Software without prior written permission of MetaStuff, Ltd. For
    137  * written permission, please contact dom4j-info@metastuff.com.
    138  *
    139  * 4. Products derived from this Software may not be called "DOM4J" nor may
    140  * "DOM4J" appear in their names without prior written permission of MetaStuff,
    141  * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
    142  *
    143  * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
    144  *
    145  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
    146  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    147  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    148  * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
    149  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    150  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    151  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    152  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    153  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    154  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    155  * POSSIBILITY OF SUCH DAMAGE.
    156  *
    157  * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
    158  */