EN · DE · RU · FR · ES

#1861: CardDavFilterTest.kt

projectforge-carddav/src/test/kotlin/org/projectforge/carddav/CardDavFilterTest.kt Unit test — org.projectforge.carddav package, projectforge-carddav/src/test/kotlin/org/projectforge/carddav/CardDavFilterTest.kt 79 lines · 43 code · 24 comments · 12 blank
Unit test that verifies the CardDavFilter.handledByCardDavFilter() static method correctly routes HTTP requests to the CardDAV servlet based on HTTP method and request URI patterns. Ensures only CardDAV-relevant requests (OPTIONS, PROPFIND, REPORT, GET on known paths) are intercepted by the filter while unrelated requests pass through.

Architecture

This test validates the CardDAV request routing logic in CardDavFilter. The system uses a Servlet Filter pattern — HTTP requests arrive at the application server and the filter decides whether to forward them to the CardDAV handler or let them continue through the normal request pipeline.

Imports and Dependencies

Test Design

The test employs a parameterized helper method pattern: checkRequest(method, requestUri, expected, msg?) creates a mocked HttpServletRequest via Mockito, stubs requestURI and method, then asserts the return value of CardDavFilter.handledByCardDavFilter(request) matches expected.

Test Coverage — Request Routing Matrix

HTTP MethodURI PatternExpectedRationale
OPTIONS/carddav, /carddav/users/kai, /users/kai, /users, /principalstrueOPTIONS is a CORS preflight / DAV capability check — all known CardDAV paths respond
PROPFIND/carddav, /carddav/users/kai, /users/kai, /carddav/users/, /users, /carddav/principals/, /principalstruePROPFIND is the WebDAV property-fetch method; intercepted on all user and principal URLs
OPTIONS/.well-known/carddavtrueWell-known URI discovery per RFC 6764 for CardDAV service location
GET/.well-known/carddavtrueGET on well-known URI returns service discovery info
GET/principalsfalseGET principal listing without DAV headers is not CardDAV
GET/carddavtrueGET on base carddav path
GET/carddav/users/joe/addressbooks/ProjectForge-123.vcftrueVCF download with dash-separated ID pattern "ProjectForge-123"
GET/users/joe/addressbooks/ProjectForge-123.vcftrueSame without /carddav prefix
GET/users/joe/addressbooks/ProjectForge123.vcffalseMissing dash separator — not recognized as ProjectForge identifier
GET/users/joe/address/ProjectForge-123.vcffalseWrong path segment "address" instead of "addressbooks"

Mocking Strategy

Uses Mockito.mock(HttpServletRequest::class.java) to create mock servlet requests. Then Mockito.when(request.method).thenReturn(method) and Mockito.when(request.requestURI).thenReturn(requestUri) set up the test fixture. No real HTTP server is involved — pure unit testing of the routing function.

The test covers both positive cases (true returns for valid CardDAV requests) and negative cases (false returns for non-CardDAV requests), including edge cases like missing dash separators in VCF filenames and wrong path segments.

Git History

868d6abb7 2025 -> 2026
63081666f Source file headers: 2024-> 2025.
fc6301b43 WIP: CardDavServer.
6c1daac93 WIP: Carddav
78a5132bf WIP: Carddav
c4062ed97 WIP: Carddav
40e554cbe WIP: Carddav
ad8b47d1f WIP: CardDavWIP: CardDav