2020import com .marklogic .client .ResourceNotFoundException ;
2121import com .marklogic .client .ResourceNotResendableException ;
2222import com .marklogic .client .admin .QueryOptionsManager ;
23+ import com .marklogic .client .document .DocumentManager ;
24+ import com .marklogic .client .document .DocumentPage ;
25+ import com .marklogic .client .document .DocumentRecord ;
26+ import com .marklogic .client .document .XMLDocumentManager ;
2327import com .marklogic .client .io .DocumentMetadataHandle ;
2428import com .marklogic .client .io .Format ;
2529import com .marklogic .client .io .SearchHandle ;
3236import org .junit .jupiter .api .Test ;
3337import org .slf4j .Logger ;
3438import org .slf4j .LoggerFactory ;
35- import org .xml .sax .SAXException ;
3639
37- import javax .xml .parsers .ParserConfigurationException ;
3840import java .io .ByteArrayOutputStream ;
3941import java .io .IOException ;
4042
4143import static org .junit .jupiter .api .Assertions .*;
4244
4345public class StringSearchTest {
4446 @ SuppressWarnings ("unused" )
45- private static final Logger logger = ( Logger ) LoggerFactory .getLogger (StringSearchTest .class );
47+ private static final Logger logger = LoggerFactory .getLogger (StringSearchTest .class );
4648
4749 @ BeforeAll
4850 public static void beforeClass () {
@@ -54,9 +56,27 @@ public static void beforeClass() {
5456 public static void afterClass () {
5557 }
5658
59+ @ Test
60+ void returnDocumentsWithMetadataValues () {
61+ XMLDocumentManager mgr = Common .client .newXMLDocumentManager ();
62+ mgr .write ("/metadata/test.xml" ,
63+ new DocumentMetadataHandle ().withMetadataValue ("hello" , "world" ),
64+ new StringHandle ("<test>metadataabc</test>" ));
65+
66+ mgr .setMetadataCategories (DocumentManager .Metadata .METADATAVALUES );
67+
68+ DocumentPage page = mgr .search (Common .client .newQueryManager ().newStructuredQueryBuilder ().term ("metadataabc" ), 1 );
69+ assertTrue (page .hasNext ());
70+
71+ DocumentRecord record = page .next ();
72+ assertEquals ("/metadata/test.xml" , record .getUri ());
73+ DocumentMetadataHandle .DocumentMetadataValues values = record .getMetadata (new DocumentMetadataHandle ()).getMetadataValues ();
74+ assertEquals ("world" , values .get ("hello" ));
75+ }
76+
5777 @ Test
5878 public void testStringSearch ()
59- throws IOException , ParserConfigurationException , SAXException , FailedRequestException , ForbiddenUserException ,
79+ throws FailedRequestException , ForbiddenUserException ,
6080 ResourceNotFoundException , ResourceNotResendableException
6181 {
6282 String optionsName = writeOptions ();
0 commit comments