Search in sources :

Example 16 with Repo

use of org.fdroid.fdroid.data.Repo in project fdroidclient by f-droid.

the class AcceptableMultiRepoUpdaterTest method getConflictingRepo.

@NonNull
private Repo getConflictingRepo() {
    Repo repo = RepoProvider.Helper.findByAddress(context, REPO_CONFLICTING_URI);
    assertNotNull(repo);
    return repo;
}
Also used : Repo(org.fdroid.fdroid.data.Repo) NonNull(android.support.annotation.NonNull)

Example 17 with Repo

use of org.fdroid.fdroid.data.Repo in project fdroidclient by f-droid.

the class AcceptableMultiRepoUpdaterTest method getMainRepo.

@NonNull
private Repo getMainRepo() {
    Repo repo = RepoProvider.Helper.findByAddress(context, REPO_MAIN_URI);
    assertNotNull(repo);
    return repo;
}
Also used : Repo(org.fdroid.fdroid.data.Repo) NonNull(android.support.annotation.NonNull)

Example 18 with Repo

use of org.fdroid.fdroid.data.Repo in project fdroidclient by f-droid.

the class AcceptableMultiRepoUpdaterTest method getArchiveRepo.

@NonNull
private Repo getArchiveRepo() {
    Repo repo = RepoProvider.Helper.findByAddress(context, REPO_ARCHIVE_URI);
    assertNotNull(repo);
    return repo;
}
Also used : Repo(org.fdroid.fdroid.data.Repo) NonNull(android.support.annotation.NonNull)

Example 19 with Repo

use of org.fdroid.fdroid.data.Repo in project fdroidclient by f-droid.

the class IndexV1UpdaterTest method testJacksonParsing.

@Test
public void testJacksonParsing() throws IOException {
    ObjectMapper mapper = IndexV1Updater.getObjectMapperInstance(FAKE_REPO_ID);
    // the app ignores all unknown fields when complete, do not ignore during dev to catch mistakes
    mapper.enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    JsonFactory f = mapper.getFactory();
    JsonParser parser = f.createParser(TestUtils.copyResourceToTempFile("guardianproject_index-v1.json"));
    Repo repo = null;
    App[] apps = null;
    Map<String, String[]> requests = null;
    Map<String, List<Apk>> packages = null;
    // go into the main object block
    parser.nextToken();
    while (true) {
        String fieldName = parser.nextFieldName();
        if (fieldName == null) {
            break;
        }
        switch(fieldName) {
            case "repo":
                repo = parseRepo(mapper, parser);
                break;
            case "requests":
                requests = parseRequests(mapper, parser);
                break;
            case "apps":
                apps = parseApps(mapper, parser);
                break;
            case "packages":
                packages = parsePackages(mapper, parser);
                break;
        }
    }
    // ensure resources get cleaned up timely and properly
    parser.close();
    RepoDetails indexV0Details = getFromFile("guardianproject_index.xml", Repo.PUSH_REQUEST_ACCEPT_ALWAYS);
    indexV0Details.apps.size();
    assertEquals(indexV0Details.apps.size(), apps.length);
    assertEquals(apps.length, packages.size());
    int totalApks = 0;
    for (String packageName : packages.keySet()) {
        totalApks += packages.get(packageName).size();
    }
    assertEquals(totalApks, indexV0Details.apks.size());
    assertEquals(indexV0Details.icon, repo.icon);
    // V1 is in millis
    assertEquals(indexV0Details.timestamp, repo.timestamp / 1000);
    assertEquals(indexV0Details.name, repo.name);
    assertArrayEquals(indexV0Details.mirrors, repo.mirrors);
    ArrayList<String> installRequests = new ArrayList<>();
    for (RepoPushRequest repoPushRequest : indexV0Details.repoPushRequestList) {
        if ("install".equals(repoPushRequest.request)) {
            installRequests.add(repoPushRequest.packageName);
        }
    }
    assertArrayEquals(installRequests.toArray(), requests.get("install"));
}
Also used : App(org.fdroid.fdroid.data.App) JsonFactory(com.fasterxml.jackson.core.JsonFactory) ArrayList(java.util.ArrayList) RepoPushRequest(org.fdroid.fdroid.data.RepoPushRequest) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RepoDetails(org.fdroid.fdroid.mock.RepoDetails) Repo(org.fdroid.fdroid.data.Repo) List(java.util.List) ArrayList(java.util.ArrayList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonParser(com.fasterxml.jackson.core.JsonParser) FDroidProviderTest(org.fdroid.fdroid.data.FDroidProviderTest) Test(org.junit.Test)

Example 20 with Repo

use of org.fdroid.fdroid.data.Repo in project fdroidclient by f-droid.

the class IndexV1UpdaterTest method testIndexV1WithOldTimestamp.

@Test(expected = RepoUpdater.UpdateException.class)
public void testIndexV1WithOldTimestamp() throws IOException, RepoUpdater.UpdateException {
    Repo repo = MultiRepoUpdaterTest.createRepo("Testy", TESTY_JAR, context, TESTY_CERT);
    repo.timestamp = System.currentTimeMillis() / 1000;
    IndexV1Updater updater = new IndexV1Updater(context, repo);
    JarFile jarFile = new JarFile(TestUtils.copyResourceToTempFile(TESTY_JAR), true);
    JarEntry indexEntry = (JarEntry) jarFile.getEntry(IndexV1Updater.DATA_FILE_NAME);
    InputStream indexInputStream = jarFile.getInputStream(indexEntry);
    updater.processIndexV1(indexInputStream, indexEntry, "fakeEtag");
    // it should never reach here, it should throw a SigningException
    fail();
    getClass().getResourceAsStream("foo");
}
Also used : IndexV1Updater(org.fdroid.fdroid.IndexV1Updater) Repo(org.fdroid.fdroid.data.Repo) InputStream(java.io.InputStream) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) FDroidProviderTest(org.fdroid.fdroid.data.FDroidProviderTest) Test(org.junit.Test)

Aggregations

Repo (org.fdroid.fdroid.data.Repo)30 Test (org.junit.Test)14 RepoDetails (org.fdroid.fdroid.mock.RepoDetails)8 ArrayList (java.util.ArrayList)5 FDroidProviderTest (org.fdroid.fdroid.data.FDroidProviderTest)5 NonNull (android.support.annotation.NonNull)4 InputStream (java.io.InputStream)4 List (java.util.List)4 JarEntry (java.util.jar.JarEntry)4 JarFile (java.util.jar.JarFile)4 IndexV1Updater (org.fdroid.fdroid.IndexV1Updater)4 Apk (org.fdroid.fdroid.data.Apk)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 ContentValues (android.content.ContentValues)3 App (org.fdroid.fdroid.data.App)3 RepoPushRequest (org.fdroid.fdroid.data.RepoPushRequest)3 Uri (android.net.Uri)2 View (android.view.View)2 TextView (android.widget.TextView)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)2