11/*
2- * Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
2+ * Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
33 */
44package com .marklogic .client .test .document ;
55
66import com .marklogic .client .DatabaseClient ;
7- import com .marklogic .client .document .*;
7+ import com .marklogic .client .document .DocumentPage ;
8+ import com .marklogic .client .document .DocumentRecord ;
9+ import com .marklogic .client .document .JSONDocumentManager ;
810import com .marklogic .client .io .BytesHandle ;
9- import com .marklogic .client .io .DocumentMetadataHandle ;
1011import com .marklogic .client .io .StringHandle ;
1112import com .marklogic .client .query .StructuredQueryBuilder ;
1213import com .marklogic .client .query .StructuredQueryDefinition ;
14+ import com .marklogic .client .test .AbstractClientTest ;
1315import com .marklogic .client .test .Common ;
14- import org .junit .jupiter .api .Disabled ;
1516import org .junit .jupiter .api .Test ;
1617
17- import static org .junit .jupiter .api .Assertions .assertEquals ;
18- import static org .junit .jupiter .api .Assertions .assertTrue ;
18+ import static org .junit .jupiter .api .Assertions .*;
1919
20- class ReadDocumentPageTest {
20+ class ReadDocumentPageTest extends AbstractClientTest {
2121
22+ /**
23+ * Verifies that the jakarta.mail library, instead of javax.mail, can probably read the URI.
24+ * See MLE-15748, which pertains to issues with javax.mail only allowing US-ASCII characters.
25+ */
2226 @ Test
23- void test () {
24- Common .deleteUrisWithPattern ("/aaa-page/*" );
25-
27+ void uriWithNonUsAsciiCharacters () {
2628 final String uri = "/aaa-page/太田佳伸のXMLファイル.xml" ;
2729 DocumentRecord documentRecord ;
2830 try (DatabaseClient client = Common .newClient ()) {
@@ -38,35 +40,27 @@ void test() {
3840 }
3941
4042 @ Test
41- @ Disabled ("Disabling for now because this seems to be a server bug." )
42- void testEmptyDocWithNoExtension () {
43- final String collection = "empty-binary-test" ;
43+ void emptyTextDocument () {
44+ final String uri = "/sample/empty-file.txt" ;
4445
4546 try (DatabaseClient client = Common .newClient ()) {
46- writeEmptyDocWithNoFileExtension (client , collection );
47-
4847 JSONDocumentManager documentManager = client .newJSONDocumentManager ();
49- StructuredQueryDefinition query = new StructuredQueryBuilder ().collection ( collection );
48+ StructuredQueryDefinition query = new StructuredQueryBuilder ().document ( uri );
5049 DocumentRecord documentRecord ;
5150 try (DocumentPage documentPage = documentManager .search (query , 1 )) {
5251 assertTrue (documentPage .hasNext (), "Expected a document in the page, but none was found." );
5352 documentRecord = documentPage .next ();
5453 }
55- String uri = documentRecord .getUri ();
56- assertEquals ("/test/empty" , uri , "The URI of the empty document should match the one written." );
57- }
58- }
54+ String actualUri = documentRecord .getUri ();
55+ assertEquals (uri , actualUri , "The URI of the empty document should match the one written." );
5956
60- protected void writeEmptyDocWithNoFileExtension (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 );
57+ IllegalStateException ex = assertThrows (IllegalStateException .class ,
58+ () -> documentRecord .getContent (new BytesHandle ()));
59+ assertEquals ("No bytes to write" , ex .getMessage (),
60+ "This assertion is documenting existing behavior, where an empty doc will result in an " +
61+ "exception being thrown when an attempt is made to retrieve its content. " +
62+ "This doesn't seem ideal - returning null seems preferable - but it's the " +
63+ "behavior that has likely always existed." );
64+ }
7165 }
7266}
0 commit comments