mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-11-03 20:08:00 +00:00 
			
		
		
		
	Merge branch 'develop' of github.com:owncloud/android-library into buildsystem/gradle_develop
Conflicts: .travis.yml
This commit is contained in:
		
						commit
						ef768b7d1b
					
				
							
								
								
									
										10
									
								
								.travis.yml
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								.travis.yml
									
									
									
									
									
								
							@ -1,15 +1,21 @@
 | 
				
			|||||||
language: android
 | 
					language: android
 | 
				
			||||||
android:
 | 
					android:
 | 
				
			||||||
  components:
 | 
					  components:
 | 
				
			||||||
    - platform-tools
 | 
					 | 
				
			||||||
    - tools
 | 
					 | 
				
			||||||
    - build-tools-20.0.0
 | 
					    - build-tools-20.0.0
 | 
				
			||||||
    - android-19
 | 
					    - android-19
 | 
				
			||||||
 | 
					    - android-17
 | 
				
			||||||
 | 
					    - android-14
 | 
				
			||||||
 | 
					    - extra-android-support
 | 
				
			||||||
 | 
					  licenses:
 | 
				
			||||||
 | 
					    - 'android-sdk-license-5be876d5'
 | 
				
			||||||
 | 
					    - 'android-sdk-license-598b93a6'
 | 
				
			||||||
 | 
					jdk: oraclejdk7
 | 
				
			||||||
before_install:
 | 
					before_install:
 | 
				
			||||||
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI -c 20M
 | 
					- 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 &
 | 
					- emulator -avd test -no-skin -no-audio -no-window &
 | 
				
			||||||
- rm pom.xml
 | 
					- rm pom.xml
 | 
				
			||||||
- android update project -p .
 | 
					- android update project -p .
 | 
				
			||||||
 | 
					before_script:
 | 
				
			||||||
- chmod +x ./wait_for_emulator.sh
 | 
					- chmod +x ./wait_for_emulator.sh
 | 
				
			||||||
- ./wait_for_emulator.sh
 | 
					- ./wait_for_emulator.sh
 | 
				
			||||||
script:
 | 
					script:
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							@ -13,7 +13,7 @@
 | 
				
			|||||||
        <owncloud.version>1.5.1-SNAPSHOT</owncloud.version>
 | 
					        <owncloud.version>1.5.1-SNAPSHOT</owncloud.version>
 | 
				
			||||||
        <java-version>1.6</java-version>
 | 
					        <java-version>1.6</java-version>
 | 
				
			||||||
        <!-- Given by maven-android-sdk-deployer -->
 | 
					        <!-- 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 -->
 | 
					        <!-- Usually the latest Android API -->
 | 
				
			||||||
        <google.android-api>19</google.android-api>
 | 
					        <google.android-api>19</google.android-api>
 | 
				
			||||||
    </properties>
 | 
					    </properties>
 | 
				
			||||||
 | 
				
			|||||||
@ -30,6 +30,7 @@ import java.io.InputStream;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import org.apache.commons.httpclient.Cookie;
 | 
					import org.apache.commons.httpclient.Cookie;
 | 
				
			||||||
import org.apache.commons.httpclient.Header;
 | 
					import org.apache.commons.httpclient.Header;
 | 
				
			||||||
 | 
					import org.apache.commons.httpclient.HostConfiguration;
 | 
				
			||||||
import org.apache.commons.httpclient.HttpClient;
 | 
					import org.apache.commons.httpclient.HttpClient;
 | 
				
			||||||
import org.apache.commons.httpclient.HttpConnectionManager;
 | 
					import org.apache.commons.httpclient.HttpConnectionManager;
 | 
				
			||||||
import org.apache.commons.httpclient.HttpException;
 | 
					import org.apache.commons.httpclient.HttpException;
 | 
				
			||||||
