diff --git a/galasa-extensions-parent/dev.galasa.ras.couchdb/src/main/java/dev/galasa/ras/couchdb/internal/CouchdbDirectoryService.java b/galasa-extensions-parent/dev.galasa.ras.couchdb/src/main/java/dev/galasa/ras/couchdb/internal/CouchdbDirectoryService.java index cb563e1f..9ee04e0d 100644 --- a/galasa-extensions-parent/dev.galasa.ras.couchdb/src/main/java/dev/galasa/ras/couchdb/internal/CouchdbDirectoryService.java +++ b/galasa-extensions-parent/dev.galasa.ras.couchdb/src/main/java/dev/galasa/ras/couchdb/internal/CouchdbDirectoryService.java @@ -374,6 +374,12 @@ private RasRunResultPage getRunsPageFromCouchdb(HttpPost httpPost, Find query) t } } + // CouchDB sometimes returns a 'nil' string as a bookmark to indicate no bookmark, + // so turn it into an actual null value + if (found.bookmark != null && found.bookmark.equals("nil")) { + found.bookmark = null; + } + runsPage = new RasRunResultPage(runs, found.bookmark); } catch (CouchdbRasException e) { throw e; diff --git a/galasa-extensions-parent/dev.galasa.ras.couchdb/src/test/java/dev/galasa/ras/couchdb/internal/CouchdbDirectoryServiceTest.java b/galasa-extensions-parent/dev.galasa.ras.couchdb/src/test/java/dev/galasa/ras/couchdb/internal/CouchdbDirectoryServiceTest.java index 2f6eff39..5697ce8b 100644 --- a/galasa-extensions-parent/dev.galasa.ras.couchdb/src/test/java/dev/galasa/ras/couchdb/internal/CouchdbDirectoryServiceTest.java +++ b/galasa-extensions-parent/dev.galasa.ras.couchdb/src/test/java/dev/galasa/ras/couchdb/internal/CouchdbDirectoryServiceTest.java @@ -470,4 +470,34 @@ public void testGetRunsPageByQueuedFromWithSortAndPageTokenReturnsRunsOk() throw assertThat(runs.get(0).getTestStructure().getRunName()).isEqualTo(mockRun1.getRunName()); assertThat(runs.get(1).getTestStructure().getRunName()).isEqualTo(mockRun2.getRunName()); } + + @Test + public void testGetRunsPageWithNilBookmarkReturnsPageWithNoNextCursor() throws Exception { + // Given... + TestStructureCouchdb mockRun1 = createRunTestStructure("run1"); + + Instant queuedFromTime = Instant.EPOCH; + RasSearchCriteriaQueuedFrom queuedFrom = new RasSearchCriteriaQueuedFrom(queuedFromTime); + + FoundRuns findRunsResponse = new FoundRuns(); + findRunsResponse.docs = List.of(mockRun1); + findRunsResponse.bookmark = "nil"; + + String expectedUri = "http://my.uri/galasa_run/_find"; + List interactions = List.of( + new PostCouchdbFindRunsInteraction(expectedUri, findRunsResponse, "queued", "$gte", queuedFromTime.toString()) + ); + + MockLogFactory mockLogFactory = new MockLogFactory(); + CouchdbRasStore mockRasStore = fixtures.createCouchdbRasStore(interactions, mockLogFactory); + CouchdbDirectoryService directoryService = new CouchdbDirectoryService(mockRasStore, mockLogFactory, new HttpRequestFactoryImpl()); + + int maxResults = 100; + + // When... + RasRunResultPage runsPage = directoryService.getRunsPage(maxResults, null, null, queuedFrom); + + // Then... + assertThat(runsPage.getNextCursor()).isNull(); + } }