Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8a150270 authored by davigonz's avatar davigonz
Browse files

Add tests for the move method

parent 47e3bd47
Loading
Loading
Loading
Loading
+54 −0
Original line number Diff line number Diff line
@@ -75,6 +75,60 @@ class DavResourceTest {
        assertTrue(called)
    }

    @Test
    fun testMove() {
        val url = sampleUrl()
        val dav = DavResource(httpClient, url)
        val destination = "$url/test";

        /* POSITIVE TEST CASES */

        // no preconditions, 201 Created, new URL mapping at the destination
        mockServer.enqueue(MockResponse()
                .setResponseCode(HttpURLConnection.HTTP_CREATED))
        var called = false
        dav.move(destination, false) {
            called = true
        }
        assertTrue(called)

        var rq = mockServer.takeRequest()
        assertEquals("MOVE", rq.method)
        assertEquals(url.encodedPath(), rq.path)
        assertEquals(destination, rq.getHeader("Destination"))
        assertNull(rq.getHeader("Overwrite"))

        // no preconditions, 204 No content, URL already mapped
        mockServer.enqueue(MockResponse()
                .setResponseCode(HttpURLConnection.HTTP_NO_CONTENT))
        called = false
        dav.move(destination, false) {
            called = true
        }
        assertTrue(called)

        rq = mockServer.takeRequest()
        assertEquals("MOVE", rq.method)
        assertEquals(url.encodedPath(), rq.path)
        assertEquals(destination, rq.getHeader("Destination"))
        assertNull(rq.getHeader("Overwrite"))

        /* NEGATIVE TEST CASES */

        // 207 multi-status (e.g. errors on some of resources affected by
        // the MOVE prevented the operation from taking place)

        mockServer.enqueue(MockResponse()
                .setResponseCode(207))
        try {
            called = false
            dav.move(destination, false) { called = true }
            fail("Expected HttpException")
        } catch(e: HttpException) {
            assertFalse(called)
        }
    }

    @Test
    fun testGet() {
        val url = sampleUrl()