arch unit test for @Accepts only in AcceptanceTests
This commit is contained in:
parent
2cb9375d03
commit
6be5cfd923
@ -3,11 +3,13 @@ package net.hostsharing.hsadminng.arch;
|
||||
import com.tngtech.archunit.junit.AnalyzeClasses;
|
||||
import com.tngtech.archunit.junit.ArchTest;
|
||||
import com.tngtech.archunit.lang.ArchRule;
|
||||
import net.hostsharing.hsadminng.Accepts;
|
||||
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.lang.syntax.ArchRuleDefinition.methods;
|
||||
import static com.tngtech.archunit.library.dependencies.SlicesRuleDefinition.slices;
|
||||
|
||||
@AnalyzeClasses(packages = ArchUnitTest.NET_HOSTSHARING_HSADMINNG)
|
||||
@ -50,6 +52,20 @@ public class ArchUnitTest {
|
||||
.should().onlyBeAccessed().byClassesThat()
|
||||
.resideInAnyPackage("..hs.hspackage..");
|
||||
|
||||
@ArchTest
|
||||
@SuppressWarnings("unused")
|
||||
public static final ArchRule acceptsAnnotationOnMethodsRule = methods()
|
||||
.that().areAnnotatedWith(Accepts.class)
|
||||
.should().beDeclaredInClassesThat().haveSimpleNameEndingWith("AcceptanceTest")
|
||||
.orShould().beDeclaredInClassesThat().haveSimpleNameNotContaining("AcceptanceTest$");
|
||||
|
||||
@ArchTest
|
||||
@SuppressWarnings("unused")
|
||||
public static final ArchRule acceptsAnnotationOnClasesRule = classes()
|
||||
.that().areAnnotatedWith(Accepts.class)
|
||||
.should().haveSimpleNameEndingWith("AcceptanceTest")
|
||||
.orShould().haveSimpleNameNotContaining("AcceptanceTest$");
|
||||
|
||||
@Test
|
||||
public void everythingShouldBeFreeOfCycles() {
|
||||
slices().matching("net.hostsharing.hsadminng.(*)..").should().beFreeOfCycles();
|
||||
|
@ -30,7 +30,7 @@ import static org.hamcrest.CoreMatchers.containsString;
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = { HsadminNgApplication.class, JpaAttempt.class }
|
||||
)
|
||||
@Accepts({ "ROL:S(Schema)" })
|
||||
@Accepts({ "GRT:S(Schema)" })
|
||||
@Transactional(propagation = Propagation.NEVER)
|
||||
class RbacGrantControllerAcceptanceTest {
|
||||
|
||||
|
@ -28,7 +28,6 @@ import static org.assertj.core.api.Assumptions.assumeThat;
|
||||
@DataJpaTest
|
||||
@ComponentScan(basePackageClasses = { RbacGrantRepository.class, Context.class, JpaAttempt.class })
|
||||
@DirtiesContext
|
||||
@Accepts({ "GRT:S(Schema)" })
|
||||
class RbacGrantRepositoryIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@ -133,9 +132,7 @@ class RbacGrantRepositoryIntegrationTest {
|
||||
@Transactional(propagation = Propagation.NEVER)
|
||||
public void packageAdmin_canNotGrantPackageOwnerRole() {
|
||||
// given
|
||||
record Given(RbacUserEntity arbitraryUser, UUID packageOwnerRoleUuid) {
|
||||
|
||||
}
|
||||
record Given(RbacUserEntity arbitraryUser, UUID packageOwnerRoleUuid) {}
|
||||
final var given = jpaAttempt.transacted(() -> {
|
||||
// to find the uuids of we need to have access rights to these
|
||||
currentUser("admin@aaa.example.com");
|
||||
|
@ -43,22 +43,22 @@ class RbacRoleControllerAcceptanceTest {
|
||||
// @formatter:off
|
||||
RestAssured
|
||||
.given()
|
||||
.header("current-user", "mike@hostsharing.net")
|
||||
.port(port)
|
||||
.header("current-user", "mike@hostsharing.net")
|
||||
.port(port)
|
||||
.when()
|
||||
.get("http://localhost/api/rbac-roles")
|
||||
.get("http://localhost/api/rbac-roles")
|
||||
.then().assertThat()
|
||||
.statusCode(200)
|
||||
.contentType("application/json")
|
||||
.body("[0].roleName", is("customer#aaa.admin"))
|
||||
.body("[1].roleName", is("customer#aaa.owner"))
|
||||
.body("[2].roleName", is("customer#aaa.tenant"))
|
||||
// ...
|
||||
.body("", hasItem(hasEntry("roleName", "global#hostsharing.admin")))
|
||||
.body("", hasItem(hasEntry("roleName", "customer#aab.admin")))
|
||||
.body("", hasItem(hasEntry("roleName", "package#aab00.admin")))
|
||||
.body("", hasItem(hasEntry("roleName", "unixuser#aab00-aaaa.owner")))
|
||||
.body( "size()", is(73)); // increases with new test data
|
||||
.statusCode(200)
|
||||
.contentType("application/json")
|
||||
.body("[0].roleName", is("customer#aaa.admin"))
|
||||
.body("[1].roleName", is("customer#aaa.owner"))
|
||||
.body("[2].roleName", is("customer#aaa.tenant"))
|
||||
// ...
|
||||
.body("", hasItem(hasEntry("roleName", "global#hostsharing.admin")))
|
||||
.body("", hasItem(hasEntry("roleName", "customer#aab.admin")))
|
||||
.body("", hasItem(hasEntry("roleName", "package#aab00.admin")))
|
||||
.body("", hasItem(hasEntry("roleName", "unixuser#aab00-aaaa.owner")))
|
||||
.body( "size()", is(73)); // increases with new test data
|
||||
// @formatter:on
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user