We put javax validations on out command, and turned this on like:
commandBus.registerDispatchInterceptor(new BeanValidationInterceptor<>());
Now we would like to test that when a wrong command is created that an error is thrown. We try this by using the fixture:
Nu willen we ook graag testen dat als wij een foutief command aanmaken dat ook deze fout wordt gegooit. Dit proberen we zo:
AggregateTestFixture fixture = new AggregateTestFixture<>(Concept.class);
fixture.getCommandBus().registerDispatchInterceptor(new BeanValidationInterceptor<>());
fixture
.given(CREATED_EVENT)
.when(wrongCommand)
.expectException(JSR303ViolationException.class);
When we run this we see that an exception is throw but not in a way that our test is correct. Instead the Exception seems to break the test, while this is what we are trying ot test. We do get:
“org.axonframework.messaging.interceptors.JSR303ViolationException: One or more JSR303 constraints were violated:
property quantity in class replaceConcept must be between 1 and 999”
Does anyone have an idea what we are doing wrong or how we are able to test BeanValidationInterceptors neatly (not from our controllers)?
Cheers,
Bas