2020
2121import java .io .IOException ;
2222
23- import javax .xml .namespace .QName ;
2423import javax .xml .parsers .ParserConfigurationException ;
2524import javax .xml .transform .TransformerException ;
2625
26+ import org .custommonkey .xmlunit .exceptions .XpathException ;
27+ import org .junit .AfterClass ;
28+ import org .junit .BeforeClass ;
29+ import org .junit .Test ;
2730import org .w3c .dom .Document ;
2831import org .xml .sax .SAXException ;
2932
3235import com .marklogic .client .DatabaseClientFactory .Authentication ;
3336import com .marklogic .client .admin .QueryOptionsManager ;
3437import com .marklogic .client .admin .ServerConfigurationManager ;
35- import com .marklogic .client .admin .config .QueryOptionsBuilder ;
3638import com .marklogic .client .io .DOMHandle ;
3739import com .marklogic .client .io .Format ;
38- import com .marklogic .client .io .QueryOptionsHandle ;
3940import com .marklogic .client .io .StringHandle ;
4041import com .marklogic .client .query .QueryManager ;
4142import com .marklogic .client .query .StructuredQueryBuilder ;
4243import com .marklogic .client .query .StructuredQueryBuilder .Operator ;
4344import com .marklogic .client .query .StructuredQueryDefinition ;
44-
45- import org .custommonkey .xmlunit .exceptions .XpathException ;
46- import org .junit .*;
4745public class TestBug18801 extends BasicJavaClientREST {
4846
4947 private static String dbName = "Bug18801DB" ;
@@ -57,73 +55,70 @@ public static void setUp() throws Exception
5755 setupAppServicesConstraint (dbName );
5856 }
5957
60- @ SuppressWarnings ("deprecation" )
6158@ Test
62- public void testDefaultFacetValue () throws IOException , ParserConfigurationException , SAXException , XpathException , TransformerException
63- {
64- System .out .println ("Running testDefaultFacetValue" );
65-
66- String [] filenames = {"constraint1.xml" , "constraint2.xml" , "constraint3.xml" , "constraint4.xml" , "constraint5.xml" };
59+ public void testDefaultFacetValue () throws IOException , ParserConfigurationException , SAXException , XpathException , TransformerException
60+ {
61+ System .out .println ("Running testDefaultFacetValue" );
62+
63+ String [] filenames = {"constraint1.xml" , "constraint2.xml" , "constraint3.xml" , "constraint4.xml" , "constraint5.xml" };
6764
68- DatabaseClient client = DatabaseClientFactory .newClient ("localhost" , 8011 , "rest-admin" , "x" , Authentication .DIGEST );
69-
70- // set query option validation to true
71- ServerConfigurationManager srvMgr = client .newServerConfigManager ();
72- srvMgr .readConfiguration ();
73- srvMgr .setQueryOptionValidation (true );
74- srvMgr .writeConfiguration ();
75-
76- // write docs
77- for (String filename : filenames )
78- {
79- writeDocumentUsingInputStreamHandle (client , filename , "/def-facet/" , "XML" );
80- }
65+ DatabaseClient client = DatabaseClientFactory .newClient ("localhost" , 8011 , "rest-admin" , "x" , Authentication .DIGEST );
66+
67+ // set query option validation to true
68+ ServerConfigurationManager srvMgr = client .newServerConfigManager ();
69+ srvMgr .readConfiguration ();
70+ srvMgr .setQueryOptionValidation (true );
71+ srvMgr .writeConfiguration ();
72+
73+ // write docs
74+ for (String filename : filenames )
75+ {
76+ writeDocumentUsingInputStreamHandle (client , filename , "/def-facet/" , "XML" );
77+ }
8178
82- // create query options manager
83- QueryOptionsManager optionsMgr = client .newServerConfigManager ().newQueryOptionsManager ();
84-
85- // create query options builder
86- QueryOptionsBuilder builder = new QueryOptionsBuilder ();
87-
88- // create query options handle
89- QueryOptionsHandle handle = new QueryOptionsHandle ();
90-
91- // build query options
92- handle .withConstraints (builder .constraint ("pop" ,
93- builder .range (builder .elementRangeIndex (new QName ("popularity" ),
94- builder .rangeType ("xs:int" )))));
95-
96- // write query options
97- optionsMgr .writeOptions ("FacetValueOpt" , handle );
98-
99- // read query option
100- StringHandle readHandle = new StringHandle ();
101- readHandle .setFormat (Format .XML );
102- optionsMgr .readOptions ("FacetValueOpt" , readHandle );
103- String output = readHandle .get ();
104- System .out .println (output );
79+ // create query options manager
80+ QueryOptionsManager optionsMgr = client .newServerConfigManager ().newQueryOptionsManager ();
81+
82+ // create query options builder
83+ String opts = new StringBuilder ()
84+ .append ("<search:options xmlns:search=\" http://marklogic.com/appservices/search\" >" )
85+ .append ("<search:constraint name=\" pop\" >" )
86+ .append ("<search:range type=\" xs:int\" >" )
87+ .append ("<search:element name=\" popularity\" ns=\" \" />" )
88+ .append ("</search:range>" )
89+ .append ("</search:constraint>" )
90+ .append ("</search:options>" ).toString ();
91+ // build and write query options with new handle
92+ optionsMgr .writeOptions ("FacetValueOpt" , new StringHandle (opts ));
93+
94+ // read query option
95+ StringHandle readHandle = new StringHandle ();
96+ readHandle .setFormat (Format .XML );
97+ optionsMgr .readOptions ("FacetValueOpt" , readHandle );
98+ String output = readHandle .get ();
99+ System .out .println (output );
105100
106- // create query manager
107- QueryManager queryMgr = client .newQueryManager ();
108-
109- // create query def
110- StructuredQueryBuilder qb = queryMgr .newStructuredQueryBuilder ("FacetValueOpt" );
111- StructuredQueryDefinition queryFinal = qb .rangeConstraint ("pop" , Operator .EQ , "5" );
112-
113- // create handle
114- DOMHandle resultsHandle = new DOMHandle ();
115- queryMgr .search (queryFinal , resultsHandle );
116-
117- // get the result
118- Document resultDoc = resultsHandle .get ();
119- //System.out.println(convertXMLDocumentToString(resultDoc));
120-
121- assertXpathEvaluatesTo ("pop" , "string(//*[local-name()='response']//*[local-name()='facet']//@*[local-name()='name'])" , resultDoc );
122- assertXpathEvaluatesTo ("3" , "string(//*[local-name()='response']//*[local-name()='facet']/*[local-name()='facet-value']//@*[local-name()='count'])" , resultDoc );
123-
124- // release client
125- client .release ();
126- }
101+ // create query manager
102+ QueryManager queryMgr = client .newQueryManager ();
103+
104+ // create query def
105+ StructuredQueryBuilder qb = queryMgr .newStructuredQueryBuilder ("FacetValueOpt" );
106+ StructuredQueryDefinition queryFinal = qb .rangeConstraint ("pop" , Operator .EQ , "5" );
107+
108+ // create handle
109+ DOMHandle resultsHandle = new DOMHandle ();
110+ queryMgr .search (queryFinal , resultsHandle );
111+
112+ // get the result
113+ Document resultDoc = resultsHandle .get ();
114+ //System.out.println(convertXMLDocumentToString(resultDoc));
115+
116+ assertXpathEvaluatesTo ("pop" , "string(//*[local-name()='response']//*[local-name()='facet']//@*[local-name()='name'])" , resultDoc );
117+ assertXpathEvaluatesTo ("3" , "string(//*[local-name()='response']//*[local-name()='facet']/*[local-name()='facet-value']//@*[local-name()='count'])" , resultDoc );
118+
119+ // release client
120+ client .release ();
121+ }
127122 @ AfterClass
128123 public static void tearDown () throws Exception
129124 {
0 commit comments