mirror of
https://github.com/etesync/android
synced 2025-02-16 17:42:03 +00:00
basic WebDAV tests
This commit is contained in:
parent
f85dbe934b
commit
0626f1ecdc
@ -15,7 +15,7 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static URI resolveURI(URI parent, String member) {
|
||||
if (!member.startsWith("/"))
|
||||
if (!member.startsWith("/") && !member.startsWith("http:") && !member.startsWith("https://"))
|
||||
member = "./" + member;
|
||||
|
||||
return parent.resolve(member);
|
||||
|
@ -216,13 +216,12 @@ public class WebDavResource {
|
||||
|
||||
/* resource operations */
|
||||
|
||||
public boolean get() throws IOException, HttpException {
|
||||
public void get() throws IOException, HttpException {
|
||||
HttpGet get = new HttpGet(location);
|
||||
HttpResponse response = client.execute(get);
|
||||
checkResponse(response);
|
||||
|
||||
content = response.getEntity().getContent();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void put(byte[] data, PutMode mode) throws IOException, HttpException {
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">DavdroidTestTest</string>
|
||||
<string name="app_name">DavdroidTest</string>
|
||||
|
||||
</resources>
|
||||
|
@ -0,0 +1,42 @@
|
||||
package at.bitfire.davdroid.webdav.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.apache.http.HttpException;
|
||||
|
||||
import android.test.InstrumentationTestCase;
|
||||
import at.bitfire.davdroid.webdav.HttpPropfind;
|
||||
import at.bitfire.davdroid.webdav.InvalidDavResponseException;
|
||||
import at.bitfire.davdroid.webdav.WebDavCollection;
|
||||
import at.bitfire.davdroid.webdav.WebDavResource;
|
||||
|
||||
public class WebDavCollectionTest extends InstrumentationTestCase {
|
||||
WebDavCollection dav;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dav = new WebDavCollection(new URI("https://wurd.dev001.net/radicale/test/"), "test", "test", true);
|
||||
}
|
||||
|
||||
|
||||
public void testAutoDetection() throws InvalidDavResponseException, IOException, HttpException {
|
||||
WebDavCollection myDav = dav;
|
||||
|
||||
myDav.propfind(HttpPropfind.Mode.CURRENT_USER_PRINCIPAL);
|
||||
String currentUserPrincipal = myDav.getCurrentUserPrincipal();
|
||||
assertEquals("/radicale/test/", currentUserPrincipal);
|
||||
|
||||
myDav = new WebDavCollection(dav, currentUserPrincipal);
|
||||
myDav.propfind(HttpPropfind.Mode.HOME_SETS);
|
||||
String homeSet = myDav.getAddressbookHomeSet();
|
||||
assertEquals("/radicale/test/", homeSet);
|
||||
assertEquals("/radicale/test/", myDav.getCalendarHomeSet());
|
||||
|
||||
myDav = new WebDavCollection(dav, homeSet);
|
||||
myDav.propfind(HttpPropfind.Mode.MEMBERS_COLLECTIONS);
|
||||
assertEquals(3, myDav.getMembers().size());
|
||||
for (WebDavResource member : myDav.getMembers())
|
||||
assertTrue(member.isAddressBook() || member.isCalendar());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package at.bitfire.davdroid.webdav.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.apache.http.HttpException;
|
||||
|
||||
import android.test.InstrumentationTestCase;
|
||||
import at.bitfire.davdroid.webdav.WebDavResource;
|
||||
|
||||
public class WebDavResourceTest extends InstrumentationTestCase {
|
||||
URI davBaseURI, uriWithoutDAV, uriWithRedirection;
|
||||
final static String davUsername = "test", davPassword = "test";
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
davBaseURI = new URI("https://wurd.dev001.net/radicale/test/");
|
||||
uriWithoutDAV = new URI("http://www.apache.org");
|
||||
uriWithRedirection = new URI("http://wurd.dev001.net/public/");
|
||||
}
|
||||
|
||||
|
||||
public void testGet() throws URISyntaxException, IOException, HttpException {
|
||||
WebDavResource dav = new WebDavResource(uriWithoutDAV, "", "", false, true);
|
||||
dav.get();
|
||||
InputStream is = dav.getContent();
|
||||
assertNotNull(is);
|
||||
}
|
||||
|
||||
public void testTrailingSlash() throws URISyntaxException {
|
||||
WebDavResource dav = new WebDavResource(new URI("http://server/path"), "", "", false, true);
|
||||
assertEquals("/path/", dav.getLocation().getPath());
|
||||
}
|
||||
|
||||
public void testOptions() throws URISyntaxException, IOException, HttpException {
|
||||
String[] davMethods = new String[] { "PROPFIND", "PUT", "DELETE" },
|
||||
davCapabilities = new String[] { "addressbook", "calendar-access" };
|
||||
|
||||
// server without DAV
|
||||
WebDavResource dav = new WebDavResource(uriWithoutDAV, "", "", false, true);
|
||||
dav.options();
|
||||
for (String method : davMethods)
|
||||
assertFalse(dav.supportsMethod(method));
|
||||
for (String capability : davCapabilities)
|
||||
assertFalse(dav.supportsDAV(capability));
|
||||
|
||||
// server with DAV
|
||||
dav = new WebDavResource(davBaseURI, davUsername, davPassword, false, true);
|
||||
dav.options();
|
||||
for (String davMethod : davMethods)
|
||||
assert(dav.supportsMethod(davMethod));
|
||||
for (String capability : davCapabilities)
|
||||
assert(dav.supportsDAV(capability));
|
||||
}
|
||||
|
||||
public void testRedirections() throws URISyntaxException, IOException {
|
||||
WebDavResource dav = new WebDavResource(uriWithRedirection, "", "", false, true);
|
||||
try {
|
||||
dav.options();
|
||||
} catch (HttpException e) {
|
||||
return;
|
||||
}
|
||||
fail();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user