add test for multi page result

This commit is contained in:
Daniel Gultsch 2023-03-21 18:21:56 +01:00
parent 1e884ec435
commit 4139c11771
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
2 changed files with 48 additions and 2 deletions

View file

@ -2,15 +2,18 @@ package im.conversations.android.xmpp;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import im.conversations.android.database.model.Account; import im.conversations.android.database.model.Account;
import im.conversations.android.database.model.StanzaId; import im.conversations.android.database.model.StanzaId;
import im.conversations.android.transformer.MessageTransformation; import im.conversations.android.transformer.MessageTransformation;
import im.conversations.android.transformer.Transformer;
import im.conversations.android.xmpp.manager.ArchiveManager; import im.conversations.android.xmpp.manager.ArchiveManager;
import im.conversations.android.xmpp.model.jabber.Body; import im.conversations.android.xmpp.model.jabber.Body;
import im.conversations.android.xmpp.model.stanza.Message; import im.conversations.android.xmpp.model.stanza.Message;
import java.time.Instant; import java.time.Instant;
import java.util.Collections;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import org.hamcrest.MatcherAssert; import org.hamcrest.MatcherAssert;
import org.junit.Assert; import org.junit.Assert;
@ -97,6 +100,49 @@ public class ArchivePagingTest extends BaseTransformationTest {
MatcherAssert.assertThat(rangesSecondAttempt, contains(new Range(Range.Order.NORMAL, "4"))); 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 { private Account account() throws ExecutionException, InterruptedException {
return this.database.accountDao().getEnabledAccount(ACCOUNT).get(); return this.database.accountDao().getEnabledAccount(ACCOUNT).get();
} }

View file

@ -3,7 +3,6 @@ package im.conversations.android.transformer;
import android.content.Context; import android.content.Context;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import im.conversations.android.axolotl.AxolotlService; import im.conversations.android.axolotl.AxolotlService;
import im.conversations.android.database.ConversationsDatabase; import im.conversations.android.database.ConversationsDatabase;
import im.conversations.android.database.model.Account; 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.retract.Retract;
import im.conversations.android.xmpp.model.stanza.Message; import im.conversations.android.xmpp.model.stanza.Message;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import org.jxmpp.jid.Jid; import org.jxmpp.jid.Jid;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -76,7 +76,7 @@ public class Transformer {
} }
public void transform( public void transform(
ImmutableList<MessageTransformation> messageTransformations, List<MessageTransformation> messageTransformations,
final Jid archive, final Jid archive,
Range queryRange, Range queryRange,
ArchiveManager.QueryResult queryResult, ArchiveManager.QueryResult queryResult,