4
4
package com .marklogic .client .test .document ;
5
5
6
6
import com .marklogic .client .DatabaseClient ;
7
- import com .marklogic .client .document .DocumentPage ;
8
- import com .marklogic .client .document .DocumentRecord ;
7
+ import com .marklogic .client .document .*;
8
+ import com .marklogic .client .io .BytesHandle ;
9
+ import com .marklogic .client .io .DocumentMetadataHandle ;
9
10
import com .marklogic .client .io .StringHandle ;
11
+ import com .marklogic .client .query .StructuredQueryBuilder ;
12
+ import com .marklogic .client .query .StructuredQueryDefinition ;
10
13
import com .marklogic .client .test .Common ;
14
+ import org .junit .jupiter .api .Disabled ;
11
15
import org .junit .jupiter .api .Test ;
12
16
13
17
import static org .junit .jupiter .api .Assertions .assertEquals ;
@@ -20,13 +24,49 @@ void test() {
20
24
Common .deleteUrisWithPattern ("/aaa-page/*" );
21
25
22
26
final String uri = "/aaa-page/太田佳伸のXMLファイル.xml" ;
23
- DatabaseClient client = Common .newClient ();
24
- client .newXMLDocumentManager ().write (uri , Common .newDefaultMetadata (),
25
- new StringHandle ("<test>太田佳伸のXMLファイル</test>" ));
26
-
27
- DocumentPage page = client .newXMLDocumentManager ().read (uri );
28
- assertTrue (page .hasNext ());
29
- DocumentRecord record = page .next ();
30
- assertEquals (uri , record .getUri ());
27
+ DocumentRecord documentRecord ;
28
+ try (DatabaseClient client = Common .newClient ()) {
29
+ client .newXMLDocumentManager ().write (uri , Common .newDefaultMetadata (),
30
+ new StringHandle ("<test>太田佳伸のXMLファイル</test>" ));
31
+
32
+ try (DocumentPage page = client .newXMLDocumentManager ().read (uri )) {
33
+ assertTrue (page .hasNext ());
34
+ documentRecord = page .next ();
35
+ }
36
+ }
37
+ assertEquals (uri , documentRecord .getUri ());
38
+ }
39
+
40
+ @ Test
41
+ @ Disabled ("Disabling for now because this seems to be a server bug." )
42
+ void testEmptyDocWithNoExtension () {
43
+ final String collection = "empty-binary-test" ;
44
+
45
+ try (DatabaseClient client = Common .newClient ()) {
46
+ writeEmptyDocWithFileExtension (client , collection );
47
+
48
+ JSONDocumentManager documentManager = client .newJSONDocumentManager ();
49
+ StructuredQueryDefinition query = new StructuredQueryBuilder ().collection (collection );
50
+ DocumentRecord documentRecord ;
51
+ try (DocumentPage documentPage = documentManager .search (query , 1 )) {
52
+ assertTrue (documentPage .hasNext (), "Expected a document in the page, but none was found." );
53
+ documentRecord = documentPage .next ();
54
+ }
55
+ String uri = documentRecord .getUri ();
56
+ assertEquals ("/test/empty" , uri , "The URI of the empty document should match the one written." );
57
+ }
58
+ }
59
+
60
+ protected void writeEmptyDocWithFileExtension (DatabaseClient client , String ... collections ) {
61
+ DocumentMetadataHandle metadata = new DocumentMetadataHandle ()
62
+ .withCollections (collections )
63
+ .withPermission ("rest-reader" , DocumentMetadataHandle .Capability .READ , DocumentMetadataHandle .Capability .UPDATE );
64
+ // This needs to be a JSON document manager because the empty document is written without a format.
65
+ JSONDocumentManager mgr = client .newJSONDocumentManager ();
66
+ DocumentWriteSet set = mgr .newWriteSet ();
67
+ BytesHandle emptyBytesHandle = new BytesHandle (new byte [0 ]);
68
+ String uri = "/test/empty" ;
69
+ set .add (uri , metadata , emptyBytesHandle );
70
+ mgr .write (set );
31
71
}
32
72
}
0 commit comments