Skip to content

Commit

Permalink
Test: share a file, favorite it and search then for favorites
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
  • Loading branch information
tobiasKaminsky committed Jul 29, 2022
1 parent 6485130 commit f3594b7
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
NC_TEST_SERVER_BASEURL=https://server
NC_TEST_SERVER_USERNAME=test
NC_TEST_SERVER_PASSWORD=test
NC_TEST_SERVER_USERNAME2=admin
NC_TEST_SERVER_PASSWORD2=admin
android.useAndroidX=true
2 changes: 2 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ android {
testInstrumentationRunnerArgument "TEST_SERVER_URL", "${NC_TEST_SERVER_BASEURL}"
testInstrumentationRunnerArgument "TEST_SERVER_USERNAME", "${NC_TEST_SERVER_USERNAME}"
testInstrumentationRunnerArgument "TEST_SERVER_PASSWORD", "${NC_TEST_SERVER_PASSWORD}"
testInstrumentationRunnerArgument "TEST_SERVER_USERNAME2", "${NC_TEST_SERVER_USERNAME2}"
testInstrumentationRunnerArgument "TEST_SERVER_PASSWORD2", "${NC_TEST_SERVER_PASSWORD2}"
testInstrumentationRunnerArguments disableAnalytics: 'true'

multiDexEnabled true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public abstract class AbstractIT {
public static final String RANDOM_MTIME = "1464818400";

public static OwnCloudClient client;
public static OwnCloudClient client2;
protected static NextcloudClient nextcloudClient;
protected static Context context;
protected static Uri url;
Expand All @@ -106,6 +107,14 @@ public static void beforeAll() throws InterruptedException,
client.setCredentials(new OwnCloudBasicCredentials(loginName, password));
client.setUserId(loginName); // for test same as userId

// second user to test internal sharing
String loginName2 = arguments.getString("TEST_SERVER_USERNAME2");
String password2 = arguments.getString("TEST_SERVER_PASSWORD2");

client2 = OwnCloudClientFactory.createOwnCloudClient(url, context, true);
client2.setCredentials(new OwnCloudBasicCredentials(loginName2, password2));
client2.setUserId(loginName2); // for test same as userId

OwnCloudClientManagerFactory.setUserAgent("Mozilla/5.0 (Android) Nextcloud-android/1.0.0");

String userId = loginName; // for test same as userId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.model.RemoteFile;
import com.owncloud.android.lib.resources.shares.CreateShareRemoteOperation;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.status.GetCapabilitiesRemoteOperation;
import com.owncloud.android.lib.resources.status.OCCapability;

Expand Down Expand Up @@ -180,6 +182,48 @@ public void oneFavorite() {
assertEquals(path, remoteFile.getRemotePath());
}

@Test
public void favoriteFiles() throws IOException {
// share a file by second user to test user
String sharedFile = createFile("sharedFavoriteImage.jpg");
String sharedRemotePath = "/sharedFavoriteImage.jpg";
assertTrue(new UploadFileRemoteOperation(sharedFile, sharedRemotePath, "image/jpg", RANDOM_MTIME)
.execute(client2).isSuccess());

// share
assertTrue(new CreateShareRemoteOperation(sharedRemotePath,
ShareType.USER,
client.getUserId(),
false,
"",
31).execute(client2)
.isSuccess()
);

// test user: favorite it
assertTrue(new ToggleFavoriteRemoteOperation(true, sharedRemotePath).execute(client).isSuccess());

String filePath = createFile("favoriteImage.jpg");
String remotePath = "/favoriteImage.jpg";
assertTrue(new UploadFileRemoteOperation(filePath, remotePath, "image/jpg", RANDOM_MTIME)
.execute(client).isSuccess());

assertTrue(new ToggleFavoriteRemoteOperation(true, remotePath).execute(client).isSuccess());

SearchRemoteOperation sut = new SearchRemoteOperation("",
SearchRemoteOperation.SearchType.FAVORITE_SEARCH,
false,
capability);
RemoteOperationResult<List<RemoteFile>> result = sut.execute(client);

// test
assertTrue(result.isSuccess());
assertEquals(2, result.getResultData().size());

assertEquals(remotePath, result.getResultData().get(0).getRemotePath());
assertEquals(sharedRemotePath, result.getResultData().get(1).getRemotePath());
}

/**
* shows just all files, but sorted by date
*/
Expand Down

0 comments on commit f3594b7

Please sign in to comment.