use of com.tngtech.archunit.core.importer.ClassFileImporter in project archifacts by archifacts.
the class C4ModelBuilderTest method assert_that_referenced_artifacts_are_not_added_automatically.
@Test
void assert_that_referenced_artifacts_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.getBuildingBlocksOfType(buildingBlockType1).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(1).extracting(Component::getName, Component::getTechnology).containsExactly(tuple("Class1ForBuildingBlockType1", "BuildingBlockType1"));
}
use of com.tngtech.archunit.core.importer.ClassFileImporter in project archifacts by archifacts.
the class C4ModelBuilderTest method assert_that_computation_rule_is_applied_to_artifact.
@Test
void assert_that_computation_rule_is_applied_to_artifact() {
final JavaClasses javaClasses = new ClassFileImporter().importPackages("org.archifacts.integration.c4.model.domain");
final Application application = Application.builder().descriptor(buildingBlockType1Descriptor).descriptor(defaultContainerDescriptor).buildApplication(javaClasses);
final C4ModelBuilder c4ModelBuilder = C4Model.builder(new Workspace(this.getClass().getSimpleName(), null));
final Set<ArtifactContainer> artifactContainers = application.getContainersOfType(containerType1);
assertThat(artifactContainers).hasSize(1);
final ArtifactContainer defaultContainer = artifactContainers.iterator().next();
application.getBuildingBlocksOfType(buildingBlockType1).forEach(c4ModelBuilder::artifact);
c4ModelBuilder.artifactRule().predicate(artifact -> artifact.getName().equals("Class1ForBuildingBlockType1")).computation((artifact, lookup) -> Set.of(lookup.container(defaultContainer).addComponent("CustomName1", null, "CustomTechnology1"), lookup.container(defaultContainer).addComponent("CustomName2", null, "CustomTechnology2")));
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("CustomName1", "CustomTechnology1"), tuple("CustomName2", "CustomTechnology2"));
}
use of com.tngtech.archunit.core.importer.ClassFileImporter in project jhipster-architectural-comparison by SelimHorri.
the class ArchTest method servicesAndRepositoriesShouldNotDependOnWebLayer.
@Test
void servicesAndRepositoriesShouldNotDependOnWebLayer() {
JavaClasses importedClasses = new ClassFileImporter().withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS).importPackages("com.selim.pack");
noClasses().that().resideInAnyPackage("com.selim.pack.service..").or().resideInAnyPackage("com.selim.pack.repository..").should().dependOnClassesThat().resideInAnyPackage("..com.selim.pack.web..").because("Services and repositories should not depend on web layer").check(importedClasses);
}
use of com.tngtech.archunit.core.importer.ClassFileImporter in project micrometer by micrometer-metrics.
the class JvmGcMetricsTest method noJvmImplementationSpecificApiSignatures.
@Test
void noJvmImplementationSpecificApiSignatures() {
JavaClasses importedClasses = new ClassFileImporter().importPackages("io.micrometer.core.instrument.binder.jvm");
ArchRule noSunManagementInMethodSignatures = methods().should().notHaveRawReturnType(resideInAPackage("com.sun.management..")).andShould().notHaveRawParameterTypes(DescribedPredicate.anyElementThat(resideInAPackage("com.sun.management..")));
noSunManagementInMethodSignatures.check(importedClasses);
}
use of com.tngtech.archunit.core.importer.ClassFileImporter in project conjob by ScottG489.
the class ArchUnitTest method coreLibraryShouldOnlyDependOnItself.
@Test
@DisplayName("Given a class in the core library, " + "when it depends on another class, " + "then the dependency should be in the core library, " + "or the dependency should be an external dependency.")
public void coreLibraryShouldOnlyDependOnItself() {
JavaClasses importedClasses = new ClassFileImporter().importPackages("conjob..");
classes().that().resideInAPackage("conjob.core..").should().onlyDependOnClassesThat(resideInAPackage("conjob.core..").or(doNot(resideInAPackage("conjob..")))).because("lower level libraries shouldn't have dependencies higher level ones.").check(importedClasses);
}
Aggregations