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

Merge pull request #211 from owncloud/cleanup/old_tests

Get rid of old ant tests
This commit is contained in:
Thomas Müller 2018-11-09 08:47:35 +01:00 committed by GitHub
commit e1b09a5ff5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
73 changed files with 3 additions and 6021 deletions

View File

@ -17,25 +17,14 @@ install:
- yes | sdkmanager --list
# After Travis updated image with Android base environment, building via ant is not possible anymore.
# Library tests are old-style tests, and trust on legacy Android ant environment.
# Need to disable tests until they are ported to JUnit 4 and gradle build.
#- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI -c 20M
#- emulator -avd test -no-window &
# Port library tests to new-style with JUnit 4 and gradle build.
- rm pom.xml
#- android update project -p .
#- chmod +x ./wait_for_emulator.sh
#- ./wait_for_emulator.sh
#
# On the other hand, Travis still uses 'android' command behind the 'components' section update.
# That command is obsolete and cannot update Android SDK Tools after 25.2.5.
# Let's solve it here with the new command 'sdkmanager'
- yes | sdkmanager --verbose tools
script:
#- ant clean
#- ant debug
#- cd test_client/tests
#- ant acceptance-test
#- cd ../..
- ./gradlew clean build
env:
global:

View File

@ -1,3 +1,2 @@
include ':'
include ':sample_client'
include ':test_client'
include ':sample_client'

View File

@ -1,9 +0,0 @@
<?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="output" path="bin/classes"/>
</classpath>

View File

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ownCloud Android library test project</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -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

View File

@ -1,60 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- ownCloud Android Library is available under MIT license
Copyright (C) 2016 ownCloud GmbH.
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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.owncloud.android.lib.test_project"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="26" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.owncloud.android.lib.test_project.TestActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

View File

@ -1,3 +0,0 @@
This is a simple text file.
To make some tests.

Binary file not shown.

View File

@ -1,50 +0,0 @@
apply plugin: 'com.android.application'
repositories {
jcenter()
}
dependencies {
implementation project(':')
}
android {
compileSdkVersion 26
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
androidTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
lintOptions {
abortOnError false
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

View File

@ -1,92 +0,0 @@
<?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>

View File

@ -1,75 +0,0 @@
<?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"&gt;)\s*(&lt;)'
replace="\1${env.OCTEST_SERVER_BASE_URL}\2"
byline="true" />
</then>
</if>
<!-- Replace OC server URL 2 if set in environment -->
<if>
<condition>
<isset property="env.OCTEST_SERVER_BASE_URL_2" />
</condition>
<then>
<replaceregexp
file="res/values/setup.xml"
match='("server_base_url_2"&gt;)\s*(&lt;)'
replace="\1${env.OCTEST_SERVER_BASE_URL_2}\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"&gt;)\s*(&lt;)'
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"&gt;)\s*(&lt;)'
replace="\1${env.OCTEST_PASSWORD}\2"
byline="true" />
</then>
</if>
<!-- Make Travis build number available to the test app in the emulator -->
<if>
<condition>
<isset property="env.TRAVIS_BUILD_NUMBER" />
</condition>
<then>
<replaceregexp
file="res/values/setup.xml"
match='("build_number"&gt;)\s*(&lt;)'
replace="\1${env.TRAVIS_BUILD_NUMBER}\2"
byline="true" />
</then>
</if>
</target>
</project>

Binary file not shown.

View File

@ -1,6 +0,0 @@
#Mon Dec 28 10:00:20 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

164
test_client/gradlew vendored
View File

@ -1,164 +0,0 @@
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

View File

@ -1,90 +0,0 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

View File

@ -1,15 +0,0 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-24
android.library.reference.1=..

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

View File

@ -1,39 +0,0 @@
<!-- ownCloud Android Library is available under MIT license
Copyright (C) 2016 ownCloud GmbH.
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.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".TestActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>

View File

@ -1,32 +0,0 @@
<!-- ownCloud Android Library is available under MIT license
Copyright (C) 2016 ownCloud GmbH.
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.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>
</menu>

View File

@ -1,32 +0,0 @@
<!-- ownCloud Android Library is available under MIT license
Copyright (C) 2016 ownCloud GmbH.
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.
-->
<resources>
<!--
Customize dimensions originally defined in res/values/dimens.xml (such as
screen margins) for sw600dp devices (e.g. 7" tablets) here.
-->
</resources>

View File

@ -1,33 +0,0 @@
<!-- ownCloud Android Library is available under MIT license
Copyright (C) 2016 ownCloud GmbH.
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.
-->
<resources>
<!--
Customize dimensions originally defined in res/values/dimens.xml (such as
screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
-->
<dimen name="activity_horizontal_margin">128dp</dimen>
</resources>

View File

@ -1,35 +0,0 @@
<!-- ownCloud Android Library is available under MIT license
Copyright (C) 2016 ownCloud GmbH.
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.
-->
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>

View File

@ -1,36 +0,0 @@
<!-- ownCloud Android Library is available under MIT license
Copyright (C) 2016 ownCloud GmbH.
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.
-->
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>

View File

@ -1,30 +0,0 @@
<!-- ownCloud Android Library is available under MIT license
Copyright (C) 2016 ownCloud GmbH.
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.
-->
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>

View File

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- ownCloud Android Library is available under MIT license
Copyright (C) 2016 ownCloud GmbH.
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.
-->
<resources>
<string name="build_number"></string>
<string name="server_base_url">https://qa.oc.solidgear.es</string>
<string name="server_base_url_2">https://qa2.oc.solidgear.es</string>
<string name="username">android-library-test</string>
<string name="password">letitgo,letitgo,thatperfectappisgone</string>
<string name ="user_agent">Mozilla/5.0 (Android) ownCloud test project</string>
</resources>

View File

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- ownCloud Android Library is available under MIT license
Copyright (C) 2016 ownCloud GmbH.
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.
-->
<resources>
<string name="app_name">oc_framework-test-project</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="test_account_not_found">The test account %1$s could not be found in the device</string>
</resources>

View File

@ -1,43 +0,0 @@
<!-- ownCloud Android Library is available under MIT license
Copyright (C) 2016 ownCloud GmbH.
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.
-->
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>

View File

@ -1,2 +0,0 @@
include ':tests'
include ':'

View File

@ -1,371 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2018 ownCloud GmbH.
*
* 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 android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.CreateRemoteFolderOperation;
import com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation;
import com.owncloud.android.lib.resources.files.ReadRemoteFolderOperation;
import com.owncloud.android.lib.resources.files.RemoteFile;
import com.owncloud.android.lib.resources.files.RemoveRemoteFileOperation;
import com.owncloud.android.lib.resources.files.RenameRemoteFileOperation;
import com.owncloud.android.lib.resources.files.UploadRemoteFileOperation;
import com.owncloud.android.lib.resources.files.chunks.ChunkedUploadRemoteFileOperation;
import com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation;
import com.owncloud.android.lib.resources.shares.GetRemoteSharesOperation;
import com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.users.GetRemoteUserAvatarOperation;
import com.owncloud.android.lib.resources.users.GetRemoteUserQuotaOperation;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* Activity to test OC framework
* @author masensio
* @author David A. Velasco
* @author David González Verdugo
*/
public class TestActivity extends Activity {
private static final String TAG = null;
// This account must exists on the server side
private String mServerUri;
private String mUser;
private String mPass;
private static final int BUFFER_SIZE = 1024;
public static final String ASSETS__TEXT_FILE_NAME = "textFile.txt";
public static final String ASSETS__IMAGE_FILE_NAME = "imageFile.png";
public static final String ASSETS__VIDEO_FILE_NAME = "videoFile.MP4";
//private Account mAccount = null;
private OwnCloudClient mClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
mServerUri = getString(R.string.server_base_url);
mUser = getString(R.string.username);
mPass = getString(R.string.password);
mClient = new OwnCloudClient(Uri.parse(mServerUri));
mClient.setFollowRedirects(true);
mClient.setCredentials(
OwnCloudCredentialsFactory.newBasicCredentials(
mUser,
mPass
)
);
mClient.setBaseUri(Uri.parse(mServerUri));
Log.v(TAG, "onCreate finished, ownCloud client ready");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.test, menu);
return true;
}
/**
* Access to the library method to Create a Folder
* @param remotePath Full path to the new directory to create in the remote server.
* @param createFullPath 'True' means that all the ancestor folders should be created if
* don't exist yet.
*
* @return
*/
public RemoteOperationResult createFolder(String remotePath, boolean createFullPath) {
return TestActivity.createFolder(remotePath, createFullPath, mClient);
}
/**
* Access to the library method to Create a Folder
* @param remotePath Full path to the new directory to create in the remote server.
* @param createFullPath 'True' means that all the ancestor folders should be created if
* don't exist yet.
* @param client Client instance configured to access the target OC server.
*
* @return Result of the operation
*/
public static RemoteOperationResult createFolder(
String remotePath, boolean createFullPath, OwnCloudClient client
) {
CreateRemoteFolderOperation createOperation =
new CreateRemoteFolderOperation(remotePath, createFullPath);
RemoteOperationResult result = createOperation.execute(client);
return result;
}
/**
* Access to the library method to Rename a File or Folder
* @param oldName Old name of the file.
* @param oldRemotePath Old remote path of the file. For folders it starts and ends by "/"
* @param newName New name to set as the name of file.
* @param isFolder 'true' for folder and 'false' for files
*
* @return
*/
public RemoteOperationResult renameFile(String oldName, String oldRemotePath, String newName, boolean isFolder) {
RenameRemoteFileOperation renameOperation = new RenameRemoteFileOperation(oldName, oldRemotePath, newName, isFolder);
RemoteOperationResult result = renameOperation.execute(mClient);
return result;
}
/**
* Access to the library method to Remove a File or Folder
*
* @param remotePath Remote path of the file or folder in the server.
* @return
*/
public RemoteOperationResult removeFile(String remotePath) {
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
RemoteOperationResult result = removeOperation.execute(mClient);
return result;
}
/**
* Access to the library method to Remove a File or Folder
*
* @param remotePath Remote path of the file or folder in the server.
* @return
*/
public static RemoteOperationResult removeFile(String remotePath, OwnCloudClient client) {
RemoveRemoteFileOperation removeOperation = new RemoveRemoteFileOperation(remotePath);
RemoteOperationResult result = removeOperation.execute(client);
return result;
}
/**
* Access to the library method to Read a Folder (PROPFIND DEPTH 1)
* @param remotePath
*
* @return
*/
public RemoteOperationResult readFile(String remotePath) {
ReadRemoteFolderOperation readOperation= new ReadRemoteFolderOperation(remotePath);
RemoteOperationResult result = readOperation.execute(mClient);
return result;
}
/**
* Access to the library method to Download a File
* @param remotePath
*
* @return
*/
public RemoteOperationResult downloadFile(RemoteFile remoteFile, String temporalFolder) {
// Create folder
String path = "/owncloud/tmp/" + temporalFolder;
File privateFolder = getFilesDir();
File folder = new File(privateFolder.getAbsolutePath() + "/" + path);
folder.mkdirs();
DownloadRemoteFileOperation downloadOperation = new DownloadRemoteFileOperation(remoteFile.getRemotePath(), folder.getAbsolutePath());
RemoteOperationResult result = downloadOperation.execute(mClient);
return result;
}
/** Access to the library method to Upload a File
* @param storagePath
* @param remotePath
* @param mimeType
*
* @return
*/
public RemoteOperationResult uploadFile(
String storagePath, String remotePath, String mimeType
) {
return TestActivity.uploadFile(storagePath, remotePath, mimeType, mClient);
}
/** Access to the library method to Upload a File
* @param storagePath
* @param remotePath
* @param mimeType
* @param client Client instance configured to access the target OC server.
*
* @return
*/
public static RemoteOperationResult uploadFile(
String storagePath, String remotePath, String mimeType, OwnCloudClient client
) {
String fileLastModifTimestamp = getFileLastModifTimeStamp(storagePath);
UploadRemoteFileOperation uploadOperation;
if ((new File(storagePath)).length() > ChunkedUploadRemoteFileOperation.CHUNK_SIZE ) {
uploadOperation = new ChunkedUploadRemoteFileOperation("1",
storagePath, remotePath, mimeType, TAG, fileLastModifTimestamp
);
} else {
uploadOperation = new UploadRemoteFileOperation(
storagePath, remotePath, mimeType, fileLastModifTimestamp
);
}
RemoteOperationResult result = uploadOperation.execute(client);
return result;
}
/** Access to the library method to Get Shares
*
* @return
*/
public RemoteOperationResult getShares(){
GetRemoteSharesOperation getOperation = new GetRemoteSharesOperation();
RemoteOperationResult result = getOperation.execute(mClient);
return result;
}
/** Access to the library method to Create Share
* @param path Full path of the file/folder being shared. Mandatory argument
* @param shareType 0 = user, 1 = group, 3 = Public link. Mandatory argument
* @param shareWith User/group ID with who the file should be shared. This is mandatory for shareType of 0 or 1
* @param publicUpload If false (default) public cannot upload to a public shared folder.
* If true public can upload to a shared folder. Only available for public link shares
* @param password Password to protect a public link share. Only available for public link shares
* @param permissions 1 - Read only Default for public shares
* 2 - Update
* 4 - Create
* 8 - Delete
* 16- Re-share
* 31- All above Default for private shares
* For user or group shares.
* To obtain combinations, add the desired values together.
* For instance, for Re-Share, delete, read, update add 16+8+2+1 = 27.
*
* @return
*/
public RemoteOperationResult createShare(String path, ShareType shareType, String shareWith, boolean publicUpload,
String password, int permissions){
CreateRemoteShareOperation createOperation = new CreateRemoteShareOperation(path, shareType, shareWith, publicUpload, password, permissions);
RemoteOperationResult result = createOperation.execute(mClient);
return result;
}
/**
* Access to the library method to Remove Share
*
* @param idShare Share ID
*/
public RemoteOperationResult removeShare(int idShare) {
RemoveRemoteShareOperation removeOperation = new RemoveRemoteShareOperation(idShare);
RemoteOperationResult result = removeOperation.execute(mClient);
return result;
}
public RemoteOperationResult getQuota(String remotePath) {
GetRemoteUserQuotaOperation getUserQuotaOperation = new GetRemoteUserQuotaOperation(remotePath);
return getUserQuotaOperation.execute(mClient);
}
public RemoteOperationResult getUserAvatar(int dimension, String etag) {
GetRemoteUserAvatarOperation getUserAvatarOperation = new GetRemoteUserAvatarOperation(dimension, etag);
return getUserAvatarOperation.execute(mClient);
}
/**
* Extracts file from AssetManager to cache folder.
*
* @param fileName Name of the asset file to extract.
* @return File instance of the extracted file.
*/
public File extractAsset(String fileName) throws IOException {
return TestActivity.extractAsset(fileName, this);
}
/**
* Extracts file from AssetManager to cache folder.
*
* @param fileName Name of the asset file to extract.
* @param context Android context to access assets and file system.
* @return File instance of the extracted file.
*/
public static File extractAsset(String fileName, Context context) throws IOException {
File extractedFile = new File(context.getCacheDir() + File.separator + fileName);
if (!extractedFile.exists()) {
InputStream in = null;
FileOutputStream out = null;
in = context.getAssets().open(fileName);
out = new FileOutputStream(extractedFile);
byte[] buffer = new byte[BUFFER_SIZE];
int readCount;
while((readCount = in.read(buffer)) != -1){
out.write(buffer, 0, readCount);
}
out.flush();
out.close();
in.close();
}
return extractedFile;
}
private static String getFileLastModifTimeStamp (String storagePath) {
File file = new File(storagePath);
Long timeStampLong = file.lastModified()/1000;
return timeStampLong.toString();
}
}

View File

@ -1,10 +0,0 @@
<?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 combineaccessrules="false" kind="src" path="/ownCloud Android library test project"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View File

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ownCloud Android library test cases</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -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

View File

@ -1,41 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- ownCloud Android Library is available under MIT license
Copyright (C) 2016 ownCloud GmbH.
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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.owncloud.android.lib.test_project.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" />
<application>
<uses-library android:name="android.test.runner" />
</application>
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:label="Tests for com.owncloud.android.lib.test_project"
android:targetPackage="com.owncloud.android.lib.test_project" />
</manifest>

View File

@ -1,18 +0,0 @@
# 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=..

View File

@ -1,34 +0,0 @@
apply plugin: 'com.android.application'
dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
implementation project(':')
}
android {
compileSdkVersion 26
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
androidTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}

