use of com.tngtech.archunit.core.domain.JavaClasses 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.domain.JavaClasses 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.domain.JavaClasses 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.domain.JavaClasses 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);
}
use of com.tngtech.archunit.core.domain.JavaClasses 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));
}
Aggregations