1   /*
2    * Copyright 2001-2004 (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    * $Id: TestInternalEntityDecl.java,v 1.4 2004/06/25 08:03:49 maartenc Exp $
8    */
9   
10  package org.dom4j.dtd;
11  
12  import junit.framework.*;
13  import junit.textui.TestRunner;
14  
15  /*** Tests the {@link InternalEntityDecl} functionality.  Tests each of
16    * the property access methods and the serialization mechanisms.
17    * Correct parsing is tested by {@link TestDocType}.<p>
18    *
19    * @todo The dom4j documentation needs to describe what
20    * representation SHOULD be generated by {@link
21    * InternalEntityDecl#toString()}.
22    *
23    * @author Bryan Thompson
24    * @author Maarten Coene
25    * @version $Revision: 1.4 $
26    */
27  
28  public class TestInternalEntityDecl extends TestCase {
29  
30      
31      public static void main( String[] args ) {
32          TestRunner.run( suite() );
33      }
34      
35      public static Test suite() {
36          return new TestSuite( TestInternalEntityDecl.class );
37      }
38      
39      public TestInternalEntityDecl(String name) {
40          super(name);
41      }
42  
43      // Test case(s)
44      //-------------------------------------------------------------------------                    
45      public void testToString() {
46          InternalEntityDecl decl1 = new InternalEntityDecl("name", "value");
47          InternalEntityDecl decl2 = new InternalEntityDecl("%name", "value");
48          
49          assertEquals("<!ENTITY name \"value\">", decl1.toString());
50          assertEquals("<!ENTITY % name \"value\">", decl2.toString());
51      }
52  
53      /***
54       * Tests parameter entity declaration, such as
55       *
56       * <pre>
57       * <!ENTITY % boolean "( true | false )">
58       * </pre>
59       * Note: There is a required whitespace between the "%" and the
60       * name of the entity.  This whitespace is required in the
61       * declaration and is not allowed when writing a reference to the
62       * entity, e.g., "%boolean;" is a legal reference but not "%
63       * boolean;".<p>
64       *
65       * Note: The "%" is part of the parameter entity name as reported
66       * by the SAX API.  See
67       *
68       * <a href="http://www.saxproject.org/apidoc/org/xml/sax/ext/LexicalHandler.html#startEntity(java.lang.String)">
69       * LexicalHandler</a>, which states:
70       *
71       * <pre>
72       * General entities are reported with their regular names,
73       * parameter entities have '%' prepended to their names, and the
74       * external DTD subset has the pseudo-entity name "[dtd]".
75       * </pre>
76       */
77      public void test_parameter_entity()
78      {
79  	
80  	String expectedName = "%boolean";
81  
82  	String expectedValue = "( true | false )";
83  
84  	String expectedText = "<!ENTITY % boolean \"( true | false )\">";
85  
86  	InternalEntityDecl actual = new InternalEntityDecl
87  	    ( expectedName,
88  	      expectedValue
89  	      );
90  
91  	assertEquals
92  	    ( "name is correct",
93  	      expectedName,
94  	      actual.getName()
95  	      );
96  
97  	assertEquals
98  	    ( "value is correct",
99  	      expectedValue,
100 	      actual.getValue()
101 	      );
102 
103 	assertEquals
104 	    ( "toString() is correct",
105 	      expectedText,
106 	      actual.toString()
107 	      );
108 
109     }
110 
111     /***
112      * Tests general entity declaration, such as:
113      *
114      * <pre>
115      * <!ENTITY foo "bar">
116      * </pre>
117      */
118 
119     public void test_general_entity()
120     {
121 
122 	String expectedName = "foo";
123 
124 	String expectedValue = "bar";
125 
126 	String expectedText = "<!ENTITY foo \"bar\">";
127 
128 	InternalEntityDecl actual = new InternalEntityDecl
129 	    ( expectedName,
130 	      expectedValue
131 	      );
132 
133 	assertEquals
134 	    ( "name is correct",
135 	      expectedName,
136 	      actual.getName()
137 	      );
138 
139 	assertEquals
140 	    ( "value is correct",
141 	      expectedValue,
142 	      actual.getValue()
143 	      );
144 
145 	assertEquals
146 	    ( "toString() is correct",
147 	      expectedText,
148 	      actual.toString()
149 	      );
150 
151     }
152 
153     // Implementation methods
154     //-------------------------------------------------------------------------                    
155 
156 
157 }
158 
159 
160 
161 /*
162  * Redistribution and use of this software and associated documentation
163  * ("Software"), with or without modification, are permitted provided
164  * that the following conditions are met:
165  *
166  * 1. Redistributions of source code must retain copyright
167  *    statements and notices.  Redistributions must also contain a
168  *    copy of this document.
169  *
170  * 2. Redistributions in binary form must reproduce the
171  *    above copyright notice, this list of conditions and the
172  *    following disclaimer in the documentation and/or other
173  *    materials provided with the distribution.
174  *
175  * 3. The name "DOM4J" must not be used to endorse or promote
176  *    products derived from this Software without prior written
177  *    permission of MetaStuff, Ltd.  For written permission,
178  *    please contact dom4j-info@metastuff.com.
179  *
180  * 4. Products derived from this Software may not be called "DOM4J"
181  *    nor may "DOM4J" appear in their names without prior written
182  *    permission of MetaStuff, Ltd. DOM4J is a registered
183  *    trademark of MetaStuff, Ltd.
184  *
185  * 5. Due credit should be given to the DOM4J Project - 
186  *    http://www.dom4j.org
187  *
188  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
189  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
190  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
191  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
192  * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
193  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
194  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
195  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
196  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
197  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
198  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
199  * OF THE POSSIBILITY OF SUCH DAMAGE.
200  *
201  * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
202  *
203  * $Id: TestInternalEntityDecl.java,v 1.4 2004/06/25 08:03:49 maartenc Exp $
204  */