jhipster-lite
jhipster-lite copied to clipboard
Hexagonal Arch: add new test - secondary can call primary from another context
I'm trying to improve the HexagonalArchTest
and I saw this issue.
In FileSystemJHipsterModulesRepository
which is in secondary
, we import a class from primary
. We should use a port instead I think. Can you have a look and suggest a fix plz @DamnClin ?
package tech.jhipster.lite.module.infrastructure.secondary;
import org.springframework.stereotype.Repository;
import tech.jhipster.lite.error.domain.Assert;
import tech.jhipster.lite.module.domain.JHipsterModuleApplied;
import tech.jhipster.lite.module.domain.JHipsterModuleChanges;
import tech.jhipster.lite.module.domain.JHipsterModulesRepository;
import tech.jhipster.lite.module.domain.postaction.JHipsterModuleExecutionContext;
import tech.jhipster.lite.npm.domain.NpmVersions;
import tech.jhipster.lite.project.infrastructure.primary.JavaProjects; // <--- should not import a primary here
import tech.jhipster.lite.projectfile.domain.ProjectFilesReader;
This is not a bug, it's totally fine! A secondary from one context can call a primary from another context. Here we are doing a java adaptation.
Oh I see, tell me if I'm correct:
- a secondary can't call a primary from the same context
- a secondary can call a primary from another context
Yep
Then, I'm changing the ticket, because I wonder if we could write an arch unit test for that, I think it should not be so easy
I think it's not really hard to do, loop other the context packages and ensure that the secondary package have no dependency to the primary one
maybe the test could ensure that only primary classes containing Java
could be called from a secondary package?
Adding a bounty as it's more work than expected, and need to think deeply to provide the good solution here