View File

@ -1,92 +0,0 @@
<?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>

View File

@ -1,20 +0,0 @@
<?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>

View File

@ -1,14 +0,0 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target
target=android-24

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

View File

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- ownCloud Android Library is available under MIT license
Copyright (C) 2016 ownCloud GmbH.
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.
-->
<resources>
<string name="app_name">Oc_framework-testTest</string>
</resources>

View File

@ -1,455 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import android.content.Context;
import android.net.Uri;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.common.network.NetworkUtils;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.resources.files.CopyRemoteFileOperation;
import com.owncloud.android.lib.test_project.R;
import com.owncloud.android.lib.test_project.TestActivity;
import junit.framework.AssertionFailedError;
import java.io.File;
import java.security.GeneralSecurityException;
//import android.test.AndroidTestCase;
/**
* Class to test CopyRemoteFileOperation
* <p/>
* With this TestCase we are experimenting a bit to improve the test suite design, in two aspects:
* <p/>
* - Reduce the dependency from the set of test cases on the "test project" needed to
* have an instrumented APK to install in the device, as required by the testing framework
* provided by Android. To get there, this class avoids calling TestActivity methods in the test
* method.
* <p/>
* - Reduce the impact of creating a remote fixture over the Internet, while the structure of the
* TestCase is kept easy to maintain. To get this, all the tests are done in a single test method,
* granting this way that setUp and tearDown are run only once.
*
* @author David A. Velasco
*/
//public class CopyFileTest extends AndroidTestCase {
public class CopyFileTest extends ActivityInstrumentationTestCase2<TestActivity> {
private static final String LOG_TAG = CopyFileTest.class.getCanonicalName();
/// Paths to files and folders in fixture
private static final String SRC_BASE_FOLDER = "/src/";
private static final String TARGET_BASE_FOLDER = "/target/";
private static final String NO_FILE = "nofile.txt";
private static final String FILE1 = "file1.txt";
private static final String FILE2 = "file2.txt";
private static final String FILE3 = "file3.txt";
private static final String FILE4 = "file4.txt";
private static final String FILE5 = "file5.txt";
private static final String FILE6 = "file6.txt";
private static final String FILE7 = "file7.txt";
private static final String EMPTY = "empty/";
private static final String NO_FOLDER = "nofolder/";
private static final String FOLDER1 = "folder1/";
private static final String FOLDER2 = "folder2/";
private static final String FOLDER3 = "folder3/";
private static final String FOLDER4 = "folder4/";
private static final String SRC_PATH_TO_FILE_1 = SRC_BASE_FOLDER + FILE1;
private static final String TARGET_PATH_TO_FILE_1 = TARGET_BASE_FOLDER + FILE1;
private static final String SRC_PATH_TO_FILE_2 = SRC_BASE_FOLDER + FILE2;
private static final String TARGET_PATH_TO_FILE_2_RENAMED =
TARGET_BASE_FOLDER + "renamed_" + FILE2;
private static final String SRC_PATH_TO_FILE_3 = SRC_BASE_FOLDER + FILE3;
private static final String SRC_PATH_TO_FILE_3_RENAMED = SRC_BASE_FOLDER + "renamed_" + FILE3;
private static final String SRC_PATH_TO_FILE_4 = SRC_BASE_FOLDER + FILE4;
private static final String SRC_PATH_TO_FILE_5 = SRC_BASE_FOLDER + FILE5;
private static final String SRC_PATH_TO_FILE_6 = SRC_BASE_FOLDER + FILE6;
private static final String SRC_PATH_TO_NON_EXISTENT_FILE = SRC_BASE_FOLDER + NO_FILE;
private static final String SRC_PATH_TO_EMPTY_FOLDER = SRC_BASE_FOLDER + EMPTY;
private static final String TARGET_PATH_TO_EMPTY_FOLDER = TARGET_BASE_FOLDER + EMPTY;
private static final String SRC_PATH_TO_FULL_FOLDER_1 = SRC_BASE_FOLDER + FOLDER1;
private static final String TARGET_PATH_TO_FULL_FOLDER_1 = TARGET_BASE_FOLDER + FOLDER1;
private static final String SRC_PATH_TO_FULL_FOLDER_2 = SRC_BASE_FOLDER + FOLDER2;
private static final String TARGET_PATH_TO_FULL_FOLDER_2_RENAMED =
TARGET_BASE_FOLDER + "renamed_" + FOLDER2;
private static final String SRC_PATH_TO_FULL_FOLDER_3 = SRC_BASE_FOLDER + FOLDER3;
private static final String SRC_PATH_TO_FULL_FOLDER_4 = SRC_BASE_FOLDER + FOLDER4;
private static final String SRC_PATH_TO_FULL_FOLDER_3_RENAMED =
SRC_BASE_FOLDER + "renamed_" + FOLDER3;
private static final String TARGET_PATH_RENAMED_WITH_INVALID_CHARS =
SRC_BASE_FOLDER + "renamed:??_" + FILE6;
private static final String TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4 = TARGET_BASE_FOLDER
+ FOLDER4;
private static final String TARGET_PATH_TO_NON_EXISTENT_FILE = TARGET_BASE_FOLDER + NO_FILE;
private static final String TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER =
TARGET_BASE_FOLDER + NO_FOLDER + FILE5;
private static final String TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7 = TARGET_BASE_FOLDER + FILE7;
private static final String[] FOLDERS_IN_FIXTURE = {
SRC_PATH_TO_EMPTY_FOLDER,
SRC_PATH_TO_FULL_FOLDER_1,
SRC_PATH_TO_FULL_FOLDER_1 + FOLDER1,
SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2,
SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FOLDER1,
SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FOLDER2,
SRC_PATH_TO_FULL_FOLDER_2,
SRC_PATH_TO_FULL_FOLDER_2 + FOLDER1,
SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2,
SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FOLDER1,
SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FOLDER2,
SRC_PATH_TO_FULL_FOLDER_3,
SRC_PATH_TO_FULL_FOLDER_3 + FOLDER1,
SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2,
SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FOLDER1,
SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FOLDER2,
SRC_PATH_TO_FULL_FOLDER_4,
SRC_PATH_TO_FULL_FOLDER_4 + FOLDER1,
SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2,
SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FOLDER1,
SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FOLDER2,
TARGET_BASE_FOLDER,
TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4
};
private static final String[] FILES_IN_FIXTURE = {
SRC_PATH_TO_FILE_1,
SRC_PATH_TO_FILE_2,
SRC_PATH_TO_FILE_3,
SRC_PATH_TO_FILE_4,
SRC_PATH_TO_FILE_5,
SRC_PATH_TO_FULL_FOLDER_1 + FILE1,
SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FILE1,
SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FILE2,
SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FOLDER2 + FILE2,
SRC_PATH_TO_FULL_FOLDER_2 + FILE1,
SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FILE1,
SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FILE2,
SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FOLDER2 + FILE2,
SRC_PATH_TO_FULL_FOLDER_3 + FILE1,
SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FILE1,
SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FILE2,
SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FOLDER2 + FILE2,
SRC_PATH_TO_FULL_FOLDER_4 + FILE1,
SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FILE1,
SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FILE2,
SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FOLDER2 + FILE2,
TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7
};
String mServerUri, mUser, mPass;
OwnCloudClient mClient = null;
public CopyFileTest() {
super(TestActivity.class);
Protocol pr = Protocol.getProtocol("https");
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
try {
ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
Protocol.registerProtocol(
"https",
new Protocol("https", psf, 443));
} catch (GeneralSecurityException e) {
throw new AssertionFailedError(
"Self-signed confident SSL context could not be loaded");
}
}
}
protected Context getContext() {
return getActivity();
}
@Override
protected void setUp() throws Exception {
super.setUp();
// Next initialization cannot be done in the constructor because getContext() is not
// ready yet, returns NULL.
initAccessToServer(getContext());
Log.v(LOG_TAG, "Setting up the remote fixture...");
RemoteOperationResult result = null;
for (String folderPath : FOLDERS_IN_FIXTURE) {
result = TestActivity.createFolder(folderPath, true, mClient);
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
}
File txtFile = TestActivity.extractAsset(
TestActivity.ASSETS__TEXT_FILE_NAME, getContext()
);
for (String filePath : FILES_IN_FIXTURE) {
result = TestActivity.uploadFile(
txtFile.getAbsolutePath(), filePath, "txt/plain", mClient
);
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
}
Log.v(LOG_TAG, "Remote fixture created.");
}
/**
* Test copy folder
*/
public void testCopyRemoteFileOperation() {
Log.v(LOG_TAG, "testCopyFolder in");
/// successful cases
// copy file
CopyRemoteFileOperation copyOperation = new CopyRemoteFileOperation(
SRC_PATH_TO_FILE_1,
TARGET_PATH_TO_FILE_1,
false
);
RemoteOperationResult result = copyOperation.execute(mClient);
assertTrue(result.isSuccess());
// copy & rename file, different location
copyOperation = new CopyRemoteFileOperation(
SRC_PATH_TO_FILE_2,
TARGET_PATH_TO_FILE_2_RENAMED,
false
);
result = copyOperation.execute(mClient);
assertTrue(result.isSuccess());
// copy & rename file, same location (rename file)
copyOperation = new CopyRemoteFileOperation(
SRC_PATH_TO_FILE_3,
SRC_PATH_TO_FILE_3_RENAMED,
false
);
result = copyOperation.execute(mClient);
assertTrue(result.isSuccess());
// copy empty folder
copyOperation = new CopyRemoteFileOperation(
SRC_PATH_TO_EMPTY_FOLDER,
TARGET_PATH_TO_EMPTY_FOLDER,
false
);
result = copyOperation.execute(mClient);
assertTrue(result.isSuccess());
// copy non-empty folder
copyOperation = new CopyRemoteFileOperation(
SRC_PATH_TO_FULL_FOLDER_1,
TARGET_PATH_TO_FULL_FOLDER_1,
false
);
result = copyOperation.execute(mClient);
assertTrue(result.isSuccess());
// copy & rename folder, different location
copyOperation = new CopyRemoteFileOperation(
SRC_PATH_TO_FULL_FOLDER_2,
TARGET_PATH_TO_FULL_FOLDER_2_RENAMED,
false
);
result = copyOperation.execute(mClient);
assertTrue(result.isSuccess());
// copy & rename folder, same location (rename folder)
copyOperation = new CopyRemoteFileOperation(
SRC_PATH_TO_FULL_FOLDER_3,
SRC_PATH_TO_FULL_FOLDER_3_RENAMED,
false
);
result = copyOperation.execute(mClient);
assertTrue(result.isSuccess());
// copy for nothing (success, but no interaction with network)
copyOperation = new CopyRemoteFileOperation(
SRC_PATH_TO_FILE_4,
SRC_PATH_TO_FILE_4,
false
);
result = copyOperation.execute(mClient);
assertTrue(result.isSuccess());
// copy overwriting
copyOperation = new CopyRemoteFileOperation(
SRC_PATH_TO_FULL_FOLDER_4,
TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4,
true
);
result = copyOperation.execute(mClient);
assertTrue(result.isSuccess());
/// Failed cases
// file to copy does not exist
copyOperation = new CopyRemoteFileOperation(
SRC_PATH_TO_NON_EXISTENT_FILE,
TARGET_PATH_TO_NON_EXISTENT_FILE,
false
);
result = copyOperation.execute(mClient);
assertTrue(result.getCode() == ResultCode.FILE_NOT_FOUND);
// folder to copy into does no exist
copyOperation = new CopyRemoteFileOperation(
SRC_PATH_TO_FILE_5,
TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER,
false
);
result = copyOperation.execute(mClient);
assertTrue(result.getHttpCode() == HttpConstants.HTTP_CONFLICT);
// target location (renaming) has invalid characters
copyOperation = new CopyRemoteFileOperation(
SRC_PATH_TO_FILE_6,
TARGET_PATH_RENAMED_WITH_INVALID_CHARS,
false
);
result = copyOperation.execute(mClient);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
// name collision
copyOperation = new CopyRemoteFileOperation(
SRC_PATH_TO_FILE_1,
TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7,
false
);
result = copyOperation.execute(mClient);
assertTrue(result.getCode() == ResultCode.INVALID_OVERWRITE);
// copy a folder into a descendant
copyOperation = new CopyRemoteFileOperation(
SRC_BASE_FOLDER,
SRC_PATH_TO_EMPTY_FOLDER,
false
);
result = copyOperation.execute(mClient);
assertTrue(result.getCode() == ResultCode.INVALID_COPY_INTO_DESCENDANT);
}
@Override
protected void tearDown() throws Exception {
Log.v(LOG_TAG, "Deleting remote fixture...");
String[] mPathsToCleanUp = {
SRC_BASE_FOLDER,
TARGET_BASE_FOLDER
};
for (String path : mPathsToCleanUp) {
RemoteOperationResult removeResult =
TestActivity.removeFile(path, mClient);
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, removeResult);
}
}
super.tearDown();
Log.v(LOG_TAG, "Remote fixture delete.");
}
private void initAccessToServer(Context context) {
Log.v(LOG_TAG, "Setting up client instance to access OC server...");
mServerUri = context.getString(R.string.server_base_url);
mUser = context.getString(R.string.username);
mPass = context.getString(R.string.password);
mClient = new OwnCloudClient(
Uri.parse(mServerUri),
NetworkUtils.getMultiThreadedConnManager()
);
mClient.setDefaultTimeouts(
OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,
OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT);
mClient.setFollowRedirects(true);
mClient.setCredentials(
OwnCloudCredentialsFactory.newBasicCredentials(
mUser,
mPass
)
);
Log.v(LOG_TAG, "Client instance set up.");
}
}

