JUnit. How to change the creation time of given events by testFixture?

Hallo,

i try to test the ordering of event and i need a possibility to change a creation event time of given events by testFixture.

How can i do this?

thx.

i have already tryed.

`

final Instant minus = Instant.now().minus(1, ChronoUnit.DAYS);

testFixture.given(someInitializationEvent, someUpdateEvent).andGivenCurrentTime(minus)
        .when(reduceCommand)
        .expectEvents(new ReduceApprovedEvent(anyString, order.getQuantity()));

`

but i if get an event, the timestamp on event sourcing handler method is not changed.

`

@EventSourcingHandler
protected void on(AvailableQuantityUpdatedEvent event, @Timestamp Instant timeStamp) {
  this.quantity = event.getQuantity();
  this.lastUpdateFromPartner = Date.from(timeStamp);
}

`

what do i’m wrong.

Hi,

there are two things:

  1. the givenCurrentTime() comes after given(events…), so the events are already created
  2. There is an issue in Axon that the timestamp of events aren’t properly set.

Number 2 is fixed in Axon 4.0.1, which will be available very soon. Issue number 1 is something you’ll be able to fix hen 4.0.1 is out.

Cheers,

Allard