diff --git a/src/androidTest/java/at/bitfire/dav4android/DavCollectionTest.kt b/src/androidTest/java/at/bitfire/dav4android/DavCollectionTest.kt index ee0020182596d5cac8471d0339d8713b5354fb86..66333d0255c6e477ac9a9353cdd4055bd0a470c7 100644 --- a/src/androidTest/java/at/bitfire/dav4android/DavCollectionTest.kt +++ b/src/androidTest/java/at/bitfire/dav4android/DavCollectionTest.kt @@ -8,14 +8,14 @@ package at.bitfire.dav4android +import at.bitfire.dav4android.exception.HttpException import at.bitfire.dav4android.property.GetETag import at.bitfire.dav4android.property.SyncToken import okhttp3.OkHttpClient import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.MockWebServer import org.junit.After -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue +import org.junit.Assert.* import org.junit.Before import org.junit.Test @@ -34,9 +34,93 @@ class DavCollectionTest { @After fun stopServer() = mockServer.shutdown() + /** + * Test sample response for an initial sync-collection report from RFC 6578 3.8. + */ + @Test + fun testInitialSyncCollectionReport() { + val url = sampleUrl() + val collection = DavCollection(httpClient, url) + mockServer.enqueue(MockResponse() + .setResponseCode(207) + .setHeader("Content-Type", "text/xml; charset=\"utf-8\"") + .setBody("\n" + + " \n" + + " \n" + + " ${sampleUrl()}test.doc\n" + + " \n" + + " \n" + + " \"00001-abcd1\"\n" + + " \n" + + " Box type A\n" + + " \n" + + " \n" + + " HTTP/1.1 200 OK\n" + + " \n" + + " \n" + + " \n" + + " ${sampleUrl()}vcard.vcf\n" + + " \n" + + " \n" + + " \"00002-abcd1\"\n" + + " \n" + + " HTTP/1.1 200 OK\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " HTTP/1.1 404 Not Found\n" + + " \n" + + " \n" + + " \n" + + " ${sampleUrl()}calendar.ics\n" + + " \n" + + " \n" + + " \"00003-abcd1\"\n" + + " \n" + + " HTTP/1.1 200 OK\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " HTTP/1.1 404 Not Found\n" + + " \n" + + " \n" + + " http://example.com/ns/sync/1234\n" + + " ") + ) + collection.reportChanges(null, false, null, GetETag.NAME) + + assertEquals(3, collection.members.size) + val members = collection.members.iterator() + val member1 = members.next() + assertEquals(sampleUrl().newBuilder().addPathSegment("test.doc").build(), member1.location) + assertEquals("00001-abcd1", member1.properties[GetETag::class.java]!!.eTag) + + val member2 = members.next() + assertEquals(sampleUrl().newBuilder().addPathSegment("vcard.vcf").build(), member2.location) + assertEquals("00002-abcd1", member2.properties[GetETag::class.java]!!.eTag) + + val member3 = members.next() + assertEquals(sampleUrl().newBuilder().addPathSegment("calendar.ics").build(), member3.location) + assertEquals("00003-abcd1", member3.properties[GetETag::class.java]!!.eTag) + + assertEquals(0, collection.removedMembers.size) + assertFalse(collection.furtherResults) + assertEquals("http://example.com/ns/sync/1234", collection.properties[SyncToken::class.java]!!.token) + } + + /** + * Test sample response for an initial sync-collection report with truncation from RFC 6578 3.10. + */ @Test - fun testSyncCollectionReport() { + fun testInitialSyncCollectionReportWithTruncation() { val url = sampleUrl() val collection = DavCollection(httpClient, url) @@ -95,4 +179,31 @@ class DavCollectionTest { assertEquals("http://example.com/ns/sync/1233", collection.properties[SyncToken::class.java]!!.token) } + /** + * Test sample response for a sync-collection report with unsupported limit from RFC 6578 3.12. + */ + @Test + fun testSyncCollectionReportWithUnsupportedLimit() { + val url = sampleUrl() + val collection = DavCollection(httpClient, url) + + mockServer.enqueue(MockResponse() + .setResponseCode(507) + .setHeader("Content-Type", "text/xml; charset=\"utf-8\"") + .setBody("\n" + + " \n" + + " \n" + + " ") + ) + + try { + collection.reportChanges("http://example.com/ns/sync/1232", false, 100, GetETag.NAME) + } catch (e: HttpException) { + assertEquals(507, e.status) + return + } + + fail() + } + } \ No newline at end of file