1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-07 16:06:08 +00:00

Merge branch 'develop' of github.com:owncloud/android-library into buildsystem/gradle_develop

Conflicts:
	.travis.yml
This commit is contained in:
Marcello Steiner 2014-11-21 12:44:23 +01:00 committed by MMMarcy
commit ef768b7d1b
25 changed files with 468 additions and 337 deletions

View File

@ -1,17 +1,23 @@
language: android
android:
components:
- platform-tools
- tools
- build-tools-20.0.0
- android-19
- android-17
- android-14
- extra-android-support
licenses:
- 'android-sdk-license-5be876d5'
- 'android-sdk-license-598b93a6'
jdk: oraclejdk7
before_install:
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI -c 20M
- emulator -avd test -no-skin -no-audio -no-window &
- rm pom.xml
- android update project -p .
- chmod +x ./wait_for_emulator.sh
- ./wait_for_emulator.sh
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI -c 20M
- emulator -avd test -no-skin -no-audio -no-window &
- rm pom.xml
- android update project -p .
before_script:
- chmod +x ./wait_for_emulator.sh
- ./wait_for_emulator.sh
script:
- ant clean
- ant debug
@ -25,4 +31,4 @@ env:
- secure: aF4U20Xlu/rfrbxCmoJAiGh1doYTAZ10UEDmajuinT+ZGSJLivuqD7DDY/00sI6IXWg+J1vL+7jJm4JSYusHPg38UHZ4q92k6RmZycW2ATUzZnGT54O5FRnY67MfVwgVpIMK9UOL/6NEciBHEjlIOL0wbKQiJB++1YtBZOQLGL4=
- secure: N+ECSwNg8v2GsAFJ2y/tCiffauHDpN76zuFI2pDqf0fjmCtJZHu4BH5ArXBHjyHKmgn20a/8eZXcwJaH1HsJ80bo7vDJ2miShjGIQ90hPcdmUiB2XVJcew4f04CtvMDH5o7DRt4ykWArlbPL2rhVag0jotlSidolHBwRFnbDhDY
matrix:
- ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a
- ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a

View File

@ -13,7 +13,7 @@
<owncloud.version>1.5.1-SNAPSHOT</owncloud.version>
<java-version>1.6</java-version>
<!-- Given by maven-android-sdk-deployer -->
<google.android-version>4.4.2_r3</google.android-version>
<google.android-version>4.4.2_r4</google.android-version>
<!-- Usually the latest Android API -->
<google.android-api>19</google.android-api>
</properties>

View File

