Skip to content

Commit 4912e7d

Browse files
committed
chore: add archUnit to sticker-award
1 parent 572881f commit 4912e7d

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

sticker-award/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@
121121
<artifactId>mockito-core</artifactId>
122122
<scope>test</scope>
123123
</dependency>
124+
125+
<!-- ArchUnit for architecture testing -->
126+
<dependency>
127+
<groupId>com.tngtech.archunit</groupId>
128+
<artifactId>archunit-junit5</artifactId>
129+
<version>1.3.0</version>
130+
<scope>test</scope>
131+
</dependency>
124132
</dependencies>
125133

126134
<build>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.datadoghq.stickerlandia.stickeraward;
2+
3+
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
4+
5+
import com.tngtech.archunit.core.domain.JavaClasses;
6+
import com.tngtech.archunit.core.importer.ClassFileImporter;
7+
import com.tngtech.archunit.lang.ArchRule;
8+
import org.junit.jupiter.api.Test;
9+
10+
/**
11+
* ArchUnit tests to validate architectural rules based on the CodeQL arch tests. These tests ensure
12+
* domain boundaries are respected and REST API classes don't directly import entity types.
13+
*/
14+
public class ArchitectureTest {
15+
16+
private static final JavaClasses classes =
17+
new ClassFileImporter().importPackages("com.datadoghq.stickerlandia.stickeraward");
18+
19+
/**
20+
* Cross-Domain Boundary Violations. Based on cross-domain-issues.ql Ensures sticker and award
21+
* domains don't import from each other.
22+
*/
23+
@Test
24+
void sticker_domain_should_not_import_award_domain() {
25+
ArchRule rule =
26+
noClasses()
27+
.that()
28+
.resideInAPackage("..sticker..")
29+
.should()
30+
.dependOnClassesThat()
31+
.resideInAPackage("..award..")
32+
.because(
33+
"Sticker domain should not import from award domain.");
34+
35+
rule.check(classes);
36+
}
37+
38+
@Test
39+
void award_domain_should_not_import_sticker_domain() {
40+
ArchRule rule =
41+
noClasses()
42+
.that()
43+
.resideInAPackage("..award..")
44+
.should()
45+
.dependOnClassesThat()
46+
.resideInAPackage("..sticker..")
47+
.because(
48+
"Award domain should not import from sticker domain.");
49+
50+
rule.check(classes);
51+
}
52+
53+
/**
54+
* REST API classes should not import entity types. Based on rest-api-no-entities.ql and
55+
* rest-api-imports-simple.ql Ensures REST resources don't directly use entity classes.
56+
*/
57+
@Test
58+
void rest_api_should_not_import_entities() {
59+
ArchRule rule =
60+
noClasses()
61+
.that()
62+
.haveSimpleNameEndingWith("Resource")
63+
.should()
64+
.dependOnClassesThat()
65+
.resideInAPackage("..entity..")
66+
.because(
67+
"REST API classes should not import entity types.");
68+
69+
rule.check(classes);
70+
}
71+
}

0 commit comments

Comments
 (0)