Closed tkachenkoas closed 2 years ago
and then I'll be a sneaky hacker: I won't inject anything from Service into Storage - I'll just create
new ClassFromServiceLayerThatIsNotIntededForPublicUsage()
- but it seems that I shouldn't be allowed to do so
Can you elaborate on what you are doing here? Where is this class located? What types in which packages does it refer to etc.?
so, I'm in "storage" layer - com.myapp.storage.CommentsDAO, ['Storage' module], and suddenly I decide that I want to use com.myapp.service.CommentsServiceNotifierUtils#someStaticHelperMethod that happens to be public in 'Service' module
according to my definition of modules, I should not be able to access service module from storage module (but it's ok to access storage from service).
in java 9 modules, my code wouldn't compile - but for Modulith I'd expect @ModuleTest of 'Storage' module to fail because one of classes imports a class from module that it's not supposed to depend on
I guess, providing a example with code would be more clear :) if this is still not good enough, I'll push some example code/PR with a test that I expect to fail :)
I think it would indeed be helpful to see a running example. An arrangement of types that you expect a validation would detect as invalid.
Just to make sure: note, that Moduliths doesn't capture violations at compile time. You either need to run an @ModuleTest
or explicitly call Modules.of(…).verify()
;
@odrotbohm
sorry, my bad. can't exactly reproduce the state that I had earlier - but once I created simple project and configured some violations, I managed to have failed tests according to my expectations https://github.com/tkachenkoas/modulith-modules-playground/runs/4873831161?check_suite_focus=true
Hi Oliver
I've been playing a bit with modulith (in demo salespoint app), and I still not 100% understand what behavior I should expect :) I only managed to catch failures when components from not allowed modules are injected, but not when classes are used directly.
so, my use case is this: first, I define modules:
@org.moduliths.Module(displayName = "Storage") package com.myapp.storage @org.moduliths.Module(displayName = "Service", allowedDependencies = "com.myapp.storage") package com.myapp.service
and then I'll be a sneaky hacker: I won't inject anything from Service into Storage - I'll just create
new ClassFromServiceLayerThatIsNotIntededForPublicUsage()
- but it seems that I shouldn't be allowed to do soam I missing some config, or this feature is missing? seems that ArchUnit provides quite a simple way to verify it. Is it in your roadmap?