mirror of
https://github.com/etesync/android
synced 2024-11-19 14:38:11 +00:00
Tests: Add journalentrymanager tests.
This commit is contained in:
parent
14e6f757c5
commit
fcbf26a03b
@ -17,6 +17,7 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
@ -27,6 +28,7 @@ import okhttp3.RequestBody;
|
|||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okio.BufferedSink;
|
import okio.BufferedSink;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
@ -126,4 +128,72 @@ public class ServiceTest {
|
|||||||
}
|
}
|
||||||
assertNotNull(caught);
|
assertNotNull(caught);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSyncEntry() throws IOException, Exceptions.HttpException, Exceptions.GenericCryptoException, Exceptions.IntegrityException {
|
||||||
|
Exception caught;
|
||||||
|
JournalManager journalManager = new JournalManager(httpClient, remote);
|
||||||
|
CollectionInfo info = CollectionInfo.defaultForServiceType(CollectionInfo.Type.ADDRESS_BOOK);
|
||||||
|
info.uid = JournalManager.Journal.genUid();
|
||||||
|
info.displayName = "Test";
|
||||||
|
Crypto.CryptoManager crypto = new Crypto.CryptoManager(info.version, Helpers.keyBase64, info.uid);
|
||||||
|
JournalManager.Journal journal = new JournalManager.Journal(crypto, info.toJson(), info.uid);
|
||||||
|
journalManager.putJournal(journal);
|
||||||
|
|
||||||
|
JournalEntryManager journalEntryManager = new JournalEntryManager(httpClient, remote, info.uid);
|
||||||
|
JournalEntryManager.Entry previousEntry = null;
|
||||||
|
JournalEntryManager.Entry entry = new JournalEntryManager.Entry();
|
||||||
|
entry.update(crypto, "Content", previousEntry);
|
||||||
|
|
||||||
|
List<JournalEntryManager.Entry> entries = new LinkedList<>();
|
||||||
|
|
||||||
|
entries.add(entry);
|
||||||
|
journalEntryManager.putEntries(entries, null);
|
||||||
|
previousEntry = entry;
|
||||||
|
|
||||||
|
entries.clear();
|
||||||
|
JournalEntryManager.Entry entry2 = new JournalEntryManager.Entry();
|
||||||
|
entry2.update(crypto, "Content", previousEntry);
|
||||||
|
entries.add(entry2);
|
||||||
|
|
||||||
|
// Pushing a correct entries without the last parameter
|
||||||
|
try {
|
||||||
|
caught = null;
|
||||||
|
journalEntryManager.putEntries(entries, null);
|
||||||
|
} catch (Exceptions.HttpException e) {
|
||||||
|
caught = e;
|
||||||
|
}
|
||||||
|
assertNotNull(caught);
|
||||||
|
|
||||||
|
// Adding a second entry
|
||||||
|
journalEntryManager.putEntries(entries, previousEntry.getUid());
|
||||||
|
previousEntry = entry2;
|
||||||
|
|
||||||
|
entries.clear();
|
||||||
|
entries.add(entry);
|
||||||
|
entries.add(entry2);
|
||||||
|
|
||||||
|
// Check last works:
|
||||||
|
entries = journalEntryManager.getEntries(crypto, entry.getUid());
|
||||||
|
assertEquals(entries.size(), 1);
|
||||||
|
entries = journalEntryManager.getEntries(crypto, entry2.getUid());
|
||||||
|
assertEquals(entries.size(), 0);
|
||||||
|
|
||||||
|
// Corrupt the journal and verify we catch it
|
||||||
|
entries.clear();
|
||||||
|
entry2 = new JournalEntryManager.Entry();
|
||||||
|
entry2.update(crypto, "Content", null);
|
||||||
|
entries.add(entry2);
|
||||||
|
|
||||||
|
journalEntryManager.putEntries(entries, previousEntry.getUid());
|
||||||
|
|
||||||
|
try {
|
||||||
|
caught = null;
|
||||||
|
journalEntryManager.getEntries(crypto, null);
|
||||||
|
} catch (Exceptions.IntegrityException e) {
|
||||||
|
caught = e;
|
||||||
|
}
|
||||||
|
assertNotNull(caught);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user