@ -92,10 +93,32 @@ public class OwnCloudClient extends HttpClient {
 | 
				
			|||||||
        		PARAM_SINGLE_COOKIE_HEADER, 			// to avoid problems with some web servers
 | 
					        		PARAM_SINGLE_COOKIE_HEADER, 			// to avoid problems with some web servers
 | 
				
			||||||
        		PARAM_SINGLE_COOKIE_HEADER_VALUE);
 | 
					        		PARAM_SINGLE_COOKIE_HEADER_VALUE);
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
 | 
					        applyProxySettings();
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        clearCredentials();
 | 
					        clearCredentials();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    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) {
 | 
						public void setCredentials(OwnCloudCredentials credentials) {
 | 
				
			||||||
    	if (credentials != null) {
 | 
					    	if (credentials != null) {
 | 
				
			||||||
    		mCredentials = credentials;
 | 
					    		mCredentials = credentials;
 | 
				
			||||||
 | 
				
			|||||||
@ -36,6 +36,7 @@ import javax.net.SocketFactory;
 | 
				
			|||||||
import javax.net.ssl.SSLContext;
 | 
					import javax.net.ssl.SSLContext;
 | 
				
			||||||
import javax.net.ssl.SSLException;
 | 
					import javax.net.ssl.SSLException;
 | 
				
			||||||
import javax.net.ssl.SSLHandshakeException;
 | 
					import javax.net.ssl.SSLHandshakeException;
 | 
				
			||||||
 | 
					import javax.net.ssl.SSLParameters;
 | 
				
			||||||
import javax.net.ssl.SSLPeerUnverifiedException;
 | 
					import javax.net.ssl.SSLPeerUnverifiedException;
 | 
				
			||||||
import javax.net.ssl.SSLSession;
 | 
					import javax.net.ssl.SSLSession;
 | 
				
			||||||
import javax.net.ssl.SSLSocket;
 | 
					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.ConnectTimeoutException;
 | 
				
			||||||
import org.apache.commons.httpclient.params.HttpConnectionParams;
 | 
					import org.apache.commons.httpclient.params.HttpConnectionParams;
 | 
				
			||||||
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
 | 
					import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
 | 
				
			||||||
 | 
					import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
 | 
				
			||||||
import org.apache.http.conn.ssl.X509HostnameVerifier;
 | 
					import org.apache.http.conn.ssl.X509HostnameVerifier;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.owncloud.android.lib.common.utils.Log_OC;
 | 
					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
 | 
					 * @author David A. Velasco
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
 | 
					public class AdvancedSslSocketFactory implements SecureProtocolSocketFactory {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static final String TAG = AdvancedSslSocketFactory.class.getSimpleName();
 | 
					    private static final String TAG = AdvancedSslSocketFactory.class.getSimpleName();
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@ -71,11 +73,17 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Constructor for AdvancedSSLProtocolSocketFactory.
 | 
					     * Constructor for AdvancedSSLProtocolSocketFactory.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public AdvancedSslSocketFactory(SSLContext sslContext, AdvancedX509TrustManager trustManager, X509HostnameVerifier hostnameVerifier) {
 | 
					    public AdvancedSslSocketFactory(
 | 
				
			||||||
 | 
					    		SSLContext sslContext, AdvancedX509TrustManager trustManager, X509HostnameVerifier hostnameVerifier
 | 
				
			||||||
 | 
							) {
 | 
				
			||||||
 | 
					    	
 | 
				
			||||||
        if (sslContext == null)
 | 
					        if (sslContext == null)
 | 
				
			||||||
            throw new IllegalArgumentException("AdvancedSslSocketFactory can not be created with a null SSLContext");
 | 
					            throw new IllegalArgumentException("AdvancedSslSocketFactory can not be created with a null SSLContext");
 | 
				
			||||||
        if (trustManager == null)
 | 
					        if (trustManager == null && mHostnameVerifier != null)
 | 
				
			||||||
            throw new IllegalArgumentException("AdvancedSslSocketFactory can not be created with a null Trust Manager");
 | 
					            throw new IllegalArgumentException(
 | 
				
			||||||
 | 
					            		"AdvancedSslSocketFactory can not be created with a null Trust Manager and a " +
 | 
				
			||||||
 | 
					            		"not null Hostname Verifier"
 | 
				
			||||||
 | 
					    		);
 | 
				
			||||||
        mSslContext = sslContext;
 | 
					        mSslContext = sslContext;
 | 
				
			||||||
        mTrustManager = trustManager;
 | 
					        mTrustManager = trustManager;
 | 
				
			||||||
        mHostnameVerifier = hostnameVerifier;
 | 
					        mHostnameVerifier = hostnameVerifier;
 | 
				
			||||||
@ -84,8 +92,11 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @see ProtocolSocketFactory#createSocket(java.lang.String,int,java.net.InetAddress,int)
 | 
					     * @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);
 | 
					        Socket socket = mSslContext.getSocketFactory().createSocket(host, port, clientHost, clientPort);
 | 
				
			||||||
 | 
					        enableSecureProtocols(socket);
 | 
				
			||||||
        verifyPeerIdentity(host, port, socket);
 | 
					        verifyPeerIdentity(host, port, socket);
 | 
				
			||||||
        return socket;
 | 
					        return socket;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -150,7 +161,8 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
 | 
				
			|||||||
            final InetAddress localAddress, final int localPort,
 | 
					            final InetAddress localAddress, final int localPort,
 | 
				
			||||||
            final HttpConnectionParams params) throws IOException,
 | 
					            final HttpConnectionParams params) throws IOException,
 | 
				
			||||||
            UnknownHostException, ConnectTimeoutException {
 | 
					            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) {
 | 
					        if (params == null) {
 | 
				
			||||||
            throw new IllegalArgumentException("Parameters may not be null");
 | 
					            throw new IllegalArgumentException("Parameters may not be null");
 | 
				
			||||||
        } 
 | 
					        } 
 | 
				
			||||||
@ -161,6 +173,7 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
 | 
				
			|||||||
        SocketFactory socketfactory = mSslContext.getSocketFactory();
 | 
					        SocketFactory socketfactory = mSslContext.getSocketFactory();
 | 
				
			||||||
        Log_OC.d(TAG, " ... with connection timeout " + timeout + " and socket timeout " + params.getSoTimeout());
 | 
					        Log_OC.d(TAG, " ... with connection timeout " + timeout + " and socket timeout " + params.getSoTimeout());
 | 
				
			||||||
        Socket socket = socketfactory.createSocket();
 | 
					        Socket socket = socketfactory.createSocket();
 | 
				
			||||||
 | 
					        enableSecureProtocols(socket);
 | 
				
			||||||
        SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
 | 
					        SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
 | 
				
			||||||
        SocketAddress remoteaddr = new InetSocketAddress(host, port);
 | 
					        SocketAddress remoteaddr = new InetSocketAddress(host, port);
 | 
				
			||||||
        socket.setSoTimeout(params.getSoTimeout());
 | 
					        socket.setSoTimeout(params.getSoTimeout());
 | 
				
			||||||
@ -178,10 +191,22 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
 | 
				
			|||||||
            UnknownHostException {
 | 
					            UnknownHostException {
 | 
				
			||||||
    	Log_OC.d(TAG, "Creating SSL Socket with remote " + host + ":" + port);
 | 
					    	Log_OC.d(TAG, "Creating SSL Socket with remote " + host + ":" + port);
 | 
				
			||||||
        Socket socket = mSslContext.getSocketFactory().createSocket(host, port);
 | 
					        Socket socket = mSslContext.getSocketFactory().createSocket(host, port);
 | 
				
			||||||
 | 
					        enableSecureProtocols(socket);
 | 
				
			||||||
        verifyPeerIdentity(host, port, socket);
 | 
					        verifyPeerIdentity(host, port, socket);
 | 
				
			||||||
        return 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) {
 | 
					    public boolean equals(Object obj) {
 | 
				
			||||||
        return ((obj != null) && obj.getClass().equals(
 | 
					        return ((obj != null) && obj.getClass().equals(
 | 
				
			||||||
                AdvancedSslSocketFactory.class));
 | 
					                AdvancedSslSocketFactory.class));
 | 
				
			||||||
@ -206,13 +231,15 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
 | 
				
			|||||||
     * 
 | 
					     * 
 | 
				
			||||||
     * The server certificate is verified first.
 | 
					     * 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
 | 
					     * @param socket
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private void verifyPeerIdentity(String host, int port, Socket socket) throws IOException {
 | 
					    private void verifyPeerIdentity(String host, int port, Socket socket) throws IOException {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            CertificateCombinedException failInHandshake = null;
 | 
					            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 {
 | 
					            try {
 | 
				
			||||||
                SSLSocket sock = (SSLSocket) socket;    // a new SSLSession instance is created as a "side effect" 
 | 
					                SSLSocket sock = (SSLSocket) socket;    // a new SSLSession instance is created as a "side effect" 
 | 
				
			||||||
                sock.startHandshake();
 | 
					                sock.startHandshake();
 | 
				
			||||||
@ -224,7 +251,9 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
 | 
				
			|||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    Throwable cause = e.getCause();
 | 
					                    Throwable cause = e.getCause();
 | 
				
			||||||
                    Throwable previousCause = null;
 | 
					                    Throwable previousCause = null;
 | 
				
			||||||
                    while (cause != null && cause != previousCause && !(cause instanceof CertificateCombinedException)) {
 | 
					                    while (	cause != null && 
 | 
				
			||||||
 | 
					                    		cause != previousCause && 
 | 
				
			||||||
 | 
					                    		!(cause instanceof CertificateCombinedException)) {
 | 
				
			||||||
                        previousCause = cause;
 | 
					                        previousCause = cause;
 | 
				
			||||||
                        cause = cause.getCause();
 | 
					                        cause = cause.getCause();
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
@ -263,9 +292,13 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            /// 3. Combine the exceptions to throw, if any
 | 
					            /// 3. Combine the exceptions to throw, if any
 | 
				
			||||||
            if (!verifiedHostname) {
 | 
					            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) {
 | 
					                if (failInHandshake == null) {
 | 
				
			||||||
                    failInHandshake = new CertificateCombinedException((X509Certificate) newSession.getPeerCertificates()[0]);
 | 
					                    failInHandshake = new CertificateCombinedException(
 | 
				
			||||||
 | 
					                    		(X509Certificate) newSession.getPeerCertificates()[0]
 | 
				
			||||||
 | 
					    				);
 | 
				
			||||||
                    failInHandshake.setHostInUrl(host);
 | 
					                    failInHandshake.setHostInUrl(host);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                failInHandshake.setSslPeerUnverifiedException(pue);
 | 
					                failInHandshake.setSslPeerUnverifiedException(pue);
 | 
				
			||||||
@ -288,4 +321,22 @@ public class AdvancedSslSocketFactory implements ProtocolSocketFactory {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/**
 | 
				
			||||||
 | 
						 * 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);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
						
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -58,6 +58,12 @@ public class NetworkUtils {
 | 
				
			|||||||
    /** Default timeout for establishing a connection */
 | 
					    /** Default timeout for establishing a connection */
 | 
				
			||||||
    public static final int DEFAULT_CONNECTION_TIMEOUT = 60000;
 | 
					    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 */
 | 
					    /** Connection manager for all the OwnCloudClients */
 | 
				
			||||||
    private static MultiThreadedHttpConnectionManager mConnManager = null;
 | 
					    private static MultiThreadedHttpConnectionManager mConnManager = null;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@ -72,7 +78,9 @@ public class NetworkUtils {
 | 
				
			|||||||
     * Registers or unregisters the proper components for advanced SSL handling.
 | 
					     * Registers or unregisters the proper components for advanced SSL handling.
 | 
				
			||||||
     * @throws IOException 
 | 
					     * @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;
 | 
					        Protocol pr = null;
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            pr = Protocol.getProtocol("https");
 | 
					            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) {
 | 
					        if (mAdvancedSslSocketFactory  == null) {
 | 
				
			||||||
            KeyStore trustStore = getKnownServersStore(context);
 | 
					            KeyStore trustStore = getKnownServersStore(context);
 | 
				
			||||||
            AdvancedX509TrustManager trustMgr = new AdvancedX509TrustManager(trustStore);
 | 
					            AdvancedX509TrustManager trustMgr = new AdvancedX509TrustManager(trustStore);
 | 
				
			||||||
            TrustManager[] tms = new TrustManager[] { trustMgr };
 | 
					            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);
 | 
					            sslContext.init(null, tms, null);
 | 
				
			||||||
                    
 | 
					                    
 | 
				
			||||||
            mHostnameVerifier = new BrowserCompatHostnameVerifier();
 | 
					            mHostnameVerifier = new BrowserCompatHostnameVerifier();
 | 
				
			||||||
@ -127,9 +144,11 @@ public class NetworkUtils {
 | 
				
			|||||||
     * @throws KeyStoreException            When the KeyStore instance could not be created.
 | 
					     * @throws KeyStoreException            When the KeyStore instance could not be created.
 | 
				
			||||||
     * @throws IOException                  When an existing local trust store could not be loaded.
 | 
					     * @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 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) {
 | 
					        if (mKnownServersStore == null) {
 | 
				
			||||||
            //mKnownServersStore = KeyStore.getInstance("BKS");
 | 
					            //mKnownServersStore = KeyStore.getInstance("BKS");
 | 
				
			||||||
            mKnownServersStore = KeyStore.getInstance(KeyStore.getDefaultType());
 | 
					            mKnownServersStore = KeyStore.getInstance(KeyStore.getDefaultType());
 | 
				
			||||||
@ -143,15 +162,17 @@ public class NetworkUtils {
 | 
				
			|||||||
                    in.close();
 | 
					                    in.close();
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            } else {
 | 
					            } 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;
 | 
					        return mKnownServersStore;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    public static void addCertToKnownServersStore(Certificate cert, Context context) throws  KeyStoreException, NoSuchAlgorithmException, 
 | 
					    public static void addCertToKnownServersStore(Certificate cert, Context context) 
 | 
				
			||||||
                                                                                            CertificateException, IOException {
 | 
					    		throws  KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
 | 
				
			||||||
 | 
					    	
 | 
				
			||||||
        KeyStore knownServers = getKnownServersStore(context);
 | 
					        KeyStore knownServers = getKnownServersStore(context);
 | 
				
			||||||
        knownServers.setCertificateEntry(Integer.toString(cert.hashCode()), cert);
 | 
					        knownServers.setCertificateEntry(Integer.toString(cert.hashCode()), cert);
 | 
				
			||||||
        FileOutputStream fos = null;
 | 
					        FileOutputStream fos = null;
 | 
				
			||||||
@ -173,7 +194,8 @@ public class NetworkUtils {
 | 
				
			|||||||
        return mConnManager;
 | 
					        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);
 | 
					    	KeyStore knownServers = getKnownServersStore(context);
 | 
				
			||||||
    	Log_OC.d(TAG, "Certificate - HashCode: " + cert.hashCode() + " "
 | 
					    	Log_OC.d(TAG, "Certificate - HashCode: " + cert.hashCode() + " "
 | 
				
			||||||
 | 
				
			|||||||
@ -175,5 +175,4 @@ public class Log_OC {
 | 
				
			|||||||
    public static String[] getLogFileNames() {
 | 
					    public static String[] getLogFileNames() {
 | 
				
			||||||
        return mLogFileNames;
 | 
					        return mLogFileNames;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -48,7 +48,7 @@ import com.owncloud.android.lib.common.utils.Log_OC;
 | 
				
			|||||||
public class ReadRemoteFileOperation extends RemoteOperation {
 | 
					public class ReadRemoteFileOperation extends RemoteOperation {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static final String TAG = ReadRemoteFileOperation.class.getSimpleName();
 | 
					    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 static final int SYNC_CONNECTION_TIMEOUT = 5000;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    private String mRemotePath;
 | 
					    private String mRemotePath;
 | 
				
			||||||
 | 
				
			|||||||
@ -43,5 +43,19 @@
 | 
				
			|||||||
				byline="true" />
 | 
									byline="true" />
 | 
				
			||||||
			</then>
 | 
								</then>
 | 
				
			||||||
		</if>
 | 
							</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">)\s*(<)'
 | 
				
			||||||
 | 
									replace="\1${env.TRAVIS_BUILD_NUMBER}\2"
 | 
				
			||||||
 | 
									byline="true" />
 | 
				
			||||||
 | 
								</then>
 | 
				
			||||||
 | 
							</if>
 | 
				
			||||||
	</target>
 | 
						</target>
 | 
				
			||||||
</project>
 | 
					</project>
 | 
				
			||||||
@ -24,6 +24,7 @@
 | 
				
			|||||||
 -->
 | 
					 -->
 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
<resources>
 | 
					<resources>
 | 
				
			||||||
 | 
					    <string name="build_number"></string>
 | 
				
			||||||
    <string name="server_base_url"></string>
 | 
					    <string name="server_base_url"></string>
 | 
				
			||||||
    <string name="username"></string>
 | 
					    <string name="username"></string>
 | 
				
			||||||
    <string name="password"></string>
 | 
					    <string name="password"></string>
 | 
				
			||||||
 | 
				
			|||||||
@ -26,9 +26,7 @@ package com.owncloud.android.lib.test_project;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import java.io.IOException;
 | 
					import java.io.IOException;
 | 
				
			||||||
import java.net.InetAddress;
 | 
					import java.net.InetAddress;
 | 
				
			||||||
import java.net.InetSocketAddress;
 | 
					 | 
				
			||||||
import java.net.Socket;
 | 
					import java.net.Socket;
 | 
				
			||||||
import java.net.SocketAddress;
 | 
					 | 
				
			||||||
import java.net.UnknownHostException;
 | 
					import java.net.UnknownHostException;
 | 
				
			||||||
import java.security.GeneralSecurityException;
 | 
					import java.security.GeneralSecurityException;
 | 
				
			||||||
import java.security.KeyStore;
 | 
					import java.security.KeyStore;
 | 
				
			||||||
@ -38,9 +36,7 @@ import java.security.cert.CertStoreException;
 | 
				
			|||||||
import java.security.cert.CertificateException;
 | 
					import java.security.cert.CertificateException;
 | 
				
			||||||
import java.security.cert.X509Certificate;
 | 
					import java.security.cert.X509Certificate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.net.SocketFactory;
 | 
					 | 
				
			||||||
import javax.net.ssl.SSLContext;
 | 
					import javax.net.ssl.SSLContext;
 | 
				
			||||||
import javax.net.ssl.SSLSocket;
 | 
					 | 
				
			||||||
import javax.net.ssl.TrustManager;
 | 
					import javax.net.ssl.TrustManager;
 | 
				
			||||||
import javax.net.ssl.TrustManagerFactory;
 | 
					import javax.net.ssl.TrustManagerFactory;
 | 
				
			||||||
import javax.net.ssl.X509TrustManager;
 | 
					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.params.HttpConnectionParams;
 | 
				
			||||||
import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
 | 
					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 {
 | 
					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 
 | 
						 * @throws GeneralSecurityException 
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public SelfSignedConfidentSslSocketFactory() 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
 | 
						@Override
 | 
				
			||||||
	public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
 | 
						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
 | 
						@Override
 | 
				
			||||||
	public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort)
 | 
						public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort)
 | 
				
			||||||
			throws IOException, UnknownHostException {
 | 
								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,
 | 
								HttpConnectionParams params) throws IOException, UnknownHostException,
 | 
				
			||||||
			ConnectTimeoutException {
 | 
								ConnectTimeoutException {
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if (params == null) {
 | 
							return mWrappedSslSocketFactory.createSocket(host, port, localAddress, localPort, params);
 | 
				
			||||||
			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;
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
@ -133,20 +124,10 @@ public class SelfSignedConfidentSslSocketFactory implements SecureProtocolSocket
 | 
				
			|||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
 | 
						public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
 | 
				
			||||||
			throws IOException, UnknownHostException {
 | 
								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 {
 | 
						public static class SelfSignedConfidentX509TrustManager implements X509TrustManager {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	    private X509TrustManager mStandardTrustManager = null;
 | 
						    private X509TrustManager mStandardTrustManager = null;
 | 
				
			||||||
 | 
				
			|||||||
@ -188,7 +188,7 @@ public class TestActivity extends Activity {
 | 
				
			|||||||
	public RemoteOperationResult removeFile(String remotePath) {
 | 
						public RemoteOperationResult removeFile(String remotePath) {
 | 
				
			||||||
		RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
 | 
							RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
 | 
				
			||||||
		RemoteOperationResult result = removeOperation.execute(mClient);
 | 
							RemoteOperationResult result = removeOperation.execute(mClient);
 | 
				
			||||||
		return TestActivity.removeFile(remotePath, mClient);
 | 
							return result;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	/** 
 | 
						/** 
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,6 @@
 | 
				
			|||||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
					<?xml version="1.0" encoding="UTF-8"?>
 | 
				
			||||||
<project name="custom_rules">
 | 
					<project name="custom_rules">
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	<!-- Run regular Android target 'test', but fails if any test is not successful -->
 | 
						<!-- Run regular Android target 'test', but fails if any test is not successful -->
 | 
				
			||||||
	<target name="acceptance-test" depends="clean, debug, install" >
 | 
						<target name="acceptance-test" depends="clean, debug, install" >
 | 
				
			||||||
		<property name="log.file" value="tests_output.txt" />
 | 
							<property name="log.file" value="tests_output.txt" />
 | 
				
			||||||
 | 
				
			|||||||
@ -23,9 +23,7 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
package com.owncloud.android.lib.test_project.test;
 | 
					package com.owncloud.android.lib.test_project.test;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.text.SimpleDateFormat;
 | 
					 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
import java.util.Date;
 | 
					 | 
				
			||||||
import java.util.Iterator;
 | 
					import java.util.Iterator;
 | 
				
			||||||
import java.util.List;
 | 
					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.common.operations.RemoteOperationResult.ResultCode;
 | 
				
			||||||
import com.owncloud.android.lib.test_project.TestActivity;
 | 
					import com.owncloud.android.lib.test_project.TestActivity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import android.test.ActivityInstrumentationTestCase2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Class to test Create Folder Operation
 | 
					 * Class to test Create Folder Operation
 | 
				
			||||||
 * @author masensio
 | 
					 * @author masensio
 | 
				
			||||||
 * @author David A. Velasco
 | 
					 * @author David A. Velasco
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActivity> {
 | 
					public class CreateFolderTest extends RemoteTest {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	private static final String LOG_TAG = CreateFolderTest.class.getCanonicalName();
 | 
						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 static final String FOLDER_PATH_BASE = "/testCreateFolder";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private TestActivity mActivity;
 | 
						private TestActivity mActivity;
 | 
				
			||||||
	private String mCurrentDate;
 | 
					 | 
				
			||||||
	private List<String> mCreatedFolderPaths;
 | 
						private List<String> mCreatedFolderPaths;
 | 
				
			||||||
 | 
						private String mFullPath2FolderBase; 
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public CreateFolderTest() {
 | 
						public CreateFolderTest() {
 | 
				
			||||||
	    super(TestActivity.class);
 | 
						    super();
 | 
				
			||||||
	   
 | 
					 | 
				
			||||||
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
 | 
					 | 
				
			||||||
		mCurrentDate = sdf.format(new Date());
 | 
					 | 
				
			||||||
		mCreatedFolderPaths = new ArrayList<String>();
 | 
							mCreatedFolderPaths = new ArrayList<String>();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	  protected void setUp() throws Exception {
 | 
						  protected void setUp() throws Exception {
 | 
				
			||||||
	    super.setUp();
 | 
						    super.setUp();
 | 
				
			||||||
	    setActivityInitialTouchMode(false);
 | 
					 | 
				
			||||||
	    mActivity = getActivity();
 | 
						    mActivity = getActivity();
 | 
				
			||||||
	    mCreatedFolderPaths.clear();
 | 
						    mCreatedFolderPaths.clear();
 | 
				
			||||||
 | 
							mFullPath2FolderBase = mBaseFolderPath + FOLDER_PATH_BASE; 
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Test Create Folder
 | 
						 * Test Create Folder
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void testCreateFolder() {
 | 
						public void testCreateFolder() {
 | 
				
			||||||
		String remotePath = FOLDER_PATH_BASE + mCurrentDate;
 | 
							String remotePath = mFullPath2FolderBase;
 | 
				
			||||||
		mCreatedFolderPaths.add(remotePath);
 | 
							mCreatedFolderPaths.add(remotePath);
 | 
				
			||||||
		RemoteOperationResult result =  mActivity.createFolder(remotePath, true);
 | 
							RemoteOperationResult result =  mActivity.createFolder(remotePath, true);
 | 
				
			||||||
		assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
 | 
							assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		// Create Subfolder
 | 
							// Create Subfolder
 | 
				
			||||||
		remotePath = FOLDER_PATH_BASE + mCurrentDate + FOLDER_PATH_BASE + mCurrentDate;
 | 
							remotePath = mFullPath2FolderBase + FOLDER_PATH_BASE;
 | 
				
			||||||
		mCreatedFolderPaths.add(remotePath);
 | 
							mCreatedFolderPaths.add(remotePath);
 | 
				
			||||||
		result =  mActivity.createFolder(remotePath, true);
 | 
							result =  mActivity.createFolder(remotePath, true);
 | 
				
			||||||
		assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
 | 
							assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
 | 
				
			||||||
@ -90,35 +83,35 @@ public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActiv
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void testCreateFolderSpecialCharacters() {		
 | 
						public void testCreateFolderSpecialCharacters() {		
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		String remotePath = FOLDER_PATH_BASE + "_\\" + mCurrentDate;
 | 
							String remotePath = mFullPath2FolderBase + "_\\";
 | 
				
			||||||
		RemoteOperationResult result =  mActivity.createFolder(remotePath, true);
 | 
							RemoteOperationResult result =  mActivity.createFolder(remotePath, true);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		remotePath = FOLDER_PATH_BASE + "_<" + mCurrentDate;		
 | 
							remotePath = mFullPath2FolderBase + "_<";		
 | 
				
			||||||
		result =  mActivity.createFolder(remotePath, true);
 | 
							result =  mActivity.createFolder(remotePath, true);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		remotePath = FOLDER_PATH_BASE + "_>" + mCurrentDate;		
 | 
							remotePath = mFullPath2FolderBase + "_>";		
 | 
				
			||||||
		result =  mActivity.createFolder(remotePath, true);
 | 
							result =  mActivity.createFolder(remotePath, true);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		remotePath = FOLDER_PATH_BASE + "_:" + mCurrentDate;		
 | 
							remotePath = mFullPath2FolderBase + "_:";		
 | 
				
			||||||
		result =  mActivity.createFolder(remotePath, true);
 | 
							result =  mActivity.createFolder(remotePath, true);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		remotePath = FOLDER_PATH_BASE + "_\"" + mCurrentDate;		
 | 
							remotePath = mFullPath2FolderBase + "_\"";		
 | 
				
			||||||
		result =  mActivity.createFolder(remotePath, true);
 | 
							result =  mActivity.createFolder(remotePath, true);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		remotePath = FOLDER_PATH_BASE + "_|" + mCurrentDate;		
 | 
							remotePath = mFullPath2FolderBase + "_|";		
 | 
				
			||||||
		result =  mActivity.createFolder(remotePath, true);
 | 
							result =  mActivity.createFolder(remotePath, true);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		remotePath = FOLDER_PATH_BASE + "_?" + mCurrentDate;		
 | 
							remotePath = mFullPath2FolderBase + "_?";		
 | 
				
			||||||
		result =  mActivity.createFolder(remotePath, true);
 | 
							result =  mActivity.createFolder(remotePath, true);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		remotePath = FOLDER_PATH_BASE + "_*" + mCurrentDate;		
 | 
							remotePath = mFullPath2FolderBase + "_*";		
 | 
				
			||||||
		result =  mActivity.createFolder(remotePath, true);
 | 
							result =  mActivity.createFolder(remotePath, true);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -130,7 +123,7 @@ public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActiv
 | 
				
			|||||||
		RemoteOperationResult removeResult = null;
 | 
							RemoteOperationResult removeResult = null;
 | 
				
			||||||
		while (it.hasNext()) {
 | 
							while (it.hasNext()) {
 | 
				
			||||||
			removeResult = mActivity.removeFile(it.next());
 | 
								removeResult = mActivity.removeFile(it.next());
 | 
				
			||||||
			if (!removeResult.isSuccess()) {
 | 
								if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
 | 
				
			||||||
				Utils.logAndThrow(LOG_TAG, removeResult);
 | 
									Utils.logAndThrow(LOG_TAG, removeResult);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -27,12 +27,11 @@ package com.owncloud.android.lib.test_project.test;
 | 
				
			|||||||
import java.io.File;
 | 
					import java.io.File;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 | 
					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.resources.shares.ShareType;
 | 
				
			||||||
import com.owncloud.android.lib.test_project.TestActivity;
 | 
					import com.owncloud.android.lib.test_project.TestActivity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import android.test.ActivityInstrumentationTestCase2;
 | 
					public class CreateShareTest extends RemoteTest {
 | 
				
			||||||
 | 
					 | 
				
			||||||
public class CreateShareTest extends ActivityInstrumentationTestCase2<TestActivity> {
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private static final String LOG_TAG = CreateShareTest.class.getCanonicalName();
 | 
						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 static final String FILE_TO_SHARE = "/fileToShare.txt";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private TestActivity mActivity;
 | 
						private TestActivity mActivity;
 | 
				
			||||||
 | 
						private String mFullPath2FileToShare;
 | 
				
			||||||
	public CreateShareTest() {
 | 
					 | 
				
			||||||
		super(TestActivity.class);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	protected void setUp() throws Exception {
 | 
						protected void setUp() throws Exception {
 | 
				
			||||||
	    super.setUp();
 | 
						    super.setUp();
 | 
				
			||||||
	    setActivityInitialTouchMode(false);
 | 
						    setActivityInitialTouchMode(false);
 | 
				
			||||||
	    mActivity = getActivity();
 | 
						    mActivity = getActivity();
 | 
				
			||||||
 | 
						    mFullPath2FileToShare = mBaseFolderPath + FILE_TO_SHARE;  
 | 
				
			||||||
	    		
 | 
						    		
 | 
				
			||||||
		File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
 | 
							File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
 | 
				
			||||||
		RemoteOperationResult result = mActivity.uploadFile(
 | 
							RemoteOperationResult result = mActivity.uploadFile(
 | 
				
			||||||
				textFile.getAbsolutePath(), 
 | 
									textFile.getAbsolutePath(), 
 | 
				
			||||||
				FILE_TO_SHARE, 
 | 
									mFullPath2FileToShare, 
 | 
				
			||||||
				"txt/plain");
 | 
									"txt/plain");
 | 
				
			||||||
		if (!result.isSuccess()) {
 | 
							if (!result.isSuccess()) {
 | 
				
			||||||
			Utils.logAndThrow(LOG_TAG, result);
 | 
								Utils.logAndThrow(LOG_TAG, result);
 | 
				
			||||||
@ -67,7 +63,7 @@ public class CreateShareTest extends ActivityInstrumentationTestCase2<TestActivi
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void testCreatePublicShare() {
 | 
						public void testCreatePublicShare() {
 | 
				
			||||||
		RemoteOperationResult result = mActivity.createShare(
 | 
							RemoteOperationResult result = mActivity.createShare(
 | 
				
			||||||
				FILE_TO_SHARE, 
 | 
									mFullPath2FileToShare, 
 | 
				
			||||||
				ShareType.PUBLIC_LINK, 
 | 
									ShareType.PUBLIC_LINK, 
 | 
				
			||||||
				"", 
 | 
									"", 
 | 
				
			||||||
				false, 
 | 
									false, 
 | 
				
			||||||
@ -79,8 +75,8 @@ public class CreateShareTest extends ActivityInstrumentationTestCase2<TestActivi
 | 
				
			|||||||
	
 | 
						
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	protected void tearDown() throws Exception {
 | 
						protected void tearDown() throws Exception {
 | 
				
			||||||
		RemoteOperationResult removeResult = mActivity.removeFile(FILE_TO_SHARE);
 | 
							RemoteOperationResult removeResult = mActivity.removeFile(mFullPath2FileToShare);
 | 
				
			||||||
		if (!removeResult.isSuccess()) {
 | 
							if (!removeResult.isSuccess()  && removeResult.getCode() != ResultCode.TIMEOUT) {
 | 
				
			||||||
			Utils.logAndThrow(LOG_TAG, removeResult);
 | 
								Utils.logAndThrow(LOG_TAG, removeResult);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		super.tearDown();
 | 
							super.tearDown();
 | 
				
			||||||
 | 
				
			|||||||
@ -27,18 +27,16 @@ package com.owncloud.android.lib.test_project.test;
 | 
				
			|||||||
import java.io.File;
 | 
					import java.io.File;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 | 
					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.test_project.TestActivity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import android.test.ActivityInstrumentationTestCase2;
 | 
					 | 
				
			||||||
import android.util.Log;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Class to test Delete a File Operation
 | 
					 * Class to test Delete a File Operation
 | 
				
			||||||
 * @author masensio
 | 
					 * @author masensio
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class DeleteFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
 | 
					public class DeleteFileTest extends RemoteTest {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private static final String LOG_TAG = DeleteFileTest.class.getCanonicalName();
 | 
						private static final String LOG_TAG = DeleteFileTest.class.getCanonicalName();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -48,41 +46,32 @@ public class DeleteFileTest extends ActivityInstrumentationTestCase2<TestActivit
 | 
				
			|||||||
	/* File to delete. */
 | 
						/* File to delete. */
 | 
				
			||||||
	private static final String FILE_PATH = "/fileToDelete.txt";
 | 
						private static final String FILE_PATH = "/fileToDelete.txt";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private static boolean mGlobalSetupDone = false;
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	private TestActivity mActivity;
 | 
						private TestActivity mActivity;
 | 
				
			||||||
	
 | 
						private String mFullPath2Folder; 
 | 
				
			||||||
	public DeleteFileTest() {
 | 
						private String mFullPath2File; 
 | 
				
			||||||
	    super(TestActivity.class);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	  protected void setUp() throws Exception {
 | 
						  protected void setUp() throws Exception {
 | 
				
			||||||
	    super.setUp();
 | 
						    super.setUp();
 | 
				
			||||||
	    setActivityInitialTouchMode(false);
 | 
						    setActivityInitialTouchMode(false);
 | 
				
			||||||
	    mActivity = getActivity();
 | 
						    mActivity = getActivity();
 | 
				
			||||||
 | 
							mFullPath2Folder = mBaseFolderPath + FOLDER_PATH; 
 | 
				
			||||||
 | 
							mFullPath2File = mBaseFolderPath + FILE_PATH;
 | 
				
			||||||
	    
 | 
						    
 | 
				
			||||||
	    if (!mGlobalSetupDone) {
 | 
							RemoteOperationResult result = mActivity.createFolder(mFullPath2Folder, true);
 | 
				
			||||||
	    	
 | 
							if (!result.isSuccess()  && result.getCode() != ResultCode.TIMEOUT) {
 | 
				
			||||||
			Log.v(LOG_TAG, "Starting global set up");
 | 
					 | 
				
			||||||
			RemoteOperationResult result = mActivity.createFolder(FOLDER_PATH, true);
 | 
					 | 
				
			||||||
			if (!result.isSuccess()) {
 | 
					 | 
				
			||||||
			Utils.logAndThrow(LOG_TAG, result);
 | 
								Utils.logAndThrow(LOG_TAG, result);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
 | 
							File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
 | 
				
			||||||
		result = mActivity.uploadFile(
 | 
							result = mActivity.uploadFile(
 | 
				
			||||||
				textFile.getAbsolutePath(), 
 | 
									textFile.getAbsolutePath(), 
 | 
				
			||||||
					FILE_PATH, 
 | 
									mFullPath2File, 
 | 
				
			||||||
				"txt/plain");
 | 
									"txt/plain");
 | 
				
			||||||
		if (!result.isSuccess()) {
 | 
							if (!result.isSuccess()) {
 | 
				
			||||||
			Utils.logAndThrow(LOG_TAG, result);
 | 
								Utils.logAndThrow(LOG_TAG, result);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
			Log.v(LOG_TAG, "Global set up done");
 | 
					 | 
				
			||||||
		    mGlobalSetupDone = true;
 | 
					 | 
				
			||||||
	    }
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
@ -90,7 +79,7 @@ public class DeleteFileTest extends ActivityInstrumentationTestCase2<TestActivit
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void testRemoveFolder() {
 | 
						public void testRemoveFolder() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		RemoteOperationResult result = mActivity.removeFile(FOLDER_PATH);
 | 
							RemoteOperationResult result = mActivity.removeFile(mFullPath2Folder);
 | 
				
			||||||
		assertTrue(result.isSuccess());
 | 
							assertTrue(result.isSuccess());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
@ -99,7 +88,7 @@ public class DeleteFileTest extends ActivityInstrumentationTestCase2<TestActivit
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void testRemoveFile() {
 | 
						public void testRemoveFile() {
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		RemoteOperationResult result = mActivity.removeFile(FILE_PATH);
 | 
							RemoteOperationResult result = mActivity.removeFile(mFullPath2File);
 | 
				
			||||||
		assertTrue(result.isSuccess());
 | 
							assertTrue(result.isSuccess());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -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.common.operations.RemoteOperationResult.ResultCode;
 | 
				
			||||||
import com.owncloud.android.lib.test_project.TestActivity;
 | 
					import com.owncloud.android.lib.test_project.TestActivity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import android.test.ActivityInstrumentationTestCase2;
 | 
					 | 
				
			||||||
import android.util.Log;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Class to test Download File Operation
 | 
					 * Class to test Download File Operation
 | 
				
			||||||
 * @author masensio
 | 
					 * @author masensio
 | 
				
			||||||
 * @author David A. Velasco
 | 
					 * @author David A. Velasco
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class DownloadFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
 | 
					public class DownloadFileTest extends RemoteTest {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	private static final String LOG_TAG = DownloadFileTest.class.getCanonicalName();
 | 
						private static final String LOG_TAG = DownloadFileTest.class.getCanonicalName();
 | 
				
			||||||
@ -49,47 +46,45 @@ public class DownloadFileTest extends ActivityInstrumentationTestCase2<TestActiv
 | 
				
			|||||||
	private static final String IMAGE_PATH = "/fileToDownload.png";
 | 
						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_PATH_WITH_SPECIAL_CHARS = "/@file@download.png";
 | 
				
			||||||
	private static final String IMAGE_NOT_FOUND = "/fileNotFound.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 String mDownloadedFilePath;
 | 
				
			||||||
	private TestActivity mActivity;
 | 
						private TestActivity mActivity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public DownloadFileTest() {
 | 
					 | 
				
			||||||
	    super(TestActivity.class);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	  protected void setUp() throws Exception {
 | 
						  protected void setUp() throws Exception {
 | 
				
			||||||
	    super.setUp();
 | 
						    super.setUp();
 | 
				
			||||||
	    setActivityInitialTouchMode(false);
 | 
						    setActivityInitialTouchMode(false);
 | 
				
			||||||
	    mActivity = getActivity();
 | 
						    mActivity = getActivity();
 | 
				
			||||||
	    mDownloadedFilePath = null;
 | 
						    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++) {
 | 
					    	RemoteOperationResult result = mActivity.uploadFile(
 | 
				
			||||||
				result = mActivity.uploadFile(
 | 
					 | 
				
			||||||
				imageFile.getAbsolutePath(), 
 | 
									imageFile.getAbsolutePath(), 
 | 
				
			||||||
						FILE_PATHS[i], 
 | 
									mFullPath2Image, 
 | 
				
			||||||
				"image/png");
 | 
									"image/png");
 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		if (!result.isSuccess()) {
 | 
							if (!result.isSuccess()) {
 | 
				
			||||||
			Utils.logAndThrow(LOG_TAG, result);
 | 
								Utils.logAndThrow(LOG_TAG, result);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
			result = mActivity.removeFile(IMAGE_NOT_FOUND);
 | 
							result = mActivity.uploadFile(
 | 
				
			||||||
			if (!result.isSuccess() && result.getCode() != ResultCode.FILE_NOT_FOUND) {
 | 
									imageFile.getAbsolutePath(), 
 | 
				
			||||||
 | 
									mFullPath2ImageWitSpecialChars, 
 | 
				
			||||||
 | 
									"image/png");
 | 
				
			||||||
 | 
							if (!result.isSuccess()) {
 | 
				
			||||||
			Utils.logAndThrow(LOG_TAG, result);
 | 
								Utils.logAndThrow(LOG_TAG, result);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
			Log.v(LOG_TAG, "Global set up done");
 | 
							result = mActivity.removeFile(mFullPath2ImageNotFound);
 | 
				
			||||||
		    mGlobalSetupDone = true;
 | 
							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() {
 | 
						public void testDownloadFile() {
 | 
				
			||||||
		RemoteOperationResult result = mActivity.downloadFile(
 | 
							RemoteOperationResult result = mActivity.downloadFile(
 | 
				
			||||||
				new RemoteFile(IMAGE_PATH), 
 | 
									new RemoteFile(mFullPath2Image), 
 | 
				
			||||||
				mActivity.getFilesDir().getAbsolutePath()
 | 
									mActivity.getFilesDir().getAbsolutePath()
 | 
				
			||||||
				);
 | 
									);
 | 
				
			||||||
		mDownloadedFilePath = IMAGE_PATH;
 | 
							mDownloadedFilePath = mFullPath2Image;
 | 
				
			||||||
		assertTrue(result.isSuccess());
 | 
							assertTrue(result.isSuccess());
 | 
				
			||||||
		// TODO some checks involving the local file
 | 
							// TODO some checks involving the local file
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -112,10 +107,10 @@ public class DownloadFileTest extends ActivityInstrumentationTestCase2<TestActiv
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void testDownloadFileSpecialChars() {
 | 
						public void testDownloadFileSpecialChars() {
 | 
				
			||||||
		RemoteOperationResult result = mActivity.downloadFile(
 | 
							RemoteOperationResult result = mActivity.downloadFile(
 | 
				
			||||||
				new RemoteFile(IMAGE_PATH_WITH_SPECIAL_CHARS),
 | 
									new RemoteFile(mFullPath2ImageWitSpecialChars),
 | 
				
			||||||
				mActivity.getFilesDir().getAbsolutePath()
 | 
									mActivity.getFilesDir().getAbsolutePath()
 | 
				
			||||||
				);
 | 
									);
 | 
				
			||||||
		mDownloadedFilePath = IMAGE_PATH_WITH_SPECIAL_CHARS;
 | 
							mDownloadedFilePath = mFullPath2ImageWitSpecialChars;
 | 
				
			||||||
		assertTrue(result.isSuccess());
 | 
							assertTrue(result.isSuccess());
 | 
				
			||||||
		// TODO some checks involving the local file
 | 
							// TODO some checks involving the local file
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -125,7 +120,7 @@ public class DownloadFileTest extends ActivityInstrumentationTestCase2<TestActiv
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void testDownloadFileNotFound() {
 | 
						public void testDownloadFileNotFound() {
 | 
				
			||||||
		RemoteOperationResult result = mActivity.downloadFile(
 | 
							RemoteOperationResult result = mActivity.downloadFile(
 | 
				
			||||||
				new RemoteFile(IMAGE_NOT_FOUND), 
 | 
									new RemoteFile(mFullPath2ImageNotFound), 
 | 
				
			||||||
				mActivity.getFilesDir().getAbsolutePath()
 | 
									mActivity.getFilesDir().getAbsolutePath()
 | 
				
			||||||
				);
 | 
									);
 | 
				
			||||||
		assertFalse(result.isSuccess());
 | 
							assertFalse(result.isSuccess());
 | 
				
			||||||
@ -136,7 +131,7 @@ public class DownloadFileTest extends ActivityInstrumentationTestCase2<TestActiv
 | 
				
			|||||||
	protected void tearDown() throws Exception {
 | 
						protected void tearDown() throws Exception {
 | 
				
			||||||
		if (mDownloadedFilePath != null) {
 | 
							if (mDownloadedFilePath != null) {
 | 
				
			||||||
			RemoteOperationResult removeResult = mActivity.removeFile(mDownloadedFilePath);
 | 
								RemoteOperationResult removeResult = mActivity.removeFile(mDownloadedFilePath);
 | 
				
			||||||
			if (!removeResult.isSuccess()) {
 | 
								if (!removeResult.isSuccess()  && removeResult.getCode() != ResultCode.TIMEOUT) {
 | 
				
			||||||
				Utils.logAndThrow(LOG_TAG, removeResult);
 | 
									Utils.logAndThrow(LOG_TAG, removeResult);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -27,11 +27,10 @@ package com.owncloud.android.lib.test_project.test;
 | 
				
			|||||||
import java.io.File;
 | 
					import java.io.File;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 | 
					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.resources.shares.ShareType;
 | 
				
			||||||
import com.owncloud.android.lib.test_project.TestActivity;
 | 
					import com.owncloud.android.lib.test_project.TestActivity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import android.test.ActivityInstrumentationTestCase2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/** 
 | 
					/** 
 | 
				
			||||||
 * Class to test Get Shares Operation
 | 
					 * 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 LOG_TAG = GetSharesTest.class.getCanonicalName();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private static final String SHARED_FILE = "/sharedFileToGet.txt";
 | 
						private static final String SHARED_FILE = "/sharedFileToGet.txt";
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	private TestActivity mActivity;
 | 
						private TestActivity mActivity;
 | 
				
			||||||
	
 | 
						private String mFullPath2SharedFile;
 | 
				
			||||||
	public GetSharesTest() {
 | 
					 | 
				
			||||||
		super(TestActivity.class);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	  protected void setUp() throws Exception {
 | 
						  protected void setUp() throws Exception {
 | 
				
			||||||
	    super.setUp();
 | 
						    super.setUp();
 | 
				
			||||||
	    setActivityInitialTouchMode(false);
 | 
						    setActivityInitialTouchMode(false);
 | 
				
			||||||
	    mActivity = getActivity();
 | 
						    mActivity = getActivity();
 | 
				
			||||||
 | 
						    mFullPath2SharedFile = mBaseFolderPath + SHARED_FILE; 
 | 
				
			||||||
	    		
 | 
						    		
 | 
				
			||||||
		File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
 | 
							File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
 | 
				
			||||||
		RemoteOperationResult result = mActivity.uploadFile(
 | 
							RemoteOperationResult result = mActivity.uploadFile(
 | 
				
			||||||
				textFile.getAbsolutePath(), 
 | 
									textFile.getAbsolutePath(), 
 | 
				
			||||||
				SHARED_FILE, 
 | 
									mFullPath2SharedFile, 
 | 
				
			||||||
				"txt/plain");
 | 
									"txt/plain");
 | 
				
			||||||
		if (!result.isSuccess()) {
 | 
							if (!result.isSuccess()) {
 | 
				
			||||||
			Utils.logAndThrow(LOG_TAG, result);
 | 
								Utils.logAndThrow(LOG_TAG, result);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		result = mActivity.createShare(SHARED_FILE, ShareType.PUBLIC_LINK, "", false, "", 1);
 | 
							result = mActivity.createShare(mFullPath2SharedFile, ShareType.PUBLIC_LINK, "", false, "", 1);
 | 
				
			||||||
		if (!result.isSuccess()) {
 | 
							if (!result.isSuccess()  && result.getCode() != ResultCode.TIMEOUT) {
 | 
				
			||||||
			Utils.logAndThrow(LOG_TAG, result);
 | 
								Utils.logAndThrow(LOG_TAG, result);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
@ -86,8 +82,8 @@ public class GetSharesTest extends ActivityInstrumentationTestCase2<TestActivity
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	protected void tearDown() throws Exception {
 | 
						protected void tearDown() throws Exception {
 | 
				
			||||||
		RemoteOperationResult removeResult = mActivity.removeFile(SHARED_FILE);
 | 
							RemoteOperationResult removeResult = mActivity.removeFile(mFullPath2SharedFile);
 | 
				
			||||||
		if (!removeResult.isSuccess()) {
 | 
							if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
 | 
				
			||||||
			Utils.logAndThrow(LOG_TAG, removeResult);
 | 
								Utils.logAndThrow(LOG_TAG, removeResult);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		super.tearDown();
 | 
							super.tearDown();
 | 
				
			||||||
 | 
				
			|||||||
@ -46,8 +46,6 @@ import com.owncloud.android.lib.test_project.TestActivity;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import android.content.Context;
 | 
					import android.content.Context;
 | 
				
			||||||
import android.net.Uri;
 | 
					import android.net.Uri;
 | 
				
			||||||
import android.test.ActivityInstrumentationTestCase2;
 | 
					 | 
				
			||||||
//import android.test.AndroidTestCase;
 | 
					 | 
				
			||||||
import android.util.Log;
 | 
					import android.util.Log;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@ -69,7 +67,7 @@ import android.util.Log;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//public class MoveFileTest extends AndroidTestCase {
 | 
					//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();
 | 
						private static final String LOG_TAG = MoveFileTest.class.getCanonicalName();
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
@ -209,7 +207,7 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
 | 
				
			|||||||
	OwnCloudClient mClient = null;
 | 
						OwnCloudClient mClient = null;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public MoveFileTest() {
 | 
						public MoveFileTest() {
 | 
				
			||||||
		super(TestActivity.class);
 | 
							super();
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		Protocol pr = Protocol.getProtocol("https");
 | 
							Protocol pr = Protocol.getProtocol("https");
 | 
				
			||||||
		if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
 | 
							if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
 | 
				
			||||||
@ -244,8 +242,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
 | 
				
			|||||||
	    
 | 
						    
 | 
				
			||||||
	    RemoteOperationResult result = null;
 | 
						    RemoteOperationResult result = null;
 | 
				
			||||||
	    for (String folderPath : FOLDERS_IN_FIXTURE) {
 | 
						    for (String folderPath : FOLDERS_IN_FIXTURE) {
 | 
				
			||||||
	    	result = TestActivity.createFolder(folderPath, true, mClient);
 | 
						    	result = TestActivity.createFolder(mBaseFolderPath + folderPath, true, mClient);
 | 
				
			||||||
			if (!result.isSuccess()) {
 | 
								if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) {
 | 
				
			||||||
				Utils.logAndThrow(LOG_TAG, result);
 | 
									Utils.logAndThrow(LOG_TAG, result);
 | 
				
			||||||
			}	    	
 | 
								}	    	
 | 
				
			||||||
	    }
 | 
						    }
 | 
				
			||||||
@ -255,7 +253,7 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
 | 
				
			|||||||
		);
 | 
							);
 | 
				
			||||||
	    for (String filePath : FILES_IN_FIXTURE) {
 | 
						    for (String filePath : FILES_IN_FIXTURE) {
 | 
				
			||||||
	    	result = TestActivity.uploadFile(
 | 
						    	result = TestActivity.uploadFile(
 | 
				
			||||||
	    			txtFile.getAbsolutePath(), filePath, "txt/plain", mClient
 | 
						    			txtFile.getAbsolutePath(), mBaseFolderPath + filePath, "txt/plain", mClient
 | 
				
			||||||
			);
 | 
								);
 | 
				
			||||||
			if (!result.isSuccess()) {
 | 
								if (!result.isSuccess()) {
 | 
				
			||||||
				Utils.logAndThrow(LOG_TAG, result);
 | 
									Utils.logAndThrow(LOG_TAG, result);
 | 
				
			||||||
@ -277,8 +275,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		// move file
 | 
							// move file
 | 
				
			||||||
		MoveRemoteFileOperation moveOperation = new MoveRemoteFileOperation(
 | 
							MoveRemoteFileOperation moveOperation = new MoveRemoteFileOperation(
 | 
				
			||||||
				SRC_PATH_TO_FILE_1,
 | 
									mBaseFolderPath + SRC_PATH_TO_FILE_1,
 | 
				
			||||||
				TARGET_PATH_TO_FILE_1,
 | 
									mBaseFolderPath + TARGET_PATH_TO_FILE_1,
 | 
				
			||||||
				false
 | 
									false
 | 
				
			||||||
		);
 | 
							);
 | 
				
			||||||
		RemoteOperationResult result = moveOperation.execute(mClient);
 | 
							RemoteOperationResult result = moveOperation.execute(mClient);
 | 
				
			||||||
@ -286,8 +284,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		// move & rename file, different location
 | 
							// move & rename file, different location
 | 
				
			||||||
		moveOperation = new MoveRemoteFileOperation(
 | 
							moveOperation = new MoveRemoteFileOperation(
 | 
				
			||||||
				SRC_PATH_TO_FILE_2,
 | 
									mBaseFolderPath + SRC_PATH_TO_FILE_2,
 | 
				
			||||||
				TARGET_PATH_TO_FILE_2_RENAMED,
 | 
									mBaseFolderPath + TARGET_PATH_TO_FILE_2_RENAMED,
 | 
				
			||||||
				false
 | 
									false
 | 
				
			||||||
		);
 | 
							);
 | 
				
			||||||
		result = moveOperation.execute(mClient);
 | 
							result = moveOperation.execute(mClient);
 | 
				
			||||||
@ -295,8 +293,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		// move & rename file, same location (rename file)
 | 
							// move & rename file, same location (rename file)
 | 
				
			||||||
		moveOperation = new MoveRemoteFileOperation(
 | 
							moveOperation = new MoveRemoteFileOperation(
 | 
				
			||||||
				SRC_PATH_TO_FILE_3,
 | 
									mBaseFolderPath + SRC_PATH_TO_FILE_3,
 | 
				
			||||||
				SRC_PATH_TO_FILE_3_RENAMED,
 | 
									mBaseFolderPath + SRC_PATH_TO_FILE_3_RENAMED,
 | 
				
			||||||
				false
 | 
									false
 | 
				
			||||||
		);
 | 
							);
 | 
				
			||||||
		result = moveOperation.execute(mClient);
 | 
							result = moveOperation.execute(mClient);
 | 
				
			||||||
@ -304,8 +302,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		// move empty folder
 | 
							// move empty folder
 | 
				
			||||||
		moveOperation = new MoveRemoteFileOperation(
 | 
							moveOperation = new MoveRemoteFileOperation(
 | 
				
			||||||
				SRC_PATH_TO_EMPTY_FOLDER,
 | 
									mBaseFolderPath + SRC_PATH_TO_EMPTY_FOLDER,
 | 
				
			||||||
				TARGET_PATH_TO_EMPTY_FOLDER,
 | 
									mBaseFolderPath + TARGET_PATH_TO_EMPTY_FOLDER,
 | 
				
			||||||
				false
 | 
									false
 | 
				
			||||||
		);
 | 
							);
 | 
				
			||||||
		result = moveOperation.execute(mClient);
 | 
							result = moveOperation.execute(mClient);
 | 
				
			||||||
@ -313,8 +311,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		// move non-empty folder
 | 
							// move non-empty folder
 | 
				
			||||||
		moveOperation = new MoveRemoteFileOperation(
 | 
							moveOperation = new MoveRemoteFileOperation(
 | 
				
			||||||
				SRC_PATH_TO_FULL_FOLDER_1,
 | 
									mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_1,
 | 
				
			||||||
				TARGET_PATH_TO_FULL_FOLDER_1,
 | 
									mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_1,
 | 
				
			||||||
				false
 | 
									false
 | 
				
			||||||
		);
 | 
							);
 | 
				
			||||||
		result = moveOperation.execute(mClient);
 | 
							result = moveOperation.execute(mClient);
 | 
				
			||||||
@ -322,8 +320,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		// move & rename folder, different location
 | 
							// move & rename folder, different location
 | 
				
			||||||
		moveOperation = new MoveRemoteFileOperation(
 | 
							moveOperation = new MoveRemoteFileOperation(
 | 
				
			||||||
				SRC_PATH_TO_FULL_FOLDER_2,
 | 
									mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_2,
 | 
				
			||||||
				TARGET_PATH_TO_FULL_FOLDER_2_RENAMED,
 | 
									mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_2_RENAMED,
 | 
				
			||||||
				false
 | 
									false
 | 
				
			||||||
		);
 | 
							);
 | 
				
			||||||
		result = moveOperation.execute(mClient);
 | 
							result = moveOperation.execute(mClient);
 | 
				
			||||||
@ -331,8 +329,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		// move & rename folder, same location (rename folder)
 | 
							// move & rename folder, same location (rename folder)
 | 
				
			||||||
		moveOperation = new MoveRemoteFileOperation(
 | 
							moveOperation = new MoveRemoteFileOperation(
 | 
				
			||||||
				SRC_PATH_TO_FULL_FOLDER_3,
 | 
									mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_3,
 | 
				
			||||||
				SRC_PATH_TO_FULL_FOLDER_3_RENAMED,
 | 
									mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_3_RENAMED,
 | 
				
			||||||
				false
 | 
									false
 | 
				
			||||||
		);
 | 
							);
 | 
				
			||||||
		result = moveOperation.execute(mClient);
 | 
							result = moveOperation.execute(mClient);
 | 
				
			||||||
@ -340,8 +338,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		// move for nothing (success, but no interaction with network)
 | 
							// move for nothing (success, but no interaction with network)
 | 
				
			||||||
		moveOperation = new MoveRemoteFileOperation(
 | 
							moveOperation = new MoveRemoteFileOperation(
 | 
				
			||||||
				SRC_PATH_TO_FILE_4,
 | 
									mBaseFolderPath + SRC_PATH_TO_FILE_4,
 | 
				
			||||||
				SRC_PATH_TO_FILE_4,
 | 
									mBaseFolderPath + SRC_PATH_TO_FILE_4,
 | 
				
			||||||
				false
 | 
									false
 | 
				
			||||||
		);
 | 
							);
 | 
				
			||||||
		result = moveOperation.execute(mClient);
 | 
							result = moveOperation.execute(mClient);
 | 
				
			||||||
@ -349,8 +347,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		// move overwriting
 | 
							// move overwriting
 | 
				
			||||||
		moveOperation = new MoveRemoteFileOperation(
 | 
							moveOperation = new MoveRemoteFileOperation(
 | 
				
			||||||
						SRC_PATH_TO_FULL_FOLDER_4,
 | 
									mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_4,
 | 
				
			||||||
						TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4,
 | 
									mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4,
 | 
				
			||||||
				true
 | 
									true
 | 
				
			||||||
		);
 | 
							);
 | 
				
			||||||
		result = moveOperation.execute(mClient);
 | 
							result = moveOperation.execute(mClient);
 | 
				
			||||||
@ -361,8 +359,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		// file to move does not exist
 | 
							// file to move does not exist
 | 
				
			||||||
		moveOperation = new MoveRemoteFileOperation(
 | 
							moveOperation = new MoveRemoteFileOperation(
 | 
				
			||||||
						SRC_PATH_TO_NON_EXISTENT_FILE,
 | 
									mBaseFolderPath + SRC_PATH_TO_NON_EXISTENT_FILE,
 | 
				
			||||||
						TARGET_PATH_TO_NON_EXISTENT_FILE,
 | 
									mBaseFolderPath + TARGET_PATH_TO_NON_EXISTENT_FILE,
 | 
				
			||||||
				false
 | 
									false
 | 
				
			||||||
		);
 | 
							);
 | 
				
			||||||
		result = moveOperation.execute(mClient);
 | 
							result = moveOperation.execute(mClient);
 | 
				
			||||||
@ -370,8 +368,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		// folder to move into does no exist
 | 
							// folder to move into does no exist
 | 
				
			||||||
		moveOperation = new MoveRemoteFileOperation(
 | 
							moveOperation = new MoveRemoteFileOperation(
 | 
				
			||||||
						SRC_PATH_TO_FILE_5,
 | 
									mBaseFolderPath + SRC_PATH_TO_FILE_5,
 | 
				
			||||||
						TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER,
 | 
									mBaseFolderPath + TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER,
 | 
				
			||||||
				false
 | 
									false
 | 
				
			||||||
		);
 | 
							);
 | 
				
			||||||
		result = moveOperation.execute(mClient);
 | 
							result = moveOperation.execute(mClient);
 | 
				
			||||||
@ -379,8 +377,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		// target location (renaming) has invalid characters
 | 
							// target location (renaming) has invalid characters
 | 
				
			||||||
		moveOperation = new MoveRemoteFileOperation(
 | 
							moveOperation = new MoveRemoteFileOperation(
 | 
				
			||||||
						SRC_PATH_TO_FILE_6,
 | 
									mBaseFolderPath + SRC_PATH_TO_FILE_6,
 | 
				
			||||||
						TARGET_PATH_RENAMED_WITH_INVALID_CHARS,
 | 
									mBaseFolderPath + TARGET_PATH_RENAMED_WITH_INVALID_CHARS,
 | 
				
			||||||
				false
 | 
									false
 | 
				
			||||||
		);
 | 
							);
 | 
				
			||||||
		result = moveOperation.execute(mClient);
 | 
							result = moveOperation.execute(mClient);
 | 
				
			||||||
@ -388,8 +386,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		// name collision
 | 
							// name collision
 | 
				
			||||||
		moveOperation = new MoveRemoteFileOperation(
 | 
							moveOperation = new MoveRemoteFileOperation(
 | 
				
			||||||
						SRC_PATH_TO_FILE_7,
 | 
									mBaseFolderPath + SRC_PATH_TO_FILE_7,
 | 
				
			||||||
						TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7,
 | 
									mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7,
 | 
				
			||||||
				false
 | 
									false
 | 
				
			||||||
		);
 | 
							);
 | 
				
			||||||
		result = moveOperation.execute(mClient);
 | 
							result = moveOperation.execute(mClient);
 | 
				
			||||||
@ -397,8 +395,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		// move a folder into a descendant
 | 
							// move a folder into a descendant
 | 
				
			||||||
		moveOperation = new MoveRemoteFileOperation(
 | 
							moveOperation = new MoveRemoteFileOperation(
 | 
				
			||||||
						SRC_BASE_FOLDER,
 | 
									mBaseFolderPath + SRC_BASE_FOLDER,
 | 
				
			||||||
						SRC_PATH_TO_EMPTY_FOLDER,
 | 
									mBaseFolderPath + SRC_PATH_TO_EMPTY_FOLDER,
 | 
				
			||||||
				false
 | 
									false
 | 
				
			||||||
		);
 | 
							);
 | 
				
			||||||
		result = moveOperation.execute(mClient);
 | 
							result = moveOperation.execute(mClient);
 | 
				
			||||||
@ -411,8 +409,8 @@ public class MoveFileTest extends ActivityInstrumentationTestCase2<TestActivity>
 | 
				
			|||||||
	    Log.v(LOG_TAG, "Deleting remote fixture...");
 | 
						    Log.v(LOG_TAG, "Deleting remote fixture...");
 | 
				
			||||||
	    
 | 
						    
 | 
				
			||||||
		String[] mPathsToCleanUp = {
 | 
							String[] mPathsToCleanUp = {
 | 
				
			||||||
			SRC_BASE_FOLDER,
 | 
									mBaseFolderPath + SRC_BASE_FOLDER,
 | 
				
			||||||
			TARGET_BASE_FOLDER
 | 
									mBaseFolderPath + TARGET_BASE_FOLDER
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		for (String path : mPathsToCleanUp) {
 | 
							for (String path : mPathsToCleanUp) {
 | 
				
			||||||
 | 
				
			|||||||
@ -26,27 +26,23 @@ package com.owncloud.android.lib.test_project.test;
 | 
				
			|||||||
import java.io.File;
 | 
					import java.io.File;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 | 
					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.test_project.TestActivity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import android.test.ActivityInstrumentationTestCase2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Class to test Read File Operation
 | 
					 * Class to test Read File Operation
 | 
				
			||||||
 * @author masensio
 | 
					 * @author masensio
 | 
				
			||||||
 * @author David A. Velasco
 | 
					 * @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 static final String LOG_TAG = ReadFileTest.class.getCanonicalName();
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	private TestActivity mActivity;
 | 
						private TestActivity mActivity;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	private String FILE_PATH = "/fileToRead.txt";
 | 
						private String FILE_PATH = "/fileToRead.txt";
 | 
				
			||||||
	
 | 
						private String mFullPath2File;
 | 
				
			||||||
	public ReadFileTest() {
 | 
					 | 
				
			||||||
		super(TestActivity.class);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	protected void setUp() throws Exception {
 | 
						protected void setUp() throws Exception {
 | 
				
			||||||
@ -54,11 +50,12 @@ public class ReadFileTest extends 	ActivityInstrumentationTestCase2<TestActivity
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		setActivityInitialTouchMode(false);
 | 
							setActivityInitialTouchMode(false);
 | 
				
			||||||
		mActivity = getActivity();
 | 
							mActivity = getActivity();
 | 
				
			||||||
 | 
							mFullPath2File = mBaseFolderPath + FILE_PATH;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
 | 
							File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
 | 
				
			||||||
		RemoteOperationResult uploadResult = mActivity.uploadFile(
 | 
							RemoteOperationResult uploadResult = mActivity.uploadFile(
 | 
				
			||||||
				textFile.getAbsolutePath(), 
 | 
									textFile.getAbsolutePath(), 
 | 
				
			||||||
				FILE_PATH, 
 | 
									mFullPath2File, 
 | 
				
			||||||
				"txt/plain");
 | 
									"txt/plain");
 | 
				
			||||||
		if (!uploadResult.isSuccess()) {
 | 
							if (!uploadResult.isSuccess()) {
 | 
				
			||||||
			Utils.logAndThrow(LOG_TAG, uploadResult);
 | 
								Utils.logAndThrow(LOG_TAG, uploadResult);
 | 
				
			||||||
@ -69,7 +66,7 @@ public class ReadFileTest extends 	ActivityInstrumentationTestCase2<TestActivity
 | 
				
			|||||||
	 * Test Read File
 | 
						 * Test Read File
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void testReadFile() {
 | 
						public void testReadFile() {
 | 
				
			||||||
		RemoteOperationResult result = mActivity.readFile(FILE_PATH);
 | 
							RemoteOperationResult result = mActivity.readFile(mFullPath2File);
 | 
				
			||||||
		assertTrue(result.getData() != null && result.getData().size() ==  1);
 | 
							assertTrue(result.getData() != null && result.getData().size() ==  1);
 | 
				
			||||||
		assertTrue(result.isSuccess());
 | 
							assertTrue(result.isSuccess());
 | 
				
			||||||
		// TODO check more properties of the result
 | 
							// TODO check more properties of the result
 | 
				
			||||||
@ -77,8 +74,8 @@ public class ReadFileTest extends 	ActivityInstrumentationTestCase2<TestActivity
 | 
				
			|||||||
	
 | 
						
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	protected void tearDown() throws Exception {
 | 
						protected void tearDown() throws Exception {
 | 
				
			||||||
		RemoteOperationResult removeResult = mActivity.removeFile(FILE_PATH);
 | 
							RemoteOperationResult removeResult = mActivity.removeFile(mFullPath2File);
 | 
				
			||||||
		if (!removeResult.isSuccess()) {
 | 
							if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
 | 
				
			||||||
			Utils.logAndThrow(LOG_TAG, removeResult);
 | 
								Utils.logAndThrow(LOG_TAG, removeResult);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
				
			|||||||
@ -27,17 +27,16 @@ package com.owncloud.android.lib.test_project.test;
 | 
				
			|||||||
import java.io.File;
 | 
					import java.io.File;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 | 
					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.test_project.TestActivity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import android.test.ActivityInstrumentationTestCase2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Class to test Read Folder Operation
 | 
					 * Class to test Read Folder Operation
 | 
				
			||||||
 * @author masensio
 | 
					 * @author masensio
 | 
				
			||||||
 * @author David A. Velasco
 | 
					 * @author David A. Velasco
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class ReadFolderTest extends	ActivityInstrumentationTestCase2<TestActivity> {
 | 
					public class ReadFolderTest extends	RemoteTest {
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	private static final String LOG_TAG = ReadFolderTest.class.getCanonicalName();
 | 
						private static final String LOG_TAG = ReadFolderTest.class.getCanonicalName();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -50,24 +49,22 @@ public class ReadFolderTest extends	ActivityInstrumentationTestCase2<TestActivit
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	private TestActivity mActivity;
 | 
						private TestActivity mActivity;
 | 
				
			||||||
	
 | 
						private String mFullPathToFolder;
 | 
				
			||||||
	public ReadFolderTest() {
 | 
					 | 
				
			||||||
		super(TestActivity.class);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	protected void setUp() throws Exception {
 | 
						protected void setUp() throws Exception {
 | 
				
			||||||
		super.setUp();
 | 
							super.setUp();
 | 
				
			||||||
		setActivityInitialTouchMode(false);
 | 
							setActivityInitialTouchMode(false);
 | 
				
			||||||
		mActivity = getActivity();
 | 
							mActivity = getActivity();
 | 
				
			||||||
 | 
							mFullPathToFolder = mBaseFolderPath + FOLDER_PATH;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
 | 
							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()) {
 | 
							if (result.isSuccess()) {
 | 
				
			||||||
			for (int i=0; i<FILE_PATHS.length && result.isSuccess(); i++) {
 | 
								for (int i=0; i<FILE_PATHS.length && result.isSuccess(); i++) {
 | 
				
			||||||
				result = mActivity.uploadFile(
 | 
									result = mActivity.uploadFile(
 | 
				
			||||||
						textFile.getAbsolutePath(), 
 | 
											textFile.getAbsolutePath(), 
 | 
				
			||||||
						FILE_PATHS[i], 
 | 
											 mBaseFolderPath + FILE_PATHS[i], 
 | 
				
			||||||
						"txt/plain");
 | 
											"txt/plain");
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -83,7 +80,7 @@ public class ReadFolderTest extends	ActivityInstrumentationTestCase2<TestActivit
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void testReadFolder() {
 | 
						public void testReadFolder() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		RemoteOperationResult result = mActivity.readFile(FOLDER_PATH);
 | 
							RemoteOperationResult result = mActivity.readFile(mFullPathToFolder);
 | 
				
			||||||
		assertTrue(result.isSuccess());
 | 
							assertTrue(result.isSuccess());
 | 
				
			||||||
		assertTrue(result.getData() != null && result.getData().size() > 1);
 | 
							assertTrue(result.getData() != null && result.getData().size() > 1);
 | 
				
			||||||
		assertTrue(result.getData().size() == 4);
 | 
							assertTrue(result.getData().size() == 4);
 | 
				
			||||||
@ -93,8 +90,8 @@ public class ReadFolderTest extends	ActivityInstrumentationTestCase2<TestActivit
 | 
				
			|||||||
	
 | 
						
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	protected void tearDown() throws Exception {
 | 
						protected void tearDown() throws Exception {
 | 
				
			||||||
		RemoteOperationResult removeResult = mActivity.removeFile(FOLDER_PATH);
 | 
							RemoteOperationResult removeResult = mActivity.removeFile(mFullPathToFolder);
 | 
				
			||||||
		if (!removeResult.isSuccess()) {
 | 
							if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
 | 
				
			||||||
			Utils.logAndThrow(LOG_TAG, removeResult);
 | 
								Utils.logAndThrow(LOG_TAG, removeResult);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
				
			|||||||
@ -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();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -29,11 +29,10 @@ import java.io.File;
 | 
				
			|||||||
import com.owncloud.android.lib.resources.shares.OCShare;
 | 
					import com.owncloud.android.lib.resources.shares.OCShare;
 | 
				
			||||||
import com.owncloud.android.lib.resources.shares.ShareType;
 | 
					import com.owncloud.android.lib.resources.shares.ShareType;
 | 
				
			||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 | 
					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.test_project.TestActivity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import android.test.ActivityInstrumentationTestCase2;
 | 
					public class RemoveShareTest extends RemoteTest {
 | 
				
			||||||
 | 
					 | 
				
			||||||
public class RemoveShareTest extends ActivityInstrumentationTestCase2<TestActivity> {
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	private static final String LOG_TAG = RemoveShareTest.class.getCanonicalName();
 | 
						private static final String LOG_TAG = RemoveShareTest.class.getCanonicalName();
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
@ -41,29 +40,27 @@ public class RemoveShareTest extends ActivityInstrumentationTestCase2<TestActivi
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	private TestActivity mActivity;
 | 
						private TestActivity mActivity;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
						private String mFullPath2FileToUnshare;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private long mShareId;
 | 
						private long mShareId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public RemoveShareTest() {
 | 
					 | 
				
			||||||
		super(TestActivity.class);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	  protected void setUp() throws Exception {
 | 
						  protected void setUp() throws Exception {
 | 
				
			||||||
	    super.setUp();
 | 
						    super.setUp();
 | 
				
			||||||
	    setActivityInitialTouchMode(false);
 | 
						    setActivityInitialTouchMode(false);
 | 
				
			||||||
	    mActivity = getActivity();
 | 
						    mActivity = getActivity();
 | 
				
			||||||
 | 
						    mFullPath2FileToUnshare = mBaseFolderPath + FILE_TO_UNSHARE;
 | 
				
			||||||
	    
 | 
						    
 | 
				
			||||||
		File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
 | 
							File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
 | 
				
			||||||
		RemoteOperationResult result = mActivity.uploadFile(
 | 
							RemoteOperationResult result = mActivity.uploadFile(
 | 
				
			||||||
				textFile.getAbsolutePath(), 
 | 
									textFile.getAbsolutePath(), 
 | 
				
			||||||
				FILE_TO_UNSHARE, 
 | 
									mFullPath2FileToUnshare, 
 | 
				
			||||||
				"txt/plain");
 | 
									"txt/plain");
 | 
				
			||||||
		if (!result.isSuccess()) {
 | 
							if (!result.isSuccess()) {
 | 
				
			||||||
			Utils.logAndThrow(LOG_TAG, result);
 | 
								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()) {
 | 
							if (!result.isSuccess()) {
 | 
				
			||||||
			Utils.logAndThrow(LOG_TAG, result);
 | 
								Utils.logAndThrow(LOG_TAG, result);
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
@ -84,8 +81,8 @@ public class RemoveShareTest extends ActivityInstrumentationTestCase2<TestActivi
 | 
				
			|||||||
	
 | 
						
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	protected void tearDown() throws Exception {
 | 
						protected void tearDown() throws Exception {
 | 
				
			||||||
		RemoteOperationResult removeResult = mActivity.removeFile(FILE_TO_UNSHARE);
 | 
							RemoteOperationResult removeResult = mActivity.removeFile(mFullPath2FileToUnshare);
 | 
				
			||||||
		if (!removeResult.isSuccess()) {
 | 
							if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
 | 
				
			||||||
			Utils.logAndThrow(LOG_TAG, removeResult);
 | 
								Utils.logAndThrow(LOG_TAG, removeResult);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		super.tearDown();
 | 
							super.tearDown();
 | 
				
			||||||
 | 
				
			|||||||
@ -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.resources.files.FileUtils;
 | 
				
			||||||
import com.owncloud.android.lib.test_project.TestActivity;
 | 
					import com.owncloud.android.lib.test_project.TestActivity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import android.test.ActivityInstrumentationTestCase2;
 | 
					 | 
				
			||||||
import android.util.Log;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Class to test Rename File Operation
 | 
					 * Class to test Rename File Operation
 | 
				
			||||||
 * @author masensio
 | 
					 * @author masensio
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
 | 
					public class RenameFileTest extends RemoteTest {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private static final String LOG_TAG = RenameFileTest.class.getCanonicalName();
 | 
						private static final String LOG_TAG = RenameFileTest.class.getCanonicalName();
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
@ -57,43 +54,37 @@ public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivit
 | 
				
			|||||||
	private static final String NEW_FILE_PATH = FileUtils.PATH_SEPARATOR + NEW_FILE_NAME;
 | 
						private static final String NEW_FILE_PATH = FileUtils.PATH_SEPARATOR + NEW_FILE_NAME;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	private static boolean mGlobalSetupDone = false;
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	private String mToCleanUpInServer;
 | 
						private String mToCleanUpInServer;
 | 
				
			||||||
	private TestActivity mActivity;
 | 
						private TestActivity mActivity;
 | 
				
			||||||
	
 | 
						private String mFullPath2OldFolder;
 | 
				
			||||||
	public RenameFileTest() {
 | 
						private String mFullPath2NewFolder;
 | 
				
			||||||
	    super(TestActivity.class);
 | 
						private String mFullPath2OldFile;
 | 
				
			||||||
	   
 | 
						private String mFullPath2NewFile;
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	  protected void setUp() throws Exception {
 | 
						  protected void setUp() throws Exception {
 | 
				
			||||||
	    super.setUp();
 | 
						    super.setUp();
 | 
				
			||||||
	    setActivityInitialTouchMode(false);
 | 
						    setActivityInitialTouchMode(false);
 | 
				
			||||||
	    mActivity = getActivity();
 | 
						    mActivity = getActivity();
 | 
				
			||||||
 | 
					    	mFullPath2OldFolder = mBaseFolderPath + OLD_FOLDER_PATH;
 | 
				
			||||||
 | 
					    	mFullPath2NewFolder = mBaseFolderPath + NEW_FOLDER_PATH;
 | 
				
			||||||
 | 
					    	mFullPath2OldFile = mBaseFolderPath + OLD_FILE_PATH;
 | 
				
			||||||
 | 
					    	mFullPath2NewFile = mBaseFolderPath + NEW_FILE_PATH;
 | 
				
			||||||
	    
 | 
						    
 | 
				
			||||||
	    if (!mGlobalSetupDone) {
 | 
							RemoteOperationResult result = mActivity.createFolder(mFullPath2OldFolder, true);
 | 
				
			||||||
	    	
 | 
							if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) {
 | 
				
			||||||
			Log.v(LOG_TAG, "Starting global set up");
 | 
					 | 
				
			||||||
			RemoteOperationResult result = mActivity.createFolder(OLD_FOLDER_NAME, true);
 | 
					 | 
				
			||||||
			if (!result.isSuccess()) {
 | 
					 | 
				
			||||||
			Utils.logAndThrow(LOG_TAG, result);
 | 
								Utils.logAndThrow(LOG_TAG, result);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		File imageFile = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME);
 | 
							File imageFile = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME);
 | 
				
			||||||
		result = mActivity.uploadFile(
 | 
							result = mActivity.uploadFile(
 | 
				
			||||||
				imageFile.getAbsolutePath(), 
 | 
									imageFile.getAbsolutePath(), 
 | 
				
			||||||
					OLD_FILE_PATH, 
 | 
									mFullPath2OldFile, 
 | 
				
			||||||
				"image/png");
 | 
									"image/png");
 | 
				
			||||||
		if (!result.isSuccess()) {
 | 
							if (!result.isSuccess()) {
 | 
				
			||||||
			Utils.logAndThrow(LOG_TAG, result);
 | 
								Utils.logAndThrow(LOG_TAG, result);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	    
 | 
						    
 | 
				
			||||||
			Log.v(LOG_TAG, "Global set up done");
 | 
					 | 
				
			||||||
		    mGlobalSetupDone = true;
 | 
					 | 
				
			||||||
	    }
 | 
					 | 
				
			||||||
	    
 | 
					 | 
				
			||||||
		mToCleanUpInServer = null;
 | 
							mToCleanUpInServer = null;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
@ -102,14 +93,14 @@ public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivit
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void testRenameFolder() {
 | 
						public void testRenameFolder() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		mToCleanUpInServer = OLD_FOLDER_PATH;
 | 
							mToCleanUpInServer = mFullPath2OldFolder;
 | 
				
			||||||
		RemoteOperationResult result = mActivity.renameFile(
 | 
							RemoteOperationResult result = mActivity.renameFile(
 | 
				
			||||||
				OLD_FOLDER_NAME, 
 | 
									OLD_FOLDER_NAME, 
 | 
				
			||||||
				OLD_FOLDER_PATH, 
 | 
									mFullPath2OldFolder, 
 | 
				
			||||||
				NEW_FOLDER_NAME,
 | 
									NEW_FOLDER_NAME,
 | 
				
			||||||
				true);
 | 
									true);
 | 
				
			||||||
		assertTrue(result.isSuccess());
 | 
							assertTrue(result.isSuccess());
 | 
				
			||||||
		mToCleanUpInServer = NEW_FOLDER_PATH;
 | 
							mToCleanUpInServer = mFullPath2NewFolder;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
@ -117,35 +108,35 @@ public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivit
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void testRenameFolderForbiddenChars() {
 | 
						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);
 | 
									NEW_FOLDER_NAME + "\\", true);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							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);
 | 
									NEW_FOLDER_NAME + "<", true);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							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);
 | 
									NEW_FOLDER_NAME + ">", true);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							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);
 | 
									NEW_FOLDER_NAME + ":", true);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							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);
 | 
									NEW_FOLDER_NAME + "\"", true);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							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);
 | 
									NEW_FOLDER_NAME + "|", true);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							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);
 | 
									NEW_FOLDER_NAME + "?", true);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							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);
 | 
									NEW_FOLDER_NAME + "*", true);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -154,14 +145,14 @@ public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivit
 | 
				
			|||||||
	 * Test Rename File
 | 
						 * Test Rename File
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void testRenameFile() {
 | 
						public void testRenameFile() {
 | 
				
			||||||
		mToCleanUpInServer = OLD_FILE_PATH;
 | 
							mToCleanUpInServer = mFullPath2OldFile;
 | 
				
			||||||
		RemoteOperationResult result = mActivity.renameFile(
 | 
							RemoteOperationResult result = mActivity.renameFile(
 | 
				
			||||||
				OLD_FILE_NAME, 
 | 
									OLD_FILE_NAME, 
 | 
				
			||||||
				OLD_FILE_PATH, 
 | 
									mFullPath2OldFile, 
 | 
				
			||||||
				NEW_FILE_NAME, 
 | 
									NEW_FILE_NAME, 
 | 
				
			||||||
				false);
 | 
									false);
 | 
				
			||||||
		assertTrue(result.isSuccess());
 | 
							assertTrue(result.isSuccess());
 | 
				
			||||||
		mToCleanUpInServer = NEW_FILE_PATH;
 | 
							mToCleanUpInServer = mFullPath2NewFile;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
@ -171,56 +162,56 @@ public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivit
 | 
				
			|||||||
	public void testRenameFileForbiddenChars() {		
 | 
						public void testRenameFileForbiddenChars() {		
 | 
				
			||||||
		RemoteOperationResult result = mActivity.renameFile(
 | 
							RemoteOperationResult result = mActivity.renameFile(
 | 
				
			||||||
				OLD_FILE_NAME, 
 | 
									OLD_FILE_NAME, 
 | 
				
			||||||
				OLD_FILE_PATH, 
 | 
									mFullPath2OldFile, 
 | 
				
			||||||
				"\\" + NEW_FILE_NAME,
 | 
									"\\" + NEW_FILE_NAME,
 | 
				
			||||||
				false);
 | 
									false);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		result = mActivity.renameFile(
 | 
							result = mActivity.renameFile(
 | 
				
			||||||
				OLD_FILE_NAME, 
 | 
									OLD_FILE_NAME, 
 | 
				
			||||||
				OLD_FILE_PATH, 
 | 
									mFullPath2OldFile, 
 | 
				
			||||||
				"<" + NEW_FILE_NAME, 
 | 
									"<" + NEW_FILE_NAME, 
 | 
				
			||||||
				false);
 | 
									false);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		result = mActivity.renameFile(
 | 
							result = mActivity.renameFile(
 | 
				
			||||||
				OLD_FILE_NAME, 
 | 
									OLD_FILE_NAME, 
 | 
				
			||||||
				OLD_FILE_PATH, 
 | 
									mFullPath2OldFile, 
 | 
				
			||||||
				">" + NEW_FILE_NAME,
 | 
									">" + NEW_FILE_NAME,
 | 
				
			||||||
				false);
 | 
									false);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		result = mActivity.renameFile(
 | 
							result = mActivity.renameFile(
 | 
				
			||||||
				OLD_FILE_NAME, 
 | 
									OLD_FILE_NAME, 
 | 
				
			||||||
				OLD_FILE_PATH, 
 | 
									mFullPath2OldFile, 
 | 
				
			||||||
				":" + NEW_FILE_NAME,
 | 
									":" + NEW_FILE_NAME,
 | 
				
			||||||
				false);
 | 
									false);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		result = mActivity.renameFile(
 | 
							result = mActivity.renameFile(
 | 
				
			||||||
				OLD_FILE_NAME,
 | 
									OLD_FILE_NAME,
 | 
				
			||||||
				OLD_FILE_PATH, 
 | 
									mFullPath2OldFile, 
 | 
				
			||||||
				"\"" + NEW_FILE_NAME,
 | 
									"\"" + NEW_FILE_NAME,
 | 
				
			||||||
				false);
 | 
									false);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		result = mActivity.renameFile(
 | 
							result = mActivity.renameFile(
 | 
				
			||||||
				OLD_FILE_NAME,
 | 
									OLD_FILE_NAME,
 | 
				
			||||||
				OLD_FILE_PATH, 
 | 
									mFullPath2OldFile, 
 | 
				
			||||||
				"|" + NEW_FILE_NAME,
 | 
									"|" + NEW_FILE_NAME,
 | 
				
			||||||
				false);
 | 
									false);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		result = mActivity.renameFile(
 | 
							result = mActivity.renameFile(
 | 
				
			||||||
				OLD_FILE_NAME,
 | 
									OLD_FILE_NAME,
 | 
				
			||||||
				OLD_FILE_PATH, 
 | 
									mFullPath2OldFile, 
 | 
				
			||||||
				"?" + NEW_FILE_NAME,
 | 
									"?" + NEW_FILE_NAME,
 | 
				
			||||||
				false);
 | 
									false);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		result = mActivity.renameFile(
 | 
							result = mActivity.renameFile(
 | 
				
			||||||
				OLD_FILE_NAME,
 | 
									OLD_FILE_NAME,
 | 
				
			||||||
				OLD_FILE_PATH, 
 | 
									mFullPath2OldFile, 
 | 
				
			||||||
				"*" + NEW_FILE_NAME, false);
 | 
									"*" + NEW_FILE_NAME, false);
 | 
				
			||||||
		assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
							assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
				
			|||||||
@ -26,9 +26,8 @@ package com.owncloud.android.lib.test_project.test;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import java.io.File;
 | 
					import java.io.File;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import android.test.ActivityInstrumentationTestCase2;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 | 
					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.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();
 | 
						private static final String LOG_TAG = UploadFileTest.class.getCanonicalName();
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
@ -54,10 +53,6 @@ public class UploadFileTest extends ActivityInstrumentationTestCase2<TestActivit
 | 
				
			|||||||
	private String mUploadedFilePath;
 | 
						private String mUploadedFilePath;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public UploadFileTest() {
 | 
					 | 
				
			||||||
	    super(TestActivity.class);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	  protected void setUp() throws Exception {
 | 
						  protected void setUp() throws Exception {
 | 
				
			||||||
	    super.setUp();
 | 
						    super.setUp();
 | 
				
			||||||
@ -75,12 +70,13 @@ public class UploadFileTest extends ActivityInstrumentationTestCase2<TestActivit
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void testUploadFile() {
 | 
						public void testUploadFile() {
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
							String fullPath2Upload = mBaseFolderPath + UPLOAD_PATH;
 | 
				
			||||||
		RemoteOperationResult result = mActivity.uploadFile(
 | 
							RemoteOperationResult result = mActivity.uploadFile(
 | 
				
			||||||
				mFileToUpload.getAbsolutePath(), 
 | 
									mFileToUpload.getAbsolutePath(), 
 | 
				
			||||||
				UPLOAD_PATH, 
 | 
									fullPath2Upload, 
 | 
				
			||||||
				"image/png"
 | 
									"image/png"
 | 
				
			||||||
				);
 | 
									);
 | 
				
			||||||
	    mUploadedFilePath = UPLOAD_PATH;
 | 
						    mUploadedFilePath = fullPath2Upload;
 | 
				
			||||||
		assertTrue(result.isSuccess());
 | 
							assertTrue(result.isSuccess());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
@ -89,12 +85,13 @@ public class UploadFileTest extends ActivityInstrumentationTestCase2<TestActivit
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void testUploadFileWithChunks() {
 | 
						public void testUploadFileWithChunks() {
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
							String fullPath2Upload = mBaseFolderPath + CHUNKED_UPLOAD_PATH;
 | 
				
			||||||
		RemoteOperationResult result = mActivity.uploadFile(
 | 
							RemoteOperationResult result = mActivity.uploadFile(
 | 
				
			||||||
				mFileToUploadWithChunks.getAbsolutePath(),
 | 
									mFileToUploadWithChunks.getAbsolutePath(),
 | 
				
			||||||
				CHUNKED_UPLOAD_PATH, 
 | 
									fullPath2Upload, 
 | 
				
			||||||
				"video/mp4"
 | 
									"video/mp4"
 | 
				
			||||||
				);
 | 
									);
 | 
				
			||||||
	    mUploadedFilePath = CHUNKED_UPLOAD_PATH;
 | 
						    mUploadedFilePath = fullPath2Upload;
 | 
				
			||||||
		assertTrue(result.isSuccess());
 | 
							assertTrue(result.isSuccess());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
@ -103,12 +100,13 @@ public class UploadFileTest extends ActivityInstrumentationTestCase2<TestActivit
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	public void testUploadFileNotFound() {
 | 
						public void testUploadFileNotFound() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							String fullPath2Upload = mBaseFolderPath + FILE_NOT_FOUND_PATH;
 | 
				
			||||||
		RemoteOperationResult result = mActivity.uploadFile(
 | 
							RemoteOperationResult result = mActivity.uploadFile(
 | 
				
			||||||
				FILE_NOT_FOUND_PATH, 
 | 
									FILE_NOT_FOUND_PATH, 
 | 
				
			||||||
				FILE_NOT_FOUND_PATH, 
 | 
									fullPath2Upload, 
 | 
				
			||||||
				"image/png"
 | 
									"image/png"
 | 
				
			||||||
				);
 | 
									);
 | 
				
			||||||
		mUploadedFilePath = FILE_NOT_FOUND_PATH;
 | 
							mUploadedFilePath = fullPath2Upload;
 | 
				
			||||||
		assertFalse(result.isSuccess());
 | 
							assertFalse(result.isSuccess());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
@ -117,7 +115,7 @@ public class UploadFileTest extends ActivityInstrumentationTestCase2<TestActivit
 | 
				
			|||||||
	protected void tearDown() throws Exception {
 | 
						protected void tearDown() throws Exception {
 | 
				
			||||||
		if (mUploadedFilePath != null) {
 | 
							if (mUploadedFilePath != null) {
 | 
				
			||||||
			RemoteOperationResult removeResult = mActivity.removeFile(mUploadedFilePath);
 | 
								RemoteOperationResult removeResult = mActivity.removeFile(mUploadedFilePath);
 | 
				
			||||||
			if (!removeResult.isSuccess()) {
 | 
								if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
 | 
				
			||||||
				Utils.logAndThrow(LOG_TAG, removeResult);
 | 
									Utils.logAndThrow(LOG_TAG, removeResult);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -24,15 +24,32 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package com.owncloud.android.lib.test_project.test;
 | 
					package com.owncloud.android.lib.test_project.test;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import android.content.Context;
 | 
				
			||||||
import android.util.Log;
 | 
					import android.util.Log;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 | 
					import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 | 
				
			||||||
 | 
					import com.owncloud.android.lib.test_project.R;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class Utils {
 | 
					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 {
 | 
						public static void logAndThrow(String tag, RemoteOperationResult result) throws Exception {
 | 
				
			||||||
		Log.e(tag, result.getLogMessage(), result.getException());
 | 
							Log.e(tag, result.getLogMessage(), result.getException());
 | 
				
			||||||
		throw new Exception(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;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user