@ -30,6 +30,7 @@ import java.io.InputStream;
import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpConnectionManager;
import org.apache.commons.httpclient.HttpException;
@ -92,11 +93,33 @@ public class OwnCloudClient extends HttpClient {
PARAM_SINGLE_COOKIE_HEADER, // to avoid problems with some web servers
PARAM_SINGLE_COOKIE_HEADER_VALUE);
applyProxySettings();
clearCredentials();
}
public void setCredentials(OwnCloudCredentials credentials) {
private void applyProxySettings() {
String proxyHost = System.getProperty("http.proxyHost");
String proxyPortSt = System.getProperty("http.proxyPort");
int proxyPort = 0;
try {
if (proxyPortSt != null && proxyPortSt.length() > 0) {
proxyPort = Integer.parseInt(proxyPortSt);
}
} catch (Exception e) {
// nothing to do here
}
if (proxyHost != null && proxyHost.length() > 0) {
HostConfiguration hostCfg = getHostConfiguration();
hostCfg.setProxy(proxyHost, proxyPort);
Log_OC.d(TAG, "Proxy settings: " + proxyHost + ":" + proxyPort);
}
}
public void setCredentials(OwnCloudCredentials credentials) {
if (credentials != null) {
mCredentials = credentials;
mCredentials.applyTo(this);

View File

@ -36,6 +36,7 @@ import javax.net.SocketFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
@ -43,6 +44,7 @@ import javax.net.ssl.SSLSocket;
import org.apache.commons.httpclient.ConnectTimeoutException;
import org.apache.commons.httpclient.params.HttpConnectionParams;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
import org.apache.http.conn.ssl.X509HostnameVerifier;
import com.owncloud.android.lib.common.utils.Log_OC;
@ -56,7 +58,7 @@ import com.owncloud.android.lib.common.utils.Log_OC;
* @author David A. Velasco
*/
public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory {
private static final String TAG = AdvancedSslSocketFactory.class.getSimpleName();
@ -71,11 +73,17 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
/**
* Constructor for AdvancedSSLProtocolSocketFactory.
*/
public AdvancedSslSocketFactory(SSLContext sslContext, AdvancedX509TrustManager trustManager, X509HostnameVerifier hostnameVerifier) {
public AdvancedSslSocketFactory(
SSLContext sslContext, AdvancedX509TrustManager trustManager, X509HostnameVerifier hostnameVerifier
) {
if (sslContext == null)
throw new IllegalArgumentException("AdvancedSslSocketFactory can not be created with a null SSLContext");
if (trustManager == null)
throw new IllegalArgumentException("AdvancedSslSocketFactory can not be created with a null Trust Manager");
if (trustManager == null && mHostnameVerifier != null)
throw new IllegalArgumentException(
"AdvancedSslSocketFactory can not be created with a null Trust Manager and a " +
"not null Hostname Verifier"
);
mSslContext = sslContext;
mTrustManager = trustManager;
mHostnameVerifier = hostnameVerifier;
@ -84,8 +92,11 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
/**
* @see ProtocolSocketFactory#createSocket(java.lang.String,int,java.net.InetAddress,int)
*/
public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort) throws IOException, UnknownHostException {
public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort)
throws IOException, UnknownHostException {
Socket socket = mSslContext.getSocketFactory().createSocket(host, port, clientHost, clientPort);
enableSecureProtocols(socket);
verifyPeerIdentity(host, port, socket);
return socket;
}
@ -150,7 +161,8 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
final InetAddress localAddress, final int localPort,
final HttpConnectionParams params) throws IOException,
UnknownHostException, ConnectTimeoutException {
Log_OC.d(TAG, "Creating SSL Socket with remote " + host + ":" + port + ", local " + localAddress + ":" + localPort + ", params: " + params);
Log_OC.d(TAG, "Creating SSL Socket with remote " + host + ":" + port + ", local " + localAddress + ":" +
localPort + ", params: " + params);
if (params == null) {
throw new IllegalArgumentException("Parameters may not be null");
}
@ -161,6 +173,7 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
SocketFactory socketfactory = mSslContext.getSocketFactory();
Log_OC.d(TAG, " ... with connection timeout " + timeout + " and socket timeout " + params.getSoTimeout());
Socket socket = socketfactory.createSocket();
enableSecureProtocols(socket);
SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
SocketAddress remoteaddr = new InetSocketAddress(host, port);
socket.setSoTimeout(params.getSoTimeout());
@ -178,10 +191,22 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
UnknownHostException {
Log_OC.d(TAG, "Creating SSL Socket with remote " + host + ":" + port);
Socket socket = mSslContext.getSocketFactory().createSocket(host, port);
enableSecureProtocols(socket);
verifyPeerIdentity(host, port, socket);
return socket;
}
@Override
public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException,
UnknownHostException {
Socket sslSocket = mSslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
enableSecureProtocols(sslSocket);
verifyPeerIdentity(host, port, sslSocket);
return sslSocket;
}
public boolean equals(Object obj) {
return ((obj != null) && obj.getClass().equals(
AdvancedSslSocketFactory.class));
@ -206,13 +231,15 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
*
* The server certificate is verified first.
*
* Then, the host name is compared with the content of the server certificate using the current host name verifier, if any.
* Then, the host name is compared with the content of the server certificate using the current host name verifier,
* if any.
* @param socket
*/
private void verifyPeerIdentity(String host, int port, Socket socket) throws IOException {
try {
CertificateCombinedException failInHandshake = null;
/// 1. VERIFY THE SERVER CERTIFICATE through the registered TrustManager (that should be an instance of AdvancedX509TrustManager)
/// 1. VERIFY THE SERVER CERTIFICATE through the registered TrustManager
/// (that should be an instance of AdvancedX509TrustManager)
try {
SSLSocket sock = (SSLSocket) socket; // a new SSLSession instance is created as a "side effect"
sock.startHandshake();
@ -224,7 +251,9 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
} else {
Throwable cause = e.getCause();
Throwable previousCause = null;
while (cause != null && cause != previousCause && !(cause instanceof CertificateCombinedException)) {
while ( cause != null &&
cause != previousCause &&
!(cause instanceof CertificateCombinedException)) {
previousCause = cause;
cause = cause.getCause();
}
@ -263,9 +292,13 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
/// 3. Combine the exceptions to throw, if any
if (!verifiedHostname) {
SSLPeerUnverifiedException pue = new SSLPeerUnverifiedException("Names in the server certificate do not match to " + host + " in the URL");
SSLPeerUnverifiedException pue = new SSLPeerUnverifiedException(
"Names in the server certificate do not match to " + host + " in the URL"
);
if (failInHandshake == null) {
failInHandshake = new CertificateCombinedException((X509Certificate) newSession.getPeerCertificates()[0]);
failInHandshake = new CertificateCombinedException(
(X509Certificate) newSession.getPeerCertificates()[0]
);
failInHandshake.setHostInUrl(host);
}
failInHandshake.setSslPeerUnverifiedException(pue);
@ -287,5 +320,23 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
throw io;
}
}
/**
* Grants that all protocols supported by the Security Provider in mSslContext are enabled in socket.
*
* Grants also that no unsupported protocol is tried to be enabled. That would trigger an exception, breaking
* the connection process although some protocols are supported.
*
* This is not cosmetic: not all the supported protocols are enabled by default. Too see an overview of
* supported and enabled protocols in the stock Security Provider in Android see the tables in
* http://developer.android.com/reference/javax/net/ssl/SSLSocket.html.
*
* @param socket
*/
private void enableSecureProtocols(Socket socket) {
SSLParameters params = mSslContext.getSupportedSSLParameters();
String [] supportedProtocols = params.getProtocols();
((SSLSocket) socket).setEnabledProtocols(supportedProtocols);
}
}

View File

@ -57,6 +57,12 @@ public class NetworkUtils {
/** Default timeout for establishing a connection */
public static final int DEFAULT_CONNECTION_TIMEOUT = 60000;
/** Standard name for protocol TLS version 1.2 in Java Secure Socket Extension (JSSE) API */
public static final String PROTOCOL_TLSv1_2 = "TLSv1.2";
/** Standard name for protocol TLS version 1.0 in JSSE API */
public static final String PROTOCOL_TLSv1_0 = "TLSv1";
/** Connection manager for all the OwnCloudClients */
private static MultiThreadedHttpConnectionManager mConnManager = null;
@ -72,7 +78,9 @@ public class NetworkUtils {
* Registers or unregisters the proper components for advanced SSL handling.
* @throws IOException
*/
public static void registerAdvancedSslContext(boolean register, Context context) throws GeneralSecurityException, IOException {
@SuppressWarnings("deprecation")
public static void registerAdvancedSslContext(boolean register, Context context)
throws GeneralSecurityException, IOException {
Protocol pr = null;
try {
pr = Protocol.getProtocol("https");
@ -93,13 +101,22 @@ public class NetworkUtils {
}
}
public static AdvancedSslSocketFactory getAdvancedSslSocketFactory(Context context) throws GeneralSecurityException, IOException {
public static AdvancedSslSocketFactory getAdvancedSslSocketFactory(Context context)
throws GeneralSecurityException, IOException {
if (mAdvancedSslSocketFactory == null) {
KeyStore trustStore = getKnownServersStore(context);
AdvancedX509TrustManager trustMgr = new AdvancedX509TrustManager(trustStore);
TrustManager[] tms = new TrustManager[] { trustMgr };
SSLContext sslContext = SSLContext.getInstance("TLS");
SSLContext sslContext;
try {
sslContext = SSLContext.getInstance("TLSv1.2");
} catch (NoSuchAlgorithmException e) {
Log_OC.w(TAG, "TLSv1.2 is not supported in this device; falling through TLSv1.0");
sslContext = SSLContext.getInstance("TLSv1");
// should be available in any device; see reference of supported protocols in
// http://developer.android.com/reference/javax/net/ssl/SSLSocket.html
}
sslContext.init(null, tms, null);
mHostnameVerifier = new BrowserCompatHostnameVerifier();
@ -127,9 +144,11 @@ public class NetworkUtils {
* @throws KeyStoreException When the KeyStore instance could not be created.
* @throws IOException When an existing local trust store could not be loaded.
* @throws NoSuchAlgorithmException When the existing local trust store was saved with an unsupported algorithm.
* @throws CertificateException When an exception occurred while loading the certificates from the local trust store.
* @throws CertificateException When an exception occurred while loading the certificates from the local
* trust store.
*/
private static KeyStore getKnownServersStore(Context context) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException {
private static KeyStore getKnownServersStore(Context context)
throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException {
if (mKnownServersStore == null) {
//mKnownServersStore = KeyStore.getInstance("BKS");
mKnownServersStore = KeyStore.getInstance(KeyStore.getDefaultType());
@ -143,15 +162,17 @@ public class NetworkUtils {
in.close();
}
} else {
mKnownServersStore.load(null, LOCAL_TRUSTSTORE_PASSWORD.toCharArray()); // necessary to initialize an empty KeyStore instance
// next is necessary to initialize an empty KeyStore instance
mKnownServersStore.load(null, LOCAL_TRUSTSTORE_PASSWORD.toCharArray());
}
}
return mKnownServersStore;
}
public static void addCertToKnownServersStore(Certificate cert, Context context) throws KeyStoreException, NoSuchAlgorithmException,
CertificateException, IOException {
public static void addCertToKnownServersStore(Certificate cert, Context context)
throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
KeyStore knownServers = getKnownServersStore(context);
knownServers.setCertificateEntry(Integer.toString(cert.hashCode()), cert);
FileOutputStream fos = null;
@ -173,7 +194,8 @@ public class NetworkUtils {
return mConnManager;
}
public static boolean isCertInKnownServersStore(Certificate cert, Context context) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
public static boolean isCertInKnownServersStore(Certificate cert, Context context)
throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
KeyStore knownServers = getKnownServersStore(context);
Log_OC.d(TAG, "Certificate - HashCode: " + cert.hashCode() + " "

View File

@ -175,5 +175,4 @@ public class Log_OC {
public static String[] getLogFileNames() {
return mLogFileNames;
}
}

View File

@ -48,7 +48,7 @@ import com.owncloud.android.lib.common.utils.Log_OC;
public class ReadRemoteFileOperation extends RemoteOperation {
private static final String TAG = ReadRemoteFileOperation.class.getSimpleName();
private static final int SYNC_READ_TIMEOUT = 10000;
private static final int SYNC_READ_TIMEOUT = 40000;
private static final int SYNC_CONNECTION_TIMEOUT = 5000;
private String mRemotePath;

View File

@ -43,5 +43,19 @@
byline="true" />
</then>
</if>
<!-- Make Travis build number available to the test app in the emulator -->
<if>
<condition>
<isset property="env.TRAVIS_BUILD_NUMBER" />
</condition>
<then>
<replaceregexp
file="res/values/setup.xml"
match='("build_number"&gt;)\s*(&lt;)'
replace="\1${env.TRAVIS_BUILD_NUMBER}\2"
byline="true" />
</then>
</if>
</target>
</project>

View File

@ -24,6 +24,7 @@
-->
<resources>
<string name="build_number"></string>
<string name="server_base_url"></string>
<string name="username"></string>
<string name="password"></string>

View File

@ -26,9 +26,7 @@ package com.owncloud.android.lib.test_project;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.UnknownHostException;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
@ -38,9 +36,7 @@ import java.security.cert.CertStoreException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.SocketFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
@ -49,7 +45,7 @@ import org.apache.commons.httpclient.ConnectTimeoutException;
import org.apache.commons.httpclient.params.HttpConnectionParams;
import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
import com.owncloud.android.lib.common.network.ServerNameIndicator;
import com.owncloud.android.lib.common.network.AdvancedSslSocketFactory;
/**
@ -64,7 +60,8 @@ import com.owncloud.android.lib.common.network.ServerNameIndicator;
public class SelfSignedConfidentSslSocketFactory implements SecureProtocolSocketFactory {
private SSLContext mSslContext = null;
//private SSLContext mSslContext = null;
private AdvancedSslSocketFactory mWrappedSslSocketFactory = null;
/**
@ -72,7 +69,13 @@ public class SelfSignedConfidentSslSocketFactory implements SecureProtocolSocket
* @throws GeneralSecurityException
*/
public SelfSignedConfidentSslSocketFactory() throws GeneralSecurityException {
mSslContext = createSslContext();
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(
null,
new TrustManager[] { new SelfSignedConfidentX509TrustManager() },
null
);
mWrappedSslSocketFactory = new AdvancedSslSocketFactory(sslContext, null, null);
}
@ -81,7 +84,7 @@ public class SelfSignedConfidentSslSocketFactory implements SecureProtocolSocket
*/
@Override
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
return mSslContext.getSocketFactory().createSocket(host, port);
return mWrappedSslSocketFactory.createSocket(host, port);
}
/**
@ -90,7 +93,7 @@ public class SelfSignedConfidentSslSocketFactory implements SecureProtocolSocket
@Override
public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort)
throws IOException, UnknownHostException {
return mSslContext.getSocketFactory().createSocket(host, port, clientHost, clientPort);
return mWrappedSslSocketFactory.createSocket(host, port, clientHost, clientPort);
}
/**
@ -112,19 +115,7 @@ public class SelfSignedConfidentSslSocketFactory implements SecureProtocolSocket
HttpConnectionParams params) throws IOException, UnknownHostException,
ConnectTimeoutException {
if (params == null) {
throw new IllegalArgumentException("Parameters may not be null");
}
int timeout = params.getConnectionTimeout();
SocketFactory socketfactory = mSslContext.getSocketFactory();
Socket socket = socketfactory.createSocket();
SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
SocketAddress remoteaddr = new InetSocketAddress(host, port);
socket.setSoTimeout(params.getSoTimeout());
socket.bind(localaddr);
ServerNameIndicator.setServerNameIndication(host, (SSLSocket)socket);
socket.connect(remoteaddr, timeout);
return socket;
return mWrappedSslSocketFactory.createSocket(host, port, localAddress, localPort, params);
}
/**
@ -133,20 +124,10 @@ public class SelfSignedConfidentSslSocketFactory implements SecureProtocolSocket
@Override
public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
throws IOException, UnknownHostException {
return mSslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
return mWrappedSslSocketFactory.createSocket(socket, host, port, autoClose);
}
private static SSLContext createSslContext() throws GeneralSecurityException {
SSLContext context = SSLContext.getInstance("TLS");
context.init(
null,
new TrustManager[] {new SelfSignedConfidentX509TrustManager()},
null);
return context;
}
public static class SelfSignedConfidentX509TrustManager implements X509TrustManager {
private X509TrustManager mStandardTrustManager = null;

View File

@ -188,7 +188,7 @@ public class TestActivity extends Activity {
public RemoteOperationResult removeFile(String remotePath) {
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
RemoteOperationResult result = removeOperation.execute(mClient);
return TestActivity.removeFile(remotePath, mClient);
return result;
}
/**

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules">
<!-- Run regular Android target 'test', but fails if any test is not successful -->
<target name="acceptance-test" depends="clean, debug, install" >
<property name="log.file" value="tests_output.txt" />

View File

@ -23,9 +23,7 @@
*/
package com.owncloud.android.lib.test_project.test;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
@ -33,15 +31,13 @@ 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 masensio
* @author David A. Velasco
*
*/
public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActivity> {
public class CreateFolderTest extends RemoteTest {
private static final String LOG_TAG = CreateFolderTest.class.getCanonicalName();
@ -49,36 +45,33 @@ public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActiv
private static final String FOLDER_PATH_BASE = "/testCreateFolder";
private TestActivity mActivity;
private String mCurrentDate;
private List<String> mCreatedFolderPaths;
private String mFullPath2FolderBase;
public CreateFolderTest() {
super(TestActivity.class);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
mCurrentDate = sdf.format(new Date());
super();
mCreatedFolderPaths = new ArrayList<String>();
}
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
mCreatedFolderPaths.clear();
mFullPath2FolderBase = mBaseFolderPath + FOLDER_PATH_BASE;
}
/**
* Test Create Folder
*/
public void testCreateFolder() {
String remotePath = FOLDER_PATH_BASE + mCurrentDate;
String remotePath = mFullPath2FolderBase;
mCreatedFolderPaths.add(remotePath);
RemoteOperationResult result = mActivity.createFolder(remotePath, true);
assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
// Create Subfolder
remotePath = FOLDER_PATH_BASE + mCurrentDate + FOLDER_PATH_BASE + mCurrentDate;
remotePath = mFullPath2FolderBase + FOLDER_PATH_BASE;
mCreatedFolderPaths.add(remotePath);
result = mActivity.createFolder(remotePath, true);
assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
@ -90,35 +83,35 @@ public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActiv
*/
public void testCreateFolderSpecialCharacters() {
String remotePath = FOLDER_PATH_BASE + "_\\" + mCurrentDate;
String remotePath = mFullPath2FolderBase + "_\\";
RemoteOperationResult result = mActivity.createFolder(remotePath, true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
remotePath = FOLDER_PATH_BASE + "_<" + mCurrentDate;
remotePath = mFullPath2FolderBase + "_<";
result = mActivity.createFolder(remotePath, true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
remotePath = FOLDER_PATH_BASE + "_>" + mCurrentDate;
remotePath = mFullPath2FolderBase + "_>";
result = mActivity.createFolder(remotePath, true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
remotePath = FOLDER_PATH_BASE + "_:" + mCurrentDate;
remotePath = mFullPath2FolderBase + "_:";
result = mActivity.createFolder(remotePath, true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
remotePath = FOLDER_PATH_BASE + "_\"" + mCurrentDate;
remotePath = mFullPath2FolderBase + "_\"";
result = mActivity.createFolder(remotePath, true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
remotePath = FOLDER_PATH_BASE + "_|" + mCurrentDate;
remotePath = mFullPath2FolderBase + "_|";
result = mActivity.createFolder(remotePath, true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
remotePath = FOLDER_PATH_BASE + "_?" + mCurrentDate;
remotePath = mFullPath2FolderBase + "_?";
result = mActivity.createFolder(remotePath, true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
remotePath = FOLDER_PATH_BASE + "_*" + mCurrentDate;
remotePath = mFullPath2FolderBase + "_*";
result = mActivity.createFolder(remotePath, true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
}
@ -130,7 +123,7 @@ public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActiv
RemoteOperationResult removeResult = null;
while (it.hasNext()) {
removeResult = mActivity.removeFile(it.next());
if (!removeResult.isSuccess()) {
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, removeResult);
}
}

View File

@ -27,12 +27,11 @@ 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;
import android.test.ActivityInstrumentationTestCase2;
public class CreateShareTest extends ActivityInstrumentationTestCase2<TestActivity> {
public class CreateShareTest extends RemoteTest {
private static final String LOG_TAG = CreateShareTest.class.getCanonicalName();
@ -40,22 +39,19 @@ public class CreateShareTest extends ActivityInstrumentationTestCase2<TestActivi
private static final String FILE_TO_SHARE = "/fileToShare.txt";
private TestActivity mActivity;
public CreateShareTest() {
super(TestActivity.class);
}
private String mFullPath2FileToShare;
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
mFullPath2FileToShare = mBaseFolderPath + FILE_TO_SHARE;
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
RemoteOperationResult result = mActivity.uploadFile(
textFile.getAbsolutePath(),
FILE_TO_SHARE,
mFullPath2FileToShare,
"txt/plain");
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
@ -67,7 +63,7 @@ public class CreateShareTest extends ActivityInstrumentationTestCase2<TestActivi
*/
public void testCreatePublicShare() {
RemoteOperationResult result = mActivity.createShare(
FILE_TO_SHARE,
mFullPath2FileToShare,
ShareType.PUBLIC_LINK,
"",
false,
@ -79,8 +75,8 @@ public class CreateShareTest extends ActivityInstrumentationTestCase2<TestActivi
@Override
protected void tearDown() throws Exception {
RemoteOperationResult removeResult = mActivity.removeFile(FILE_TO_SHARE);
if (!removeResult.isSuccess()) {
RemoteOperationResult removeResult = mActivity.removeFile(mFullPath2FileToShare);
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, removeResult);
}
super.tearDown();

View File

@ -27,18 +27,16 @@ 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;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
/**
* Class to test Delete a File Operation
* @author masensio
*
*/
public class DeleteFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
public class DeleteFileTest extends RemoteTest {
private static final String LOG_TAG = DeleteFileTest.class.getCanonicalName();
@ -48,40 +46,31 @@ public class DeleteFileTest extends ActivityInstrumentationTestCase2<TestActivit
/* File to delete. */
private static final String FILE_PATH = "/fileToDelete.txt";
private static boolean mGlobalSetupDone = false;
private TestActivity mActivity;
public DeleteFileTest() {
super(TestActivity.class);
}
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;
if (!mGlobalSetupDone) {
Log.v(LOG_TAG, "Starting global set up");
RemoteOperationResult result = mActivity.createFolder(FOLDER_PATH, true);
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
result = mActivity.uploadFile(
textFile.getAbsolutePath(),
FILE_PATH,
"txt/plain");
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
Log.v(LOG_TAG, "Global set up done");
mGlobalSetupDone = true;
}
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);
}
}
@ -90,7 +79,7 @@ public class DeleteFileTest extends ActivityInstrumentationTestCase2<TestActivit
*/
public void testRemoveFolder() {
RemoteOperationResult result = mActivity.removeFile(FOLDER_PATH);
RemoteOperationResult result = mActivity.removeFile(mFullPath2Folder);
assertTrue(result.isSuccess());
}
@ -99,7 +88,7 @@ public class DeleteFileTest extends ActivityInstrumentationTestCase2<TestActivit
*/
public void testRemoveFile() {
RemoteOperationResult result = mActivity.removeFile(FILE_PATH);
RemoteOperationResult result = mActivity.removeFile(mFullPath2File);
assertTrue(result.isSuccess());
}

View File

@ -31,16 +31,13 @@ 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;
import android.util.Log;
/**
* Class to test Download File Operation
* @author masensio
* @author David A. Velasco
*/
public class DownloadFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
public class DownloadFileTest extends RemoteTest {
private static final String LOG_TAG = DownloadFileTest.class.getCanonicalName();
@ -49,49 +46,47 @@ public class DownloadFileTest extends ActivityInstrumentationTestCase2<TestActiv
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 static final String [] FILE_PATHS = { IMAGE_PATH, IMAGE_PATH_WITH_SPECIAL_CHARS };
private static boolean mGlobalSetupDone = false;
private String mFullPath2Image;
private String mFullPath2ImageWitSpecialChars;
private String mFullPath2ImageNotFound;
private String mDownloadedFilePath;
private TestActivity mActivity;
public DownloadFileTest() {
super(TestActivity.class);
}
@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;
if (!mGlobalSetupDone) {
RemoteOperationResult result = null;
File imageFile = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME);
File imageFile = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME);
for (int i=0; i<FILE_PATHS.length && (result == null || result.isSuccess()); i++) {
result = mActivity.uploadFile(
imageFile.getAbsolutePath(),
FILE_PATHS[i],
"image/png");
}
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
result = mActivity.removeFile(IMAGE_NOT_FOUND);
if (!result.isSuccess() && result.getCode() != ResultCode.FILE_NOT_FOUND) {
Utils.logAndThrow(LOG_TAG, result);
}
Log.v(LOG_TAG, "Global set up done");
mGlobalSetupDone = true;
}
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);
}
}
/**
@ -99,10 +94,10 @@ public class DownloadFileTest extends ActivityInstrumentationTestCase2<TestActiv
*/
public void testDownloadFile() {
RemoteOperationResult result = mActivity.downloadFile(
new RemoteFile(IMAGE_PATH),
new RemoteFile(mFullPath2Image),
mActivity.getFilesDir().getAbsolutePath()
);
mDownloadedFilePath = IMAGE_PATH;
mDownloadedFilePath = mFullPath2Image;
assertTrue(result.isSuccess());
// TODO some checks involving the local file
}
@ -112,10 +107,10 @@ public class DownloadFileTest extends ActivityInstrumentationTestCase2<TestActiv
*/
public void testDownloadFileSpecialChars() {
RemoteOperationResult result = mActivity.downloadFile(
new RemoteFile(IMAGE_PATH_WITH_SPECIAL_CHARS),
new RemoteFile(mFullPath2ImageWitSpecialChars),
mActivity.getFilesDir().getAbsolutePath()
);
mDownloadedFilePath = IMAGE_PATH_WITH_SPECIAL_CHARS;
mDownloadedFilePath = mFullPath2ImageWitSpecialChars;
assertTrue(result.isSuccess());
// TODO some checks involving the local file
}
@ -125,7 +120,7 @@ public class DownloadFileTest extends ActivityInstrumentationTestCase2<TestActiv
*/
public void testDownloadFileNotFound() {
RemoteOperationResult result = mActivity.downloadFile(
new RemoteFile(IMAGE_NOT_FOUND),
new RemoteFile(mFullPath2ImageNotFound),
mActivity.getFilesDir().getAbsolutePath()
);
assertFalse(result.isSuccess());
@ -136,7 +131,7 @@ public class DownloadFileTest extends ActivityInstrumentationTestCase2<TestActiv
protected void tearDown() throws Exception {
if (mDownloadedFilePath != null) {
RemoteOperationResult removeResult = mActivity.removeFile(mDownloadedFilePath);
if (!removeResult.isSuccess()) {
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, removeResult);
}
}

View File

@ -27,11 +27,10 @@ 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;
import android.test.ActivityInstrumentationTestCase2;
/**
* Class to test Get Shares Operation
*
@ -39,36 +38,33 @@ import android.test.ActivityInstrumentationTestCase2;
*
*/
public class GetSharesTest extends ActivityInstrumentationTestCase2<TestActivity> {
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;
public GetSharesTest() {
super(TestActivity.class);
}
@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(),
SHARED_FILE,
mFullPath2SharedFile,
"txt/plain");
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
result = mActivity.createShare(SHARED_FILE, ShareType.PUBLIC_LINK, "", false, "", 1);
if (!result.isSuccess()) {
result = mActivity.createShare(mFullPath2SharedFile, ShareType.PUBLIC_LINK, "", false, "", 1);
if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, result);
}
@ -86,8 +82,8 @@ public class GetSharesTest extends ActivityInstrumentationTestCase2<TestActivity
@Override
protected void tearDown() throws Exception {
RemoteOperationResult removeResult = mActivity.removeFile(SHARED_FILE);
if (!removeResult.isSuccess()) {
RemoteOperationResult removeResult = mActivity.removeFile(mFullPath2SharedFile);
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, removeResult);
}
super.tearDown();

View File

@ -46,8 +46,6 @@ import com.owncloud.android.lib.test_project.TestActivity;
import android.content.Context;
import android.net.Uri;
import android.test.ActivityInstrumentationTestCase2;
//import android.test.AndroidTestCase;
import android.util.Log;
/**
@ -69,7 +67,7 @@ import android.util.Log;
*/
//public class MoveFileTest extends AndroidTestCase {
public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
public class MoveFileTest extends RemoteTest {
private static final String LOG_TAG = MoveFileTest.class.getCanonicalName();
@ -209,7 +207,7 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
OwnCloudClient mClient = null;
public MoveFileTest() {
super(TestActivity.class);
super();
Protocol pr = Protocol.getProtocol("https");
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
@ -244,8 +242,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
RemoteOperationResult result = null;
for (String folderPath : FOLDERS_IN_FIXTURE) {
result = TestActivity.createFolder(folderPath, true, mClient);
if (!result.isSuccess()) {
result = TestActivity.createFolder(mBaseFolderPath + folderPath, true, mClient);
if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, result);
}
}
@ -255,7 +253,7 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
);
for (String filePath : FILES_IN_FIXTURE) {
result = TestActivity.uploadFile(
txtFile.getAbsolutePath(), filePath, "txt/plain", mClient
txtFile.getAbsolutePath(), mBaseFolderPath + filePath, "txt/plain", mClient
);
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
@ -277,8 +275,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
// move file
MoveRemoteFileOperation moveOperation = new MoveRemoteFileOperation(
SRC_PATH_TO_FILE_1,
TARGET_PATH_TO_FILE_1,
mBaseFolderPath + SRC_PATH_TO_FILE_1,
mBaseFolderPath + TARGET_PATH_TO_FILE_1,
false
);
RemoteOperationResult result = moveOperation.execute(mClient);
@ -286,8 +284,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
// move & rename file, different location
moveOperation = new MoveRemoteFileOperation(
SRC_PATH_TO_FILE_2,
TARGET_PATH_TO_FILE_2_RENAMED,
mBaseFolderPath + SRC_PATH_TO_FILE_2,
mBaseFolderPath + TARGET_PATH_TO_FILE_2_RENAMED,
false
);
result = moveOperation.execute(mClient);
@ -295,8 +293,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
// move & rename file, same location (rename file)
moveOperation = new MoveRemoteFileOperation(
SRC_PATH_TO_FILE_3,
SRC_PATH_TO_FILE_3_RENAMED,
mBaseFolderPath + SRC_PATH_TO_FILE_3,
mBaseFolderPath + SRC_PATH_TO_FILE_3_RENAMED,
false
);
result = moveOperation.execute(mClient);
@ -304,8 +302,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
// move empty folder
moveOperation = new MoveRemoteFileOperation(
SRC_PATH_TO_EMPTY_FOLDER,
TARGET_PATH_TO_EMPTY_FOLDER,
mBaseFolderPath + SRC_PATH_TO_EMPTY_FOLDER,
mBaseFolderPath + TARGET_PATH_TO_EMPTY_FOLDER,
false
);
result = moveOperation.execute(mClient);
@ -313,8 +311,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
// move non-empty folder
moveOperation = new MoveRemoteFileOperation(
SRC_PATH_TO_FULL_FOLDER_1,
TARGET_PATH_TO_FULL_FOLDER_1,
mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_1,
mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_1,
false
);
result = moveOperation.execute(mClient);
@ -322,8 +320,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
// move & rename folder, different location
moveOperation = new MoveRemoteFileOperation(
SRC_PATH_TO_FULL_FOLDER_2,
TARGET_PATH_TO_FULL_FOLDER_2_RENAMED,
mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_2,
mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_2_RENAMED,
false
);
result = moveOperation.execute(mClient);
@ -331,8 +329,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
// move & rename folder, same location (rename folder)
moveOperation = new MoveRemoteFileOperation(
SRC_PATH_TO_FULL_FOLDER_3,
SRC_PATH_TO_FULL_FOLDER_3_RENAMED,
mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_3,
mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_3_RENAMED,
false
);
result = moveOperation.execute(mClient);
@ -340,8 +338,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
// move for nothing (success, but no interaction with network)
moveOperation = new MoveRemoteFileOperation(
SRC_PATH_TO_FILE_4,
SRC_PATH_TO_FILE_4,
mBaseFolderPath + SRC_PATH_TO_FILE_4,
mBaseFolderPath + SRC_PATH_TO_FILE_4,
false
);
result = moveOperation.execute(mClient);
@ -349,9 +347,9 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
// move overwriting
moveOperation = new MoveRemoteFileOperation(
SRC_PATH_TO_FULL_FOLDER_4,
TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4,
true
mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_4,
mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4,
true
);
result = moveOperation.execute(mClient);
assertTrue(result.isSuccess());
@ -361,45 +359,45 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
// file to move does not exist
moveOperation = new MoveRemoteFileOperation(
SRC_PATH_TO_NON_EXISTENT_FILE,
TARGET_PATH_TO_NON_EXISTENT_FILE,
false
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(
SRC_PATH_TO_FILE_5,
TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER,
false
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(
SRC_PATH_TO_FILE_6,
TARGET_PATH_RENAMED_WITH_INVALID_CHARS,
false
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(
SRC_PATH_TO_FILE_7,
TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7,
false
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(
SRC_BASE_FOLDER,
SRC_PATH_TO_EMPTY_FOLDER,
false
mBaseFolderPath + SRC_BASE_FOLDER,
mBaseFolderPath + SRC_PATH_TO_EMPTY_FOLDER,
false
);
result = moveOperation.execute(mClient);
assertTrue(result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT);
@ -411,8 +409,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
Log.v(LOG_TAG, "Deleting remote fixture...");
String[] mPathsToCleanUp = {
SRC_BASE_FOLDER,
TARGET_BASE_FOLDER
mBaseFolderPath + SRC_BASE_FOLDER,
mBaseFolderPath + TARGET_BASE_FOLDER
};
for (String path : mPathsToCleanUp) {

View File

@ -26,27 +26,23 @@ 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;
import android.test.ActivityInstrumentationTestCase2;
/**
* Class to test Read File Operation
* @author masensio
* @author David A. Velasco
*/
public class ReadFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
public class ReadFileTest extends RemoteTest {
private static final String LOG_TAG = ReadFileTest.class.getCanonicalName();
private TestActivity mActivity;
private String FILE_PATH = "/fileToRead.txt";
public ReadFileTest() {
super(TestActivity.class);
}
private String mFullPath2File;
@Override
protected void setUp() throws Exception {
@ -54,11 +50,12 @@ public class ReadFileTest extends ActivityInstrumentationTestCase2<TestActivity
setActivityInitialTouchMode(false);
mActivity = getActivity();
mFullPath2File = mBaseFolderPath + FILE_PATH;
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
RemoteOperationResult uploadResult = mActivity.uploadFile(
textFile.getAbsolutePath(),
FILE_PATH,
mFullPath2File,
"txt/plain");
if (!uploadResult.isSuccess()) {
Utils.logAndThrow(LOG_TAG, uploadResult);
@ -69,7 +66,7 @@ public class ReadFileTest extends ActivityInstrumentationTestCase2<TestActivity
* Test Read File
*/
public void testReadFile() {
RemoteOperationResult result = mActivity.readFile(FILE_PATH);
RemoteOperationResult result = mActivity.readFile(mFullPath2File);
assertTrue(result.getData() != null && result.getData().size() == 1);
assertTrue(result.isSuccess());
// TODO check more properties of the result
@ -77,8 +74,8 @@ public class ReadFileTest extends ActivityInstrumentationTestCase2<TestActivity
@Override
protected void tearDown() throws Exception {
RemoteOperationResult removeResult = mActivity.removeFile(FILE_PATH);
if (!removeResult.isSuccess()) {
RemoteOperationResult removeResult = mActivity.removeFile(mFullPath2File);
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, removeResult);
}

View File

@ -27,17 +27,16 @@ 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;
import android.test.ActivityInstrumentationTestCase2;
/**
* Class to test Read Folder Operation
* @author masensio
* @author David A. Velasco
*/
public class ReadFolderTest extends ActivityInstrumentationTestCase2<TestActivity> {
public class ReadFolderTest extends RemoteTest {
private static final String LOG_TAG = ReadFolderTest.class.getCanonicalName();
@ -50,24 +49,22 @@ public class ReadFolderTest extends ActivityInstrumentationTestCase2<TestActivit
private TestActivity mActivity;
public ReadFolderTest() {
super(TestActivity.class);
}
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(FOLDER_PATH, true);
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(),
FILE_PATHS[i],
mBaseFolderPath + FILE_PATHS[i],
"txt/plain");
}
}
@ -83,7 +80,7 @@ public class ReadFolderTest extends ActivityInstrumentationTestCase2<TestActivit
*/
public void testReadFolder() {
RemoteOperationResult result = mActivity.readFile(FOLDER_PATH);
RemoteOperationResult result = mActivity.readFile(mFullPathToFolder);
assertTrue(result.isSuccess());
assertTrue(result.getData() != null && result.getData().size() > 1);
assertTrue(result.getData().size() == 4);
@ -93,8 +90,8 @@ public class ReadFolderTest extends ActivityInstrumentationTestCase2<TestActivit
@Override
protected void tearDown() throws Exception {
RemoteOperationResult removeResult = mActivity.removeFile(FOLDER_PATH);
if (!removeResult.isSuccess()) {
RemoteOperationResult removeResult = mActivity.removeFile(mFullPathToFolder);
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, removeResult);
}

View File

@ -0,0 +1,69 @@
/* 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 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<TestActivity> {
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();
}
}

View File

@ -29,41 +29,38 @@ 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;
import android.test.ActivityInstrumentationTestCase2;
public class RemoveShareTest extends ActivityInstrumentationTestCase2<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;
public RemoveShareTest() {
super(TestActivity.class);
}
@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(),
FILE_TO_UNSHARE,
mFullPath2FileToUnshare,
"txt/plain");
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
result = mActivity.createShare(FILE_TO_UNSHARE, ShareType.PUBLIC_LINK, "", false, "", 1);
result = mActivity.createShare(mFullPath2FileToUnshare, ShareType.PUBLIC_LINK, "", false, "", 1);
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
} else {
@ -84,8 +81,8 @@ public class RemoveShareTest extends ActivityInstrumentationTestCase2<TestActivi
@Override
protected void tearDown() throws Exception {
RemoteOperationResult removeResult = mActivity.removeFile(FILE_TO_UNSHARE);
if (!removeResult.isSuccess()) {
RemoteOperationResult removeResult = mActivity.removeFile(mFullPath2FileToUnshare);
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, removeResult);
}
super.tearDown();

View File

@ -31,16 +31,13 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCo
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 Rename File Operation
* @author masensio
*
*/
public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
public class RenameFileTest extends RemoteTest {
private static final String LOG_TAG = RenameFileTest.class.getCanonicalName();
@ -57,42 +54,36 @@ public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivit
private static final String NEW_FILE_PATH = FileUtils.PATH_SEPARATOR + NEW_FILE_NAME;
private static boolean mGlobalSetupDone = false;
private String mToCleanUpInServer;
private TestActivity mActivity;
public RenameFileTest() {
super(TestActivity.class);
}
private String mFullPath2OldFolder;
private String mFullPath2NewFolder;
private String mFullPath2OldFile;
private String mFullPath2NewFile;
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
if (!mGlobalSetupDone) {
Log.v(LOG_TAG, "Starting global set up");
RemoteOperationResult result = mActivity.createFolder(OLD_FOLDER_NAME, true);
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
File imageFile = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME);
result = mActivity.uploadFile(
imageFile.getAbsolutePath(),
OLD_FILE_PATH,
"image/png");
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
Log.v(LOG_TAG, "Global set up done");
mGlobalSetupDone = true;
}
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;
}
@ -102,14 +93,14 @@ public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivit
*/
public void testRenameFolder() {
mToCleanUpInServer = OLD_FOLDER_PATH;
mToCleanUpInServer = mFullPath2OldFolder;
RemoteOperationResult result = mActivity.renameFile(
OLD_FOLDER_NAME,
OLD_FOLDER_PATH,
mFullPath2OldFolder,
NEW_FOLDER_NAME,
true);
assertTrue(result.isSuccess());
mToCleanUpInServer = NEW_FOLDER_PATH;
mToCleanUpInServer = mFullPath2NewFolder;
}
/**
@ -117,35 +108,35 @@ public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivit
*/
public void testRenameFolderForbiddenChars() {
RemoteOperationResult result = mActivity.renameFile(OLD_FOLDER_NAME, OLD_FOLDER_PATH,
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, OLD_FOLDER_PATH,
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, OLD_FOLDER_PATH,
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, OLD_FOLDER_PATH,
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, OLD_FOLDER_PATH,
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, OLD_FOLDER_PATH,
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, OLD_FOLDER_PATH,
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, OLD_FOLDER_PATH,
result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder,
NEW_FOLDER_NAME + "*", true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
}
@ -154,14 +145,14 @@ public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivit
* Test Rename File
*/
public void testRenameFile() {
mToCleanUpInServer = OLD_FILE_PATH;
mToCleanUpInServer = mFullPath2OldFile;
RemoteOperationResult result = mActivity.renameFile(
OLD_FILE_NAME,
OLD_FILE_PATH,
mFullPath2OldFile,
NEW_FILE_NAME,
false);
assertTrue(result.isSuccess());
mToCleanUpInServer = NEW_FILE_PATH;
mToCleanUpInServer = mFullPath2NewFile;
}
@ -171,56 +162,56 @@ public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivit
public void testRenameFileForbiddenChars() {
RemoteOperationResult result = mActivity.renameFile(
OLD_FILE_NAME,
OLD_FILE_PATH,
mFullPath2OldFile,
"\\" + NEW_FILE_NAME,
false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(
OLD_FILE_NAME,
OLD_FILE_PATH,
mFullPath2OldFile,
"<" + NEW_FILE_NAME,
false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(
OLD_FILE_NAME,
OLD_FILE_PATH,
mFullPath2OldFile,
">" + NEW_FILE_NAME,
false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(
OLD_FILE_NAME,
OLD_FILE_PATH,
mFullPath2OldFile,
":" + NEW_FILE_NAME,
false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(
OLD_FILE_NAME,
OLD_FILE_PATH,
mFullPath2OldFile,
"\"" + NEW_FILE_NAME,
false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(
OLD_FILE_NAME,
OLD_FILE_PATH,
mFullPath2OldFile,
"|" + NEW_FILE_NAME,
false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(
OLD_FILE_NAME,
OLD_FILE_PATH,
mFullPath2OldFile,
"?" + NEW_FILE_NAME,
false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(
OLD_FILE_NAME,
OLD_FILE_PATH,
mFullPath2OldFile,
"*" + NEW_FILE_NAME, false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);

View File

@ -26,9 +26,8 @@ package com.owncloud.android.lib.test_project.test;
import java.io.File;
import android.test.ActivityInstrumentationTestCase2;
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;
/**
@ -38,7 +37,7 @@ import com.owncloud.android.lib.test_project.TestActivity;
*
*/
public class UploadFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
public class UploadFileTest extends RemoteTest {
private static final String LOG_TAG = UploadFileTest.class.getCanonicalName();
@ -54,10 +53,6 @@ public class UploadFileTest extends ActivityInstrumentationTestCase2<TestActivit
private String mUploadedFilePath;
public UploadFileTest() {
super(TestActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
@ -75,12 +70,13 @@ public class UploadFileTest extends ActivityInstrumentationTestCase2<TestActivit
*/
public void testUploadFile() {
String fullPath2Upload = mBaseFolderPath + UPLOAD_PATH;
RemoteOperationResult result = mActivity.uploadFile(
mFileToUpload.getAbsolutePath(),
UPLOAD_PATH,
fullPath2Upload,
"image/png"
);
mUploadedFilePath = UPLOAD_PATH;
mUploadedFilePath = fullPath2Upload;
assertTrue(result.isSuccess());
}
@ -89,12 +85,13 @@ public class UploadFileTest extends ActivityInstrumentationTestCase2<TestActivit
*/
public void testUploadFileWithChunks() {
String fullPath2Upload = mBaseFolderPath + CHUNKED_UPLOAD_PATH;
RemoteOperationResult result = mActivity.uploadFile(
mFileToUploadWithChunks.getAbsolutePath(),
CHUNKED_UPLOAD_PATH,
fullPath2Upload,
"video/mp4"
);
mUploadedFilePath = CHUNKED_UPLOAD_PATH;
mUploadedFilePath = fullPath2Upload;
assertTrue(result.isSuccess());
}
@ -103,12 +100,13 @@ public class UploadFileTest extends ActivityInstrumentationTestCase2<TestActivit
*/
public void testUploadFileNotFound() {
String fullPath2Upload = mBaseFolderPath + FILE_NOT_FOUND_PATH;
RemoteOperationResult result = mActivity.uploadFile(
FILE_NOT_FOUND_PATH,
FILE_NOT_FOUND_PATH,
fullPath2Upload,
"image/png"
);
mUploadedFilePath = FILE_NOT_FOUND_PATH;
mUploadedFilePath = fullPath2Upload;
assertFalse(result.isSuccess());
}
@ -117,7 +115,7 @@ public class UploadFileTest extends ActivityInstrumentationTestCase2<TestActivit
protected void tearDown() throws Exception {
if (mUploadedFilePath != null) {
RemoteOperationResult removeResult = mActivity.removeFile(mUploadedFilePath);
if (!removeResult.isSuccess()) {
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, removeResult);
}
}

View File

@ -24,15 +24,32 @@
package com.owncloud.android.lib.test_project.test;
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;
}
}