20
20
21
21
import java .io .IOException ;
22
22
23
- import javax .xml .namespace .QName ;
24
23
import javax .xml .parsers .ParserConfigurationException ;
25
24
import javax .xml .transform .TransformerException ;
26
25
26
+ import org .custommonkey .xmlunit .exceptions .XpathException ;
27
+ import org .junit .AfterClass ;
28
+ import org .junit .BeforeClass ;
29
+ import org .junit .Test ;
27
30
import org .w3c .dom .Document ;
28
31
import org .xml .sax .SAXException ;
29
32
32
35
import com .marklogic .client .DatabaseClientFactory .Authentication ;
33
36
import com .marklogic .client .admin .QueryOptionsManager ;
34
37
import com .marklogic .client .admin .ServerConfigurationManager ;
35
- import com .marklogic .client .admin .config .QueryOptionsBuilder ;
36
38
import com .marklogic .client .io .DOMHandle ;
37
39
import com .marklogic .client .io .Format ;
38
- import com .marklogic .client .io .QueryOptionsHandle ;
39
40
import com .marklogic .client .io .StringHandle ;
40
41
import com .marklogic .client .query .QueryManager ;
41
42
import com .marklogic .client .query .StructuredQueryBuilder ;
42
43
import com .marklogic .client .query .StructuredQueryBuilder .Operator ;
43
44
import com .marklogic .client .query .StructuredQueryDefinition ;
44
-
45
- import org .custommonkey .xmlunit .exceptions .XpathException ;
46
- import org .junit .*;
47
45
public class TestBug18801 extends BasicJavaClientREST {
48
46
49
47
private static String dbName = "Bug18801DB" ;
@@ -57,73 +55,70 @@ public static void setUp() throws Exception
57
55
setupAppServicesConstraint (dbName );
58
56
}
59
57
60
- @ SuppressWarnings ("deprecation" )
61
58
@ 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" };
67
64
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
+ }
81
78
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 );
105
100
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
+ }
127
122
@ AfterClass
128
123
public static void tearDown () throws Exception
129
124
{
0 commit comments