Create a TimeProvider contract to get the current data time

Description

Currently date based constraint validators for @Past and @Future use the default system time to create the instant to compare with. This causes problems during testing, where there always will be border cases based on when the test is run. For testing purposes we want to be able to provide for example a constant instant via the TimeProvider contract. This way the test harness could be easily setup. Per default the TimeProvider would of course use the system time.

We can also consider to make the contract available for users, so that they can plug in their custom implementation. To a certain degree this is what for example java.lang.Clock tries to solve as well.

Environment

None

Activity

Show:
Hardy Ferentschik
February 12, 2015, 8:58 PM

I thought a bit about this one before and adding the contract and making in pluggable via a HV specific feature is easy. The interesting thing was, how to get hold of the time provider in a constraint validator (eg Past). I see basically two options:

  • Have some homegrown injection solution for this (nasty and might be a bit work)

  • Provide access via HibernateConstraintValidatorContext. Quite simple, the drawback being that the provider would only be accessible during the isValid call

Gunnar Morling
February 13, 2015, 12:06 PM

> Provide access via HibernateConstraintValidatorContext

Yes, I think that's the better approach. Also what I had in mind. If people want to inject stuff, they always can plug in the custom injection-enabled constraint validator factory and validators.

Hardy Ferentschik
February 13, 2015, 6:35 PM

Yes, I think that's the better approach. Also what I had in mind.

+1

Assignee

Hardy Ferentschik

Reporter

Hardy Ferentschik

Labels

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Suitable for new contributors

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Components

Fix versions

Priority

Major
Configure