View File

@ -1,133 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.test_project.TestActivity;
/**
* Class to test Create Folder Operation
* @author masensio
* @author David A. Velasco
*
*/
public class CreateFolderTest extends RemoteTest {
private static final String LOG_TAG = CreateFolderTest.class.getCanonicalName();
private static final String FOLDER_PATH_BASE = "/testCreateFolder";
private TestActivity mActivity;
private List<String> mCreatedFolderPaths;
private String mFullPath2FolderBase;
public CreateFolderTest() {
super();
mCreatedFolderPaths = new ArrayList<String>();
}
@Override
protected void setUp() throws Exception {
super.setUp();
mActivity = getActivity();
mCreatedFolderPaths.clear();
mFullPath2FolderBase = mBaseFolderPath + FOLDER_PATH_BASE;
}
/**
* Test Create Folder
*/
public void testCreateFolder() {
String remotePath = mFullPath2FolderBase;
mCreatedFolderPaths.add(remotePath);
RemoteOperationResult result = mActivity.createFolder(remotePath, true);
assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
// Create Subfolder
remotePath = mFullPath2FolderBase + FOLDER_PATH_BASE;
mCreatedFolderPaths.add(remotePath);
result = mActivity.createFolder(remotePath, true);
assertTrue(result.isSuccess() || result.getCode() == ResultCode.TIMEOUT);
}
/**
* Test to Create Folder with special characters: / \ < > : " | ? *
*/
public void testCreateFolderSpecialCharacters() {
String remotePath = mFullPath2FolderBase + "_\\";
RemoteOperationResult result = mActivity.createFolder(remotePath, true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
remotePath = mFullPath2FolderBase + "_<";
result = mActivity.createFolder(remotePath, true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
remotePath = mFullPath2FolderBase + "_>";
result = mActivity.createFolder(remotePath, true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
remotePath = mFullPath2FolderBase + "_:";
result = mActivity.createFolder(remotePath, true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
remotePath = mFullPath2FolderBase + "_\"";
result = mActivity.createFolder(remotePath, true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
remotePath = mFullPath2FolderBase + "_|";
result = mActivity.createFolder(remotePath, true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
remotePath = mFullPath2FolderBase + "_?";
result = mActivity.createFolder(remotePath, true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
remotePath = mFullPath2FolderBase + "_*";
result = mActivity.createFolder(remotePath, true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
}
@Override
protected void tearDown() throws Exception {
Iterator<String> it = mCreatedFolderPaths.iterator();
RemoteOperationResult removeResult = null;
while (it.hasNext()) {
removeResult = mActivity.removeFile(it.next());
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, removeResult);
}
}
super.tearDown();
}
}

View File

@ -1,310 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.io.File;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.test_project.R;
import com.owncloud.android.lib.test_project.TestActivity;
/**
* Test Create Share: the server must support SHARE API
*/
public class CreateShareTest extends RemoteTest {
private static final String LOG_TAG = CreateShareTest.class.getCanonicalName();
/* File to share.*/
private static final String FILE_TO_SHARE = "/fileToShare.txt";
/* Non-existent file*/
private static final String NON_EXISTENT_FILE = "/nonExistentFile.txt";
private TestActivity mActivity;
private String mFullPath2FileToShare;
private String mFullPath2NonExistentFile;
private String mRemoteServer;
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
mFullPath2FileToShare = mBaseFolderPath + FILE_TO_SHARE;
mFullPath2NonExistentFile = mBaseFolderPath + NON_EXISTENT_FILE;
mRemoteServer = getActivity().getString(R.string.server_base_url_2);
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
RemoteOperationResult result = mActivity.uploadFile(
textFile.getAbsolutePath(),
mFullPath2FileToShare,
"txt/plain");
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
}
/**
* Test creation of public shares
*/
public void testCreatePublicShare() {
/// Successful cases
RemoteOperationResult result = mActivity.createShare(
mFullPath2FileToShare,
ShareType.PUBLIC_LINK,
"",
false,
"",
1);
assertTrue(result.isSuccess());
/// Failed cases
// file doesn't exist
result = mActivity.createShare(
mFullPath2NonExistentFile,
ShareType.PUBLIC_LINK,
"",
false,
"",
1);
assertFalse(result.isSuccess());
assertEquals(
RemoteOperationResult.ResultCode.SHARE_NOT_FOUND,
result.getCode()
);
assertTrue( // error message from server as part of the result
result.getData().size() == 1 &&
result.getData().get(0) instanceof String
);
}
/**
* Test creation of private shares with groups
*/
public void testCreatePrivateShareWithUser() {
/// Successful cases
RemoteOperationResult result = mActivity.createShare(
mFullPath2FileToShare,
ShareType.USER,
"admin",
false,
"",
31);
assertTrue(result.isSuccess());
/// Failed cases
// sharee doesn't exist
result = mActivity.createShare(
mFullPath2FileToShare,
ShareType.USER,
"no_exist",
false,
"",
31);
assertFalse(result.isSuccess());
assertEquals(
RemoteOperationResult.ResultCode.SHARE_FORBIDDEN,
result.getCode()
);
assertTrue( // error message from server as part of the result
result.getData().size() == 1 &&
result.getData().get(0) instanceof String
);
// file doesn't exist
result = mActivity.createShare(
mFullPath2NonExistentFile,
ShareType.USER,
"admin",
false,
"",
31);
assertFalse(result.isSuccess());
assertEquals(
RemoteOperationResult.ResultCode.SHARE_NOT_FOUND,
result.getCode()
);
assertTrue( // error message from server as part of the result
result.getData().size() == 1 &&
result.getData().get(0) instanceof String
);
}
/**
* Test creation of private shares with groups
*/
public void testCreatePrivateShareWithGroup() {
/// Successful cases
RemoteOperationResult result = mActivity.createShare(
mFullPath2FileToShare,
ShareType.GROUP,
"admin",
false,
"",
1);
assertTrue(result.isSuccess());
/// Failed cases
// sharee doesn't exist
result = mActivity.createShare(
mFullPath2FileToShare,
ShareType.GROUP,
"no_exist",
false,
"",
31);
assertFalse(result.isSuccess());
assertEquals(
RemoteOperationResult.ResultCode.SHARE_FORBIDDEN,
result.getCode()
);
assertTrue( // error message from server as part of the result
result.getData().size() == 1 &&
result.getData().get(0) instanceof String
);
// file doesn't exist
result = mActivity.createShare(
mFullPath2NonExistentFile,
ShareType.GROUP,
"admin",
false,
"",
31);
assertFalse(result.isSuccess());
assertEquals(
RemoteOperationResult.ResultCode.SHARE_NOT_FOUND,
result.getCode()
);
assertTrue( // error message from server as part of the result
result.getData().size() == 1 &&
result.getData().get(0) instanceof String
);
}
/**
* Test creation of federated shares with remote users
*/
public void testCreateFederatedShareWithUser() {
String remoteDomain = mRemoteServer.split("//")[1];
/// Successful cases
RemoteOperationResult result = mActivity.createShare(
mFullPath2FileToShare,
ShareType.FEDERATED,
"admin@" + remoteDomain,
false,
"",
1);
assertTrue(result.isSuccess());
/// Failed cases
// sharee doesn't exist in an existing remote server
result = mActivity.createShare(
mFullPath2FileToShare,
ShareType.FEDERATED,
"no_exist@" + remoteDomain,
false,
"",
31);
assertFalse(result.isSuccess());
assertEquals(
RemoteOperationResult.ResultCode.SHARE_FORBIDDEN,
result.getCode()
);
assertTrue( // error message from server as part of the result
result.getData().size() == 1 &&
result.getData().get(0) instanceof String
);
// remote server doesn't exist
result = mActivity.createShare(
mFullPath2FileToShare,
ShareType.FEDERATED,
"no_exist",
false,
"",
31);
assertFalse(result.isSuccess());
assertEquals(
RemoteOperationResult.ResultCode.SHARE_WRONG_PARAMETER,
result.getCode()
);
assertTrue( // error message from server as part of the result
result.getData().size() == 1 &&
result.getData().get(0) instanceof String
);
// file doesn't exist
result = mActivity.createShare(
mFullPath2NonExistentFile,
ShareType.FEDERATED,
"admin@" + remoteDomain,
false,
"",
31);
assertFalse(result.isSuccess());
assertEquals(
RemoteOperationResult.ResultCode.SHARE_NOT_FOUND,
result.getCode()
);
assertTrue( // error message from server as part of the result
result.getData().size() == 1 &&
result.getData().get(0) instanceof String
);
}
@Override
protected void tearDown() throws Exception {
RemoteOperationResult removeResult = mActivity.removeFile(mFullPath2FileToShare);
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, removeResult);
}
super.tearDown();
}
}

View File

@ -1,104 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.io.File;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.test_project.TestActivity;
/**
* Class to test Delete a File Operation
* @author masensio
*
*/
public class DeleteFileTest extends RemoteTest {
private static final String LOG_TAG = DeleteFileTest.class.getCanonicalName();
/* Folder data to delete. */
private static final String FOLDER_PATH = "/folderToDelete";
/* File to delete. */
private static final String FILE_PATH = "/fileToDelete.txt";
private TestActivity mActivity;
private String mFullPath2Folder;
private String mFullPath2File;
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
mFullPath2Folder = mBaseFolderPath + FOLDER_PATH;
mFullPath2File = mBaseFolderPath + FILE_PATH;
RemoteOperationResult result = mActivity.createFolder(mFullPath2Folder, true);
if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, result);
}
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
result = mActivity.uploadFile(
textFile.getAbsolutePath(),
mFullPath2File,
"txt/plain");
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
}
/**
* Test Remove Folder
*/
public void testRemoveFolder() {
RemoteOperationResult result = mActivity.removeFile(mFullPath2Folder);
assertTrue(result.isSuccess());
}
/**
* Test Remove File
*/
public void testRemoveFile() {
RemoteOperationResult result = mActivity.removeFile(mFullPath2File);
assertTrue(result.isSuccess());
}
@Override
protected void tearDown() throws Exception {
// nothing to do:
// - if tests were fine, there is nothing to clean up in the server side
// - if tests failed, there is nothing we can do to clean up the server side
super.tearDown();
}
}

View File

@ -1,143 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.io.File;
import com.owncloud.android.lib.resources.files.RemoteFile;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.test_project.TestActivity;
/**
* Class to test Download File Operation
* @author masensio
* @author David A. Velasco
*/
public class DownloadFileTest extends RemoteTest {
private static final String LOG_TAG = DownloadFileTest.class.getCanonicalName();
/* Files to download. These files must exist on the account */
private static final String IMAGE_PATH = "/fileToDownload.png";
private static final String IMAGE_PATH_WITH_SPECIAL_CHARS = "/@file@download.png";
private static final String IMAGE_NOT_FOUND = "/fileNotFound.png";
private String mFullPath2Image;
private String mFullPath2ImageWitSpecialChars;
private String mFullPath2ImageNotFound;
private String mDownloadedFilePath;
private TestActivity mActivity;
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
mDownloadedFilePath = null;
mFullPath2Image = mBaseFolderPath + IMAGE_PATH;
mFullPath2ImageWitSpecialChars = mBaseFolderPath + IMAGE_PATH_WITH_SPECIAL_CHARS;
mFullPath2ImageNotFound = mBaseFolderPath + IMAGE_NOT_FOUND;
File imageFile = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME);
RemoteOperationResult result = mActivity.uploadFile(
imageFile.getAbsolutePath(),
mFullPath2Image,
"image/png");
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
result = mActivity.uploadFile(
imageFile.getAbsolutePath(),
mFullPath2ImageWitSpecialChars,
"image/png");
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
result = mActivity.removeFile(mFullPath2ImageNotFound);
if (!result.isSuccess() && result.getCode() != ResultCode.FILE_NOT_FOUND) {
Utils.logAndThrow(LOG_TAG, result);
}
}
/**
* Test Download a File
*/
public void testDownloadFile() {
RemoteOperationResult result = mActivity.downloadFile(
new RemoteFile(mFullPath2Image), ""
);
mDownloadedFilePath = mFullPath2Image;
assertTrue(result.isSuccess());
// TODO some checks involving the local file
}
/**
* Test Download a File with special chars
*/
public void testDownloadFileSpecialChars() {
RemoteOperationResult result = mActivity.downloadFile(
new RemoteFile(mFullPath2ImageWitSpecialChars), ""
);
mDownloadedFilePath = mFullPath2ImageWitSpecialChars;
assertTrue(result.isSuccess());
// TODO some checks involving the local file
}
/**
* Test Download a Not Found File
*/
public void testDownloadFileNotFound() {
RemoteOperationResult result = mActivity.downloadFile(
new RemoteFile(mFullPath2ImageNotFound), ""
);
assertFalse(result.isSuccess());
}
@Override
protected void tearDown() throws Exception {
if (mDownloadedFilePath != null) {
RemoteOperationResult removeResult = mActivity.removeFile(mDownloadedFilePath);
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, removeResult);
}
}
File[] files = mActivity.getFilesDir().listFiles();
for (File file : files) {
file.delete();
}
super.tearDown();
}
}

View File

