|
| 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 | +} |
0 commit comments