Search in sources :

Example 96 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project jhipster-lite by jhipster.

the class HexagonalArchTest method applicationShouldNotInteractWithSecondary.

@Test
void applicationShouldNotInteractWithSecondary() {
    JavaClasses importedClasses = new ClassFileImporter().withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS).importPackages("tech.jhipster.lite");
    noClasses().that().resideInAnyPackage("..application..").should().dependOnClassesThat().resideInAnyPackage("..secondary..").because("Application should not interact with secondary").check(importedClasses);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.jupiter.api.Test)

Example 97 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project jhipster-lite by jhipster.

the class AnnotationArchTest method shouldHaveUnitTestAnnotation.

@Test
void shouldHaveUnitTestAnnotation() {
    JavaClasses importedClasses = new ClassFileImporter().importPackages("tech.jhipster.lite").that(are(not(equivalentTo(UnitTest.class)).and(not(equivalentTo(IntegrationTest.class)))));
    ArchRule rule = classes().that().resideInAnyPackage("tech.jhipster.lite..").and().haveSimpleNameEndingWith("Test").should().beAnnotatedWith(UnitTest.class).orShould().beAnnotatedWith(ComponentTest.class).orShould().beAnnotatedWith(Nested.class).orShould().beInterfaces();
    rule.check(importedClasses);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.jupiter.api.Test)

Example 98 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project jhipster-lite by jhipster.

the class AnnotationArchTest method shouldHaveGeneratorStepAnnotationInResources.

@Test
void shouldHaveGeneratorStepAnnotationInResources() {
    JavaClasses importedClasses = new ClassFileImporter().importPackages("tech.jhipster.lite");
    ArchRule rule = methods().that().areDeclaredInClassesThat().resideInAnyPackage("tech.jhipster.lite.generator..").and().areDeclaredInClassesThat().areAnnotatedWith(RestController.class).and().areAnnotatedWith(PostMapping.class).should().beAnnotatedWith(GeneratorStep.class);
    rule.check(importedClasses);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.jupiter.api.Test)

Example 99 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.

the class SecurityTest method only_security_infrastructure_should_use_java_security_on_whole_classpath.

@Test
public void only_security_infrastructure_should_use_java_security_on_whole_classpath() {
    ArchRule rule = classes().that().resideInAPackage("java.security.cert..").should().onlyBeAccessed().byAnyPackage("..example.layers.security..", "java..", "..sun..", "javax..", "apple.security..", "org.jcp..");
    JavaClasses classes = new ClassFileImporter().importClasspath(onlyAppAndRuntime());
    rule.check(classes);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Example 100 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.

the class SecurityTest method only_security_infrastructure_should_use_java_security.

@Test
public void only_security_infrastructure_should_use_java_security() {
    ArchRule rule = classes().that().resideInAPackage("java.security..").should().onlyBeAccessed().byAnyPackage("..example.layers.security..", "java.security..").because("we want to have one isolated cross-cutting concern 'security'");
    JavaClasses classes = new ClassFileImporter().importPackages("com.tngtech.archunit.example.layers", "java.security");
    rule.check(classes);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Aggregations

ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)136 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)98 Test (org.junit.Test)76 Test (org.junit.jupiter.api.Test)52 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)15 JavaClass (com.tngtech.archunit.core.domain.JavaClass)14 EvaluationResult (com.tngtech.archunit.lang.EvaluationResult)13 Workspace (com.structurizr.Workspace)12 ArchRule (com.tngtech.archunit.lang.ArchRule)12 Application (org.archifacts.core.model.Application)12 Component (com.structurizr.model.Component)10 Container (com.structurizr.model.Container)10 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)10 ArtifactContainer (org.archifacts.core.model.ArtifactContainer)10 JavaPackage (com.tngtech.archunit.core.domain.JavaPackage)5 LayeredArchitecture (com.tngtech.archunit.library.Architectures.LayeredArchitecture)5 OnionArchitecture (com.tngtech.archunit.library.Architectures.OnionArchitecture)5 Optional (java.util.Optional)5 Artifact (org.archifacts.core.model.Artifact)5 MiscArtifact (org.archifacts.core.model.MiscArtifact)5