@ -1,144 +0,0 @@
/* ownCloud Android Library is available under MIT license
* @author masensio
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.security.GeneralSecurityException;
import junit.framework.AssertionFailedError;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.common.network.NetworkUtils;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.status.GetRemoteCapabilitiesOperation;
import com.owncloud.android.lib.test_project.R;
/**
* Class to test GetRemoteCapabilitiesOperation
*
*/
public class GetCapabilitiesTest extends RemoteTest {
private static final String LOG_TAG = GetCapabilitiesTest.class.getCanonicalName();
String mServerUri, mUser, mPass;
OwnCloudClient mClient = null;
public GetCapabilitiesTest() {
super();
Protocol pr = Protocol.getProtocol("https");
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
try {
ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
Protocol.registerProtocol(
"https",
new Protocol("https", psf, 443));
} catch (GeneralSecurityException e) {
throw new AssertionFailedError(
"Self-signed confident SSL context could not be loaded");
}
}
}
protected Context getContext() {
return getActivity();
}
@Override
protected void setUp() throws Exception {
super.setUp();
// Next initialization cannot be done in the constructor because getContext() is not
// ready yet, returns NULL.
initAccessToServer(getContext());
Log.v(LOG_TAG, "Setting up the remote fixture...");
Log.v(LOG_TAG, "Remote fixture created.");
}
// Tests
/**
* Test get capabilities
*
* Requires OC server 8.1 or later
*/
public void testGetRemoteCapabilitiesOperation() {
// get capabilities
GetRemoteCapabilitiesOperation getCapabilitiesOperation = new GetRemoteCapabilitiesOperation();
RemoteOperationResult result = getCapabilitiesOperation.execute(mClient);
assertTrue(result.isSuccess());
assertTrue(result.getData() != null && result.getData().size() == 1);
}
@Override
protected void tearDown() throws Exception {
Log.v(LOG_TAG, "Deleting remote fixture...");
super.tearDown();
Log.v(LOG_TAG, "Remote fixture delete.");
}
private void initAccessToServer(Context context) {
Log.v(LOG_TAG, "Setting up client instance to access OC server...");
mServerUri = context.getString(R.string.server_base_url);
mUser = context.getString(R.string.username);
mPass = context.getString(R.string.password);
mClient = new OwnCloudClient(
Uri.parse(mServerUri),
NetworkUtils.getMultiThreadedConnManager()
);
mClient.setDefaultTimeouts(
OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,
OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT);
mClient.setFollowRedirects(true);
mClient.setCredentials(
OwnCloudCredentialsFactory.newBasicCredentials(
mUser,
mPass
)
);
Log.v(LOG_TAG, "Client instance set up.");
}
}

View File

@ -1,282 +0,0 @@
/* ownCloud Android Library is available under MIT license
* @author David A. Velasco
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.security.GeneralSecurityException;
import junit.framework.AssertionFailedError;
import org.json.JSONException;
import org.json.JSONObject;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.common.network.NetworkUtils;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.shares.GetRemoteShareesOperation;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.test_project.R;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
/**
* Class to test GetRemoteShareesOperation
*
* With this TestCase we are experimenting a bit to improve the test suite design, in two aspects:
*
* - Reduce the dependency from the set of test cases on the "test project" needed to
* have an instrumented APK to install in the device, as required by the testing framework
* provided by Android. To get there, this class avoids calling TestActivity methods in the test
* method.
*
* - Reduce the impact of creating a remote fixture over the Internet, while the structure of the
* TestCase is kept easy to maintain. To get this, all the tests are done in a single test method,
* granting this way that setUp and tearDown are run only once.
*
*/
public class GetShareesTest extends RemoteTest {
private static final String LOG_TAG = GetShareesTest.class.getCanonicalName();
String mServerUri, mUser, mPass, mServerUri2;
OwnCloudClient mClient = null;
public GetShareesTest() {
super();
Protocol pr = Protocol.getProtocol("https");
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
try {
ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
Protocol.registerProtocol(
"https",
new Protocol("https", psf, 443));
} catch (GeneralSecurityException e) {
throw new AssertionFailedError(
"Self-signed confident SSL context could not be loaded");
}
}
}
protected Context getContext() {
return getActivity();
}
@Override
protected void setUp() throws Exception {
super.setUp();
// Next initialization cannot be done in the constructor because getContext() is not
// ready yet, returns NULL.
initAccessToServer(getContext());
Log.v(LOG_TAG, "Setting up the remote fixture...");
Log.v(LOG_TAG, "Remote fixture created.");
}
/**
* Test get sharees
*
* Requires OC server 8.2 or later
*/
public void testGetRemoteShareesOperation() {
Log.v(LOG_TAG, "testGetRemoteSharees in");
/// successful cases
// search for sharees including "a"
GetRemoteShareesOperation getShareesOperation = new GetRemoteShareesOperation("a", 1, 50);
RemoteOperationResult result = getShareesOperation.execute(mClient);
JSONObject resultItem;
JSONObject value;
int type;
int userCount = 0, groupCount = 0;
assertTrue(result.isSuccess() && result.getData().size() > 0);
try {
for (int i=0; i<result.getData().size(); i++) {
resultItem = (JSONObject) result.getData().get(i);
value = resultItem.getJSONObject(GetRemoteShareesOperation.NODE_VALUE);
type = value.getInt(GetRemoteShareesOperation.PROPERTY_SHARE_TYPE);
if (type == ShareType.GROUP.getValue()) {
groupCount++;
} else {
userCount++;
}
}
assertTrue(userCount > 0);
assertTrue(groupCount > 0);
} catch (JSONException e) {
AssertionFailedError afe = new AssertionFailedError(e.getLocalizedMessage());
afe.setStackTrace(e.getStackTrace());
throw afe;
}
// search for sharees including "ad" - expecting user "admin" & group "admin"
getShareesOperation = new GetRemoteShareesOperation("ad", 1, 50);
result = getShareesOperation.execute(mClient);
assertTrue(result.isSuccess() && result.getData().size() == 2);
userCount = 0; groupCount = 0;
try {
for (int i=0; i<2; i++) {
resultItem = (JSONObject) result.getData().get(i);
value = resultItem.getJSONObject(GetRemoteShareesOperation.NODE_VALUE);
type = value.getInt(GetRemoteShareesOperation.PROPERTY_SHARE_TYPE);
if (type == ShareType.GROUP.getValue()) {
groupCount++;
} else {
userCount++;
}
}
assertEquals(userCount, 1);
assertEquals(groupCount, 1);
} catch (JSONException e) {
AssertionFailedError afe = new AssertionFailedError(e.getLocalizedMessage());
afe.setStackTrace(e.getStackTrace());
throw afe;
}
// search for sharees including "bd" - expecting 0 results
getShareesOperation = new GetRemoteShareesOperation("bd", 1, 50);
result = getShareesOperation.execute(mClient);
assertTrue(result.isSuccess() && result.getData().size() == 0);
/// failed cases
// search for sharees including wrong page values
getShareesOperation = new GetRemoteShareesOperation("a", 0, 50);
result = getShareesOperation.execute(mClient);
assertTrue(!result.isSuccess() && result.getHttpCode() == HttpConstants.HTTP_BAD_REQUEST);
getShareesOperation = new GetRemoteShareesOperation("a", 1, 0);
result = getShareesOperation.execute(mClient);
assertTrue(!result.isSuccess() && result.getHttpCode() == HttpConstants.HTTP_BAD_REQUEST);
}
/**
* Test get federated sharees
*
* Requires OC server 8.2 or later
*/
public void testGetFederatedShareesOperation() {
Log.v(LOG_TAG, "testGetFederatedSharees in");
/// successful cases
// search for sharees including "@"
GetRemoteShareesOperation getShareesOperation = new GetRemoteShareesOperation("@", 1, 50);
RemoteOperationResult result = getShareesOperation.execute(mClient);
JSONObject resultItem;
JSONObject value;
int type;
int fedCount = 0;
assertTrue(result.isSuccess() && result.getData().size() > 0);
try {
for (int i=0; i<result.getData().size(); i++) {
resultItem = (JSONObject) result.getData().get(i);
value = resultItem.getJSONObject(GetRemoteShareesOperation.NODE_VALUE);
type = value.getInt(GetRemoteShareesOperation.PROPERTY_SHARE_TYPE);
if (type == ShareType.FEDERATED.getValue()) {
fedCount++;
}
}
assertTrue(fedCount > 0);
} catch (JSONException e) {
AssertionFailedError afe = new AssertionFailedError(e.getLocalizedMessage());
afe.setStackTrace(e.getStackTrace());
throw afe;
}
// search for 'admin' sharee from external server - expecting at least 1 result
String remoteSharee = "admin@" + mServerUri2.split("//")[1];
getShareesOperation = new GetRemoteShareesOperation(remoteSharee, 1, 50);
result = getShareesOperation.execute(mClient);
assertTrue(result.isSuccess() && result.getData().size() > 0);
/// failed cases
// search for sharees including wrong page values
getShareesOperation = new GetRemoteShareesOperation("@", 0, 50);
result = getShareesOperation.execute(mClient);
assertTrue(!result.isSuccess() && result.getHttpCode() == HttpConstants.HTTP_BAD_REQUEST);
getShareesOperation = new GetRemoteShareesOperation("@", 1, 0);
result = getShareesOperation.execute(mClient);
assertTrue(!result.isSuccess() && result.getHttpCode() == HttpConstants.HTTP_BAD_REQUEST);
}
@Override
protected void tearDown() throws Exception {
Log.v(LOG_TAG, "Deleting remote fixture...");
super.tearDown();
Log.v(LOG_TAG, "Remote fixture delete.");
}
private void initAccessToServer(Context context) {
Log.v(LOG_TAG, "Setting up client instance to access OC server...");
mServerUri = context.getString(R.string.server_base_url);
mServerUri2 = context.getString(R.string.server_base_url_2);
mUser = context.getString(R.string.username);
mPass = context.getString(R.string.password);
mClient = new OwnCloudClient(
Uri.parse(mServerUri),
NetworkUtils.getMultiThreadedConnManager()
);
mClient.setDefaultTimeouts(
OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,
OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT);
mClient.setFollowRedirects(true);
mClient.setCredentials(
OwnCloudCredentialsFactory.newBasicCredentials(
mUser,
mPass
)
);
Log.v(LOG_TAG, "Client instance set up.");
}
}

View File

@ -1,93 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.io.File;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.test_project.TestActivity;
/**
* Class to test Get Shares Operation
*
* @author masensio
*
*/
public class GetSharesTest extends RemoteTest {
private static final String LOG_TAG = GetSharesTest.class.getCanonicalName();
private static final String SHARED_FILE = "/sharedFileToGet.txt";
private TestActivity mActivity;
private String mFullPath2SharedFile;
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
mFullPath2SharedFile = mBaseFolderPath + SHARED_FILE;
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
RemoteOperationResult result = mActivity.uploadFile(
textFile.getAbsolutePath(),
mFullPath2SharedFile,
"txt/plain");
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
result = mActivity.createShare(mFullPath2SharedFile, ShareType.PUBLIC_LINK, "", false, "", 1);
if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, result);
}
}
/**
* Test Get Shares: the server must support SHARE API
*/
public void testGetShares() {
RemoteOperationResult result = mActivity.getShares();
assertTrue(result.isSuccess());
assertTrue(result.getData() != null && result.getData().size() == 1);
}
@Override
protected void tearDown() throws Exception {
RemoteOperationResult removeResult = mActivity.removeFile(mFullPath2SharedFile);
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, removeResult);
}
super.tearDown();
}
}

View File

@ -1,107 +0,0 @@
/* ownCloud Android Library is available under MIT license
*
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.util.*;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.users.GetRemoteUserAvatarOperation.ResultData;
import com.owncloud.android.lib.test_project.TestActivity;
/**
* Class to test {@link GetRemoteUserAvatarOperation}
*
* @author David A. Velasco
*/
public class GetUserAvatarTest extends RemoteTest {
private static final String LOG_TAG = GetUserAvatarTest.class.getCanonicalName();
private static final int AVATAR_DIMENSION = 256;
private TestActivity mActivity;
@Override
protected void setUp() throws Exception {
super.setUp();
mActivity = getActivity();
}
/**
* Test get user avatar (succesful)
*/
public void testGetUserAvatar() {
RemoteOperationResult result = mActivity.getUserAvatar(AVATAR_DIMENSION, null);
assertTrue(result.isSuccess());
ResultData userAvatar = (ResultData) result.getData().get(0);
assertTrue(userAvatar.getEtag() != null && userAvatar.getEtag().length() > 0);
assertTrue(userAvatar.getMimeType() != null && userAvatar.getMimeType().startsWith("image"));
assertTrue(userAvatar.getAvatarData() != null && userAvatar.getAvatarData().length > 0);
}
/**
* Test get user avatar only if changed, but wasn't changed
*
* DISABLED: conditioned call has been disabled due to problems with the network stack;
* see comment in src/com/owncloud/android/lib/resources/users/GetRemoteUserAvatarOperation.java#87
*/
/*
public void testGetUserAvatarOnlyIfChangedAfterUnchanged() {
RemoteOperationResult result = mActivity.getUserAvatar(AVATAR_DIMENSION, null);
ResultData userAvatar = (ResultData) result.getData().get(0);
String etag = userAvatar.getEtag();
// request again, with the just received etag
result = mActivity.getUserAvatar(AVATAR_DIMENSION, etag);
assertFalse(result.isSuccess());
assertTrue(result.getHttpCode() == HttpConstants.HTTP_NOT_MODIFIED);
}
*/
/**
* Test get user avatar only if changed, and was changed
*/
public void testGetUserAvatarOnlyIfChangedAfterChanged() {
// TODO can't test this without provisioning API or mocking the server
}
/**
* Test get user avatar not found
*/
public void testGetUserAvatarNofFound() {
// TODO can't test this without provisioning API, mocking the server or another set of credentials
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
}

View File

@ -1,73 +0,0 @@
/* ownCloud Android Library is available under MIT license
*
* Copyright (C) 2018 ownCloud Inc.
* Copyright (C) 2015 Bartosz Przybylski
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.util.*;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.users.GetRemoteUserQuotaOperation.Quota;
import com.owncloud.android.lib.test_project.TestActivity;
/**
* Class to test Get User Quota
*
* @author Bartosz Przybylski
* @author David A. Velasco
* @author David González Verdugo
*/
public class GetUserQuotaTest extends RemoteTest {
private static final String LOG_TAG = GetUserQuotaTest.class.getCanonicalName();
private TestActivity mActivity;
private String mFullPath2Root;
private String ROOT_PATH = "/";
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
mFullPath2Root = mBaseFolderPath + ROOT_PATH;
}
/**
* Test GetUserQuota
*/
public void testGetUserQuota() {
RemoteOperationResult result = mActivity.getQuota(mFullPath2Root);
assertTrue(result.isSuccess());
Quota quota = (Quota)((ArrayList<Object>)result.getData()).get(0);
assertTrue(quota.getFree() >= 0);
assertTrue(quota.getUsed() >= 0);
assertTrue(quota.getTotal() > 0);
}
}

View File

