Android Open Source - AppManager-for-Android App Manager Schema Test






From Project

Back to project page AppManager-for-Android.

License

The source code is released under:

Apache License

If you think the Android project AppManager-for-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.appmanager.android.util;
/* ww w .j  a  va 2s . co m*/
import com.appmanager.android.entity.FileEntry;

import junit.framework.TestCase;

import java.net.URLEncoder;

/**
 * @author maimuzo
 * @since 2014/08/30
 */
public class AppManagerSchemaTest extends TestCase {
    private static final String APK_PATH = "github.com/app-manager/AppManager-for-Android/blob/master/tests/apk/dummy.apk?raw=true";
    private static final String ORIGINAL_URL_HTTP = "http://" + APK_PATH;
    private static final String ORIGINAL_URL_HTTPS = "https://" + APK_PATH;
    private static final String AUTH_USER = "testuser";
    private static final String AUTH_PASS = "authpass";
    private static final String NAME_ALP = "testName";
    private static final String NAME_JP = "??????";
    private static final String NAME_JP_ENCODED = "%E3%83%86%E3%82%B9%E3%83%88%E5%90%8D";

    public void testCanEncode(){
        assertEquals(AppManagerSchema.encode(ORIGINAL_URL_HTTPS, NAME_ALP, AUTH_USER, AUTH_PASS), "https://testuser:authpass@" + AppManagerSchema.MAIN_SPECIAL_HOST + "/" + APK_PATH + "#" + NAME_ALP);
        assertEquals(AppManagerSchema.encode(ORIGINAL_URL_HTTP, NAME_ALP, AUTH_USER, AUTH_PASS), "http://testuser:authpass@" + AppManagerSchema.MAIN_SPECIAL_HOST + "/" + APK_PATH + "#" + NAME_ALP);
        assertEquals(AppManagerSchema.encode(ORIGINAL_URL_HTTPS, NAME_JP, AUTH_USER, AUTH_PASS), "https://testuser:authpass@" + AppManagerSchema.MAIN_SPECIAL_HOST + "/" + APK_PATH + "#" + NAME_JP_ENCODED);
        assertEquals(AppManagerSchema.encode(ORIGINAL_URL_HTTPS, NAME_ALP, "", AUTH_PASS), "https://" + AppManagerSchema.MAIN_SPECIAL_HOST + "/" + APK_PATH + "#" + NAME_ALP);
        assertEquals(AppManagerSchema.encode(ORIGINAL_URL_HTTPS, NAME_ALP, AUTH_USER, ""), "https://" + AppManagerSchema.MAIN_SPECIAL_HOST + "/" + APK_PATH + "#" + NAME_ALP);
        assertEquals(AppManagerSchema.encode(ORIGINAL_URL_HTTPS, NAME_ALP, "", ""), "https://" + AppManagerSchema.MAIN_SPECIAL_HOST + "/" + APK_PATH + "#" + NAME_ALP);
        assertEquals(AppManagerSchema.encode(ORIGINAL_URL_HTTPS, NAME_ALP, null, AUTH_PASS), "https://" + AppManagerSchema.MAIN_SPECIAL_HOST + "/" + APK_PATH + "#" + NAME_ALP);
        assertEquals(AppManagerSchema.encode(ORIGINAL_URL_HTTPS, NAME_ALP, AUTH_USER, null), "https://" + AppManagerSchema.MAIN_SPECIAL_HOST + "/" + APK_PATH + "#" + NAME_ALP);
        assertEquals(AppManagerSchema.encode(ORIGINAL_URL_HTTPS, NAME_ALP, null, null), "https://" + AppManagerSchema.MAIN_SPECIAL_HOST + "/" + APK_PATH + "#" + NAME_ALP);
        assertEquals(AppManagerSchema.encode(ORIGINAL_URL_HTTPS, "", null, null), "https://" + AppManagerSchema.MAIN_SPECIAL_HOST + "/" + APK_PATH);
        assertEquals(AppManagerSchema.encode(ORIGINAL_URL_HTTPS, null, null, null), "https://" + AppManagerSchema.MAIN_SPECIAL_HOST + "/" + APK_PATH);
    }

