add test to update index.xml using index-v1.json

This commit is contained in:
Hans-Christoph Steiner 2017-07-07 14:34:41 +02:00
parent 6c247e3201
commit dcf395ad9a
3 changed files with 67 additions and 42 deletions

View File

@ -29,18 +29,24 @@ public class FDroidRepoUpdateTest extends MultiRepoUpdaterTest {
assertEmpty();
updateEarlier();
updateLater();
updateV1Later();
}
protected void updateEarlier() throws RepoUpdater.UpdateException {
Utils.debugLog(TAG, "Updating earlier version of F-Droid repo");
updateRepo(createUpdater(REPO_FDROID, REPO_FDROID_URI, context, REPO_FDROID_PUB_KEY),
updateRepo(createRepoUpdater(REPO_FDROID, REPO_FDROID_URI, context, REPO_FDROID_PUB_KEY),
"index.fdroid.2016-10-30.jar");
}
protected void updateLater() throws RepoUpdater.UpdateException {
Utils.debugLog(TAG, "Updating later version of F-Droid repo");
updateRepo(createUpdater(REPO_FDROID, REPO_FDROID_URI, context, REPO_FDROID_PUB_KEY),
updateRepo(createRepoUpdater(REPO_FDROID, REPO_FDROID_URI, context, REPO_FDROID_PUB_KEY),
"index.fdroid.2016-11-10.jar");
}
protected void updateV1Later() throws RepoUpdater.UpdateException {
Utils.debugLog(TAG, "Updating later version of F-Droid index-v1");
updateRepo(createIndexV1Updater(REPO_FDROID, REPO_FDROID_URI, context, REPO_FDROID_PUB_KEY),
"index-v1.fdroid.2017-07-07.jar");
}
}

View File

@ -5,7 +5,7 @@ import android.content.ContentValues;
import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import org.fdroid.fdroid.IndexV1Updater;
import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.RepoUpdater;
import org.fdroid.fdroid.RepoUpdater.UpdateException;
@ -21,11 +21,16 @@ import org.junit.After;
import org.junit.Before;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public abstract class MultiRepoUpdaterTest extends FDroidProviderTest {
@SuppressWarnings("unused")
@ -177,30 +182,44 @@ public abstract class MultiRepoUpdaterTest extends FDroidProviderTest {
return RepoProvider.Helper.findByAddress(context, repo.address);
}
protected RepoUpdater createUpdater(String name, String uri, Context context) {
protected RepoUpdater createRepoUpdater(String name, String uri, Context context) {
return new RepoUpdater(context, createRepo(name, uri, context));
}
protected RepoUpdater createUpdater(String name, String uri, Context context, String signingCert) {
protected RepoUpdater createRepoUpdater(String name, String uri, Context context, String signingCert) {
return new RepoUpdater(context, createRepo(name, uri, context, signingCert));
}
protected IndexV1Updater createIndexV1Updater(String name, String uri, Context context, String signingCert) {
return new IndexV1Updater(context, createRepo(name, uri, context, signingCert));
}
protected void updateConflicting() throws UpdateException {
updateRepo(createUpdater(REPO_CONFLICTING, REPO_CONFLICTING_URI, context), "multiRepo.conflicting.jar");
updateRepo(createRepoUpdater(REPO_CONFLICTING, REPO_CONFLICTING_URI, context), "multiRepo.conflicting.jar");
}
protected void updateMain() throws UpdateException {
updateRepo(createUpdater(REPO_MAIN, REPO_MAIN_URI, context), "multiRepo.normal.jar");
updateRepo(createRepoUpdater(REPO_MAIN, REPO_MAIN_URI, context), "multiRepo.normal.jar");
}
protected void updateArchive() throws UpdateException {
updateRepo(createUpdater(REPO_ARCHIVE, REPO_ARCHIVE_URI, context), "multiRepo.archive.jar");
updateRepo(createRepoUpdater(REPO_ARCHIVE, REPO_ARCHIVE_URI, context), "multiRepo.archive.jar");
}
protected void updateRepo(RepoUpdater updater, String indexJarPath) throws UpdateException {
File indexJar = TestUtils.copyResourceToTempFile(indexJarPath);
try {
if (updater instanceof IndexV1Updater) {
JarFile jarFile = new JarFile(indexJar);
JarEntry indexEntry = (JarEntry) jarFile.getEntry(IndexV1Updater.DATA_FILE_NAME);
InputStream indexInputStream = jarFile.getInputStream(indexEntry);
((IndexV1Updater) updater).processIndexV1(indexInputStream, indexEntry, null);
} else {
updater.processDownloadedFile(indexJar);
}
} catch (IOException e) {
e.printStackTrace();
fail();
} finally {
if (indexJar != null && indexJar.exists()) {
indexJar.delete();

Binary file not shown.