@ -1,456 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.io.File;
import java.security.GeneralSecurityException;
import junit.framework.AssertionFailedError;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.common.network.NetworkUtils;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.resources.files.MoveRemoteFileOperation;
import com.owncloud.android.lib.test_project.R;
import com.owncloud.android.lib.test_project.TestActivity;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
/**
* Class to test MoveRemoteFileOperation
*
* With this TestCase we are experimenting a bit to improve the test suite design, in two aspects:
*
* - Reduce the dependency from the set of test cases on the "test project" needed to
* have an instrumented APK to install in the device, as required by the testing framework
* provided by Android. To get there, this class avoids calling TestActivity methods in the test
* method.
*
* - Reduce the impact of creating a remote fixture over the Internet, while the structure of the
* TestCase is kept easy to maintain. To get this, all the tests are done in a single test method,
* granting this way that setUp and tearDown are run only once.
*
*
* @author David A. Velasco
*/
//public class MoveFileTest extends AndroidTestCase {
public class MoveFileTest extends RemoteTest {
private static final String LOG_TAG = MoveFileTest.class.getCanonicalName();
/// Paths to files and folders in fixture
private static final String SRC_BASE_FOLDER = "/src/";
private static final String TARGET_BASE_FOLDER = "/target/";
private static final String NO_FILE = "nofile.txt";
private static final String FILE1 = "file1.txt";
private static final String FILE2 = "file2.txt";
private static final String FILE3 = "file3.txt";
private static final String FILE4 = "file4.txt";
private static final String FILE5 = "file5.txt";
private static final String FILE6 = "file6.txt";
private static final String FILE7 = "file7.txt";
private static final String EMPTY = "empty/";
private static final String NO_FOLDER = "nofolder/";
private static final String FOLDER1 = "folder1/";
private static final String FOLDER2 = "folder2/";
private static final String FOLDER3 = "folder3/";
private static final String FOLDER4 = "folder4/";
private static final String SRC_PATH_TO_FILE_1 = SRC_BASE_FOLDER + FILE1;
private static final String TARGET_PATH_TO_FILE_1 = TARGET_BASE_FOLDER + FILE1;
private static final String SRC_PATH_TO_FILE_2 = SRC_BASE_FOLDER + FILE2;
private static final String TARGET_PATH_TO_FILE_2_RENAMED =
TARGET_BASE_FOLDER + "renamed_" + FILE2;
private static final String SRC_PATH_TO_FILE_3 = SRC_BASE_FOLDER + FILE3;
private static final String SRC_PATH_TO_FILE_3_RENAMED = SRC_BASE_FOLDER + "renamed_" + FILE3;
private static final String SRC_PATH_TO_FILE_4 = SRC_BASE_FOLDER + FILE4;
private static final String SRC_PATH_TO_FILE_5 = SRC_BASE_FOLDER + FILE5;
private static final String SRC_PATH_TO_FILE_6 = SRC_BASE_FOLDER + FILE6;
private static final String SRC_PATH_TO_FILE_7 = SRC_BASE_FOLDER + FILE7;
private static final String SRC_PATH_TO_NON_EXISTENT_FILE = SRC_BASE_FOLDER + NO_FILE;
private static final String SRC_PATH_TO_EMPTY_FOLDER = SRC_BASE_FOLDER + EMPTY;
private static final String TARGET_PATH_TO_EMPTY_FOLDER = TARGET_BASE_FOLDER + EMPTY;
private static final String SRC_PATH_TO_FULL_FOLDER_1 = SRC_BASE_FOLDER + FOLDER1;
private static final String TARGET_PATH_TO_FULL_FOLDER_1 = TARGET_BASE_FOLDER + FOLDER1;
private static final String SRC_PATH_TO_FULL_FOLDER_2 = SRC_BASE_FOLDER + FOLDER2;
private static final String TARGET_PATH_TO_FULL_FOLDER_2_RENAMED =
TARGET_BASE_FOLDER + "renamed_" + FOLDER2;
private static final String SRC_PATH_TO_FULL_FOLDER_3 = SRC_BASE_FOLDER + FOLDER3;
private static final String SRC_PATH_TO_FULL_FOLDER_4 = SRC_BASE_FOLDER + FOLDER4;
private static final String SRC_PATH_TO_FULL_FOLDER_3_RENAMED =
SRC_BASE_FOLDER + "renamed_" + FOLDER3;
private static final String TARGET_PATH_RENAMED_WITH_INVALID_CHARS =
SRC_BASE_FOLDER + "renamed:??_" + FILE6;
private static final String TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4 = TARGET_BASE_FOLDER
+ FOLDER4;
private static final String TARGET_PATH_TO_NON_EXISTENT_FILE = TARGET_BASE_FOLDER + NO_FILE;
private static final String TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER =
TARGET_BASE_FOLDER + NO_FOLDER + FILE5;
private static final String TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7 = TARGET_BASE_FOLDER + FILE7;
private static final String[] FOLDERS_IN_FIXTURE = {
SRC_PATH_TO_EMPTY_FOLDER,
SRC_PATH_TO_FULL_FOLDER_1,
SRC_PATH_TO_FULL_FOLDER_1 + FOLDER1,
SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2,
SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FOLDER1,
SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FOLDER2,
SRC_PATH_TO_FULL_FOLDER_2,
SRC_PATH_TO_FULL_FOLDER_2 + FOLDER1,
SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2,
SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FOLDER1,
SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FOLDER2,
SRC_PATH_TO_FULL_FOLDER_3,
SRC_PATH_TO_FULL_FOLDER_3 + FOLDER1,
SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2,
SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FOLDER1,
SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FOLDER2,
SRC_PATH_TO_FULL_FOLDER_4,
SRC_PATH_TO_FULL_FOLDER_4 + FOLDER1,
SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2,
SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FOLDER1,
SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FOLDER2,
TARGET_BASE_FOLDER,
TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4
};
private static final String[] FILES_IN_FIXTURE = {
SRC_PATH_TO_FILE_1,
SRC_PATH_TO_FILE_2,
SRC_PATH_TO_FILE_3,
SRC_PATH_TO_FILE_4,
SRC_PATH_TO_FILE_5,
SRC_PATH_TO_FULL_FOLDER_1 + FILE1,
SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FILE1,
SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FILE2,
SRC_PATH_TO_FULL_FOLDER_1 + FOLDER2 + FOLDER2 + FILE2,
SRC_PATH_TO_FULL_FOLDER_2 + FILE1,
SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FILE1,
SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FILE2,
SRC_PATH_TO_FULL_FOLDER_2 + FOLDER2 + FOLDER2 + FILE2,
SRC_PATH_TO_FULL_FOLDER_3 + FILE1,
SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FILE1,
SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FILE2,
SRC_PATH_TO_FULL_FOLDER_3 + FOLDER2 + FOLDER2 + FILE2,
SRC_PATH_TO_FULL_FOLDER_4 + FILE1,
SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FILE1,
SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FILE2,
SRC_PATH_TO_FULL_FOLDER_4 + FOLDER2 + FOLDER2 + FILE2,
TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7
};
String mServerUri, mUser, mPass;
OwnCloudClient mClient = null;
public MoveFileTest() {
super();
Protocol pr = Protocol.getProtocol("https");
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
try {
ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
Protocol.registerProtocol(
"https",
new Protocol("https", psf, 443));
} catch (GeneralSecurityException e) {
throw new AssertionFailedError(
"Self-signed confident SSL context could not be loaded");
}
}
}
protected Context getContext() {
return getActivity();
}
@Override
protected void setUp() throws Exception {
super.setUp();
// Next initialization cannot be done in the constructor because getContext() is not
// ready yet, returns NULL.
initAccessToServer(getContext());
Log.v(LOG_TAG, "Setting up the remote fixture...");
RemoteOperationResult result = null;
for (String folderPath : FOLDERS_IN_FIXTURE) {
result = TestActivity.createFolder(mBaseFolderPath + folderPath, true, mClient);
if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, result);
}
}
File txtFile = TestActivity.extractAsset(
TestActivity.ASSETS__TEXT_FILE_NAME, getContext()
);
for (String filePath : FILES_IN_FIXTURE) {
result = TestActivity.uploadFile(
txtFile.getAbsolutePath(), mBaseFolderPath + filePath, "txt/plain", mClient
);
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
}
Log.v(LOG_TAG, "Remote fixture created.");
}
/**
* Test move folder
*/
public void testMoveRemoteFileOperation() {
Log.v(LOG_TAG, "testMoveFolder in");
/// successful cases
// move file
MoveRemoteFileOperation moveOperation = new MoveRemoteFileOperation(
mBaseFolderPath + SRC_PATH_TO_FILE_1,
mBaseFolderPath + TARGET_PATH_TO_FILE_1,
false
);
RemoteOperationResult result = moveOperation.execute(mClient);
assertTrue(result.isSuccess());
// move & rename file, different location
moveOperation = new MoveRemoteFileOperation(
mBaseFolderPath + SRC_PATH_TO_FILE_2,
mBaseFolderPath + TARGET_PATH_TO_FILE_2_RENAMED,
false
);
result = moveOperation.execute(mClient);
assertTrue(result.isSuccess());
// move & rename file, same location (rename file)
moveOperation = new MoveRemoteFileOperation(
mBaseFolderPath + SRC_PATH_TO_FILE_3,
mBaseFolderPath + SRC_PATH_TO_FILE_3_RENAMED,
false
);
result = moveOperation.execute(mClient);
assertTrue(result.isSuccess());
// move empty folder
moveOperation = new MoveRemoteFileOperation(
mBaseFolderPath + SRC_PATH_TO_EMPTY_FOLDER,
mBaseFolderPath + TARGET_PATH_TO_EMPTY_FOLDER,
false
);
result = moveOperation.execute(mClient);
assertTrue(result.isSuccess());
// move non-empty folder
moveOperation = new MoveRemoteFileOperation(
mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_1,
mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_1,
false
);
result = moveOperation.execute(mClient);
assertTrue(result.isSuccess());
// move & rename folder, different location
moveOperation = new MoveRemoteFileOperation(
mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_2,
mBaseFolderPath + TARGET_PATH_TO_FULL_FOLDER_2_RENAMED,
false
);
result = moveOperation.execute(mClient);
assertTrue(result.isSuccess());
// move & rename folder, same location (rename folder)
moveOperation = new MoveRemoteFileOperation(
mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_3,
mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_3_RENAMED,
false
);
result = moveOperation.execute(mClient);
assertTrue(result.isSuccess());
// move for nothing (success, but no interaction with network)
moveOperation = new MoveRemoteFileOperation(
mBaseFolderPath + SRC_PATH_TO_FILE_4,
mBaseFolderPath + SRC_PATH_TO_FILE_4,
false
);
result = moveOperation.execute(mClient);
assertTrue(result.isSuccess());
// move overwriting
moveOperation = new MoveRemoteFileOperation(
mBaseFolderPath + SRC_PATH_TO_FULL_FOLDER_4,
mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_EMPTY_FOLDER_4,
true
);
result = moveOperation.execute(mClient);
assertTrue(result.isSuccess());
/// Failed cases
// file to move does not exist
moveOperation = new MoveRemoteFileOperation(
mBaseFolderPath + SRC_PATH_TO_NON_EXISTENT_FILE,
mBaseFolderPath + TARGET_PATH_TO_NON_EXISTENT_FILE,
false
);
result = moveOperation.execute(mClient);
assertTrue(result.getCode() == ResultCode.FILE_NOT_FOUND);
// folder to move into does no exist
moveOperation = new MoveRemoteFileOperation(
mBaseFolderPath + SRC_PATH_TO_FILE_5,
mBaseFolderPath + TARGET_PATH_TO_FILE_5_INTO_NON_EXISTENT_FOLDER,
false
);
result = moveOperation.execute(mClient);
assertTrue(result.getHttpCode() == HttpConstants.HTTP_CONFLICT);
// target location (renaming) has invalid characters
moveOperation = new MoveRemoteFileOperation(
mBaseFolderPath + SRC_PATH_TO_FILE_6,
mBaseFolderPath + TARGET_PATH_RENAMED_WITH_INVALID_CHARS,
false
);
result = moveOperation.execute(mClient);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
// name collision
moveOperation = new MoveRemoteFileOperation(
mBaseFolderPath + SRC_PATH_TO_FILE_7,
mBaseFolderPath + TARGET_PATH_TO_ALREADY_EXISTENT_FILE_7,
false
);
result = moveOperation.execute(mClient);
assertTrue(result.getCode() == ResultCode.INVALID_OVERWRITE);
// move a folder into a descendant
moveOperation = new MoveRemoteFileOperation(
mBaseFolderPath + SRC_BASE_FOLDER,
mBaseFolderPath + SRC_PATH_TO_EMPTY_FOLDER,
false
);
result = moveOperation.execute(mClient);
assertTrue(result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT);
}
@Override
protected void tearDown() throws Exception {
Log.v(LOG_TAG, "Deleting remote fixture...");
String[] mPathsToCleanUp = {
mBaseFolderPath + SRC_BASE_FOLDER,
mBaseFolderPath + TARGET_BASE_FOLDER
};
for (String path : mPathsToCleanUp) {
RemoteOperationResult removeResult =
TestActivity.removeFile(path, mClient);
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT ) {
Utils.logAndThrow(LOG_TAG, removeResult);
}
}
super.tearDown();
Log.v(LOG_TAG, "Remote fixture delete.");
}
private void initAccessToServer(Context context) {
Log.v(LOG_TAG, "Setting up client instance to access OC server...");
mServerUri = context.getString(R.string.server_base_url);
mUser = context.getString(R.string.username);
mPass = context.getString(R.string.password);
mClient = new OwnCloudClient(
Uri.parse(mServerUri),
NetworkUtils.getMultiThreadedConnManager()
);
mClient.setDefaultTimeouts(
OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,
OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT);
mClient.setFollowRedirects(true);
mClient.setCredentials(
OwnCloudCredentialsFactory.newBasicCredentials(
mUser,
mPass
)
);
Log.v(LOG_TAG, "Client instance set up.");
}
}

View File

