diff --git a/test_client/src/com/owncloud/android/lib/test_project/TestActivity.java b/test_client/src/com/owncloud/android/lib/test_project/TestActivity.java index 896ea0f5..44d19ef4 100644 --- a/test_client/src/com/owncloud/android/lib/test_project/TestActivity.java +++ b/test_client/src/com/owncloud/android/lib/test_project/TestActivity.java @@ -28,7 +28,6 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.security.GeneralSecurityException; import org.apache.commons.httpclient.protocol.Protocol; @@ -56,7 +55,6 @@ import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.app.Activity; -import android.content.res.AssetManager; import android.util.Log; import android.view.Menu; @@ -78,6 +76,8 @@ public class TestActivity extends Activity { private static final String WEBDAV_PATH = "/remote.php/webdav"; private static final int BUFFER_SIZE = 1024; + public static final String ASSETS__TEXT_FILE_NAME = "textFile.txt"; + //private Account mAccount = null; private OwnCloudClient mClient; 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 index 686f30cc..c2bca6e7 100644 --- 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 @@ -30,7 +30,6 @@ import com.owncloud.android.lib.resources.files.FileUtils; import com.owncloud.android.lib.test_project.TestActivity; import android.test.ActivityInstrumentationTestCase2; -import android.util.Log; /** * Class to test Read File Operation @@ -42,10 +41,10 @@ public class ReadFileTest extends ActivityInstrumentationTestCase2 { + private static final String LOG_TAG = ReadFolderTest.class.getCanonicalName(); + + private static final String FOLDER_PATH = "/folderToRead"; + private static final String FILE1_NAME = "file1.txt"; + private static final String FILE2_NAME = "file2.txt"; + private static final String FILE3_NAME = "file3.txt"; - /* Folder data to read. This folder must exist on the account */ - private final String mRemoteFolderPath = "/folderToRead"; - private TestActivity mActivity; public ReadFolderTest() { - super(TestActivity.class); + super(TestActivity.class); } @Override - protected void setUp() throws Exception { - super.setUp(); - setActivityInitialTouchMode(false); - mActivity = getActivity(); + protected void setUp() throws Exception { + super.setUp(); + setActivityInitialTouchMode(false); + mActivity = getActivity(); + + File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME); + RemoteOperationResult result = mActivity.createFolder(FOLDER_PATH, true); + if (result.isSuccess()) { + String [] filePaths = { + FOLDER_PATH + FileUtils.PATH_SEPARATOR + FILE1_NAME, + FOLDER_PATH + FileUtils.PATH_SEPARATOR + FILE2_NAME, + FOLDER_PATH + FileUtils.PATH_SEPARATOR + FILE3_NAME + }; + + for (int i=0; i 1); - assertTrue(result.getData().size() == 4); + RemoteOperationResult result = mActivity.readFile(FOLDER_PATH); 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(FOLDER_PATH); + 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/tests/src/com/owncloud/android/lib/test_project/test/Utils.java new file mode 100644 index 00000000..9ce9c2c8 --- /dev/null +++ b/test_client/tests/src/com/owncloud/android/lib/test_project/test/Utils.java @@ -0,0 +1,38 @@ +/* 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, + * 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 android.util.Log; + +import com.owncloud.android.lib.common.operations.RemoteOperationResult; + +public class Utils { + + public static void logAndThrow(String tag, RemoteOperationResult result) throws Exception { + Log.e(tag, result.getLogMessage(), result.getException()); + throw new Exception(result.getLogMessage(), result.getException()); + } + +}