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: TestExternalEntityDecl.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 ExternalEntityDecl} 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    * ExternalEntityDecl#toString()}.
22    *
23    * @todo Test support for NOTATION and NDATA when used as part of an
24    * external entity declaration.  dom4j does not appear to support
25    * NOTATION and NDATA at this time.
26    *
27    * @author Bryan Thompson
28    * @author Maarten Coene
29    * @version $Revision: 1.4 $
30    */
31  
32  public class TestExternalEntityDecl extends TestCase {
33  
34      
35      public static void main( String[] args ) {
36          TestRunner.run( suite() );
37      }
38      
39      public static Test suite() {
40          return new TestSuite( TestExternalEntityDecl.class );
41      }
42      
43      public TestExternalEntityDecl(String name) {
44          super(name);
45      }
46  
47      // Test case(s)
48      //-------------------------------------------------------------------------                    
49      public void testToString() {
50          ExternalEntityDecl decl1 = new ExternalEntityDecl("name", null, "systemID");
51          ExternalEntityDecl decl2 = new ExternalEntityDecl("%name", null, "systemID");
52           
53          assertEquals("<!ENTITY name SYSTEM \"systemID\" >", decl1.toString());
54          assertEquals("<!ENTITY % name SYSTEM \"systemID\" >", decl2.toString());
55      }
56  
57      /***
58       * Tests external entity declaration using only the SYSTEM
59       * identifier.
60       */
61      public void test_systemId()
62      {
63  
64  	String expectedName = "anEntity";
65  
66  	String expectedPublicID = null;
67  
68  	String expectedSystemID = "http://www.myorg.org/foo";
69  
70  	String expectedText = "<!ENTITY anEntity SYSTEM \"http://www.myorg.org/foo\" >" ;
71  
72  	ExternalEntityDecl actual = new ExternalEntityDecl
73  	    ( expectedName,
74   	      expectedPublicID,
75  	      expectedSystemID
76  	      );
77  
78  	assertEquals
79  	    ( "name is correct",
80  	      expectedName,
81  	      actual.getName()
82  	      );
83  
84  	assertEquals
85  	    ( "publicID is correct",
86  	      expectedPublicID,
87  	      actual.getPublicID()
88  	      );
89  
90  	assertEquals
91  	    ( "systemID is correct",
92  	      expectedSystemID,
93  	      actual.getSystemID()
94  	      );
95  
96  	assertEquals
97  	    ( "toString() is correct",
98  	      expectedText,
99  	      actual.toString()
100 	      );
101 
102     }
103 
104     /***
105      * Tests external entity declaration using both SYSTEM and PUBLIC
106      * identifiers.
107      */
108 
109     public void test_publicId_systemId()
110     {
111 
112 	String expectedName = "anEntity";
113 
114 	String expectedPublicID = "-//dom4j//DTD sample";
115 
116 	String expectedSystemID = "http://www.myorg.org/foo";
117 
118 	String expectedText = "<!ENTITY anEntity PUBLIC \"-//dom4j//DTD sample\" \"http://www.myorg.org/foo\" >" ;
119 
120 	ExternalEntityDecl actual = new ExternalEntityDecl
121 	    ( expectedName,
122 	      expectedPublicID,
123 	      expectedSystemID
124 	      );
125 
126 	assertEquals
127 	    ( "name is correct",
128 	      expectedName,
129 	      actual.getName()
130 	      );
131 
132 	assertEquals
133 	    ( "publicID is correct",
134 	      expectedPublicID,
135 	      actual.getPublicID()
136 	      );
137 
138 	assertEquals
139 	    ( "systemID is correct",
140 	      expectedSystemID,
141 	      actual.getSystemID()
142 	      );
143 
144 	assertEquals
145 	    ( "toString() is correct",
146 	      expectedText,
147 	      actual.toString()
148 	      );
149 
150     }
151 
152     // Implementation methods
153     //-------------------------------------------------------------------------                    
154 
155 
156 }
157 
158 
159 
160 /*
161  * Redistribution and use of this software and associated documentation
162  * ("Software"), with or without modification, are permitted provided
163  * that the following conditions are met:
164  *
165  * 1. Redistributions of source code must retain copyright
166  *    statements and notices.  Redistributions must also contain a
167  *    copy of this document.
168  *
169  * 2. Redistributions in binary form must reproduce the
170  *    above copyright notice, this list of conditions and the
171  *    following disclaimer in the documentation and/or other
172  *    materials provided with the distribution.
173  *
174  * 3. The name "DOM4J" must not be used to endorse or promote
175  *    products derived from this Software without prior written
176  *    permission of MetaStuff, Ltd.  For written permission,
177  *    please contact dom4j-info@metastuff.com.
178  *
179  * 4. Products derived from this Software may not be called "DOM4J"
180  *    nor may "DOM4J" appear in their names without prior written
181  *    permission of MetaStuff, Ltd. DOM4J is a registered
182  *    trademark of MetaStuff, Ltd.
183  *
184  * 5. Due credit should be given to the DOM4J Project - 
185  *    http://www.dom4j.org
186  *
187  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
188  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
189  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
190  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
191  * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
192  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
193  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
194  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
195  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
196  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
197  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
198  * OF THE POSSIBILITY OF SUCH DAMAGE.
199  *
200  * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
201  *
202  * $Id: TestExternalEntityDecl.java,v 1.4 2004/06/25 08:03:49 maartenc Exp $
203  */