EN · DE · RU · FR · ES

#1863: CardDavUtilsTest.kt

projectforge-carddav/src/test/kotlin/org/projectforge/carddav/CardDavUtilsTest.kt Unit test — org.projectforge.carddav package, projectforge-carddav/src/test/kotlin/org/projectforge/carddav/CardDavUtilsTest.kt 50 lines · 23 code · 22 comments · 5 blank
Tests URL manipulation utilities in CardDavUtils: principal URL generation, URI normalization (stripping CardDAV prefixes), and contact ID extraction from VCF and photo file paths. These are core routing helpers for the CardDAV server implementation.

Architecture

CardDavUtils is a utility class providing static helper methods for the CardDAV protocol implementation. This test covers three key URL/path manipulation functions essential for CardDAV resource addressing.

Imports

Tested Methods

1. getPrincipalsUsersUrl(uri, user)

Converts a resource URL path to the corresponding principal URL. In WebDAV/CardDAV, each user has a principal resource representing their identity. This method maps user collection URLs to principal URLs:

The method strips URL suffixes (the ... represents trailing path segments) and rewrites users to principals/users/{username}. This is defined in RFC 3744 (WebDAV Access Control) and RFC 6352 (CardDAV).

2. normalizedUri(uri)

Strips the CardDAV prefix from URIs, normalizing them to their base resource type:

This method is used internally by the CardDAV dispatcher to determine which handler should process a request after the filter decides it's CardDAV traffic.

3. extractContactId(path)

Extracts the numeric ProjectForge contact ID from various file path patterns:

The method uses regex matching on ProjectForge-{id} and contact-{id} patterns, enabling the server to map CardDAV resource URLs back to ProjectForge database IDs.

User Object Construction Pattern

The test uses Kotlin's apply scope function pattern: PFUserDO().also { it.username = "joe" }. This creates a partially initialized PFUserDO with only the username set — sufficient for the URL generation methods which only need the username property.

All three methods are pure functions (no side effects, no external dependencies), making them ideal for unit testing without mocks. The only dependency is the PFUserDO entity which is constructed directly in the test.

Git History

868d6abb7 2025 -> 2026
63081666f Source file headers: 2024-> 2025.
cc9abacea CardDav-Server: WIP: image handling.
c4062ed97 WIP: Carddav
40e554cbe WIP: Carddav