Skip to content

Commit f6bcab4

Browse files
committed
[test] Add tests for WebDAV XML Declaration Serialization
1 parent 581a05c commit f6bcab4

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

extensions/webdav/src/main/resources/org/exist/webdav/webdav.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@
2727
#expand-xincludes=no
2828
#process-xsl-pi=no
2929
#encoding=UTF-8
30-
#omit-xml-declaration=no
30+
omit-xml-declaration=yes
31+
omit-original-xml-declaration=yes
3132
output-doctype=yes

extensions/webdav/src/test/java/org/exist/webdav/SerializationTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ public class SerializationTest {
4949
"<!DOCTYPE bookmap PUBLIC \"-//OASIS//DTD DITA BookMap//EN\" \"bookmap.dtd\">\n" +
5050
"<bookmap id=\"bookmap-1\"/>";
5151

52+
private static final String XML_WITH_XMLDECL =
53+
"<?xml version=\"1.1\" encoding=\"ISO-8859-1\" standalone=\"yes\"?>\n" +
54+
"<bookmap id=\"bookmap-2\"/>";
55+
5256
private static String PREV_PROPFIND_METHOD_XML_SIZE = null;
5357

5458
@ClassRule
@@ -103,4 +107,37 @@ public void getDocTypeDefault() throws IOException, NotAuthorizedException, BadR
103107
resource.downloadTo(tempRetrieveFile, null);
104108
assertEquals(XML_WITH_DOCTYPE, new String(Files.readAllBytes(tempRetrieveFile.toPath()), UTF_8));
105109
}
110+
111+
@Test
112+
public void getXmlDeclDefault() throws IOException, NotAuthorizedException, BadRequestException, HttpException, ConflictException, NotFoundException {
113+
final String docName = "test-with-xmldecl.xml";
114+
final HostBuilder builder = new HostBuilder();
115+
builder.setServer("localhost");
116+
final int port = EXIST_WEB_SERVER.getPort();
117+
builder.setPort(port);
118+
builder.setRootPath("webdav/db");
119+
final Host host = builder.buildHost();
120+
121+
// workaround pre-emptive auth issues of Milton Client
122+
final AbstractHttpClient httpClient = (AbstractHttpClient)host.getClient();
123+
httpClient.addRequestInterceptor(new AlwaysBasicPreAuth(TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD));
124+
125+
final Folder folder = host.getFolder("/");
126+
assertNotNull(folder);
127+
128+
// store document
129+
final byte data[] = XML_WITH_XMLDECL.getBytes(UTF_8);
130+
final java.io.File tmpStoreFile = TEMP_FOLDER.newFile();
131+
Files.write(tmpStoreFile.toPath(), data);
132+
assertNotNull(folder.uploadFile(docName, tmpStoreFile, null));
133+
134+
// retrieve document
135+
final Resource resource = folder.child(docName);
136+
assertNotNull(resource);
137+
assertTrue(resource instanceof File);
138+
assertEquals("application/xml", ((File) resource).contentType);
139+
final java.io.File tempRetrieveFile = TEMP_FOLDER.newFile();
140+
resource.downloadTo(tempRetrieveFile, null);
141+
assertEquals("<bookmap id=\"bookmap-2\"/>", new String(Files.readAllBytes(tempRetrieveFile.toPath()), UTF_8));
142+
}
106143
}

0 commit comments

Comments
 (0)