@ -1,155 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import com.owncloud.android.lib.common.OwnCloudClientManager;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.lib.common.SingleSessionManager;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory.Policy;
import com.owncloud.android.lib.common.SimpleFactoryManager;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
/**
* Unit test for OwnCloudClientManagerFactory
*
* @author David A. Velasco
*/
public class OwnCloudClientManagerFactoryTest extends TestCase {
@Override
protected void setUp() {
OwnCloudClientManagerFactory.setDefaultPolicy(Policy.ALWAYS_NEW_CLIENT);
}
public void testGetDefaultPolicy() {
Policy defaultPolicy = OwnCloudClientManagerFactory.getDefaultPolicy();
assertNotNull("Returned null value", defaultPolicy);
assertTrue("Returned unknown value",
(Policy.ALWAYS_NEW_CLIENT.equals(defaultPolicy) ||
(Policy.SINGLE_SESSION_PER_ACCOUNT.equals(defaultPolicy))));
}
public void testSetDefaultPolicy() {
OwnCloudClientManagerFactory.setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT);
Policy defaultPolicy = OwnCloudClientManagerFactory.getDefaultPolicy();
assertEquals("SINGLE_SESSION_PER_ACCOUNT not set",
Policy.SINGLE_SESSION_PER_ACCOUNT, defaultPolicy);
OwnCloudClientManagerFactory.setDefaultPolicy(Policy.ALWAYS_NEW_CLIENT);
defaultPolicy = OwnCloudClientManagerFactory.getDefaultPolicy();
assertEquals("ALWAYS_NEW_CLIENT not set", Policy.ALWAYS_NEW_CLIENT, defaultPolicy);
try {
OwnCloudClientManagerFactory.setDefaultPolicy(null);
throw new AssertionFailedError("Accepted NULL parameter");
} catch(Exception e) {
assertTrue("Unexpected exception when setting default policy null",
(e instanceof IllegalArgumentException));
}
defaultPolicy = OwnCloudClientManagerFactory.getDefaultPolicy();
assertEquals("ALWAYS_NEW_CLIENT changed after setting null",
Policy.ALWAYS_NEW_CLIENT, defaultPolicy);
}
public void testGetDefaultSingleton() {
OwnCloudClientManager mgr = OwnCloudClientManagerFactory.getDefaultSingleton();
assertNotNull("Returned NULL default singleton", mgr);
assertTrue("Default singleton does not implement default policy",
mgr instanceof SimpleFactoryManager);
OwnCloudClientManager mgr2 = OwnCloudClientManagerFactory.getDefaultSingleton();
assertSame("Not singleton", mgr, mgr2);
OwnCloudClientManagerFactory.setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT);
mgr = OwnCloudClientManagerFactory.getDefaultSingleton();
assertNotNull("Returned NULL default singleton", mgr);
assertTrue("Default singleton does not implement default policy",
mgr instanceof SingleSessionManager);
mgr2 = OwnCloudClientManagerFactory.getDefaultSingleton();
assertSame("Not singleton", mgr, mgr2);
}
public void testNewDefaultOwnCloudClientManager() {
OwnCloudClientManager mgr = OwnCloudClientManagerFactory.newDefaultOwnCloudClientManager();
assertNotNull("Returned NULL default manager", mgr);
assertTrue("New manager does not implement default policy",
mgr instanceof SimpleFactoryManager);
assertNotSame("Not new instance",
mgr, OwnCloudClientManagerFactory.getDefaultSingleton());
assertNotSame("Not new instance",
mgr, OwnCloudClientManagerFactory.newDefaultOwnCloudClientManager());
OwnCloudClientManagerFactory.setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT);
mgr = OwnCloudClientManagerFactory.newDefaultOwnCloudClientManager();
assertNotNull("Returned NULL default manager", mgr);
assertTrue("New manager does not implement default policy",
mgr instanceof SingleSessionManager);
assertNotSame("Not new instance",
mgr, OwnCloudClientManagerFactory.getDefaultSingleton());
assertNotSame("Not new instance",
mgr, OwnCloudClientManagerFactory.newDefaultOwnCloudClientManager());
}
public void testNewOwnCloudClientManager() {
OwnCloudClientManager mgr = OwnCloudClientManagerFactory.
newOwnCloudClientManager(Policy.ALWAYS_NEW_CLIENT);
assertNotNull("Returned NULL manager", mgr);
assertTrue("New manager does not implement policy ALWAYS_NEW_CLIENT",
mgr instanceof SimpleFactoryManager);
assertNotSame("Not new instance",
mgr, OwnCloudClientManagerFactory.getDefaultSingleton());
assertNotSame("Not new instance",
mgr, OwnCloudClientManagerFactory.newDefaultOwnCloudClientManager());
assertNotSame("Not new instance",
mgr, OwnCloudClientManagerFactory.newOwnCloudClientManager(
Policy.ALWAYS_NEW_CLIENT));
OwnCloudClientManager mgr2 = OwnCloudClientManagerFactory.
newOwnCloudClientManager(Policy.SINGLE_SESSION_PER_ACCOUNT);
assertNotNull("Returned NULL manager", mgr2);
assertTrue("New manager does not implement policy SINGLE_SESSION_PER_ACCOUNT",
mgr2 instanceof SingleSessionManager);
assertNotSame("Not new instance",
mgr2, OwnCloudClientManagerFactory.getDefaultSingleton());
assertNotSame("Not new instance",
mgr2, OwnCloudClientManagerFactory.newDefaultOwnCloudClientManager());
assertNotSame("Not new instance",
mgr2, OwnCloudClientManagerFactory.newOwnCloudClientManager(
Policy.SINGLE_SESSION_PER_ACCOUNT));
}
}

View File

@ -1,375 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.io.IOException;
import java.io.InputStream;
import java.net.SocketTimeoutException;
import java.security.GeneralSecurityException;
import org.apache.jackrabbit.webdav.DavConstants;
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
import junit.framework.AssertionFailedError;
import android.net.Uri;
import android.test.AndroidTestCase;
import android.util.Log;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentials;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.common.network.NetworkUtils;
import com.owncloud.android.lib.test_project.R;
/**
* Unit test for OwnCloudClient
*
* @author David A. Velasco
*/
public class OwnCloudClientTest extends AndroidTestCase {
private static final String TAG = OwnCloudClientTest.class.getSimpleName();
private Uri mServerUri;
private String mUsername;
private String mPassword;
public OwnCloudClientTest() {
super();
Protocol pr = Protocol.getProtocol("https");
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
try {
ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
Protocol.registerProtocol(
"https",
new Protocol("https", psf, 443));
} catch (GeneralSecurityException e) {
throw new AssertionFailedError(
"Self-signed confident SSL context could not be loaded");
}
}
}
@Override
protected void setUp() throws Exception {
super.setUp();
mServerUri = Uri.parse(getContext().getString(R.string.server_base_url));
mUsername = getContext().getString(R.string.username);
mPassword = getContext().getString(R.string.password);
}
public void testConstructor() {
try {
new OwnCloudClient(null, NetworkUtils.getMultiThreadedConnManager());
throw new AssertionFailedError("Accepted NULL parameter");
} catch(Exception e) {
assertTrue("Unexpected exception passing NULL baseUri",
(e instanceof IllegalArgumentException));
}
try {
new OwnCloudClient(mServerUri, null);
throw new AssertionFailedError("Accepted NULL parameter");
} catch(Exception e) {
assertTrue("Unexpected exception passing NULL connectionMgr",
(e instanceof IllegalArgumentException));
}
OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
assertNotNull("OwnCloudClient instance not built", client);
}
public void testGetSetCredentials() {
OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
assertNotNull("Returned NULL credentials", client.getCredentials());
assertEquals("Not instanced without credentials",
client.getCredentials(), OwnCloudCredentialsFactory.getAnonymousCredentials());
OwnCloudCredentials credentials =
OwnCloudCredentialsFactory.newBasicCredentials("user", "pass");
client.setCredentials(credentials);
assertEquals("Basic credentials not set", credentials, client.getCredentials());
credentials = OwnCloudCredentialsFactory.newBearerCredentials("user", "bearerToken");
client.setCredentials(credentials);
assertEquals("Bearer credentials not set", credentials, client.getCredentials());
credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials("user", "samlSessionCookie=124");
client.setCredentials(credentials);
assertEquals("SAML2 session credentials not set", credentials, client.getCredentials());
}
public void testExecuteMethodWithTimeouts() throws HttpException, IOException {
OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
int connectionTimeout = client.getConnectionTimeout();
int readTimeout = client.getDataTimeout();
HeadMethod head = new HeadMethod(client.getWebdavUri() + "/");
try {
client.executeMethod(head, 1, 1000);
throw new AssertionFailedError("Completed HEAD with impossible read timeout");
} catch (Exception e) {
Log.e("OwnCloudClientTest", "EXCEPTION", e);
assertTrue("Unexcepted exception " + e.getLocalizedMessage(),
(e instanceof ConnectTimeoutException) ||
(e instanceof SocketTimeoutException));
} finally {
head.releaseConnection();
}
assertEquals("Connection timeout was changed for future requests",
connectionTimeout, client.getConnectionTimeout());
assertEquals("Read timeout was changed for future requests",
readTimeout, client.getDataTimeout());
try {
client.executeMethod(head, 1000, 1);
throw new AssertionFailedError("Completed HEAD with impossible connection timeout");
} catch (Exception e) {
Log.e("OwnCloudClientTest", "EXCEPTION", e);
assertTrue("Unexcepted exception " + e.getLocalizedMessage(),
(e instanceof ConnectTimeoutException) ||
(e instanceof SocketTimeoutException));
} finally {
head.releaseConnection();
}
assertEquals("Connection timeout was changed for future requests",
connectionTimeout, client.getConnectionTimeout());
assertEquals("Read timeout was changed for future requests",
readTimeout, client.getDataTimeout());
}
public void testExecuteMethod() {
OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
HeadMethod head = new HeadMethod(client.getWebdavUri() + "/");
int status = -1;
try {
status = client.executeMethod(head);
assertTrue("Wrong status code returned: " + status,
status > 99 && status < 600);
} catch (IOException e) {
Log.e(TAG, "Exception in HEAD method execution", e);
// TODO - make it fail? ; try several times, and make it fail if none
// is right?
} finally {
head.releaseConnection();
}
}
public void testExhaustResponse() {
OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
PropFindMethod propfind = null;
try {
propfind = new PropFindMethod(client.getWebdavUri() + "/",
DavConstants.PROPFIND_ALL_PROP,
DavConstants.DEPTH_0);
client.executeMethod(propfind);
InputStream responseBody = propfind.getResponseBodyAsStream();
if (responseBody != null) {
client.exhaustResponse(responseBody);
try {
int character = responseBody.read();
assertEquals("Response body was not fully exhausted",
character, -1); // -1 is acceptable
} catch (IOException e) {
// this is the preferred result
}
} else {
Log.e(TAG, "Could not test exhaustResponse due to wrong response");
// TODO - make it fail? ; try several times, and make it fail if none
// is right?
}
} catch (IOException e) {
Log.e(TAG, "Exception in PROPFIND method execution", e);
// TODO - make it fail? ; try several times, and make it fail if none
// is right?
} finally {
propfind.releaseConnection();
}
client.exhaustResponse(null); // must run with no exception
}
public void testGetSetDefaultTimeouts() {
OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
int oldDataTimeout = client.getDataTimeout();
int oldConnectionTimeout = client.getConnectionTimeout();
client.setDefaultTimeouts(oldDataTimeout + 1000, oldConnectionTimeout + 1000);
assertEquals("Data timeout not set",
oldDataTimeout + 1000, client.getDataTimeout());
assertEquals("Connection timeout not set",
oldConnectionTimeout + 1000, client.getConnectionTimeout());
client.setDefaultTimeouts(0, 0);
assertEquals("Zero data timeout not set",
0, client.getDataTimeout());
assertEquals("Zero connection timeout not set",
0, client.getConnectionTimeout());
client.setDefaultTimeouts(-1, -1);
assertEquals("Negative data timeout not ignored",
0, client.getDataTimeout());
assertEquals("Negative connection timeout not ignored",
0, client.getConnectionTimeout());
client.setDefaultTimeouts(-1, 1000);
assertEquals("Negative data timeout not ignored",
0, client.getDataTimeout());
assertEquals("Connection timeout not set",
1000, client.getConnectionTimeout());
client.setDefaultTimeouts(1000, -1);
assertEquals("Data timeout not set",
1000, client.getDataTimeout());
assertEquals("Negative connection timeout not ignored",
1000, client.getConnectionTimeout());
}
public void testGetWebdavUri() {
OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
client.setCredentials(OwnCloudCredentialsFactory.newBearerCredentials("user", "fakeToken"));
Uri webdavUri = client.getWebdavUri();
assertTrue("WebDAV URI does not point to the right entry point",
webdavUri.getPath().endsWith(OwnCloudClient.WEBDAV_PATH_4_0));
assertTrue("WebDAV URI is not a subpath of base URI",
webdavUri.getAuthority().equals(mServerUri.getAuthority()) &&
webdavUri.getPath().startsWith(mServerUri.getPath()));
client.setCredentials(OwnCloudCredentialsFactory.newBasicCredentials(
mUsername, mPassword));
webdavUri = client.getWebdavUri();
assertTrue("WebDAV URI does not point to the right entry point",
webdavUri.getPath().endsWith(OwnCloudClient.WEBDAV_PATH_4_0));
PropFindMethod propfind = null;
try {
propfind = new PropFindMethod(webdavUri + "/",
DavConstants.PROPFIND_ALL_PROP,
DavConstants.DEPTH_0);
int status = client.executeMethod(propfind);
assertEquals("WebDAV request did not work on WebDAV URI",
HttpConstants.HTTP_MULTI_STATUS, status);
} catch (IOException e) {
Log.e(TAG, "Exception in PROPFIND method execution", e);
// TODO - make it fail? ; try several times, and make it fail if none
// is right?
} finally {
propfind.releaseConnection();
}
}
public void testGetSetBaseUri() {
OwnCloudClient client =
new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
assertEquals("Returned base URI different that URI passed to constructor",
mServerUri, client.getBaseUri());
Uri otherUri = Uri.parse("https://whatever.com/basePath/here");
client.setBaseUri(otherUri);
assertEquals("Returned base URI different that URI passed to constructor",
otherUri, client.getBaseUri());
try {
client.setBaseUri(null);
throw new AssertionFailedError("Accepted NULL parameter");
} catch(Exception e) {
assertTrue("Unexpected exception passing NULL base URI",
(e instanceof IllegalArgumentException));
}
}
public void testGetCookiesString() {
// TODO implement test body
/*public String getCookiesString(){
Cookie[] cookies = getState().getCookies();
String cookiesString ="";
for (Cookie cookie: cookies) {
cookiesString = cookiesString + cookie.toString() + ";";
logCookie(cookie);
}
return cookiesString;
}
*/
}
public void testSetFollowRedirects() {
// TODO - to implement this test we need a redirected server
}
}

View File

@ -1,85 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.io.File;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.test_project.TestActivity;
/**
* Class to test Read File Operation
* @author masensio
* @author David A. Velasco
*/
public class ReadFileTest extends RemoteTest {
private static final String LOG_TAG = ReadFileTest.class.getCanonicalName();
private TestActivity mActivity;
private String FILE_PATH = "/fileToRead.txt";
private String mFullPath2File;
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
mFullPath2File = mBaseFolderPath + FILE_PATH;
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
RemoteOperationResult uploadResult = mActivity.uploadFile(
textFile.getAbsolutePath(),
mFullPath2File,
"txt/plain");
if (!uploadResult.isSuccess()) {
Utils.logAndThrow(LOG_TAG, uploadResult);
}
}
/**
* Test Read File
*/
public void testReadFile() {
RemoteOperationResult result = mActivity.readFile(mFullPath2File);
assertTrue(result.getData() != null && result.getData().size() == 1);
assertTrue(result.isSuccess());
// TODO check more properties of the result
}
@Override
protected void tearDown() throws Exception {
RemoteOperationResult removeResult = mActivity.removeFile(mFullPath2File);
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, removeResult);
}
super.tearDown();
}
}

View File

