+ verifyNoRedirect {
+ assertThat(this["soneHits"], contains(soneWithProfileField))
+ }
+ }
+
+ @Test
+ fun `sone hits are paginated correctly`() {
+ core.preferences.postsPerPage = 2
+ val sones = listOf(createSone("1Sone"), createSone("Other1"), createSone("22Sone"), createSone("333Sone"), createSone("Other2"))
+ .onEach { addSone(it.id, it) }
+ addHttpRequestParameter("query", "sone")
+ verifyNoRedirect {
+ assertThat(this["sonePagination"], isOnPage(0).hasPages(2))
+ assertThat(this["soneHits"], contains(sones[0], sones[2]))
+ }
+ }
+
+ @Test
+ fun `sone hits page 2 is shown correctly`() {
+ core.preferences.postsPerPage = 2
+ val sones = listOf(createSone("1Sone"), createSone("Other1"), createSone("22Sone"), createSone("333Sone"), createSone("Other2"))
+ .onEach { addSone(it.id, it) }
+ addHttpRequestParameter("query", "sone")
+ addHttpRequestParameter("sonePage", "1")
+ verifyNoRedirect {
+ assertThat(this["sonePagination"], isOnPage(1).hasPages(2))
+ assertThat(this["soneHits"], contains(sones[3]))
+ }
+ }
+
+ @Test
+ fun `post hits are paginated correctly`() {
+ core.preferences.postsPerPage = 2
+ val sones = listOf(createSoneWithPost("match1", "1Sone"), createSoneWithPost("no-match1", "Other1"), createSoneWithPost("match2", "22Sone"), createSoneWithPost("match3", "333Sone"), createSoneWithPost("no-match2", "Other2"))
+ addHttpRequestParameter("query", "sone")
+ verifyNoRedirect {
+ assertThat(this["postPagination"], isOnPage(0).hasPages(2))
+ assertThat(this["postHits"], contains(sones[0], sones[2]))
+ }
+ }
+
+ @Test
+ fun `post hits page 2 is shown correctly`() {
+ core.preferences.postsPerPage = 2
+ val sones = listOf(createSoneWithPost("match1", "1Sone"), createSoneWithPost("no-match1", "Other1"), createSoneWithPost("match2", "22Sone"), createSoneWithPost("match3", "333Sone"), createSoneWithPost("no-match2", "Other2"))
+ addHttpRequestParameter("query", "sone")
+ addHttpRequestParameter("postPage", "1")
+ verifyNoRedirect {
+ assertThat(this["postPagination"], isOnPage(1).hasPages(2))
+ assertThat(this["postHits"], contains(sones[3]))
+ }
+ }
+
+ @Test
+ fun `post search results are cached`() {
+ val post = createPost("with-match", "text")
+ val callCounter = AtomicInteger()
+ whenever(post.text).thenAnswer { callCounter.incrementAndGet(); "text" }
+ val sone = createSoneWithPost(post)
+ addSone("sone", sone)
+ addHttpRequestParameter("query", "text")
+ verifyNoRedirect {
+ assertThat(this["postHits"], contains(post))
+ }
+ verifyNoRedirect {
+ assertThat(callCounter.get(), equalTo(1))
+ }
+ }
+
+ @Test
+ fun `post search results are cached for five minutes`() {
+ val post = createPost("with-match", "text")
+ val callCounter = AtomicInteger()
+ whenever(post.text).thenAnswer { callCounter.incrementAndGet(); "text" }
+ val sone = createSoneWithPost(post)
+ addSone("sone", sone)
+ addHttpRequestParameter("query", "text")
+ verifyNoRedirect {
+ assertThat(this["postHits"], contains(post))
+ }
+ whenever(ticker.read()).thenReturn(TimeUnit.MINUTES.toNanos(5) + 1)
+ verifyNoRedirect {
+ assertThat(callCounter.get(), equalTo(2))
+ }