|
| 1 | +/* |
| 2 | + * Copyright © 2024 MarkLogic Corporation. All Rights Reserved. |
| 3 | + */ |
| 4 | + |
| 5 | +package com.marklogic.client.fastfunctest.search; |
| 6 | + |
| 7 | +import com.marklogic.client.fastfunctest.AbstractFunctionalTest; |
| 8 | +import com.marklogic.client.io.*; |
| 9 | +import com.marklogic.client.query.*; |
| 10 | +import org.junit.jupiter.api.*; |
| 11 | + |
| 12 | +import java.io.FileNotFoundException; |
| 13 | + |
| 14 | +import static org.custommonkey.xmlunit.XMLAssert.*; |
| 15 | + |
| 16 | + |
| 17 | +class SearchWithPageLengthTest extends AbstractFunctionalTest { |
| 18 | + |
| 19 | + static final QueryManager queryMgr = client.newQueryManager(); |
| 20 | + StringQueryDefinition qd = queryMgr.newStringDefinition(); |
| 21 | + |
| 22 | + @BeforeEach |
| 23 | + public void testSetup() throws FileNotFoundException { |
| 24 | + String[] filenames = {"constraint1.xml", "constraint2.xml", "constraint3.xml", "constraint4.xml", "constraint5.xml"}; |
| 25 | + for (String filename : filenames) { |
| 26 | + writeDocumentUsingInputStreamHandle(client, filename, "/return-results-false/", "XML"); |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + @AfterEach |
| 31 | + public void testCleanUp() { |
| 32 | + deleteDocuments(connectAsAdmin()); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + void testSearchPageLengthZero() { |
| 37 | + queryMgr.setPageLength(0); |
| 38 | + qd.setCriteria("Bush"); |
| 39 | + SearchHandle resultsHandle = new SearchHandle(); |
| 40 | + queryMgr.search(qd, resultsHandle); |
| 41 | + |
| 42 | + assertEquals(0, resultsHandle.getPageLength()); |
| 43 | + assertEquals("The server allows for a zero page length, which results in no results being returned.", |
| 44 | + 0, resultsHandle.getMatchResults().length); |
| 45 | + } |
| 46 | + |
| 47 | + |
| 48 | + @Test |
| 49 | + void testSearchPageLengthNegative() { |
| 50 | + queryMgr.setPageLength(-1); |
| 51 | + qd.setCriteria("Bush"); |
| 52 | + SearchHandle resultsHandle = new SearchHandle(); |
| 53 | + queryMgr.search(qd, resultsHandle); |
| 54 | + |
| 55 | + assertEquals("Negative page lengths are not sent to the server, so the default page length of 10 should be used.", |
| 56 | + 10, resultsHandle.getPageLength()); |
| 57 | + assertEquals(2, resultsHandle.getMatchResults().length); |
| 58 | + } |
| 59 | +} |
0 commit comments