    public void testCanDecode(){
        for (String specialHost : AppManagerSchema.SPECIAL_HOSTS) {
            assertNotNull(AppManagerSchema.decode("https://testuser:authpass@" + specialHost + "/" + APK_PATH + "#" + NAME_ALP));
            FileEntry fe1 = AppManagerSchema.decode("https://testuser:authpass@" + specialHost + "/" + APK_PATH + "#" + NAME_ALP);
            FileEntry fe2 = packFileEntry(ORIGINAL_URL_HTTPS, NAME_ALP, AUTH_USER, AUTH_PASS);
            assertTrue(fe1.contentEqualsTo(fe2));
            assertTrue(AppManagerSchema.decode("http://testuser:authpass@" + specialHost + "/" + APK_PATH + "#" + NAME_ALP).contentEqualsTo(packFileEntry(ORIGINAL_URL_HTTP, NAME_ALP, AUTH_USER, AUTH_PASS)));
            assertTrue(AppManagerSchema.decode("https://testuser:authpass@" + specialHost + "/" + APK_PATH + "#" + NAME_JP_ENCODED).contentEqualsTo(packFileEntry(ORIGINAL_URL_HTTPS, NAME_JP, AUTH_USER, AUTH_PASS)));
            assertNull(AppManagerSchema.decode("https://testuser@" + specialHost + "/" + APK_PATH + "#" + NAME_ALP));
            assertTrue(AppManagerSchema.decode("https://:authpass@" + specialHost + "/" + APK_PATH + "#" + NAME_ALP).contentEqualsTo(packFileEntry(ORIGINAL_URL_HTTPS, NAME_ALP, null, null)));
            assertTrue(AppManagerSchema.decode("https://" + specialHost + "/" + APK_PATH + "#" + NAME_ALP).contentEqualsTo(packFileEntry(ORIGINAL_URL_HTTPS, NAME_ALP, null, null)));
            assertTrue(AppManagerSchema.decode("https://" + specialHost + "/" + APK_PATH).contentEqualsTo(packFileEntry(ORIGINAL_URL_HTTPS, null, null, null)));
            assertNull(AppManagerSchema.decode("https://sonnanonaiyo/" + APK_PATH));
            assertNull(AppManagerSchema.decode("https://" + APK_PATH));
        }
    }

    private FileEntry packFileEntry(String url, String name, String user, String pass){
        FileEntry fe = new FileEntry();
        fe.name = name;
        fe.url = url;
        fe.basicAuthUser = user;
        fe.basicAuthPassword = pass;
        return fe;
    }
}




Java Source Code List

com.appmanager.android.adapter.FileEntryAdapter.java
com.appmanager.android.app.AboutActivity.java
com.appmanager.android.app.BaseActivity.java
com.appmanager.android.app.DetailActivity.java
com.appmanager.android.app.EditActivity.java
com.appmanager.android.app.HelpActivity.java
com.appmanager.android.app.HelpDeveloperActivity.java
com.appmanager.android.app.HelpTesterActivity.java
com.appmanager.android.app.LicenseActivity.java
com.appmanager.android.app.MainActivity.java
com.appmanager.android.app.SettingsActivity.java
com.appmanager.android.dao.FileEntryDao.java
com.appmanager.android.entity.Configuration.java
com.appmanager.android.entity.FileEntry.java
com.appmanager.android.receiver.BootCompleteReceiver.java
com.appmanager.android.samples.dummy.ApplicationTest.java
com.appmanager.android.samples.dummy.app.MainActivity.java
com.appmanager.android.service.CheckAndInstallService.java
com.appmanager.android.task.GetConfigTask.java
com.appmanager.android.task.InstallTask.java
com.appmanager.android.util.AppDownloader.java
com.appmanager.android.util.AppManagerSchemaTest.java
com.appmanager.android.util.AppManagerSchema.java
com.appmanager.android.util.BitmapUtils.java
com.appmanager.android.util.DbHelper.java
com.appmanager.android.util.InstallUtils.java
com.appmanager.android.util.LogUtils.java
com.appmanager.android.util.VersionUtils.java
com.appmanager.android.validator.FileEntryValidator.java