23
23
24
24
import org .exist .Namespaces ;
25
25
import org .exist .TestUtils ;
26
+ import org .exist .storage .serializers .EXistOutputKeys ;
26
27
import org .exist .test .ExistWebServer ;
27
28
import org .junit .After ;
28
29
import org .junit .Before ;
@@ -77,7 +78,7 @@ private final String getBaseUri() {
77
78
78
79
private static final String EOL = System .getProperty ("line.separator" );
79
80
80
- private static final String TEST_COLLECTION_NAME = "test" ;
81
+ private static final String TEST_COLLECTION_NAME = "xmlrpc-serialization- test" ;
81
82
82
83
private static final String XML_DOC_NAME = "defaultns.xml" ;
83
84
private static final String XML =
@@ -107,6 +108,12 @@ private final String getBaseUri() {
107
108
" <entry xmlns=\" \" xml:id=\" aargh\" />" + EOL +
108
109
"</root>" ;
109
110
111
+ private static final XmldbURI TEST_XML_DOC_WITH_DOCTYPE_URI = XmldbURI .create ("test-with-doctype.xml" );
112
+
113
+ private static final String XML_WITH_DOCTYPE =
114
+ "<!DOCTYPE bookmap PUBLIC \" -//OASIS//DTD DITA BookMap//EN\" \" bookmap.dtd\" >\n " +
115
+ "<bookmap id=\" bookmap-1\" />" ;
116
+
110
117
private Collection testCollection ;
111
118
112
119
@ Test
@@ -161,6 +168,40 @@ public void xqueryUpdateNsTest() throws XMLDBException {
161
168
assertXMLEquals (XML_UPDATED_EXPECTED , onDiskResource );
162
169
}
163
170
171
+ @ Test
172
+ public void getDocTypeDefault () throws XMLDBException {
173
+ final Resource res = testCollection .getResource (TEST_XML_DOC_WITH_DOCTYPE_URI .lastSegmentString ());
174
+ assertEquals ("<bookmap id=\" bookmap-1\" />" , res .getContent ());
175
+ }
176
+
177
+ @ Test
178
+ public void getDocTypeNo () throws XMLDBException {
179
+ final String prevOutputDocType = testCollection .getProperty (EXistOutputKeys .OUTPUT_DOCTYPE );
180
+ try {
181
+ final Resource res = testCollection .getResource (TEST_XML_DOC_WITH_DOCTYPE_URI .lastSegmentString ());
182
+ testCollection .setProperty (EXistOutputKeys .OUTPUT_DOCTYPE , "NO" );
183
+ assertEquals ("<bookmap id=\" bookmap-1\" />" , res .getContent ());
184
+ } finally {
185
+ if (prevOutputDocType != null ) {
186
+ testCollection .setProperty (EXistOutputKeys .OUTPUT_DOCTYPE , prevOutputDocType );
187
+ }
188
+ }
189
+ }
190
+
191
+ @ Test
192
+ public void getDocTypeYes () throws XMLDBException {
193
+ final String prevOutputDocType = testCollection .getProperty (EXistOutputKeys .OUTPUT_DOCTYPE );
194
+ try {
195
+ final Resource res = testCollection .getResource (TEST_XML_DOC_WITH_DOCTYPE_URI .lastSegmentString ());
196
+ testCollection .setProperty (EXistOutputKeys .OUTPUT_DOCTYPE , "yes" );
197
+ assertEquals (XML_WITH_DOCTYPE , res .getContent ());
198
+ } finally {
199
+ if (prevOutputDocType != null ) {
200
+ testCollection .setProperty (EXistOutputKeys .OUTPUT_DOCTYPE , prevOutputDocType );
201
+ }
202
+ }
203
+ }
204
+
164
205
private static void assertXMLEquals (final String expected , final Resource actual ) throws XMLDBException {
165
206
final Source srcExpected = Input .fromString (expected ).build ();
166
207
final Source srcActual = Input .fromString (actual .getContent ().toString ()).build ();
@@ -182,6 +223,10 @@ public void setUp() throws XMLDBException {
182
223
final XMLResource res = (XMLResource ) testCollection .createResource (XML_DOC_NAME , "XMLResource" );
183
224
res .setContent (XML );
184
225
testCollection .storeResource (res );
226
+
227
+ final XMLResource res1 = (XMLResource ) testCollection .createResource (TEST_XML_DOC_WITH_DOCTYPE_URI .lastSegmentString (), "XMLResource" );
228
+ res1 .setContent (XML_WITH_DOCTYPE );
229
+ testCollection .storeResource (res1 );
185
230
}
186
231
187
232
@ After
0 commit comments