44package com .marklogic .client .test .document ;
55
66import 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 ;
910import com .marklogic .client .io .StringHandle ;
11+ import com .marklogic .client .query .StructuredQueryBuilder ;
12+ import com .marklogic .client .query .StructuredQueryDefinition ;
1013import com .marklogic .client .test .Common ;
14+ import org .junit .jupiter .api .Disabled ;
1115import org .junit .jupiter .api .Test ;
1216
17+ import java .util .ArrayList ;
18+ import java .util .List ;
19+
1320import static org .junit .jupiter .api .Assertions .assertEquals ;
1421import static org .junit .jupiter .api .Assertions .assertTrue ;
1522
@@ -29,4 +36,35 @@ void test() {
2936 DocumentRecord record = page .next ();
3037 assertEquals (uri , record .getUri ());
3138 }
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+ DatabaseClient client = Common .newClient ();
45+
46+ writeEmptyDocWithFileExtension (client , collection );
47+
48+ GenericDocumentManager documentManager = client .newDocumentManager ();
49+ StructuredQueryDefinition query = new StructuredQueryBuilder ().collection (collection );
50+ DocumentPage documentPage = documentManager .search (query , 1 );
51+ DocumentRecord documentRecord = documentPage .next ();
52+ String uri = documentRecord .getUri ();
53+ assertEquals ("/test/empty" , uri , "The URI of the empty document should match the one written." );
54+ }
55+
56+ protected List <String > writeEmptyDocWithFileExtension (DatabaseClient client , String ... collections ) {
57+ DocumentMetadataHandle metadata = new DocumentMetadataHandle ()
58+ .withCollections (collections )
59+ .withPermission ("rest-reader" , DocumentMetadataHandle .Capability .READ , DocumentMetadataHandle .Capability .UPDATE );
60+ JSONDocumentManager mgr = client .newJSONDocumentManager ();
61+ DocumentWriteSet set = mgr .newWriteSet ();
62+ BytesHandle emptyBytesHandle = new BytesHandle (new byte [0 ]);
63+ List <String > uris = new ArrayList <>();
64+ String uri = "/test/empty" ;
65+ uris .add (uri );
66+ set .add (uri , metadata , emptyBytesHandle );
67+ mgr .write (set );
68+ return uris ;
69+ }
3270}
0 commit comments