using custom CommandTargetResolver in fixtures

51 views
Skip to first unread message

jorgheymans

unread,
Jan 11, 2017, 2:01:55 AM1/11/17
to Axon Framework Users
Hi,

In order to use a custom command target resolver during tests i came up with this:

    fixture = Fixtures.newGivenWhenThenFixture(BusinessDomainAR.class);
    AggregateAnnotationCommandHandler aggregateAnnotationCommandHandler =
        new AggregateAnnotationCommandHandler(BusinessDomainAR.class, fixture.getRepository(),
            new CustomCommandTargetResolver.ForBusinessDomain());
    fixture.registerCommandHandler(AddAdministrator.class, aggregateAnnotationCommandHandler);
    fixture.registerCommandHandler(RemoveAdministrator.class, aggregateAnnotationCommandHandler);  
    // register all other command classes used in the AR
    ...

Is there a way that allows me to do this without registering each command class individually ? 

Thanks,
Jorg

Allard Buijze

unread,
Jan 11, 2017, 10:59:32 AM1/11/17
to Axon Framework Users
Hi Jorg,

you can do: 
aggregateAnnotationCommandHandler.subscribe(CommandBus) to automatically subscribe all supported commands to the Command Bus.

Cheers,

Allard

--
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.
For more options, visit https://groups.google.com/d/optout.

jorgheymans

unread,
Jan 12, 2017, 1:52:42 AM1/12/17
to Axon Framework Users
Hi Allard,

There is no such method on the commandhandler, only a deprecated subscribe() method. I'm still on 2.4.6 maybe that's why. I made it a bit more convenient for my case using some classpath scanning and reflection, it's ok like that.

Jorg

Allard Buijze

unread,
Jan 12, 2017, 9:03:22 AM1/12/17
to Axon Framework Users
Ah 2.4.6. That explains why the method doesn't exist.

In that case, you have the supportedCommands() method on the AggregateAnnotationCommandHandler. For each entry there, subscribe the AggregateAnnotationCommandHandler to the command bus. Something like:
AggregateAnnotationCommandHandler.supportedCommands().forEach(c -> commandBus.subscribe(c, this));

Cheers,

Allard
Reply all
Reply to author
Forward
0 new messages