Skip to content

Commit d4d6064

Browse files
author
ehennum
committed
Bug:20973 confirm result count in search unit tests
git-svn-id: svn+ssh://svn.marklogic.com/project/engsvn/client-api/java/branches/b2_0@158469 62cac252-8da6-4816-9e9d-6dc37b19578c
1 parent bfa38ad commit d4d6064

File tree

3 files changed

+36
-57
lines changed

3 files changed

+36
-57
lines changed

src/test/java/com/marklogic/client/test/KeyValueSearchTest.java

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.marklogic.client.test;
1717

18+
import static org.junit.Assert.assertEquals;
1819
import static org.junit.Assert.assertFalse;
1920
import static org.junit.Assert.assertNotNull;
2021
import static org.junit.Assert.fail;
@@ -30,7 +31,6 @@
3031
import com.marklogic.client.FailedRequestException;
3132
import com.marklogic.client.ForbiddenUserException;
3233
import com.marklogic.client.ResourceNotFoundException;
33-
import com.marklogic.client.admin.NamespacesManager;
3434
import com.marklogic.client.io.SearchHandle;
3535
import com.marklogic.client.query.KeyValueQueryDefinition;
3636
import 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
}

src/test/java/com/marklogic/client/test/StringSearchTest.java

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.marklogic.client.io.SearchHandle;
4646
import com.marklogic.client.io.StringHandle;
4747
import com.marklogic.client.query.FacetResult;
48+
import com.marklogic.client.query.FacetValue;
4849
import com.marklogic.client.query.MatchDocumentSummary;
4950
import com.marklogic.client.query.MatchLocation;
5051
import com.marklogic.client.query.QueryManager;
@@ -83,45 +84,37 @@ public void testStringSearch()
8384

8485
FacetResult[] facets = results.getFacetResults();
8586
assertNotNull(facets);
86-
assertTrue(facets.length > 0);
87+
assertEquals("expected 1 facet", 1, facets.length);
88+
FacetValue[] facetVals = facets[0].getFacetValues();
89+
assertEquals("expected 6 facet values", 6, facetVals.length);
8790

8891
MatchDocumentSummary[] summaries = results.getMatchResults();
89-
assertTrue(summaries.length > 0);
90-
for (MatchDocumentSummary summary : summaries) {
91-
MatchLocation[] locations = summary.getMatchLocations();
92-
for (MatchLocation location : locations) {
93-
assertNotNull(location.getAllSnippetText());
94-
}
95-
}
96-
9792
assertNotNull(summaries);
93+
assertEquals("expected 2 results", 2, summaries.length);
9894
}
9995

10096
@Test
10197
public void testStringSearch2() throws IOException {
10298
QueryManager queryMgr = Common.client.newQueryManager();
10399

104-
// "em-1"
105100
StringQueryDefinition qdef = queryMgr.newStringDefinition();
106101
qdef.setCriteria("10");
107102

108103
SearchHandle handle = new SearchHandle();
109104
handle = queryMgr.search(qdef, handle);
110-
111105
assertNotNull(handle);
112-
}
113106

114-
@Test
115-
public void testStringSearch3() throws IOException {
116-
QueryManager queryMgr = Common.client.newQueryManager();
117-
// "metatest-1"
118-
StringQueryDefinition qdef = queryMgr.newStringDefinition();
119-
qdef.setCriteria("10");
120-
121-
SearchHandle handle = new SearchHandle();
122-
handle = queryMgr.search(qdef, handle);
107+
MatchDocumentSummary[] summaries = handle.getMatchResults();
108+
assertNotNull(summaries);
109+
assertEquals("expected 2 results", 2, summaries.length);
123110

124-
assertNotNull(handle);
111+
for (MatchDocumentSummary summary : summaries) {
112+
MatchLocation[] locations = summary.getMatchLocations();
113+
assertEquals("expected 1 match location", 1, locations.length);
114+
for (MatchLocation location : locations) {
115+
assertNotNull(location.getAllSnippetText());
116+
}
117+
}
125118
}
126119

127120
@Test
@@ -140,7 +133,9 @@ public void testStringSearch4()
140133

141134
FacetResult[] facets = results.getFacetResults();
142135
assertNotNull(facets);
143-
assertTrue(facets.length > 0);
136+
assertEquals("expected 1 facet", 1, facets.length);
137+
FacetValue[] facetVals = facets[0].getFacetValues();
138+
assertEquals("expected 6 facet values", 6, facetVals.length);
144139

145140
MatchDocumentSummary[] summaries = results.getMatchResults();
146141
assertTrue(summaries == null || summaries.length == 0);
@@ -154,7 +149,7 @@ public void testStringSearch4()
154149

155150
summaries = results.getMatchResults();
156151
assertNotNull(summaries);
157-
assertTrue(summaries.length > 0);
152+
assertEquals("expected 2 results", 2, summaries.length);
158153
}
159154

160155
@Test

src/test/java/com/marklogic/client/test/StructuredSearchTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,14 @@ public void testStructuredSearch() throws IOException {
6868

6969
MatchDocumentSummary[] summaries = results.getMatchResults();
7070
assertNotNull(summaries);
71-
assertTrue(summaries.length > 0);
71+
assertEquals("expected 1 result", 1, summaries.length);
7272
for (MatchDocumentSummary summary : summaries) {
7373
MatchLocation[] locations = summary.getMatchLocations();
74+
assertEquals("expected 1 match location", 1, locations.length);
7475
for (MatchLocation location : locations) {
7576
assertNotNull(location.getAllSnippetText());
7677
}
7778
}
78-
79-
assertNotNull(summaries);
8079
}
8180
}
8281

@@ -90,10 +89,10 @@ public void testStructuredSearch1() throws IOException {
9089
}) {
9190

9291
MatchDocumentSummary summary = queryMgr.findOne(t);
93-
if (summary != null) {
94-
GenericDocumentManager docMgr = Common.client.newDocumentManager();
95-
assertTrue("Document exists", docMgr.exists(summary.getUri())!=null);
96-
}
92+
assertNotNull(summary);
93+
94+
GenericDocumentManager docMgr = Common.client.newDocumentManager();
95+
assertNotNull("Document exists", docMgr.exists(summary.getUri()));
9796
}
9897
}
9998

@@ -173,7 +172,8 @@ public void testExtractMetadata() throws SAXException, IOException {
173172

174173
MatchDocumentSummary[] summaries = sh.getMatchResults();
175174
assertNotNull(summaries);
176-
assertTrue(summaries.length > 0);
175+
assertEquals("expected 1 result", 1, summaries.length);
176+
177177
MatchDocumentSummary matchResult = summaries[0];
178178
Document metadata = matchResult.getMetadata();
179179
Element subKey = (Element)

0 commit comments

Comments
 (0)