diff --git a/.codecov.yml b/.codecov.yml index cf2e895b16..5a7046653d 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -11,4 +11,3 @@ coverage: comment: layout: "header, diff, changes, uncovered, tree" behavior: default - \ No newline at end of file diff --git a/.drone.yml b/.drone.yml index 3328d708e5..e75f7ee6ae 100644 --- a/.drone.yml +++ b/.drone.yml @@ -44,5 +44,7 @@ pipeline: services: server: image: nextcloudci/server:server-1 + server2: + image: nextcloudci/server:server-1 branches: master diff --git a/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java index a2f16068cc..6956d9c5ea 100644 --- a/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/ChunkedUploadRemoteFileOperation.java @@ -76,6 +76,11 @@ protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOExcep RandomAccessFile raf = null; File file = new File(mLocalPath); + + if (!file.exists()) { + return new RemoteOperationResult(RemoteOperationResult.ResultCode.LOCAL_FILE_NOT_FOUND); + } + SharedPreferences sharedPref = mContext.getApplicationContext(). getSharedPreferences("com.nextcloud.PREFERENCE_upload", Context.MODE_PRIVATE); String chunkId = String.format("%08d", Math.abs(file.getName().hashCode())); diff --git a/src/com/owncloud/android/lib/resources/files/FileUtils.java b/src/com/owncloud/android/lib/resources/files/FileUtils.java index 828b4c01de..cd8dd3eaec 100644 --- a/src/com/owncloud/android/lib/resources/files/FileUtils.java +++ b/src/com/owncloud/android/lib/resources/files/FileUtils.java @@ -24,6 +24,8 @@ package com.owncloud.android.lib.resources.files; +import com.owncloud.android.lib.common.utils.Log_OC; + import java.io.File; public class FileUtils { @@ -48,4 +50,26 @@ public static boolean isValidName(String fileName) { return !fileName.contains(PATH_SEPARATOR); } + + /** + * Validate the path to detect if contains any forbidden character: \ , < , > , : , " , | , + * ? , * + * @param path + * @return + */ + public static boolean isValidPath(String path, boolean versionSupportsForbidenChars) { + boolean result = true; + + Log_OC.d(TAG, "path ....... " + path); + if (!versionSupportsForbidenChars && + (path.contains("\\") || path.contains("<") || path.contains(">") || + path.contains(":") || path.contains("\"") || path.contains("|") || + path.contains("?") || path.contains("*") ) ){ + result = false; + } else if (path.contains("\\")) { + return false; + } + return result; + } + } diff --git a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java index 6b9b2ac8c8..089f8192e6 100644 --- a/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java +++ b/src/com/owncloud/android/lib/resources/files/UploadRemoteFileOperation.java @@ -138,6 +138,11 @@ protected RemoteOperationResult uploadFile(OwnCloudClient client) throws IOExcep try { File f = new File(mLocalPath); + + if (!f.exists()) { + return new RemoteOperationResult(RemoteOperationResult.ResultCode.LOCAL_FILE_NOT_FOUND); + } + mEntity = new FileRequestEntity(f, mMimeType); synchronized (mDataTransferListeners) { ((ProgressiveDataTransferer)mEntity) diff --git a/test_client/build.gradle b/test_client/build.gradle index adfe3336ba..9ea68550b1 100644 --- a/test_client/build.gradle +++ b/test_client/build.gradle @@ -41,6 +41,8 @@ dependencies { androidJacocoAnt "org.jacoco:org.jacoco.core:${project.jacocoVersion}" androidJacocoAnt "org.jacoco:org.jacoco.report:${project.jacocoVersion}" androidJacocoAnt "org.jacoco:org.jacoco.agent:${project.jacocoVersion}" + androidTestCompile 'junit:junit:4.12' + implementation 'commons-io:commons-io:2.6' } android { diff --git a/test_client/assets/imageFile.png b/test_client/src/androidTest/assets/imageFile.png similarity index 100% rename from test_client/assets/imageFile.png rename to test_client/src/androidTest/assets/imageFile.png diff --git a/test_client/assets/textFile.txt b/test_client/src/androidTest/assets/textFile.txt similarity index 100% rename from test_client/assets/textFile.txt rename to test_client/src/androidTest/assets/textFile.txt diff --git a/test_client/assets/videoFile.MP4 b/test_client/src/androidTest/assets/videoFile.mp4 similarity index 100% rename from test_client/assets/videoFile.MP4 rename to test_client/src/androidTest/assets/videoFile.mp4 diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/CopyFileTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/CopyFileTest.java similarity index 57% rename from test_client/tests/src/com/owncloud/android/lib/test_project/test/CopyFileTest.java rename to test_client/src/androidTest/java/com/owncloud/android/lib/CopyFileTest.java index 1c350f83fd..5d32561510 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/CopyFileTest.java +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/CopyFileTest.java @@ -1,55 +1,40 @@ /* ownCloud Android Library is available under MIT license * Copyright (C) 2014 ownCloud Inc. - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ -package com.owncloud.android.lib.test_project.test; +package com.owncloud.android.lib; -import android.content.Context; -import android.net.Uri; -import android.test.ActivityInstrumentationTestCase2; import android.util.Log; -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.OwnCloudClientFactory; -import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; -import com.owncloud.android.lib.common.network.NetworkUtils; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.resources.files.CopyRemoteFileOperation; -import com.owncloud.android.lib.test_project.R; -import com.owncloud.android.lib.test_project.SelfSignedConfidentSslSocketFactory; -import com.owncloud.android.lib.test_project.TestActivity; - -import junit.framework.AssertionFailedError; +import com.owncloud.android.lib.resources.status.OwnCloudVersion; +import com.owncloud.android.lib.testclient.TestActivity; import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.protocol.Protocol; -import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; import java.io.File; -import java.security.GeneralSecurityException; - -//import android.test.AndroidTestCase; /** * Class to test CopyRemoteFileOperation @@ -69,7 +54,8 @@ */ //public class CopyFileTest extends AndroidTestCase { -public class CopyFileTest extends ActivityInstrumentationTestCase2 { +//public class CopyFileTest extends ActivityInstrumentationTestCase2 { +public class CopyFileTest extends RemoteTest { private static final String LOG_TAG = CopyFileTest.class.getCanonicalName(); @@ -97,8 +83,7 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2 private static final String TARGET_PATH_TO_FILE_1 = TARGET_BASE_FOLDER + FILE1; private static final String SRC_PATH_TO_FILE_2 = SRC_BASE_FOLDER + FILE2; - private static final String TARGET_PATH_TO_FILE_2_RENAMED = - TARGET_BASE_FOLDER + "renamed_" + FILE2; + private static final String TARGET_PATH_TO_FILE_2_RENAMED = TARGET_BASE_FOLDER + "renamed_" + FILE2; private static final String SRC_PATH_TO_FILE_3 = SRC_BASE_FOLDER + FILE3; private static final String SRC_PATH_TO_FILE_3_RENAMED = SRC_BASE_FOLDER + "renamed_" + FILE3; @@ -119,25 +104,20 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2 private static final String SRC_PATH_TO_FULL_FOLDER_2 = SRC_BASE_FOLDER + FOLDER2; - private static final String TARGET_PATH_TO_FULL_FOLDER_2_RENAMED = - TARGET_BASE_FOLDER + "renamed_" + FOLDER2; + private static final String TARGET_PATH_TO_FULL_FOLDER_2_RENAMED = TARGET_BASE_FOLDER + "renamed_" + FOLDER2; private static final String SRC_PATH_TO_FULL_FOLDER_3 = SRC_BASE_FOLDER + FOLDER3; private static final String SRC_PATH_TO_FULL_FOLDER_4 = SRC_BASE_FOLDER + FOLDER4; - private static final String SRC_PATH_TO_FULL_FOLDER_3_RENAMED = - SRC_BASE_FOLDER + "renamed_" + FOLDER3; + private static final String SRC_PATH_TO_FULL_FOLDER_3_RENAMED = SRC_BASE_FOLDER + "renamed_" + FOLDER3; - private static final String TARGET_PATH_RENAMED_WITH_INVALID_CHARS = - SRC_BASE_FOLDER + "renamed:??_" + FILE6; + private static final String TARGET_PATH_RENAMED_WITH_INVALID_CHARS = SRC_BASE_FOLDER + "renamed:??_" + FILE6; - private static final String TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4 = TARGET_BASE_FOLDER - + FOLDER4; + private static final String TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4 = TARGET_BASE_FOLDER + FOLDER4; private static final String TARGET_PATH_TO_NON_EXISTENT_FILE = TARGET_BASE_FOLDER + NO_FILE; - private static final String TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER = - TARGET_BASE_FOLDER + NO_FOLDER + FILE5; + private static final String TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER = TARGET_BASE_FOLDER + NO_FOLDER + FILE5; private static final String TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7 = TARGET_BASE_FOLDER + FILE7; @@ -202,59 +182,25 @@ public class CopyFileTest extends ActivityInstrumentationTestCase2 TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7 }; - - String mServerUri, mUser, mPass; - OwnCloudClient mClient = null; - - public CopyFileTest() { - super(TestActivity.class); - - Protocol pr = Protocol.getProtocol("https"); - if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) { - try { - ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory(); - Protocol.registerProtocol( - "https", - new Protocol("https", psf, 443)); - - } catch (GeneralSecurityException e) { - throw new AssertionFailedError( - "Self-signed confident SSL context could not be loaded"); - } - } - - } - - - protected Context getContext() { - return getActivity(); - } - @Override protected void setUp() throws Exception { super.setUp(); - // Next initialization cannot be done in the constructor because getContext() is not - // ready yet, returns NULL. - initAccessToServer(getContext()); - Log.v(LOG_TAG, "Setting up the remote fixture..."); - RemoteOperationResult result = null; + RemoteOperationResult result; for (String folderPath : FOLDERS_IN_FIXTURE) { - result = TestActivity.createFolder(folderPath, true, mClient); + result = mActivity.createFolder(folderPath, true); if (!result.isSuccess()) { Utils.logAndThrow(LOG_TAG, result); } } - File txtFile = TestActivity.extractAsset( - TestActivity.ASSETS__TEXT_FILE_NAME, getContext() - ); + File txtFile = getFile(TestActivity.ASSETS__TEXT_FILE_NAME); + for (String filePath : FILES_IN_FIXTURE) { - result = TestActivity.uploadFile( - txtFile.getAbsolutePath(), filePath, "txt/plain", mClient - ); + result = mActivity.uploadFile(txtFile.getAbsolutePath(), filePath, "txt/plain", null); + if (!result.isSuccess()) { Utils.logAndThrow(LOG_TAG, result); } @@ -274,148 +220,90 @@ public void testCopyRemoteFileOperation() { /// successful cases // copy file - CopyRemoteFileOperation copyOperation = new CopyRemoteFileOperation( - SRC_PATH_TO_FILE_1, - TARGET_PATH_TO_FILE_1, - false - ); + CopyRemoteFileOperation copyOperation = new CopyRemoteFileOperation(SRC_PATH_TO_FILE_1, TARGET_PATH_TO_FILE_1, + false); RemoteOperationResult result = copyOperation.execute(mClient); - assertTrue(result.isSuccess()); + assertTrue("copy file",result.isSuccess()); // copy & rename file, different location - copyOperation = new CopyRemoteFileOperation( - SRC_PATH_TO_FILE_2, - TARGET_PATH_TO_FILE_2_RENAMED, - false - ); + copyOperation = new CopyRemoteFileOperation(SRC_PATH_TO_FILE_2, TARGET_PATH_TO_FILE_2_RENAMED, false); result = copyOperation.execute(mClient); - assertTrue(result.isSuccess()); + assertTrue("copy & rename file, different location",result.isSuccess()); // copy & rename file, same location (rename file) - copyOperation = new CopyRemoteFileOperation( - SRC_PATH_TO_FILE_3, - SRC_PATH_TO_FILE_3_RENAMED, - false - ); + copyOperation = new CopyRemoteFileOperation(SRC_PATH_TO_FILE_3, SRC_PATH_TO_FILE_3_RENAMED, false); result = copyOperation.execute(mClient); - assertTrue(result.isSuccess()); + assertTrue("copy & rename file, same location (rename file)",result.isSuccess()); // copy empty folder - copyOperation = new CopyRemoteFileOperation( - SRC_PATH_TO_EMPTY_FOLDER, - TARGET_PATH_TO_EMPTY_FOLDER, - false - ); + copyOperation = new CopyRemoteFileOperation(SRC_PATH_TO_EMPTY_FOLDER, TARGET_PATH_TO_EMPTY_FOLDER, false); result = copyOperation.execute(mClient); - assertTrue(result.isSuccess()); + assertTrue("copy empty folder",result.isSuccess()); // copy non-empty folder - copyOperation = new CopyRemoteFileOperation( - SRC_PATH_TO_FULL_FOLDER_1, - TARGET_PATH_TO_FULL_FOLDER_1, - false - ); + copyOperation = new CopyRemoteFileOperation(SRC_PATH_TO_FULL_FOLDER_1, TARGET_PATH_TO_FULL_FOLDER_1, false); result = copyOperation.execute(mClient); - assertTrue(result.isSuccess()); + assertTrue("copy non-empty folder",result.isSuccess()); // copy & rename folder, different location - copyOperation = new CopyRemoteFileOperation( - SRC_PATH_TO_FULL_FOLDER_2, - TARGET_PATH_TO_FULL_FOLDER_2_RENAMED, - false - ); + copyOperation = new CopyRemoteFileOperation(SRC_PATH_TO_FULL_FOLDER_2, TARGET_PATH_TO_FULL_FOLDER_2_RENAMED, + false); result = copyOperation.execute(mClient); - assertTrue(result.isSuccess()); + assertTrue("copy & rename folder, different location",result.isSuccess()); // copy & rename folder, same location (rename folder) - copyOperation = new CopyRemoteFileOperation( - SRC_PATH_TO_FULL_FOLDER_3, - SRC_PATH_TO_FULL_FOLDER_3_RENAMED, - false - ); + copyOperation = new CopyRemoteFileOperation(SRC_PATH_TO_FULL_FOLDER_3, SRC_PATH_TO_FULL_FOLDER_3_RENAMED, + false); result = copyOperation.execute(mClient); - assertTrue(result.isSuccess()); + assertTrue("copy & rename folder, same location (rename folder)",result.isSuccess()); // copy for nothing (success, but no interaction with network) - copyOperation = new CopyRemoteFileOperation( - SRC_PATH_TO_FILE_4, - SRC_PATH_TO_FILE_4, - false - ); + copyOperation = new CopyRemoteFileOperation(SRC_PATH_TO_FILE_4, SRC_PATH_TO_FILE_4, false); result = copyOperation.execute(mClient); - assertTrue(result.isSuccess()); + assertTrue("copy for nothing (success, but no interaction with network)", result.isSuccess()); // copy overwriting - copyOperation = new CopyRemoteFileOperation( - SRC_PATH_TO_FULL_FOLDER_4, - TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4, - true - ); + copyOperation = new CopyRemoteFileOperation(SRC_PATH_TO_FULL_FOLDER_4, + TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4, true); result = copyOperation.execute(mClient); - assertTrue(result.isSuccess()); + assertTrue("copy overwriting", result.isSuccess()); /// Failed cases // file to copy does not exist - copyOperation = new CopyRemoteFileOperation( - SRC_PATH_TO_NON_EXISTENT_FILE, - TARGET_PATH_TO_NON_EXISTENT_FILE, - false - ); + copyOperation = new CopyRemoteFileOperation(SRC_PATH_TO_NON_EXISTENT_FILE, TARGET_PATH_TO_NON_EXISTENT_FILE, + false); result = copyOperation.execute(mClient); - assertTrue(result.getCode() == ResultCode.FILE_NOT_FOUND); + assertTrue("file to copy does not exist",result.getCode() == ResultCode.FILE_NOT_FOUND); // folder to copy into does no exist - copyOperation = new CopyRemoteFileOperation( - SRC_PATH_TO_FILE_5, - TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER, - false - ); - result = copyOperation.execute(mClient); - assertTrue(result.getHttpCode() == HttpStatus.SC_CONFLICT); - - // target location (renaming) has invalid characters - copyOperation = new CopyRemoteFileOperation( - SRC_PATH_TO_FILE_6, - TARGET_PATH_RENAMED_WITH_INVALID_CHARS, - false - ); + copyOperation = new CopyRemoteFileOperation(SRC_PATH_TO_FILE_5, TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER, + false); result = copyOperation.execute(mClient); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); + assertTrue("folder to copy into does no exist",result.getHttpCode() == HttpStatus.SC_CONFLICT); // name collision - copyOperation = new CopyRemoteFileOperation( - SRC_PATH_TO_FILE_1, - TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7, - false - ); + mActivity.getClient().setOwnCloudVersion(OwnCloudVersion.nextcloud_10); + copyOperation = new CopyRemoteFileOperation(SRC_PATH_TO_FILE_1, TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7, false); result = copyOperation.execute(mClient); - assertTrue(result.getCode() == ResultCode.INVALID_OVERWRITE); + assertTrue("Name collision", result.getCode() == ResultCode.INVALID_OVERWRITE); // copy a folder into a descendant - copyOperation = new CopyRemoteFileOperation( - SRC_BASE_FOLDER, - SRC_PATH_TO_EMPTY_FOLDER, - false - ); + copyOperation = new CopyRemoteFileOperation(SRC_BASE_FOLDER, SRC_PATH_TO_EMPTY_FOLDER, false); result = copyOperation.execute(mClient); - assertTrue(result.getCode() == ResultCode.INVALID_COPY_INTO_DESCENDANT); + assertTrue("Copy a folder into a descendant",result.getCode() == ResultCode.INVALID_COPY_INTO_DESCENDANT); } @Override protected void tearDown() throws Exception { Log.v(LOG_TAG, "Deleting remote fixture..."); - String[] mPathsToCleanUp = { - SRC_BASE_FOLDER, - TARGET_BASE_FOLDER - }; + String[] mPathsToCleanUp = {SRC_BASE_FOLDER, TARGET_BASE_FOLDER}; for (String path : mPathsToCleanUp) { - RemoteOperationResult removeResult = - TestActivity.removeFile(path, mClient); - if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) { + RemoteOperationResult removeResult = mActivity.removeFile(path); + if (!removeResult.isSuccess()) { Utils.logAndThrow(LOG_TAG, removeResult); } } @@ -424,33 +312,4 @@ protected void tearDown() throws Exception { Log.v(LOG_TAG, "Remote fixture delete."); } - - - private void initAccessToServer(Context context) { - Log.v(LOG_TAG, "Setting up client instance to access OC server..."); - - mServerUri = context.getString(R.string.server_base_url); - mUser = context.getString(R.string.username); - mPass = context.getString(R.string.password); - - mClient = new OwnCloudClient( - Uri.parse(mServerUri), - NetworkUtils.getMultiThreadedConnManager() - ); - mClient.setDefaultTimeouts( - OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT, - OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT); - mClient.setFollowRedirects(true); - mClient.setCredentials( - OwnCloudCredentialsFactory.newBasicCredentials( - mUser, - mPass - ) - ); - - Log.v(LOG_TAG, "Client instance set up."); - - } - - } diff --git a/test_client/src/androidTest/java/com/owncloud/android/lib/CreateFolderTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/CreateFolderTest.java new file mode 100644 index 0000000000..7cd6926f14 --- /dev/null +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/CreateFolderTest.java @@ -0,0 +1,136 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ +package com.owncloud.android.lib; + +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; +import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation; +import com.owncloud.android.lib.resources.status.OwnCloudVersion; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * Class to test Create Folder Operation + * + * @author masensio + * @author David A. Velasco + */ +public class CreateFolderTest extends RemoteTest { + + + private static final String LOG_TAG = CreateFolderTest.class.getCanonicalName(); + + private static final String FOLDER_PATH_BASE = "/testCreateFolder"; + + private List mCreatedFolderPaths; + private String mFullPath2FolderBase; + + public CreateFolderTest() { + super(); + mCreatedFolderPaths = new ArrayList<>(); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + mCreatedFolderPaths.clear(); + mFullPath2FolderBase = mBaseFolderPath + FOLDER_PATH_BASE; + } + + /** + * Test Create Folder + */ + public void testCreateFolder() { + String remotePath = mFullPath2FolderBase; + mCreatedFolderPaths.add(remotePath); + RemoteOperationResult result = mActivity.createFolder(remotePath, true); + assertTrue(result.isSuccess()); + + // Create Subfolder + remotePath = mFullPath2FolderBase + FOLDER_PATH_BASE; + mCreatedFolderPaths.add(remotePath); + result = mActivity.createFolder(remotePath, true); + assertTrue(result.isSuccess()); + } + + /** + * Test to Create Folder with special characters: / \ < > : " | ? * + * > oc8.1 no characters are forbidden + */ + public void testCreateFolderSpecialCharactersOnNewVersion() { + mActivity.getClient().setOwnCloudVersion(OwnCloudVersion.nextcloud_10); + + String remotePath = mFullPath2FolderBase + "_<"; + RemoteOperationResult result = mActivity.createFolder(remotePath, true); + assertTrue("Remote path: " + remotePath, result.isSuccess()); + + remotePath = mFullPath2FolderBase + "_>"; + result = mActivity.createFolder(remotePath, true); + assertTrue("Remote path: " + remotePath, result.isSuccess()); + + remotePath = mFullPath2FolderBase + "_:"; + result = mActivity.createFolder(remotePath, true); + assertTrue("Remote path: " + remotePath, result.isSuccess()); + + remotePath = mFullPath2FolderBase + "_\""; + result = mActivity.createFolder(remotePath, true); + assertTrue("Remote path: " + remotePath, result.isSuccess()); + + remotePath = mFullPath2FolderBase + "_|"; + result = mActivity.createFolder(remotePath, true); + assertTrue("Remote path: " + remotePath, result.isSuccess()); + + remotePath = mFullPath2FolderBase + "_?"; + result = mActivity.createFolder(remotePath, true); + assertTrue("Remote path: " + remotePath, result.isSuccess()); + + remotePath = mFullPath2FolderBase + "_*"; + result = mActivity.createFolder(remotePath, true); + assertTrue("Remote path: " + remotePath, result.isSuccess()); + } + + + @Override + protected void tearDown() throws Exception { + Iterator it = mCreatedFolderPaths.iterator(); + RemoteOperationResult removeResult; + while (it.hasNext()) { + String path = it.next(); + + ExistenceCheckRemoteOperation existenceCheckOperation = new ExistenceCheckRemoteOperation(path, false); + RemoteOperationResult result = existenceCheckOperation.execute(mClient); + + if (result.isSuccess()) { + removeResult = mActivity.removeFile(path); + if (!removeResult.isSuccess()) { + Utils.logAndThrow(LOG_TAG, removeResult); + } + } + } + super.tearDown(); + } +} diff --git a/test_client/src/androidTest/java/com/owncloud/android/lib/CreateShareTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/CreateShareTest.java new file mode 100644 index 0000000000..8fe5341b9f --- /dev/null +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/CreateShareTest.java @@ -0,0 +1,180 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +package com.owncloud.android.lib; + +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; +import com.owncloud.android.lib.resources.shares.ShareType; +import com.owncloud.android.lib.testclient.TestActivity; + +import java.io.File; + +/** + * Test Create Share: the server must support SHARE API + */ +public class CreateShareTest extends RemoteTest { + + private static final String LOG_TAG = CreateShareTest.class.getCanonicalName(); + + /* File to share.*/ + private static final String FILE_TO_SHARE = "/fileToShare.txt"; + + /* Non-existent file*/ + private static final String NON_EXISTENT_FILE = "/nonExistentFile.txt"; + + private TestActivity mActivity; + private String mFullPath2FileToShare; + private String mFullPath2NonExistentFile; + + @Override + protected void setUp() throws Exception { + super.setUp(); + setActivityInitialTouchMode(false); + mActivity = getActivity(); + mFullPath2FileToShare = mBaseFolderPath + FILE_TO_SHARE; + mFullPath2NonExistentFile = mBaseFolderPath + NON_EXISTENT_FILE; + + File textFile = getFile(TestActivity.ASSETS__TEXT_FILE_NAME); + RemoteOperationResult result = mActivity.uploadFile(textFile.getAbsolutePath(), mFullPath2FileToShare, + "txt/plain", null); + + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + } + + /** + * Test creation of public shares + */ + public void testCreatePublicShare() { + /// Successful cases + RemoteOperationResult result = mActivity.createShare(mFullPath2FileToShare, ShareType.PUBLIC_LINK, "", false, + "", 1); + assertTrue(result.isSuccess()); + + /// Failed cases + + // file doesn't exist + result = mActivity.createShare(mFullPath2NonExistentFile, ShareType.PUBLIC_LINK, "", false, "", 1); + assertFalse(result.isSuccess()); + assertEquals(ResultCode.FILE_NOT_FOUND, result.getCode()); + } + + /** + * Test creation of private shares with groups + */ + public void testCreatePrivateShareWithUser() { + /// Successful cases + RemoteOperationResult result = mActivity.createShare(mFullPath2FileToShare, ShareType.USER, "admin", false, + "", 31); + assertTrue(result.isSuccess()); + + /// Failed cases + + // sharee doesn't exist + result = mActivity.createShare(mFullPath2FileToShare, ShareType.USER, "no_exist", false, "", 31); + assertFalse(result.isSuccess()); + // TODO 404 is File not found, but actually it is "user not found" + assertEquals(ResultCode.FILE_NOT_FOUND, result.getCode()); + + // file doesn't exist + result = mActivity.createShare(mFullPath2NonExistentFile, ShareType.USER, "admin", false, "", 31); + assertFalse(result.isSuccess()); + assertEquals(ResultCode.FILE_NOT_FOUND, result.getCode()); + } + + /** + * Test creation of private shares with groups + */ + public void testCreatePrivateShareWithGroup() { + /// Successful cases + RemoteOperationResult result = mActivity.createShare(mFullPath2FileToShare, ShareType.GROUP, "admin", false, + "", 1); + assertTrue(result.isSuccess()); + + + /// Failed cases + + // sharee doesn't exist + result = mActivity.createShare(mFullPath2FileToShare, ShareType.GROUP, "no_exist", false, "", 31); + assertFalse(result.isSuccess()); + // TODO 404 is File not found, but actually it is "user not found" + assertEquals(ResultCode.FILE_NOT_FOUND, result.getCode()); + + // file doesn't exist + result = mActivity.createShare(mFullPath2NonExistentFile, ShareType.GROUP, "admin", false, "", 31); + assertFalse(result.isSuccess()); + assertEquals(ResultCode.FILE_NOT_FOUND, result.getCode()); + } + + /** + * Test creation of federated shares with remote users + */ + public void testCreateFederatedShareWithUser() { + + /// Successful cases + RemoteOperationResult result = mActivity.createShare(mFullPath2FileToShare, ShareType.FEDERATED, + "admin@" + mServerUri2, false, "", 1); + assertTrue(result.isSuccess()); + + /// Failed cases + + // sharee doesn't exist in an existing remote server + result = mActivity.createShare(mFullPath2FileToShare, ShareType.FEDERATED, "no_exist@" + mServerUri2, false, + "", 31); + assertFalse("sharee doesn't exist in an existing remote server", result.isSuccess()); + assertEquals("sharee doesn't exist in an existing remote server, forbidden", RemoteOperationResult.ResultCode.SHARE_FORBIDDEN, result.getCode()); + + // error message from server as part of the result + // TODO verify error message + assertTrue("sharee doesn't exist in an existing remote server, no error message", result.getData().size() == 1 && result.getData().get(0) instanceof String); + + // remote server doesn't exist + result = mActivity.createShare(mFullPath2FileToShare, ShareType.FEDERATED, "no_exist", false, "", 31); + assertFalse(result.isSuccess()); + // TODO expected: but was: + assertEquals("remote server doesn't exist",ResultCode.SHARE_FORBIDDEN, result.getCode()); + + // error message from server as part of the result + // TODO verify error message + assertTrue("remote server doesn't exist, no error message", result.getData().size() == 1 && result.getData().get(0) instanceof String); + + // file doesn't exist + result = mActivity.createShare(mFullPath2NonExistentFile, ShareType.FEDERATED, "admin@" + mServerUri2, false, + "", 31); + assertFalse("file doesn't exist", result.isSuccess()); + assertEquals("file doesn't exist", ResultCode.FILE_NOT_FOUND, result.getCode()); + } + + + @Override + protected void tearDown() throws Exception { + RemoteOperationResult removeResult = mActivity.removeFile(mFullPath2FileToShare); + if (!removeResult.isSuccess()) { + Utils.logAndThrow(LOG_TAG, removeResult); + } + super.tearDown(); + } +} diff --git a/test_client/src/androidTest/java/com/owncloud/android/lib/DeleteFileTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/DeleteFileTest.java new file mode 100644 index 0000000000..55e0a51cfb --- /dev/null +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/DeleteFileTest.java @@ -0,0 +1,95 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +package com.owncloud.android.lib; + +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.testclient.TestActivity; + +import java.io.File; + +/** + * Class to test Delete a File Operation + * + * @author masensio + */ + +public class DeleteFileTest extends RemoteTest { + + private static final String LOG_TAG = DeleteFileTest.class.getCanonicalName(); + + /* Folder data to delete. */ + private static final String FOLDER_PATH = "/folderToDelete"; + + /* File to delete. */ + private static final String FILE_PATH = "/fileToDelete.txt"; + + private String mFullPath2Folder; + private String mFullPath2File; + + @Override + protected void setUp() throws Exception { + super.setUp(); + setActivityInitialTouchMode(false); + mFullPath2Folder = mBaseFolderPath + FOLDER_PATH; + mFullPath2File = mBaseFolderPath + FILE_PATH; + + RemoteOperationResult result = mActivity.createFolder(mFullPath2Folder, true); + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + + File textFile = getFile(TestActivity.ASSETS__TEXT_FILE_NAME); + result = mActivity.uploadFile(textFile.getAbsolutePath(), mFullPath2File, "txt/plain", null); + + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + } + + /** + * Test Remove Folder + */ + public void testRemoveFolder() { + RemoteOperationResult result = mActivity.removeFile(mFullPath2Folder); + assertTrue(result.isSuccess()); + } + + /** + * Test Remove File + */ + public void testRemoveFile() { + RemoteOperationResult result = mActivity.removeFile(mFullPath2File); + assertTrue(result.isSuccess()); + } + + + @Override + protected void tearDown() throws Exception { + // nothing to do: + // - if tests were fine, there is nothing to clean up in the server side + // - if tests failed, there is nothing we can do to clean up the server side + super.tearDown(); + } +} diff --git a/test_client/src/androidTest/java/com/owncloud/android/lib/DownloadFileTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/DownloadFileTest.java new file mode 100644 index 0000000000..4cf1ae8c19 --- /dev/null +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/DownloadFileTest.java @@ -0,0 +1,135 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +package com.owncloud.android.lib; + +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; +import com.owncloud.android.lib.resources.files.RemoteFile; +import com.owncloud.android.lib.testclient.TestActivity; + +import org.apache.commons.io.FileUtils; + +import java.io.File; +import java.io.FileNotFoundException; + +/** + * Class to test Download File Operation + * + * @author masensio + * @author David A. Velasco + */ + +public class DownloadFileTest extends RemoteTest { + + + private static final String LOG_TAG = DownloadFileTest.class.getCanonicalName(); + + /* Files to download. These files must exist on the account */ + private static final String IMAGE_PATH = "/fileToDownload.png"; + private static final String IMAGE_PATH_WITH_SPECIAL_CHARS = "/@file@download.png"; + private static final String IMAGE_NOT_FOUND = "/fileNotFound.png"; + + private String mFullPath2Image; + private String mFullPath2ImageWitSpecialChars; + private String mFullPath2ImageNotFound; + private String mDownloadedFilePath; + + @Override + protected void setUp() throws Exception { + super.setUp(); + setActivityInitialTouchMode(false); + mDownloadedFilePath = null; + mFullPath2Image = mBaseFolderPath + IMAGE_PATH; + mFullPath2ImageWitSpecialChars = mBaseFolderPath + IMAGE_PATH_WITH_SPECIAL_CHARS; + mFullPath2ImageNotFound = mBaseFolderPath + IMAGE_NOT_FOUND; + + File imageFile = getFile(TestActivity.ASSETS__IMAGE_FILE_NAME); + + RemoteOperationResult result = mActivity.uploadFile(imageFile.getAbsolutePath(), mFullPath2Image, + "image/png", null); + + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + + result = mActivity.uploadFile(imageFile.getAbsolutePath(), mFullPath2ImageWitSpecialChars, "image/png", null); + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + + result = mActivity.removeFile(mFullPath2ImageNotFound); + if (!result.isSuccess() && result.getCode() != ResultCode.FILE_NOT_FOUND) { + Utils.logAndThrow(LOG_TAG, result); + } + } + + /** + * Test Download a File + */ + public void testDownloadFile() throws FileNotFoundException { + RemoteOperationResult result = mActivity.downloadFile(new RemoteFile(mFullPath2Image), ""); + mDownloadedFilePath = mFullPath2Image; + assertTrue(result.isSuccess()); + // TODO some checks involving the local file + } + + /** + * Test Download a File with special chars + */ + public void testDownloadFileSpecialChars() throws FileNotFoundException { + RemoteOperationResult result = mActivity.downloadFile(new RemoteFile(mFullPath2ImageWitSpecialChars), ""); + mDownloadedFilePath = mFullPath2ImageWitSpecialChars; + assertTrue(result.isSuccess()); + // TODO some checks involving the local file + } + + /** + * Test Download a Not Found File + */ + public void testDownloadFileNotFound() throws FileNotFoundException { + RemoteOperationResult result = mActivity.downloadFile(new RemoteFile(mFullPath2ImageNotFound), ""); + assertFalse(result.isSuccess()); + } + + @Override + protected void tearDown() throws Exception { + if (mDownloadedFilePath != null) { + RemoteOperationResult removeResult = mActivity.removeFile(mDownloadedFilePath); + if (!removeResult.isSuccess()) { + Utils.logAndThrow(LOG_TAG, removeResult); + } + } + + File[] files = mActivity.getFilesDir().listFiles(); + for (File file : files) { + if (file.isDirectory()) { + FileUtils.deleteDirectory(file); + } else if (!file.delete()) { + throw new FileNotFoundException(file.getAbsolutePath()); + } + } + super.tearDown(); + } +} diff --git a/test_client/src/androidTest/java/com/owncloud/android/util/ExceptionParserIT.java b/test_client/src/androidTest/java/com/owncloud/android/lib/ExceptionParserIT.java similarity index 99% rename from test_client/src/androidTest/java/com/owncloud/android/util/ExceptionParserIT.java rename to test_client/src/androidTest/java/com/owncloud/android/lib/ExceptionParserIT.java index 470d9c37c6..f6e28cbfef 100644 --- a/test_client/src/androidTest/java/com/owncloud/android/util/ExceptionParserIT.java +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/ExceptionParserIT.java @@ -1,4 +1,5 @@ -package com.owncloud.android.util; +package com.owncloud.android.lib; + import android.support.test.runner.AndroidJUnit4; diff --git a/test_client/src/androidTest/java/com/owncloud/android/lib/GetCapabilitiesTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/GetCapabilitiesTest.java new file mode 100644 index 0000000000..a54a400d05 --- /dev/null +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/GetCapabilitiesTest.java @@ -0,0 +1,53 @@ +/* ownCloud Android Library is available under MIT license + * @author masensio + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +package com.owncloud.android.lib; + +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.resources.status.GetRemoteCapabilitiesOperation; +import com.owncloud.android.lib.resources.status.OCCapability; + +/** + * Class to test GetRemoteCapabilitiesOperation + */ +public class GetCapabilitiesTest extends RemoteTest { + // Tests + + /** + * Test get capabilities + *

+ * Requires OC server 8.1 or later + */ + public void testGetRemoteCapabilitiesOperation() { + // get capabilities + RemoteOperationResult result = new GetRemoteCapabilitiesOperation().execute(mClient); + assertTrue(result.isSuccess()); + assertTrue(result.getData() != null && result.getData().size() == 1); + + OCCapability capability = (OCCapability) result.getData().get(0); + + // TODO assert basic capabilities + } +} diff --git a/test_client/src/androidTest/java/com/owncloud/android/lib/GetShareesTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/GetShareesTest.java new file mode 100644 index 0000000000..ca655a72c4 --- /dev/null +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/GetShareesTest.java @@ -0,0 +1,193 @@ +/* ownCloud Android Library is available under MIT license + * @author David A. Velasco + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +package com.owncloud.android.lib; + +import android.util.Log; + +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.resources.shares.GetRemoteShareesOperation; +import com.owncloud.android.lib.resources.shares.ShareType; +import com.owncloud.android.lib.testclient.R; + +import junit.framework.AssertionFailedError; + +import org.apache.commons.httpclient.HttpStatus; +import org.json.JSONException; +import org.json.JSONObject; + +/** + * Class to test GetRemoteShareesOperation + *

+ * With this TestCase we are experimenting a bit to improve the test suite design, in two aspects: + *

+ * - Reduce the dependency from the set of test cases on the "test project" needed to + * have an instrumented APK to install in the device, as required by the testing framework + * provided by Android. To get there, this class avoids calling TestActivity methods in the test + * method. + *

+ * - Reduce the impact of creating a remote fixture over the Internet, while the structure of the + * TestCase is kept easy to maintain. To get this, all the tests are done in a single test method, + * granting this way that setUp and tearDown are run only once. + */ + +public class GetShareesTest extends RemoteTest { + + private static final String LOG_TAG = GetShareesTest.class.getCanonicalName(); + + /** + * Test get sharees + *

+ * Requires OC server 8.2 or later + */ + public void testGetRemoteShareesOperation() { + Log.v(LOG_TAG, "testGetRemoteSharees in"); + + /// successful cases + + // search for sharees including "a" + RemoteOperationResult result = new GetRemoteShareesOperation("a", 1, 50).execute(mClient); + JSONObject resultItem; + JSONObject value; + int type; + int userCount = 0; + int groupCount = 0; + assertTrue(result.isSuccess() && result.getData().size() > 0); + try { + for (int i = 0; i < result.getData().size(); i++) { + resultItem = (JSONObject) result.getData().get(i); + value = resultItem.getJSONObject(GetRemoteShareesOperation.NODE_VALUE); + type = value.getInt(GetRemoteShareesOperation.PROPERTY_SHARE_TYPE); + if (type == ShareType.GROUP.getValue()) { + groupCount++; + } else { + userCount++; + } + } + assertTrue(userCount > 0); + assertTrue(groupCount > 0); + } catch (JSONException e) { + AssertionFailedError afe = new AssertionFailedError(e.getLocalizedMessage()); + afe.setStackTrace(e.getStackTrace()); + throw afe; + } + + // search for sharees including "ad" - expecting user "admin" & group "admin" + result = new GetRemoteShareesOperation("ad", 1, 50).execute(mClient); + assertTrue(result.isSuccess() && result.getData().size() == 2); + userCount = 0; + groupCount = 0; + try { + for (int i = 0; i < 2; i++) { + resultItem = (JSONObject) result.getData().get(i); + value = resultItem.getJSONObject(GetRemoteShareesOperation.NODE_VALUE); + type = value.getInt(GetRemoteShareesOperation.PROPERTY_SHARE_TYPE); + if (type == ShareType.GROUP.getValue()) { + groupCount++; + } else { + userCount++; + } + } + assertEquals(userCount, 1); + assertEquals(groupCount, 1); + } catch (JSONException e) { + AssertionFailedError afe = new AssertionFailedError(e.getLocalizedMessage()); + afe.setStackTrace(e.getStackTrace()); + throw afe; + } + + + // search for sharees including "bd" - expecting 0 results + result = new GetRemoteShareesOperation("bd", 1, 50).execute(mClient); + assertTrue(result.isSuccess() && result.getData().size() == 0); + + + /// failed cases + + // search for sharees including wrong page values + result = new GetRemoteShareesOperation("a", 0, 50).execute(mClient); + assertTrue(!result.isSuccess() && result.getHttpCode() == HttpStatus.SC_BAD_REQUEST); + + result = new GetRemoteShareesOperation("a", 1, 0).execute(mClient); + assertTrue(!result.isSuccess() && result.getHttpCode() == HttpStatus.SC_BAD_REQUEST); + } + + /** + * Test get federated sharees + *

+ * Requires OC server 8.2 or later + */ + public void testGetFederatedShareesOperation() { + Log.v(LOG_TAG, "testGetFederatedSharees in"); + + /// successful cases + + // search for sharees including "@" + RemoteOperationResult result = new GetRemoteShareesOperation("@", 1, 50).execute(mClient); + JSONObject resultItem; + JSONObject value; + int type; + int fedCount = 0; + assertTrue(result.isSuccess() && result.getData().size() > 0); + try { + for (int i = 0; i < result.getData().size(); i++) { + resultItem = (JSONObject) result.getData().get(i); + value = resultItem.getJSONObject(GetRemoteShareesOperation.NODE_VALUE); + type = value.getInt(GetRemoteShareesOperation.PROPERTY_SHARE_TYPE); + if (type == ShareType.FEDERATED.getValue()) { + fedCount++; + } + } + assertTrue(fedCount > 0); + } catch (JSONException e) { + AssertionFailedError afe = new AssertionFailedError(e.getLocalizedMessage()); + afe.setStackTrace(e.getStackTrace()); + throw afe; + } + + // search for 'admin' sharee from external server - expecting at least 1 result + mServerUri2 = getActivity().getString(R.string.server_base_url_2); + String remoteSharee = "admin@" + mServerUri2.split("//")[1]; + result = new GetRemoteShareesOperation(remoteSharee, 1, 50).execute(mClient); + assertTrue(result.isSuccess() && result.getData().size() > 0); + + + /// failed cases + + // search for sharees including wrong page values + result = new GetRemoteShareesOperation("@", 0, 50).execute(mClient); + assertTrue(!result.isSuccess() && result.getHttpCode() == HttpStatus.SC_BAD_REQUEST); + + result = new GetRemoteShareesOperation("@", 1, 0).execute(mClient); + assertTrue(!result.isSuccess() && result.getHttpCode() == HttpStatus.SC_BAD_REQUEST); + } + + @Override + protected void tearDown() throws Exception { + Log.v(LOG_TAG, "Deleting remote fixture..."); + super.tearDown(); + Log.v(LOG_TAG, "Remote fixture delete."); + } +} diff --git a/test_client/src/androidTest/java/com/owncloud/android/lib/GetSharesTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/GetSharesTest.java new file mode 100644 index 0000000000..a121e8ffd1 --- /dev/null +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/GetSharesTest.java @@ -0,0 +1,87 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +package com.owncloud.android.lib; + +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.resources.shares.ShareType; +import com.owncloud.android.lib.testclient.TestActivity; + +import java.io.File; + +/** + * Class to test Get Shares Operation + * + * @author masensio + */ + +public class GetSharesTest extends RemoteTest { + + private static final String LOG_TAG = GetSharesTest.class.getCanonicalName(); + + private static final String SHARED_FILE = "/sharedFileToGet.txt"; + + private String mFullPath2SharedFile; + + @Override + protected void setUp() throws Exception { + super.setUp(); + setActivityInitialTouchMode(false); + mFullPath2SharedFile = mBaseFolderPath + SHARED_FILE; + + File textFile = getFile(TestActivity.ASSETS__TEXT_FILE_NAME); + RemoteOperationResult result = mActivity.uploadFile(textFile.getAbsolutePath(), mFullPath2SharedFile, + "txt/plain", null); + + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + + result = mActivity.createShare(mFullPath2SharedFile, ShareType.PUBLIC_LINK, "", false, "", 1); + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + + } + + /** + * Test Get Shares: the server must support SHARE API + */ + public void testGetShares() { + RemoteOperationResult result = mActivity.getShares(); + assertTrue(result.isSuccess()); + assertTrue(result.getData() != null && result.getData().size() == 1); + } + + @Override + protected void tearDown() throws Exception { + RemoteOperationResult removeResult = mActivity.removeFile(mFullPath2SharedFile); + if (!removeResult.isSuccess()) { + Utils.logAndThrow(LOG_TAG, removeResult); + } + super.tearDown(); + } + + +} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/GetUserQuotaTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/GetUserQuotaTest.java similarity index 68% rename from test_client/tests/src/com/owncloud/android/lib/test_project/test/GetUserQuotaTest.java rename to test_client/src/androidTest/java/com/owncloud/android/lib/GetUserQuotaTest.java index daa2a3cff9..b36bad4791 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/GetUserQuotaTest.java +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/GetUserQuotaTest.java @@ -25,15 +25,12 @@ * */ -package com.owncloud.android.lib.test_project.test; - -import java.io.File; -import java.util.*; +package com.owncloud.android.lib; +import com.owncloud.android.lib.common.Quota; +import com.owncloud.android.lib.common.UserInfo; import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; -import com.owncloud.android.lib.test_project.TestActivity; -import com.owncloud.android.lib.resources.files.*; +import com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation; /** @@ -43,29 +40,22 @@ */ public class GetUserQuotaTest extends RemoteTest { - private static final String LOG_TAG = GetUserQuotaTest.class.getCanonicalName(); - - /* Files to download. These files must exist on the account */ - private static final String IMAGE_PATH = "/fileToDownload.png"; - private static final String IMAGE_PATH_WITH_SPECIAL_CHARS = "/@file@download.png"; - private static final String IMAGE_NOT_FOUND = "/fileNotFound.png"; - - private TestActivity mActivity; - @Override protected void setUp() throws Exception { super.setUp(); setActivityInitialTouchMode(false); - mActivity = getActivity(); } /** * Test GetUserQuota */ public void testGetUserQuota() { - RemoteOperationResult result = mActivity.getQuota(); + RemoteOperationResult result = new GetRemoteUserInfoOperation().execute(mClient); assertTrue(result.isSuccess()); - Quota quota = (Quota)((ArrayList)result.getData()).get(0); + assertTrue(result.getData() != null && result.getData().size() == 1); + + UserInfo userInfo = (UserInfo) result.getData().get(0); + Quota quota = userInfo.getQuota(); assertTrue(quota.getFree() >= 0); assertTrue(quota.getUsed() >= 0); assertTrue(quota.getTotal() > 0); diff --git a/test_client/src/androidTest/java/com/owncloud/android/lib/MoveFileTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/MoveFileTest.java new file mode 100644 index 0000000000..4679711936 --- /dev/null +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/MoveFileTest.java @@ -0,0 +1,371 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +package com.owncloud.android.lib; + +import android.util.Log; + +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; +import com.owncloud.android.lib.resources.files.MoveRemoteFileOperation; +import com.owncloud.android.lib.resources.status.OwnCloudVersion; +import com.owncloud.android.lib.testclient.TestActivity; + +import org.apache.commons.httpclient.HttpStatus; + +import java.io.File; + +/** + * Class to test MoveRemoteFileOperation + *

+ * With this TestCase we are experimenting a bit to improve the test suite design, in two aspects: + *

+ * - Reduce the dependency from the set of test cases on the "test project" needed to + * have an instrumented APK to install in the device, as required by the testing framework + * provided by Android. To get there, this class avoids calling TestActivity methods in the test + * method. + *

+ * - Reduce the impact of creating a remote fixture over the Internet, while the structure of the + * TestCase is kept easy to maintain. To get this, all the tests are done in a single test method, + * granting this way that setUp and tearDown are run only once. + * + * @author David A. Velasco + */ + +//public class MoveFileTest extends AndroidTestCase { +public class MoveFileTest extends RemoteTest { + + private static final String LOG_TAG = MoveFileTest.class.getCanonicalName(); + + /// Paths to files and folders in fixture + + private static final String SRC_BASE_FOLDER = "/src/"; + private static final String TARGET_BASE_FOLDER = "/target/"; + private static final String NO_FILE = "nofile.txt"; + private static final String FILE1 = "file1.txt"; + private static final String FILE2 = "file2.txt"; + private static final String FILE3 = "file3.txt"; + private static final String FILE4 = "file4.txt"; + private static final String FILE5 = "file5.txt"; + private static final String FILE6 = "file6.txt"; + private static final String FILE7 = "file7.txt"; + private static final String EMPTY = "empty/"; + private static final String NO_FOLDER = "nofolder/"; + private static final String FOLDER1 = "folder1/"; + private static final String FOLDER2 = "folder2/"; + private static final String FOLDER3 = "folder3/"; + private static final String FOLDER4 = "folder4/"; + + private static final String SRC_PATH_TO_FILE_1 = SRC_BASE_FOLDER + FILE1; + private static final String TARGET_PATH_TO_FILE_1 = TARGET_BASE_FOLDER + FILE1; + + private static final String SRC_PATH_TO_FILE_2 = SRC_BASE_FOLDER + FILE2; + private static final String TARGET_PATH_TO_FILE_2_RENAMED = TARGET_BASE_FOLDER + "renamed_" + FILE2; + + private static final String SRC_PATH_TO_FILE_3 = SRC_BASE_FOLDER + FILE3; + private static final String SRC_PATH_TO_FILE_3_RENAMED = SRC_BASE_FOLDER + "renamed_" + FILE3; + + private static final String SRC_PATH_TO_FILE_4 = SRC_BASE_FOLDER + FILE4; + + private static final String SRC_PATH_TO_FILE_5 = SRC_BASE_FOLDER + FILE5; + + private static final String SRC_PATH_TO_FILE_6 = SRC_BASE_FOLDER + FILE6; + + private static final String SRC_PATH_TO_FILE_7 = SRC_BASE_FOLDER + FILE7; + + private static final String SRC_PATH_TO_NON_EXISTENT_FILE = SRC_BASE_FOLDER + NO_FILE; + + private static final String SRC_PATH_TO_EMPTY_FOLDER = SRC_BASE_FOLDER + EMPTY; + private static final String TARGET_PATH_TO_EMPTY_FOLDER = TARGET_BASE_FOLDER + EMPTY; + + private static final String SRC_PATH_TO_FULL_FOLDER_1 = SRC_BASE_FOLDER + FOLDER1; + private static final String TARGET_PATH_TO_FULL_FOLDER_1 = TARGET_BASE_FOLDER + FOLDER1; + + private static final String SRC_PATH_TO_FULL_FOLDER_2 = SRC_BASE_FOLDER + FOLDER2; + + private static final String TARGET_PATH_TO_FULL_FOLDER_2_RENAMED = TARGET_BASE_FOLDER + "renamed_" + FOLDER2; + + private static final String SRC_PATH_TO_FULL_FOLDER_3 = SRC_BASE_FOLDER + FOLDER3; + private static final String SRC_PATH_TO_FULL_FOLDER_4 = SRC_BASE_FOLDER + FOLDER4; + + private static final String SRC_PATH_TO_FULL_FOLDER_3_RENAMED = SRC_BASE_FOLDER + "renamed_" + FOLDER3; + + private static final String TARGET_PATH_RENAMED_WITH_INVALID_CHARS = SRC_BASE_FOLDER + "renamed:??_" + FILE6; + + private static final String TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4 = TARGET_BASE_FOLDER + FOLDER4; + + private static final String TARGET_PATH_TO_NON_EXISTENT_FILE = TARGET_BASE_FOLDER + NO_FILE; + + private static final String TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER = TARGET_BASE_FOLDER + NO_FOLDER + FILE5; + + private static final String TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7 = TARGET_BASE_FOLDER + FILE7; + + private static final String[] FOLDERS_IN_FIXTURE = { + SRC_PATH_TO_EMPTY_FOLDER, + + SRC_PATH_TO_FULL_FOLDER_1, + SRC_PATH_TO_FULL_FOLDER_1 + FOLDER1, + SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2, + SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FOLDER1, + SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FOLDER2, + + SRC_PATH_TO_FULL_FOLDER_2, + SRC_PATH_TO_FULL_FOLDER_2 + FOLDER1, + SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2, + SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FOLDER1, + SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FOLDER2, + + SRC_PATH_TO_FULL_FOLDER_3, + SRC_PATH_TO_FULL_FOLDER_3 + FOLDER1, + SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2, + SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FOLDER1, + SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FOLDER2, + + SRC_PATH_TO_FULL_FOLDER_4, + SRC_PATH_TO_FULL_FOLDER_4 + FOLDER1, + SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2, + SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FOLDER1, + SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FOLDER2, + + TARGET_BASE_FOLDER, + TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4 + }; + + private static final String[] FILES_IN_FIXTURE = { + SRC_PATH_TO_FILE_1, + SRC_PATH_TO_FILE_2, + SRC_PATH_TO_FILE_3, + SRC_PATH_TO_FILE_4, + SRC_PATH_TO_FILE_5, + + SRC_PATH_TO_FULL_FOLDER_1 + FILE1, + SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FILE1, + SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FILE2, + SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FOLDER2 + FILE2, + + SRC_PATH_TO_FULL_FOLDER_2 + FILE1, + SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FILE1, + SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FILE2, + SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FOLDER2 + FILE2, + + SRC_PATH_TO_FULL_FOLDER_3 + FILE1, + SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FILE1, + SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FILE2, + SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FOLDER2 + FILE2, + + SRC_PATH_TO_FULL_FOLDER_4 + FILE1, + SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FILE1, + SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FILE2, + SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FOLDER2 + FILE2, + + TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7 + }; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + Log.v(LOG_TAG, "Setting up the remote fixture..."); + + RemoteOperationResult result; + for (String folderPath : FOLDERS_IN_FIXTURE) { + result = mActivity.createFolder(mBaseFolderPath + folderPath, true); + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + } + + File txtFile = getFile(TestActivity.ASSETS__TEXT_FILE_NAME); + for (String filePath : FILES_IN_FIXTURE) { + result = mActivity.uploadFile(txtFile.getAbsolutePath(), mBaseFolderPath + filePath, "txt/plain", null); + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + } + + Log.v(LOG_TAG, "Remote fixture created."); + } + + + /** + * Test move folder + */ + public void testMoveRemoteFileOperation() { + Log.v(LOG_TAG, "testMoveFolder in"); + + /// successful cases + + // move file + MoveRemoteFileOperation moveOperation = new MoveRemoteFileOperation( + mBaseFolderPath + SRC_PATH_TO_FILE_1, + mBaseFolderPath + TARGET_PATH_TO_FILE_1, + false + ); + RemoteOperationResult result = moveOperation.execute(mClient); + assertTrue("move file", result.isSuccess()); + + // move & rename file, different location + moveOperation = new MoveRemoteFileOperation( + mBaseFolderPath + SRC_PATH_TO_FILE_2, + mBaseFolderPath + TARGET_PATH_TO_FILE_2_RENAMED, + false + ); + result = moveOperation.execute(mClient); + assertTrue("move & rename file, different location", result.isSuccess()); + + // move & rename file, same location (rename file) + moveOperation = new MoveRemoteFileOperation( + mBaseFolderPath + SRC_PATH_TO_FILE_3, + mBaseFolderPath + SRC_PATH_TO_FILE_3_RENAMED, + false + ); + result = moveOperation.execute(mClient); + assertTrue("move & rename file, same location (rename file)", result.isSuccess()); + + // move empty folder + moveOperation = new MoveRemoteFileOperation( + mBaseFolderPath + SRC_PATH_TO_EMPTY_FOLDER, + mBaseFolderPath + TARGET_PATH_TO_EMPTY_FOLDER, + false + ); + result = moveOperation.execute(mClient); + assertTrue("move empty folder", result.isSuccess()); + + // move non-empty folder + moveOperation = new MoveRemoteFileOperation( + mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_1, + mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_1, + false + ); + result = moveOperation.execute(mClient); + assertTrue("move non-empty folder", result.isSuccess()); + + // move & rename folder, different location + moveOperation = new MoveRemoteFileOperation( + mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_2, + mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_2_RENAMED, + false + ); + result = moveOperation.execute(mClient); + assertTrue("move & rename folder, different location", result.isSuccess()); + + // move & rename folder, same location (rename folder) + moveOperation = new MoveRemoteFileOperation( + mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_3, + mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_3_RENAMED, + false + ); + result = moveOperation.execute(mClient); + assertTrue("move & rename folder, same location (rename folder)", result.isSuccess()); + + // move for nothing (success, but no interaction with network) + moveOperation = new MoveRemoteFileOperation( + mBaseFolderPath + SRC_PATH_TO_FILE_4, + mBaseFolderPath + SRC_PATH_TO_FILE_4, + false + ); + result = moveOperation.execute(mClient); + assertTrue("move for nothing (success, but no interaction with network)", result.isSuccess()); + + // move overwriting + moveOperation = new MoveRemoteFileOperation( + mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_4, + mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4, + true + ); + result = moveOperation.execute(mClient); + assertTrue("move overwriting", result.isSuccess()); + + + /// Failed cases + + // file to move does not exist + moveOperation = new MoveRemoteFileOperation( + mBaseFolderPath + SRC_PATH_TO_NON_EXISTENT_FILE, + mBaseFolderPath + TARGET_PATH_TO_NON_EXISTENT_FILE, + false + ); + result = moveOperation.execute(mClient); + assertTrue("file to move does not exist", result.getCode() == ResultCode.FILE_NOT_FOUND); + + // folder to move into does no exist + moveOperation = new MoveRemoteFileOperation( + mBaseFolderPath + SRC_PATH_TO_FILE_5, + mBaseFolderPath + TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER, + false + ); + result = moveOperation.execute(mClient); + assertTrue("folder to move into does no exist", result.getHttpCode() == HttpStatus.SC_CONFLICT); + + // target location (renaming) has invalid characters + mActivity.getClient().setOwnCloudVersion(null); + moveOperation = new MoveRemoteFileOperation( + mBaseFolderPath + SRC_PATH_TO_FILE_6, + mBaseFolderPath + TARGET_PATH_RENAMED_WITH_INVALID_CHARS, + false + ); + result = moveOperation.execute(mClient); + assertTrue("target location (renaming) has invalid characters", result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); + mActivity.getClient().setOwnCloudVersion(OwnCloudVersion.nextcloud_10); + + // name collision + moveOperation = new MoveRemoteFileOperation( + mBaseFolderPath + SRC_PATH_TO_FILE_7, + mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7, + false + ); + result = moveOperation.execute(mClient); + assertTrue("name collision", result.getCode() == ResultCode.INVALID_OVERWRITE); + + // move a folder into a descendant + moveOperation = new MoveRemoteFileOperation( + mBaseFolderPath + SRC_BASE_FOLDER, + mBaseFolderPath + SRC_PATH_TO_EMPTY_FOLDER, + false + ); + result = moveOperation.execute(mClient); + assertTrue("move a folder into a descendant", result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT); + } + + @Override + protected void tearDown() throws Exception { + Log.v(LOG_TAG, "Deleting remote fixture..."); + + String[] mPathsToCleanUp = { + mBaseFolderPath + SRC_BASE_FOLDER, + mBaseFolderPath + TARGET_BASE_FOLDER + }; + + for (String path : mPathsToCleanUp) { + RemoteOperationResult removeResult = mActivity.removeFile(path); + if (!removeResult.isSuccess()) { + Utils.logAndThrow(LOG_TAG, removeResult); + } + } + + super.tearDown(); + + Log.v(LOG_TAG, "Remote fixture delete."); + } +} diff --git a/test_client/src/androidTest/java/com/owncloud/android/lib/OwnCloudClientManagerFactoryTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/OwnCloudClientManagerFactoryTest.java new file mode 100644 index 0000000000..8bec02f4b9 --- /dev/null +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/OwnCloudClientManagerFactoryTest.java @@ -0,0 +1,131 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ +package com.owncloud.android.lib; + +import com.owncloud.android.lib.common.OwnCloudClientManager; +import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; +import com.owncloud.android.lib.common.OwnCloudClientManagerFactory.Policy; +import com.owncloud.android.lib.common.SimpleFactoryManager; +import com.owncloud.android.lib.common.SingleSessionManager; + +import junit.framework.AssertionFailedError; +import junit.framework.TestCase; + +/** + * Unit test for OwnCloudClientManagerFactory + * + * @author David A. Velasco + */ +public class OwnCloudClientManagerFactoryTest extends TestCase { + + @Override + protected void setUp() throws Exception { + super.setUp(); + OwnCloudClientManagerFactory.setDefaultPolicy(Policy.ALWAYS_NEW_CLIENT); + } + + public void testGetDefaultPolicy() { + Policy defaultPolicy = OwnCloudClientManagerFactory.getDefaultPolicy(); + assertNotNull("Returned null value", defaultPolicy); + assertTrue("Returned unknown value", (Policy.ALWAYS_NEW_CLIENT.equals(defaultPolicy) || + (Policy.SINGLE_SESSION_PER_ACCOUNT.equals(defaultPolicy)))); + } + + public void testSetDefaultPolicy() { + OwnCloudClientManagerFactory.setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT); + Policy defaultPolicy = OwnCloudClientManagerFactory.getDefaultPolicy(); + assertEquals("SINGLE_SESSION_PER_ACCOUNT not set", Policy.SINGLE_SESSION_PER_ACCOUNT, defaultPolicy); + + OwnCloudClientManagerFactory.setDefaultPolicy(Policy.ALWAYS_NEW_CLIENT); + defaultPolicy = OwnCloudClientManagerFactory.getDefaultPolicy(); + assertEquals("ALWAYS_NEW_CLIENT not set", Policy.ALWAYS_NEW_CLIENT, defaultPolicy); + + try { + OwnCloudClientManagerFactory.setDefaultPolicy(null); + throw new AssertionFailedError("Accepted NULL parameter"); + + } catch (IllegalArgumentException e) { + // Expected exception when setting default policy null + return; + } catch (Exception e) { + assertTrue("Unexpected exception when setting default policy null", false); + } + defaultPolicy = OwnCloudClientManagerFactory.getDefaultPolicy(); + assertEquals("ALWAYS_NEW_CLIENT changed after setting null", Policy.ALWAYS_NEW_CLIENT, defaultPolicy); + } + + + public void testGetDefaultSingleton() { + OwnCloudClientManager mgr = OwnCloudClientManagerFactory.getDefaultSingleton(); + assertNotNull("Returned NULL default singleton", mgr); + assertTrue("Default singleton does not implement default policy", mgr instanceof SimpleFactoryManager); + + OwnCloudClientManager mgr2 = OwnCloudClientManagerFactory.getDefaultSingleton(); + assertSame("Not singleton", mgr, mgr2); + + OwnCloudClientManagerFactory.setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT); + mgr = OwnCloudClientManagerFactory.getDefaultSingleton(); + assertNotNull("Returned NULL default singleton", mgr); + assertTrue("Default singleton does not implement default policy", mgr instanceof SingleSessionManager); + + mgr2 = OwnCloudClientManagerFactory.getDefaultSingleton(); + assertSame("Not singleton", mgr, mgr2); + } + + public void testNewDefaultOwnCloudClientManager() { + OwnCloudClientManager mgr = OwnCloudClientManagerFactory.newDefaultOwnCloudClientManager(); + assertNotNull("Returned NULL default manager", mgr); + assertTrue("New manager does not implement default policy", mgr instanceof SimpleFactoryManager); + assertNotSame("Not new instance", mgr, OwnCloudClientManagerFactory.getDefaultSingleton()); + assertNotSame("Not new instance", mgr, OwnCloudClientManagerFactory.newDefaultOwnCloudClientManager()); + + OwnCloudClientManagerFactory.setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT); + mgr = OwnCloudClientManagerFactory.newDefaultOwnCloudClientManager(); + assertNotNull("Returned NULL default manager", mgr); + assertTrue("New manager does not implement default policy", mgr instanceof SingleSessionManager); + assertNotSame("Not new instance", mgr, OwnCloudClientManagerFactory.getDefaultSingleton()); + assertNotSame("Not new instance", mgr, OwnCloudClientManagerFactory.newDefaultOwnCloudClientManager()); + } + + public void testNewOwnCloudClientManager() { + OwnCloudClientManager mgr = OwnCloudClientManagerFactory.newOwnCloudClientManager(Policy.ALWAYS_NEW_CLIENT); + + assertNotNull("Returned NULL manager", mgr); + assertTrue("New manager does not implement policy ALWAYS_NEW_CLIENT", mgr instanceof SimpleFactoryManager); + assertNotSame("Not new instance", mgr, OwnCloudClientManagerFactory.getDefaultSingleton()); + assertNotSame("Not new instance", mgr, OwnCloudClientManagerFactory.newDefaultOwnCloudClientManager()); + assertNotSame("Not new instance", mgr, OwnCloudClientManagerFactory.newOwnCloudClientManager( + Policy.ALWAYS_NEW_CLIENT)); + + OwnCloudClientManager mgr2 = OwnCloudClientManagerFactory.newOwnCloudClientManager(Policy.SINGLE_SESSION_PER_ACCOUNT); + + assertNotNull("Returned NULL manager", mgr2); + assertTrue("New manager does not implement policy SINGLE_SESSION_PER_ACCOUNT", + mgr2 instanceof SingleSessionManager); + assertNotSame("Not new instance", mgr2, OwnCloudClientManagerFactory.getDefaultSingleton()); + assertNotSame("Not new instance", mgr2, OwnCloudClientManagerFactory.newDefaultOwnCloudClientManager()); + assertNotSame("Not new instance", mgr2, OwnCloudClientManagerFactory.newOwnCloudClientManager( + Policy.SINGLE_SESSION_PER_ACCOUNT)); + } +} diff --git a/test_client/src/androidTest/java/com/owncloud/android/lib/OwnCloudClientTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/OwnCloudClientTest.java new file mode 100644 index 0000000000..9e7b9256d9 --- /dev/null +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/OwnCloudClientTest.java @@ -0,0 +1,313 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ +package com.owncloud.android.lib; + +import android.net.Uri; +import android.test.AndroidTestCase; +import android.util.Log; + +import com.owncloud.android.lib.common.OwnCloudClient; +import com.owncloud.android.lib.common.OwnCloudCredentials; +import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; +import com.owncloud.android.lib.common.accounts.AccountUtils; +import com.owncloud.android.lib.common.network.NetworkUtils; +import com.owncloud.android.lib.testclient.R; + +import junit.framework.AssertionFailedError; + +import org.apache.commons.httpclient.ConnectTimeoutException; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.httpclient.methods.HeadMethod; +import org.apache.jackrabbit.webdav.DavConstants; +import org.apache.jackrabbit.webdav.client.methods.PropFindMethod; + +import java.io.IOException; +import java.io.InputStream; +import java.net.SocketTimeoutException; + + +/** + * Unit test for OwnCloudClient + * + * @author David A. Velasco + */ +public class OwnCloudClientTest extends AndroidTestCase { + + private static final String TAG = OwnCloudClientTest.class.getSimpleName(); + + private Uri mServerUri; + private String mUsername; + private String mPassword; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mServerUri = Uri.parse(getContext().getString(R.string.server_base_url)); + mUsername = getContext().getString(R.string.username); + mPassword = getContext().getString(R.string.password); + } + + + public void testConstructor() { + try { + new OwnCloudClient(null, NetworkUtils.getMultiThreadedConnManager(), false); + throw new AssertionFailedError("Accepted NULL parameter"); + } catch (IllegalArgumentException e) { + assertTrue("Expected exception passing NULL baseUri", true); + } catch (Exception e) { + assertTrue("Unexpected exception", false); + } + + try { + new OwnCloudClient(mServerUri, null, false); + throw new AssertionFailedError("Accepted NULL parameter"); + + } catch (IllegalArgumentException e) { + assertTrue("Expected exception passing NULL connectionMgr", true); + } catch (Exception e) { + assertTrue("Unexpected exception passing NULL connectionMgr", false); + } + + OwnCloudClient client = new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(), false); + assertNotNull("OwnCloudClient instance not built", client); + } + + + public void testGetSetCredentials() { + OwnCloudClient client = new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(), false); + + assertNotNull("Returned NULL credentials", client.getCredentials()); + assertEquals("Not instanced without credentials", client.getCredentials(), + OwnCloudCredentialsFactory.getAnonymousCredentials()); + + OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials("user", "pass"); + client.setCredentials(credentials); + assertEquals("Basic credentials not set", credentials, client.getCredentials()); + + credentials = OwnCloudCredentialsFactory.newBearerCredentials("bearerToken"); + client.setCredentials(credentials); + assertEquals("Bearer credentials not set", credentials, client.getCredentials()); + + credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials("user", "samlSessionCookie=124"); + client.setCredentials(credentials); + assertEquals("SAML2 session credentials not set", credentials, client.getCredentials()); + } + + public void testExecuteMethodWithTimeouts() { + OwnCloudClient client = new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(), false); + int connectionTimeout = client.getConnectionTimeout(); + int readTimeout = client.getDataTimeout(); + + HeadMethod head = new HeadMethod(client.getWebdavUri() + "/"); + try { + client.executeMethod(head, 1, 1000); + throw new AssertionFailedError("Completed HEAD with impossible read timeout"); + } catch (ConnectTimeoutException | SocketTimeoutException e) { + Log.e("OwnCloudClientTest", "EXCEPTION", e); + assertTrue("Expected exception " + e.getLocalizedMessage(), true); + + } catch (IOException e) { + assertFalse("Unexpected exception", false); + } finally { + head.releaseConnection(); + } + + assertEquals("Connection timeout was changed for future requests", connectionTimeout, + client.getConnectionTimeout()); + assertEquals("Read timeout was changed for future requests", readTimeout, client.getDataTimeout()); + + try { + client.executeMethod(head, 1000, 1); + throw new AssertionFailedError("Completed HEAD with impossible connection timeout"); + + } catch (ConnectTimeoutException | SocketTimeoutException e) { + Log.e("OwnCloudClientTest", "EXCEPTION", e); + assertTrue("Expected exception " + e.getLocalizedMessage(), true); + } catch (Exception e) { + Log.e("OwnCloudClientTest", "EXCEPTION", e); + assertTrue("Unexpected exception " + e.getLocalizedMessage(), false); + } finally { + head.releaseConnection(); + } + + assertEquals("Connection timeout was changed for future requests", connectionTimeout, + client.getConnectionTimeout()); + assertEquals("Read timeout was changed for future requests", readTimeout, client.getDataTimeout()); + } + + + public void testExecuteMethod() { + OwnCloudClient client = new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(), false); + HeadMethod head = new HeadMethod(client.getWebdavUri() + "/"); + int status; + try { + status = client.executeMethod(head); + assertTrue("Wrong status code returned: " + status, status > 99 && status < 600); + + } catch (IOException e) { + Log.e(TAG, "Exception in HEAD method execution", e); + // TODO - make it fail? ; try several times, and make it fail if none + // is right? + + } finally { + head.releaseConnection(); + } + } + + public void testExhaustResponse() { + OwnCloudClient client = new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(), false); + + PropFindMethod propfind = null; + try { + propfind = new PropFindMethod(client.getWebdavUri() + "/", DavConstants.PROPFIND_ALL_PROP, + DavConstants.DEPTH_0); + client.executeMethod(propfind); + InputStream responseBody = propfind.getResponseBodyAsStream(); + if (responseBody != null) { + client.exhaustResponse(responseBody); + + try { + int character = responseBody.read(); + assertEquals("Response body was not fully exhausted", character, -1); // -1 is acceptable + } catch (IOException e) { + // this is the preferred result + } + } else { + Log.e(TAG, "Could not test exhaustResponse due to wrong response"); + // TODO - make it fail? ; try several times, and make it fail if none + // is right? + } + } catch (IOException e) { + Log.e(TAG, "Exception in PROPFIND method execution", e); + // TODO - make it fail? ; try several times, and make it fail if none + // is right? + } finally { + if (propfind != null) { + propfind.releaseConnection(); + } + } + + client.exhaustResponse(null); // must run with no exception + } + + public void testGetSetDefaultTimeouts() { + OwnCloudClient client = new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(), false); + + int oldDataTimeout = client.getDataTimeout(); + int oldConnectionTimeout = client.getConnectionTimeout(); + + client.setDefaultTimeouts(oldDataTimeout + 1000, oldConnectionTimeout + 1000); + assertEquals("Data timeout not set", oldDataTimeout + 1000, client.getDataTimeout()); + assertEquals("Connection timeout not set", oldConnectionTimeout + 1000, client.getConnectionTimeout()); + + client.setDefaultTimeouts(0, 0); + assertEquals("Zero data timeout not set", 0, client.getDataTimeout()); + assertEquals("Zero connection timeout not set", 0, client.getConnectionTimeout()); + + client.setDefaultTimeouts(-1, -1); + assertEquals("Negative data timeout not ignored", 0, client.getDataTimeout()); + assertEquals("Negative connection timeout not ignored", 0, client.getConnectionTimeout()); + + client.setDefaultTimeouts(-1, 1000); + assertEquals("Negative data timeout not ignored", 0, client.getDataTimeout()); + assertEquals("Connection timeout not set", 1000, client.getConnectionTimeout()); + + client.setDefaultTimeouts(1000, -1); + assertEquals("Data timeout not set", 1000, client.getDataTimeout()); + assertEquals("Negative connection timeout not ignored", 1000, client.getConnectionTimeout()); + } + + public void testGetWebdavUri() { + OwnCloudClient client = new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(), false); + client.setCredentials(OwnCloudCredentialsFactory.newBearerCredentials("fakeToken")); + Uri webdavUri = client.getWebdavUri(); + assertTrue("WebDAV URI does not point to the right entry point for OAuth2 authenticated servers", + webdavUri.getPath().endsWith(AccountUtils.ODAV_PATH)); + assertTrue("WebDAV URI is not a sub path of base URI", webdavUri.getAuthority().equals(mServerUri.getAuthority()) + && webdavUri.getPath().startsWith(mServerUri.getPath())); + + client.setCredentials(OwnCloudCredentialsFactory.newBasicCredentials(mUsername, mPassword)); + webdavUri = client.getWebdavUri(); + assertTrue("WebDAV URI does not point to the right entry point", + webdavUri.getPath().endsWith(AccountUtils.WEBDAV_PATH_4_0)); + PropFindMethod propfind = null; + + try { + propfind = new PropFindMethod(webdavUri + "/", DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_0); + int status = client.executeMethod(propfind); + assertEquals("WebDAV request did not work on WebDAV URI", HttpStatus.SC_MULTI_STATUS, status); + + } catch (IOException e) { + Log.e(TAG, "Exception in PROPFIND method execution", e); + // TODO - make it fail? ; try several times, and make it fail if none + // is right? + + } finally { + if (propfind != null) { + propfind.releaseConnection(); + } + } + } + + public void testGetSetBaseUri() { + OwnCloudClient client = new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager(), false); + assertEquals("Returned base URI different that URI passed to constructor", mServerUri, client.getBaseUri()); + + Uri otherUri = Uri.parse("https://whatever.com/basePath/here"); + client.setBaseUri(otherUri); + assertEquals("Returned base URI different that URI passed to constructor", otherUri, client.getBaseUri()); + + try { + client.setBaseUri(null); + throw new AssertionFailedError("Accepted NULL parameter"); + } catch (IllegalArgumentException e) { + assertTrue("Unexpected exception passing NULL base URI", true); + } catch (Exception e) { + assertTrue("Unexpected exception passing NULL base URI", false); + } + } + +// public void testGetCookiesString() { + // TODO implement test body + /*public String getCookiesString(){ + Cookie[] cookies = getState().getCookies(); + String cookiesString =""; + for (Cookie cookie: cookies) { + cookiesString = cookiesString + cookie.toString() + ";"; + + logCookie(cookie); + } + + return cookiesString; + + } + */ +// } + + +// public void testSetFollowRedirects() { +// // TODO - to implement this test we need a redirected server +// } + +} diff --git a/test_client/src/androidTest/java/com/owncloud/android/lib/ReadFileTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/ReadFileTest.java new file mode 100644 index 0000000000..6dfb051f83 --- /dev/null +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/ReadFileTest.java @@ -0,0 +1,80 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ +package com.owncloud.android.lib; + +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.testclient.TestActivity; + +import java.io.File; + +/** + * Class to test Read File Operation + * + * @author masensio + * @author David A. Velasco + */ + +public class ReadFileTest extends RemoteTest { + + private static final String LOG_TAG = ReadFileTest.class.getCanonicalName(); + + private String FILE_PATH = "/fileToRead.txt"; + private String mFullPath2File; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + setActivityInitialTouchMode(false); + mFullPath2File = mBaseFolderPath + FILE_PATH; + + File textFile = getFile(TestActivity.ASSETS__TEXT_FILE_NAME); + RemoteOperationResult uploadResult = mActivity.uploadFile(textFile.getAbsolutePath(), mFullPath2File, + "txt/plain", null); + + if (!uploadResult.isSuccess()) { + Utils.logAndThrow(LOG_TAG, uploadResult); + } + } + + /** + * Test Read File + */ + public void testReadFile() { + RemoteOperationResult result = mActivity.readFile(mFullPath2File); + assertTrue(result.getData() != null && result.getData().size() == 1); + assertTrue(result.isSuccess()); + // TODO check more properties of the result + } + + @Override + protected void tearDown() throws Exception { + RemoteOperationResult removeResult = mActivity.removeFile(mFullPath2File); + if (!removeResult.isSuccess()) { + Utils.logAndThrow(LOG_TAG, removeResult); + } + + super.tearDown(); + } +} diff --git a/test_client/src/androidTest/java/com/owncloud/android/lib/ReadFolderTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/ReadFolderTest.java new file mode 100644 index 0000000000..a2c792efd2 --- /dev/null +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/ReadFolderTest.java @@ -0,0 +1,95 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +package com.owncloud.android.lib; + +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.testclient.TestActivity; + +import java.io.File; + +/** + * Class to test Read Folder Operation + * + * @author masensio + * @author David A. Velasco + */ + +public class ReadFolderTest extends RemoteTest { + + private static final String LOG_TAG = ReadFolderTest.class.getCanonicalName(); + + private static final String FOLDER_PATH = "/folderToRead"; + private static final String[] FILE_PATHS = { + FOLDER_PATH + "/file1.txt", + FOLDER_PATH + "/file2.txt", + FOLDER_PATH + "/file3.txt", + }; + + + private String mFullPathToFolder; + + @Override + protected void setUp() throws Exception { + super.setUp(); + setActivityInitialTouchMode(false); + mFullPathToFolder = mBaseFolderPath + FOLDER_PATH; + + File textFile = getFile(TestActivity.ASSETS__TEXT_FILE_NAME); + RemoteOperationResult result = mActivity.createFolder(mFullPathToFolder, true); + if (result.isSuccess()) { + for (int i = 0; i < FILE_PATHS.length && result.isSuccess(); i++) { + result = mActivity.uploadFile(textFile.getAbsolutePath(), mBaseFolderPath + FILE_PATHS[i], "txt/plain", + null); + } + } + + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + } + + /** + * Test Read Folder + */ + public void testReadFolder() { + RemoteOperationResult result = mActivity.readFile(mFullPathToFolder); + assertTrue(result.isSuccess()); + assertTrue(result.getData() != null && result.getData().size() > 1); + assertTrue(result.getData().size() == 4); + // TODO assert more properties about the result + } + + + @Override + protected void tearDown() throws Exception { + RemoteOperationResult removeResult = mActivity.removeFile(mFullPathToFolder); + if (!removeResult.isSuccess()) { + Utils.logAndThrow(LOG_TAG, removeResult); + } + + super.tearDown(); + } + +} diff --git a/test_client/src/androidTest/java/com/owncloud/android/lib/RemoteTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/RemoteTest.java new file mode 100644 index 0000000000..05469958bc --- /dev/null +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/RemoteTest.java @@ -0,0 +1,132 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ +package com.owncloud.android.lib; + +import android.net.Uri; +import android.test.ActivityInstrumentationTestCase2; + +import com.owncloud.android.lib.common.OwnCloudClient; +import com.owncloud.android.lib.common.OwnCloudClientFactory; +import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; +import com.owncloud.android.lib.common.network.NetworkUtils; +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.lib.testclient.R; +import com.owncloud.android.lib.testclient.SelfSignedConfidentSslSocketFactory; +import com.owncloud.android.lib.testclient.TestActivity; + +import junit.framework.AssertionFailedError; + +import org.apache.commons.httpclient.protocol.Protocol; +import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; +import org.apache.commons.io.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.security.GeneralSecurityException; + +/** + * Class to create test folder for further testing + * + * @author David A. Velasco + */ +public class RemoteTest extends ActivityInstrumentationTestCase2 { + + private static final String LOG_TAG = RemoteTest.class.getSimpleName(); + + protected String mBaseFolderPath = "/test_for_build_"; + protected TestActivity mActivity; + protected OwnCloudClient mClient; + protected String mServerUri2; + private String mServerUri; + private String mUser; + private String mPass; + + public RemoteTest() { + super(TestActivity.class); + + Protocol pr = Protocol.getProtocol("https"); + if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) { + try { + ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory(); + Protocol.registerProtocol("https", new Protocol("https", psf, 443)); + } catch (GeneralSecurityException e) { + throw new AssertionFailedError("Self-signed confident SSL context could not be loaded"); + } + } + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + setActivityInitialTouchMode(false); + mBaseFolderPath += Long.toString(System.currentTimeMillis()); + + RemoteOperationResult result = getActivity().createFolder(mBaseFolderPath, true); + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + + mActivity = getActivity(); + + mServerUri = getActivity().getString(R.string.server_base_url); + mServerUri2 = getActivity().getString(R.string.server_base_url_2); + mUser = getActivity().getString(R.string.username); + mPass = getActivity().getString(R.string.password); + + initAccessToServer(); + } + + private void initAccessToServer() { + Log_OC.v(LOG_TAG, "Setting up client instance to access OC server..."); + + mClient = new OwnCloudClient(Uri.parse(mServerUri), NetworkUtils.getMultiThreadedConnManager(), false); + mClient.setDefaultTimeouts(OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT, + OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT); + mClient.setFollowRedirects(true); + mClient.setCredentials(OwnCloudCredentialsFactory.newBasicCredentials(mUser, mPass)); + + Log_OC.v(LOG_TAG, "Client instance set up."); + } + + + @Override + protected void tearDown() throws Exception { + RemoteOperationResult removeResult = getActivity().removeFile(mBaseFolderPath); + if (!removeResult.isSuccess()) { + Utils.logAndThrow(LOG_TAG, removeResult); + } + super.tearDown(); + } + + public File getFile(String filename) throws IOException { + InputStream inputStream = getInstrumentation().getContext().getAssets().open(filename); + File temp = File.createTempFile("file", "file"); + FileUtils.copyInputStreamToFile(inputStream, temp); + + return temp; + } + +} diff --git a/test_client/src/androidTest/java/com/owncloud/android/lib/RemoveShareTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/RemoveShareTest.java new file mode 100644 index 0000000000..a97bb7806a --- /dev/null +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/RemoveShareTest.java @@ -0,0 +1,89 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +package com.owncloud.android.lib; + +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.resources.shares.OCShare; +import com.owncloud.android.lib.resources.shares.ShareType; +import com.owncloud.android.lib.testclient.TestActivity; + +import java.io.File; + +public class RemoveShareTest extends RemoteTest { + + private static final String LOG_TAG = RemoveShareTest.class.getCanonicalName(); + + private static final String FILE_TO_UNSHARE = "/fileToUnshare.txt"; + + private TestActivity mActivity; + + private String mFullPath2FileToUnshare; + + private long mShareId; + + @Override + protected void setUp() throws Exception { + super.setUp(); + setActivityInitialTouchMode(false); + mActivity = getActivity(); + mFullPath2FileToUnshare = mBaseFolderPath + FILE_TO_UNSHARE; + + File textFile = getFile(TestActivity.ASSETS__TEXT_FILE_NAME); + RemoteOperationResult result = mActivity.uploadFile(textFile.getAbsolutePath(), mFullPath2FileToUnshare, + "txt/plain", null); + + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + + result = mActivity.createShare(mFullPath2FileToUnshare, ShareType.PUBLIC_LINK, "", false, "", 1); + + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } else { + OCShare created = (OCShare) result.getData().get(0); + mShareId = created.getRemoteId(); + } + + } + + /** + * Test Remove Share: the server must support SHARE API + */ + public void testRemoveShare() { + RemoteOperationResult result = mActivity.removeShare((int) mShareId); + assertTrue(result.isSuccess()); + } + + + @Override + protected void tearDown() throws Exception { + RemoteOperationResult removeResult = mActivity.removeFile(mFullPath2FileToUnshare); + if (!removeResult.isSuccess()) { + Utils.logAndThrow(LOG_TAG, removeResult); + } + super.tearDown(); + } +} diff --git a/test_client/src/androidTest/java/com/owncloud/android/lib/RenameFileTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/RenameFileTest.java new file mode 100644 index 0000000000..ecf19c0e84 --- /dev/null +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/RenameFileTest.java @@ -0,0 +1,262 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +package com.owncloud.android.lib; + +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; +import com.owncloud.android.lib.resources.files.FileUtils; +import com.owncloud.android.lib.testclient.TestActivity; + +import java.io.File; + +/** + * Class to test Rename File Operation + * + * @author masensio + */ + +public class RenameFileTest extends RemoteTest { + + private static final String LOG_TAG = RenameFileTest.class.getCanonicalName(); + + /* Folder data to rename. This folder must exist on the account */ + private static final String OLD_FOLDER_NAME = "folderToRename"; + private static final String OLD_FOLDER_PATH = FileUtils.PATH_SEPARATOR + OLD_FOLDER_NAME; + private static final String NEW_FOLDER_NAME = "renamedFolder"; + private static final String NEW_FOLDER_PATH = FileUtils.PATH_SEPARATOR + NEW_FOLDER_NAME; + + /* File data to rename. This file must exist on the account */ + private static final String OLD_FILE_NAME = "fileToRename.png"; + private static final String OLD_FILE_PATH = FileUtils.PATH_SEPARATOR + OLD_FILE_NAME; + private static final String NEW_FILE_NAME = "renamedFile.png"; + private static final String NEW_FILE_PATH = FileUtils.PATH_SEPARATOR + NEW_FILE_NAME; + + + private String mToCleanUpInServer; + private String mFullPath2OldFolder; + private String mFullPath2NewFolder; + private String mFullPath2OldFile; + private String mFullPath2NewFile; + + @Override + protected void setUp() throws Exception { + super.setUp(); + setActivityInitialTouchMode(false); + mFullPath2OldFolder = mBaseFolderPath + OLD_FOLDER_PATH; + mFullPath2NewFolder = mBaseFolderPath + NEW_FOLDER_PATH; + mFullPath2OldFile = mBaseFolderPath + OLD_FILE_PATH; + mFullPath2NewFile = mBaseFolderPath + NEW_FILE_PATH; + + createTestFolder(); + uploadTestFile(); + + mToCleanUpInServer = null; + } + + /** + * Test Rename Folder + */ + public void testRenameFolder() { + + mToCleanUpInServer = mFullPath2OldFolder; + RemoteOperationResult result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, NEW_FOLDER_NAME, true); + assertTrue(result.isSuccess()); + mToCleanUpInServer = mFullPath2NewFolder; + } + + /** + * Test Rename Folder with forbidden characters : \ < > : " | ? * + */ + public void testRenameFolderForbiddenCharsOnNewServer() throws Exception { + RemoteOperationResult result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, + NEW_FOLDER_NAME + "\\", true); + assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); + + result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, NEW_FOLDER_NAME + "<", true); + assertTrue(result.isSuccess()); + + createTestFolder(); + result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, NEW_FOLDER_NAME + ">", true); + assertTrue(result.isSuccess()); + + createTestFolder(); + result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, NEW_FOLDER_NAME + ":", true); + assertTrue(result.isSuccess()); + + createTestFolder(); + result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, NEW_FOLDER_NAME + "\"", true); + assertTrue(result.isSuccess()); + + createTestFolder(); + result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, NEW_FOLDER_NAME + "|", true); + assertTrue(result.isSuccess()); + + createTestFolder(); + result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, NEW_FOLDER_NAME + "?", true); + assertTrue(result.isSuccess()); + + createTestFolder(); + result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, NEW_FOLDER_NAME + "*", true); + assertTrue(result.isSuccess()); + } + + /** + * Test Rename Folder with forbidden characters : \ < > : " | ? * + */ + public void testRenameFolderForbiddenCharsOnOlderServer() { + mActivity.getClient().setOwnCloudVersion(null); + + RemoteOperationResult result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, + NEW_FOLDER_NAME + "\\", true); + assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); + + result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, NEW_FOLDER_NAME + "<", true); + assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); + + result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, NEW_FOLDER_NAME + ">", true); + assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); + + result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, NEW_FOLDER_NAME + ":", true); + assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); + + result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, NEW_FOLDER_NAME + "\"", true); + assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); + + result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, NEW_FOLDER_NAME + "|", true); + assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); + + result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, NEW_FOLDER_NAME + "?", true); + assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); + + result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, NEW_FOLDER_NAME + "*", true); + assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); + } + + /** + * Test Rename File + */ + public void testRenameFile() { + mToCleanUpInServer = mFullPath2OldFile; + RemoteOperationResult result = mActivity.renameFile(OLD_FILE_NAME, mFullPath2OldFile, NEW_FILE_NAME, false); + assertTrue(result.isSuccess()); + mToCleanUpInServer = mFullPath2NewFile; + } + + + /** + * Test Rename Folder with forbidden characters: \ < > : " | ? * + */ + public void testRenameFileForbiddenCharsOnOlderServer() { + mActivity.getClient().setOwnCloudVersion(null); + RemoteOperationResult result = mActivity.renameFile(OLD_FILE_NAME, mFullPath2OldFile, "\\" + NEW_FILE_NAME, + false); + assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); + + result = mActivity.renameFile(OLD_FILE_NAME, mFullPath2OldFile, "<" + NEW_FILE_NAME, false); + assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); + + result = mActivity.renameFile(OLD_FILE_NAME, mFullPath2OldFile, ">" + NEW_FILE_NAME, false); + assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); + + result = mActivity.renameFile(OLD_FILE_NAME, mFullPath2OldFile, ":" + NEW_FILE_NAME, false); + assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); + + result = mActivity.renameFile(OLD_FILE_NAME, mFullPath2OldFile, "\"" + NEW_FILE_NAME, false); + assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); + + result = mActivity.renameFile(OLD_FILE_NAME, mFullPath2OldFile, "|" + NEW_FILE_NAME, false); + assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); + + result = mActivity.renameFile(OLD_FILE_NAME, mFullPath2OldFile, "?" + NEW_FILE_NAME, false); + assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); + + result = mActivity.renameFile(OLD_FILE_NAME, mFullPath2OldFile, "*" + NEW_FILE_NAME, false); + assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); + } + + /** + * Test Rename Folder with forbidden characters: \ < > : " | ? * + */ + public void testRenameFileForbiddenCharsOnNewServer() throws Exception { + RemoteOperationResult result = mActivity.renameFile(OLD_FILE_NAME, mFullPath2OldFile, "\\" + NEW_FILE_NAME, + false); + assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); + + result = mActivity.renameFile(OLD_FILE_NAME, mFullPath2OldFile, "<" + NEW_FILE_NAME, false); + assertTrue(result.isSuccess()); + + uploadTestFile(); + result = mActivity.renameFile(OLD_FILE_NAME, mFullPath2OldFile, ">" + NEW_FILE_NAME, false); + assertTrue(result.isSuccess()); + + uploadTestFile(); + result = mActivity.renameFile(OLD_FILE_NAME, mFullPath2OldFile, ":" + NEW_FILE_NAME, false); + assertTrue(result.isSuccess()); + + uploadTestFile(); + result = mActivity.renameFile(OLD_FILE_NAME, mFullPath2OldFile, "\"" + NEW_FILE_NAME, false); + assertTrue(result.isSuccess()); + + uploadTestFile(); + result = mActivity.renameFile(OLD_FILE_NAME, mFullPath2OldFile, "|" + NEW_FILE_NAME, false); + assertTrue(result.isSuccess()); + + uploadTestFile(); + result = mActivity.renameFile(OLD_FILE_NAME, mFullPath2OldFile, "?" + NEW_FILE_NAME, false); + assertTrue(result.isSuccess()); + + uploadTestFile(); + result = mActivity.renameFile(OLD_FILE_NAME, mFullPath2OldFile, "*" + NEW_FILE_NAME, false); + assertTrue(result.isSuccess()); + } + + @Override + protected void tearDown() throws Exception { + if (mToCleanUpInServer != null) { + RemoteOperationResult removeResult = mActivity.removeFile(mToCleanUpInServer); + if (!removeResult.isSuccess()) { + Utils.logAndThrow(LOG_TAG, removeResult); + } + } + super.tearDown(); + } + + private void uploadTestFile() throws Exception { + File imageFile = getFile(TestActivity.ASSETS__IMAGE_FILE_NAME); + RemoteOperationResult result = mActivity.uploadFile(imageFile.getAbsolutePath(), mFullPath2OldFile, + "image/png", null); + + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + } + + private void createTestFolder() throws Exception { + RemoteOperationResult result = mActivity.createFolder(mFullPath2OldFolder, true); + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + } +} diff --git a/test_client/src/androidTest/java/com/owncloud/android/lib/SimpleFactoryManagerTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/SimpleFactoryManagerTest.java new file mode 100644 index 0000000000..42b0418438 --- /dev/null +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/SimpleFactoryManagerTest.java @@ -0,0 +1,98 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ +package com.owncloud.android.lib; + +import android.net.Uri; +import android.test.AndroidTestCase; + +import com.owncloud.android.lib.common.OwnCloudAccount; +import com.owncloud.android.lib.common.OwnCloudClient; +import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; +import com.owncloud.android.lib.common.SimpleFactoryManager; +import com.owncloud.android.lib.testclient.R; + +import junit.framework.AssertionFailedError; + +/** + * Unit test for SimpleFactoryManager + * + * @author David A. Velasco + */ + +public class SimpleFactoryManagerTest extends AndroidTestCase { + + private SimpleFactoryManager mSFMgr; + + private OwnCloudAccount mValidAccount; + private OwnCloudAccount mAnonymousAccount; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mSFMgr = new SimpleFactoryManager(); + Uri serverUri = Uri.parse(getContext().getString(R.string.server_base_url)); + String username = getContext().getString(R.string.username); + + mValidAccount = new OwnCloudAccount(serverUri, OwnCloudCredentialsFactory.newBasicCredentials( + username, getContext().getString(R.string.password))); + + mAnonymousAccount = new OwnCloudAccount(serverUri, OwnCloudCredentialsFactory.getAnonymousCredentials()); + } + + public void testGetClientFor() { + try { + OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext()); + + assertNotSame("Got same client instances for same account", client, mSFMgr.getClientFor(mValidAccount, + getContext())); + + assertNotSame("Got same client instances for different accounts", client, + mSFMgr.getClientFor(mAnonymousAccount, getContext())); + + } catch (Exception e) { + throw new AssertionFailedError("Exception getting client for account: " + e.getMessage()); + } + // TODO harder tests + } + + public void testRemoveClientFor() { + try { + OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext()); + mSFMgr.removeClientFor(mValidAccount); + assertNotSame("Got same client instance after removing it from manager", + client, mSFMgr.getClientFor(mValidAccount, getContext())); + } catch (Exception e) { + throw new AssertionFailedError("Exception getting client for account: " + e.getMessage()); + } + // TODO harder tests + } + + +// public void testSaveAllClients() { + // TODO implement test; + // or refactor saveAllClients() method out of OwnCloudClientManager to make + // it independent of AccountManager +// } + +} diff --git a/test_client/src/androidTest/java/com/owncloud/android/lib/SingleSessionManagerTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/SingleSessionManagerTest.java new file mode 100644 index 0000000000..8290a1b135 --- /dev/null +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/SingleSessionManagerTest.java @@ -0,0 +1,96 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ +package com.owncloud.android.lib; + +import android.net.Uri; +import android.test.AndroidTestCase; + +import com.owncloud.android.lib.common.OwnCloudAccount; +import com.owncloud.android.lib.common.OwnCloudClient; +import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; +import com.owncloud.android.lib.common.SingleSessionManager; +import com.owncloud.android.lib.testclient.R; + +import junit.framework.AssertionFailedError; + +/** + * Unit test for SingleSessionManager + * + * @author David A. Velasco + */ +public class SingleSessionManagerTest extends AndroidTestCase { + + private SingleSessionManager mSSMgr; + + private OwnCloudAccount mValidAccount; + private OwnCloudAccount mAnonymousAccount; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mSSMgr = new SingleSessionManager(); + Uri serverUri = Uri.parse(getContext().getString(R.string.server_base_url)); + String username = getContext().getString(R.string.username); + + mValidAccount = new OwnCloudAccount(serverUri, OwnCloudCredentialsFactory.newBasicCredentials(username, + getContext().getString(R.string.password))); + + mAnonymousAccount = new OwnCloudAccount(serverUri, OwnCloudCredentialsFactory.getAnonymousCredentials()); + } + + public void testGetClientFor() { + try { + OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext()); + OwnCloudClient client2 = mSSMgr.getClientFor(mAnonymousAccount, getContext()); + + assertNotSame("Got same client instances for different accounts", client1, client2); + assertSame("Got different client instances for same account", + client1, mSSMgr.getClientFor(mValidAccount, getContext())); + } catch (Exception e) { + throw new AssertionFailedError("Exception getting client for account: " + e.getMessage()); + } + + // TODO harder tests + } + + public void testRemoveClientFor() { + try { + OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext()); + mSSMgr.removeClientFor(mValidAccount); + assertNotSame("Got same client instance after removing it from manager", + client1, mSSMgr.getClientFor(mValidAccount, getContext())); + } catch (Exception e) { + throw new AssertionFailedError("Exception getting client for account: " + e.getMessage()); + } + + // TODO harder tests + } + + +// public void testSaveAllClients() { + // TODO implement test; + // or refactor saveAllClients() method out of OwnCloudClientManager to make + // it independent of AccountManager +// } +} diff --git a/test_client/src/androidTest/java/com/owncloud/android/lib/UpdatePrivateShareTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/UpdatePrivateShareTest.java new file mode 100644 index 0000000000..709ca1babf --- /dev/null +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/UpdatePrivateShareTest.java @@ -0,0 +1,172 @@ +/* ownCloud Android Library is available under MIT license + * @author masensio + * @author David A. Velasco + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +package com.owncloud.android.lib; + +import android.util.Log; + +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.resources.shares.OCShare; +import com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation; +import com.owncloud.android.lib.resources.shares.ShareType; +import com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation; +import com.owncloud.android.lib.testclient.TestActivity; + +import java.io.File; + +/** + * Class to test UpdateRemoteShareOperation + * with private shares + */ +public class UpdatePrivateShareTest extends RemoteTest { + private static final String LOG_TAG = UpdatePrivateShareTest.class.getCanonicalName(); + + /* File to share and update */ + private static final String FILE_TO_SHARE = "/fileToShare.txt"; + + /* Folder to share and update */ + private static final String FOLDER_TO_SHARE = "/folderToShare"; + + /* Sharees */ + private static final String USER_SHAREE = "admin"; + private static final String GROUP_SHAREE = "admin"; + + private String mFullPath2FileToShare; + private String mFullPath2FolderToShare; + + private OCShare mFileShare; + private OCShare mFolderShare; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + Log.v(LOG_TAG, "Setting up the remote fixture..."); + + // Upload the file + mFullPath2FileToShare = mBaseFolderPath + FILE_TO_SHARE; + + File textFile = getFile(TestActivity.ASSETS__TEXT_FILE_NAME); + RemoteOperationResult result = getActivity().uploadFile(textFile.getAbsolutePath(), mFullPath2FileToShare, + "txt/plain", null); + + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + + // Share the file privately with other user + result = getActivity().createShare(mFullPath2FileToShare, ShareType.USER, USER_SHAREE, false, "", + OCShare.MAXIMUM_PERMISSIONS_FOR_FILE); + + if (result.isSuccess()) { + mFileShare = (OCShare) result.getData().get(0); + } else { + mFileShare = null; + } + + // Create the folder + mFullPath2FolderToShare = mBaseFolderPath + FOLDER_TO_SHARE; + result = getActivity().createFolder(mFullPath2FolderToShare, true); + + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + + // Share the folder privately with a group + result = getActivity().createShare(mFullPath2FolderToShare, ShareType.GROUP, GROUP_SHAREE, false, "", + OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER); + + if (result.isSuccess()) { + mFolderShare = (OCShare) result.getData().get(0); + } else { + mFolderShare = null; + } + + Log.v(LOG_TAG, "Remote fixture created."); + } + + public void testUpdateSharePermissions() { + Log.v(LOG_TAG, "testUpdateSharePermissions in"); + + if (mFileShare != null) { + /// successful tests + // Update Share permissions on a shared file + UpdateRemoteShareOperation updateShare = new UpdateRemoteShareOperation(mFileShare.getRemoteId()); + updateShare.setPermissions(OCShare.READ_PERMISSION_FLAG); // minimum permissions + RemoteOperationResult result = updateShare.execute(mClient); + assertTrue(result.isSuccess()); + + // Update Share permissions on a shared folder + updateShare = new UpdateRemoteShareOperation(mFolderShare.getRemoteId()); + updateShare.setPermissions(OCShare.READ_PERMISSION_FLAG + OCShare.DELETE_PERMISSION_FLAG); + result = updateShare.execute(mClient); + assertTrue(result.isSuccess()); + + + /// unsuccessful tests + // Update Share with invalid permissions + updateShare = new UpdateRemoteShareOperation(mFileShare.getRemoteId()); + // greater than maximum value + updateShare.setPermissions(OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER + 1); + result = updateShare.execute(mClient); + assertFalse(result.isSuccess()); + + // Unshare the file before next unsuccessful tests + RemoveRemoteShareOperation unshare = new RemoveRemoteShareOperation((int) mFileShare.getRemoteId()); + result = unshare.execute(mClient); + + if (result.isSuccess()) { + // Update Share permissions on unknown share + UpdateRemoteShareOperation updateNoShare = new UpdateRemoteShareOperation(mFileShare.getRemoteId()); + updateNoShare.setPermissions(OCShare.READ_PERMISSION_FLAG); // minimum permissions + result = updateNoShare.execute(mClient); + assertFalse(result.isSuccess()); + } + } + } + + @Override + protected void tearDown() throws Exception { + Log.v(LOG_TAG, "Deleting remote fixture..."); + + if (mFullPath2FileToShare != null) { + RemoteOperationResult removeResult = getActivity().removeFile(mFullPath2FileToShare); + if (!removeResult.isSuccess()) { + Utils.logAndThrow(LOG_TAG, removeResult); + } + } + + if (mFullPath2FolderToShare != null) { + RemoteOperationResult removeResult = getActivity().removeFile(mFullPath2FolderToShare); + if (!removeResult.isSuccess()) { + Utils.logAndThrow(LOG_TAG, removeResult); + } + } + + super.tearDown(); + Log.v(LOG_TAG, "Remote fixture delete."); + } +} diff --git a/test_client/src/androidTest/java/com/owncloud/android/lib/UpdatePublicShareTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/UpdatePublicShareTest.java new file mode 100644 index 0000000000..33bf0535af --- /dev/null +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/UpdatePublicShareTest.java @@ -0,0 +1,204 @@ +/* ownCloud Android Library is available under MIT license + * @author masensio + * @author David A. Velasco + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +package com.owncloud.android.lib; + +import android.util.Log; + +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.resources.shares.OCShare; +import com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation; +import com.owncloud.android.lib.resources.shares.ShareType; +import com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation; +import com.owncloud.android.lib.testclient.TestActivity; + +import java.io.File; +import java.util.Calendar; + +/** + * Class to test UpdateRemoteShareOperation + * with public shares + */ +public class UpdatePublicShareTest extends RemoteTest { + private static final String LOG_TAG = UpdatePublicShareTest.class.getCanonicalName(); + + /* File to share and update.*/ + private static final String FILE_TO_SHARE = "/fileToShare.txt"; + + /* Folder to share and update */ + private static final String FOLDER_TO_SHARE = "/folderToShare"; + + // Data for tests + private static final String PASSWORD = "password"; + private static final String PASS_SPECIAL_CHARS = "p@ssw�rd"; + + private String mFullPath2FileToShare; + private String mFullPath2FolderToShare; + + private OCShare mShare; + private OCShare mFolderShare; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + Log.v(LOG_TAG, "Setting up the remote fixture..."); + + // Upload the file + mFullPath2FileToShare = mBaseFolderPath + FILE_TO_SHARE; + + File textFile = getFile(TestActivity.ASSETS__TEXT_FILE_NAME); + RemoteOperationResult result = getActivity().uploadFile(textFile.getAbsolutePath(), mFullPath2FileToShare, + "txt/plain", null); + + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + + // Share the file with a public link + result = getActivity().createShare(mFullPath2FileToShare, ShareType.PUBLIC_LINK, "", false, "", + OCShare.READ_PERMISSION_FLAG); + + if (result.isSuccess()) { + mShare = (OCShare) result.getData().get(0); + } else { + Utils.logAndThrow(LOG_TAG, result); + } + + // Create the folder + mFullPath2FolderToShare = mBaseFolderPath + FOLDER_TO_SHARE; + result = getActivity().createFolder(mFullPath2FolderToShare, true); + + if (!result.isSuccess()) { + Utils.logAndThrow(LOG_TAG, result); + } + + // Share the folder publicly via link + result = getActivity().createShare(mFullPath2FolderToShare, ShareType.PUBLIC_LINK, "", false, "", + OCShare.READ_PERMISSION_FLAG); + + if (result.isSuccess()) { + mFolderShare = (OCShare) result.getData().get(0); + } else { + Utils.logAndThrow(LOG_TAG, result); + } + + Log.v(LOG_TAG, "Remote fixtures created."); + } + + public void testUpdatePublicShare() { + Log.v(LOG_TAG, "testUpdatePublicShare in"); + + if (mShare != null) { + // successful tests + // Update Share with password + UpdateRemoteShareOperation updateShare = new UpdateRemoteShareOperation(mShare.getRemoteId()); + updateShare.setPassword(PASSWORD); + RemoteOperationResult result = updateShare.execute(mClient); + assertTrue(result.isSuccess()); + + // Update Share with password with special characters + updateShare = new UpdateRemoteShareOperation(mShare.getRemoteId()); + updateShare.setPassword(PASS_SPECIAL_CHARS); + result = updateShare.execute(mClient); + assertTrue(result.isSuccess()); + + // Update Share with expiration date + updateShare = new UpdateRemoteShareOperation(mShare.getRemoteId()); + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.DAY_OF_MONTH, 7); + long expirationDateInMillis = calendar.getTimeInMillis(); + updateShare.setExpirationDate(expirationDateInMillis); + result = updateShare.execute(mClient); + assertTrue(result.isSuccess()); + + // Update the Folder Share with edit permission + updateShare = new UpdateRemoteShareOperation(mFolderShare.getRemoteId()); + updateShare.setPublicUpload(true); + result = updateShare.execute(mClient); + assertTrue(result.isSuccess()); + + // unsuccessful test + // Update Share with expiration date in the past + updateShare = new UpdateRemoteShareOperation(mShare.getRemoteId()); + calendar.set(Calendar.YEAR, 2014); + expirationDateInMillis = calendar.getTimeInMillis(); + updateShare.setExpirationDate(expirationDateInMillis); + result = updateShare.execute(mClient); + assertFalse(result.isSuccess()); + + // Try to update the file Share with edit permission + updateShare = new UpdateRemoteShareOperation(mShare.getRemoteId()); + updateShare.setPublicUpload(true); + result = updateShare.execute(mClient); + assertFalse(result.isSuccess()); + + // Unshare the file before the unsuccessful tests + result = new RemoveRemoteShareOperation((int) mShare.getRemoteId()).execute(mClient); + + if (result.isSuccess()) { + // Update Share with password on unknown share + UpdateRemoteShareOperation updateNoShare = new UpdateRemoteShareOperation(mShare.getRemoteId()); + updateNoShare.setPassword(PASSWORD); + result = updateNoShare.execute(mClient); + assertFalse(result.isSuccess()); + + // Update Share with expiration date on unknown share + updateNoShare = new UpdateRemoteShareOperation(mShare.getRemoteId()); + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.DAY_OF_MONTH, 7); + expirationDateInMillis = cal.getTimeInMillis(); + updateNoShare.setExpirationDate(expirationDateInMillis); + result = updateNoShare.execute(mClient); + assertFalse(result.isSuccess()); + } + } + } + + @Override + protected void tearDown() throws Exception { + Log.v(LOG_TAG, "Deleting remote fixture..."); + + if (mFullPath2FileToShare != null) { + RemoteOperationResult removeResult = getActivity().removeFile(mFullPath2FileToShare); + + if (!removeResult.isSuccess()) { + Utils.logAndThrow(LOG_TAG, removeResult); + } + } + + if (mFullPath2FolderToShare != null) { + RemoteOperationResult removeResult = getActivity().removeFile(mFullPath2FolderToShare); + + if (!removeResult.isSuccess()) { + Utils.logAndThrow(LOG_TAG, removeResult); + } + } + + super.tearDown(); + Log.v(LOG_TAG, "Remote fixture delete."); + } +} diff --git a/test_client/src/androidTest/java/com/owncloud/android/lib/UploadFileTest.java b/test_client/src/androidTest/java/com/owncloud/android/lib/UploadFileTest.java new file mode 100644 index 0000000000..60c5cfdda8 --- /dev/null +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/UploadFileTest.java @@ -0,0 +1,106 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2015 ownCloud Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +package com.owncloud.android.lib; + +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.testclient.TestActivity; + +import java.io.File; + +/** + * Class to test Update File Operation + * + * @author masensio + * @author David A. Velasco + */ + +public class UploadFileTest extends RemoteTest { + + private static final String LOG_TAG = UploadFileTest.class.getCanonicalName(); + + private static final String UPLOAD_PATH = "/uploadedImage.png"; + + private static final String CHUNKED_UPLOAD_PATH = "/uploadedVideo.MP4"; + + private static final String FILE_NOT_FOUND_PATH = "/notFoundShouldNotBeHere.png"; + + private File mFileToUpload, mFileToUploadWithChunks; + private String mUploadedFilePath; + + @Override + protected void setUp() throws Exception { + super.setUp(); + setActivityInitialTouchMode(false); + mUploadedFilePath = null; + + mFileToUpload = getFile(TestActivity.ASSETS__IMAGE_FILE_NAME); + mFileToUploadWithChunks = getFile(TestActivity.ASSETS__VIDEO_FILE_NAME); + } + + /** + * Test Upload File without chunks + */ + public void testUploadFile() { + + String fullPath2Upload = mBaseFolderPath + UPLOAD_PATH; + RemoteOperationResult result = mActivity.uploadFile(mFileToUpload.getAbsolutePath(), fullPath2Upload, + "image/png", null); + mUploadedFilePath = fullPath2Upload; + assertTrue(result.isSuccess()); + } + + /** + * Test Upload File with chunks + */ + public void testUploadFileWithChunks() { + + String fullPath2Upload = mBaseFolderPath + CHUNKED_UPLOAD_PATH; + RemoteOperationResult result = mActivity.uploadFile(mFileToUploadWithChunks.getAbsolutePath(), fullPath2Upload, + "video/mp4", null); + mUploadedFilePath = fullPath2Upload; + assertTrue(result.isSuccess()); + } + + /** + * Test Upload Not Found File + */ + public void testUploadFileNotFound() { + String fullPath2Upload = mBaseFolderPath + FILE_NOT_FOUND_PATH; + RemoteOperationResult result = mActivity.uploadFile(FILE_NOT_FOUND_PATH, fullPath2Upload, "image/png", null); + mUploadedFilePath = fullPath2Upload; + assertFalse(result.isSuccess()); + } + + @Override + protected void tearDown() throws Exception { + if (mUploadedFilePath != null) { + RemoteOperationResult removeResult = mActivity.removeFile(mUploadedFilePath); + if (!removeResult.isSuccess()) { + Utils.logAndThrow(LOG_TAG, removeResult); + } + } + super.tearDown(); + } +} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/Utils.java b/test_client/src/androidTest/java/com/owncloud/android/lib/Utils.java similarity index 56% rename from test_client/tests/src/com/owncloud/android/lib/test_project/test/Utils.java rename to test_client/src/androidTest/java/com/owncloud/android/lib/Utils.java index 81fce582c0..c493507c6f 100644 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/Utils.java +++ b/test_client/src/androidTest/java/com/owncloud/android/lib/Utils.java @@ -1,55 +1,36 @@ /* ownCloud Android Library is available under MIT license * Copyright (C) 2015 ownCloud Inc. - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ -package com.owncloud.android.lib.test_project.test; +package com.owncloud.android.lib; -import android.content.Context; import android.util.Log; import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.test_project.R; public class Utils { - - private static String LOG_TAG = Utils.class.getSimpleName(); - - private static String sBuildNumber = null; - - public static void logAndThrow(String tag, RemoteOperationResult result) throws Exception { - Log.e(tag, result.getLogMessage(), result.getException()); - throw new Exception(result.getLogMessage(), result.getException()); - } - - public static String getBuildNumber(Context context) { - if (sBuildNumber == null) { - sBuildNumber = context.getString(R.string.build_number); - if (sBuildNumber == null || sBuildNumber.length() == 0) { - Log.w(LOG_TAG, "Build number unknown, using current time instead"); - sBuildNumber = Long.toString(System.currentTimeMillis()); - } - } - return sBuildNumber; - } - + public static void logAndThrow(String tag, RemoteOperationResult result) throws Exception { + Log.e(tag, result.getLogMessage(), result.getException()); + throw new Exception(result.getLogMessage(), result.getException()); + } } diff --git a/test_client/src/main/java/com/owncloud/android/lib/testclient/TestActivity.java b/test_client/src/main/java/com/owncloud/android/lib/testclient/TestActivity.java index 0db227e777..ecce34ef93 100644 --- a/test_client/src/main/java/com/owncloud/android/lib/testclient/TestActivity.java +++ b/test_client/src/main/java/com/owncloud/android/lib/testclient/TestActivity.java @@ -1,22 +1,22 @@ /* ownCloud Android Library is available under MIT license * Copyright (C) 2015 ownCloud Inc. - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * @@ -48,327 +48,276 @@ import com.owncloud.android.lib.resources.shares.GetRemoteSharesOperation; import com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation; import com.owncloud.android.lib.resources.shares.ShareType; +import com.owncloud.android.lib.resources.status.OwnCloudVersion; import org.apache.commons.httpclient.protocol.Protocol; import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; +import java.io.FileNotFoundException; import java.security.GeneralSecurityException; /** * Activity to test OC framework + * * @author masensio * @author David A. Velasco */ public class TestActivity extends Activity { - - private static final String TAG = null; - // This account must exists on the server side - private String mServerUri; - private String mUser; - private String mPass; - - private static final int BUFFER_SIZE = 1024; - - public static final String ASSETS__TEXT_FILE_NAME = "textFile.txt"; - public static final String ASSETS__IMAGE_FILE_NAME = "imageFile.png"; - public static final String ASSETS__VIDEO_FILE_NAME = "videoFile.MP4"; - - //private Account mAccount = null; - private OwnCloudClient mClient; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_test); - - mServerUri = getString(R.string.server_base_url); - mUser = getString(R.string.username); - mPass = getString(R.string.password); - - Protocol pr = Protocol.getProtocol("https"); - if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) { - try { - ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory(); - Protocol.registerProtocol( - "https", - new Protocol("https", psf, 443)); - - } catch (GeneralSecurityException e) { - Log.e(TAG, "Self-signed confident SSL context could not be loaded"); - } - } - - mClient = new OwnCloudClient(Uri.parse(mServerUri), NetworkUtils.getMultiThreadedConnManager(), false); - mClient.setDefaultTimeouts( - OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT, - OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT); - mClient.setFollowRedirects(true); - mClient.setCredentials( - OwnCloudCredentialsFactory.newBasicCredentials( - mUser, - mPass - ) - ); - mClient.setBaseUri(Uri.parse(mServerUri)); - - Log.v(TAG, "onCreate finished, ownCloud client ready"); - - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.test, menu); - return true; - } - - /** - * Access to the library method to Create a Folder - * @param remotePath Full path to the new directory to create in the remote server. - * @param createFullPath 'True' means that all the ancestor folders should be created if - * don't exist yet. - * - * @return - */ - public RemoteOperationResult createFolder(String remotePath, boolean createFullPath) { - - return TestActivity.createFolder(remotePath, createFullPath, mClient); - } - - /** - * Access to the library method to Create a Folder - * @param remotePath Full path to the new directory to create in the remote server. - * @param createFullPath 'True' means that all the ancestor folders should be created if - * don't exist yet. - * @param client Client instance configured to access the target OC server. - * - * @return Result of the operation - */ - public static RemoteOperationResult createFolder( - String remotePath, boolean createFullPath, OwnCloudClient client - ) { - - CreateRemoteFolderOperation createOperation = - new CreateRemoteFolderOperation(remotePath, createFullPath); - RemoteOperationResult result = createOperation.execute(client); - - return result; - } - - /** - * Access to the library method to Rename a File or Folder - * @param oldName Old name of the file. - * @param oldRemotePath Old remote path of the file. For folders it starts and ends by "/" - * @param newName New name to set as the name of file. - * @param isFolder 'true' for folder and 'false' for files - * - * @return + + private static final String TAG = null; + + public static final String ASSETS__TEXT_FILE_NAME = "textFile.txt"; + public static final String ASSETS__IMAGE_FILE_NAME = "imageFile.png"; + public static final String ASSETS__VIDEO_FILE_NAME = "videoFile.mp4"; + + private OwnCloudClient mClient; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_test); + + String serverUri = getString(R.string.server_base_url); + String username = getString(R.string.username); + String password = getString(R.string.password); + + Protocol pr = Protocol.getProtocol("https"); + if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) { + try { + ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory(); + Protocol.registerProtocol("https", new Protocol("https", psf, 443)); + } catch (GeneralSecurityException e) { + Log.e(TAG, "Self-signed confident SSL context could not be loaded"); + } + } + + mClient = new OwnCloudClient(Uri.parse(serverUri), NetworkUtils.getMultiThreadedConnManager(), false); + mClient.setDefaultTimeouts(OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT, + OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT); + mClient.setFollowRedirects(true); + mClient.setCredentials(OwnCloudCredentialsFactory.newBasicCredentials(username, password)); + mClient.setBaseUri(Uri.parse(serverUri)); + mClient.setOwnCloudVersion(OwnCloudVersion.nextcloud_10); + + Log.v(TAG, "onCreate finished, ownCloud client ready"); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.test, menu); + return true; + } + + /** + * Access to the library method to Create a Folder + * + * @param remotePath Full path to the new directory to create in the remote server. + * @param createFullPath 'True' means that all the ancestor folders should be created if + * don't exist yet. + * @return RemoteOperationResult result of call + */ + public RemoteOperationResult createFolder(String remotePath, boolean createFullPath) { + return TestActivity.createFolder(remotePath, createFullPath, mClient); + } + + /** + * Access to the library method to Create a Folder + * + * @param remotePath Full path to the new directory to create in the remote server. + * @param createFullPath 'True' means that all the ancestor folders should be created if + * don't exist yet. + * @param client Client instance configured to access the target OC server. + * @return Result of the operation + */ + public static RemoteOperationResult createFolder(String remotePath, boolean createFullPath, OwnCloudClient client) { + + CreateRemoteFolderOperation createOperation = new CreateRemoteFolderOperation(remotePath, createFullPath); + + return createOperation.execute(client); + } + + /** + * Access to the library method to Rename a File or Folder + * + * @param oldName Old name of the file. + * @param oldRemotePath Old remote path of the file. For folders it starts and ends by "/" + * @param newName New name to set as the name of file. + * @param isFolder 'true' for folder and 'false' for files + * @return RemoteOperationResult result of call + */ + + public RemoteOperationResult renameFile(String oldName, String oldRemotePath, String newName, boolean isFolder) { + + RenameRemoteFileOperation renameOperation = new RenameRemoteFileOperation(oldName, oldRemotePath, newName, isFolder); + + return renameOperation.execute(mClient); + } + + /** + * Access to the library method to Remove a File or Folder + * + * @param remotePath Remote path of the file or folder in the server. + * @return RemoteOperationResult result of call + */ + public RemoteOperationResult removeFile(String remotePath) { + return TestActivity.removeFile(remotePath, mClient); + } + + /** + * Access to the library method to Remove a File or Folder + * + * @param remotePath Remote path of the file or folder in the server. + * @return RemoteOperationResult result of call + */ + public static RemoteOperationResult removeFile(String remotePath, OwnCloudClient client) { + RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath); + return removeOperation.execute(client); + } + + + /** + * Access to the library method to Read a Folder (PROPFIND DEPTH 1) + * + * @param remotePath remote path of folder, with trailing "/" + * @return RemoteOperationResult result of call + */ + public RemoteOperationResult readFile(String remotePath) { + + ReadRemoteFolderOperation readOperation = new ReadRemoteFolderOperation(remotePath); + + return readOperation.execute(mClient); + } + + /** + * Access to the library method to Download a File + * + * @param remoteFile remoteFile to download + * @param temporalFolder to which folder the file should be downloaded, created if needed + * @return RemoteOperationResult result of call + */ + public RemoteOperationResult downloadFile(RemoteFile remoteFile, String temporalFolder) + throws FileNotFoundException { + // Create folder + String path = "/owncloud/tmp/" + temporalFolder; + File privateFolder = getFilesDir(); + File folder = new File(privateFolder.getAbsolutePath() + "/" + path); + + if (!folder.mkdirs()) { + throw new FileNotFoundException("Folder " + temporalFolder + " could not be created"); + } + + DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remoteFile.getRemotePath(), + folder.getAbsolutePath()); + + return downloadOperation.execute(mClient); + } + + /** + * Access to the library method to Upload a File + * + * @param storagePath local path of file + * @param remotePath remote path of file + * @param mimeType mimeType, can be null to auto-detect on server + * @param requiredEtag if set upload will be skipped if same etag on server, can be null + * @return RemoteOperationResult result of call + */ + public RemoteOperationResult uploadFile(String storagePath, String remotePath, String mimeType, + String requiredEtag) { + return TestActivity.uploadFile(this, storagePath, remotePath, mimeType, mClient, requiredEtag); + } + + + /** + * Access to the library method to Upload a File + * + * @param context context of app + * @param storagePath local path of file + * @param remotePath remote path of file + * @param mimeType mimeType, can be null to auto-detect on server + * @param client Client instance configured to access the target OC server. + * @param requiredEtag if set upload will be skipped if same etag on server, can be null + * @return RemoteOperationResult result of call */ + public static RemoteOperationResult uploadFile(Context context, String storagePath, String remotePath, + String mimeType, OwnCloudClient client, String requiredEtag) { - public RemoteOperationResult renameFile(String oldName, String oldRemotePath, String newName, boolean isFolder) { - - RenameRemoteFileOperation renameOperation = new RenameRemoteFileOperation(oldName, oldRemotePath, newName, isFolder); - RemoteOperationResult result = renameOperation.execute(mClient); - - return result; - } - - /** - * Access to the library method to Remove a File or Folder - * - * @param remotePath Remote path of the file or folder in the server. - * @return - */ - public RemoteOperationResult removeFile(String remotePath) { - RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath); - RemoteOperationResult result = removeOperation.execute(mClient); - return result; - } - - /** - * Access to the library method to Remove a File or Folder - * - * @param remotePath Remote path of the file or folder in the server. - * @return - */ - public static RemoteOperationResult removeFile(String remotePath, OwnCloudClient client) { - RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath); - RemoteOperationResult result = removeOperation.execute(client); - return result; - } - - - /** - * Access to the library method to Read a Folder (PROPFIND DEPTH 1) - * @param remotePath - * - * @return - */ - public RemoteOperationResult readFile(String remotePath) { - - ReadRemoteFolderOperation readOperation= new ReadRemoteFolderOperation(remotePath); - RemoteOperationResult result = readOperation.execute(mClient); - - return result; - } - - /** - * Access to the library method to Download a File - * @param remoteFile - * @param temporalFolder - * - * @return - */ - public RemoteOperationResult downloadFile(RemoteFile remoteFile, String temporalFolder) { - // Create folder - String path = "/owncloud/tmp/" + temporalFolder; - File privateFolder = getFilesDir(); - File folder = new File(privateFolder.getAbsolutePath() + "/" + path); - folder.mkdirs(); - - DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remoteFile.getRemotePath(), folder.getAbsolutePath()); - RemoteOperationResult result = downloadOperation.execute(mClient); - - return result; - } - - /** Access to the library method to Upload a File - * @param storagePath - * @param remotePath - * @param mimeType - * @param requiredEtag - * - * @return - */ - public RemoteOperationResult uploadFile(String storagePath, String remotePath, String mimeType, - String requiredEtag) { - return TestActivity.uploadFile(this, storagePath, remotePath, mimeType, mClient, requiredEtag); - } - - - /** Access to the library method to Upload a File - * - * @param context - * @param storagePath - * @param remotePath - * @param mimeType - * @param client Client instance configured to access the target OC server. - * @param requiredEtag - * @return - */ - public static RemoteOperationResult uploadFile(Context context, String storagePath, String remotePath, - String mimeType, OwnCloudClient client, String requiredEtag) { - - String fileLastModifTimestamp = getFileLastModifTimeStamp(storagePath); - - UploadRemoteFileOperation uploadOperation; - - if ((new File(storagePath)).length() > ChunkedUploadRemoteFileOperation.CHUNK_SIZE) { - uploadOperation = new ChunkedUploadRemoteFileOperation( - context, storagePath, remotePath, mimeType, requiredEtag, fileLastModifTimestamp - ); - } else { + String fileLastModifiedTimestamp = getFileLastModifiedTimeStamp(storagePath); + + UploadRemoteFileOperation uploadOperation; + + if ((new File(storagePath)).length() > ChunkedUploadRemoteFileOperation.CHUNK_SIZE) { + uploadOperation = new ChunkedUploadRemoteFileOperation( + context, storagePath, remotePath, mimeType, requiredEtag, fileLastModifiedTimestamp + ); + } else { uploadOperation = new UploadRemoteFileOperation( - storagePath, remotePath, mimeType, requiredEtag, fileLastModifTimestamp - ); + storagePath, remotePath, mimeType, requiredEtag, fileLastModifiedTimestamp + ); } - return uploadOperation.execute(client); - } - - /** Access to the library method to Get Shares - * - * @return - */ - public RemoteOperationResult getShares() { - GetRemoteSharesOperation getOperation = new GetRemoteSharesOperation(); - return getOperation.execute(mClient); - } - - /** Access to the library method to Create Share - * @param path Full path of the file/folder being shared. Mandatory argument - * @param shareType 0 = user, 1 = group, 3 = Public link. Mandatory argument - * @param shareWith User/group ID with who the file should be shared. This is mandatory for shareType of 0 or 1 - * @param publicUpload If false (default) public cannot upload to a public shared folder. - * If true public can upload to a shared folder. Only available for public link shares - * @param password Password to protect a public link share. Only available for public link shares - * @param permissions 1 - Read only Default for public shares - * 2 - Update - * 4 - Create - * 8 - Delete - * 16- Re-share - * 31- All above Default for private shares - * For user or group shares. - * To obtain combinations, add the desired values together. - * For instance, for Re-Share, delete, read, update add 16+8+2+1 = 27. - * - * @return - */ - public RemoteOperationResult createShare(String path, ShareType shareType, String shareWith, boolean publicUpload, - String password, int permissions){ - - CreateRemoteShareOperation createOperation = new CreateRemoteShareOperation(path, shareType, shareWith, - publicUpload, password, permissions); - return createOperation.execute(mClient); - } - - - /** - * Access to the library method to Remove Share - * - * @param idShare Share ID - */ - - public RemoteOperationResult removeShare(int idShare) { - RemoveRemoteShareOperation removeOperation = new RemoveRemoteShareOperation(idShare); - return removeOperation.execute(mClient); - } - - - /** - * Extracts file from AssetManager to cache folder. - * - * @param fileName Name of the asset file to extract. - * @return File instance of the extracted file. - */ - public File extractAsset(String fileName) throws IOException { - return TestActivity.extractAsset(fileName, this); - } - - /** - * Extracts file from AssetManager to cache folder. - * - * @param fileName Name of the asset file to extract. - * @param context Android context to access assets and file system. - * @return File instance of the extracted file. - */ - public static File extractAsset(String fileName, Context context) throws IOException { - File extractedFile = new File(context.getCacheDir() + File.separator + fileName); - if (!extractedFile.exists()) { - InputStream in = null; - FileOutputStream out = null; - in = context.getAssets().open(fileName); - out = new FileOutputStream(extractedFile); - byte[] buffer = new byte[BUFFER_SIZE]; - int readCount; - while((readCount = in.read(buffer)) != -1){ - out.write(buffer, 0, readCount); - } - out.flush(); - out.close(); - in.close(); - } - return extractedFile; - } - - private static String getFileLastModifTimeStamp (String storagePath) { + return uploadOperation.execute(client); + } + + /** + * Access to the library method to Get Shares + * + * @return RemoteOperationResult result of call + */ + public RemoteOperationResult getShares() { + GetRemoteSharesOperation getOperation = new GetRemoteSharesOperation(); + return getOperation.execute(mClient); + } + + /** + * Access to the library method to Create Share + * + * @param path Full path of the file/folder being shared. Mandatory argument + * @param shareType 0 = user, 1 = group, 3 = Public link. Mandatory argument + * @param shareWith User/group ID with who the file should be shared. This is mandatory for shareType of 0 or 1 + * @param publicUpload If false (default) public cannot upload to a public shared folder. + * If true public can upload to a shared folder. Only available for public link shares + * @param password Password to protect a public link share. Only available for public link shares + * @param permissions 1 - Read only Default for public shares + * 2 - Update + * 4 - Create + * 8 - Delete + * 16- Re-share + * 31- All above Default for private shares + * For user or group shares. + * To obtain combinations, add the desired values together. + * For instance, for Re-Share, delete, read, update add 16+8+2+1 = 27. + * @return RemoteOperationResult result of call + */ + public RemoteOperationResult createShare(String path, ShareType shareType, String shareWith, boolean publicUpload, + String password, int permissions) { + + CreateRemoteShareOperation createOperation = new CreateRemoteShareOperation(path, shareType, shareWith, + publicUpload, password, permissions); + return createOperation.execute(mClient); + } + + + /** + * Access to the library method to Remove Share + * + * @param idShare Share ID + */ + + public RemoteOperationResult removeShare(int idShare) { + RemoveRemoteShareOperation removeOperation = new RemoveRemoteShareOperation(idShare); + return removeOperation.execute(mClient); + } + + private static String getFileLastModifiedTimeStamp(String storagePath) { File file = new File(storagePath); - Long timeStampLong = file.lastModified()/1000; + Long timeStampLong = file.lastModified() / 1000; return timeStampLong.toString(); } + + public OwnCloudClient getClient() { + return mClient; + } } diff --git a/test_client/src/main/res/values/setup.xml b/test_client/src/main/res/values/setup.xml index 289e08897b..65b97b2a74 100644 --- a/test_client/src/main/res/values/setup.xml +++ b/test_client/src/main/res/values/setup.xml @@ -24,10 +24,9 @@ --> - - - - - + http://server + http://server2 + test + test Mozilla/5.0 (Android) ownCloud test project diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateFolderTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateFolderTest.java deleted file mode 100644 index 3f9f9d8033..0000000000 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateFolderTest.java +++ /dev/null @@ -1,133 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2015 ownCloud Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ -package com.owncloud.android.lib.test_project.test; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; -import com.owncloud.android.lib.test_project.TestActivity; - -/** - * Class to test Create Folder Operation - * @author masensio - * @author David A. Velasco - * - */ -public class CreateFolderTest extends RemoteTest { - - - private static final String LOG_TAG = CreateFolderTest.class.getCanonicalName(); - - private static final String FOLDER_PATH_BASE = "/testCreateFolder"; - - private TestActivity mActivity; - private List mCreatedFolderPaths; - private String mFullPath2FolderBase; - - public CreateFolderTest() { - super(); - mCreatedFolderPaths = new ArrayList(); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - mActivity = getActivity(); - mCreatedFolderPaths.clear(); - mFullPath2FolderBase = mBaseFolderPath + FOLDER_PATH_BASE; - } - - /** - * Test Create Folder - */ - public void testCreateFolder() { - String remotePath = mFullPath2FolderBase; - mCreatedFolderPaths.add(remotePath); - RemoteOperationResult result = mActivity.createFolder(remotePath, true); - assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT); - - // Create Subfolder - remotePath = mFullPath2FolderBase + FOLDER_PATH_BASE; - mCreatedFolderPaths.add(remotePath); - result = mActivity.createFolder(remotePath, true); - assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT); - } - - - /** - * Test to Create Folder with special characters: / \ < > : " | ? * - */ - public void testCreateFolderSpecialCharacters() { - - String remotePath = mFullPath2FolderBase + "_\\"; - RemoteOperationResult result = mActivity.createFolder(remotePath, true); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - remotePath = mFullPath2FolderBase + "_<"; - result = mActivity.createFolder(remotePath, true); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - remotePath = mFullPath2FolderBase + "_>"; - result = mActivity.createFolder(remotePath, true); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - remotePath = mFullPath2FolderBase + "_:"; - result = mActivity.createFolder(remotePath, true); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - remotePath = mFullPath2FolderBase + "_\""; - result = mActivity.createFolder(remotePath, true); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - remotePath = mFullPath2FolderBase + "_|"; - result = mActivity.createFolder(remotePath, true); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - remotePath = mFullPath2FolderBase + "_?"; - result = mActivity.createFolder(remotePath, true); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - remotePath = mFullPath2FolderBase + "_*"; - result = mActivity.createFolder(remotePath, true); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - } - - - @Override - protected void tearDown() throws Exception { - Iterator it = mCreatedFolderPaths.iterator(); - RemoteOperationResult removeResult = null; - while (it.hasNext()) { - removeResult = mActivity.removeFile(it.next()); - if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) { - Utils.logAndThrow(LOG_TAG, removeResult); - } - } - super.tearDown(); - } - -} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateShareTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateShareTest.java deleted file mode 100644 index 495bdc7804..0000000000 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/CreateShareTest.java +++ /dev/null @@ -1,310 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2015 ownCloud Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package com.owncloud.android.lib.test_project.test; - -import java.io.File; - -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; -import com.owncloud.android.lib.resources.shares.ShareType; -import com.owncloud.android.lib.test_project.R; -import com.owncloud.android.lib.test_project.TestActivity; - -/** - * Test Create Share: the server must support SHARE API - */ -public class CreateShareTest extends RemoteTest { - - private static final String LOG_TAG = CreateShareTest.class.getCanonicalName(); - - /* File to share.*/ - private static final String FILE_TO_SHARE = "/fileToShare.txt"; - - /* Non-existent file*/ - private static final String NON_EXISTENT_FILE = "/nonExistentFile.txt"; - - private TestActivity mActivity; - private String mFullPath2FileToShare; - private String mFullPath2NonExistentFile; - private String mRemoteServer; - - @Override - protected void setUp() throws Exception { - super.setUp(); - setActivityInitialTouchMode(false); - mActivity = getActivity(); - mFullPath2FileToShare = mBaseFolderPath + FILE_TO_SHARE; - mFullPath2NonExistentFile = mBaseFolderPath + NON_EXISTENT_FILE; - mRemoteServer = getActivity().getString(R.string.server_base_url_2); - - File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME); - RemoteOperationResult result = mActivity.uploadFile( - textFile.getAbsolutePath(), - mFullPath2FileToShare, - "txt/plain"); - if (!result.isSuccess()) { - Utils.logAndThrow(LOG_TAG, result); - } - } - - /** - * Test creation of public shares - */ - public void testCreatePublicShare() { - - /// Successful cases - RemoteOperationResult result = mActivity.createShare( - mFullPath2FileToShare, - ShareType.PUBLIC_LINK, - "", - false, - "", - 1); - assertTrue(result.isSuccess()); - - /// Failed cases - - // file doesn't exist - result = mActivity.createShare( - mFullPath2NonExistentFile, - ShareType.PUBLIC_LINK, - "", - false, - "", - 1); - assertFalse(result.isSuccess()); - assertEquals( - RemoteOperationResult.ResultCode.SHARE_NOT_FOUND, - result.getCode() - ); - assertTrue( // error message from server as part of the result - result.getData().size() == 1 && - result.getData().get(0) instanceof String - ); - - } - - - /** - * Test creation of private shares with groups - */ - public void testCreatePrivateShareWithUser() { - - /// Successful cases - RemoteOperationResult result = mActivity.createShare( - mFullPath2FileToShare, - ShareType.USER, - "admin", - false, - "", - 31); - assertTrue(result.isSuccess()); - - - /// Failed cases - - // sharee doesn't exist - result = mActivity.createShare( - mFullPath2FileToShare, - ShareType.USER, - "no_exist", - false, - "", - 31); - assertFalse(result.isSuccess()); - assertEquals( - RemoteOperationResult.ResultCode.SHARE_FORBIDDEN, - result.getCode() - ); - assertTrue( // error message from server as part of the result - result.getData().size() == 1 && - result.getData().get(0) instanceof String - ); - - // file doesn't exist - result = mActivity.createShare( - mFullPath2NonExistentFile, - ShareType.USER, - "admin", - false, - "", - 31); - assertFalse(result.isSuccess()); - assertEquals( - RemoteOperationResult.ResultCode.SHARE_NOT_FOUND, - result.getCode() - ); - assertTrue( // error message from server as part of the result - result.getData().size() == 1 && - result.getData().get(0) instanceof String - ); - - } - - - /** - * Test creation of private shares with groups - */ - public void testCreatePrivateShareWithGroup() { - - /// Successful cases - RemoteOperationResult result = mActivity.createShare( - mFullPath2FileToShare, - ShareType.GROUP, - "admin", - false, - "", - 1); - assertTrue(result.isSuccess()); - - - /// Failed cases - - // sharee doesn't exist - result = mActivity.createShare( - mFullPath2FileToShare, - ShareType.GROUP, - "no_exist", - false, - "", - 31); - assertFalse(result.isSuccess()); - assertEquals( - RemoteOperationResult.ResultCode.SHARE_FORBIDDEN, - result.getCode() - ); - assertTrue( // error message from server as part of the result - result.getData().size() == 1 && - result.getData().get(0) instanceof String - ); - - // file doesn't exist - result = mActivity.createShare( - mFullPath2NonExistentFile, - ShareType.GROUP, - "admin", - false, - "", - 31); - assertFalse(result.isSuccess()); - assertEquals( - RemoteOperationResult.ResultCode.SHARE_NOT_FOUND, - result.getCode() - ); - assertTrue( // error message from server as part of the result - result.getData().size() == 1 && - result.getData().get(0) instanceof String - ); - - } - - /** - * Test creation of federated shares with remote users - */ - public void testCreateFederatedShareWithUser() { - - String remoteDomain = mRemoteServer.split("//")[1]; - - /// Successful cases - RemoteOperationResult result = mActivity.createShare( - mFullPath2FileToShare, - ShareType.FEDERATED, - "admin@" + remoteDomain, - false, - "", - 1); - assertTrue(result.isSuccess()); - - - /// Failed cases - - // sharee doesn't exist in an existing remote server - result = mActivity.createShare( - mFullPath2FileToShare, - ShareType.FEDERATED, - "no_exist@" + remoteDomain, - false, - "", - 31); - assertFalse(result.isSuccess()); - assertEquals( - RemoteOperationResult.ResultCode.SHARE_FORBIDDEN, - result.getCode() - ); - assertTrue( // error message from server as part of the result - result.getData().size() == 1 && - result.getData().get(0) instanceof String - ); - - // remote server doesn't exist - result = mActivity.createShare( - mFullPath2FileToShare, - ShareType.FEDERATED, - "no_exist", - false, - "", - 31); - assertFalse(result.isSuccess()); - assertEquals( - RemoteOperationResult.ResultCode.SHARE_WRONG_PARAMETER, - result.getCode() - ); - assertTrue( // error message from server as part of the result - result.getData().size() == 1 && - result.getData().get(0) instanceof String - ); - - // file doesn't exist - result = mActivity.createShare( - mFullPath2NonExistentFile, - ShareType.FEDERATED, - "admin@" + remoteDomain, - false, - "", - 31); - assertFalse(result.isSuccess()); - assertEquals( - RemoteOperationResult.ResultCode.SHARE_NOT_FOUND, - result.getCode() - ); - assertTrue( // error message from server as part of the result - result.getData().size() == 1 && - result.getData().get(0) instanceof String - ); - - } - - - @Override - protected void tearDown() throws Exception { - RemoteOperationResult removeResult = mActivity.removeFile(mFullPath2FileToShare); - if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) { - Utils.logAndThrow(LOG_TAG, removeResult); - } - super.tearDown(); - } - - -} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/DeleteFileTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/DeleteFileTest.java deleted file mode 100644 index 89cbbebf95..0000000000 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/DeleteFileTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2015 ownCloud Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package com.owncloud.android.lib.test_project.test; - -import java.io.File; - -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; -import com.owncloud.android.lib.test_project.TestActivity; - -/** - * Class to test Delete a File Operation - * @author masensio - * - */ - -public class DeleteFileTest extends RemoteTest { - - private static final String LOG_TAG = DeleteFileTest.class.getCanonicalName(); - - /* Folder data to delete. */ - private static final String FOLDER_PATH = "/folderToDelete"; - - /* File to delete. */ - private static final String FILE_PATH = "/fileToDelete.txt"; - - private TestActivity mActivity; - private String mFullPath2Folder; - private String mFullPath2File; - - @Override - protected void setUp() throws Exception { - super.setUp(); - setActivityInitialTouchMode(false); - mActivity = getActivity(); - mFullPath2Folder = mBaseFolderPath + FOLDER_PATH; - mFullPath2File = mBaseFolderPath + FILE_PATH; - - RemoteOperationResult result = mActivity.createFolder(mFullPath2Folder, true); - if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) { - Utils.logAndThrow(LOG_TAG, result); - } - - File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME); - result = mActivity.uploadFile( - textFile.getAbsolutePath(), - mFullPath2File, - "txt/plain"); - if (!result.isSuccess()) { - Utils.logAndThrow(LOG_TAG, result); - } - - } - - /** - * Test Remove Folder - */ - public void testRemoveFolder() { - - RemoteOperationResult result = mActivity.removeFile(mFullPath2Folder); - assertTrue(result.isSuccess()); - } - - /** - * Test Remove File - */ - public void testRemoveFile() { - - RemoteOperationResult result = mActivity.removeFile(mFullPath2File); - assertTrue(result.isSuccess()); - } - - - @Override - protected void tearDown() throws Exception { - // nothing to do: - // - if tests were fine, there is nothing to clean up in the server side - // - if tests failed, there is nothing we can do to clean up the server side - super.tearDown(); - } - -} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/DownloadFileTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/DownloadFileTest.java deleted file mode 100644 index 04f360907b..0000000000 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/DownloadFileTest.java +++ /dev/null @@ -1,143 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2015 ownCloud Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package com.owncloud.android.lib.test_project.test; - -import java.io.File; - -import com.owncloud.android.lib.resources.files.RemoteFile; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; -import com.owncloud.android.lib.test_project.TestActivity; - -/** - * Class to test Download File Operation - * @author masensio - * @author David A. Velasco - */ - -public class DownloadFileTest extends RemoteTest { - - - private static final String LOG_TAG = DownloadFileTest.class.getCanonicalName(); - - /* Files to download. These files must exist on the account */ - private static final String IMAGE_PATH = "/fileToDownload.png"; - private static final String IMAGE_PATH_WITH_SPECIAL_CHARS = "/@file@download.png"; - private static final String IMAGE_NOT_FOUND = "/fileNotFound.png"; - - private String mFullPath2Image; - private String mFullPath2ImageWitSpecialChars; - private String mFullPath2ImageNotFound; - private String mDownloadedFilePath; - private TestActivity mActivity; - - - @Override - protected void setUp() throws Exception { - super.setUp(); - setActivityInitialTouchMode(false); - mActivity = getActivity(); - mDownloadedFilePath = null; - mFullPath2Image = mBaseFolderPath + IMAGE_PATH; - mFullPath2ImageWitSpecialChars = mBaseFolderPath + IMAGE_PATH_WITH_SPECIAL_CHARS; - mFullPath2ImageNotFound = mBaseFolderPath + IMAGE_NOT_FOUND; - - File imageFile = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME); - - RemoteOperationResult result = mActivity.uploadFile( - imageFile.getAbsolutePath(), - mFullPath2Image, - "image/png"); - if (!result.isSuccess()) { - Utils.logAndThrow(LOG_TAG, result); - } - - result = mActivity.uploadFile( - imageFile.getAbsolutePath(), - mFullPath2ImageWitSpecialChars, - "image/png"); - if (!result.isSuccess()) { - Utils.logAndThrow(LOG_TAG, result); - } - - result = mActivity.removeFile(mFullPath2ImageNotFound); - if (!result.isSuccess() && result.getCode() != ResultCode.FILE_NOT_FOUND) { - Utils.logAndThrow(LOG_TAG, result); - } - - } - - /** - * Test Download a File - */ - public void testDownloadFile() { - RemoteOperationResult result = mActivity.downloadFile( - new RemoteFile(mFullPath2Image), "" - ); - mDownloadedFilePath = mFullPath2Image; - assertTrue(result.isSuccess()); - // TODO some checks involving the local file - } - - /** - * Test Download a File with special chars - */ - public void testDownloadFileSpecialChars() { - RemoteOperationResult result = mActivity.downloadFile( - new RemoteFile(mFullPath2ImageWitSpecialChars), "" - ); - mDownloadedFilePath = mFullPath2ImageWitSpecialChars; - assertTrue(result.isSuccess()); - // TODO some checks involving the local file - } - - /** - * Test Download a Not Found File - */ - public void testDownloadFileNotFound() { - RemoteOperationResult result = mActivity.downloadFile( - new RemoteFile(mFullPath2ImageNotFound), "" - ); - assertFalse(result.isSuccess()); - } - - - @Override - protected void tearDown() throws Exception { - if (mDownloadedFilePath != null) { - RemoteOperationResult removeResult = mActivity.removeFile(mDownloadedFilePath); - if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) { - Utils.logAndThrow(LOG_TAG, removeResult); - } - } - File[] files = mActivity.getFilesDir().listFiles(); - for (File file : files) { - file.delete(); - } - super.tearDown(); - } - - -} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/GetCapabilitiesTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/GetCapabilitiesTest.java deleted file mode 100644 index b00435e15c..0000000000 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/GetCapabilitiesTest.java +++ /dev/null @@ -1,145 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * @author masensio - * Copyright (C) 2015 ownCloud Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package com.owncloud.android.lib.test_project.test; - -import java.security.GeneralSecurityException; - -import junit.framework.AssertionFailedError; - -import org.apache.commons.httpclient.protocol.Protocol; -import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; - -import android.content.Context; -import android.net.Uri; -import android.util.Log; - -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.OwnCloudClientFactory; -import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; -import com.owncloud.android.lib.common.network.NetworkUtils; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.resources.status.GetRemoteCapabilitiesOperation; -import com.owncloud.android.lib.test_project.R; -import com.owncloud.android.lib.test_project.SelfSignedConfidentSslSocketFactory; - -/** - * Class to test GetRemoteCapabilitiesOperation - * - */ -public class GetCapabilitiesTest extends RemoteTest { - private static final String LOG_TAG = GetCapabilitiesTest.class.getCanonicalName(); - - String mServerUri, mUser, mPass; - OwnCloudClient mClient = null; - - public GetCapabilitiesTest() { - super(); - - Protocol pr = Protocol.getProtocol("https"); - if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) { - try { - ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory(); - Protocol.registerProtocol( - "https", - new Protocol("https", psf, 443)); - - } catch (GeneralSecurityException e) { - throw new AssertionFailedError( - "Self-signed confident SSL context could not be loaded"); - } - } - - } - - - protected Context getContext() { - return getActivity(); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - - // Next initialization cannot be done in the constructor because getContext() is not - // ready yet, returns NULL. - initAccessToServer(getContext()); - - Log.v(LOG_TAG, "Setting up the remote fixture..."); - - Log.v(LOG_TAG, "Remote fixture created."); - - } - - - // Tests - /** - * Test get capabilities - * - * Requires OC server 8.1 or later - */ - public void testGetRemoteCapabilitiesOperation() { - // get capabilities - GetRemoteCapabilitiesOperation getCapabilitiesOperation = new GetRemoteCapabilitiesOperation(); - RemoteOperationResult result = getCapabilitiesOperation.execute(mClient); - assertTrue(result.isSuccess()); - assertTrue(result.getData() != null && result.getData().size() == 1); - - } - - @Override - protected void tearDown() throws Exception { - Log.v(LOG_TAG, "Deleting remote fixture..."); - super.tearDown(); - Log.v(LOG_TAG, "Remote fixture delete."); - } - - - private void initAccessToServer(Context context) { - Log.v(LOG_TAG, "Setting up client instance to access OC server..."); - - mServerUri = context.getString(R.string.server_base_url); - mUser = context.getString(R.string.username); - mPass = context.getString(R.string.password); - - mClient = new OwnCloudClient( - Uri.parse(mServerUri), - NetworkUtils.getMultiThreadedConnManager() - ); - mClient.setDefaultTimeouts( - OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT, - OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT); - mClient.setFollowRedirects(true); - mClient.setCredentials( - OwnCloudCredentialsFactory.newBasicCredentials( - mUser, - mPass - ) - ); - - Log.v(LOG_TAG, "Client instance set up."); - - } -} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/GetShareesTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/GetShareesTest.java deleted file mode 100644 index cb0ea060ad..0000000000 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/GetShareesTest.java +++ /dev/null @@ -1,283 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * @author David A. Velasco - * Copyright (C) 2015 ownCloud Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package com.owncloud.android.lib.test_project.test; - -import java.security.GeneralSecurityException; - -import junit.framework.AssertionFailedError; - -import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.protocol.Protocol; -import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; -import org.json.JSONException; -import org.json.JSONObject; - -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.OwnCloudClientFactory; -import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; -import com.owncloud.android.lib.common.network.NetworkUtils; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.resources.shares.GetRemoteShareesOperation; -import com.owncloud.android.lib.resources.shares.ShareType; -import com.owncloud.android.lib.test_project.R; -import com.owncloud.android.lib.test_project.SelfSignedConfidentSslSocketFactory; - -import android.content.Context; -import android.net.Uri; -import android.util.Log; - -/** - * Class to test GetRemoteShareesOperation - * - * With this TestCase we are experimenting a bit to improve the test suite design, in two aspects: - * - * - Reduce the dependency from the set of test cases on the "test project" needed to - * have an instrumented APK to install in the device, as required by the testing framework - * provided by Android. To get there, this class avoids calling TestActivity methods in the test - * method. - * - * - Reduce the impact of creating a remote fixture over the Internet, while the structure of the - * TestCase is kept easy to maintain. To get this, all the tests are done in a single test method, - * granting this way that setUp and tearDown are run only once. - * - */ - -public class GetShareesTest extends RemoteTest { - - private static final String LOG_TAG = GetShareesTest.class.getCanonicalName(); - - String mServerUri, mUser, mPass, mServerUri2; - OwnCloudClient mClient = null; - - public GetShareesTest() { - super(); - - Protocol pr = Protocol.getProtocol("https"); - if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) { - try { - ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory(); - Protocol.registerProtocol( - "https", - new Protocol("https", psf, 443)); - - } catch (GeneralSecurityException e) { - throw new AssertionFailedError( - "Self-signed confident SSL context could not be loaded"); - } - } - - } - - - protected Context getContext() { - return getActivity(); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - - // Next initialization cannot be done in the constructor because getContext() is not - // ready yet, returns NULL. - initAccessToServer(getContext()); - - Log.v(LOG_TAG, "Setting up the remote fixture..."); - - Log.v(LOG_TAG, "Remote fixture created."); - - } - - - /** - * Test get sharees - * - * Requires OC server 8.2 or later - */ - public void testGetRemoteShareesOperation() { - Log.v(LOG_TAG, "testGetRemoteSharees in"); - - /// successful cases - - // search for sharees including "a" - GetRemoteShareesOperation getShareesOperation = new GetRemoteShareesOperation("a", 1, 50); - RemoteOperationResult result = getShareesOperation.execute(mClient); - JSONObject resultItem; - JSONObject value; - int type; - int userCount = 0, groupCount = 0; - assertTrue(result.isSuccess() && result.getData().size() > 0); - try { - for (int i=0; i 0); - assertTrue(groupCount > 0); - } catch (JSONException e) { - AssertionFailedError afe = new AssertionFailedError(e.getLocalizedMessage()); - afe.setStackTrace(e.getStackTrace()); - throw afe; - } - - // search for sharees including "ad" - expecting user "admin" & group "admin" - getShareesOperation = new GetRemoteShareesOperation("ad", 1, 50); - result = getShareesOperation.execute(mClient); - assertTrue(result.isSuccess() && result.getData().size() == 2); - userCount = 0; groupCount = 0; - try { - for (int i=0; i<2; i++) { - resultItem = (JSONObject) result.getData().get(i); - value = resultItem.getJSONObject(GetRemoteShareesOperation.NODE_VALUE); - type = value.getInt(GetRemoteShareesOperation.PROPERTY_SHARE_TYPE); - if (type == ShareType.GROUP.getValue()) { - groupCount++; - } else { - userCount++; - } - } - assertEquals(userCount, 1); - assertEquals(groupCount, 1); - } catch (JSONException e) { - AssertionFailedError afe = new AssertionFailedError(e.getLocalizedMessage()); - afe.setStackTrace(e.getStackTrace()); - throw afe; - } - - - // search for sharees including "bd" - expecting 0 results - getShareesOperation = new GetRemoteShareesOperation("bd", 1, 50); - result = getShareesOperation.execute(mClient); - assertTrue(result.isSuccess() && result.getData().size() == 0); - - - /// failed cases - - // search for sharees including wrong page values - getShareesOperation = new GetRemoteShareesOperation("a", 0, 50); - result = getShareesOperation.execute(mClient); - assertTrue(!result.isSuccess() && result.getHttpCode() == HttpStatus.SC_BAD_REQUEST); - - getShareesOperation = new GetRemoteShareesOperation("a", 1, 0); - result = getShareesOperation.execute(mClient); - assertTrue(!result.isSuccess() && result.getHttpCode() == HttpStatus.SC_BAD_REQUEST); - } - - /** - * Test get federated sharees - * - * Requires OC server 8.2 or later - */ - public void testGetFederatedShareesOperation() { - Log.v(LOG_TAG, "testGetFederatedSharees in"); - - /// successful cases - - // search for sharees including "@" - GetRemoteShareesOperation getShareesOperation = new GetRemoteShareesOperation("@", 1, 50); - RemoteOperationResult result = getShareesOperation.execute(mClient); - JSONObject resultItem; - JSONObject value; - int type; - int fedCount = 0; - assertTrue(result.isSuccess() && result.getData().size() > 0); - try { - for (int i=0; i 0); - } catch (JSONException e) { - AssertionFailedError afe = new AssertionFailedError(e.getLocalizedMessage()); - afe.setStackTrace(e.getStackTrace()); - throw afe; - } - - // search for 'admin' sharee from external server - expecting at least 1 result - String remoteSharee = "admin@" + mServerUri2.split("//")[1]; - getShareesOperation = new GetRemoteShareesOperation(remoteSharee, 1, 50); - result = getShareesOperation.execute(mClient); - assertTrue(result.isSuccess() && result.getData().size() > 0); - - - /// failed cases - - // search for sharees including wrong page values - getShareesOperation = new GetRemoteShareesOperation("@", 0, 50); - result = getShareesOperation.execute(mClient); - assertTrue(!result.isSuccess() && result.getHttpCode() == HttpStatus.SC_BAD_REQUEST); - - getShareesOperation = new GetRemoteShareesOperation("@", 1, 0); - result = getShareesOperation.execute(mClient); - assertTrue(!result.isSuccess() && result.getHttpCode() == HttpStatus.SC_BAD_REQUEST); - } - - @Override - protected void tearDown() throws Exception { - Log.v(LOG_TAG, "Deleting remote fixture..."); - super.tearDown(); - Log.v(LOG_TAG, "Remote fixture delete."); - } - - - private void initAccessToServer(Context context) { - Log.v(LOG_TAG, "Setting up client instance to access OC server..."); - - mServerUri = context.getString(R.string.server_base_url); - mServerUri2 = context.getString(R.string.server_base_url_2); - mUser = context.getString(R.string.username); - mPass = context.getString(R.string.password); - - mClient = new OwnCloudClient( - Uri.parse(mServerUri), - NetworkUtils.getMultiThreadedConnManager() - ); - mClient.setDefaultTimeouts( - OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT, - OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT); - mClient.setFollowRedirects(true); - mClient.setCredentials( - OwnCloudCredentialsFactory.newBasicCredentials( - mUser, - mPass - ) - ); - - Log.v(LOG_TAG, "Client instance set up."); - - } - - -} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/GetSharesTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/GetSharesTest.java deleted file mode 100644 index 153fa8c595..0000000000 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/GetSharesTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2015 ownCloud Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package com.owncloud.android.lib.test_project.test; - -import java.io.File; - -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; -import com.owncloud.android.lib.resources.shares.ShareType; -import com.owncloud.android.lib.test_project.TestActivity; - -/** - * Class to test Get Shares Operation - * - * @author masensio - * - */ - -public class GetSharesTest extends RemoteTest { - - private static final String LOG_TAG = GetSharesTest.class.getCanonicalName(); - - private static final String SHARED_FILE = "/sharedFileToGet.txt"; - - private TestActivity mActivity; - private String mFullPath2SharedFile; - - @Override - protected void setUp() throws Exception { - super.setUp(); - setActivityInitialTouchMode(false); - mActivity = getActivity(); - mFullPath2SharedFile = mBaseFolderPath + SHARED_FILE; - - File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME); - RemoteOperationResult result = mActivity.uploadFile( - textFile.getAbsolutePath(), - mFullPath2SharedFile, - "txt/plain"); - if (!result.isSuccess()) { - Utils.logAndThrow(LOG_TAG, result); - } - - result = mActivity.createShare(mFullPath2SharedFile, ShareType.PUBLIC_LINK, "", false, "", 1); - if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) { - Utils.logAndThrow(LOG_TAG, result); - } - - } - - /** - * Test Get Shares: the server must support SHARE API - */ - public void testGetShares() { - RemoteOperationResult result = mActivity.getShares(); - assertTrue(result.isSuccess()); - assertTrue(result.getData() != null && result.getData().size() == 1); - } - - - @Override - protected void tearDown() throws Exception { - RemoteOperationResult removeResult = mActivity.removeFile(mFullPath2SharedFile); - if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) { - Utils.logAndThrow(LOG_TAG, removeResult); - } - super.tearDown(); - } - - -} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/MoveFileTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/MoveFileTest.java deleted file mode 100644 index e83f0478ca..0000000000 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/MoveFileTest.java +++ /dev/null @@ -1,457 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2015 ownCloud Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package com.owncloud.android.lib.test_project.test; - -import java.io.File; -import java.security.GeneralSecurityException; - -import junit.framework.AssertionFailedError; - -import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.protocol.Protocol; -import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; - -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.OwnCloudClientFactory; -import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; -import com.owncloud.android.lib.common.network.NetworkUtils; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; -import com.owncloud.android.lib.resources.files.MoveRemoteFileOperation; -import com.owncloud.android.lib.test_project.R; -import com.owncloud.android.lib.test_project.SelfSignedConfidentSslSocketFactory; -import com.owncloud.android.lib.test_project.TestActivity; - -import android.content.Context; -import android.net.Uri; -import android.util.Log; - -/** - * Class to test MoveRemoteFileOperation - * - * With this TestCase we are experimenting a bit to improve the test suite design, in two aspects: - * - * - Reduce the dependency from the set of test cases on the "test project" needed to - * have an instrumented APK to install in the device, as required by the testing framework - * provided by Android. To get there, this class avoids calling TestActivity methods in the test - * method. - * - * - Reduce the impact of creating a remote fixture over the Internet, while the structure of the - * TestCase is kept easy to maintain. To get this, all the tests are done in a single test method, - * granting this way that setUp and tearDown are run only once. - * - * - * @author David A. Velasco - */ - -//public class MoveFileTest extends AndroidTestCase { -public class MoveFileTest extends RemoteTest { - - private static final String LOG_TAG = MoveFileTest.class.getCanonicalName(); - - - /// Paths to files and folders in fixture - - private static final String SRC_BASE_FOLDER = "/src/"; - private static final String TARGET_BASE_FOLDER = "/target/"; - private static final String NO_FILE = "nofile.txt"; - private static final String FILE1 = "file1.txt"; - private static final String FILE2 = "file2.txt"; - private static final String FILE3 = "file3.txt"; - private static final String FILE4 = "file4.txt"; - private static final String FILE5 = "file5.txt"; - private static final String FILE6 = "file6.txt"; - private static final String FILE7 = "file7.txt"; - private static final String EMPTY = "empty/"; - private static final String NO_FOLDER = "nofolder/"; - private static final String FOLDER1 = "folder1/"; - private static final String FOLDER2 = "folder2/"; - private static final String FOLDER3 = "folder3/"; - private static final String FOLDER4 = "folder4/"; - - private static final String SRC_PATH_TO_FILE_1 = SRC_BASE_FOLDER + FILE1; - private static final String TARGET_PATH_TO_FILE_1 = TARGET_BASE_FOLDER + FILE1; - - private static final String SRC_PATH_TO_FILE_2 = SRC_BASE_FOLDER + FILE2; - private static final String TARGET_PATH_TO_FILE_2_RENAMED = - TARGET_BASE_FOLDER + "renamed_" + FILE2; - - private static final String SRC_PATH_TO_FILE_3 = SRC_BASE_FOLDER + FILE3; - private static final String SRC_PATH_TO_FILE_3_RENAMED = SRC_BASE_FOLDER + "renamed_" + FILE3; - - private static final String SRC_PATH_TO_FILE_4 = SRC_BASE_FOLDER + FILE4; - - private static final String SRC_PATH_TO_FILE_5 = SRC_BASE_FOLDER + FILE5; - - private static final String SRC_PATH_TO_FILE_6 = SRC_BASE_FOLDER + FILE6; - - private static final String SRC_PATH_TO_FILE_7 = SRC_BASE_FOLDER + FILE7; - - private static final String SRC_PATH_TO_NON_EXISTENT_FILE = SRC_BASE_FOLDER + NO_FILE; - - private static final String SRC_PATH_TO_EMPTY_FOLDER = SRC_BASE_FOLDER + EMPTY; - private static final String TARGET_PATH_TO_EMPTY_FOLDER = TARGET_BASE_FOLDER + EMPTY; - - private static final String SRC_PATH_TO_FULL_FOLDER_1 = SRC_BASE_FOLDER + FOLDER1; - private static final String TARGET_PATH_TO_FULL_FOLDER_1 = TARGET_BASE_FOLDER + FOLDER1; - - private static final String SRC_PATH_TO_FULL_FOLDER_2 = SRC_BASE_FOLDER + FOLDER2; - - private static final String TARGET_PATH_TO_FULL_FOLDER_2_RENAMED = - TARGET_BASE_FOLDER + "renamed_" + FOLDER2; - - private static final String SRC_PATH_TO_FULL_FOLDER_3 = SRC_BASE_FOLDER + FOLDER3; - private static final String SRC_PATH_TO_FULL_FOLDER_4 = SRC_BASE_FOLDER + FOLDER4; - - private static final String SRC_PATH_TO_FULL_FOLDER_3_RENAMED = - SRC_BASE_FOLDER + "renamed_" + FOLDER3; - - private static final String TARGET_PATH_RENAMED_WITH_INVALID_CHARS = - SRC_BASE_FOLDER + "renamed:??_" + FILE6; - - private static final String TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4 = TARGET_BASE_FOLDER - + FOLDER4; - - private static final String TARGET_PATH_TO_NON_EXISTENT_FILE = TARGET_BASE_FOLDER + NO_FILE; - - private static final String TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER = - TARGET_BASE_FOLDER + NO_FOLDER + FILE5; - - private static final String TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7 = TARGET_BASE_FOLDER + FILE7; - - private static final String[] FOLDERS_IN_FIXTURE = { - SRC_PATH_TO_EMPTY_FOLDER, - - SRC_PATH_TO_FULL_FOLDER_1, - SRC_PATH_TO_FULL_FOLDER_1 + FOLDER1, - SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2, - SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FOLDER1, - SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FOLDER2, - - SRC_PATH_TO_FULL_FOLDER_2, - SRC_PATH_TO_FULL_FOLDER_2 + FOLDER1, - SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2, - SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FOLDER1, - SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FOLDER2, - - SRC_PATH_TO_FULL_FOLDER_3, - SRC_PATH_TO_FULL_FOLDER_3 + FOLDER1, - SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2, - SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FOLDER1, - SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FOLDER2, - - SRC_PATH_TO_FULL_FOLDER_4, - SRC_PATH_TO_FULL_FOLDER_4 + FOLDER1, - SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2, - SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FOLDER1, - SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FOLDER2, - - TARGET_BASE_FOLDER, - TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4 - }; - - private static final String[] FILES_IN_FIXTURE = { - SRC_PATH_TO_FILE_1, - SRC_PATH_TO_FILE_2, - SRC_PATH_TO_FILE_3, - SRC_PATH_TO_FILE_4, - SRC_PATH_TO_FILE_5, - - SRC_PATH_TO_FULL_FOLDER_1 + FILE1, - SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FILE1, - SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FILE2, - SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FOLDER2 + FILE2, - - SRC_PATH_TO_FULL_FOLDER_2 + FILE1, - SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FILE1, - SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FILE2, - SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FOLDER2 + FILE2, - - SRC_PATH_TO_FULL_FOLDER_3 + FILE1, - SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FILE1, - SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FILE2, - SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FOLDER2 + FILE2, - - SRC_PATH_TO_FULL_FOLDER_4 + FILE1, - SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FILE1, - SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FILE2, - SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FOLDER2 + FILE2, - - TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7 - }; - - - String mServerUri, mUser, mPass; - OwnCloudClient mClient = null; - - public MoveFileTest() { - super(); - - Protocol pr = Protocol.getProtocol("https"); - if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) { - try { - ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory(); - Protocol.registerProtocol( - "https", - new Protocol("https", psf, 443)); - - } catch (GeneralSecurityException e) { - throw new AssertionFailedError( - "Self-signed confident SSL context could not be loaded"); - } - } - - } - - - protected Context getContext() { - return getActivity(); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - - // Next initialization cannot be done in the constructor because getContext() is not - // ready yet, returns NULL. - initAccessToServer(getContext()); - - Log.v(LOG_TAG, "Setting up the remote fixture..."); - - RemoteOperationResult result = null; - for (String folderPath : FOLDERS_IN_FIXTURE) { - result = TestActivity.createFolder(mBaseFolderPath + folderPath, true, mClient); - if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) { - Utils.logAndThrow(LOG_TAG, result); - } - } - - File txtFile = TestActivity.extractAsset( - TestActivity.ASSETS__TEXT_FILE_NAME, getContext() - ); - for (String filePath : FILES_IN_FIXTURE) { - result = TestActivity.uploadFile( - txtFile.getAbsolutePath(), mBaseFolderPath + filePath, "txt/plain", mClient - ); - if (!result.isSuccess()) { - Utils.logAndThrow(LOG_TAG, result); - } - } - - Log.v(LOG_TAG, "Remote fixture created."); - - } - - - /** - * Test move folder - */ - public void testMoveRemoteFileOperation() { - Log.v(LOG_TAG, "testMoveFolder in"); - - /// successful cases - - // move file - MoveRemoteFileOperation moveOperation = new MoveRemoteFileOperation( - mBaseFolderPath + SRC_PATH_TO_FILE_1, - mBaseFolderPath + TARGET_PATH_TO_FILE_1, - false - ); - RemoteOperationResult result = moveOperation.execute(mClient); - assertTrue(result.isSuccess()); - - // move & rename file, different location - moveOperation = new MoveRemoteFileOperation( - mBaseFolderPath + SRC_PATH_TO_FILE_2, - mBaseFolderPath + TARGET_PATH_TO_FILE_2_RENAMED, - false - ); - result = moveOperation.execute(mClient); - assertTrue(result.isSuccess()); - - // move & rename file, same location (rename file) - moveOperation = new MoveRemoteFileOperation( - mBaseFolderPath + SRC_PATH_TO_FILE_3, - mBaseFolderPath + SRC_PATH_TO_FILE_3_RENAMED, - false - ); - result = moveOperation.execute(mClient); - assertTrue(result.isSuccess()); - - // move empty folder - moveOperation = new MoveRemoteFileOperation( - mBaseFolderPath + SRC_PATH_TO_EMPTY_FOLDER, - mBaseFolderPath + TARGET_PATH_TO_EMPTY_FOLDER, - false - ); - result = moveOperation.execute(mClient); - assertTrue(result.isSuccess()); - - // move non-empty folder - moveOperation = new MoveRemoteFileOperation( - mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_1, - mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_1, - false - ); - result = moveOperation.execute(mClient); - assertTrue(result.isSuccess()); - - // move & rename folder, different location - moveOperation = new MoveRemoteFileOperation( - mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_2, - mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_2_RENAMED, - false - ); - result = moveOperation.execute(mClient); - assertTrue(result.isSuccess()); - - // move & rename folder, same location (rename folder) - moveOperation = new MoveRemoteFileOperation( - mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_3, - mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_3_RENAMED, - false - ); - result = moveOperation.execute(mClient); - assertTrue(result.isSuccess()); - - // move for nothing (success, but no interaction with network) - moveOperation = new MoveRemoteFileOperation( - mBaseFolderPath + SRC_PATH_TO_FILE_4, - mBaseFolderPath + SRC_PATH_TO_FILE_4, - false - ); - result = moveOperation.execute(mClient); - assertTrue(result.isSuccess()); - - // move overwriting - moveOperation = new MoveRemoteFileOperation( - mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_4, - mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4, - true - ); - result = moveOperation.execute(mClient); - assertTrue(result.isSuccess()); - - - /// Failed cases - - // file to move does not exist - moveOperation = new MoveRemoteFileOperation( - mBaseFolderPath + SRC_PATH_TO_NON_EXISTENT_FILE, - mBaseFolderPath + TARGET_PATH_TO_NON_EXISTENT_FILE, - false - ); - result = moveOperation.execute(mClient); - assertTrue(result.getCode() == ResultCode.FILE_NOT_FOUND); - - // folder to move into does no exist - moveOperation = new MoveRemoteFileOperation( - mBaseFolderPath + SRC_PATH_TO_FILE_5, - mBaseFolderPath + TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER, - false - ); - result = moveOperation.execute(mClient); - assertTrue(result.getHttpCode() == HttpStatus.SC_CONFLICT); - - // target location (renaming) has invalid characters - moveOperation = new MoveRemoteFileOperation( - mBaseFolderPath + SRC_PATH_TO_FILE_6, - mBaseFolderPath + TARGET_PATH_RENAMED_WITH_INVALID_CHARS, - false - ); - result = moveOperation.execute(mClient); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - // name collision - moveOperation = new MoveRemoteFileOperation( - mBaseFolderPath + SRC_PATH_TO_FILE_7, - mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7, - false - ); - result = moveOperation.execute(mClient); - assertTrue(result.getCode() == ResultCode.INVALID_OVERWRITE); - - // move a folder into a descendant - moveOperation = new MoveRemoteFileOperation( - mBaseFolderPath + SRC_BASE_FOLDER, - mBaseFolderPath + SRC_PATH_TO_EMPTY_FOLDER, - false - ); - result = moveOperation.execute(mClient); - assertTrue(result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT); - - } - - @Override - protected void tearDown() throws Exception { - Log.v(LOG_TAG, "Deleting remote fixture..."); - - String[] mPathsToCleanUp = { - mBaseFolderPath + SRC_BASE_FOLDER, - mBaseFolderPath + TARGET_BASE_FOLDER - }; - - for (String path : mPathsToCleanUp) { - RemoteOperationResult removeResult = - TestActivity.removeFile(path, mClient); - if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT ) { - Utils.logAndThrow(LOG_TAG, removeResult); - } - } - - super.tearDown(); - - Log.v(LOG_TAG, "Remote fixture delete."); - } - - - private void initAccessToServer(Context context) { - Log.v(LOG_TAG, "Setting up client instance to access OC server..."); - - mServerUri = context.getString(R.string.server_base_url); - mUser = context.getString(R.string.username); - mPass = context.getString(R.string.password); - - mClient = new OwnCloudClient( - Uri.parse(mServerUri), - NetworkUtils.getMultiThreadedConnManager() - ); - mClient.setDefaultTimeouts( - OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT, - OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT); - mClient.setFollowRedirects(true); - mClient.setCredentials( - OwnCloudCredentialsFactory.newBasicCredentials( - mUser, - mPass - ) - ); - - Log.v(LOG_TAG, "Client instance set up."); - - } - - -} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/OwnCloudClientManagerFactoryTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/OwnCloudClientManagerFactoryTest.java deleted file mode 100644 index 80d4ec8c8e..0000000000 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/OwnCloudClientManagerFactoryTest.java +++ /dev/null @@ -1,155 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2015 ownCloud Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ -package com.owncloud.android.lib.test_project.test; - -import com.owncloud.android.lib.common.OwnCloudClientManager; -import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; -import com.owncloud.android.lib.common.SingleSessionManager; -import com.owncloud.android.lib.common.OwnCloudClientManagerFactory.Policy; -import com.owncloud.android.lib.common.SimpleFactoryManager; - -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; - -/** - * Unit test for OwnCloudClientManagerFactory - * - * @author David A. Velasco - */ -public class OwnCloudClientManagerFactoryTest extends TestCase { - - @Override - protected void setUp() { - OwnCloudClientManagerFactory.setDefaultPolicy(Policy.ALWAYS_NEW_CLIENT); - } - - public void testGetDefaultPolicy() { - Policy defaultPolicy = OwnCloudClientManagerFactory.getDefaultPolicy(); - assertNotNull("Returned null value", defaultPolicy); - assertTrue("Returned unknown value", - (Policy.ALWAYS_NEW_CLIENT.equals(defaultPolicy) || - (Policy.SINGLE_SESSION_PER_ACCOUNT.equals(defaultPolicy)))); - } - - public void testSetDefaultPolicy() { - OwnCloudClientManagerFactory.setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT); - Policy defaultPolicy = OwnCloudClientManagerFactory.getDefaultPolicy(); - assertEquals("SINGLE_SESSION_PER_ACCOUNT not set", - Policy.SINGLE_SESSION_PER_ACCOUNT, defaultPolicy); - - OwnCloudClientManagerFactory.setDefaultPolicy(Policy.ALWAYS_NEW_CLIENT); - defaultPolicy = OwnCloudClientManagerFactory.getDefaultPolicy(); - assertEquals("ALWAYS_NEW_CLIENT not set", Policy.ALWAYS_NEW_CLIENT, defaultPolicy); - - try { - OwnCloudClientManagerFactory.setDefaultPolicy(null); - throw new AssertionFailedError("Accepted NULL parameter"); - - } catch(Exception e) { - assertTrue("Unexpected exception when setting default policy null", - (e instanceof IllegalArgumentException)); - } - defaultPolicy = OwnCloudClientManagerFactory.getDefaultPolicy(); - assertEquals("ALWAYS_NEW_CLIENT changed after setting null", - Policy.ALWAYS_NEW_CLIENT, defaultPolicy); - - } - - - public void testGetDefaultSingleton() { - OwnCloudClientManager mgr = OwnCloudClientManagerFactory.getDefaultSingleton(); - assertNotNull("Returned NULL default singleton", mgr); - assertTrue("Default singleton does not implement default policy", - mgr instanceof SimpleFactoryManager); - - OwnCloudClientManager mgr2 = OwnCloudClientManagerFactory.getDefaultSingleton(); - assertSame("Not singleton", mgr, mgr2); - - OwnCloudClientManagerFactory.setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT); - mgr = OwnCloudClientManagerFactory.getDefaultSingleton(); - assertNotNull("Returned NULL default singleton", mgr); - assertTrue("Default singleton does not implement default policy", - mgr instanceof SingleSessionManager); - - mgr2 = OwnCloudClientManagerFactory.getDefaultSingleton(); - assertSame("Not singleton", mgr, mgr2); - } - - - public void testNewDefaultOwnCloudClientManager() { - OwnCloudClientManager mgr = OwnCloudClientManagerFactory.newDefaultOwnCloudClientManager(); - assertNotNull("Returned NULL default manager", mgr); - assertTrue("New manager does not implement default policy", - mgr instanceof SimpleFactoryManager); - assertNotSame("Not new instance", - mgr, OwnCloudClientManagerFactory.getDefaultSingleton()); - assertNotSame("Not new instance", - mgr, OwnCloudClientManagerFactory.newDefaultOwnCloudClientManager()); - - OwnCloudClientManagerFactory.setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT); - mgr = OwnCloudClientManagerFactory.newDefaultOwnCloudClientManager(); - assertNotNull("Returned NULL default manager", mgr); - assertTrue("New manager does not implement default policy", - mgr instanceof SingleSessionManager); - assertNotSame("Not new instance", - mgr, OwnCloudClientManagerFactory.getDefaultSingleton()); - assertNotSame("Not new instance", - mgr, OwnCloudClientManagerFactory.newDefaultOwnCloudClientManager()); - - } - - - public void testNewOwnCloudClientManager() { - OwnCloudClientManager mgr = OwnCloudClientManagerFactory. - newOwnCloudClientManager(Policy.ALWAYS_NEW_CLIENT); - - assertNotNull("Returned NULL manager", mgr); - assertTrue("New manager does not implement policy ALWAYS_NEW_CLIENT", - mgr instanceof SimpleFactoryManager); - assertNotSame("Not new instance", - mgr, OwnCloudClientManagerFactory.getDefaultSingleton()); - assertNotSame("Not new instance", - mgr, OwnCloudClientManagerFactory.newDefaultOwnCloudClientManager()); - assertNotSame("Not new instance", - mgr, OwnCloudClientManagerFactory.newOwnCloudClientManager( - Policy.ALWAYS_NEW_CLIENT)); - - - OwnCloudClientManager mgr2 = OwnCloudClientManagerFactory. - newOwnCloudClientManager(Policy.SINGLE_SESSION_PER_ACCOUNT); - - assertNotNull("Returned NULL manager", mgr2); - assertTrue("New manager does not implement policy SINGLE_SESSION_PER_ACCOUNT", - mgr2 instanceof SingleSessionManager); - assertNotSame("Not new instance", - mgr2, OwnCloudClientManagerFactory.getDefaultSingleton()); - assertNotSame("Not new instance", - mgr2, OwnCloudClientManagerFactory.newDefaultOwnCloudClientManager()); - assertNotSame("Not new instance", - mgr2, OwnCloudClientManagerFactory.newOwnCloudClientManager( - Policy.SINGLE_SESSION_PER_ACCOUNT)); - } - - -} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/OwnCloudClientTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/OwnCloudClientTest.java deleted file mode 100644 index 0e8eca0a50..0000000000 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/OwnCloudClientTest.java +++ /dev/null @@ -1,377 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2015 ownCloud Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ -package com.owncloud.android.lib.test_project.test; - -import java.io.IOException; -import java.io.InputStream; -import java.net.SocketTimeoutException; -import java.security.GeneralSecurityException; -import org.apache.commons.httpclient.ConnectTimeoutException; -import org.apache.commons.httpclient.HttpException; -import org.apache.commons.httpclient.methods.HeadMethod; -import org.apache.commons.httpclient.protocol.Protocol; -import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; -import org.apache.commons.httpclient.HttpStatus; -import org.apache.jackrabbit.webdav.DavConstants; -import org.apache.jackrabbit.webdav.client.methods.PropFindMethod; - -import junit.framework.AssertionFailedError; - -import android.net.Uri; -import android.test.AndroidTestCase; -import android.util.Log; - -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.OwnCloudCredentials; -import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; -import com.owncloud.android.lib.common.accounts.AccountUtils; -import com.owncloud.android.lib.common.network.NetworkUtils; -import com.owncloud.android.lib.test_project.R; -import com.owncloud.android.lib.test_project.SelfSignedConfidentSslSocketFactory; - - -/** - * Unit test for OwnCloudClient - * - * @author David A. Velasco - */ -public class OwnCloudClientTest extends AndroidTestCase { - - private static final String TAG = OwnCloudClientTest.class.getSimpleName(); - - private Uri mServerUri; - private String mUsername; - private String mPassword; - - public OwnCloudClientTest() { - super(); - - Protocol pr = Protocol.getProtocol("https"); - if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) { - try { - ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory(); - Protocol.registerProtocol( - "https", - new Protocol("https", psf, 443)); - - } catch (GeneralSecurityException e) { - throw new AssertionFailedError( - "Self-signed confident SSL context could not be loaded"); - } - } - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - mServerUri = Uri.parse(getContext().getString(R.string.server_base_url)); - mUsername = getContext().getString(R.string.username); - mPassword = getContext().getString(R.string.password); - } - - - public void testConstructor() { - try { - new OwnCloudClient(null, NetworkUtils.getMultiThreadedConnManager()); - throw new AssertionFailedError("Accepted NULL parameter"); - - } catch(Exception e) { - assertTrue("Unexpected exception passing NULL baseUri", - (e instanceof IllegalArgumentException)); - } - - try { - new OwnCloudClient(mServerUri, null); - throw new AssertionFailedError("Accepted NULL parameter"); - - } catch(Exception e) { - assertTrue("Unexpected exception passing NULL connectionMgr", - (e instanceof IllegalArgumentException)); - } - - OwnCloudClient client = - new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); - assertNotNull("OwnCloudClient instance not built", client); - } - - - public void testGetSetCredentials() { - OwnCloudClient client = - new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); - - assertNotNull("Returned NULL credentials", client.getCredentials()); - assertEquals("Not instanced without credentials", - client.getCredentials(), OwnCloudCredentialsFactory.getAnonymousCredentials()); - - OwnCloudCredentials credentials = - OwnCloudCredentialsFactory.newBasicCredentials("user", "pass"); - client.setCredentials(credentials); - assertEquals("Basic credentials not set", credentials, client.getCredentials()); - - credentials = OwnCloudCredentialsFactory.newBearerCredentials("bearerToken"); - client.setCredentials(credentials); - assertEquals("Bearer credentials not set", credentials, client.getCredentials()); - - credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials("user", "samlSessionCookie=124"); - client.setCredentials(credentials); - assertEquals("SAML2 session credentials not set", credentials, client.getCredentials()); - - } - - public void testExecuteMethodWithTimeouts() throws HttpException, IOException { - OwnCloudClient client = - new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); - int connectionTimeout = client.getConnectionTimeout(); - int readTimeout = client.getDataTimeout(); - - HeadMethod head = new HeadMethod(client.getWebdavUri() + "/"); - try { - client.executeMethod(head, 1, 1000); - throw new AssertionFailedError("Completed HEAD with impossible read timeout"); - - } catch (Exception e) { - Log.e("OwnCloudClientTest", "EXCEPTION", e); - assertTrue("Unexcepted exception " + e.getLocalizedMessage(), - (e instanceof ConnectTimeoutException) || - (e instanceof SocketTimeoutException)); - - } finally { - head.releaseConnection(); - } - - assertEquals("Connection timeout was changed for future requests", - connectionTimeout, client.getConnectionTimeout()); - assertEquals("Read timeout was changed for future requests", - readTimeout, client.getDataTimeout()); - - try { - client.executeMethod(head, 1000, 1); - throw new AssertionFailedError("Completed HEAD with impossible connection timeout"); - - } catch (Exception e) { - Log.e("OwnCloudClientTest", "EXCEPTION", e); - assertTrue("Unexcepted exception " + e.getLocalizedMessage(), - (e instanceof ConnectTimeoutException) || - (e instanceof SocketTimeoutException)); - - } finally { - head.releaseConnection(); - } - - assertEquals("Connection timeout was changed for future requests", - connectionTimeout, client.getConnectionTimeout()); - assertEquals("Read timeout was changed for future requests", - readTimeout, client.getDataTimeout()); - - } - - - public void testExecuteMethod() { - OwnCloudClient client = - new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); - HeadMethod head = new HeadMethod(client.getWebdavUri() + "/"); - int status = -1; - try { - status = client.executeMethod(head); - assertTrue("Wrong status code returned: " + status, - status > 99 && status < 600); - - } catch (IOException e) { - Log.e(TAG, "Exception in HEAD method execution", e); - // TODO - make it fail? ; try several times, and make it fail if none - // is right? - - } finally { - head.releaseConnection(); - } - } - - - public void testExhaustResponse() { - OwnCloudClient client = - new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); - - PropFindMethod propfind = null; - try { - propfind = new PropFindMethod(client.getWebdavUri() + "/", - DavConstants.PROPFIND_ALL_PROP, - DavConstants.DEPTH_0); - client.executeMethod(propfind); - InputStream responseBody = propfind.getResponseBodyAsStream(); - if (responseBody != null) { - client.exhaustResponse(responseBody); - - try { - int character = responseBody.read(); - assertEquals("Response body was not fully exhausted", - character, -1); // -1 is acceptable - - } catch (IOException e) { - // this is the preferred result - } - - } else { - Log.e(TAG, "Could not test exhaustResponse due to wrong response"); - // TODO - make it fail? ; try several times, and make it fail if none - // is right? - } - - } catch (IOException e) { - Log.e(TAG, "Exception in PROPFIND method execution", e); - // TODO - make it fail? ; try several times, and make it fail if none - // is right? - - } finally { - propfind.releaseConnection(); - } - - client.exhaustResponse(null); // must run with no exception - } - - - public void testGetSetDefaultTimeouts() { - OwnCloudClient client = - new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); - - int oldDataTimeout = client.getDataTimeout(); - int oldConnectionTimeout = client.getConnectionTimeout(); - - client.setDefaultTimeouts(oldDataTimeout + 1000, oldConnectionTimeout + 1000); - assertEquals("Data timeout not set", - oldDataTimeout + 1000, client.getDataTimeout()); - assertEquals("Connection timeout not set", - oldConnectionTimeout + 1000, client.getConnectionTimeout()); - - client.setDefaultTimeouts(0, 0); - assertEquals("Zero data timeout not set", - 0, client.getDataTimeout()); - assertEquals("Zero connection timeout not set", - 0, client.getConnectionTimeout()); - - client.setDefaultTimeouts(-1, -1); - assertEquals("Negative data timeout not ignored", - 0, client.getDataTimeout()); - assertEquals("Negative connection timeout not ignored", - 0, client.getConnectionTimeout()); - - client.setDefaultTimeouts(-1, 1000); - assertEquals("Negative data timeout not ignored", - 0, client.getDataTimeout()); - assertEquals("Connection timeout not set", - 1000, client.getConnectionTimeout()); - - client.setDefaultTimeouts(1000, -1); - assertEquals("Data timeout not set", - 1000, client.getDataTimeout()); - assertEquals("Negative connection timeout not ignored", - 1000, client.getConnectionTimeout()); - - } - - - public void testGetWebdavUri() { - OwnCloudClient client = - new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); - client.setCredentials(OwnCloudCredentialsFactory.newBearerCredentials("fakeToken")); - Uri webdavUri = client.getWebdavUri(); - assertTrue("WebDAV URI does not point to the right entry point for OAuth2 " + - "authenticated servers", - webdavUri.getPath().endsWith(AccountUtils.ODAV_PATH)); - assertTrue("WebDAV URI is not a subpath of base URI", - webdavUri.getAuthority().equals(mServerUri.getAuthority()) && - webdavUri.getPath().startsWith(mServerUri.getPath())); - - client.setCredentials(OwnCloudCredentialsFactory.newBasicCredentials( - mUsername, mPassword)); - webdavUri = client.getWebdavUri(); - assertTrue("WebDAV URI does not point to the right entry point", - webdavUri.getPath().endsWith(AccountUtils.WEBDAV_PATH_4_0)); - PropFindMethod propfind = null; - try { - propfind = new PropFindMethod(webdavUri + "/", - DavConstants.PROPFIND_ALL_PROP, - DavConstants.DEPTH_0); - int status = client.executeMethod(propfind); - assertEquals("WebDAV request did not work on WebDAV URI", - HttpStatus.SC_MULTI_STATUS, status); - - } catch (IOException e) { - Log.e(TAG, "Exception in PROPFIND method execution", e); - // TODO - make it fail? ; try several times, and make it fail if none - // is right? - - } finally { - propfind.releaseConnection(); - } - - } - - - public void testGetSetBaseUri() { - OwnCloudClient client = - new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); - assertEquals("Returned base URI different that URI passed to constructor", - mServerUri, client.getBaseUri()); - - Uri otherUri = Uri.parse("https://whatever.com/basePath/here"); - client.setBaseUri(otherUri); - assertEquals("Returned base URI different that URI passed to constructor", - otherUri, client.getBaseUri()); - - try { - client.setBaseUri(null); - throw new AssertionFailedError("Accepted NULL parameter"); - - } catch(Exception e) { - assertTrue("Unexpected exception passing NULL base URI", - (e instanceof IllegalArgumentException)); - } - } - - - public void testGetCookiesString() { - // TODO implement test body - /*public String getCookiesString(){ - Cookie[] cookies = getState().getCookies(); - String cookiesString =""; - for (Cookie cookie: cookies) { - cookiesString = cookiesString + cookie.toString() + ";"; - - logCookie(cookie); - } - - return cookiesString; - - } - */ - } - - - public void testSetFollowRedirects() { - // TODO - to implement this test we need a redirected server - } - - -} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/ReadFileTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/ReadFileTest.java deleted file mode 100644 index 71871eac62..0000000000 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/ReadFileTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2015 ownCloud Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ -package com.owncloud.android.lib.test_project.test; - -import java.io.File; - -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; -import com.owncloud.android.lib.test_project.TestActivity; - -/** - * Class to test Read File Operation - * @author masensio - * @author David A. Velasco - */ - -public class ReadFileTest extends RemoteTest { - - private static final String LOG_TAG = ReadFileTest.class.getCanonicalName(); - - private TestActivity mActivity; - - private String FILE_PATH = "/fileToRead.txt"; - private String mFullPath2File; - - @Override - protected void setUp() throws Exception { - super.setUp(); - - setActivityInitialTouchMode(false); - mActivity = getActivity(); - mFullPath2File = mBaseFolderPath + FILE_PATH; - - File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME); - RemoteOperationResult uploadResult = mActivity.uploadFile( - textFile.getAbsolutePath(), - mFullPath2File, - "txt/plain"); - if (!uploadResult.isSuccess()) { - Utils.logAndThrow(LOG_TAG, uploadResult); - } - } - - /** - * Test Read File - */ - public void testReadFile() { - RemoteOperationResult result = mActivity.readFile(mFullPath2File); - assertTrue(result.getData() != null && result.getData().size() == 1); - assertTrue(result.isSuccess()); - // TODO check more properties of the result - } - - @Override - protected void tearDown() throws Exception { - RemoteOperationResult removeResult = mActivity.removeFile(mFullPath2File); - if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) { - Utils.logAndThrow(LOG_TAG, removeResult); - } - - super.tearDown(); - } - -} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/ReadFolderTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/ReadFolderTest.java deleted file mode 100644 index a05bccf6b8..0000000000 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/ReadFolderTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2015 ownCloud Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package com.owncloud.android.lib.test_project.test; - -import java.io.File; - -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; -import com.owncloud.android.lib.test_project.TestActivity; - -/** - * Class to test Read Folder Operation - * @author masensio - * @author David A. Velasco - */ - -public class ReadFolderTest extends RemoteTest { - - private static final String LOG_TAG = ReadFolderTest.class.getCanonicalName(); - - private static final String FOLDER_PATH = "/folderToRead"; - private static final String [] FILE_PATHS = { - FOLDER_PATH + "/file1.txt", - FOLDER_PATH + "/file2.txt", - FOLDER_PATH + "/file3.txt", - }; - - - private TestActivity mActivity; - private String mFullPathToFolder; - - @Override - protected void setUp() throws Exception { - super.setUp(); - setActivityInitialTouchMode(false); - mActivity = getActivity(); - mFullPathToFolder = mBaseFolderPath + FOLDER_PATH; - - File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME); - RemoteOperationResult result = mActivity.createFolder( mFullPathToFolder, true); - if (result.isSuccess()) { - for (int i=0; i 1); - assertTrue(result.getData().size() == 4); - // TODO assert more properties about the result - } - - - @Override - protected void tearDown() throws Exception { - RemoteOperationResult removeResult = mActivity.removeFile(mFullPathToFolder); - if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) { - Utils.logAndThrow(LOG_TAG, removeResult); - } - - super.tearDown(); - } - -} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/RemoteTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/RemoteTest.java deleted file mode 100644 index f0089663fa..0000000000 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/RemoteTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2015 ownCloud Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ -package com.owncloud.android.lib.test_project.test; - -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; -import com.owncloud.android.lib.test_project.TestActivity; - -import android.test.ActivityInstrumentationTestCase2; - -/** - * Class to test Create Folder Operation - * @author David A. Velasco - * - */ -public class RemoteTest extends ActivityInstrumentationTestCase2 { - - private static final String LOG_TAG = RemoteTest.class.getSimpleName(); - - protected String mBaseFolderPath = "/test_for_build_"; - - public RemoteTest() { - super(TestActivity.class); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - setActivityInitialTouchMode(false); - mBaseFolderPath += Utils.getBuildNumber(getActivity()); - - RemoteOperationResult result = getActivity().createFolder(mBaseFolderPath, true); - if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) { - Utils.logAndThrow(LOG_TAG, result); - } - } - - - @Override - protected void tearDown() throws Exception { - RemoteOperationResult removeResult = getActivity().removeFile(mBaseFolderPath); - if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) { - Utils.logAndThrow(LOG_TAG, removeResult); - } - super.tearDown(); - } - -} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/RemoveShareTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/RemoveShareTest.java deleted file mode 100644 index 646538616b..0000000000 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/RemoveShareTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2015 ownCloud Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package com.owncloud.android.lib.test_project.test; - -import java.io.File; - -import com.owncloud.android.lib.resources.shares.OCShare; -import com.owncloud.android.lib.resources.shares.ShareType; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; -import com.owncloud.android.lib.test_project.TestActivity; - -public class RemoveShareTest extends RemoteTest { - - private static final String LOG_TAG = RemoveShareTest.class.getCanonicalName(); - - private static final String FILE_TO_UNSHARE = "/fileToUnshare.txt"; - - private TestActivity mActivity; - - private String mFullPath2FileToUnshare; - - private long mShareId; - - @Override - protected void setUp() throws Exception { - super.setUp(); - setActivityInitialTouchMode(false); - mActivity = getActivity(); - mFullPath2FileToUnshare = mBaseFolderPath + FILE_TO_UNSHARE; - - File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME); - RemoteOperationResult result = mActivity.uploadFile( - textFile.getAbsolutePath(), - mFullPath2FileToUnshare, - "txt/plain"); - if (!result.isSuccess()) { - Utils.logAndThrow(LOG_TAG, result); - } - - result = mActivity.createShare(mFullPath2FileToUnshare, ShareType.PUBLIC_LINK, "", false, "", 1); - if (!result.isSuccess()) { - Utils.logAndThrow(LOG_TAG, result); - } else { - OCShare created = (OCShare) result.getData().get(0); - mShareId = created.getRemoteId(); - } - - } - - /** - * Test Remove Share: the server must support SHARE API - */ - public void testRemoveShare() { - RemoteOperationResult result = mActivity.removeShare((int) mShareId); - assertTrue(result.isSuccess()); - } - - - @Override - protected void tearDown() throws Exception { - RemoteOperationResult removeResult = mActivity.removeFile(mFullPath2FileToUnshare); - if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) { - Utils.logAndThrow(LOG_TAG, removeResult); - } - super.tearDown(); - } - -} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/RenameFileTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/RenameFileTest.java deleted file mode 100644 index d704facad4..0000000000 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/RenameFileTest.java +++ /dev/null @@ -1,232 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2015 ownCloud Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package com.owncloud.android.lib.test_project.test; - -import java.io.File; - -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; -import com.owncloud.android.lib.resources.files.FileUtils; -import com.owncloud.android.lib.test_project.TestActivity; - -/** - * Class to test Rename File Operation - * @author masensio - * - */ - -public class RenameFileTest extends RemoteTest { - - private static final String LOG_TAG = RenameFileTest.class.getCanonicalName(); - - /* Folder data to rename. This folder must exist on the account */ - private static final String OLD_FOLDER_NAME = "folderToRename"; - private static final String OLD_FOLDER_PATH = FileUtils.PATH_SEPARATOR + OLD_FOLDER_NAME; - private static final String NEW_FOLDER_NAME = "renamedFolder"; - private static final String NEW_FOLDER_PATH = FileUtils.PATH_SEPARATOR + NEW_FOLDER_NAME; - - /* File data to rename. This file must exist on the account */ - private static final String OLD_FILE_NAME = "fileToRename.png"; - private static final String OLD_FILE_PATH = FileUtils.PATH_SEPARATOR + OLD_FILE_NAME; - private static final String NEW_FILE_NAME = "renamedFile.png"; - private static final String NEW_FILE_PATH = FileUtils.PATH_SEPARATOR + NEW_FILE_NAME; - - - private String mToCleanUpInServer; - private TestActivity mActivity; - private String mFullPath2OldFolder; - private String mFullPath2NewFolder; - private String mFullPath2OldFile; - private String mFullPath2NewFile; - - @Override - protected void setUp() throws Exception { - super.setUp(); - setActivityInitialTouchMode(false); - mActivity = getActivity(); - mFullPath2OldFolder = mBaseFolderPath + OLD_FOLDER_PATH; - mFullPath2NewFolder = mBaseFolderPath + NEW_FOLDER_PATH; - mFullPath2OldFile = mBaseFolderPath + OLD_FILE_PATH; - mFullPath2NewFile = mBaseFolderPath + NEW_FILE_PATH; - - RemoteOperationResult result = mActivity.createFolder(mFullPath2OldFolder, true); - if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) { - Utils.logAndThrow(LOG_TAG, result); - } - - File imageFile = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME); - result = mActivity.uploadFile( - imageFile.getAbsolutePath(), - mFullPath2OldFile, - "image/png"); - if (!result.isSuccess()) { - Utils.logAndThrow(LOG_TAG, result); - } - - mToCleanUpInServer = null; - } - - /** - * Test Rename Folder - */ - public void testRenameFolder() { - - mToCleanUpInServer = mFullPath2OldFolder; - RemoteOperationResult result = mActivity.renameFile( - OLD_FOLDER_NAME, - mFullPath2OldFolder, - NEW_FOLDER_NAME, - true); - assertTrue(result.isSuccess()); - mToCleanUpInServer = mFullPath2NewFolder; - } - - /** - * Test Rename Folder with forbidden characters : \ < > : " | ? * - */ - public void testRenameFolderForbiddenChars() { - - RemoteOperationResult result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, - NEW_FOLDER_NAME + "\\", true); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, - NEW_FOLDER_NAME + "<", true); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, - NEW_FOLDER_NAME + ">", true); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, - NEW_FOLDER_NAME + ":", true); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, - NEW_FOLDER_NAME + "\"", true); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, - NEW_FOLDER_NAME + "|", true); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, - NEW_FOLDER_NAME + "?", true); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder, - NEW_FOLDER_NAME + "*", true); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - } - - /** - * Test Rename File - */ - public void testRenameFile() { - mToCleanUpInServer = mFullPath2OldFile; - RemoteOperationResult result = mActivity.renameFile( - OLD_FILE_NAME, - mFullPath2OldFile, - NEW_FILE_NAME, - false); - assertTrue(result.isSuccess()); - mToCleanUpInServer = mFullPath2NewFile; - } - - - /** - * Test Rename Folder with forbidden characters: \ < > : " | ? * - */ - public void testRenameFileForbiddenChars() { - RemoteOperationResult result = mActivity.renameFile( - OLD_FILE_NAME, - mFullPath2OldFile, - "\\" + NEW_FILE_NAME, - false); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - result = mActivity.renameFile( - OLD_FILE_NAME, - mFullPath2OldFile, - "<" + NEW_FILE_NAME, - false); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - result = mActivity.renameFile( - OLD_FILE_NAME, - mFullPath2OldFile, - ">" + NEW_FILE_NAME, - false); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - result = mActivity.renameFile( - OLD_FILE_NAME, - mFullPath2OldFile, - ":" + NEW_FILE_NAME, - false); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - result = mActivity.renameFile( - OLD_FILE_NAME, - mFullPath2OldFile, - "\"" + NEW_FILE_NAME, - false); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - result = mActivity.renameFile( - OLD_FILE_NAME, - mFullPath2OldFile, - "|" + NEW_FILE_NAME, - false); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - result = mActivity.renameFile( - OLD_FILE_NAME, - mFullPath2OldFile, - "?" + NEW_FILE_NAME, - false); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - result = mActivity.renameFile( - OLD_FILE_NAME, - mFullPath2OldFile, - "*" + NEW_FILE_NAME, false); - assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME); - - } - - - @Override - protected void tearDown() throws Exception { - if (mToCleanUpInServer != null) { - RemoteOperationResult removeResult = mActivity.removeFile(mToCleanUpInServer); - if (!removeResult.isSuccess()) { - Utils.logAndThrow(LOG_TAG, removeResult); - } - } - super.tearDown(); - } - -} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/SimpleFactoryManagerTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/SimpleFactoryManagerTest.java deleted file mode 100644 index 6122e9f3a6..0000000000 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/SimpleFactoryManagerTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2015 ownCloud Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ -package com.owncloud.android.lib.test_project.test; - -import java.security.GeneralSecurityException; - -import org.apache.commons.httpclient.protocol.Protocol; -import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; - -import android.net.Uri; -import android.test.AndroidTestCase; - -import com.owncloud.android.lib.common.OwnCloudAccount; -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; -import com.owncloud.android.lib.common.SimpleFactoryManager; -import com.owncloud.android.lib.test_project.R; -import com.owncloud.android.lib.test_project.SelfSignedConfidentSslSocketFactory; - -import junit.framework.AssertionFailedError; - -/** - * Unit test for SimpleFactoryManager - * - * @author David A. Velasco - */ - -public class SimpleFactoryManagerTest extends AndroidTestCase { - - private SimpleFactoryManager mSFMgr; - - private Uri mServerUri; - private String mUsername; - private OwnCloudAccount mValidAccount; - private OwnCloudAccount mAnonymousAccount; - - public SimpleFactoryManagerTest() { - super(); - - Protocol pr = Protocol.getProtocol("https"); - if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) { - try { - ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory(); - Protocol.registerProtocol( - "https", - new Protocol("https", psf, 443)); - - } catch (GeneralSecurityException e) { - throw new AssertionFailedError( - "Self-signed confident SSL context could not be loaded"); - } - } - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - mSFMgr = new SimpleFactoryManager(); - mServerUri = Uri.parse(getContext().getString(R.string.server_base_url)); - mUsername = getContext().getString(R.string.username); - - mValidAccount = new OwnCloudAccount( - mServerUri, OwnCloudCredentialsFactory.newBasicCredentials( - mUsername, - getContext().getString(R.string.password) - ) - ); - - mAnonymousAccount = new OwnCloudAccount( - mServerUri, OwnCloudCredentialsFactory.getAnonymousCredentials()); - - } - - public void testGetClientFor() { - try { - OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext()); - - assertNotSame("Got same client instances for same account", - client, mSFMgr.getClientFor(mValidAccount, getContext())); - - assertNotSame("Got same client instances for different accounts", - client, mSFMgr.getClientFor(mAnonymousAccount, getContext())); - - } catch (Exception e) { - throw new AssertionFailedError("Exception getting client for account: " + e.getMessage()); - } - // TODO harder tests - } - - public void testRemoveClientFor() { - try { - OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext()); - mSFMgr.removeClientFor(mValidAccount); - assertNotSame("Got same client instance after removing it from manager", - client, mSFMgr.getClientFor(mValidAccount, getContext())); - - } catch (Exception e) { - throw new AssertionFailedError("Exception getting client for account: " + e.getMessage()); - } - // TODO harder tests - } - - - public void testSaveAllClients() { - // TODO implement test; - // or refactor saveAllClients() method out of OwnCloudClientManager to make - // it independent of AccountManager - } - -} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/SingleSessionManagerTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/SingleSessionManagerTest.java deleted file mode 100644 index f565cc0eaf..0000000000 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/SingleSessionManagerTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2015 ownCloud Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ -package com.owncloud.android.lib.test_project.test; - -import java.security.GeneralSecurityException; - -import org.apache.commons.httpclient.protocol.Protocol; -import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; - -import android.net.Uri; -import android.test.AndroidTestCase; - -import com.owncloud.android.lib.common.OwnCloudAccount; -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; -import com.owncloud.android.lib.common.SingleSessionManager; -import com.owncloud.android.lib.test_project.R; -import com.owncloud.android.lib.test_project.SelfSignedConfidentSslSocketFactory; - -import junit.framework.AssertionFailedError; - -/** - * Unit test for SingleSessionManager - * - * @author David A. Velasco - */ -public class SingleSessionManagerTest extends AndroidTestCase { - - private SingleSessionManager mSSMgr; - - private Uri mServerUri; - private String mUsername; - private OwnCloudAccount mValidAccount; - private OwnCloudAccount mAnonymousAccount; - - public SingleSessionManagerTest() { - super(); - - Protocol pr = Protocol.getProtocol("https"); - if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) { - try { - ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory(); - Protocol.registerProtocol( - "https", - new Protocol("https", psf, 443)); - - } catch (GeneralSecurityException e) { - throw new AssertionFailedError( - "Self-signed confident SSL context could not be loaded"); - } - } - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - mSSMgr = new SingleSessionManager(); - mServerUri = Uri.parse(getContext().getString(R.string.server_base_url)); - mUsername = getContext().getString(R.string.username); - - mValidAccount = new OwnCloudAccount( - mServerUri, OwnCloudCredentialsFactory.newBasicCredentials( - mUsername, - getContext().getString(R.string.password) - ) - ); - - mAnonymousAccount = new OwnCloudAccount( - mServerUri, OwnCloudCredentialsFactory.getAnonymousCredentials()); - - } - - public void testGetClientFor() { - try { - OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext()); - OwnCloudClient client2 = mSSMgr.getClientFor(mAnonymousAccount, getContext()); - - assertNotSame("Got same client instances for different accounts", - client1, client2); - assertSame("Got different client instances for same account", - client1, mSSMgr.getClientFor(mValidAccount, getContext())); - - } catch (Exception e) { - throw new AssertionFailedError("Exception getting client for account: " + e.getMessage()); - } - - // TODO harder tests - } - - public void testRemoveClientFor() { - try { - OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext()); - mSSMgr.removeClientFor(mValidAccount); - assertNotSame("Got same client instance after removing it from manager", - client1, mSSMgr.getClientFor(mValidAccount, getContext())); - } catch (Exception e) { - throw new AssertionFailedError("Exception getting client for account: " + e.getMessage()); - } - - // TODO harder tests - } - - - public void testSaveAllClients() { - // TODO implement test; - // or refactor saveAllClients() method out of OwnCloudClientManager to make - // it independent of AccountManager - } - -} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/UpdatePrivateShareTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/UpdatePrivateShareTest.java deleted file mode 100644 index 128b064131..0000000000 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/UpdatePrivateShareTest.java +++ /dev/null @@ -1,258 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * @author masensio - * @author David A. Velasco - * Copyright (C) 2015 ownCloud Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package com.owncloud.android.lib.test_project.test; - -import java.io.File; -import java.security.GeneralSecurityException; - -import junit.framework.AssertionFailedError; - -import org.apache.commons.httpclient.protocol.Protocol; -import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; - -import android.content.Context; -import android.net.Uri; -import android.util.Log; - -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.OwnCloudClientFactory; -import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; -import com.owncloud.android.lib.common.network.NetworkUtils; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; -import com.owncloud.android.lib.resources.shares.OCShare; -import com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation; -import com.owncloud.android.lib.resources.shares.ShareType; -import com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation; -import com.owncloud.android.lib.test_project.R; -import com.owncloud.android.lib.test_project.SelfSignedConfidentSslSocketFactory; -import com.owncloud.android.lib.test_project.TestActivity; - -/** - * Class to test UpdateRemoteShareOperation - * with private shares - * - */ -public class UpdatePrivateShareTest extends RemoteTest { - private static final String LOG_TAG = UpdatePrivateShareTest.class.getCanonicalName(); - - /* File to share and update */ - private static final String FILE_TO_SHARE = "/fileToShare.txt"; - - /* Folder to share and update */ - private static final String FOLDER_TO_SHARE = "/folderToShare"; - - /* Sharees */ - private static final String USER_SHAREE = "admin"; - private static final String GROUP_SHAREE = "admin"; - - private String mFullPath2FileToShare; - private String mFullPath2FolderToShare; - - private OCShare mFileShare; - private OCShare mFolderShare; - - String mServerUri, mUser, mPass; - OwnCloudClient mClient = null; - - public UpdatePrivateShareTest(){ - super(); - - Protocol pr = Protocol.getProtocol("https"); - if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) { - try { - ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory(); - Protocol.registerProtocol( - "https", - new Protocol("https", psf, 443)); - - } catch (GeneralSecurityException e) { - throw new AssertionFailedError( - "Self-signed confident SSL context could not be loaded"); - } - } - } - - protected Context getContext() { - return getActivity(); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - - // Next initialization cannot be done in the constructor because getContext() is not - // ready yet, returns NULL. - initAccessToServer(getContext()); - - Log.v(LOG_TAG, "Setting up the remote fixture..."); - - // Upload the file - mFullPath2FileToShare = mBaseFolderPath + FILE_TO_SHARE; - - File textFile = getActivity().extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME); - RemoteOperationResult result = getActivity().uploadFile( - textFile.getAbsolutePath(), - mFullPath2FileToShare, - "txt/plain"); - if (!result.isSuccess()) { - Utils.logAndThrow(LOG_TAG, result); - } - - // Share the file privately with other user - result = getActivity().createShare( - mFullPath2FileToShare, - ShareType.USER, - USER_SHAREE, - false, - "", - OCShare.MAXIMUM_PERMISSIONS_FOR_FILE); - - if (result.isSuccess()){ - mFileShare = (OCShare) result.getData().get(0); - } else{ - mFileShare = null; - } - - // Create the folder - mFullPath2FolderToShare = mBaseFolderPath + FOLDER_TO_SHARE; - result = getActivity().createFolder( - mFullPath2FolderToShare, - true); - if (!result.isSuccess()) { - Utils.logAndThrow(LOG_TAG, result); - } - - // Share the folder privately with a group - result = getActivity().createShare( - mFullPath2FolderToShare, - ShareType.GROUP, - GROUP_SHAREE, - false, - "", - OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER); - - if (result.isSuccess()){ - mFolderShare = (OCShare) result.getData().get(0); - } else{ - mFolderShare = null; - } - - Log.v(LOG_TAG, "Remote fixture created."); - - } - - - public void testUpdateSharePermissions() { - Log.v(LOG_TAG, "testUpdateSharePermissions in"); - - if (mFileShare != null) { - /// successful tests - // Update Share permissions on a shared file - UpdateRemoteShareOperation updateShare = new UpdateRemoteShareOperation( - mFileShare.getRemoteId() - ); - updateShare.setPermissions(OCShare.READ_PERMISSION_FLAG); // minimum permissions - RemoteOperationResult result = updateShare.execute(mClient); - assertTrue(result.isSuccess()); - - // Update Share permissions on a shared folder - updateShare = new UpdateRemoteShareOperation(mFolderShare.getRemoteId()); - updateShare.setPermissions(OCShare.READ_PERMISSION_FLAG + OCShare.DELETE_PERMISSION_FLAG); - result = updateShare.execute(mClient); - assertTrue(result.isSuccess()); - - - /// unsuccessful tests - // Update Share with invalid permissions - updateShare = new UpdateRemoteShareOperation(mFileShare.getRemoteId()); - // greater than maximum value - updateShare.setPermissions(OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER + 1); - result = updateShare.execute(mClient); - assertFalse(result.isSuccess()); - - // Unshare the file before next unsuccessful tests - RemoveRemoteShareOperation unshare = new RemoveRemoteShareOperation( - (int) mFileShare.getRemoteId() - ); - result = unshare.execute(mClient); - - if (result.isSuccess()) { - // Update Share permissions on unknown share - UpdateRemoteShareOperation updateNoShare = new UpdateRemoteShareOperation( - mFileShare.getRemoteId() - ); - updateNoShare.setPermissions(OCShare.READ_PERMISSION_FLAG); // minimum permissions - result = updateNoShare.execute(mClient); - assertFalse(result.isSuccess()); - } - - } - - } - - @Override - protected void tearDown() throws Exception { - Log.v(LOG_TAG, "Deleting remote fixture..."); - if (mFullPath2FileToShare != null) { - RemoteOperationResult removeResult = getActivity().removeFile(mFullPath2FileToShare); - if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) { - Utils.logAndThrow(LOG_TAG, removeResult); - } - } - super.tearDown(); - Log.v(LOG_TAG, "Remote fixture delete."); - } - - - private void initAccessToServer(Context context) { - Log.v(LOG_TAG, "Setting up client instance to access OC server..."); - - mServerUri = context.getString(R.string.server_base_url); - mUser = context.getString(R.string.username); - mPass = context.getString(R.string.password); - - mClient = new OwnCloudClient( - Uri.parse(mServerUri), - NetworkUtils.getMultiThreadedConnManager() - ); - mClient.setDefaultTimeouts( - OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT, - OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT); - mClient.setFollowRedirects(true); - mClient.setCredentials( - OwnCloudCredentialsFactory.newBasicCredentials( - mUser, - mPass - ) - ); - - Log.v(LOG_TAG, "Client instance set up."); - - } - -} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/UpdatePublicShareTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/UpdatePublicShareTest.java deleted file mode 100644 index 21f474aec2..0000000000 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/UpdatePublicShareTest.java +++ /dev/null @@ -1,284 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * @author masensio - * @author David A. Velasco - * Copyright (C) 2015 ownCloud Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package com.owncloud.android.lib.test_project.test; - -import java.io.File; -import java.security.GeneralSecurityException; -import java.util.Calendar; - -import junit.framework.AssertionFailedError; - -import org.apache.commons.httpclient.protocol.Protocol; -import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; - -import android.content.Context; -import android.net.Uri; -import android.util.Log; - -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.OwnCloudClientFactory; -import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; -import com.owncloud.android.lib.common.network.NetworkUtils; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; -import com.owncloud.android.lib.resources.shares.OCShare; -import com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation; -import com.owncloud.android.lib.resources.shares.ShareType; -import com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation; -import com.owncloud.android.lib.test_project.R; -import com.owncloud.android.lib.test_project.SelfSignedConfidentSslSocketFactory; -import com.owncloud.android.lib.test_project.TestActivity; - -/** - * Class to test UpdateRemoteShareOperation - * with public shares - * - */ -public class UpdatePublicShareTest extends RemoteTest { - private static final String LOG_TAG = UpdatePublicShareTest.class.getCanonicalName(); - - /* File to share and update.*/ - private static final String FILE_TO_SHARE = "/fileToShare.txt"; - - /* Folder to share and update */ - private static final String FOLDER_TO_SHARE = "/folderToShare"; - - // Data for tests - private static final String PASSWORD = "password"; - private static final String PASS_SPECIAL_CHARS = "p@ssw�rd"; - - private String mFullPath2FileToShare; - private String mFullPath2FolderToShare; - - private OCShare mShare; - private OCShare mFolderShare; - - String mServerUri, mUser, mPass; - OwnCloudClient mClient = null; - - public UpdatePublicShareTest(){ - super(); - - Protocol pr = Protocol.getProtocol("https"); - if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) { - try { - ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory(); - Protocol.registerProtocol( - "https", - new Protocol("https", psf, 443)); - - } catch (GeneralSecurityException e) { - throw new AssertionFailedError( - "Self-signed confident SSL context could not be loaded"); - } - } - } - - protected Context getContext() { - return getActivity(); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - - // Next initialization cannot be done in the constructor because getContext() is not - // ready yet, returns NULL. - initAccessToServer(getContext()); - - Log.v(LOG_TAG, "Setting up the remote fixture..."); - - // Upload the file - mFullPath2FileToShare = mBaseFolderPath + FILE_TO_SHARE; - - File textFile = getActivity().extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME); - RemoteOperationResult result = getActivity().uploadFile( - textFile.getAbsolutePath(), - mFullPath2FileToShare, - "txt/plain"); - if (!result.isSuccess()) { - Utils.logAndThrow(LOG_TAG, result); - } - - // Share the file with a public link - result = getActivity().createShare( - mFullPath2FileToShare, - ShareType.PUBLIC_LINK, - "", - false, - "", - OCShare.READ_PERMISSION_FLAG); - - if (result.isSuccess()){ - mShare = (OCShare) result.getData().get(0); - } else{ - Utils.logAndThrow(LOG_TAG, result); - } - - // Create the folder - mFullPath2FolderToShare = mBaseFolderPath + FOLDER_TO_SHARE; - result = getActivity().createFolder( - mFullPath2FolderToShare, - true); - if (!result.isSuccess()) { - Utils.logAndThrow(LOG_TAG, result); - } - - // Share the folder publicly via link - result = getActivity().createShare( - mFullPath2FolderToShare, - ShareType.PUBLIC_LINK, - "", - false, - "", - OCShare.READ_PERMISSION_FLAG); - - if (result.isSuccess()){ - mFolderShare = (OCShare) result.getData().get(0); - } else{ - Utils.logAndThrow(LOG_TAG, result); - } - - Log.v(LOG_TAG, "Remote fixtures created."); - - } - - - public void testUpdatePublicShare() { - Log.v(LOG_TAG, "testUpdatePublicShare in"); - - if (mShare != null) { - // successful tests - // Update Share with password - UpdateRemoteShareOperation updateShare = new UpdateRemoteShareOperation(mShare.getRemoteId()); - updateShare.setPassword(PASSWORD); - RemoteOperationResult result = updateShare.execute(mClient); - assertTrue(result.isSuccess()); - - // Update Share with password with special characters - updateShare = new UpdateRemoteShareOperation(mShare.getRemoteId()); - updateShare.setPassword(PASS_SPECIAL_CHARS); - result = updateShare.execute(mClient); - assertTrue(result.isSuccess()); - - // Update Share with expiration date - updateShare = new UpdateRemoteShareOperation(mShare.getRemoteId()); - Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.DAY_OF_MONTH, 7); - long expirationDateInMillis = calendar.getTimeInMillis() ; - updateShare.setExpirationDate(expirationDateInMillis); - result = updateShare.execute(mClient); - assertTrue(result.isSuccess()); - - // Update the Folder Share with edit permission - updateShare = new UpdateRemoteShareOperation(mFolderShare.getRemoteId()); - updateShare.setPublicUpload(true); - result = updateShare.execute(mClient); - assertTrue(result.isSuccess()); - - // unsuccessful test - // Update Share with expiration date in the past - updateShare = new UpdateRemoteShareOperation(mShare.getRemoteId()); - calendar.set(Calendar.YEAR, 2014); - expirationDateInMillis = calendar.getTimeInMillis() ; - updateShare.setExpirationDate(expirationDateInMillis); - result = updateShare.execute(mClient); - assertFalse(result.isSuccess()); - - // Try to update the file Share with edit permission - updateShare = new UpdateRemoteShareOperation(mShare.getRemoteId()); - updateShare.setPublicUpload(true); - result = updateShare.execute(mClient); - assertFalse(result.isSuccess()); - - // Unshare the file before the unsuccessful tests - RemoveRemoteShareOperation unshare = new RemoveRemoteShareOperation((int) mShare.getRemoteId()); - result = unshare.execute(mClient); - - if (result.isSuccess()) { - // Update Share with password on unknown share - UpdateRemoteShareOperation updateNoShare = new UpdateRemoteShareOperation(mShare.getRemoteId()); - updateNoShare.setPassword(PASSWORD); - result = updateNoShare.execute(mClient); - assertFalse(result.isSuccess()); - - // Update Share with expiration date on unknown share - updateNoShare = new UpdateRemoteShareOperation(mShare.getRemoteId()); - Calendar cal = Calendar.getInstance(); - cal.add(Calendar.DAY_OF_MONTH, 7); - expirationDateInMillis = cal.getTimeInMillis() ; - updateNoShare.setExpirationDate(expirationDateInMillis); - result = updateNoShare.execute(mClient); - assertFalse(result.isSuccess()); - - } - - } - - } - - @Override - protected void tearDown() throws Exception { - Log.v(LOG_TAG, "Deleting remote fixture..."); - if (mFullPath2FileToShare != null) { - RemoteOperationResult removeResult = getActivity().removeFile(mFullPath2FileToShare); - if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) { - Utils.logAndThrow(LOG_TAG, removeResult); - } - } - super.tearDown(); - Log.v(LOG_TAG, "Remote fixture delete."); - } - - - private void initAccessToServer(Context context) { - Log.v(LOG_TAG, "Setting up client instance to access OC server..."); - - mServerUri = context.getString(R.string.server_base_url); - mUser = context.getString(R.string.username); - mPass = context.getString(R.string.password); - - mClient = new OwnCloudClient( - Uri.parse(mServerUri), - NetworkUtils.getMultiThreadedConnManager() - ); - mClient.setDefaultTimeouts( - OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT, - OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT); - mClient.setFollowRedirects(true); - mClient.setCredentials( - OwnCloudCredentialsFactory.newBasicCredentials( - mUser, - mPass - ) - ); - - Log.v(LOG_TAG, "Client instance set up."); - - } - -} diff --git a/test_client/tests/src/com/owncloud/android/lib/test_project/test/UploadFileTest.java b/test_client/tests/src/com/owncloud/android/lib/test_project/test/UploadFileTest.java deleted file mode 100644 index 4d524d4e5e..0000000000 --- a/test_client/tests/src/com/owncloud/android/lib/test_project/test/UploadFileTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2015 ownCloud Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package com.owncloud.android.lib.test_project.test; - -import java.io.File; - -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; -import com.owncloud.android.lib.test_project.TestActivity; - -/** - * Class to test Update File Operation - * @author masensio - * @author David A. Velasco - * - */ - -public class UploadFileTest extends RemoteTest { - - private static final String LOG_TAG = UploadFileTest.class.getCanonicalName(); - - private static final String UPLOAD_PATH = "/uploadedImage.png"; - - private static final String CHUNKED_UPLOAD_PATH = "/uploadedVideo.MP4"; - - private static final String FILE_NOT_FOUND_PATH = "/notFoundShouldNotBeHere.png"; - - - private TestActivity mActivity; - private File mFileToUpload, mFileToUploadWithChunks; - private String mUploadedFilePath; - - - @Override - protected void setUp() throws Exception { - super.setUp(); - setActivityInitialTouchMode(false); - mActivity = getActivity(); - mUploadedFilePath = null; - - mFileToUpload = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME); - mFileToUploadWithChunks = mActivity.extractAsset(TestActivity.ASSETS__VIDEO_FILE_NAME); - } - - - /** - * Test Upload File without chunks - */ - public void testUploadFile() { - - String fullPath2Upload = mBaseFolderPath + UPLOAD_PATH; - RemoteOperationResult result = mActivity.uploadFile( - mFileToUpload.getAbsolutePath(), - fullPath2Upload, - "image/png" - ); - mUploadedFilePath = fullPath2Upload; - assertTrue(result.isSuccess()); - } - - /** - * Test Upload File with chunks - */ - public void testUploadFileWithChunks() { - - String fullPath2Upload = mBaseFolderPath + CHUNKED_UPLOAD_PATH; - RemoteOperationResult result = mActivity.uploadFile( - mFileToUploadWithChunks.getAbsolutePath(), - fullPath2Upload, - "video/mp4" - ); - mUploadedFilePath = fullPath2Upload; - assertTrue(result.isSuccess()); - } - - /** - * Test Upload Not Found File - */ - public void testUploadFileNotFound() { - - String fullPath2Upload = mBaseFolderPath + FILE_NOT_FOUND_PATH; - RemoteOperationResult result = mActivity.uploadFile( - FILE_NOT_FOUND_PATH, - fullPath2Upload, - "image/png" - ); - mUploadedFilePath = fullPath2Upload; - assertFalse(result.isSuccess()); - } - - - @Override - protected void tearDown() throws Exception { - if (mUploadedFilePath != null) { - RemoteOperationResult removeResult = mActivity.removeFile(mUploadedFilePath); - if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) { - Utils.logAndThrow(LOG_TAG, removeResult); - } - } - super.tearDown(); - } - -}