Skip to content

Commit ee9765f

Browse files
committed
Add ArchUnit example.
1 parent 85bd73e commit ee9765f

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed

jmolecules-example-archunit/pom.xml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>org.jmolecules.examples</groupId>
8+
<artifactId>jmolecules-examples</artifactId>
9+
<version>1.0.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>jmolecules-example-archunit</artifactId>
13+
<name>jMolecules Examples - ArchUnit</name>
14+
15+
<dependencies>
16+
17+
<dependency>
18+
<groupId>org.jmolecules</groupId>
19+
<artifactId>jmolecules-ddd</artifactId>
20+
</dependency>
21+
22+
<dependency>
23+
<groupId>org.jmolecules.integrations</groupId>
24+
<artifactId>jmolecules-archunit</artifactId>
25+
<scope>test</scope>
26+
</dependency>
27+
28+
<dependency>
29+
<groupId>com.tngtech.archunit</groupId>
30+
<artifactId>archunit-junit5</artifactId>
31+
<version>${archunit.version}</version>
32+
<scope>test</scope>
33+
</dependency>
34+
35+
<dependency>
36+
<groupId>org.junit.jupiter</groupId>
37+
<artifactId>junit-jupiter</artifactId>
38+
<scope>test</scope>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>org.assertj</groupId>
43+
<artifactId>assertj-core</artifactId>
44+
<scope>test</scope>
45+
</dependency>
46+
47+
</dependencies>
48+
49+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package example;
2+
3+
import org.jmolecules.ddd.types.AggregateRoot;
4+
import org.jmolecules.ddd.types.Identifier;
5+
6+
public class MyAggregateRoot implements AggregateRoot<MyAggregateRoot, Identifier> {
7+
8+
MyAggregateRoot aggregate;
9+
10+
@Override
11+
public Identifier getId() {
12+
return null;
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package example;
17+
18+
import static org.assertj.core.api.Assertions.*;
19+
20+
import org.jmolecules.archunit.JMoleculesDddRules;
21+
22+
import com.tngtech.archunit.core.domain.JavaClasses;
23+
import com.tngtech.archunit.junit.AnalyzeClasses;
24+
import com.tngtech.archunit.junit.ArchTest;
25+
26+
@AnalyzeClasses(packagesOf = MyAggregateRoot.class)
27+
class ArchitectureTests {
28+
29+
@ArchTest
30+
void detectsArchitectureViolation(JavaClasses classes) {
31+
32+
var violations = JMoleculesDddRules.all().evaluate(classes);
33+
34+
assertThat(violations.getFailureReport().getDetails()).hasSize(1)
35+
.element(0).asString()
36+
.contains("Field", "aggregate", "Association");
37+
}
38+
}

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<modules>
1414
<module>jmolecules-axon</module>
1515
<module>jmolecules-ddd-apt</module>
16+
<module>jmolecules-example-archunit</module>
1617
<module>jmolecules-kotlin</module>
1718
<module>jmolecules-presentation</module>
1819
<module>jmolecules-spring-data-jdbc</module>

0 commit comments

Comments
 (0)