Skip to content

Commit 1e9852b

Browse files
Ajit GeorgeAjit George
authored andcommitted
Test method for Git Issue 116
1 parent 34e537d commit 1e9852b

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

test-complete/src/test/java/com/marklogic/client/functionaltest/TestBulkSearchEWithQBE.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.w3c.dom.Element;
3636
import org.xml.sax.SAXException;
3737

38+
import com.fasterxml.jackson.core.JsonParser;
3839
import com.fasterxml.jackson.core.JsonProcessingException;
3940
import com.fasterxml.jackson.databind.JsonNode;
4041
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -50,6 +51,7 @@
5051
import com.marklogic.client.io.DOMHandle;
5152
import com.marklogic.client.io.Format;
5253
import com.marklogic.client.io.JacksonHandle;
54+
import com.marklogic.client.io.JacksonParserHandle;
5355
import com.marklogic.client.io.StringHandle;
5456
import com.marklogic.client.io.DocumentMetadataHandle.Capability;
5557
import com.marklogic.client.query.QueryManager;
@@ -378,5 +380,65 @@ public void testBulkSearchQBEWithJSONCombinedQuery() throws IOException, ParserC
378380
assertEquals("document count", 102,page.getTotalSize());
379381

380382
}
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));
381400

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+
}
382444
}

0 commit comments

Comments
 (0)