-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathAbstractIT.java
More file actions
87 lines (68 loc) · 3.14 KB
/
AbstractIT.java
File metadata and controls
87 lines (68 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.owncloud.android;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.content.ActivityNotFoundException;
import android.content.Context;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.utils.FileStorageUtils;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import java.io.File;
import java.io.IOException;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
/**
* Common base for all integration tests
*/
@RunWith(AndroidJUnit4.class)
public abstract class AbstractIT {
protected static OwnCloudClient client;
protected static Account account;
protected static Context context;
private static final String username = "test";
private static final String password = "test";
private static final String baseUrl = "server";
@BeforeClass
public static void beforeAll() {
try {
context = InstrumentationRegistry.getTargetContext();
Account temp = new Account(username + "@" + baseUrl, MainApp.getAccountType(context));
if (!com.owncloud.android.authentication.AccountUtils.exists(temp, context)) {
AccountManager accountManager = AccountManager.get(context);
accountManager.addAccountExplicitly(temp, password, null);
accountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_ACCOUNT_VERSION,
Integer.toString(com.owncloud.android.authentication.AccountUtils.ACCOUNT_VERSION));
accountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_VERSION, "14.0.0.0");
accountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_BASE_URL, "http://" + baseUrl);
}
account = com.owncloud.android.authentication.AccountUtils.getOwnCloudAccountByName(context,
username + "@" + baseUrl);
if (account == null) {
throw new ActivityNotFoundException();
}
client = OwnCloudClientFactory.createOwnCloudClient(account, context);
createDummyFiles();
} catch (OperationCanceledException e) {
e.printStackTrace();
} catch (AuthenticatorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (AccountUtils.AccountNotFoundException e) {
e.printStackTrace();
}
}
protected FileDataStorageManager getStorageManager() {
return new FileDataStorageManager(account, context.getContentResolver());
}
private static void createDummyFiles() throws IOException {
new File(FileStorageUtils.getSavePath(account.name)).mkdirs();
File file = new File(FileStorageUtils.getSavePath(account.name) + "/123.txt");
file.createNewFile();
}
}