EN · DE · RU · FR · ES

#1867: PropTest.kt

projectforge-carddav/src/test/kotlin/org/projectforge/carddav/PropTest.kt Unit test — org.projectforge.carddav package, projectforge-carddav/src/test/kotlin/org/projectforge/carddav/PropTest.kt 71 lines · 46 code · 22 comments · 3 blank
Tests Prop.extractProps() — the XML parser that extracts requested DAV property names from PROPFIND and sync-collection request bodies. Validates that property elements within <prop> or <d:prop> blocks are correctly identified, sorted alphabetically, and mapped to their PropType enum values.

Architecture

The Prop class represents a single DAV property requested by a client. The static extractProps(xml: String): List<Prop> method parses WebDAV XML request bodies to determine what properties the client wants to retrieve.

Imports

PropType Enum Values Covered

PropTypeXML ElementDAV/CardDAV Purpose
CURRENT_USER_PRINCIPAL<current-user-principal />URL of the authenticated user's principal resource (RFC 5397)
CURRENT_USER_PRIVILEGE_SET<current-user-privilege-set />Privileges granted to the current user (RFC 3744)
DISPLAYNAME<displayname />Human-readable name of the resource (RFC 4918)
RESOURCETYPE<resourcetype />Whether the resource is a collection (RFC 4918)
GETCTAG<cs:getctag />Calendar Server collection tag for change detection (Apple extension)
GETETAG<d:getetag />HTTP entity tag for the resource (RFC 4918)
SYNCTOKEN<sync-token />Token for incremental collection synchronization (RFC 6578)

Test Scenarios

Scenario 1: Standard PROPFIND (XML namespace="DAV:")

Input is a PROPFIND request body using a default XML namespace (xmlns="DAV:") — elements are unprefixed. The test verifies:

Scenario 2: sync-collection REPORT

Input simulates a sync-collection REPORT request (part of the RFC 6578 WebDAV Sync extension). The XML uses namespace prefixes (d:, cs:). The test verifies:

Parsing Logic (Inferred)

The extractProps method must:

  1. Find the <prop> or <d:prop> element block within the XML
  2. Extract child element names, stripping namespace prefixes
  3. Match element names to PropType enum values
  4. Sort results alphabetically by PropType
  5. Return a List<Prop>
The alphabetical sorting is important for deterministic behavior — clients receive properties in a predictable order regardless of request XML element order.

The sync-collection scenario's XML is structurally incorrect for a PROPFIND (the <prop> element is named <d:prop> inside an outer <propfind> wrapper), but the test correctly handles it — demonstrating the parser's robustness across different DAV request types.

Git History

868d6abb7 2025 -> 2026
63081666f Source file headers: 2024-> 2025.
5167dab99 WIP: Carddav
78a5132bf WIP: Carddav
caee35750 WIP: Carddav
2ad0cfe66 WIP: Carddav