-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add archunit tests with default rules (#355)
feat(archunit): Add archunit tests with default rules some as warnings.
- Loading branch information
1 parent
3329c98
commit ac329d0
Showing
17 changed files
with
402 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...main/java/co/com/bancolombia/factory/validations/architecture/ArchitectureValidation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package co.com.bancolombia.factory.validations.architecture; | ||
|
||
import co.com.bancolombia.Constants; | ||
import co.com.bancolombia.factory.ModuleBuilder; | ||
import co.com.bancolombia.utils.FileUtils; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import lombok.SneakyThrows; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.artifacts.Configuration; | ||
import org.gradle.api.artifacts.ResolvedDependency; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class ArchitectureValidation { | ||
|
||
public static void inject(Project project, ModuleBuilder builder) { | ||
if (!FileUtils.readBooleanProperty("skipArchitectureTests")) { | ||
builder.addParam("reactive", builder.isReactive()); | ||
project.getAllprojects().stream() | ||
.filter(p -> p.getName().equals("app-service")) | ||
.findFirst() | ||
.ifPresent(appService -> generateArchUnitFiles(project, appService, builder)); | ||
} | ||
} | ||
|
||
private static void prepareParams(Project project, Project appService, ModuleBuilder builder) { | ||
Map<String, Boolean> deps = new TreeMap<>(); | ||
appService.getConfigurations().stream() | ||
.filter(Configuration::isCanBeResolved) | ||
.flatMap(c -> c.getResolvedConfiguration().getFirstLevelModuleDependencies().stream()) | ||
.forEach(dependency -> fillDependencyTree(deps, dependency)); | ||
boolean hasSpringWeb = deps.containsKey("org.springframework:spring-web"); | ||
project.getLogger().debug("hasSpringWeb: {}", hasSpringWeb); | ||
builder.addParam("hasSpringWeb", hasSpringWeb); | ||
} | ||
|
||
private static void fillDependencyTree(Map<String, Boolean> deps, ResolvedDependency dependency) { | ||
deps.put(dependency.getModuleGroup() + ":" + dependency.getName(), true); | ||
dependency.getChildren().forEach(dep -> fillDependencyTree(deps, dep)); | ||
} | ||
|
||
@SneakyThrows | ||
private static void generateArchUnitFiles( | ||
Project project, Project appService, ModuleBuilder builder) { | ||
prepareParams(project, appService, builder); | ||
project | ||
.getLogger() | ||
.lifecycle("Injecting ArchitectureTest in module {}", appService.getProjectDir().getName()); | ||
builder.setupFromTemplate("structure/applications/appservice/arch-validations"); | ||
builder.appendDependencyToModule( | ||
"app-service", | ||
"testImplementation 'com.tngtech.archunit:archunit:" + Constants.ARCH_UNIT_VERSION + "'"); | ||
builder.persist(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/main/resources/structure/applications/appservice/arch-validations/.gitignore.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ArchitectureTest.java |
Oops, something went wrong.