Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArchUnit verification fails for annotated aggregate references as collection elements #253

Closed
etrandafir93 opened this issue Aug 2, 2024 · 1 comment
Assignees
Labels
Milestone

Comments

@etrandafir93
Copy link
Contributor

etrandafir93 commented Aug 2, 2024

When it comes to validating the annotated classes, JMoleculesDddRules fails to catch the violation for an aggregate referencing a Collection of other aggregates as shown below:

@AggregateRoot 
class AnnotatedAggregate { ... }

@AggregateRoot
class OtherAnnotatedAggregate {
    AnnotatedAggregate invalidAnnotatedAggregate; // <-- throws violation (correct)
    Collection<AnnotatedAggregate> invalidAnnotatedAggregateInCollection; // <-- doesn't throw violation (not correct)
}

Reproduced in tests, here.

PS: this works ok for the interfaces, and only fails with the annotations. Also, I believe it can be interesting to have that same test/assertions run against two set of objects (one using the interfaces and its equivalent that uses annotations).

If the project is open for contributions, I wouldn't mind looking into it.


Later edit: This rule also seems to be skipped when it comes to annotated objects: Aggregates only refer to entities that are declared to be part of it.

Example here:

@AggregateRoot
static class SomeAnnotatedAggregate {
    // ...
    AnnotatedEntity valid;
}

@AggregateRoot
static class OtherAnnotatedAggregate {
    AnnotatedEntity invalidAnnotatedEntity; // <-- doesn't throw violation (not correct)
    Collection<AnnotatedEntity> invalidAnnoatedEntityInCollection; // <-- doesn't throw violation (not correct)
}

I have added these failing test cases to my branch and created PR (#254) for visibility:
#254

@odrotbohm odrotbohm self-assigned this Aug 23, 2024
@odrotbohm odrotbohm added the type: bug Bug label Aug 23, 2024
@odrotbohm odrotbohm added this to the 0.22 milestone Aug 23, 2024
odrotbohm pushed a commit that referenced this issue Aug 29, 2024
@odrotbohm odrotbohm changed the title JMoleculesDddRules fails to catch violation for annotated classes ArchUnit verification fails for annotated aggregate references as collection elements Aug 29, 2024
@odrotbohm
Copy link
Member

I've applied the addition for the collection element verification. For the entity verification, please refer to my comment on the PR.

odrotbohm pushed a commit that referenced this issue Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants