Search in sources :

Example 31 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project SORMAS-Project by hzi-braunschweig.

the class DatabaseExportServiceTest method test_all_entities_have_export_configuration.

@Test
public void test_all_entities_have_export_configuration() {
    Collection<String> exportableTables = DatabaseExportService.EXPORT_CONFIGS.values();
    Set<String> missingEntities = new HashSet<>();
    Set<String> exportedButNotWanted = new HashSet<>();
    JavaClasses classes = new ClassFileImporter().importPackages("de.symeda.sormas.backend");
    for (JavaClass clazz : classes) {
        if (clazz.isAnnotatedWith(Entity.class)) {
            Entity entityAnnotation = clazz.getAnnotationOfType(Entity.class);
            String tableName = entityAnnotation.name();
            if (StringUtils.isBlank(tableName)) {
                tableName = clazz.getSimpleName().toLowerCase();
            }
            if (!exportableTables.contains(tableName)) {
                missingEntities.add(clazz.getSimpleName());
            } else if (NOT_EXPORTED_ENTITIES.contains(clazz.reflect())) {
                exportedButNotWanted.add(clazz.getSimpleName());
            }
        }
    }
    // remove not exported entities from the list of missing ones
    NOT_EXPORTED_ENTITIES.forEach(e -> missingEntities.remove(e.getSimpleName()));
    assertThat("Missing export configuration for entities [" + String.join(", ", missingEntities) + "]", missingEntities, hasSize(0));
    assertThat("Export configuration not wanted for entities [" + String.join(", ", exportedButNotWanted) + "]", exportedButNotWanted, hasSize(0));
}
Also used : Entity(javax.persistence.Entity) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) JavaClass(com.tngtech.archunit.core.domain.JavaClass) HashSet(java.util.HashSet) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Example 32 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project auth0-full-stack-java-example by oktadev.

the class ArchTest method servicesAndRepositoriesShouldNotDependOnWebLayer.

@Test
void servicesAndRepositoriesShouldNotDependOnWebLayer() {
    JavaClasses importedClasses = new ClassFileImporter().withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS).importPackages("com.auth0.flickr2");
    noClasses().that().resideInAnyPackage("com.auth0.flickr2.service..").or().resideInAnyPackage("com.auth0.flickr2.repository..").should().dependOnClassesThat().resideInAnyPackage("..com.auth0.flickr2.web..").because("Services and repositories should not depend on web layer").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 33 with ClassFileImporter

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

the class ArchitecturesTest method layered_architecture_allows_individual_empty_optionalLayer.

@Test
public void layered_architecture_allows_individual_empty_optionalLayer() {
    LayeredArchitecture architecture = layeredArchitecture().optionalLayer("can be absent").definedBy(absolute("should.not.be.found.."));
    JavaClasses classes = new ClassFileImporter().importPackages(absolute(""));
    EvaluationResult result = architecture.evaluate(classes);
    assertThat(result.hasViolation()).as("result of evaluating empty optionalLayer has violation").isFalse();
    assertThat(result.getFailureReport().isEmpty()).as("failure report").isTrue();
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) LayeredArchitecture(com.tngtech.archunit.library.Architectures.LayeredArchitecture) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Example 34 with ClassFileImporter

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

the class ArchitecturesTest method onion_architecture_rejects_empty_layers_by_default.

@Test
public void onion_architecture_rejects_empty_layers_by_default() {
    OnionArchitecture architecture = anOnionArchitectureWithEmptyLayers();
    JavaClasses classes = new ClassFileImporter().importPackages(absolute("onionarchitecture"));
    EvaluationResult result = architecture.evaluate(classes);
    assertFailureOnionArchitectureWithEmptyLayers(result);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) OnionArchitecture(com.tngtech.archunit.library.Architectures.OnionArchitecture) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Example 35 with ClassFileImporter

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

the class ArchitecturesTest method layered_architecture_allows_empty_layers_if_all_layers_are_optional.

@Test
public void layered_architecture_allows_empty_layers_if_all_layers_are_optional() {
    LayeredArchitecture architecture = aLayeredArchitectureWithEmptyLayers().withOptionalLayers(true);
    assertThat(architecture.getDescription()).startsWith("Layered architecture consisting of (optional)");
    JavaClasses classes = new ClassFileImporter().importPackages(absolute(""));
    assertThatRule(architecture).checking(classes).hasNoViolation();
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) LayeredArchitecture(com.tngtech.archunit.library.Architectures.LayeredArchitecture) 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