Skip to content

Commit e622291

Browse files
committed
Can now specify a page length of 0 when searching with OkHttpServices.
1 parent 0c5e2e5 commit e622291

File tree

4 files changed

+93
-1
lines changed

4 files changed

+93
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ ml-development-tools/src/test/ml-modules
3737
ml-development-tools/src/test/java/com/marklogic/client/test/dbfunction/generated
3838

3939
.vscode
40+
docker/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright © 2024 MarkLogic Corporation. All Rights Reserved.
3+
*/
4+
5+
package com.marklogic.client.fastfunctest;
6+
7+
import com.marklogic.client.impl.OkHttpServices;
8+
import com.marklogic.client.impl.RESTServices;
9+
import com.marklogic.client.io.*;
10+
import com.marklogic.client.query.*;
11+
import org.custommonkey.xmlunit.exceptions.XpathException;
12+
import org.junit.jupiter.api.*;
13+
import org.w3c.dom.Document;
14+
15+
import static org.custommonkey.xmlunit.XMLAssert.*;
16+
17+
18+
class TestSearchPageLength extends AbstractFunctionalTest {
19+
20+
static final QueryManager queryMgr = client.newQueryManager();
21+
StringQueryDefinition qd = queryMgr.newStringDefinition();
22+
23+
@Test
24+
void testSearchPageLengthZero() throws XpathException {
25+
queryMgr.setPageLength(0);
26+
qd.setCriteria("Foo");
27+
DOMHandle resultsHandle = new DOMHandle();
28+
queryMgr.search(qd, resultsHandle);
29+
30+
Document resultDoc = resultsHandle.get();
31+
assertXpathEvaluatesTo("0", "string(//*[local-name()='response']//@*[local-name()='page-length'])", resultDoc);
32+
}
33+
34+
35+
@Test
36+
void testSearchPageLengthNegative() throws XpathException {
37+
queryMgr.setPageLength(-1);
38+
qd.setCriteria("Foo");
39+
DOMHandle resultsHandle = new DOMHandle();
40+
queryMgr.search(qd, resultsHandle);
41+
42+
Document resultDoc = resultsHandle.get();
43+
assertXpathEvaluatesTo("10", "string(//*[local-name()='response']//@*[local-name()='page-length'])", resultDoc);
44+
}
45+
46+
@Test
47+
void testOkHttpPageLengthParamaterZero() throws XpathException {
48+
RESTServices services = new OkHttpServices();
49+
services.connect(client.getHost(), client.getPort(), null, DB_NAME, client.getSecurityContext());
50+
51+
qd.setCriteria("Foo");
52+
DOMHandle resultsHandle = new DOMHandle();
53+
54+
int pageLength = 0;
55+
services.search(client.newLogger(System.out), resultsHandle, qd, 1, pageLength, null, null, null);
56+
Document resultDoc = resultsHandle.get();
57+
assertXpathEvaluatesTo("0", "string(//*[local-name()='response']//@*[local-name()='page-length'])", resultDoc);
58+
}
59+
60+
@Test
61+
void testOkHttpPageLengthParamaterNegative() throws XpathException {
62+
RESTServices services = new OkHttpServices();
63+
services.connect(client.getHost(), client.getPort(), null, DB_NAME, client.getSecurityContext());
64+
65+
qd.setCriteria("Foo");
66+
DOMHandle resultsHandle = new DOMHandle();
67+
68+
int pageLength = -1;
69+
services.search(client.newLogger(System.out), resultsHandle, qd, 1, pageLength, null, null, null);
70+
Document resultDoc = resultsHandle.get();
71+
assertXpathEvaluatesTo("10", "string(//*[local-name()='response']//@*[local-name()='page-length'])", resultDoc);
72+
}
73+
}

marklogic-client-api/src/main/java/com/marklogic/client/impl/OkHttpServices.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1908,7 +1908,7 @@ public <T extends SearchReadHandle> T search(RequestLogger reqlog, T searchHandl
19081908
params.add("start", Long.toString(start));
19091909
}
19101910

1911-
if (len > 0) {
1911+
if (len > -1) {
19121912
params.add("pageLength", Long.toString(len));
19131913
}
19141914

test-app/docker-compose.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: marklogic-javaclient-test-app
2+
3+
services:
4+
5+
marklogic:
6+
image: "progressofficial/marklogic-db:latest"
7+
platform: linux/amd64
8+
environment:
9+
- MARKLOGIC_INIT=true
10+
- MARKLOGIC_ADMIN_USERNAME=admin
11+
- MARKLOGIC_ADMIN_PASSWORD=admin
12+
volumes:
13+
- ./docker/marklogic/logs:/var/opt/MarkLogic/Logs
14+
ports:
15+
- "8000-8002:8000-8002"
16+
- "8012:8012"
17+
- "8014:8014"
18+
- "8020:8020"

0 commit comments

Comments
 (0)