Skip to content

Commit

Permalink
Add Topic property
Browse files Browse the repository at this point in the history
  • Loading branch information
rfc2822 committed Feb 4, 2024
1 parent 8a56432 commit 731ca44
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/main/kotlin/at/bitfire/dav4jvm/PropertyRegistry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import at.bitfire.dav4jvm.property.carddav.AddressbookHomeSet
import at.bitfire.dav4jvm.property.carddav.SupportedAddressData
import at.bitfire.dav4jvm.property.push.PushSubscribe
import at.bitfire.dav4jvm.property.push.PushTransports
import at.bitfire.dav4jvm.property.push.Topic
import at.bitfire.dav4jvm.property.webdav.AddMember
import at.bitfire.dav4jvm.property.webdav.CreationDate
import at.bitfire.dav4jvm.property.webdav.CurrentUserPrincipal
Expand Down Expand Up @@ -92,7 +93,8 @@ object PropertyRegistry {
SupportedCalendarComponentSet.Factory,
SupportedCalendarData.Factory,
SupportedReportSet.Factory,
SyncToken.Factory
SyncToken.Factory,
Topic.Factory
))
}

Expand Down
35 changes: 35 additions & 0 deletions src/main/kotlin/at/bitfire/dav4jvm/property/push/Topic.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.push

import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.PropertyFactory
import at.bitfire.dav4jvm.XmlUtils
import org.xmlpull.v1.XmlPullParser

class Topic private constructor(
val topic: String
): Property {

companion object {

@JvmField
val NAME = Property.Name(NS_WEBDAV_PUSH, "topic")

}


object Factory: PropertyFactory {

override fun getName() = NAME

override fun create(parser: XmlPullParser) =
Topic(XmlUtils.requireReadText(parser))

}

}
9 changes: 7 additions & 2 deletions src/test/kotlin/at/bitfire/dav4jvm/property/WebPushTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import at.bitfire.dav4jvm.Property
import at.bitfire.dav4jvm.property.push.NS_WEBDAV_PUSH
import at.bitfire.dav4jvm.property.push.PushSubscribe
import at.bitfire.dav4jvm.property.push.PushTransports
import at.bitfire.dav4jvm.property.push.Topic
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
Expand All @@ -28,18 +29,22 @@ class WebPushTest: PropertyTest() {
}

@Test
fun testPushTransports() {
fun testServiceDetection() {
val results = parseProperty(
"<push-transports xmlns=\"DAV:Push\">" +
" <transport><something><else/></something></transport>" +
" <transport><web-push/></transport>" +
"</push-transports>")
"</push-transports>" +
"<topic xmlns=\"DAV:Push\">SomeTopic</topic>")
val result = results.first() as PushTransports

assertEquals(setOf(
Property.Name(NS_WEBDAV_PUSH, "something"),
PushTransports.WEB_PUSH
), result.transports)
assertTrue(result.hasWebPush())

assertEquals("SomeTopic", (results[1] as Topic).topic)
}

}

0 comments on commit 731ca44

Please sign in to comment.