EN · DE · RU · FR · ES

#1866: PropFindRequestHandlerTest.kt

projectforge-carddav/src/test/kotlin/org/projectforge/carddav/PropFindRequestHandlerTest.kt Unit test — org.projectforge.carddav package, projectforge-carddav/src/test/kotlin/org/projectforge/carddav/PropFindRequestHandlerTest.kt 108 lines · 83 code · 22 comments · 3 blank
Tests PropFindRequestHandler.generatePropFindResponse() — the core WebDAV PROPFIND response generator. Verifies correct XML multistatus responses for two scenarios: resource type/displayname queries and principal/privilege queries. Uses Mockito mocks for HTTP servlet objects and a real PFUserDO entity.

Architecture

PropFindRequestHandler is the server-side handler that responds to CardDAV PROPFIND requests per RFC 4918 (WebDAV). PROPFIND is the primary mechanism by which CardDAV clients discover server capabilities, resource types, and user principal information.

Imports

Test Scenarios

Scenario 1: RESOURCETYPE + DISPLAYNAME

When a client PROPFINDs for resourcetype and displayname properties on /carddav/users/kai/, the handler must respond with:

The response is a full XML multistatus document with DAV, CardDAV, CalDAV, and custom namespace declarations.

Scenario 2: CURRENT_USER_PRINCIPAL + PRIVILEGE_SET + PRINCIPAL_URL

When a client queries user identity properties:

Dependency Graph

ClassRole
PropRepresents a single requested DAV property with a PropType enum value
PropTypeEnum of known DAV properties: RESOURCETYPE, DISPLAYNAME, CURRENT_USER_PRINCIPAL, CURRENT_USER_PRIVILEGE_SET, PRINCIPAL_URL, GETETAG, GETCTAG, SYNCTOKEN
RequestWrapperWraps HttpServletRequest, extracts the request URI for response href generation
WriterContextBundles request wrapper, response, user, and requested props — the complete context needed by the handler
PropFindRequestHandlerStatic method generatePropFindResponse(WriterContext): String — pure function generating XML string

Mocking Strategy

XML Namespace Declarations

All responses include these XML namespace declarations:

xmlns:d="DAV:"
xmlns:card="urn:ietf:params:xml:ns:carddav"
xmlns:cs="http://calendarserver.org/ns/"
xmlns:me="http://me.com/_namespace/"

These correspond to: DAV core, CardDAV, Apple CalendarServer extensions, and a custom namespace.

The handler is a pure function (produces XML string from context) — no side effects, no database access. This design makes it highly testable and follows the functional core/imperative shell pattern.

Git History

CommitWhat changed in this file
868d6abb7Copyright year 2025→2026. No logic change.
63081666fCopyright year 2024→2025. No logic change.
f86cfa20aRemoved <card:addressbook/> from expected XML. Resource type reports only <d:collection/> — no longer claims CardDAV address book capability. Final cleanup after the addressbook element went through multiple add/remove cycles.
139f9f316Added <card:addressbook/> to resource type. Part of photo/avatar support — the element was briefly added to advertise CardDAV capability, then removed again in f86cfa20a.
5167dab99Major API change. (1) Prop.RESOURCETYPEProp(PropType.RESOURCETYPE): Prop became constructor-based. (2) Display name changed from i18n key "address.cardDAV..." to actual username "kai". (3) <card:addressbook/> temporarily removed.
6c1daac93Introduced WriterContext. generatePropFindResponse() signature changed from (request, user, props) to a single context object. Added HttpServletResponse mock. Cleaner extensibility.
0d7a81f91Added xmlns:me namespace. Swapped element order: <collection/> before <addressbook/>. DAV-required element now comes first.
b14376470cr:addressbookcard:addressbook. Namespace prefix standardized from obscure cr to conventional card.
744d238deNamespace URI fix. xmlns prefix crcard, corrected the CardDAV namespace URI string.
c4062ed97Added XML namespace prefixes. Bare elements (<multistatus>) → namespace-qualified (<d:multistatus>). Matched handler output after it started emitting qualified XML.
40e554cbeChanged test URI from generic /carddav to user-specific /carddav/users/kai/. Matched actual per-user URL structure.
2ad0cfe66Initial creation. Basic PROPFIND test with inline XML literals, Mockito HTTP mocks. Verified RESOURCETYPE + DISPLAYNAME properties.