add ArchUnitTest
This commit is contained in:
parent
2ac476d99b
commit
142aac2bce
@ -44,6 +44,7 @@ dependencies {
|
|||||||
testImplementation 'org.testcontainers:testcontainers'
|
testImplementation 'org.testcontainers:testcontainers'
|
||||||
testImplementation 'org.testcontainers:junit-jupiter'
|
testImplementation 'org.testcontainers:junit-jupiter'
|
||||||
testImplementation 'org.testcontainers:postgresql'
|
testImplementation 'org.testcontainers:postgresql'
|
||||||
|
testImplementation 'com.tngtech.archunit:archunit-junit5:1.0.0-rc1'
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencyManagement {
|
dependencyManagement {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package net.hostsharing.hsadminng.hscustomer;
|
package net.hostsharing.hsadminng.hscustomer;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -0,0 +1,67 @@
|
|||||||
|
package net.hostsharing.hsadminng.arch;
|
||||||
|
|
||||||
|
import com.tngtech.archunit.junit.AnalyzeClasses;
|
||||||
|
import com.tngtech.archunit.junit.ArchTest;
|
||||||
|
import com.tngtech.archunit.lang.ArchRule;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
|
||||||
|
import static com.tngtech.archunit.library.dependencies.SlicesRuleDefinition.slices;
|
||||||
|
|
||||||
|
@AnalyzeClasses(packages = ArchUnitTest.NET_HOSTSHARING_HSADMINNG)
|
||||||
|
public class ArchUnitTest {
|
||||||
|
|
||||||
|
public static final String NET_HOSTSHARING_HSADMINNG = "net.hostsharing.hsadminng";
|
||||||
|
|
||||||
|
@ArchTest
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static final ArchRule contextPackageRule = classes()
|
||||||
|
.that().resideInAPackage("..context..")
|
||||||
|
.should().onlyDependOnClassesThat()
|
||||||
|
.resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG);
|
||||||
|
|
||||||
|
@ArchTest
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static final ArchRule configPackageRule = classes()
|
||||||
|
.that().resideInAPackage("..config..")
|
||||||
|
.should().onlyDependOnClassesThat()
|
||||||
|
.resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG);
|
||||||
|
|
||||||
|
@ArchTest
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static final ArchRule errorsPackageRule = classes()
|
||||||
|
.that().resideInAPackage("..errors..")
|
||||||
|
.should().onlyDependOnClassesThat()
|
||||||
|
.resideOutsideOfPackage(NET_HOSTSHARING_HSADMINNG);
|
||||||
|
|
||||||
|
@ArchTest
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static final ArchRule hsPackagesRule = classes()
|
||||||
|
.that().resideInAPackage("..hs*")
|
||||||
|
.should().onlyBeAccessed().byClassesThat()
|
||||||
|
.resideInAnyPackage("..hs*");
|
||||||
|
|
||||||
|
@ArchTest
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public static final ArchRule hsPackagePackageRule = classes()
|
||||||
|
.that().resideInAPackage("..hspackage..")
|
||||||
|
.should().onlyBeAccessed().byClassesThat()
|
||||||
|
.resideInAnyPackage("..hspackage..");
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void everythingShouldBeFreeOfCycles() {
|
||||||
|
slices().matching("net.hostsharing.hsadminng.(*)..").should().beFreeOfCycles();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void restControllerNaming() {
|
||||||
|
classes().that().areAnnotatedWith(RestController.class).should().haveSimpleNameEndingWith("Controller");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void repositoryNaming() {
|
||||||
|
classes().that().implement(JpaRepository.class).should().haveSimpleNameEndingWith("Repository");
|
||||||
|
}
|
||||||
|
}
|
@ -10,8 +10,6 @@ import org.springframework.test.web.servlet.MockMvc;
|
|||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import static java.util.Collections.singletonList;
|
|
||||||
import static java.util.UUID.randomUUID;
|
|
||||||
import static org.hamcrest.Matchers.hasSize;
|
import static org.hamcrest.Matchers.hasSize;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
Loading…
Reference in New Issue
Block a user