Hello,
I have a command/query distributed system where i’m using RabbitMQ as a way to send messages from the command to the query. In the query service, I have an application class that registers to receive message from the queue and an event handler (in a separate class) that handles those messages and I was wondering the best way to unit test this code. I know Axon provides testing framework but I didn’t see a way to test having the event handler in a separate projects (distributed system).
Is there a way to mimic sending messages and test if the event handler is handling those message and if it’s doing what it’s suppose to be doing? or should i only be concerned with testing the event handler functionality?
below is my code:
`
@SpringBootApplication
public class IntegrationRunQueryApplication {
public static void main(String[] args) {
SpringApplication.run(IntegrationRunQueryApplication .class, args);
}
@Bean
public Serializer axonJsonSerializer() { return new JacksonSerializer();}
@Bean
public SpringAMQPMessageSource IntegrationsQueue(Serializer serializer){
return new SpringAMQPMessageSource(new DefaultAMQPMessageConverter(serializer)){
@RabbitListener(queues = "Integrations")
@Override
public void onMessage(Message message, Channel channel) throws Exception{
super.onMessage(message, channel);
}
};
}
}
`
`
@ProcessingGroup("IntegrationRun")
@Component
public class IntegrationRunListener {
private IntegrationRunRepository repository;
public IntegrationRunListener (){}
@Autowired
public IntegrationRunListener (IntegrationRunRepository repository){
this.repository = repository;
}
@EventHandler
public void onRunCreated(IntegrationRunCreatedEvent event){
repository.save(new IntegrationRunEntity(event.getGuid(), event.getIntegrationId(), event.getPartner(), event.getCategory(), event.getIntegrationRunDate()));
}
}
`
Thanks,
Amr.