1515 */
1616package com .marklogic .client .test ;
1717
18+ import static org .junit .Assert .assertEquals ;
1819import static org .junit .Assert .assertFalse ;
1920import static org .junit .Assert .assertNotNull ;
2021import static org .junit .Assert .fail ;
3031import com .marklogic .client .FailedRequestException ;
3132import com .marklogic .client .ForbiddenUserException ;
3233import com .marklogic .client .ResourceNotFoundException ;
33- import com .marklogic .client .admin .NamespacesManager ;
3434import com .marklogic .client .io .SearchHandle ;
3535import com .marklogic .client .query .KeyValueQueryDefinition ;
3636import com .marklogic .client .query .MatchDocumentSummary ;
@@ -41,30 +41,13 @@ public class KeyValueSearchTest {
4141 @ BeforeClass
4242 public static void beforeClass ()
4343 throws ResourceNotFoundException , ForbiddenUserException , FailedRequestException {
44- Common .connectAdmin ();
45-
46- // setup namespaces to test kv with namespaces
47- NamespacesManager nsMgr = Common .client .newServerConfigManager ()
48- .newNamespacesManager ();
49-
50- nsMgr .updatePrefix ("ns1" , "http://marklogic.com/test-ns1" );
51- nsMgr .updatePrefix ("ns2" , "http://marklogic.com/test-ns2" );
52-
53- Common .release ();
5444 Common .connect ();
5545 }
5646
5747 @ AfterClass
5848 public static void afterClass ()
5949 throws ForbiddenUserException , FailedRequestException {
6050 Common .release ();
61- Common .connectAdmin ();
62- NamespacesManager nsMgr = Common .client .newServerConfigManager ()
63- .newNamespacesManager ();
64-
65- nsMgr .deleteAll ();
66-
67- Common .release ();
6851
6952 }
7053
@@ -79,14 +62,15 @@ public void testKVSearch() throws IOException {
7962 assertFalse (results .getMetrics ().getTotalTime () == -1 );
8063
8164 MatchDocumentSummary [] summaries = results .getMatchResults ();
65+ assertNotNull (summaries );
66+ assertEquals ("expected 1 result" , 1 , summaries .length );
8267 for (MatchDocumentSummary summary : summaries ) {
8368 MatchLocation [] locations = summary .getMatchLocations ();
69+ assertEquals ("expected 1 match location" , 1 , locations .length );
8470 for (MatchLocation location : locations ) {
8571 assertNotNull (location .getAllSnippetText ());
8672 }
8773 }
88-
89- assertNotNull (summaries );
9074 }
9175
9276 @ Test (expected =FailedRequestException .class )
@@ -118,20 +102,21 @@ public void testKVSearchGoodNamespacePrefix() throws IOException {
118102 QueryManager queryMgr = Common .client .newQueryManager ();
119103 KeyValueQueryDefinition qdef = queryMgr .newKeyValueDefinition (null );
120104
121- qdef .put (queryMgr .newElementLocator (new QName ("ns1:leaf " )), "leaf3 " );
105+ qdef .put (queryMgr .newElementLocator (new QName ("json:thirdKey " )), "3 " );
122106 SearchHandle results = queryMgr .search (qdef , new SearchHandle ());
123107 assertNotNull (results );
124108 assertFalse (results .getMetrics ().getTotalTime () == -1 );
125109
126110 MatchDocumentSummary [] summaries = results .getMatchResults ();
111+ assertNotNull (summaries );
112+ assertEquals ("expected 1 result" , 1 , summaries .length );
127113 for (MatchDocumentSummary summary : summaries ) {
128114 MatchLocation [] locations = summary .getMatchLocations ();
115+ assertEquals ("expected 1 match location" , 1 , locations .length );
129116 for (MatchLocation location : locations ) {
130117 assertNotNull (location .getAllSnippetText ());
131118 }
132119 }
133-
134- assertNotNull (summaries );
135120 }
136121
137122 @ Test
@@ -145,13 +130,12 @@ public void testJsonSearch() throws IOException {
145130 assertFalse (results .getMetrics ().getTotalTime () == -1 );
146131
147132 MatchDocumentSummary [] summaries = results .getMatchResults ();
133+ assertNotNull (summaries );
148134 for (MatchDocumentSummary summary : summaries ) {
149135 MatchLocation [] locations = summary .getMatchLocations ();
150136 for (MatchLocation location : locations ) {
151137 assertNotNull (location .getAllSnippetText ());
152138 }
153139 }
154-
155- assertNotNull (summaries );
156140 }
157141}
0 commit comments