|
35 | 35 | import org.w3c.dom.Element; |
36 | 36 | import org.xml.sax.SAXException; |
37 | 37 |
|
| 38 | +import com.fasterxml.jackson.core.JsonParser; |
38 | 39 | import com.fasterxml.jackson.core.JsonProcessingException; |
39 | 40 | import com.fasterxml.jackson.databind.JsonNode; |
40 | 41 | import com.fasterxml.jackson.databind.ObjectMapper; |
|
50 | 51 | import com.marklogic.client.io.DOMHandle; |
51 | 52 | import com.marklogic.client.io.Format; |
52 | 53 | import com.marklogic.client.io.JacksonHandle; |
| 54 | +import com.marklogic.client.io.JacksonParserHandle; |
53 | 55 | import com.marklogic.client.io.StringHandle; |
54 | 56 | import com.marklogic.client.io.DocumentMetadataHandle.Capability; |
55 | 57 | import com.marklogic.client.query.QueryManager; |
@@ -378,5 +380,65 @@ public void testBulkSearchQBEWithJSONCombinedQuery() throws IOException, ParserC |
378 | 380 | assertEquals("document count", 102,page.getTotalSize()); |
379 | 381 |
|
380 | 382 | } |
| 383 | + |
| 384 | + /* |
| 385 | + * This test method verifies if JacksonParserHandle class supports SearchReadHandle. |
| 386 | + * Verifies Git Issue 116. The test functionality is same as testBulkSearchQBEWithJSONResponseFormat. |
| 387 | + */ |
| 388 | + |
| 389 | + @Test |
| 390 | + public void testBulkSearchQBEResponseInParserHandle() throws IOException, ParserConfigurationException, SAXException, TransformerException { |
| 391 | + int count; |
| 392 | + |
| 393 | + //Creating a xml document manager for bulk search |
| 394 | + XMLDocumentManager docMgr = client.newXMLDocumentManager(); |
| 395 | + //using QBE for query definition and set the search criteria |
| 396 | + |
| 397 | + QueryManager queryMgr = client.newQueryManager(); |
| 398 | + String queryAsString = "{\"$query\": { \"says\": {\"$word\":\"woof\",\"$exact\": false}}}"; |
| 399 | + RawQueryByExampleDefinition qd = queryMgr.newRawQueryByExampleDefinition(new StringHandle(queryAsString).withFormat(Format.JSON)); |
381 | 400 |
|
| 401 | + // set document manager level settings for search response |
| 402 | + docMgr.setPageLength(25); |
| 403 | + docMgr.setSearchView(QueryView.RESULTS); |
| 404 | + docMgr.setNonDocumentFormat(Format.JSON); |
| 405 | + |
| 406 | + // Search for documents where content has bar and get first result record, get JacksonParserHandle on it,Use DOMHandle to read results |
| 407 | + JacksonParserHandle sh = new JacksonParserHandle(); |
| 408 | + DocumentPage page; |
| 409 | + |
| 410 | + long pageNo=1; |
| 411 | + do{ |
| 412 | + count=0; |
| 413 | + page = docMgr.search(qd, pageNo,sh); |
| 414 | + if(pageNo >1){ |
| 415 | + assertFalse("Is this first Page", page.isFirstPage()); |
| 416 | + assertTrue("Is page has previous page ?",page.hasPreviousPage()); |
| 417 | + } |
| 418 | + while(page.hasNext()){ |
| 419 | + DocumentRecord rec = page.next(); |
| 420 | + rec.getFormat(); |
| 421 | + validateRecord(rec,Format.JSON); |
| 422 | + System.out.println(rec.getContent(new StringHandle()).get().toString()); |
| 423 | + count++; |
| 424 | + } |
| 425 | + |
| 426 | + assertEquals("document count", page.size(),count); |
| 427 | + pageNo = pageNo + page.getPageSize(); |
| 428 | + }while(!page.isLastPage() && page.hasContent() ); |
| 429 | + |
| 430 | + ObjectMapper mapper = new ObjectMapper(); |
| 431 | + JsonParser jsonParser = sh.get(); |
| 432 | + |
| 433 | + JsonNode jnode = null; |
| 434 | + jnode = mapper.readValue(jsonParser,JsonNode.class); |
| 435 | + |
| 436 | + assertTrue("Page start in results and on page", jnode.get("start").asLong() == page.getStart()); |
| 437 | + |
| 438 | + assertEquals("page count is ",5,page.getTotalPages()); |
| 439 | + assertTrue("Page has previous page ?",page.hasPreviousPage()); |
| 440 | + assertEquals("page size", 25,page.getPageSize()); |
| 441 | + assertEquals("document count", 102,page.getTotalSize()); |
| 442 | + |
| 443 | + } |
382 | 444 | } |
0 commit comments