|
@@ -7,8 +7,6 @@ import android.accounts.OperationCanceledException;
|
|
import android.app.Activity;
|
|
import android.app.Activity;
|
|
import android.content.ActivityNotFoundException;
|
|
import android.content.ActivityNotFoundException;
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
-import android.net.Uri;
|
|
|
|
-import android.os.Bundle;
|
|
|
|
|
|
|
|
import com.facebook.testing.screenshot.Screenshot;
|
|
import com.facebook.testing.screenshot.Screenshot;
|
|
import com.nextcloud.client.RetryTestRule;
|
|
import com.nextcloud.client.RetryTestRule;
|
|
@@ -29,21 +27,13 @@ import com.owncloud.android.lib.common.OwnCloudClient;
|
|
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
|
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
|
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
|
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
|
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
|
-import com.owncloud.android.lib.resources.e2ee.ToggleEncryptionRemoteOperation;
|
|
|
|
-import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation;
|
|
|
|
-import com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation;
|
|
|
|
-import com.owncloud.android.lib.resources.files.model.RemoteFile;
|
|
|
|
import com.owncloud.android.operations.CreateFolderOperation;
|
|
import com.owncloud.android.operations.CreateFolderOperation;
|
|
import com.owncloud.android.operations.UploadFileOperation;
|
|
import com.owncloud.android.operations.UploadFileOperation;
|
|
import com.owncloud.android.utils.FileStorageUtils;
|
|
import com.owncloud.android.utils.FileStorageUtils;
|
|
|
|
|
|
import junit.framework.TestCase;
|
|
import junit.framework.TestCase;
|
|
|
|
|
|
-import org.apache.commons.httpclient.HttpStatus;
|
|
|
|
-import org.apache.commons.httpclient.methods.GetMethod;
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
-import org.junit.After;
|
|
|
|
-import org.junit.Assert;
|
|
|
|
import org.junit.BeforeClass;
|
|
import org.junit.BeforeClass;
|
|
import org.junit.Rule;
|
|
import org.junit.Rule;
|
|
|
|
|
|
@@ -78,7 +68,7 @@ public abstract class AbstractIT {
|
|
protected static User user;
|
|
protected static User user;
|
|
protected static Context targetContext;
|
|
protected static Context targetContext;
|
|
|
|
|
|
- private Activity currentActivity;
|
|
|
|
|
|
+ protected Activity currentActivity;
|
|
|
|
|
|
protected FileDataStorageManager fileDataStorageManager =
|
|
protected FileDataStorageManager fileDataStorageManager =
|
|
new FileDataStorageManager(account, targetContext.getContentResolver());
|
|
new FileDataStorageManager(account, targetContext.getContentResolver());
|
|
@@ -87,26 +77,15 @@ public abstract class AbstractIT {
|
|
public static void beforeAll() {
|
|
public static void beforeAll() {
|
|
try {
|
|
try {
|
|
targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
|
targetContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
|
- Bundle arguments = androidx.test.platform.app.InstrumentationRegistry.getArguments();
|
|
|
|
-
|
|
|
|
- Uri baseUrl = Uri.parse(arguments.getString("TEST_SERVER_URL"));
|
|
|
|
- String loginName = arguments.getString("TEST_SERVER_USERNAME");
|
|
|
|
- String password = arguments.getString("TEST_SERVER_PASSWORD");
|
|
|
|
-
|
|
|
|
- Account temp = new Account(loginName + "@" + baseUrl, MainApp.getAccountType(targetContext));
|
|
|
|
- UserAccountManager accountManager = UserAccountManagerImpl.fromContext(targetContext);
|
|
|
|
- if (!accountManager.exists(temp)) {
|
|
|
|
- AccountManager platformAccountManager = AccountManager.get(targetContext);
|
|
|
|
- platformAccountManager.addAccountExplicitly(temp, password, null);
|
|
|
|
- platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_ACCOUNT_VERSION,
|
|
|
|
- Integer.toString(UserAccountManager.ACCOUNT_VERSION));
|
|
|
|
- platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_VERSION, "14.0.0.0");
|
|
|
|
- platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_BASE_URL, baseUrl.toString());
|
|
|
|
- platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_USER_ID, loginName); // same as userId
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ Account temp = new Account("test@server.com", MainApp.getAccountType(targetContext));
|
|
|
|
+ AccountManager platformAccountManager = AccountManager.get(targetContext);
|
|
|
|
+ platformAccountManager.addAccountExplicitly(temp, "password", null);
|
|
|
|
+ platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_BASE_URL, "https://server.com");
|
|
|
|
+ platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_USER_ID, "test");
|
|
|
|
|
|
final UserAccountManager userAccountManager = UserAccountManagerImpl.fromContext(targetContext);
|
|
final UserAccountManager userAccountManager = UserAccountManagerImpl.fromContext(targetContext);
|
|
- account = userAccountManager.getAccountByName(loginName + "@" + baseUrl);
|
|
|
|
|
|
+ account = userAccountManager.getAccountByName("test@server.com");
|
|
|
|
|
|
if (account == null) {
|
|
if (account == null) {
|
|
throw new ActivityNotFoundException();
|
|
throw new ActivityNotFoundException();
|
|
@@ -116,12 +95,6 @@ public abstract class AbstractIT {
|
|
user = optionalUser.orElseThrow(IllegalAccessError::new);
|
|
user = optionalUser.orElseThrow(IllegalAccessError::new);
|
|
|
|
|
|
client = OwnCloudClientFactory.createOwnCloudClient(account, targetContext);
|
|
client = OwnCloudClientFactory.createOwnCloudClient(account, targetContext);
|
|
-
|
|
|
|
- createDummyFiles();
|
|
|
|
-
|
|
|
|
- waitForServer(client, baseUrl);
|
|
|
|
-
|
|
|
|
- deleteAllFiles(); // makes sure that no file/folder is in root
|
|
|
|
} catch (OperationCanceledException e) {
|
|
} catch (OperationCanceledException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
} catch (AuthenticatorException e) {
|
|
} catch (AuthenticatorException e) {
|
|
@@ -133,36 +106,6 @@ public abstract class AbstractIT {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- @After
|
|
|
|
- public void after() {
|
|
|
|
- deleteAllFiles();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public static void deleteAllFiles() {
|
|
|
|
- RemoteOperationResult result = new ReadFolderRemoteOperation("/").execute(client);
|
|
|
|
- assertTrue(result.getLogMessage(), result.isSuccess());
|
|
|
|
-
|
|
|
|
- for (Object object : result.getData()) {
|
|
|
|
- RemoteFile remoteFile = (RemoteFile) object;
|
|
|
|
-
|
|
|
|
- if (!remoteFile.getRemotePath().equals("/")) {
|
|
|
|
- if (remoteFile.isEncrypted()) {
|
|
|
|
- assertTrue(new ToggleEncryptionRemoteOperation(remoteFile.getLocalId(),
|
|
|
|
- remoteFile.getRemotePath(),
|
|
|
|
- false)
|
|
|
|
- .execute(client)
|
|
|
|
- .isSuccess());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- assertTrue(new RemoveFileRemoteOperation(remoteFile.getRemotePath())
|
|
|
|
- .execute(client)
|
|
|
|
- .isSuccess()
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
protected FileDataStorageManager getStorageManager() {
|
|
protected FileDataStorageManager getStorageManager() {
|
|
return fileDataStorageManager;
|
|
return fileDataStorageManager;
|
|
}
|
|
}
|
|
@@ -171,14 +114,6 @@ public abstract class AbstractIT {
|
|
return AccountManager.get(targetContext).getAccounts();
|
|
return AccountManager.get(targetContext).getAccounts();
|
|
}
|
|
}
|
|
|
|
|
|
- private static void createDummyFiles() throws IOException {
|
|
|
|
- new File(FileStorageUtils.getSavePath(account.name)).mkdirs();
|
|
|
|
-
|
|
|
|
- createFile("empty.txt", 0);
|
|
|
|
- createFile("nonEmpty.txt", 100);
|
|
|
|
- createFile("chunkedFile.txt", 500000);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public static void createFile(String name, int iteration) throws IOException {
|
|
public static void createFile(String name, int iteration) throws IOException {
|
|
File file = new File(FileStorageUtils.getSavePath(account.name) + File.separator + name);
|
|
File file = new File(FileStorageUtils.getSavePath(account.name) + File.separator + name);
|
|
file.createNewFile();
|
|
file.createNewFile();
|
|
@@ -192,28 +127,6 @@ public abstract class AbstractIT {
|
|
writer.close();
|
|
writer.close();
|
|
}
|
|
}
|
|
|
|
|
|
- private static void waitForServer(OwnCloudClient client, Uri baseUrl) {
|
|
|
|
- GetMethod get = new GetMethod(baseUrl + "/status.php");
|
|
|
|
-
|
|
|
|
- try {
|
|
|
|
- int i = 0;
|
|
|
|
- while (client.executeMethod(get) != HttpStatus.SC_OK && i < 3) {
|
|
|
|
- System.out.println("wait…");
|
|
|
|
- Thread.sleep(60 * 1000);
|
|
|
|
- i++;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (i == 3) {
|
|
|
|
- Assert.fail("Server not ready!");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } catch (InterruptedException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
protected File getFile(String filename) throws IOException {
|
|
protected File getFile(String filename) throws IOException {
|
|
InputStream inputStream = getInstrumentation().getContext().getAssets().open(filename);
|
|
InputStream inputStream = getInstrumentation().getContext().getAssets().open(filename);
|
|
File temp = File.createTempFile("file", "file");
|
|
File temp = File.createTempFile("file", "file");
|