-
Notifications
You must be signed in to change notification settings - Fork 2
Steps Common Dates
Jörg Flade edited this page Jun 24, 2026
·
3 revisions
These steps generate a date relative to today and store it in ScenarioContext.
The stored value can then be used in request bodies, URL parameters, or response validation.
Given that a date {int} days in the past is stored as {string}
Given that a date {int} days in the future is stored as {string}Scenario: Create a subscription that started yesterday
Given that a date 1 days in the past is stored as "START_DATE"
And that the body of the request is
"""
{
"startDate": "${START_DATE}",
"plan": "PREMIUM"
}
"""
When executing an authorized POST call to "/api/v1/subscriptions" with previously given body
Then I ensure that the status code of the response is 201
Scenario: Schedule an event for tomorrow
Given that a date 1 days in the future is stored as "TOMORROW"
And that the body of the request is
"""
{ "scheduledAt": "${TOMORROW}", "type": "REMINDER" }
"""
When executing an authorized POST call to "/api/v1/events" with previously given body
Then I ensure that the status code of the response is 201Given that a date {int} months in the past is stored as {string}
Given that a date {int} months in the future is stored as {string}Scenario: Fetch invoices from the last 3 months
Given that a date 3 months in the past is stored as "FROM_DATE"
When executing an authorized GET call to "/api/v1/invoices?from=${FROM_DATE}"
Then I ensure that the status code of the response is 200
Scenario: Renew a contract for 6 months ahead
Given that a date 6 months in the future is stored as "NEW_EXPIRY"
And that the body of the request is
"""
{ "expiresAt": "${NEW_EXPIRY}" }
"""
When executing an authorized PATCH call to "/api/v1/contracts/con-123" with previously given body
Then I ensure that the status code of the response is 200Given that a date {int} years in the past is stored as {string}
Given that a date {int} years in the future is stored as {string}Scenario: Check records from 2 years ago
Given that a date 2 years in the past is stored as "ARCHIVE_DATE"
When executing an authorized GET call to "/api/v1/archive?since=${ARCHIVE_DATE}"
Then I ensure that the status code of the response is 200
Scenario: Create a long-term license valid for 5 years
Given that a date 5 years in the future is stored as "LICENSE_EXPIRY"
And that the body of the request is
"""
{ "validUntil": "${LICENSE_EXPIRY}" }
"""
When executing an authorized POST call to "/api/v1/licenses" with previously given body
Then I ensure that the status code of the response is 201The JSON-Unit matcher ${json-unit.matches:isDateOfContext}<var> validates that a date field in the response equals a date previously stored in ScenarioContext.
The context variable name follows immediately after the closing } with no space.
Note: Only the date portion is compared — the time component is ignored.
Scenario: Created subscription has the expected start date
Given that a date 5 days in the past is stored as "EXPECTED_START"
When executing an authorized GET call to "/api/v1/subscriptions/sub-123"
Then I ensure that the body of the response is equal to
"""
{
"startDate": "${json-unit.matches:isDateOfContext}EXPECTED_START",
"plan": "PREMIUM"
}
"""
Scenario: Verify both start and end dates
Given that a date 30 days in the past is stored as "EXPECTED_START"
And that a date 335 days in the future is stored as "EXPECTED_END"
When executing an authorized GET call to "/api/v1/contracts/con-456"
Then I ensure that the body of the response contains the following fields and values
| startDate | ${json-unit.matches:isDateOfContext}EXPECTED_START |
| endDate | ${json-unit.matches:isDateOfContext}EXPECTED_END |For validating that a field simply contains any valid date (without comparing to a specific value), use ${json-unit.matches:isValidDate} — see JSON-Unit.
Examples: bdd-cucumber-gherkin-lib/src/test/resources/features/date_operations/date_operations.feature