add test to update index.xml using index-v1.json
This commit is contained in:
parent
6c247e3201
commit
dcf395ad9a
@ -29,18 +29,24 @@ public class FDroidRepoUpdateTest extends MultiRepoUpdaterTest {
|
|||||||
assertEmpty();
|
assertEmpty();
|
||||||
updateEarlier();
|
updateEarlier();
|
||||||
updateLater();
|
updateLater();
|
||||||
|
updateV1Later();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateEarlier() throws RepoUpdater.UpdateException {
|
protected void updateEarlier() throws RepoUpdater.UpdateException {
|
||||||
Utils.debugLog(TAG, "Updating earlier version of F-Droid repo");
|
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");
|
"index.fdroid.2016-10-30.jar");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateLater() throws RepoUpdater.UpdateException {
|
protected void updateLater() throws RepoUpdater.UpdateException {
|
||||||
Utils.debugLog(TAG, "Updating later version of F-Droid repo");
|
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");
|
"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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import android.content.ContentValues;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import org.fdroid.fdroid.IndexV1Updater;
|
||||||
import org.fdroid.fdroid.Preferences;
|
import org.fdroid.fdroid.Preferences;
|
||||||
import org.fdroid.fdroid.RepoUpdater;
|
import org.fdroid.fdroid.RepoUpdater;
|
||||||
import org.fdroid.fdroid.RepoUpdater.UpdateException;
|
import org.fdroid.fdroid.RepoUpdater.UpdateException;
|
||||||
@ -21,11 +21,16 @@ import org.junit.After;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
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.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
public abstract class MultiRepoUpdaterTest extends FDroidProviderTest {
|
public abstract class MultiRepoUpdaterTest extends FDroidProviderTest {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@ -177,30 +182,44 @@ public abstract class MultiRepoUpdaterTest extends FDroidProviderTest {
|
|||||||
return RepoProvider.Helper.findByAddress(context, repo.address);
|
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));
|
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));
|
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 {
|
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 {
|
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 {
|
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 {
|
protected void updateRepo(RepoUpdater updater, String indexJarPath) throws UpdateException {
|
||||||
File indexJar = TestUtils.copyResourceToTempFile(indexJarPath);
|
File indexJar = TestUtils.copyResourceToTempFile(indexJarPath);
|
||||||
try {
|
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);
|
updater.processDownloadedFile(indexJar);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
fail();
|
||||||
} finally {
|
} finally {
|
||||||
if (indexJar != null && indexJar.exists()) {
|
if (indexJar != null && indexJar.exists()) {
|
||||||
indexJar.delete();
|
indexJar.delete();
|
||||||
|
BIN
app/src/test/resources/index-v1.fdroid.2017-07-07.jar
Normal file
BIN
app/src/test/resources/index-v1.fdroid.2017-07-07.jar
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user