Search in sources :

Example 81 with ClassFileImporter

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

the class C4ModelBuilderTest method assert_that_relationships_are_not_added_automatically.

@Test
void assert_that_relationships_are_not_added_automatically() {
    final JavaClasses javaClasses = new ClassFileImporter().importPackages("org.archifacts.integration.c4.model.domain");
    final Application application = Application.builder().descriptor(buildingBlockType1Descriptor).descriptor(defaultContainerDescriptor).descriptor(referenceDescriptor).buildApplication(javaClasses);
    final C4ModelBuilder c4ModelBuilder = C4Model.builder(new Workspace(this.getClass().getSimpleName(), null));
    application.getArtifacts().stream().forEach(c4ModelBuilder::artifact);
    final C4Model c4Model = c4ModelBuilder.build();
    final Set<Container> containers = c4Model.softwareSystem().getContainers();
    assertThat(containers).hasSize(1).extracting(Container::getName, Container::getTechnology).containsExactly(tuple("DefaultContainer", "ContainerType1"));
    final Set<Component> components = containers.iterator().next().getComponents();
    assertThat(components).hasSize(2).extracting(Component::getName, Component::getTechnology).containsExactlyInAnyOrder(tuple("Class1ForBuildingBlockType1", "BuildingBlockType1"), tuple("MiscArtifact1", "Misc"));
    assertThat(components).flatMap(Component::getRelationships).isEmpty();
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ArtifactContainer(org.archifacts.core.model.ArtifactContainer) Container(com.structurizr.model.Container) Component(com.structurizr.model.Component) Application(org.archifacts.core.model.Application) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Workspace(com.structurizr.Workspace) Test(org.junit.jupiter.api.Test)

Example 82 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project checkstyle-backport-jre8 by rnveach.

the class ArchUnitTest method nonProtectedCheckMethodsTest.

/**
 * The goal is to ensure all classes of a specific name pattern have non-protected methods,
 * except for those which are annotated with {@code Override}. In the bytecode there is no
 * trace anymore if this method was annotated with {@code Override} or not (limitation of
 * Archunit), eventually we need to make checkstyle's Check on this.
 * Test contains assertions in the callstack, but TeamCity inspection does not see them.
 *
 * @noinspection JUnitTestMethodWithNoAssertions
 */
@Test
public void nonProtectedCheckMethodsTest() {
    // This list contains methods which have been overridden and are set to ignore in this test.
    final String[] methodsWithOverrideAnnotation = { "processFiltered", "getMethodName", "mustCheckName", "postProcessHeaderLines", "getLogMessageId" };
    final String ignoreMethodList = String.join("|", methodsWithOverrideAnnotation);
    final JavaClasses importedClasses = new ClassFileImporter().withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS).importPackages("com.puppycrawl.tools.checkstyle.checks");
    final ArchRule checkMethodsShouldNotBeProtectedRule = methods().that().haveNameNotMatching(".*(" + ignoreMethodList + ")").and().areDeclaredInClassesThat().haveSimpleNameEndingWith("Check").and().areDeclaredInClassesThat().doNotHaveModifier(JavaModifier.ABSTRACT).should().notBeProtected();
    checkMethodsShouldNotBeProtectedRule.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 83 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project giskard by Giskard-AI.

the class ArchTest method servicesAndRepositoriesShouldNotDependOnWebLayer.

@Test
void servicesAndRepositoriesShouldNotDependOnWebLayer() {
    JavaClasses importedClasses = new ClassFileImporter().withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS).importPackages("ai.giskard");
    noClasses().that().resideInAnyPackage("ai.giskard.service..").or().resideInAnyPackage("ai.giskard.repository..").should().dependOnClassesThat().resideInAnyPackage("..ai.giskard.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 84 with ClassFileImporter

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

the class CdcPostgresSerializableTest method serializable_classes_should_have_valid_serialVersionUID.

@Test
public void serializable_classes_should_have_valid_serialVersionUID() {
    String basePackage = PostgresCdcSources.class.getPackage().getName();
    JavaClasses classes = new ClassFileImporter().withImportOption(onlyCurrentModule()).importPackages(basePackage);
    ArchUnitRules.SERIALIZABLE_SHOULD_HAVE_VALID_SERIAL_VERSION_UID.check(classes);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Test(org.junit.Test)

Example 85 with ClassFileImporter

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

the class PythonSerializableTest method serializable_classes_should_have_valid_serialVersionUID.

@Test
public void serializable_classes_should_have_valid_serialVersionUID() {
    String basePackage = PythonServiceConfig.class.getPackage().getName();
    JavaClasses classes = new ClassFileImporter().withImportOption(onlyCurrentModule()).importPackages(basePackage);
    ArchUnitRules.SERIALIZABLE_SHOULD_HAVE_VALID_SERIAL_VERSION_UID.check(classes);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) 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