@ -1,101 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.io.File;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.test_project.TestActivity;
/**
* Class to test Read Folder Operation
* @author masensio
* @author David A. Velasco
*/
public class ReadFolderTest extends RemoteTest {
private static final String LOG_TAG = ReadFolderTest.class.getCanonicalName();
private static final String FOLDER_PATH = "/folderToRead";
private static final String [] FILE_PATHS = {
FOLDER_PATH + "/file1.txt",
FOLDER_PATH + "/file2.txt",
FOLDER_PATH + "/file3.txt",
};
private TestActivity mActivity;
private String mFullPathToFolder;
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
mFullPathToFolder = mBaseFolderPath + FOLDER_PATH;
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
RemoteOperationResult result = mActivity.createFolder( mFullPathToFolder, true);
if (result.isSuccess()) {
for (int i=0; i<FILE_PATHS.length && result.isSuccess(); i++) {
result = mActivity.uploadFile(
textFile.getAbsolutePath(),
mBaseFolderPath + FILE_PATHS[i],
"txt/plain");
}
}
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
}
/**
* Test Read Folder
*/
public void testReadFolder() {
RemoteOperationResult result = mActivity.readFile(mFullPathToFolder);
assertTrue(result.isSuccess());
assertTrue(result.getData() != null && result.getData().size() > 1);
assertTrue(result.getData().size() == 4);
// TODO assert more properties about the result
}
@Override
protected void tearDown() throws Exception {
RemoteOperationResult removeResult = mActivity.removeFile(mFullPathToFolder);
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, removeResult);
}
super.tearDown();
}
}

View File

@ -1,69 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.test_project.TestActivity;
import android.test.ActivityInstrumentationTestCase2;
/**
* Class to test Create Folder Operation
* @author David A. Velasco
*
*/
public class RemoteTest extends ActivityInstrumentationTestCase2<TestActivity> {
private static final String LOG_TAG = RemoteTest.class.getSimpleName();
protected String mBaseFolderPath = "/test_for_build_";
public RemoteTest() {
super(TestActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mBaseFolderPath += Utils.getBuildNumber(getActivity());
RemoteOperationResult result = getActivity().createFolder(mBaseFolderPath, true);
if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, result);
}
}
@Override
protected void tearDown() throws Exception {
RemoteOperationResult removeResult = getActivity().removeFile(mBaseFolderPath);
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, removeResult);
}
super.tearDown();
}
}

View File

@ -1,91 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.io.File;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.test_project.TestActivity;
public class RemoveShareTest extends RemoteTest {
private static final String LOG_TAG = RemoveShareTest.class.getCanonicalName();
private static final String FILE_TO_UNSHARE = "/fileToUnshare.txt";
private TestActivity mActivity;
private String mFullPath2FileToUnshare;
private long mShareId;
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
mFullPath2FileToUnshare = mBaseFolderPath + FILE_TO_UNSHARE;
File textFile = mActivity.extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
RemoteOperationResult result = mActivity.uploadFile(
textFile.getAbsolutePath(),
mFullPath2FileToUnshare,
"txt/plain");
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
result = mActivity.createShare(mFullPath2FileToUnshare, ShareType.PUBLIC_LINK, "", false, "", 1);
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
} else {
OCShare created = (OCShare) result.getData().get(0);
mShareId = created.getRemoteId();
}
}
/**
* Test Remove Share: the server must support SHARE API
*/
public void testRemoveShare() {
RemoteOperationResult result = mActivity.removeShare((int) mShareId);
assertTrue(result.isSuccess());
}
@Override
protected void tearDown() throws Exception {
RemoteOperationResult removeResult = mActivity.removeFile(mFullPath2FileToUnshare);
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, removeResult);
}
super.tearDown();
}
}

View File

@ -1,232 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.io.File;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.resources.files.FileUtils;
import com.owncloud.android.lib.test_project.TestActivity;
/**
* Class to test Rename File Operation
* @author masensio
*
*/
public class RenameFileTest extends RemoteTest {
private static final String LOG_TAG = RenameFileTest.class.getCanonicalName();
/* Folder data to rename. This folder must exist on the account */
private static final String OLD_FOLDER_NAME = "folderToRename";
private static final String OLD_FOLDER_PATH = FileUtils.PATH_SEPARATOR + OLD_FOLDER_NAME;
private static final String NEW_FOLDER_NAME = "renamedFolder";
private static final String NEW_FOLDER_PATH = FileUtils.PATH_SEPARATOR + NEW_FOLDER_NAME;
/* File data to rename. This file must exist on the account */
private static final String OLD_FILE_NAME = "fileToRename.png";
private static final String OLD_FILE_PATH = FileUtils.PATH_SEPARATOR + OLD_FILE_NAME;
private static final String NEW_FILE_NAME = "renamedFile.png";
private static final String NEW_FILE_PATH = FileUtils.PATH_SEPARATOR + NEW_FILE_NAME;
private String mToCleanUpInServer;
private TestActivity mActivity;
private String mFullPath2OldFolder;
private String mFullPath2NewFolder;
private String mFullPath2OldFile;
private String mFullPath2NewFile;
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
mFullPath2OldFolder = mBaseFolderPath + OLD_FOLDER_PATH;
mFullPath2NewFolder = mBaseFolderPath + NEW_FOLDER_PATH;
mFullPath2OldFile = mBaseFolderPath + OLD_FILE_PATH;
mFullPath2NewFile = mBaseFolderPath + NEW_FILE_PATH;
RemoteOperationResult result = mActivity.createFolder(mFullPath2OldFolder, true);
if (!result.isSuccess() && result.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, result);
}
File imageFile = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME);
result = mActivity.uploadFile(
imageFile.getAbsolutePath(),
mFullPath2OldFile,
"image/png");
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
mToCleanUpInServer = null;
}
/**
* Test Rename Folder
*/
public void testRenameFolder() {
mToCleanUpInServer = mFullPath2OldFolder;
RemoteOperationResult result = mActivity.renameFile(
OLD_FOLDER_NAME,
mFullPath2OldFolder,
NEW_FOLDER_NAME,
true);
assertTrue(result.isSuccess());
mToCleanUpInServer = mFullPath2NewFolder;
}
/**
* Test Rename Folder with forbidden characters : \ < > : " | ? *
*/
public void testRenameFolderForbiddenChars() {
RemoteOperationResult result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder,
NEW_FOLDER_NAME + "\\", true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder,
NEW_FOLDER_NAME + "<", true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder,
NEW_FOLDER_NAME + ">", true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder,
NEW_FOLDER_NAME + ":", true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder,
NEW_FOLDER_NAME + "\"", true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder,
NEW_FOLDER_NAME + "|", true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder,
NEW_FOLDER_NAME + "?", true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(OLD_FOLDER_NAME, mFullPath2OldFolder,
NEW_FOLDER_NAME + "*", true);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
}
/**
* Test Rename File
*/
public void testRenameFile() {
mToCleanUpInServer = mFullPath2OldFile;
RemoteOperationResult result = mActivity.renameFile(
OLD_FILE_NAME,
mFullPath2OldFile,
NEW_FILE_NAME,
false);
assertTrue(result.isSuccess());
mToCleanUpInServer = mFullPath2NewFile;
}
/**
* Test Rename Folder with forbidden characters: \ < > : " | ? *
*/
public void testRenameFileForbiddenChars() {
RemoteOperationResult result = mActivity.renameFile(
OLD_FILE_NAME,
mFullPath2OldFile,
"\\" + NEW_FILE_NAME,
false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(
OLD_FILE_NAME,
mFullPath2OldFile,
"<" + NEW_FILE_NAME,
false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(
OLD_FILE_NAME,
mFullPath2OldFile,
">" + NEW_FILE_NAME,
false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(
OLD_FILE_NAME,
mFullPath2OldFile,
":" + NEW_FILE_NAME,
false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(
OLD_FILE_NAME,
mFullPath2OldFile,
"\"" + NEW_FILE_NAME,
false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(
OLD_FILE_NAME,
mFullPath2OldFile,
"|" + NEW_FILE_NAME,
false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(
OLD_FILE_NAME,
mFullPath2OldFile,
"?" + NEW_FILE_NAME,
false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
result = mActivity.renameFile(
OLD_FILE_NAME,
mFullPath2OldFile,
"*" + NEW_FILE_NAME, false);
assertTrue(result.getCode() == ResultCode.INVALID_CHARACTER_IN_NAME);
}
@Override
protected void tearDown() throws Exception {
if (mToCleanUpInServer != null) {
RemoteOperationResult removeResult = mActivity.removeFile(mToCleanUpInServer);
if (!removeResult.isSuccess()) {
Utils.logAndThrow(LOG_TAG, removeResult);
}
}
super.tearDown();
}
}

View File

@ -1,132 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.security.GeneralSecurityException;
import android.net.Uri;
import android.test.AndroidTestCase;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.SimpleFactoryManager;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.test_project.R;
import com.owncloud.android.lib.test_project.SelfSignedConfidentSslSocketFactory;
import junit.framework.AssertionFailedError;
/**
* Unit test for SimpleFactoryManager
*
* @author David A. Velasco
*/
public class SimpleFactoryManagerTest extends AndroidTestCase {
private SimpleFactoryManager mSFMgr;
private Uri mServerUri;
private String mUsername;
private OwnCloudAccount mValidAccount;
private OwnCloudAccount mAnonymousAccount;
public SimpleFactoryManagerTest() {
super();
Protocol pr = Protocol.getProtocol("https");
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
try {
ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
Protocol.registerProtocol(
"https",
new Protocol("https", psf, 443));
} catch (GeneralSecurityException e) {
throw new AssertionFailedError(
"Self-signed confident SSL context could not be loaded");
}
}
}
@Override
protected void setUp() throws Exception {
super.setUp();
mSFMgr = new SimpleFactoryManager();
mServerUri = Uri.parse(getContext().getString(R.string.server_base_url));
mUsername = getContext().getString(R.string.username);
mValidAccount = new OwnCloudAccount(
mServerUri, OwnCloudCredentialsFactory.newBasicCredentials(
mUsername,
getContext().getString(R.string.password)
)
);
mAnonymousAccount = new OwnCloudAccount(
mServerUri, OwnCloudCredentialsFactory.getAnonymousCredentials());
}
public void testGetClientFor() {
try {
OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext());
assertNotSame("Got same client instances for same account",
client, mSFMgr.getClientFor(mValidAccount, getContext()));
assertNotSame("Got same client instances for different accounts",
client, mSFMgr.getClientFor(mAnonymousAccount, getContext()));
} catch (Exception e) {
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
}
// TODO harder tests
}
public void testRemoveClientFor() {
try {
OwnCloudClient client = mSFMgr.getClientFor(mValidAccount, getContext());
mSFMgr.removeClientFor(mValidAccount);
assertNotSame("Got same client instance after removing it from manager",
client, mSFMgr.getClientFor(mValidAccount, getContext()));
} catch (Exception e) {
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
}
// TODO harder tests
}
public void testSaveAllClients() {
// TODO implement test;
// or refactor saveAllClients() method out of OwnCloudClientManager to make
// it independent of AccountManager
}
}

View File

@ -1,131 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.security.GeneralSecurityException;
import android.net.Uri;
import android.test.AndroidTestCase;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.SingleSessionManager;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.test_project.R;
import junit.framework.AssertionFailedError;
/**
* Unit test for SingleSessionManager
*
* @author David A. Velasco
*/
public class SingleSessionManagerTest extends AndroidTestCase {
private SingleSessionManager mSSMgr;
private Uri mServerUri;
private String mUsername;
private OwnCloudAccount mValidAccount;
private OwnCloudAccount mAnonymousAccount;
public SingleSessionManagerTest() {
super();
Protocol pr = Protocol.getProtocol("https");
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
try {
ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
Protocol.registerProtocol(
"https",
new Protocol("https", psf, 443));
} catch (GeneralSecurityException e) {
throw new AssertionFailedError(
"Self-signed confident SSL context could not be loaded");
}
}
}
@Override
protected void setUp() throws Exception {
super.setUp();
mSSMgr = new SingleSessionManager();
mServerUri = Uri.parse(getContext().getString(R.string.server_base_url));
mUsername = getContext().getString(R.string.username);
mValidAccount = new OwnCloudAccount(
mServerUri, OwnCloudCredentialsFactory.newBasicCredentials(
mUsername,
getContext().getString(R.string.password)
)
);
mAnonymousAccount = new OwnCloudAccount(
mServerUri, OwnCloudCredentialsFactory.getAnonymousCredentials());
}
public void testGetClientFor() {
try {
OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext());
OwnCloudClient client2 = mSSMgr.getClientFor(mAnonymousAccount, getContext());
assertNotSame("Got same client instances for different accounts",
client1, client2);
assertSame("Got different client instances for same account",
client1, mSSMgr.getClientFor(mValidAccount, getContext()));
} catch (Exception e) {
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
}
// TODO harder tests
}
public void testRemoveClientFor() {
try {
OwnCloudClient client1 = mSSMgr.getClientFor(mValidAccount, getContext());
mSSMgr.removeClientFor(mValidAccount);
assertNotSame("Got same client instance after removing it from manager",
client1, mSSMgr.getClientFor(mValidAccount, getContext()));
} catch (Exception e) {
throw new AssertionFailedError("Exception getting client for account: " + e.getMessage());
}
// TODO harder tests
}
public void testSaveAllClients() {
// TODO implement test;
// or refactor saveAllClients() method out of OwnCloudClientManager to make
// it independent of AccountManager
}
}

View File

@ -1,257 +0,0 @@
/* ownCloud Android Library is available under MIT license
* @author masensio
* @author David A. Velasco
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.io.File;
import java.security.GeneralSecurityException;
import junit.framework.AssertionFailedError;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.common.network.NetworkUtils;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation;
import com.owncloud.android.lib.test_project.R;
import com.owncloud.android.lib.test_project.TestActivity;
/**
* Class to test UpdateRemoteShareOperation
* with private shares
*
*/
public class UpdatePrivateShareTest extends RemoteTest {
private static final String LOG_TAG = UpdatePrivateShareTest.class.getCanonicalName();
/* File to share and update */
private static final String FILE_TO_SHARE = "/fileToShare.txt";
/* Folder to share and update */
private static final String FOLDER_TO_SHARE = "/folderToShare";
/* Sharees */
private static final String USER_SHAREE = "admin";
private static final String GROUP_SHAREE = "admin";
private String mFullPath2FileToShare;
private String mFullPath2FolderToShare;
private OCShare mFileShare;
private OCShare mFolderShare;
String mServerUri, mUser, mPass;
OwnCloudClient mClient = null;
public UpdatePrivateShareTest(){
super();
Protocol pr = Protocol.getProtocol("https");
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
try {
ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
Protocol.registerProtocol(
"https",
new Protocol("https", psf, 443));
} catch (GeneralSecurityException e) {
throw new AssertionFailedError(
"Self-signed confident SSL context could not be loaded");
}
}
}
protected Context getContext() {
return getActivity();
}
@Override
protected void setUp() throws Exception {
super.setUp();
// Next initialization cannot be done in the constructor because getContext() is not
// ready yet, returns NULL.
initAccessToServer(getContext());
Log.v(LOG_TAG, "Setting up the remote fixture...");
// Upload the file
mFullPath2FileToShare = mBaseFolderPath + FILE_TO_SHARE;
File textFile = getActivity().extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
RemoteOperationResult result = getActivity().uploadFile(
textFile.getAbsolutePath(),
mFullPath2FileToShare,
"txt/plain");
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
// Share the file privately with other user
result = getActivity().createShare(
mFullPath2FileToShare,
ShareType.USER,
USER_SHAREE,
false,
"",
OCShare.MAXIMUM_PERMISSIONS_FOR_FILE);
if (result.isSuccess()){
mFileShare = (OCShare) result.getData().get(0);
} else{
mFileShare = null;
}
// Create the folder
mFullPath2FolderToShare = mBaseFolderPath + FOLDER_TO_SHARE;
result = getActivity().createFolder(
mFullPath2FolderToShare,
true);
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
// Share the folder privately with a group
result = getActivity().createShare(
mFullPath2FolderToShare,
ShareType.GROUP,
GROUP_SHAREE,
false,
"",
OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER);
if (result.isSuccess()){
mFolderShare = (OCShare) result.getData().get(0);
} else{
mFolderShare = null;
}
Log.v(LOG_TAG, "Remote fixture created.");
}
public void testUpdateSharePermissions() {
Log.v(LOG_TAG, "testUpdateSharePermissions in");
if (mFileShare != null) {
/// successful tests
// Update Share permissions on a shared file
UpdateRemoteShareOperation updateShare = new UpdateRemoteShareOperation(
mFileShare.getRemoteId()
);
updateShare.setPermissions(OCShare.READ_PERMISSION_FLAG); // minimum permissions
RemoteOperationResult result = updateShare.execute(mClient);
assertTrue(result.isSuccess());
// Update Share permissions on a shared folder
updateShare = new UpdateRemoteShareOperation(mFolderShare.getRemoteId());
updateShare.setPermissions(OCShare.READ_PERMISSION_FLAG + OCShare.DELETE_PERMISSION_FLAG);
result = updateShare.execute(mClient);
assertTrue(result.isSuccess());
/// unsuccessful tests
// Update Share with invalid permissions
updateShare = new UpdateRemoteShareOperation(mFileShare.getRemoteId());
// greater than maximum value
updateShare.setPermissions(OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER + 1);
result = updateShare.execute(mClient);
assertFalse(result.isSuccess());
// Unshare the file before next unsuccessful tests
RemoveRemoteShareOperation unshare = new RemoveRemoteShareOperation(
(int) mFileShare.getRemoteId()
);
result = unshare.execute(mClient);
if (result.isSuccess()) {
// Update Share permissions on unknown share
UpdateRemoteShareOperation updateNoShare = new UpdateRemoteShareOperation(
mFileShare.getRemoteId()
);
updateNoShare.setPermissions(OCShare.READ_PERMISSION_FLAG); // minimum permissions
result = updateNoShare.execute(mClient);
assertFalse(result.isSuccess());
}
}
}
@Override
protected void tearDown() throws Exception {
Log.v(LOG_TAG, "Deleting remote fixture...");
if (mFullPath2FileToShare != null) {
RemoteOperationResult removeResult = getActivity().removeFile(mFullPath2FileToShare);
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, removeResult);
}
}
super.tearDown();
Log.v(LOG_TAG, "Remote fixture delete.");
}
private void initAccessToServer(Context context) {
Log.v(LOG_TAG, "Setting up client instance to access OC server...");
mServerUri = context.getString(R.string.server_base_url);
mUser = context.getString(R.string.username);
mPass = context.getString(R.string.password);
mClient = new OwnCloudClient(
Uri.parse(mServerUri),
NetworkUtils.getMultiThreadedConnManager()
);
mClient.setDefaultTimeouts(
OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,
OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT);
mClient.setFollowRedirects(true);
mClient.setCredentials(
OwnCloudCredentialsFactory.newBasicCredentials(
mUser,
mPass
)
);
Log.v(LOG_TAG, "Client instance set up.");
}
}

