Loading app/build.gradle +1 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ android { testOptions { unitTests { returnDefaultValues = true //includeAndroidResources = true includeAndroidResources = true unitTests.all { systemProperty 'robolectric.dependency.repo.url', "\""+getTestProp("testServerUrl")+"\"" systemProperty 'robolectric.dependency.repo.username', "\""+getTestProp("testAccountName")+"\"" Loading app/src/test/java/foundation/e/drive/TestUtils.java +29 −32 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ package foundation.e.drive; import android.accounts.Account; import android.accounts.AccountManager; import android.content.Context; import android.os.Bundle; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.network.CertificateCombinedException; Loading @@ -11,8 +12,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.status.GetRemoteStatusOperation; import org.junit.BeforeClass; import java.io.File; import java.io.FileWriter; import java.io.IOException; Loading @@ -20,10 +19,10 @@ import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.Properties; import static com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_OC_BASE_URL; import static org.junit.Assert.assertTrue; import static org.robolectric.Shadows.shadowOf; public abstract class TestUtils { public static final String TEST_LOCAL_ROOT_FOLDER_PATH = "/tmp/eDrive/test/"; //THis is where test file and folder for synchronisatio will be stored Loading @@ -31,8 +30,7 @@ public abstract class TestUtils { public static String TEST_ACCOUNT_TYPE ="eelo"; public static String TEST_SERVER_URI; public static String TEST_ACCOUNT_NAME; private static String TEST_ACCOUNT_PASSWORD; //Shouldn't be accessible from outside private static String TEST_ACCOUNT_PASSWORD; private static Account validAccount; Loading @@ -40,15 +38,16 @@ public abstract class TestUtils { * This method execute before the class, it assure that credentials are available */ public static void loadServerCredentials() { TEST_ACCOUNT_PASSWORD = BuildConfig.testAccountPWd; TEST_ACCOUNT_NAME = BuildConfig.testAccountName; TEST_SERVER_URI = BuildConfig.testServerUrl; final Properties properties = System.getProperties(); TEST_ACCOUNT_PASSWORD = properties.getProperty("robolectric.dependency.repo.password"); TEST_ACCOUNT_NAME = properties.getProperty("robolectric.dependency.repo.username"); TEST_SERVER_URI = properties.getProperty("robolectric.dependency.repo.url"); } /** * Get the valid Account object. Create it if it isn't already instanciated * @return * @return Account */ public static Account getValidAccount() { if (validAccount == null) { Loading @@ -65,23 +64,22 @@ public abstract class TestUtils { storeAccountInManager(getValidAccount(), TEST_ACCOUNT_PASSWORD, TEST_SERVER_URI, accountManager); } public static void storeAccountInManager(Account account, String password, String serverUrl, AccountManager manager) { shadowOf(manager).addAccount(account); // Commenting this make failure due to JobUtils.stopScheduleJob()" method... shadowOf(manager).setPassword(account, password); shadowOf(manager).setUserData(account, KEY_OC_BASE_URL, serverUrl); final Bundle userData = new Bundle(); userData.putString(KEY_OC_BASE_URL, serverUrl); manager.addAccountExplicitly(account, password, userData); } /** * Test the connexion to the server * Add the certificate to the knownServerCertificateStore if required * @throws KeyStoreException * @throws CertificateException * @throws NoSuchAlgorithmException * @throws IOException * @throws InterruptedException * @throws KeyStoreException exception * @throws CertificateException exception * @throws NoSuchAlgorithmException exception * @throws IOException exception * @throws InterruptedException exception */ public static void testConnection(OwnCloudClient client, Context context) throws KeyStoreException, public static void testConnection(final OwnCloudClient client, final Context context) throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException, Loading @@ -97,8 +95,8 @@ public abstract class TestUtils { if (RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED.equals(result.getCode())) { Log_OC.d("AbstractIT", "Accepting certificate"); CertificateCombinedException exception = (CertificateCombinedException) result.getException(); X509Certificate certificate = exception.getServerCertificate(); final CertificateCombinedException exception = (CertificateCombinedException) result.getException(); final X509Certificate certificate = exception.getServerCertificate(); NetworkUtils.addCertToKnownServersStore(certificate, context); Thread.sleep(1000); Loading @@ -110,7 +108,6 @@ public abstract class TestUtils { if (!result.isSuccess()) { throw new RuntimeException("No connection to server possible, even with accepted cert"); } } else { throw new RuntimeException("No connection to server possible"); } Loading @@ -123,18 +120,18 @@ public abstract class TestUtils { * @param filePath path of the file to create * @param iteration number of time to write dummy content * @return the File instance * @throws IOException * @throws SecurityException * @throws IOException exception * @throws SecurityException exception */ public static File createFile(String filePath, int iteration) throws IOException, SecurityException{ File file = new File(filePath); if (!file.getParentFile().exists()) { final File file = new File(filePath); if (file.getParentFile() != null && !file.getParentFile().exists()) { assertTrue(file.getParentFile().mkdirs()); } file.createNewFile(); FileWriter writer = new FileWriter(file); final FileWriter writer = new FileWriter(file); for (int i = 0; i < iteration; i++) { writer.write("123123123123123123123123123\n"); Loading app/src/test/java/foundation/e/drive/operations/UploadFileOperationTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -45,7 +45,7 @@ public class UploadFileOperationTest { public UploadFileOperationTest(){ TestUtils.loadServerCredentials(); accountManager = AccountManager.get(RuntimeEnvironment.application); accountManager = AccountManager.get(RuntimeEnvironment.getApplication()); TestUtils.prepareValidAccount(accountManager); ShadowLog.stream = System.out; client = CommonUtils.getOwnCloudClient(CommonUtils.getAccount(TestUtils.TEST_ACCOUNT_NAME, TestUtils.TEST_ACCOUNT_TYPE, accountManager), RuntimeEnvironment.application); Loading app/src/test/java/foundation/e/drive/services/AbstractServiceIT.java +1 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.android.controller.ServiceController; import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowAccountManager; import org.robolectric.shadows.ShadowLog; import foundation.e.drive.TestUtils; Loading app/src/test/java/foundation/e/drive/services/InitializerServiceTest.java +1 −2 Original line number Diff line number Diff line package foundation.e.drive.services; import android.accounts.AccountManager; import android.app.job.JobScheduler; import android.content.Context; Loading @@ -24,7 +23,7 @@ public class InitializerServiceTest extends AbstractServiceIT<InitializerService mServiceController = Robolectric.buildService(InitializerService.class); mService = mServiceController.get(); context = RuntimeEnvironment.application; context = RuntimeEnvironment.getApplication(); accountManager = AccountManager.get(context); jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); contentResolver = context.getContentResolver(); Loading Loading
app/build.gradle +1 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ android { testOptions { unitTests { returnDefaultValues = true //includeAndroidResources = true includeAndroidResources = true unitTests.all { systemProperty 'robolectric.dependency.repo.url', "\""+getTestProp("testServerUrl")+"\"" systemProperty 'robolectric.dependency.repo.username', "\""+getTestProp("testAccountName")+"\"" Loading
app/src/test/java/foundation/e/drive/TestUtils.java +29 −32 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ package foundation.e.drive; import android.accounts.Account; import android.accounts.AccountManager; import android.content.Context; import android.os.Bundle; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.network.CertificateCombinedException; Loading @@ -11,8 +12,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.status.GetRemoteStatusOperation; import org.junit.BeforeClass; import java.io.File; import java.io.FileWriter; import java.io.IOException; Loading @@ -20,10 +19,10 @@ import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.Properties; import static com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_OC_BASE_URL; import static org.junit.Assert.assertTrue; import static org.robolectric.Shadows.shadowOf; public abstract class TestUtils { public static final String TEST_LOCAL_ROOT_FOLDER_PATH = "/tmp/eDrive/test/"; //THis is where test file and folder for synchronisatio will be stored Loading @@ -31,8 +30,7 @@ public abstract class TestUtils { public static String TEST_ACCOUNT_TYPE ="eelo"; public static String TEST_SERVER_URI; public static String TEST_ACCOUNT_NAME; private static String TEST_ACCOUNT_PASSWORD; //Shouldn't be accessible from outside private static String TEST_ACCOUNT_PASSWORD; private static Account validAccount; Loading @@ -40,15 +38,16 @@ public abstract class TestUtils { * This method execute before the class, it assure that credentials are available */ public static void loadServerCredentials() { TEST_ACCOUNT_PASSWORD = BuildConfig.testAccountPWd; TEST_ACCOUNT_NAME = BuildConfig.testAccountName; TEST_SERVER_URI = BuildConfig.testServerUrl; final Properties properties = System.getProperties(); TEST_ACCOUNT_PASSWORD = properties.getProperty("robolectric.dependency.repo.password"); TEST_ACCOUNT_NAME = properties.getProperty("robolectric.dependency.repo.username"); TEST_SERVER_URI = properties.getProperty("robolectric.dependency.repo.url"); } /** * Get the valid Account object. Create it if it isn't already instanciated * @return * @return Account */ public static Account getValidAccount() { if (validAccount == null) { Loading @@ -65,23 +64,22 @@ public abstract class TestUtils { storeAccountInManager(getValidAccount(), TEST_ACCOUNT_PASSWORD, TEST_SERVER_URI, accountManager); } public static void storeAccountInManager(Account account, String password, String serverUrl, AccountManager manager) { shadowOf(manager).addAccount(account); // Commenting this make failure due to JobUtils.stopScheduleJob()" method... shadowOf(manager).setPassword(account, password); shadowOf(manager).setUserData(account, KEY_OC_BASE_URL, serverUrl); final Bundle userData = new Bundle(); userData.putString(KEY_OC_BASE_URL, serverUrl); manager.addAccountExplicitly(account, password, userData); } /** * Test the connexion to the server * Add the certificate to the knownServerCertificateStore if required * @throws KeyStoreException * @throws CertificateException * @throws NoSuchAlgorithmException * @throws IOException * @throws InterruptedException * @throws KeyStoreException exception * @throws CertificateException exception * @throws NoSuchAlgorithmException exception * @throws IOException exception * @throws InterruptedException exception */ public static void testConnection(OwnCloudClient client, Context context) throws KeyStoreException, public static void testConnection(final OwnCloudClient client, final Context context) throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException, Loading @@ -97,8 +95,8 @@ public abstract class TestUtils { if (RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED.equals(result.getCode())) { Log_OC.d("AbstractIT", "Accepting certificate"); CertificateCombinedException exception = (CertificateCombinedException) result.getException(); X509Certificate certificate = exception.getServerCertificate(); final CertificateCombinedException exception = (CertificateCombinedException) result.getException(); final X509Certificate certificate = exception.getServerCertificate(); NetworkUtils.addCertToKnownServersStore(certificate, context); Thread.sleep(1000); Loading @@ -110,7 +108,6 @@ public abstract class TestUtils { if (!result.isSuccess()) { throw new RuntimeException("No connection to server possible, even with accepted cert"); } } else { throw new RuntimeException("No connection to server possible"); } Loading @@ -123,18 +120,18 @@ public abstract class TestUtils { * @param filePath path of the file to create * @param iteration number of time to write dummy content * @return the File instance * @throws IOException * @throws SecurityException * @throws IOException exception * @throws SecurityException exception */ public static File createFile(String filePath, int iteration) throws IOException, SecurityException{ File file = new File(filePath); if (!file.getParentFile().exists()) { final File file = new File(filePath); if (file.getParentFile() != null && !file.getParentFile().exists()) { assertTrue(file.getParentFile().mkdirs()); } file.createNewFile(); FileWriter writer = new FileWriter(file); final FileWriter writer = new FileWriter(file); for (int i = 0; i < iteration; i++) { writer.write("123123123123123123123123123\n"); Loading
app/src/test/java/foundation/e/drive/operations/UploadFileOperationTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -45,7 +45,7 @@ public class UploadFileOperationTest { public UploadFileOperationTest(){ TestUtils.loadServerCredentials(); accountManager = AccountManager.get(RuntimeEnvironment.application); accountManager = AccountManager.get(RuntimeEnvironment.getApplication()); TestUtils.prepareValidAccount(accountManager); ShadowLog.stream = System.out; client = CommonUtils.getOwnCloudClient(CommonUtils.getAccount(TestUtils.TEST_ACCOUNT_NAME, TestUtils.TEST_ACCOUNT_TYPE, accountManager), RuntimeEnvironment.application); Loading
app/src/test/java/foundation/e/drive/services/AbstractServiceIT.java +1 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.android.controller.ServiceController; import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowAccountManager; import org.robolectric.shadows.ShadowLog; import foundation.e.drive.TestUtils; Loading
app/src/test/java/foundation/e/drive/services/InitializerServiceTest.java +1 −2 Original line number Diff line number Diff line package foundation.e.drive.services; import android.accounts.AccountManager; import android.app.job.JobScheduler; import android.content.Context; Loading @@ -24,7 +23,7 @@ public class InitializerServiceTest extends AbstractServiceIT<InitializerService mServiceController = Robolectric.buildService(InitializerService.class); mService = mServiceController.get(); context = RuntimeEnvironment.application; context = RuntimeEnvironment.getApplication(); accountManager = AccountManager.get(context); jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); contentResolver = context.getContentResolver(); Loading