GH-601 - Support for wildcard references to named interfaces in explicitly defined allowed application module dependencies.
When defining allowed application module dependencies to named interfaces, the asterisk can now be used to allow referencing all named interfaces declared by the target module.
This commit is contained in:
@@ -16,16 +16,18 @@
|
||||
package org.springframework.modulith.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import example.ni.api.ApiType;
|
||||
import example.ni.spi.SpiType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.jupiter.api.DynamicTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
||||
import org.springframework.modulith.core.ApplicationModule.DeclaredDependency;
|
||||
|
||||
import com.acme.withatbean.SampleAggregate;
|
||||
import com.acme.withatbean.TestEvents.JMoleculesAnnotated;
|
||||
@@ -85,13 +87,25 @@ class ModuleUnitTest {
|
||||
.<Class<?>> extracting(JavaClass::reflect)
|
||||
.containsExactly(SampleAggregate.class);
|
||||
}
|
||||
|
||||
|
||||
@Test // GH-319
|
||||
void containsPackage() {
|
||||
|
||||
void containsPackage() {
|
||||
|
||||
assertThat(module.containsPackage(packageName)).isTrue();
|
||||
assertThat(module.containsPackage(packageName + ".foo")).isTrue();
|
||||
|
||||
|
||||
assertThat(module.containsPackage(packageName + "foo")).isFalse();
|
||||
}
|
||||
|
||||
@Test // GH-601
|
||||
void wildcardedDeclaredDependencyAllowsDependenciesToAllNamedInterfaces() {
|
||||
|
||||
var modules = TestUtils.of("example", "example.ninvalid");
|
||||
|
||||
var module = modules.getModuleByName("ni").orElseThrow();
|
||||
var dependency = DeclaredDependency.of("ni :: *", module, modules);
|
||||
|
||||
assertThat(dependency.contains(SpiType.class)).isTrue();
|
||||
assertThat(dependency.contains(ApiType.class)).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.modulith.core;
|
||||
|
||||
import static com.tngtech.archunit.core.domain.JavaClass.Predicates.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.jmolecules.ddd.annotation.AggregateRoot;
|
||||
@@ -28,6 +29,7 @@ import com.tngtech.archunit.base.DescribedPredicate;
|
||||
import com.tngtech.archunit.core.domain.JavaClass;
|
||||
import com.tngtech.archunit.core.domain.JavaClasses;
|
||||
import com.tngtech.archunit.core.importer.ClassFileImporter;
|
||||
import com.tngtech.archunit.core.importer.ImportOption;
|
||||
|
||||
/**
|
||||
* Utilities for testing.
|
||||
@@ -77,6 +79,10 @@ class TestUtils {
|
||||
return JavaPackage.of(TestUtils.getClasses(packageType), packageType.getPackageName());
|
||||
}
|
||||
|
||||
public static ApplicationModules of(String basePackage, String... ignoredPackages) {
|
||||
return of(ModulithMetadata.of(basePackage), basePackage, JavaClass.Predicates.resideInAnyPackage(ignoredPackages));
|
||||
}
|
||||
|
||||
public static ApplicationModule getApplicationModule(String packageName) {
|
||||
return new ApplicationModule(getPackage(packageName), false);
|
||||
}
|
||||
@@ -92,4 +98,10 @@ class TestUtils {
|
||||
return Classes.of(new ClassFileImporter()
|
||||
.importPackages(packageName));
|
||||
}
|
||||
|
||||
private static ApplicationModules of(ModulithMetadata metadata, String basePackage,
|
||||
DescribedPredicate<JavaClass> ignores) {
|
||||
return new ApplicationModules(metadata, List.of(basePackage), ignores, false,
|
||||
new ImportOption.OnlyIncludeTests()) {};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user