jhipster-lite icon indicating copy to clipboard operation
jhipster-lite copied to clipboard

Hexagonal Arch: add new test - secondary can call primary from another context

Open pascalgrimaud opened this issue 2 years ago • 7 comments

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;

pascalgrimaud avatar Aug 04 '22 06:08 pascalgrimaud

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.

DamnClin avatar Aug 04 '22 06:08 DamnClin

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

pascalgrimaud avatar Aug 04 '22 06:08 pascalgrimaud

Yep

DamnClin avatar Aug 04 '22 06:08 DamnClin

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

pascalgrimaud avatar Aug 04 '22 06:08 pascalgrimaud

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

DamnClin avatar Aug 04 '22 06:08 DamnClin

maybe the test could ensure that only primary classes containing Java could be called from a secondary package?

hdurix avatar Aug 04 '22 07:08 hdurix

Adding a bounty as it's more work than expected, and need to think deeply to provide the good solution here

pascalgrimaud avatar Sep 14 '22 16:09 pascalgrimaud