View File

@ -1,283 +0,0 @@
/* ownCloud Android Library is available under MIT license
* @author masensio
* @author David A. Velasco
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.io.File;
import java.security.GeneralSecurityException;
import java.util.Calendar;
import junit.framework.AssertionFailedError;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.common.network.NetworkUtils;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation;
import com.owncloud.android.lib.test_project.R;
import com.owncloud.android.lib.test_project.TestActivity;
/**
* Class to test UpdateRemoteShareOperation
* with public shares
*
*/
public class UpdatePublicShareTest extends RemoteTest {
private static final String LOG_TAG = UpdatePublicShareTest.class.getCanonicalName();
/* File to share and update.*/
private static final String FILE_TO_SHARE = "/fileToShare.txt";
/* Folder to share and update */
private static final String FOLDER_TO_SHARE = "/folderToShare";
// Data for tests
private static final String PASSWORD = "password";
private static final String PASS_SPECIAL_CHARS = "p@ssw<73>rd";
private String mFullPath2FileToShare;
private String mFullPath2FolderToShare;
private OCShare mShare;
private OCShare mFolderShare;
String mServerUri, mUser, mPass;
OwnCloudClient mClient = null;
public UpdatePublicShareTest(){
super();
Protocol pr = Protocol.getProtocol("https");
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
try {
ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
Protocol.registerProtocol(
"https",
new Protocol("https", psf, 443));
} catch (GeneralSecurityException e) {
throw new AssertionFailedError(
"Self-signed confident SSL context could not be loaded");
}
}
}
protected Context getContext() {
return getActivity();
}
@Override
protected void setUp() throws Exception {
super.setUp();
// Next initialization cannot be done in the constructor because getContext() is not
// ready yet, returns NULL.
initAccessToServer(getContext());
Log.v(LOG_TAG, "Setting up the remote fixture...");
// Upload the file
mFullPath2FileToShare = mBaseFolderPath + FILE_TO_SHARE;
File textFile = getActivity().extractAsset(TestActivity.ASSETS__TEXT_FILE_NAME);
RemoteOperationResult result = getActivity().uploadFile(
textFile.getAbsolutePath(),
mFullPath2FileToShare,
"txt/plain");
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
// Share the file with a public link
result = getActivity().createShare(
mFullPath2FileToShare,
ShareType.PUBLIC_LINK,
"",
false,
"",
OCShare.READ_PERMISSION_FLAG);
if (result.isSuccess()){
mShare = (OCShare) result.getData().get(0);
} else{
Utils.logAndThrow(LOG_TAG, result);
}
// Create the folder
mFullPath2FolderToShare = mBaseFolderPath + FOLDER_TO_SHARE;
result = getActivity().createFolder(
mFullPath2FolderToShare,
true);
if (!result.isSuccess()) {
Utils.logAndThrow(LOG_TAG, result);
}
// Share the folder publicly via link
result = getActivity().createShare(
mFullPath2FolderToShare,
ShareType.PUBLIC_LINK,
"",
false,
"",
OCShare.READ_PERMISSION_FLAG);
if (result.isSuccess()){
mFolderShare = (OCShare) result.getData().get(0);
} else{
Utils.logAndThrow(LOG_TAG, result);
}
Log.v(LOG_TAG, "Remote fixtures created.");
}
public void testUpdatePublicShare() {
Log.v(LOG_TAG, "testUpdatePublicShare in");
if (mShare != null) {
// successful tests
// Update Share with password
UpdateRemoteShareOperation updateShare = new UpdateRemoteShareOperation(mShare.getRemoteId());
updateShare.setPassword(PASSWORD);
RemoteOperationResult result = updateShare.execute(mClient);
assertTrue(result.isSuccess());
// Update Share with password with special characters
updateShare = new UpdateRemoteShareOperation(mShare.getRemoteId());
updateShare.setPassword(PASS_SPECIAL_CHARS);
result = updateShare.execute(mClient);
assertTrue(result.isSuccess());
// Update Share with expiration date
updateShare = new UpdateRemoteShareOperation(mShare.getRemoteId());
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, 7);
long expirationDateInMillis = calendar.getTimeInMillis() ;
updateShare.setExpirationDate(expirationDateInMillis);
result = updateShare.execute(mClient);
assertTrue(result.isSuccess());
// Update the Folder Share with edit permission
updateShare = new UpdateRemoteShareOperation(mFolderShare.getRemoteId());
updateShare.setPublicUpload(true);
result = updateShare.execute(mClient);
assertTrue(result.isSuccess());
// unsuccessful test
// Update Share with expiration date in the past
updateShare = new UpdateRemoteShareOperation(mShare.getRemoteId());
calendar.set(Calendar.YEAR, 2014);
expirationDateInMillis = calendar.getTimeInMillis() ;
updateShare.setExpirationDate(expirationDateInMillis);
result = updateShare.execute(mClient);
assertFalse(result.isSuccess());
// Try to update the file Share with edit permission
updateShare = new UpdateRemoteShareOperation(mShare.getRemoteId());
updateShare.setPublicUpload(true);
result = updateShare.execute(mClient);
assertFalse(result.isSuccess());
// Unshare the file before the unsuccessful tests
RemoveRemoteShareOperation unshare = new RemoveRemoteShareOperation((int) mShare.getRemoteId());
result = unshare.execute(mClient);
if (result.isSuccess()) {
// Update Share with password on unknown share
UpdateRemoteShareOperation updateNoShare = new UpdateRemoteShareOperation(mShare.getRemoteId());
updateNoShare.setPassword(PASSWORD);
result = updateNoShare.execute(mClient);
assertFalse(result.isSuccess());
// Update Share with expiration date on unknown share
updateNoShare = new UpdateRemoteShareOperation(mShare.getRemoteId());
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, 7);
expirationDateInMillis = cal.getTimeInMillis() ;
updateNoShare.setExpirationDate(expirationDateInMillis);
result = updateNoShare.execute(mClient);
assertFalse(result.isSuccess());
}
}
}
@Override
protected void tearDown() throws Exception {
Log.v(LOG_TAG, "Deleting remote fixture...");
if (mFullPath2FileToShare != null) {
RemoteOperationResult removeResult = getActivity().removeFile(mFullPath2FileToShare);
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, removeResult);
}
}
super.tearDown();
Log.v(LOG_TAG, "Remote fixture delete.");
}
private void initAccessToServer(Context context) {
Log.v(LOG_TAG, "Setting up client instance to access OC server...");
mServerUri = context.getString(R.string.server_base_url);
mUser = context.getString(R.string.username);
mPass = context.getString(R.string.password);
mClient = new OwnCloudClient(
Uri.parse(mServerUri),
NetworkUtils.getMultiThreadedConnManager()
);
mClient.setDefaultTimeouts(
OwnCloudClientFactory.DEFAULT_DATA_TIMEOUT,
OwnCloudClientFactory.DEFAULT_CONNECTION_TIMEOUT);
mClient.setFollowRedirects(true);
mClient.setCredentials(
OwnCloudCredentialsFactory.newBasicCredentials(
mUser,
mPass
)
);
Log.v(LOG_TAG, "Client instance set up.");
}
}

View File

@ -1,124 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import java.io.File;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.test_project.TestActivity;
/**
* Class to test Update File Operation
* @author masensio
* @author David A. Velasco
*
*/
public class UploadFileTest extends RemoteTest {
private static final String LOG_TAG = UploadFileTest.class.getCanonicalName();
private static final String UPLOAD_PATH = "/uploadedImage.png";
private static final String CHUNKED_UPLOAD_PATH = "/uploadedVideo.MP4";
private static final String FILE_NOT_FOUND_PATH = "/notFoundShouldNotBeHere.png";
private TestActivity mActivity;
private File mFileToUpload, mFileToUploadWithChunks;
private String mUploadedFilePath;
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
mUploadedFilePath = null;
mFileToUpload = mActivity.extractAsset(TestActivity.ASSETS__IMAGE_FILE_NAME);
mFileToUploadWithChunks = mActivity.extractAsset(TestActivity.ASSETS__VIDEO_FILE_NAME);
}
/**
* Test Upload File without chunks
*/
public void testUploadFile() {
String fullPath2Upload = mBaseFolderPath + UPLOAD_PATH;
RemoteOperationResult result = mActivity.uploadFile(
mFileToUpload.getAbsolutePath(),
fullPath2Upload,
"image/png"
);
mUploadedFilePath = fullPath2Upload;
assertTrue(result.isSuccess());
}
/**
* Test Upload File with chunks
*/
public void testUploadFileWithChunks() {
String fullPath2Upload = mBaseFolderPath + CHUNKED_UPLOAD_PATH;
RemoteOperationResult result = mActivity.uploadFile(
mFileToUploadWithChunks.getAbsolutePath(),
fullPath2Upload,
"video/mp4"
);
mUploadedFilePath = fullPath2Upload;
assertTrue(result.isSuccess());
}
/**
* Test Upload Not Found File
*/
public void testUploadFileNotFound() {
String fullPath2Upload = mBaseFolderPath + FILE_NOT_FOUND_PATH;
RemoteOperationResult result = mActivity.uploadFile(
FILE_NOT_FOUND_PATH,
fullPath2Upload,
"image/png"
);
mUploadedFilePath = fullPath2Upload;
assertFalse(result.isSuccess());
}
@Override
protected void tearDown() throws Exception {
if (mUploadedFilePath != null) {
RemoteOperationResult removeResult = mActivity.removeFile(mUploadedFilePath);
if (!removeResult.isSuccess() && removeResult.getCode() != ResultCode.TIMEOUT) {
Utils.logAndThrow(LOG_TAG, removeResult);
}
}
super.tearDown();
}
}

View File

@ -1,55 +0,0 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.test_project.test;
import android.content.Context;
import android.util.Log;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.test_project.R;
public class Utils {
private static String LOG_TAG = Utils.class.getSimpleName();
private static String sBuildNumber = null;
public static void logAndThrow(String tag, RemoteOperationResult result) throws Exception {
Log.e(tag, result.getLogMessage(), result.getException());
throw new Exception(result.getLogMessage(), result.getException());
}
public static String getBuildNumber(Context context) {
if (sBuildNumber == null) {
sBuildNumber = context.getString(R.string.build_number);
if (sBuildNumber == null || sBuildNumber.length() == 0) {
Log.w(LOG_TAG, "Build number unknown, using current time instead");
sBuildNumber = Long.toString(System.currentTimeMillis());
}
}
return sBuildNumber;
}
}