Skip to content

Commit ed54d7b

Browse files
Ajit GeorgeAjit George
authored andcommitted
Added methods to verify additional values method for POJO and XML
documents
1 parent 8ca7923 commit ed54d7b

File tree

2 files changed

+635
-424
lines changed

2 files changed

+635
-424
lines changed

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

Lines changed: 124 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@
1616

1717
package com.marklogic.client.functionaltest;
1818

19+
import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
1920
import static org.junit.Assert.*;
2021

22+
import java.io.File;
2123
import java.io.IOException;
24+
import java.util.Calendar;
2225
import java.util.HashMap;
2326

2427
import javax.xml.parsers.ParserConfigurationException;
2528
import javax.xml.transform.TransformerException;
2629

30+
import org.custommonkey.xmlunit.exceptions.XpathException;
2731
import org.junit.After;
2832
import org.junit.AfterClass;
2933
import org.junit.Before;
@@ -47,14 +51,17 @@
4751
import com.marklogic.client.document.XMLDocumentManager;
4852
import com.marklogic.client.io.DOMHandle;
4953
import com.marklogic.client.io.DocumentMetadataHandle;
54+
import com.marklogic.client.io.FileHandle;
5055
import com.marklogic.client.io.Format;
5156
import com.marklogic.client.io.JacksonHandle;
5257
import com.marklogic.client.io.SearchHandle;
5358
import com.marklogic.client.io.StringHandle;
5459
import com.marklogic.client.io.DocumentMetadataHandle.Capability;
5560
import com.marklogic.client.query.MatchDocumentSummary;
5661
import com.marklogic.client.query.MatchLocation;
62+
import com.marklogic.client.query.QueryDefinition;
5763
import com.marklogic.client.query.QueryManager;
64+
import com.marklogic.client.query.StructuredQueryBuilder;
5865
import com.marklogic.client.query.QueryManager.QueryView;
5966
import com.marklogic.client.query.StringQueryDefinition;
6067

