Commit 86542e01 authored by Ricki Hirner's avatar Ricki Hirner 🐑
Browse files

Add Owner property and some tests

parent 32f2a204
Pipeline #216081072 passed with stages
in 3 minutes and 1 second
......@@ -44,6 +44,7 @@ object PropertyRegistry {
GetETag.Factory(),
GetLastModified.Factory(),
GroupMembership.Factory(),
Owner.Factory(),
QuotaAvailableBytes.Factory(),
QuotaUsedBytes.Factory(),
ResourceType.Factory(),
......
......@@ -17,9 +17,13 @@ abstract class HrefListProperty: Property {
val hrefs = LinkedList<String>()
val href
get() = hrefs.firstOrNull()
override fun toString() = "href=[" + hrefs.joinToString(", ") + "]"
abstract class Factory: PropertyFactory {
fun create(parser: XmlPullParser, list: HrefListProperty): HrefListProperty {
......
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package at.bitfire.dav4jvm.property
import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.XmlUtils
import org.xmlpull.v1.XmlPullParser
class Owner: HrefListProperty() {
companion object {
@JvmField
val NAME = Property.Name(XmlUtils.NS_WEBDAV, "owner")
}
class Factory : HrefListProperty.Factory() {
override fun getName() = NAME
override fun create(parser: XmlPullParser) =
create(parser, Owner())
}
}
\ No newline at end of file
package at.bitfire.dav4jvm.property
import org.junit.Assert.assertEquals
import org.junit.Test
class CalendarDescriptionTest: PropertyTest() {
@Test
fun testSource() {
val results = parseProperty("<calendar-description xmlns=\"urn:ietf:params:xml:ns:caldav\">My Calendar</calendar-description>")
val result = results.first() as CalendarDescription
assertEquals("My Calendar", result.description)
}
}
\ No newline at end of file
package at.bitfire.dav4jvm.property
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
class OwnerTest: PropertyTest() {
@Test
fun testOwner_WithoutHref() {
val results = parseProperty("<owner xmlns=\"DAV:\">https://example.com</owner>")
val owner = results.first() as Owner
assertNull(owner.href)
}
@Test
fun testOwner_OneHref() {
val results = parseProperty("<owner xmlns=\"DAV:\"><href>https://example.com</href></owner>")
val owner = results.first() as Owner
assertEquals("https://example.com", owner.href)
}
}
\ No newline at end of file
package at.bitfire.dav4jvm.property
import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.XmlUtils
import java.io.StringReader
open class PropertyTest {
companion object {
fun parseProperty(s: String): List<Property> {
val parser = XmlUtils.newPullParser()
parser.setInput(StringReader("<test>$s</test>"))
parser.nextTag() // move into <test>
return Property.parse(parser)
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment