From 4139c117711c343ee54c818928b1aec3b3ffbc09 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 21 Mar 2023 18:21:56 +0100 Subject: [PATCH] add test for multi page result --- .../android/xmpp/ArchivePagingTest.java | 46 +++++++++++++++++++ .../android/transformer/Transformer.java | 4 +- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/app/src/androidTest/java/im/conversations/android/xmpp/ArchivePagingTest.java b/app/src/androidTest/java/im/conversations/android/xmpp/ArchivePagingTest.java index 0c4d2a80c..603b2eebb 100644 --- a/app/src/androidTest/java/im/conversations/android/xmpp/ArchivePagingTest.java +++ b/app/src/androidTest/java/im/conversations/android/xmpp/ArchivePagingTest.java @@ -2,15 +2,18 @@ package im.conversations.android.xmpp; import static org.hamcrest.Matchers.*; +import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.google.common.collect.Iterables; import im.conversations.android.database.model.Account; import im.conversations.android.database.model.StanzaId; import im.conversations.android.transformer.MessageTransformation; +import im.conversations.android.transformer.Transformer; import im.conversations.android.xmpp.manager.ArchiveManager; import im.conversations.android.xmpp.model.jabber.Body; import im.conversations.android.xmpp.model.stanza.Message; import java.time.Instant; +import java.util.Collections; import java.util.concurrent.ExecutionException; import org.hamcrest.MatcherAssert; import org.junit.Assert; @@ -97,6 +100,49 @@ public class ArchivePagingTest extends BaseTransformationTest { MatcherAssert.assertThat(rangesSecondAttempt, contains(new Range(Range.Order.NORMAL, "4"))); } + @Test + public void liveMessageQuerySubmitTwice() throws ExecutionException, InterruptedException { + final var stub2 = new StubMessage(2); + transformer.transform(stub2.messageTransformation(), stub2.stanzaId()); + + final var ranges = database.archiveDao().resetLivePage(account(), ACCOUNT); + Assert.assertEquals(2, ranges.size()); + MatcherAssert.assertThat( + ranges, + contains(new Range(Range.Order.REVERSE, "2"), new Range(Range.Order.NORMAL, "2"))); + + final var account = account(); + + final var transformer = + new Transformer(account, ApplicationProvider.getApplicationContext(), database); + + transformer.transform( + Collections.emptyList(), + ACCOUNT, + new Range(Range.Order.REVERSE, "2"), + new ArchiveManager.QueryResult(true, Page.emptyWithCount("2", null)), + true); + transformer.transform( + Collections.emptyList(), + ACCOUNT, + new Range(Range.Order.NORMAL, "2"), + new ArchiveManager.QueryResult(false, new Page("3", "4", 2)), + false); + + transformer.transform( + Collections.emptyList(), + ACCOUNT, + new Range(Range.Order.NORMAL, "4"), + new ArchiveManager.QueryResult(true, new Page("5", "6", 2)), + false); + + final var rangesSecondAttempt = database.archiveDao().resetLivePage(account(), ACCOUNT); + // we mark the reversing range as complete in the submit above; hence it is not included in + // the second ranges + Assert.assertEquals(1, rangesSecondAttempt.size()); + MatcherAssert.assertThat(rangesSecondAttempt, contains(new Range(Range.Order.NORMAL, "6"))); + } + private Account account() throws ExecutionException, InterruptedException { return this.database.accountDao().getEnabledAccount(ACCOUNT).get(); } diff --git a/app/src/main/java/im/conversations/android/transformer/Transformer.java b/app/src/main/java/im/conversations/android/transformer/Transformer.java index 82cc95814..d0e8f0e35 100644 --- a/app/src/main/java/im/conversations/android/transformer/Transformer.java +++ b/app/src/main/java/im/conversations/android/transformer/Transformer.java @@ -3,7 +3,6 @@ package im.conversations.android.transformer; import android.content.Context; import androidx.annotation.VisibleForTesting; import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; import im.conversations.android.axolotl.AxolotlService; import im.conversations.android.database.ConversationsDatabase; import im.conversations.android.database.model.Account; @@ -24,6 +23,7 @@ import im.conversations.android.xmpp.model.reply.Reply; import im.conversations.android.xmpp.model.retract.Retract; import im.conversations.android.xmpp.model.stanza.Message; import java.util.Arrays; +import java.util.List; import java.util.Objects; import org.jxmpp.jid.Jid; import org.slf4j.Logger; @@ -76,7 +76,7 @@ public class Transformer { } public void transform( - ImmutableList messageTransformations, + List messageTransformations, final Jid archive, Range queryRange, ArchiveManager.QueryResult queryResult,