CREATE_IF_MISSING feature and AggregateTestFixture

83 views
Skip to first unread message

Rob Nobel

unread,
Sep 15, 2020, 11:34:47 AM9/15/20
to Axon Framework Users
Hi, I've been testing some things with regard to the CREATE_IF_MISSING aggregate feature. I've been trying several things in a running Spring boot application+dockerized Axon server and all works well, however I can not get the unittests to work when using the AggregateTestFixture. 

The aggregate only has a default public constructor. This is the only commandhandler:

@CommandHandler
@CreationPolicy(AggregateCreationPolicy.CREATE_IF_MISSING)
public void handle(ImportOrganisationCommand cmd) {
  if (id == null) {
     apply(new OrganisationCreatedEvent(cmd.getOrganisation()));
  } else if (!cmd.getOrganisation().equals(organisation)) {
     apply(new OrganisationUpdatedEvent(cmd.getOrganisation()));
  }
}


This is the test:

@Test
void test1() {
  ImportOrganisationCommand cmd = new ImportOrganisationCommand("1", org1);
  OrganisationCreatedEvent organisationCreatedEvent = new   OrganisationCreatedEvent(org1);
 
  testFixture.givenNoPriorActivity()
    .when(cmd)
    .expectEvents(organisationCreatedEvent);
}


which results in the following error:

org.axonframework.common.AxonConfigurationException: Identifier must be set after handling the message

I do not understand what the problem is ?

Steven van Beelen

unread,
Sep 16, 2020, 9:02:59 AM9/16/20
to Axon Framework Users
Hi Rob,

I don't think this is currently an issue with the usage of the create-if-missing functionality.
It is true that this exact message will only occur if a create-or-update is in progress, but it is there to signal users that the aggregate identifier is required to be set after handling the creation.

So, I am pretty confident you might be missing an Event Sourcing Handler for the OrganisationCreatedEvent to actually set the aggregate identifier field in the aggregate.
Could you confirm this is the case?

If not, then we have some further investigating to do!

Cheers,
Steven

PS. It is important to note that this mailing list will be discontinued as specified in this thread.
Instead of this mailing list we have moved to use a forum style of communication, at https://discuss.axoniq.io/.
Hope to see you there!

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/axonframework/1fe93611-9447-446d-b59d-23cc9cec9cebn%40googlegroups.com.

Rob Nobel

unread,
Sep 16, 2020, 10:45:11 AM9/16/20
to Axon Framework Users
Hi Steven, 

You are absolutely right, there is no issue. I did already use the Event Sourcing handler as you mentioned, but something was wrong with my testdata, which I kept overlooking. Sorry, my bad!

Op woensdag 16 september 2020 om 15:02:59 UTC+2 schreef Steven van Beelen:

Steven van Beelen

unread,
Sep 16, 2020, 10:48:09 AM9/16/20
to Axon Framework Users
Hi Rob,

No worries, stuff like that can happen!
Happy to have been of help here.

Cheers,
Steven

Reply all
Reply to author
Forward
0 new messages