Skip to content

Commit

Permalink
initial layered architecture test
Browse files Browse the repository at this point in the history
  • Loading branch information
WeRockStar committed Mar 19, 2024
1 parent a1e7744 commit 186545e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions kshop/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'com.tngtech.archunit:archunit-junit5:1.2.1'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kampus.kshop.health;
package com.kampus.kshop.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.kampus.kshop.repository;

import org.springframework.stereotype.Repository;

@Repository
public class ChangeMeRepository {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.kampus.kshop.service;

import org.springframework.stereotype.Service;

@Service
public class ChangeMeService {
}
24 changes: 24 additions & 0 deletions kshop/src/test/java/com/kampus/kshop/architecture/LayeredTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.kampus.kshop.architecture;

import com.tngtech.archunit.core.importer.ImportOption;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;

import static com.tngtech.archunit.library.Architectures.layeredArchitecture;

@AnalyzeClasses(packages = "com.kampus.kshop", importOptions = ImportOption.DoNotIncludeTests.class)
public class LayeredTest {

@ArchTest
static final ArchRule layeredArchitecture =
layeredArchitecture()
.consideringAllDependencies()
.layer("Controller").definedBy("..controller..")
.layer("Service").definedBy("..service..")
.layer("Repository").definedBy("..repository..")
.whereLayer("Controller").mayNotBeAccessedByAnyLayer()
.whereLayer("Service").mayOnlyBeAccessedByLayers("Controller")
.whereLayer("Repository").mayOnlyBeAccessedByLayers("Service");

}

0 comments on commit 186545e

Please sign in to comment.