I have the problem that the field in the abstract class "uitworpAggregateId" will not be found by the fixture method registerIgnoredField(). But the field "gebeurtenisId" is found.
Is this a bug or a feature.
I am testing with:
FixtureConfiguration<MyAggregate> fixture = new AggregateTestFixture(MyAggregate.class);
@Test
void myTest(){
fixture.registerIgnoredField(UitworpAggregateAanmakenEvent.class, "uitworpAggregateId");
}
Where the event classes are:
@EqualsAndHashCode
@Getter
@SuperBuilder(toBuilder = true)
@ToString
public abstract class AbstractUitworpAggregateEvent {
public UUID uitworpAggregateId;
public UUID myAggregateId;
}
@EqualsAndHashCode(callSuper = true)
@Getter
@Jacksonized
@SuperBuilder(toBuilder = true)
@ToString(callSuper = true)
public class UitworpAggregateAanmakenEvent extends AbstractUitworpAggregateEvent {
private final UUID gebeurtenisId;
}
spring boot version 3.4.1 axon version 4.10.4 java 21
It seams that in the class org.axonframework.test.matchers.IgnoreField
some methods does not loop correctly trough all the classes.
public IgnoreField(Class<?> clazz, String fieldName) {
try {
ignoredField = clazz.getDeclaredField(fieldName);
} catch (NoSuchFieldException e) {
throw new FixtureExecutionException("The given field does not exist", e);
}
}
In my case it would be corrected by changing
ignoredField = clazz.getDeclaredField(fieldName);
by
ignoredField = clazz.getSuperclass().getDeclaredField(fieldName);
Question to AxonIQ is this a correct finding?
Thanks Jan
1 Answer 1
The registerIgnoredField method takes two parameters, a Class and a String. The Class represents the declaring class of the field. The String is the name.
In your case, you have an event class extending an abstract class. Since the field is declared in the abstract parent class, you need to specify that class as the first parameter.
Instead of:
fixture.registerIgnoredField(UitworpAggregateAanmakenEvent.class, "uitworpAggregateId");
do:
fixture.registerIgnoredField(AbstractUitworpAggregateEvent.class, "uitworpAggregateId");
A recommendation in general: be careful when creating too much structure in your event classes. They are typically very flat. It's also perfectly fine to "repeat" certain fields in different events.
Eventually, structures are bound to change, and you'll have very complex modifications to do in your events to accommodate those changes.