@@ -393,5 +400,121 @@ public void testBulkSearchSQDwithTransactionsandDOMHandle() throws Exception{
393400
assertNull("Total search results after rollback are ",results.get().getElementsByTagNameNS("*", "response").item(0).getAttributes().getNamedItem("total"));
394401

395402
}
403+
404+
405+
/* Searching for boolean and string in XML element using value query.
406+
* Purpose: To validate QueryBuilder's new value methods (in 8.0) in XML document using an element.
407+
*
408+
* Load a file that has a boolean value in a XML attribute and use query def to search on that boolean value
409+
*
410+
* Methods used : value(StructuredQueryBuilder.TextIndex index, boolean)
411+
* value(StructuredQueryBuilder.TextIndex index, String)
412+
*/
413+
@Test
414+
public void testQueryBuilderValueWithBooleanAndString() throws XpathException, SAXException, IOException {
415+
416+
String docId[] = {"play-persons.xml"};
417+
418+
TextDocumentManager docMgr = client.newTextDocumentManager();
419+
QueryManager queryMgr = client.newQueryManager();
420+
DocumentWriteSet writeset = docMgr.newWriteSet();
421+
422+
// Put meta-data
423+
424+
DocumentMetadataHandle metadataHandle = new DocumentMetadataHandle();
425+
metadataHandle.getCollections().addAll("my-collection1","my-collection2");
426+
metadataHandle.getPermissions().add("app-user", Capability.UPDATE, Capability.READ);
427+
metadataHandle.getProperties().put("reviewed", true);
428+
metadataHandle.getProperties().put("myString", "foo");
429+
metadataHandle.getProperties().put("myInteger", 10);
430+
metadataHandle.getProperties().put("myDecimal", 34.56678);
431+
metadataHandle.getProperties().put("myCalendar", Calendar.getInstance().get(Calendar.YEAR));
432+
metadataHandle.setQuality(23);
433+
434+
writeset.addDefault(metadataHandle);
435+
436+
// Create a new document using StringHandle
437+
StringBuffer strBuf = new StringBuffer();
438+
439+
strBuf.append("<PLAY>");
440+
strBuf.append("<TITLE>All's Well That Ends Well</TITLE>");
441+
strBuf.append("<PERSONAE>");
442+
strBuf.append("<TITLE>Dramatis Personae</TITLE>");
443+
444+
strBuf.append("<PGROUP>");
445+
strBuf.append("<subgroup>true</subgroup>");
446+
447+
strBuf.append("<PERSONA>KING OF FRANCE</PERSONA>");
448+
strBuf.append("<PERSONA>DUKE OF FLORENCE</PERSONA>");
449+
strBuf.append("<PERSONA>BERTRAM, Count of Rousillon.</PERSONA>");
450+
strBuf.append("<PERSONA>LAFEU, an old lord.</PERSONA>");
451+
strBuf.append("</PGROUP>");
452+
453+
strBuf.append("<PGROUP>");
454+
strBuf.append("<subgroup>false</subgroup>");
455+
456+
strBuf.append("<PERSONA>PAROLLES, a follower of Bertram.</PERSONA>");
457+
strBuf.append("<PERSONA>A Page. </PERSONA>");
458+
strBuf.append("</PGROUP>");
459+
460+
strBuf.append("<PGROUP>");
461+
strBuf.append("<subgroup>false</subgroup>");
462+
strBuf.append("<PERSONA>COUNTESS OF ROUSILLON, mother to Bertram. </PERSONA>");
463+
strBuf.append("<PERSONA>HELENA, a gentlewoman protected by the Countess.</PERSONA>");
464+
strBuf.append("<PERSONA>An old Widow of Florence. </PERSONA>");
465+
strBuf.append("<PERSONA>DIANA, daughter to the Widow.</PERSONA>");
466+
strBuf.append("</PGROUP>");
467+
468+
strBuf.append("<PGROUP>");
469+
strBuf.append("<subgroup>false</subgroup>");
470+
strBuf.append("<PERSONA>VIOLENTA</PERSONA>");
471+
strBuf.append("<PERSONA>MARIANA</PERSONA>");
472+
strBuf.append("<GRPDESCR>neighbours and friends to the Widow.</GRPDESCR>");
473+
strBuf.append("</PGROUP>");
474+
475+
strBuf.append("<PERSONA>Lords, Officers, Soldiers, &amp;c., French and Florentine.</PERSONA>");
476+
strBuf.append("</PERSONAE>");
477+
strBuf.append("</PLAY>");
478+
479+
writeset.add("/1/"+docId[0], new StringHandle().with(strBuf.toString()));
480+
docMgr.write(writeset);
481+
482+
docMgr.write(writeset);
483+
484+
// Search for the range with attribute value true in rangeRelativeBucketConstraintOpt.xml document.
485+
StructuredQueryBuilder qb = new StructuredQueryBuilder();
486+
487+
// Build an object that represents StructuredQueryBuilder.ElementAttribute for use in values method
488+
// that is of type StructuredQueryBuilder.TextIndex
489+
490+
QueryDefinition qd = qb.value(qb.element("subgroup"), false);
491+
492+
// Create handle for the result
493+
StringHandle resultsHandle = new StringHandle().withFormat(Format.XML);
494+
queryMgr.search(qd, resultsHandle);
495+
496+
// Get the result
497+
String resultDoc = resultsHandle.get();
498+
499+
System.out.println(resultDoc);
500+
//Verify that search response has found 1 element attribute
501+
assertXpathEvaluatesTo("fn:doc(\"/1/play-persons.xml\")", "string(//*[local-name()='response']//*[local-name()='result']//@*[local-name()='path'])", resultDoc);
502+
assertXpathEvaluatesTo("3", "count(//*[local-name()='response']//*[local-name()='match'])", resultDoc);
503+
504+
// Search for the following royal (XML ELEMENT) in all-well.xml document.
505+
StructuredQueryBuilder qbStr = new StructuredQueryBuilder();
506+
QueryDefinition qdStr = qbStr.value(qbStr.element("PERSONA"), "KING OF FRANCE","DUKE OF FLORENCE", "BERTRAM, Count of Rousillon.","LAFEU, an old lord.");
507+
508+
// Create handle for the result
509+
StringHandle resultsHandleStr = new StringHandle().withFormat(Format.XML);
510+
queryMgr.search(qdStr, resultsHandleStr);
511+
512+
// Get the result
513+
String resultDocStr = resultsHandleStr.get();
514+
515+
System.out.println(resultDocStr);
516+
//Verify that search response has found 4 PERSONA elements under /PLAY/PERSONAE
517+
assertXpathEvaluatesTo("fn:doc(\"/1/play-persons.xml\")", "string(//*[local-name()='response']//*[local-name()='result']//@*[local-name()='path'])", resultDocStr);
518+
assertXpathEvaluatesTo("4", "count(//*[local-name()='response']//*[local-name()='match'])", resultDocStr);
519+
}
396520
}
397-

0 commit comments

Comments
 (0)