Merge pull request #21 from owncloud/travis_ci
Added Travis support, including automatic tests on Android 4.4 emulator.
27
.travis.yml
Normal file
@ -0,0 +1,27 @@
|
||||
language: java
|
||||
jdk: oraclejdk7
|
||||
before_install:
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -qq libstdc++6:i386 lib32z1
|
||||
- curl -3L https://raw.github.com/embarkmobile/android-sdk-installer/version-1/android-sdk-installer
|
||||
| bash /dev/stdin --install=$COMPONENTS
|
||||
- source ~/.android-sdk-installer/env
|
||||
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI -c 20M
|
||||
- emulator -avd test -no-skin -no-audio -no-window &
|
||||
- rm pom.xml
|
||||
- android update project -p .
|
||||
before_script:
|
||||
- chmod +x ./wait_for_emulator.sh
|
||||
- ./wait_for_emulator.sh
|
||||
script:
|
||||
- ant clean
|
||||
- ant debug
|
||||
- cd test_client/tests
|
||||
- ant acceptance-test
|
||||
env:
|
||||
global:
|
||||
- secure: f4Kms/mzkYRG4Kp8k6hsvG3Y0ztbJnA2J79OBw3VdqJOKVTzwsxMd1Yh325YDYO7I4HeHxGXy0H4p3rAPzIWr/nrOJ4wmcDwQYDQtVjF7S1ARWsX51FrCEV6A9ec2LAqNCQ8ZC0SoGb+HsmpFCE3uKAxRQt+B5MzOZvKNcvYpMA=
|
||||
- secure: aF4U20Xlu/rfrbxCmoJAiGh1doYTAZ10UEDmajuinT+ZGSJLivuqD7DDY/00sI6IXWg+J1vL+7jJm4JSYusHPg38UHZ4q92k6RmZycW2ATUzZnGT54O5FRnY67MfVwgVpIMK9UOL/6NEciBHEjlIOL0wbKQiJB++1YtBZOQLGL4=
|
||||
- secure: N+ECSwNg8v2GsAFJ2y/tCiffauHDpN76zuFI2pDqf0fjmCtJZHu4BH5ArXBHjyHKmgn20a/8eZXcwJaH1HsJ80bo7vDJ2miShjGIQ90hPcdmUiB2XVJcew4f04CtvMDH5o7DRt4ykWArlbPL2rhVag0jotlSidolHBwRFnbDhDY=
|
||||
matrix:
|
||||
- COMPONENTS=build-tools-19.0.3,android-19,sysimg-19 ANDROID_TARGET=android-19 ANDROID_ABI=armeabi-v7a
|
@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ownCloud Android Library Test Project</name>
|
||||
<name>ownCloud Android library test project</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
3
test_client/assets/textFile.txt
Normal file
@ -0,0 +1,3 @@
|
||||
This is a simple text file.
|
||||
|
||||
To make some tests.
|
92
test_client/build.xml
Normal file
@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="ownCloud Android library test client" default="help">
|
||||
|
||||
<!-- The local.properties file is created and updated by the 'android' tool.
|
||||
It contains the path to the SDK. It should *NOT* be checked into
|
||||
Version Control Systems. -->
|
||||
<property file="local.properties" />
|
||||
|
||||
<!-- The ant.properties file can be created by you. It is only edited by the
|
||||
'android' tool to add properties to it.
|
||||
This is the place to change some Ant specific build properties.
|
||||
Here are some properties you may want to change/update:
|
||||
|
||||
source.dir
|
||||
The name of the source directory. Default is 'src'.
|
||||
out.dir
|
||||
The name of the output directory. Default is 'bin'.
|
||||
|
||||
For other overridable properties, look at the beginning of the rules
|
||||
files in the SDK, at tools/ant/build.xml
|
||||
|
||||
Properties related to the SDK location or the project target should
|
||||
be updated using the 'android' tool with the 'update' action.
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems.
|
||||
|
||||
-->
|
||||
<property file="ant.properties" />
|
||||
|
||||
<!-- if sdk.dir was not set from one of the property file, then
|
||||
get it from the ANDROID_HOME env var.
|
||||
This must be done before we load project.properties since
|
||||
the proguard config can use sdk.dir -->
|
||||
<property environment="env" />
|
||||
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
|
||||
<isset property="env.ANDROID_HOME" />
|
||||
</condition>
|
||||
|
||||
<!-- The project.properties file is created and updated by the 'android'
|
||||
tool, as well as ADT.
|
||||
|
||||
This contains project specific properties such as project target, and library
|
||||
dependencies. Lower level build properties are stored in ant.properties
|
||||
(or in .classpath for Eclipse projects).
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems. -->
|
||||
<loadproperties srcFile="project.properties" />
|
||||
|
||||
<!-- quick check on sdk.dir -->
|
||||
<fail
|
||||
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
|
||||
unless="sdk.dir"
|
||||
/>
|
||||
|
||||
<!--
|
||||
Import per project custom build rules if present at the root of the project.
|
||||
This is the place to put custom intermediary targets such as:
|
||||
-pre-build
|
||||
-pre-compile
|
||||
-post-compile (This is typically used for code obfuscation.
|
||||
Compiled code location: ${out.classes.absolute.dir}
|
||||
If this is not done in place, override ${out.dex.input.absolute.dir})
|
||||
-post-package
|
||||
-post-build
|
||||
-pre-clean
|
||||
-->
|
||||
<import file="custom_rules.xml" optional="true" />
|
||||
|
||||
<!-- Import the actual build file.
|
||||
|
||||
To customize existing targets, there are two options:
|
||||
- Customize only one target:
|
||||
- copy/paste the target into this file, *before* the
|
||||
<import> task.
|
||||
- customize it to your needs.
|
||||
- Customize the whole content of build.xml
|
||||
- copy/paste the content of the rules files (minus the top node)
|
||||
into this file, replacing the <import> task.
|
||||
- customize to your needs.
|
||||
|
||||
***********************
|
||||
****** IMPORTANT ******
|
||||
***********************
|
||||
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
|
||||
in order to avoid having your file be overridden by tools such as "android update project"
|
||||
-->
|
||||
<!-- version-tag: 1 -->
|
||||
<import file="${sdk.dir}/tools/ant/build.xml" />
|
||||
|
||||
</project>
|
47
test_client/custom_rules.xml
Normal file
@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="custom_rules">
|
||||
<target name="-pre-build" >
|
||||
<!-- Replace OC server URL if set in environment -->
|
||||
<if>
|
||||
<condition>
|
||||
<isset property="env.OCTEST_SERVER_BASE_URL" />
|
||||
</condition>
|
||||
<then>
|
||||
<replaceregexp
|
||||
file="res/values/setup.xml"
|
||||
match='("server_base_url">)\s*(<)'
|
||||
replace="\1${env.OCTEST_SERVER_BASE_URL}\2"
|
||||
byline="true" />
|
||||
</then>
|
||||
</if>
|
||||
|
||||
<!-- Replace test username if set in environment -->
|
||||
<if>
|
||||
<condition>
|
||||
<isset property="env.OCTEST_USERNAME" />
|
||||
</condition>
|
||||
<then>
|
||||
<echo>Setting username ${env.OCTEST_USERNAME}</echo>
|
||||
<replaceregexp
|
||||
file="res/values/setup.xml"
|
||||
match='("username">)\s*(<)'
|
||||
replace="\1${env.OCTEST_USERNAME}\2"
|
||||
byline="true" />
|
||||
</then>
|
||||
</if>
|
||||
|
||||
<!-- Replace test username if set in environment -->
|
||||
<if>
|
||||
<condition>
|
||||
<isset property="env.OCTEST_PASSWORD" />
|
||||
</condition>
|
||||
<then>
|
||||
<replaceregexp
|
||||
file="res/values/setup.xml"
|
||||
match='("password">)\s*(<)'
|
||||
replace="\1${env.OCTEST_PASSWORD}\2"
|
||||
byline="true" />
|
||||
</then>
|
||||
</if>
|
||||
</target>
|
||||
</project>
|
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 50 KiB |
Before Width: | Height: | Size: 7.5 KiB After Width: | Height: | Size: 7.5 KiB |
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
@ -0,0 +1,212 @@
|
||||
/* 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.KeyStore;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.CertStoreException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
import javax.net.SocketFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import org.apache.commons.httpclient.ConnectTimeoutException;
|
||||
import org.apache.commons.httpclient.params.HttpConnectionParams;
|
||||
import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
|
||||
|
||||
import com.owncloud.android.lib.common.network.ServerNameIndicator;
|
||||
|
||||
|
||||
/**
|
||||
* SelfSignedConfidentSslSocketFactory allows to create SSL {@link Socket}s
|
||||
* that accepts self-signed server certificates.
|
||||
*
|
||||
* WARNING: this SHOULD NOT be used in productive environments.
|
||||
*
|
||||
* @author David A. Velasco
|
||||
*/
|
||||
|
||||
public class SelfSignedConfidentSslSocketFactory implements SecureProtocolSocketFactory {
|
||||
|
||||
|
||||
private SSLContext mSslContext = null;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for SelfSignedConfidentSslSocketFactory.
|
||||
* @throws GeneralSecurityException
|
||||
*/
|
||||
public SelfSignedConfidentSslSocketFactory() throws GeneralSecurityException {
|
||||
mSslContext = createSslContext();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see SecureProtocolSocketFactory#createSocket(java.lang.String,int)
|
||||
*/
|
||||
@Override
|
||||
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
|
||||
return mSslContext.getSocketFactory().createSocket(host, port);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see SecureProtocolSocketFactory#createSocket(java.lang.String,int,java.net.InetAddress,int)
|
||||
*/
|
||||
@Override
|
||||
public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort)
|
||||
throws IOException, UnknownHostException {
|
||||
return mSslContext.getSocketFactory().createSocket(host, port, clientHost, clientPort);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to get a new socket connection to the given host within the given time limit.
|
||||
*
|
||||
* @param host The host name/IP
|
||||
* @param port The port on the host
|
||||
* @param clientHost The local host name/IP to bind the socket to
|
||||
* @param clientPort The port on the local machine
|
||||
* @param params {@link HttpConnectionParams} HTTP connection parameters.
|
||||
*
|
||||
* @return Socket A new socket
|
||||
*
|
||||
* @throws IOException if an I/O error occurs while creating the socket
|
||||
* @throws UnknownHostException if the IP address of the host cannot be determined
|
||||
*/
|
||||
@Override
|
||||
public Socket createSocket(String host, int port, InetAddress localAddress, int localPort,
|
||||
HttpConnectionParams params) throws IOException, UnknownHostException,
|
||||
ConnectTimeoutException {
|
||||
|
||||
if (params == null) {
|
||||
throw new IllegalArgumentException("Parameters may not be null");
|
||||
}
|
||||
int timeout = params.getConnectionTimeout();
|
||||
SocketFactory socketfactory = mSslContext.getSocketFactory();
|
||||
Socket socket = socketfactory.createSocket();
|
||||
SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
|
||||
SocketAddress remoteaddr = new InetSocketAddress(host, port);
|
||||
socket.setSoTimeout(params.getSoTimeout());
|
||||
socket.bind(localaddr);
|
||||
ServerNameIndicator.setServerNameIndication(host, (SSLSocket)socket);
|
||||
socket.connect(remoteaddr, timeout);
|
||||
return socket;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see SecureProtocolSocketFactory#createSocket(java.net.Socket,java.lang.String,int,boolean)
|
||||
*/
|
||||
@Override
|
||||
public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
|
||||
throws IOException, UnknownHostException {
|
||||
return mSslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static SSLContext createSslContext() throws GeneralSecurityException {
|
||||
SSLContext context = SSLContext.getInstance("TLS");
|
||||
context.init(
|
||||
null,
|
||||
new TrustManager[] {new SelfSignedConfidentX509TrustManager()},
|
||||
null);
|
||||
return context;
|
||||
}
|
||||
|
||||
public static class SelfSignedConfidentX509TrustManager implements X509TrustManager {
|
||||
|
||||
private X509TrustManager mStandardTrustManager = null;
|
||||
|
||||
public SelfSignedConfidentX509TrustManager()
|
||||
throws NoSuchAlgorithmException, KeyStoreException, CertStoreException {
|
||||
super();
|
||||
TrustManagerFactory factory = TrustManagerFactory
|
||||
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||
factory.init((KeyStore)null);
|
||||
mStandardTrustManager = findX509TrustManager(factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[],String authType)
|
||||
*/
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType)
|
||||
throws CertificateException {
|
||||
mStandardTrustManager.checkClientTrusted(chain, authType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[],
|
||||
* String authType)
|
||||
*/
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType)
|
||||
throws CertificateException {
|
||||
if (chain != null && chain.length == 1) {
|
||||
chain[0].checkValidity();
|
||||
} else {
|
||||
mStandardTrustManager.checkServerTrusted(chain, authType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.net.ssl.X509TrustManager#getAcceptedIssuers()
|
||||
*/
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return mStandardTrustManager.getAcceptedIssuers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Locates the first X509TrustManager provided by a given TrustManagerFactory
|
||||
* @param factory TrustManagerFactory to inspect in the search for a X509TrustManager
|
||||
* @return The first X509TrustManager found in factory.
|
||||
* @throws CertStoreException When no X509TrustManager instance was found in factory
|
||||
*/
|
||||
private X509TrustManager findX509TrustManager(TrustManagerFactory factory)
|
||||
throws CertStoreException {
|
||||
TrustManager tms[] = factory.getTrustManagers();
|
||||
for (int i = 0; i < tms.length; i++) {
|
||||
if (tms[i] instanceof X509TrustManager) {
|
||||
return (X509TrustManager) tms[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -25,10 +25,18 @@
|
||||
package com.owncloud.android.lib.test_project;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
import org.apache.commons.httpclient.protocol.Protocol;
|
||||
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
|
||||
|
||||
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.resources.files.RemoteFile;
|
||||
import com.owncloud.android.lib.common.network.NetworkUtils;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.resources.files.ChunkedUploadRemoteFileOperation;
|
||||
import com.owncloud.android.lib.resources.files.CreateRemoteFolderOperation;
|
||||
@ -47,6 +55,7 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.app.Activity;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
|
||||
/**
|
||||
@ -57,13 +66,20 @@ import android.view.Menu;
|
||||
|
||||
public class TestActivity extends Activity {
|
||||
|
||||
private static final String TAG = null;
|
||||
// This account must exists on the server side
|
||||
private String mServerUri;
|
||||
private String mWebdavPath;
|
||||
private String mUser;
|
||||
private String mPass;
|
||||
private boolean mChunked;
|
||||
|
||||
private static final String WEBDAV_PATH = "/remote.php/webdav";
|
||||
private static final int BUFFER_SIZE = 1024;
|
||||
|
||||
public static final String ASSETS__TEXT_FILE_NAME = "textFile.txt";
|
||||
public static final String ASSETS__IMAGE_FILE_NAME = "imageFile.png";
|
||||
public static final String ASSETS__VIDEO_FILE_NAME = "videoFile.MP4";
|
||||
|
||||
//private Account mAccount = null;
|
||||
private OwnCloudClient mClient;
|
||||
|
||||
@ -73,15 +89,34 @@ public class TestActivity extends Activity {
|
||||
setContentView(R.layout.activity_test);
|
||||
|
||||
mServerUri = getString(R.string.server_base_url);
|
||||
mWebdavPath = getString(R.string.webdav_path);
|
||||
mUser = getString(R.string.username);
|
||||
mPass = getString(R.string.password);
|
||||
mChunked = getResources().getBoolean(R.bool.chunked);
|
||||
|
||||
Uri uri = Uri.parse(mServerUri + mWebdavPath);
|
||||
mClient = OwnCloudClientFactory.createOwnCloudClient(uri ,getApplicationContext(), true);
|
||||
mClient.setBasicCredentials(mUser, mPass);
|
||||
mClient.setBaseUri(Uri.parse(mServerUri));
|
||||
Protocol pr = Protocol.getProtocol("https");
|
||||
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
|
||||
try {
|
||||
ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
|
||||
Protocol.registerProtocol(
|
||||
"https",
|
||||
new Protocol("https", psf, 443));
|
||||
|
||||
} catch (GeneralSecurityException e) {
|
||||
Log.e(TAG, "Self-signed confident SSL context could not be loaded");
|
||||
}
|
||||
}
|
||||
|
||||
Uri uri = Uri.parse(mServerUri + WEBDAV_PATH);
|
||||
mClient = new OwnCloudClient(NetworkUtils.getMultiThreadedConnManager());
|
||||
mClient.setDefaultTimeouts(
|
||||
OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,
|
||||
OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT);
|
||||
mClient.setWebdavUri(uri);
|
||||
mClient.setFollowRedirects(true);
|
||||
mClient.setBasicCredentials(mUser, mPass);
|
||||
mClient.setBaseUri(Uri.parse(mServerUri));
|
||||
|
||||
Log.v(TAG, "onCreate finished, ownCloud client ready");
|
||||
|
||||
}
|
||||
|
||||
@ -248,4 +283,33 @@ public class TestActivity extends Activity {
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extracts file from AssetManager to cache folder.
|
||||
*
|
||||
* @param fileName Name of the asset file to extract.
|
||||
* @return File instance of the extracted file.
|
||||
*/
|
||||
public File extractAsset(String fileName) throws IOException {
|
||||
File extractedFile = new File(getCacheDir() + File.separator + fileName);
|
||||
if (!extractedFile.exists()) {
|
||||
InputStream in = null;
|
||||
FileOutputStream out = null;
|
||||
in = getAssets().open(fileName);
|
||||
out = new FileOutputStream(extractedFile);
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
int readCount;
|
||||
while((readCount = in.read(buffer)) != -1){
|
||||
out.write(buffer, 0, readCount);
|
||||
}
|
||||
out.flush();
|
||||
out.close();
|
||||
in.close();
|
||||
}
|
||||
return extractedFile;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/ownCloud Android Library Test Project"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/ownCloud Android library test project"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ownCloud Android Library Tests</name>
|
||||
<name>ownCloud Android library test cases</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
18
test_client/tests/ant.properties
Normal file
@ -0,0 +1,18 @@
|
||||
# This file is used to override default values used by the Ant build system.
|
||||
#
|
||||
# This file must be checked into Version Control Systems, as it is
|
||||
# integral to the build system of your project.
|
||||
|
||||
# This file is only used by the Ant script.
|
||||
|
||||
# You can use this to override default values such as
|
||||
# 'source.dir' for the location of your java source folder and
|
||||
# 'out.dir' for the location of your output folder.
|
||||
|
||||
# You can also use it define how the release builds are signed by declaring
|
||||
# the following properties:
|
||||
# 'key.store' for the location of your keystore and
|
||||
# 'key.alias' for the name of the key to use.
|
||||
# The password will be asked during the build when you use the 'release' target.
|
||||
|
||||
tested.project.dir=..
|
92
test_client/tests/build.xml
Normal file
@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="ownCloud Android library test cases" default="help">
|
||||
|
||||
<!-- The local.properties file is created and updated by the 'android' tool.
|
||||
It contains the path to the SDK. It should *NOT* be checked into
|
||||
Version Control Systems. -->
|
||||
<property file="local.properties" />
|
||||
|
||||
<!-- The ant.properties file can be created by you. It is only edited by the
|
||||
'android' tool to add properties to it.
|
||||
This is the place to change some Ant specific build properties.
|
||||
Here are some properties you may want to change/update:
|
||||
|
||||
source.dir
|
||||
The name of the source directory. Default is 'src'.
|
||||
out.dir
|
||||
The name of the output directory. Default is 'bin'.
|
||||
|
||||
For other overridable properties, look at the beginning of the rules
|
||||
files in the SDK, at tools/ant/build.xml
|
||||
|
||||
Properties related to the SDK location or the project target should
|
||||
be updated using the 'android' tool with the 'update' action.
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems.
|
||||
|
||||
-->
|
||||
<property file="ant.properties" />
|
||||
|
||||
<!-- if sdk.dir was not set from one of the property file, then
|
||||
get it from the ANDROID_HOME env var.
|
||||
This must be done before we load project.properties since
|
||||
the proguard config can use sdk.dir -->
|
||||
<property environment="env" />
|
||||
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
|
||||
<isset property="env.ANDROID_HOME" />
|
||||
</condition>
|
||||
|
||||
<!-- The project.properties file is created and updated by the 'android'
|
||||
tool, as well as ADT.
|
||||
|
||||
This contains project specific properties such as project target, and library
|
||||
dependencies. Lower level build properties are stored in ant.properties
|
||||
(or in .classpath for Eclipse projects).
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems. -->
|
||||
<loadproperties srcFile="project.properties" />
|
||||
|
||||
<!-- quick check on sdk.dir -->
|
||||
<fail
|
||||
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
|
||||
unless="sdk.dir"
|
||||
/>
|
||||
|
||||
<!--
|
||||
Import per project custom build rules if present at the root of the project.
|
||||
This is the place to put custom intermediary targets such as:
|
||||
-pre-build
|
||||
-pre-compile
|
||||
-post-compile (This is typically used for code obfuscation.
|
||||
Compiled code location: ${out.classes.absolute.dir}
|
||||
If this is not done in place, override ${out.dex.input.absolute.dir})
|
||||
-post-package
|
||||
-post-build
|
||||
-pre-clean
|
||||
-->
|
||||
<import file="custom_rules.xml" optional="true" />
|
||||
|
||||
<!-- Import the actual build file.
|
||||
|
||||
To customize existing targets, there are two options:
|
||||
- Customize only one target:
|
||||
- copy/paste the target into this file, *before* the
|
||||
<import> task.
|
||||
- customize it to your needs.
|
||||
- Customize the whole content of build.xml
|
||||
- copy/paste the content of the rules files (minus the top node)
|
||||
into this file, replacing the <import> task.
|
||||
- customize to your needs.
|
||||
|
||||
***********************
|
||||
****** IMPORTANT ******
|
||||
***********************
|
||||
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
|
||||
in order to avoid having your file be overridden by tools such as "android update project"
|
||||
-->
|
||||
<!-- version-tag: 1 -->
|
||||
<import file="${sdk.dir}/tools/ant/build.xml" />
|
||||
|
||||
</project>
|
19
test_client/tests/custom_rules.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="custom_rules">
|
||||
<!-- Run regular Android target 'test', but fails if any test is not successful -->
|
||||
<target name="acceptance-test" depends="clean, debug, install" >
|
||||
<property name="log.file" value="tests_output.txt" />
|
||||
<record name="${log.file}" action="start" />
|
||||
<antcall target="test" /> <!-- regular Android target -->
|
||||
<record name="${log.file}" action="stop" />
|
||||
<loadfile property="tests.output" srcFile="${log.file}" />
|
||||
<echo>Checking for failures</echo>
|
||||
<fail message="Acceptance tests failed." >
|
||||
<condition>
|
||||
<contains string="${tests.output}" substring="FAILURES" />
|
||||
</condition>
|
||||
</fail>
|
||||
<echo>All tests passed.</echo>
|
||||
</target>
|
||||
|
||||
</project>
|
Before Width: | Height: | Size: 9.2 KiB After Width: | Height: | Size: 9.2 KiB |
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
@ -24,7 +24,10 @@
|
||||
package com.owncloud.android.lib.test_project.test;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||
@ -35,18 +38,26 @@ import android.test.ActivityInstrumentationTestCase2;
|
||||
/**
|
||||
* Class to test Create Folder Operation
|
||||
* @author masensio
|
||||
* @author David A. Velasco
|
||||
*
|
||||
*/
|
||||
public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActivity> {
|
||||
|
||||
|
||||
private static final String LOG_TAG = CreateFolderTest.class.getCanonicalName();
|
||||
|
||||
private static final String FOLDER_PATH_BASE = "/testCreateFolder";
|
||||
|
||||
private TestActivity mActivity;
|
||||
private String mCurrentDate;
|
||||
private List<String> mCreatedFolderPaths;
|
||||
|
||||
public CreateFolderTest() {
|
||||
super(TestActivity.class);
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
|
||||
mCurrentDate = sdf.format(new Date());
|
||||
mCreatedFolderPaths = new ArrayList<String>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -54,24 +65,22 @@ public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActiv
|
||||
super.setUp();
|
||||
setActivityInitialTouchMode(false);
|
||||
mActivity = getActivity();
|
||||
mCreatedFolderPaths.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Create Folder
|
||||
*/
|
||||
public void testCreateFolder() {
|
||||
|
||||
String remotePath = "/testCreateFolder" + mCurrentDate;
|
||||
boolean createFullPath = true;
|
||||
|
||||
RemoteOperationResult result = mActivity.createFolder(remotePath, createFullPath);
|
||||
String remotePath = FOLDER_PATH_BASE + mCurrentDate;
|
||||
mCreatedFolderPaths.add(remotePath);
|
||||
RemoteOperationResult result = mActivity.createFolder(remotePath, true);
|
||||
assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
|
||||
|
||||
// Create Subfolder
|
||||
remotePath = "/testCreateFolder" + mCurrentDate + "/" + "testCreateFolder" + mCurrentDate;
|
||||
createFullPath = true;
|
||||
|
||||
result = mActivity.createFolder(remotePath, createFullPath);
|
||||
remotePath = FOLDER_PATH_BASE + mCurrentDate + FOLDER_PATH_BASE + mCurrentDate;
|
||||
mCreatedFolderPaths.add(remotePath);
|
||||
result = mActivity.createFolder(remotePath, true);
|
||||
assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
|
||||
}
|
||||
|
||||
@ -80,40 +89,52 @@ public class CreateFolderTest extends ActivityInstrumentationTestCase2<TestActiv
|
||||
* Test to Create Folder with special characters: / \ < > : " | ? *
|
||||
*/
|
||||
public void testCreateFolderSpecialCharacters() {
|
||||
boolean createFullPath = true;
|
||||
|
||||
String remotePath = "/testSpecialCharacters_\\" + mCurrentDate;
|
||||
RemoteOperationResult result = mActivity.createFolder(remotePath, createFullPath);
|
||||
String remotePath = FOLDER_PATH_BASE + "_\\" + mCurrentDate;
|
||||
RemoteOperationResult result = mActivity.createFolder(remotePath, true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
remotePath = "/testSpecialCharacters_<" + mCurrentDate;
|
||||
result = mActivity.createFolder(remotePath, createFullPath);
|
||||
remotePath = FOLDER_PATH_BASE + "_<" + mCurrentDate;
|
||||
result = mActivity.createFolder(remotePath, true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
remotePath = "/testSpecialCharacters_>" + mCurrentDate;
|
||||
result = mActivity.createFolder(remotePath, createFullPath);
|
||||
remotePath = FOLDER_PATH_BASE + "_>" + mCurrentDate;
|
||||
result = mActivity.createFolder(remotePath, true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
remotePath = "/testSpecialCharacters_:" + mCurrentDate;
|
||||
result = mActivity.createFolder(remotePath, createFullPath);
|
||||
remotePath = FOLDER_PATH_BASE + "_:" + mCurrentDate;
|
||||
result = mActivity.createFolder(remotePath, true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
remotePath = "/testSpecialCharacters_\"" + mCurrentDate;
|
||||
result = mActivity.createFolder(remotePath, createFullPath);
|
||||
remotePath = FOLDER_PATH_BASE + "_\"" + mCurrentDate;
|
||||
result = mActivity.createFolder(remotePath, true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
remotePath = "/testSpecialCharacters_|" + mCurrentDate;
|
||||
result = mActivity.createFolder(remotePath, createFullPath);
|
||||
remotePath = FOLDER_PATH_BASE + "_|" + mCurrentDate;
|
||||
result = mActivity.createFolder(remotePath, true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
remotePath = "/testSpecialCharacters_?" + mCurrentDate;
|
||||
result = mActivity.createFolder(remotePath, createFullPath);
|
||||
remotePath = FOLDER_PATH_BASE + "_?" + mCurrentDate;
|
||||
result = mActivity.createFolder(remotePath, true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
remotePath = "/testSpecialCharacters_*" + mCurrentDate;
|
||||
result = mActivity.createFolder(remotePath, createFullPath);
|
||||
remotePath = FOLDER_PATH_BASE + "_*" + mCurrentDate;
|
||||
result = mActivity.createFolder(remotePath, true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
Iterator<String> it = mCreatedFolderPaths.iterator();
|
||||
RemoteOperationResult removeResult = null;
|
||||
while (it.hasNext()) {
|
||||
removeResult = mActivity.removeFile(it.next());
|
||||
if (!removeResult.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, removeResult);
|
||||
}
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
@ -24,6 +24,8 @@
|
||||
|
||||
package com.owncloud.android.lib.test_project.test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.resources.shares.ShareType;
|
||||
import com.owncloud.android.lib.test_project.TestActivity;
|
||||
@ -32,9 +34,11 @@ import android.test.ActivityInstrumentationTestCase2;
|
||||
|
||||
public class CreateShareTest extends ActivityInstrumentationTestCase2<TestActivity> {
|
||||
|
||||
/* File to share.*/
|
||||
private final String mFileToShare = "/fileToShare.png";
|
||||
private static final String LOG_TAG = CreateShareTest.class.getCanonicalName();
|
||||
|
||||
/* File to share.*/
|
||||
private static final String FILE_TO_SHARE = "/fileToShare.txt";
|
||||
|
||||
private TestActivity mActivity;
|
||||
|
||||
public CreateShareTest() {
|
||||
@ -43,17 +47,44 @@ public class CreateShareTest extends ActivityInstrumentationTestCase2<TestActivi
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
setActivityInitialTouchMode(false);
|
||||
mActivity = getActivity();
|
||||
|
||||
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
|
||||
RemoteOperationResult result = mActivity.uploadFile(
|
||||
textFile.getAbsolutePath(),
|
||||
FILE_TO_SHARE,
|
||||
"txt/plain");
|
||||
if (!result.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Create Share: the server must support SHARE API
|
||||
*/
|
||||
public void testCreateShare() {
|
||||
RemoteOperationResult result = mActivity.createShare(mFileToShare, ShareType.PUBLIC_LINK, "", false, "", 1);
|
||||
public void testCreatePublicShare() {
|
||||
RemoteOperationResult result = mActivity.createShare(
|
||||
FILE_TO_SHARE,
|
||||
ShareType.PUBLIC_LINK,
|
||||
"",
|
||||
false,
|
||||
"",
|
||||
1);
|
||||
assertTrue(result.isSuccess());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
RemoteOperationResult removeResult = mActivity.removeFile(FILE_TO_SHARE);
|
||||
if (!removeResult.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, removeResult);
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -24,11 +24,13 @@
|
||||
|
||||
package com.owncloud.android.lib.test_project.test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||
import com.owncloud.android.lib.test_project.TestActivity;
|
||||
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Class to test Delete a File Operation
|
||||
@ -38,17 +40,20 @@ import android.test.ActivityInstrumentationTestCase2;
|
||||
|
||||
public class DeleteFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
|
||||
|
||||
private static final String LOG_TAG = DeleteFileTest.class.getCanonicalName();
|
||||
|
||||
/* Folder data to delete. */
|
||||
private final String mFolderPath = "/folderToDelete";
|
||||
private static final String FOLDER_PATH = "/folderToDelete";
|
||||
|
||||
/* File to delete. */
|
||||
private final String mFilePath = "fileToDelete.png";
|
||||
private static final String FILE_PATH = "/fileToDelete.txt";
|
||||
|
||||
private static boolean mGlobalSetupDone = false;
|
||||
|
||||
private TestActivity mActivity;
|
||||
|
||||
public DeleteFileTest() {
|
||||
super(TestActivity.class);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -56,6 +61,28 @@ public class DeleteFileTest extends ActivityInstrumentationTestCase2<TestActivit
|
||||
super.setUp();
|
||||
setActivityInitialTouchMode(false);
|
||||
mActivity = getActivity();
|
||||
|
||||
if (!mGlobalSetupDone) {
|
||||
|
||||
Log.v(LOG_TAG, "Starting global set up");
|
||||
RemoteOperationResult result = mActivity.createFolder(FOLDER_PATH, true);
|
||||
if (!result.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, result);
|
||||
}
|
||||
|
||||
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
|
||||
result = mActivity.uploadFile(
|
||||
textFile.getAbsolutePath(),
|
||||
FILE_PATH,
|
||||
"txt/plain");
|
||||
if (!result.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, result);
|
||||
}
|
||||
|
||||
Log.v(LOG_TAG, "Global set up done");
|
||||
mGlobalSetupDone = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,8 +90,8 @@ public class DeleteFileTest extends ActivityInstrumentationTestCase2<TestActivit
|
||||
*/
|
||||
public void testRemoveFolder() {
|
||||
|
||||
RemoteOperationResult result = mActivity.removeFile(mFolderPath);
|
||||
assertTrue(result.isSuccess() || result.getCode() == ResultCode.FILE_NOT_FOUND);
|
||||
RemoteOperationResult result = mActivity.removeFile(FOLDER_PATH);
|
||||
assertTrue(result.isSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,16 +99,17 @@ public class DeleteFileTest extends ActivityInstrumentationTestCase2<TestActivit
|
||||
*/
|
||||
public void testRemoveFile() {
|
||||
|
||||
RemoteOperationResult result = mActivity.removeFile(mFilePath);
|
||||
assertTrue(result.isSuccess() || result.getCode() == ResultCode.FILE_NOT_FOUND);
|
||||
RemoteOperationResult result = mActivity.removeFile(FILE_PATH);
|
||||
assertTrue(result.isSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore initial conditions
|
||||
*/
|
||||
public void testRestoreInitialConditions() {
|
||||
RemoteOperationResult result = mActivity.createFolder(mFolderPath, true);
|
||||
assertTrue(result.isSuccess());
|
||||
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
// nothing to do:
|
||||
// - if tests were fine, there is nothing to clean up in the server side
|
||||
// - if tests failed, there is nothing we can do to clean up the server side
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
@ -24,41 +24,41 @@
|
||||
|
||||
package com.owncloud.android.lib.test_project.test;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.io.File;
|
||||
|
||||
import com.owncloud.android.lib.resources.files.RemoteFile;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||
import com.owncloud.android.lib.test_project.TestActivity;
|
||||
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Class to test Download File Operation
|
||||
* @author masensio
|
||||
*
|
||||
* @author David A. Velasco
|
||||
*/
|
||||
|
||||
public class DownloadFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
|
||||
|
||||
|
||||
private static final String LOG_TAG = DownloadFileTest.class.getCanonicalName();
|
||||
|
||||
/* Files to download. These files must exist on the account */
|
||||
private final String mRemoteFilePng = "/fileToDownload.png";
|
||||
private final String mRemoteFileChunks = "/fileToDownload.mp4";
|
||||
private final String mRemoteFileSpecialChars = "/@file@download.png";
|
||||
private final String mRemoteFileSpecialCharsChunks = "/@file@download.mp4";
|
||||
private final String mRemoteFileNotFound = "/fileNotFound.png"; /* This file mustn't exist on the account */
|
||||
|
||||
private String mCurrentDate;
|
||||
private static final String IMAGE_PATH = "/fileToDownload.png";
|
||||
private static final String IMAGE_PATH_WITH_SPECIAL_CHARS = "/@file@download.png";
|
||||
private static final String IMAGE_NOT_FOUND = "/fileNotFound.png";
|
||||
private static final String [] FILE_PATHS = { IMAGE_PATH, IMAGE_PATH_WITH_SPECIAL_CHARS };
|
||||
|
||||
private static boolean mGlobalSetupDone = false;
|
||||
|
||||
private String mDownloadedFilePath;
|
||||
private TestActivity mActivity;
|
||||
|
||||
|
||||
public DownloadFileTest() {
|
||||
super(TestActivity.class);
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
|
||||
mCurrentDate = sdf.format(new Date());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -66,67 +66,86 @@ public class DownloadFileTest extends ActivityInstrumentationTestCase2<TestActiv
|
||||
super.setUp();
|
||||
setActivityInitialTouchMode(false);
|
||||
mActivity = getActivity();
|
||||
mDownloadedFilePath = null;
|
||||
|
||||
if (!mGlobalSetupDone) {
|
||||
|
||||
RemoteOperationResult result = null;
|
||||
File imageFile = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME);
|
||||
|
||||
for (int i=0; i<FILE_PATHS.length && (result == null || result.isSuccess()); i++) {
|
||||
result = mActivity.uploadFile(
|
||||
imageFile.getAbsolutePath(),
|
||||
FILE_PATHS[i],
|
||||
"image/png");
|
||||
}
|
||||
if (!result.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, result);
|
||||
}
|
||||
|
||||
result = mActivity.removeFile(IMAGE_NOT_FOUND);
|
||||
if (!result.isSuccess() && result.getCode() != ResultCode.FILE_NOT_FOUND) {
|
||||
Utils.logAndThrow(LOG_TAG, result);
|
||||
}
|
||||
|
||||
Log.v(LOG_TAG, "Global set up done");
|
||||
mGlobalSetupDone = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Download a File
|
||||
*/
|
||||
public void testDownloadFile() {
|
||||
String temporalFolder = "/download" + mCurrentDate;
|
||||
|
||||
RemoteFile remoteFile= new RemoteFile(mRemoteFilePng);
|
||||
|
||||
RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
|
||||
assertTrue(result.isSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Download a File with chunks
|
||||
*/
|
||||
public void testDownloadFileChunks() {
|
||||
String temporalFolder = "/download" + mCurrentDate;
|
||||
|
||||
RemoteFile remoteFile= new RemoteFile(mRemoteFileChunks);
|
||||
|
||||
RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
|
||||
RemoteOperationResult result = mActivity.downloadFile(
|
||||
new RemoteFile(IMAGE_PATH),
|
||||
mActivity.getFilesDir().getAbsolutePath()
|
||||
);
|
||||
mDownloadedFilePath = IMAGE_PATH;
|
||||
assertTrue(result.isSuccess());
|
||||
// TODO some checks involving the local file
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Download a File with special chars
|
||||
*/
|
||||
public void testDownloadFileSpecialChars() {
|
||||
String temporalFolder = "/download" + mCurrentDate;
|
||||
|
||||
RemoteFile remoteFile= new RemoteFile(mRemoteFileSpecialChars);
|
||||
|
||||
RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
|
||||
assertTrue(result.isSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Download a File with special chars and chunks
|
||||
*/
|
||||
public void testDownloadFileSpecialCharsChunks() {
|
||||
String temporalFolder = "/download" + mCurrentDate;
|
||||
|
||||
RemoteFile remoteFile= new RemoteFile(mRemoteFileSpecialCharsChunks);
|
||||
|
||||
RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
|
||||
RemoteOperationResult result = mActivity.downloadFile(
|
||||
new RemoteFile(IMAGE_PATH_WITH_SPECIAL_CHARS),
|
||||
mActivity.getFilesDir().getAbsolutePath()
|
||||
);
|
||||
mDownloadedFilePath = IMAGE_PATH_WITH_SPECIAL_CHARS;
|
||||
assertTrue(result.isSuccess());
|
||||
// TODO some checks involving the local file
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Download a Not Found File
|
||||
*/
|
||||
public void testDownloadFileNotFound() {
|
||||
String temporalFolder = "/download" + mCurrentDate;
|
||||
|
||||
RemoteFile remoteFile = new RemoteFile(mRemoteFileNotFound);
|
||||
|
||||
RemoteOperationResult result = mActivity.downloadFile(remoteFile, temporalFolder);
|
||||
RemoteOperationResult result = mActivity.downloadFile(
|
||||
new RemoteFile(IMAGE_NOT_FOUND),
|
||||
mActivity.getFilesDir().getAbsolutePath()
|
||||
);
|
||||
assertFalse(result.isSuccess());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if (mDownloadedFilePath != null) {
|
||||
RemoteOperationResult removeResult = mActivity.removeFile(mDownloadedFilePath);
|
||||
if (!removeResult.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, removeResult);
|
||||
}
|
||||
}
|
||||
File[] files = mActivity.getFilesDir().listFiles();
|
||||
for (File file : files) {
|
||||
file.delete();
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -24,7 +24,10 @@
|
||||
|
||||
package com.owncloud.android.lib.test_project.test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.resources.shares.ShareType;
|
||||
import com.owncloud.android.lib.test_project.TestActivity;
|
||||
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
@ -38,6 +41,10 @@ import android.test.ActivityInstrumentationTestCase2;
|
||||
|
||||
public class GetSharesTest extends ActivityInstrumentationTestCase2<TestActivity> {
|
||||
|
||||
private static final String LOG_TAG = GetSharesTest.class.getCanonicalName();
|
||||
|
||||
private static final String SHARED_FILE = "/sharedFileToGet.txt";
|
||||
|
||||
private TestActivity mActivity;
|
||||
|
||||
public GetSharesTest() {
|
||||
@ -50,6 +57,21 @@ public class GetSharesTest extends ActivityInstrumentationTestCase2<TestActivity
|
||||
super.setUp();
|
||||
setActivityInitialTouchMode(false);
|
||||
mActivity = getActivity();
|
||||
|
||||
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
|
||||
RemoteOperationResult result = mActivity.uploadFile(
|
||||
textFile.getAbsolutePath(),
|
||||
SHARED_FILE,
|
||||
"txt/plain");
|
||||
if (!result.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, result);
|
||||
}
|
||||
|
||||
result = mActivity.createShare(SHARED_FILE, ShareType.PUBLIC_LINK, "", false, "", 1);
|
||||
if (!result.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,5 +80,18 @@ public class GetSharesTest extends ActivityInstrumentationTestCase2<TestActivity
|
||||
public void testGetShares() {
|
||||
RemoteOperationResult result = mActivity.getShares();
|
||||
assertTrue(result.isSuccess());
|
||||
assertTrue(result.getData() != null && result.getData().size() == 1);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
RemoteOperationResult removeResult = mActivity.removeFile(SHARED_FILE);
|
||||
if (!removeResult.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, removeResult);
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -23,6 +23,8 @@
|
||||
*/
|
||||
package com.owncloud.android.lib.test_project.test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.test_project.TestActivity;
|
||||
|
||||
@ -31,37 +33,56 @@ import android.test.ActivityInstrumentationTestCase2;
|
||||
/**
|
||||
* Class to test Read File Operation
|
||||
* @author masensio
|
||||
*
|
||||
* @author David A. Velasco
|
||||
*/
|
||||
|
||||
public class ReadFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
|
||||
|
||||
/* File data to read. This file must exist on the account */
|
||||
private final String mRemoteFolderPath = "/fileToRead.txt";
|
||||
|
||||
|
||||
private TestActivity mActivity;
|
||||
|
||||
public ReadFileTest() {
|
||||
super(TestActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
setActivityInitialTouchMode(false);
|
||||
mActivity = getActivity();
|
||||
}
|
||||
private static final String LOG_TAG = ReadFileTest.class.getCanonicalName();
|
||||
|
||||
private TestActivity mActivity;
|
||||
|
||||
private String FILE_PATH = "/fileToRead.txt";
|
||||
|
||||
public ReadFileTest() {
|
||||
super(TestActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
/**
|
||||
* Test Read File
|
||||
*/
|
||||
public void testReadFile() {
|
||||
|
||||
RemoteOperationResult result = mActivity.readFile(mRemoteFolderPath);
|
||||
assertTrue(result.getData().size() == 1);
|
||||
assertTrue(result.isSuccess());
|
||||
}
|
||||
|
||||
setActivityInitialTouchMode(false);
|
||||
mActivity = getActivity();
|
||||
|
||||
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
|
||||
RemoteOperationResult uploadResult = mActivity.uploadFile(
|
||||
textFile.getAbsolutePath(),
|
||||
FILE_PATH,
|
||||
"txt/plain");
|
||||
if (!uploadResult.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, uploadResult);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Read File
|
||||
*/
|
||||
public void testReadFile() {
|
||||
RemoteOperationResult result = mActivity.readFile(FILE_PATH);
|
||||
assertTrue(result.getData() != null && result.getData().size() == 1);
|
||||
assertTrue(result.isSuccess());
|
||||
// TODO check more properties of the result
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
RemoteOperationResult removeResult = mActivity.removeFile(FILE_PATH);
|
||||
if (!removeResult.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, removeResult);
|
||||
}
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
/* 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 java.io.File;
|
||||
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.test_project.TestActivity;
|
||||
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
|
||||
/**
|
||||
* Class to test Read Folder Operation
|
||||
* @author masensio
|
||||
* @author David A. Velasco
|
||||
*/
|
||||
|
||||
public class ReadFolderTest extends ActivityInstrumentationTestCase2<TestActivity> {
|
||||
|
||||
private static final String LOG_TAG = ReadFolderTest.class.getCanonicalName();
|
||||
|
||||
private static final String FOLDER_PATH = "/folderToRead";
|
||||
private static final String [] FILE_PATHS = {
|
||||
FOLDER_PATH + "/file1.txt",
|
||||
FOLDER_PATH + "/file2.txt",
|
||||
FOLDER_PATH + "/file3.txt",
|
||||
};
|
||||
|
||||
|
||||
private TestActivity mActivity;
|
||||
|
||||
public ReadFolderTest() {
|
||||
super(TestActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
setActivityInitialTouchMode(false);
|
||||
mActivity = getActivity();
|
||||
|
||||
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
|
||||
RemoteOperationResult result = mActivity.createFolder(FOLDER_PATH, true);
|
||||
if (result.isSuccess()) {
|
||||
for (int i=0; i<FILE_PATHS.length && result.isSuccess(); i++) {
|
||||
result = mActivity.uploadFile(
|
||||
textFile.getAbsolutePath(),
|
||||
FILE_PATHS[i],
|
||||
"txt/plain");
|
||||
}
|
||||
}
|
||||
|
||||
if (!result.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Read Folder
|
||||
*/
|
||||
public void testReadFolder() {
|
||||
|
||||
RemoteOperationResult result = mActivity.readFile(FOLDER_PATH);
|
||||
assertTrue(result.isSuccess());
|
||||
assertTrue(result.getData() != null && result.getData().size() > 1);
|
||||
assertTrue(result.getData().size() == 4);
|
||||
// TODO assert more properties about the result
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
RemoteOperationResult removeResult = mActivity.removeFile(FOLDER_PATH);
|
||||
if (!removeResult.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, removeResult);
|
||||
}
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
@ -24,19 +24,25 @@
|
||||
|
||||
package com.owncloud.android.lib.test_project.test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.owncloud.android.lib.resources.shares.OCShare;
|
||||
import com.owncloud.android.lib.resources.shares.ShareType;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.test_project.TestActivity;
|
||||
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.util.Log;
|
||||
|
||||
public class RemoveShareTest extends ActivityInstrumentationTestCase2<TestActivity> {
|
||||
|
||||
private static final String TAG = RemoveShareTest.class.getSimpleName();
|
||||
private static final String LOG_TAG = RemoveShareTest.class.getCanonicalName();
|
||||
|
||||
private static final String FILE_TO_UNSHARE = "/fileToUnshare.txt";
|
||||
|
||||
private TestActivity mActivity;
|
||||
|
||||
private long mShareId;
|
||||
|
||||
public RemoveShareTest() {
|
||||
super(TestActivity.class);
|
||||
|
||||
@ -47,28 +53,42 @@ public class RemoveShareTest extends ActivityInstrumentationTestCase2<TestActivi
|
||||
super.setUp();
|
||||
setActivityInitialTouchMode(false);
|
||||
mActivity = getActivity();
|
||||
|
||||
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
|
||||
RemoteOperationResult result = mActivity.uploadFile(
|
||||
textFile.getAbsolutePath(),
|
||||
FILE_TO_UNSHARE,
|
||||
"txt/plain");
|
||||
if (!result.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, result);
|
||||
}
|
||||
|
||||
result = mActivity.createShare(FILE_TO_UNSHARE, ShareType.PUBLIC_LINK, "", false, "", 1);
|
||||
if (!result.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, result);
|
||||
} else {
|
||||
OCShare created = (OCShare) result.getData().get(0);
|
||||
mShareId = created.getIdRemoteShared();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Remove Share: the server must support SHARE API
|
||||
*/
|
||||
public void testRemoveShare() {
|
||||
// Get the shares
|
||||
RemoteOperationResult result = mActivity.getShares();
|
||||
if (result.isSuccess()) {
|
||||
int size = result.getData().size();
|
||||
|
||||
if (size > 0) {
|
||||
OCShare share = ((OCShare) result.getData().get(size -1));
|
||||
long id = share.getIdRemoteShared();
|
||||
Log.d(TAG, "File to unshare: " + share.getPath() );
|
||||
result = mActivity.removeShare((int) id); // Unshare
|
||||
assertTrue(result.isSuccess());
|
||||
} else {
|
||||
assertTrue(true);
|
||||
}
|
||||
} else {
|
||||
assertTrue(true);
|
||||
}
|
||||
RemoteOperationResult result = mActivity.removeShare((int) mShareId);
|
||||
assertTrue(result.isSuccess());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
RemoteOperationResult removeResult = mActivity.removeFile(FILE_TO_UNSHARE);
|
||||
if (!removeResult.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, removeResult);
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,241 @@
|
||||
/* 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 java.io.File;
|
||||
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
|
||||
import com.owncloud.android.lib.resources.files.FileUtils;
|
||||
import com.owncloud.android.lib.test_project.TestActivity;
|
||||
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Class to test Rename File Operation
|
||||
* @author masensio
|
||||
*
|
||||
*/
|
||||
|
||||
public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
|
||||
|
||||
private static final String LOG_TAG = RenameFileTest.class.getCanonicalName();
|
||||
|
||||
/* Folder data to rename. This folder must exist on the account */
|
||||
private static final String OLD_FOLDER_NAME = "folderToRename";
|
||||
private static final String OLD_FOLDER_PATH = FileUtils.PATH_SEPARATOR + OLD_FOLDER_NAME;
|
||||
private static final String NEW_FOLDER_NAME = "renamedFolder";
|
||||
private static final String NEW_FOLDER_PATH = FileUtils.PATH_SEPARATOR + NEW_FOLDER_NAME;
|
||||
|
||||
/* File data to rename. This file must exist on the account */
|
||||
private static final String OLD_FILE_NAME = "fileToRename.png";
|
||||
private static final String OLD_FILE_PATH = FileUtils.PATH_SEPARATOR + OLD_FILE_NAME;
|
||||
private static final String NEW_FILE_NAME = "renamedFile.png";
|
||||
private static final String NEW_FILE_PATH = FileUtils.PATH_SEPARATOR + NEW_FILE_NAME;
|
||||
|
||||
|
||||
private static boolean mGlobalSetupDone = false;
|
||||
|
||||
private String mToCleanUpInServer;
|
||||
private TestActivity mActivity;
|
||||
|
||||
public RenameFileTest() {
|
||||
super(TestActivity.class);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
setActivityInitialTouchMode(false);
|
||||
mActivity = getActivity();
|
||||
|
||||
if (!mGlobalSetupDone) {
|
||||
|
||||
Log.v(LOG_TAG, "Starting global set up");
|
||||
RemoteOperationResult result = mActivity.createFolder(OLD_FOLDER_NAME, true);
|
||||
if (!result.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, result);
|
||||
}
|
||||
|
||||
File imageFile = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME);
|
||||
result = mActivity.uploadFile(
|
||||
imageFile.getAbsolutePath(),
|
||||
OLD_FILE_PATH,
|
||||
"image/png");
|
||||
if (!result.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, result);
|
||||
}
|
||||
|
||||
Log.v(LOG_TAG, "Global set up done");
|
||||
mGlobalSetupDone = true;
|
||||
}
|
||||
|
||||
mToCleanUpInServer = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Rename Folder
|
||||
*/
|
||||
public void testRenameFolder() {
|
||||
|
||||
mToCleanUpInServer = OLD_FOLDER_PATH;
|
||||
RemoteOperationResult result = mActivity.renameFile(
|
||||
OLD_FOLDER_NAME,
|
||||
OLD_FOLDER_PATH,
|
||||
NEW_FOLDER_NAME,
|
||||
true);
|
||||
assertTrue(result.isSuccess());
|
||||
mToCleanUpInServer = NEW_FOLDER_PATH;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Rename Folder with forbidden characters : \ < > : " | ? *
|
||||
*/
|
||||
public void testRenameFolderForbiddenChars() {
|
||||
|
||||
RemoteOperationResult result = mActivity.renameFile(OLD_FOLDER_NAME, OLD_FOLDER_PATH,
|
||||
NEW_FOLDER_NAME + "\\", true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(OLD_FOLDER_NAME, OLD_FOLDER_PATH,
|
||||
NEW_FOLDER_NAME + "<", true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(OLD_FOLDER_NAME, OLD_FOLDER_PATH,
|
||||
NEW_FOLDER_NAME + ">", true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(OLD_FOLDER_NAME, OLD_FOLDER_PATH,
|
||||
NEW_FOLDER_NAME + ":", true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(OLD_FOLDER_NAME, OLD_FOLDER_PATH,
|
||||
NEW_FOLDER_NAME + "\"", true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(OLD_FOLDER_NAME, OLD_FOLDER_PATH,
|
||||
NEW_FOLDER_NAME + "|", true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(OLD_FOLDER_NAME, OLD_FOLDER_PATH,
|
||||
NEW_FOLDER_NAME + "?", true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(OLD_FOLDER_NAME, OLD_FOLDER_PATH,
|
||||
NEW_FOLDER_NAME + "*", true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Rename File
|
||||
*/
|
||||
public void testRenameFile() {
|
||||
mToCleanUpInServer = OLD_FILE_PATH;
|
||||
RemoteOperationResult result = mActivity.renameFile(
|
||||
OLD_FILE_NAME,
|
||||
OLD_FILE_PATH,
|
||||
NEW_FILE_NAME,
|
||||
false);
|
||||
assertTrue(result.isSuccess());
|
||||
mToCleanUpInServer = NEW_FILE_PATH;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test Rename Folder with forbidden characters: \ < > : " | ? *
|
||||
*/
|
||||
public void testRenameFileForbiddenChars() {
|
||||
RemoteOperationResult result = mActivity.renameFile(
|
||||
OLD_FILE_NAME,
|
||||
OLD_FILE_PATH,
|
||||
"\\" + NEW_FILE_NAME,
|
||||
false);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(
|
||||
OLD_FILE_NAME,
|
||||
OLD_FILE_PATH,
|
||||
"<" + NEW_FILE_NAME,
|
||||
false);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(
|
||||
OLD_FILE_NAME,
|
||||
OLD_FILE_PATH,
|
||||
">" + NEW_FILE_NAME,
|
||||
false);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(
|
||||
OLD_FILE_NAME,
|
||||
OLD_FILE_PATH,
|
||||
":" + NEW_FILE_NAME,
|
||||
false);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(
|
||||
OLD_FILE_NAME,
|
||||
OLD_FILE_PATH,
|
||||
"\"" + NEW_FILE_NAME,
|
||||
false);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(
|
||||
OLD_FILE_NAME,
|
||||
OLD_FILE_PATH,
|
||||
"|" + NEW_FILE_NAME,
|
||||
false);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(
|
||||
OLD_FILE_NAME,
|
||||
OLD_FILE_PATH,
|
||||
"?" + NEW_FILE_NAME,
|
||||
false);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(
|
||||
OLD_FILE_NAME,
|
||||
OLD_FILE_PATH,
|
||||
"*" + NEW_FILE_NAME, false);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if (mToCleanUpInServer != null) {
|
||||
RemoteOperationResult removeResult = mActivity.removeFile(mToCleanUpInServer);
|
||||
if (!removeResult.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, removeResult);
|
||||
}
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,127 @@
|
||||
/* 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 java.io.File;
|
||||
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.test_project.TestActivity;
|
||||
|
||||
/**
|
||||
* Class to test Update File Operation
|
||||
* @author masensio
|
||||
* @author David A. Velasco
|
||||
*
|
||||
*/
|
||||
|
||||
public class UploadFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
|
||||
|
||||
private static final String LOG_TAG = UploadFileTest.class.getCanonicalName();
|
||||
|
||||
private static final String UPLOAD_PATH = "/uploadedImage.png";
|
||||
|
||||
private static final String CHUNKED_UPLOAD_PATH = "/uploadedVideo.MP4";
|
||||
|
||||
private static final String FILE_NOT_FOUND_PATH = "/notFoundShouldNotBeHere.png";
|
||||
|
||||
|
||||
private TestActivity mActivity;
|
||||
private File mFileToUpload, mFileToUploadWithChunks;
|
||||
private String mUploadedFilePath;
|
||||
|
||||
|
||||
public UploadFileTest() {
|
||||
super(TestActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
setActivityInitialTouchMode(false);
|
||||
mActivity = getActivity();
|
||||
mUploadedFilePath = null;
|
||||
|
||||
mFileToUpload = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME);
|
||||
mFileToUploadWithChunks = mActivity.extractAsset(TestActivity.ASSETS__VIDEO_FILE_NAME);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test Upload File without chunks
|
||||
*/
|
||||
public void testUploadFile() {
|
||||
|
||||
RemoteOperationResult result = mActivity.uploadFile(
|
||||
mFileToUpload.getAbsolutePath(),
|
||||
UPLOAD_PATH,
|
||||
"image/png"
|
||||
);
|
||||
mUploadedFilePath = UPLOAD_PATH;
|
||||
assertTrue(result.isSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Upload File with chunks
|
||||
*/
|
||||
public void testUploadFileWithChunks() {
|
||||
|
||||
RemoteOperationResult result = mActivity.uploadFile(
|
||||
mFileToUploadWithChunks.getAbsolutePath(),
|
||||
CHUNKED_UPLOAD_PATH,
|
||||
"video/mp4"
|
||||
);
|
||||
mUploadedFilePath = CHUNKED_UPLOAD_PATH;
|
||||
assertTrue(result.isSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Upload Not Found File
|
||||
*/
|
||||
public void testUploadFileNotFound() {
|
||||
|
||||
RemoteOperationResult result = mActivity.uploadFile(
|
||||
FILE_NOT_FOUND_PATH,
|
||||
FILE_NOT_FOUND_PATH,
|
||||
"image/png"
|
||||
);
|
||||
mUploadedFilePath = FILE_NOT_FOUND_PATH;
|
||||
assertFalse(result.isSuccess());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if (mUploadedFilePath != null) {
|
||||
RemoteOperationResult removeResult = mActivity.removeFile(mUploadedFilePath);
|
||||
if (!removeResult.isSuccess()) {
|
||||
Utils.logAndThrow(LOG_TAG, removeResult);
|
||||
}
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
@ -24,46 +24,15 @@
|
||||
|
||||
package com.owncloud.android.lib.test_project.test;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.test_project.TestActivity;
|
||||
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
public class Utils {
|
||||
|
||||
/**
|
||||
* Class to test Read Folder Operation
|
||||
* @author masensio
|
||||
*
|
||||
*/
|
||||
|
||||
public class ReadFolderTest extends ActivityInstrumentationTestCase2<TestActivity> {
|
||||
|
||||
|
||||
/* Folder data to read. This folder must exist on the account */
|
||||
private final String mRemoteFolderPath = "/folderToRead";
|
||||
|
||||
|
||||
private TestActivity mActivity;
|
||||
|
||||
public ReadFolderTest() {
|
||||
super(TestActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
setActivityInitialTouchMode(false);
|
||||
mActivity = getActivity();
|
||||
public static void logAndThrow(String tag, RemoteOperationResult result) throws Exception {
|
||||
Log.e(tag, result.getLogMessage(), result.getException());
|
||||
throw new Exception(result.getLogMessage(), result.getException());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Read Folder
|
||||
*/
|
||||
public void testReadFolder() {
|
||||
|
||||
RemoteOperationResult result = mActivity.readFile(mRemoteFolderPath);
|
||||
assertTrue(result.getData().size() > 1);
|
||||
assertTrue(result.getData().size() == 4);
|
||||
assertTrue(result.isSuccess());
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
@ -1,4 +0,0 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
@ -1,177 +0,0 @@
|
||||
/* 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 Rename File Operation
|
||||
* @author masensio
|
||||
*
|
||||
*/
|
||||
|
||||
public class RenameFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
|
||||
|
||||
/* Folder data to rename. This folder must exist on the account */
|
||||
private final String mOldFolderName = "folderToRename";
|
||||
private final String mOldFolderPath = "/folderToRename";
|
||||
private final String mNewFolderName = "renamedFolder";
|
||||
private final String mNewFolderPath = "/renamedFolder";
|
||||
|
||||
/* File data to rename. This file must exist on the account */
|
||||
private final String mOldFileName = "fileToRename.png";
|
||||
private final String mOldFilePath = "/fileToRename.png";
|
||||
private final String mNewFileName = "renamedFile";
|
||||
private final String mFileExtension = ".png";
|
||||
private final String mNewFilePath ="/renamedFile.png";
|
||||
|
||||
|
||||
private TestActivity mActivity;
|
||||
|
||||
public RenameFileTest() {
|
||||
super(TestActivity.class);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
setActivityInitialTouchMode(false);
|
||||
mActivity = getActivity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Rename Folder
|
||||
*/
|
||||
public void testRenameFolder() {
|
||||
|
||||
RemoteOperationResult result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
|
||||
mNewFolderName, true);
|
||||
assertTrue(result.isSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Rename Folder with forbidden characters : \ < > : " | ? *
|
||||
*/
|
||||
public void testRenameFolderForbiddenChars() {
|
||||
|
||||
RemoteOperationResult result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
|
||||
mNewFolderName + "\\", true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
|
||||
mNewFolderName + "<", true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
|
||||
mNewFolderName + ">", true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
|
||||
mNewFolderName + ":", true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
|
||||
mNewFolderName + "\"", true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
|
||||
mNewFolderName + "|", true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
|
||||
mNewFolderName + "?", true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(mOldFolderName, mOldFolderPath,
|
||||
mNewFolderName + "*", true);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Rename File
|
||||
*/
|
||||
public void testRenameFile() {
|
||||
RemoteOperationResult result = mActivity.renameFile(mOldFileName, mOldFilePath,
|
||||
mNewFileName + mFileExtension, false);
|
||||
assertTrue(result.isSuccess());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test Rename Folder with forbidden characters: \ < > : " | ? *
|
||||
*/
|
||||
public void testRenameFileForbiddenChars() {
|
||||
RemoteOperationResult result = mActivity.renameFile(mOldFileName, mOldFilePath,
|
||||
mNewFileName + "\\" + mFileExtension, false);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(mOldFileName, mOldFilePath,
|
||||
mNewFileName + "<" + mFileExtension, false);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(mOldFileName, mOldFilePath,
|
||||
mNewFileName + ">" + mFileExtension, false);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(mOldFileName, mOldFilePath,
|
||||
mNewFileName + ":" + mFileExtension, false);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(mOldFileName, mOldFilePath,
|
||||
mNewFileName + "\"" + mFileExtension, false);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(mOldFileName, mOldFilePath,
|
||||
mNewFileName + "|" + mFileExtension, false);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(mOldFileName, mOldFilePath,
|
||||
mNewFileName + "?" + mFileExtension, false);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
result = mActivity.renameFile(mOldFileName, mOldFilePath,
|
||||
mNewFileName + "*" + mFileExtension, false);
|
||||
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Restore initial conditions
|
||||
*/
|
||||
public void testRestoreInitialConditions() {
|
||||
RemoteOperationResult result = mActivity.renameFile(mNewFolderName, mNewFolderPath, mOldFolderName, true);
|
||||
assertTrue(result.isSuccess());
|
||||
|
||||
result = mActivity.renameFile(mNewFileName + mFileExtension, mNewFilePath, mOldFileName, false);
|
||||
assertTrue(result.isSuccess());
|
||||
}
|
||||
|
||||
}
|
@ -1,168 +0,0 @@
|
||||
/* 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 java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.Environment;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.util.Log;
|
||||
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.test_project.TestActivity;
|
||||
|
||||
/**
|
||||
* Class to test Update File Operation
|
||||
* @author masensio
|
||||
*
|
||||
*/
|
||||
|
||||
public class UploadFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
|
||||
|
||||
/* Files to upload. These files must exists on the device */
|
||||
private final String mFileToUpload = "fileToUpload.png";
|
||||
private final String mMimeType = "image/png";
|
||||
|
||||
private final String mFileToUploadWithChunks = "fileToUploadChunks.MP4";
|
||||
private final String mMimeTypeWithChunks = "video/mp4";
|
||||
|
||||
private final String mFileNotFound = "fileNotFound.png";
|
||||
|
||||
private final String mStoragePath = "/owncloud/tmp/uploadTest";
|
||||
private String mPath;
|
||||
|
||||
private String mCurrentDate;
|
||||
|
||||
private TestActivity mActivity;
|
||||
|
||||
public UploadFileTest() {
|
||||
super(TestActivity.class);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
setActivityInitialTouchMode(false);
|
||||
mActivity = getActivity();
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
|
||||
mCurrentDate = sdf.format(new Date());
|
||||
|
||||
File sdCard = Environment.getExternalStorageDirectory();
|
||||
mPath = sdCard.getAbsolutePath() + "/" + mStoragePath + mCurrentDate;
|
||||
|
||||
//mActivity.createFolder(mPath, true);
|
||||
|
||||
copyAssets();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy Files to ulpload to SdCard
|
||||
*/
|
||||
private void copyAssets() {
|
||||
AssetManager assetManager = getActivity().getAssets();
|
||||
String[] files = { mFileToUpload, mFileToUploadWithChunks };
|
||||
|
||||
// Folder with contents
|
||||
File folder = new File(mPath);
|
||||
folder.mkdirs();
|
||||
|
||||
|
||||
for(String filename : files) {
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
try {
|
||||
in = assetManager.open(filename);
|
||||
File outFile = new File(folder, filename);
|
||||
out = new FileOutputStream(outFile);
|
||||
copyFile(in, out);
|
||||
in.close();
|
||||
in = null;
|
||||
out.flush();
|
||||
out.close();
|
||||
out = null;
|
||||
} catch(IOException e) {
|
||||
Log.e("tag", "Failed to copy asset file: " + filename, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void copyFile(InputStream in, OutputStream out) throws IOException {
|
||||
byte[] buffer = new byte[1024];
|
||||
int read;
|
||||
while((read = in.read(buffer)) != -1){
|
||||
out.write(buffer, 0, read);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test Upload File without chunks
|
||||
*/
|
||||
public void testUploadFile() {
|
||||
|
||||
String storagePath = mPath + "/" + mFileToUpload;
|
||||
//String remotePath = "/uploadTest" + mCurrentDate + "/" + mFileToUpload;
|
||||
String remotePath = "/" + mFileToUpload;
|
||||
|
||||
RemoteOperationResult result = mActivity.uploadFile(storagePath, remotePath, mMimeType);
|
||||
assertTrue(result.isSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Upload File with chunks
|
||||
*/
|
||||
public void testUploadFileWithChunks() {
|
||||
|
||||
String storagePath = mPath + "/" + mFileToUploadWithChunks;
|
||||
//String remotePath = "/uploadTest" + mCurrentDate + "/" +mFileToUploadWithChunks;
|
||||
String remotePath = "/" + mFileToUploadWithChunks;
|
||||
|
||||
RemoteOperationResult result = mActivity.uploadFile(storagePath, remotePath, mMimeTypeWithChunks);
|
||||
assertTrue(result.isSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Upload Not Found File
|
||||
*/
|
||||
public void testUploadFileNotFound() {
|
||||
|
||||
String storagePath = mPath + "/" + mFileNotFound;
|
||||
//String remotePath = "/uploadTest" + mCurrentDate + "/" + mFileToUpload;
|
||||
String remotePath = "/" + mFileNotFound;
|
||||
|
||||
RemoteOperationResult result = mActivity.uploadFile(storagePath, remotePath, mMimeType);
|
||||
assertFalse(result.isSuccess());
|
||||
}
|
||||
|
||||
}
|
19
wait_for_emulator.sh
Normal file
@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
bootanim=""
|
||||
failcounter=0
|
||||
checkcounter=0
|
||||
until [[ "$bootanim" =~ "stopped" ]]; do
|
||||
bootanim=`adb -e shell getprop init.svc.bootanim 2>&1`
|
||||
echo "($checkcounter) $bootanim"
|
||||
if [[ "$bootanim" =~ "not found" ]]; then
|
||||
let "failcounter += 1"
|
||||
if [[ $failcounter -gt 30 ]]; then
|
||||
echo "Failed to start emulator"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
let "checkcounter += 1"
|
||||
sleep 10
|
||||
done
|
||||
echo "Done"
|