I would like to test an external Axon command-handler. It’s getting via constructor DI an Axon-Repository.
This test-case should be as minimalistic and fast, as possible. It should test, whether on a given command, given Events were executed.
class QualificationCommandHandlingTests {
private val fixture = AggregateTestFixture(CreateQualificationHandler::class.java)
@Test
fun `Test Qualification Command Handling`() {
val uuid = UUID.randomUUID()
val title = "New Qualification"
fixture
.given()
.`when`(CreateQualification(uuid.toString(), title))
.expectSuccessfulHandlerExecution()
.expectEvents(QualificationCreated(uuid, title))
}
}
@Component
class CreateQualificationHandler(val qualificationRepository: Repository<Qualification>) {
@CommandHandler
fun handle(createQualification: CreateQualification) {
qualificationRepository.newInstance {
Qualification.create(UUID.fromString(createQualification.uuid), createQualification.title)
}
}
}
Problem is, that whe are developing axon in a spring env, so the external command-handlers get injected with spring beans. (for example, the repo).
-
Problem: Given test case is failing, because axon is expecting an empty constructor. Is it possible, to inject the necessary dependencies myself, without creating a spring boot test?
-
What would be the minimalistic approach to test simple “event has been thrown as a result of command on aggregate” in a spring env? How could I mock in this layer, the necessary dependencies, as minimalistic, as possible?