Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add component type to dependencies to self #490

Merged
merged 19 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
da37c7a
fix component type self dependencies
codecholeric Dec 13, 2020
b385be1
make component type dependencies more resilient
codecholeric Dec 13, 2020
ec4e923
separate annotation tests from `ClassFileImporterTest`
codecholeric Dec 15, 2020
a4065c6
speed up resolving constructors from `ConstructorCallTarget`
codecholeric Dec 12, 2020
d1a6059
speed up expensive getters in `JavaClass`
codecholeric Dec 12, 2020
87f54a4
remove redundant search for call target
codecholeric Dec 12, 2020
459e42b
make access target resolution process more specific
codecholeric Dec 13, 2020
bf7c52c
improve creating class hierarchy path
codecholeric Dec 13, 2020
6247ba6
cache Dependency.hashCode
codecholeric Dec 13, 2020
dd41c51
sort component type dependency test to the other dependency tests
codecholeric Dec 13, 2020
f8f78fd
move local class to a separate class
codecholeric Dec 13, 2020
d1af7e2
rename `get...AccessesFor` -> `create...AccessesFor`
codecholeric Dec 6, 2020
86e41a5
move accesses by target from `AccessContext` to `ImportContext`
codecholeric Dec 6, 2020
06b2ed0
complete `JavaCodeUnits` inside of `JavaClass`
codecholeric Dec 6, 2020
21a693b
move registering "accesses to self" into `JavaClasses`
codecholeric Dec 6, 2020
21bbc94
refactor tests for accesses to self of subclasses
codecholeric Dec 12, 2020
356e3f8
simplify calls to self creation
codecholeric Dec 12, 2020
3f011f1
move all reverse dependency registering into `ReverseDependencies`
codecholeric Dec 13, 2020
7f4b8cd
add component type dependencies to self
codecholeric Dec 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.tngtech.archunit.example.layers.controller.two.UseCaseTwoController;
import com.tngtech.archunit.example.layers.security.Secured;

@SuppressWarnings("unused")
@MyService
@ComplexServiceAnnotation(
controllerAnnotation = @ComplexControllerAnnotation(simpleControllerAnnotation = @SimpleControllerAnnotation),
Expand All @@ -17,9 +18,6 @@
serviceType = ServiceType.STANDARD
)
public class ServiceViolatingLayerRules {
public static final String illegalAccessToController = "illegalAccessToController";
public static final String doSomething = "doSomething";
public static final String dependentMethod = "dependentMethod";

void illegalAccessToController() {
System.out.println(UseCaseOneTwoController.someString);
Expand All @@ -34,7 +32,16 @@ public SomeGuiController dependentMethod(UseCaseTwoController otherController) {
return null;
}

public SomeGuiController[][] dependentOnComponentTypeMethod(UseCaseTwoController[] otherController) {
return null;
}

@Secured
public void properlySecured() {
}

public static final String illegalAccessToController = "illegalAccessToController";
public static final String doSomething = "doSomething";
public static final String dependentMethod = "dependentMethod";
public static final String dependentOnComponentTypeMethod = "dependentOnComponentTypeMethod";
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Field <com.tngtech.archunit.example.layers.controller.SomeController.otherServic
Field <com.tngtech.archunit.example.layers.controller.SomeController.service> has type <com.tngtech.archunit.example.layers.service.ServiceViolatingDaoRules> in (SomeController.java:0)
Field <com.tngtech.archunit.example.layers.persistence.layerviolation.DaoCallingService.service> has type <com.tngtech.archunit.example.layers.service.ServiceViolatingLayerRules> in (DaoCallingService.java:0)
Field <com.tngtech.archunit.example.layers.service.ServiceType.$VALUES> has type <[Lcom.tngtech.archunit.example.layers.service.ServiceType;> in (ServiceType.java:0)
Field <com.tngtech.archunit.example.layers.service.ServiceType.$VALUES> depends on component type <com.tngtech.archunit.example.layers.service.ServiceType> in (ServiceType.java:0)
Field <com.tngtech.archunit.example.layers.service.ServiceViolatingDaoRules.myEntityManager> has type <com.tngtech.archunit.example.layers.service.ServiceViolatingDaoRules$MyEntityManager> in (ServiceViolatingDaoRules.java:0)
Method <com.tngtech.archunit.example.layers.SomeMediator.violateLayerRulesIndirectly()> calls method <com.tngtech.archunit.example.layers.service.ServiceViolatingLayerRules.doSomething()> in (SomeMediator.java:15)
Method <com.tngtech.archunit.example.layers.controller.SomeGuiController.callServiceLayer()> calls constructor <com.tngtech.archunit.example.layers.service.ServiceHelper.<init>()> in (SomeGuiController.java:7)
Expand All @@ -21,6 +20,4 @@ Method <com.tngtech.archunit.example.layers.service.ComplexServiceAnnotation.ser
Method <com.tngtech.archunit.example.layers.service.ComplexServiceAnnotation.simpleServiceAnnotation()> has return type <com.tngtech.archunit.example.layers.service.SimpleServiceAnnotation> in (ComplexServiceAnnotation.java:0)
Method <com.tngtech.archunit.example.layers.service.ServiceType.values()> calls method <[Lcom.tngtech.archunit.example.layers.service.ServiceType;.clone()> in (ServiceType.java:3)
Method <com.tngtech.archunit.example.layers.service.ServiceType.values()> has return type <[Lcom.tngtech.archunit.example.layers.service.ServiceType;> in (ServiceType.java:0)
Method <com.tngtech.archunit.example.layers.service.ServiceType.values()> depends on component type <com.tngtech.archunit.example.layers.service.ServiceType> in (ServiceType.java:0)
Method <com.tngtech.archunit.example.layers.service.ServiceType.values()> depends on component type <com.tngtech.archunit.example.layers.service.ServiceType> in (ServiceType.java:3)
Method <com.tngtech.archunit.example.layers.service.ServiceViolatingDaoRules.illegallyUseEntityManager()> calls method <com.tngtech.archunit.example.layers.service.ServiceViolatingDaoRules$MyEntityManager.persist(java.lang.Object)> in (ServiceViolatingDaoRules.java:27)
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
import static com.tngtech.archunit.example.layers.core.VeryCentralCore.DO_CORE_STUFF_METHOD_NAME;
import static com.tngtech.archunit.example.layers.persistence.layerviolation.DaoCallingService.violateLayerRules;
import static com.tngtech.archunit.example.layers.service.ServiceViolatingLayerRules.dependentMethod;
import static com.tngtech.archunit.example.layers.service.ServiceViolatingLayerRules.dependentOnComponentTypeMethod;
import static com.tngtech.archunit.example.layers.service.ServiceViolatingLayerRules.illegalAccessToController;
import static com.tngtech.archunit.testutils.CyclicErrorMatcher.cycle;
import static com.tngtech.archunit.testutils.ExpectedAccess.callFromConstructor;
Expand Down Expand Up @@ -251,7 +252,7 @@ private static void expectAccessToStandardStreams(ExpectedTestFailures expectFai
.inLine(14))
.by(callFromMethod(ServiceViolatingLayerRules.class, "illegalAccessToController")
.getting().field(System.class, "out")
.inLine(25));
.inLine(23));
}

private static void expectThrownGenericExceptions(ExpectedTestFailures expectFailures) {
Expand Down Expand Up @@ -686,13 +687,13 @@ Stream<DynamicTest> LayerDependencyRulesTest() {
"should access classes that reside in a package '..controller..'")
.by(callFromMethod(ServiceViolatingLayerRules.class, illegalAccessToController)
.getting().field(UseCaseOneTwoController.class, someString)
.inLine(25))
.inLine(23))
.by(callFromMethod(ServiceViolatingLayerRules.class, illegalAccessToController)
.toConstructor(UseCaseTwoController.class)
.inLine(26))
.inLine(24))
.by(callFromMethod(ServiceViolatingLayerRules.class, illegalAccessToController)
.toMethod(UseCaseTwoController.class, doSomethingTwo)
.inLine(27))
.inLine(25))

.ofRule("no classes that reside in a package '..persistence..' should " +
"access classes that reside in a package '..service..'")
Expand All @@ -719,27 +720,32 @@ Stream<DynamicTest> LayerDependencyRulesTest() {
+ "only access classes that reside in any package ['..service..', '..persistence..', 'java..']")
.by(callFromMethod(ServiceViolatingLayerRules.class, illegalAccessToController)
.getting().field(UseCaseOneTwoController.class, UseCaseOneTwoController.someString)
.inLine(25))
.inLine(23))
.by(callFromMethod(ServiceViolatingLayerRules.class, illegalAccessToController)
.toConstructor(UseCaseTwoController.class)
.inLine(26))
.inLine(24))
.by(callFromMethod(ServiceViolatingLayerRules.class, illegalAccessToController)
.toMethod(UseCaseTwoController.class, UseCaseTwoController.doSomethingTwo)
.inLine(27))
.inLine(25))

.ofRule("no classes that reside in a package '..service..' " +
"should depend on classes that reside in a package '..controller..'")
.by(callFromMethod(ServiceViolatingLayerRules.class, illegalAccessToController)
.getting().field(UseCaseOneTwoController.class, someString)
.inLine(25).asDependency())
.inLine(23).asDependency())
.by(callFromMethod(ServiceViolatingLayerRules.class, illegalAccessToController)
.toConstructor(UseCaseTwoController.class)
.inLine(26).asDependency())
.inLine(24).asDependency())
.by(callFromMethod(ServiceViolatingLayerRules.class, illegalAccessToController)
.toMethod(UseCaseTwoController.class, doSomethingTwo)
.inLine(27).asDependency())
.inLine(25).asDependency())
.by(method(ServiceViolatingLayerRules.class, dependentMethod).withParameter(UseCaseTwoController.class))
.by(method(ServiceViolatingLayerRules.class, dependentMethod).withReturnType(SomeGuiController.class))
.by(method(ServiceViolatingLayerRules.class, dependentOnComponentTypeMethod).withParameter(UseCaseTwoController[].class))
.by(method(ServiceViolatingLayerRules.class, dependentOnComponentTypeMethod).dependingOnComponentType(UseCaseTwoController.class))
.by(method(ServiceViolatingLayerRules.class, dependentOnComponentTypeMethod).withReturnType(SomeGuiController[][].class))
.by(method(ServiceViolatingLayerRules.class, dependentOnComponentTypeMethod).dependingOnComponentType(SomeGuiController[].class))
.by(method(ServiceViolatingLayerRules.class, dependentOnComponentTypeMethod).dependingOnComponentType(SomeGuiController.class))
.by(annotatedClass(ServiceViolatingLayerRules.class).withAnnotationParameterType(ComplexControllerAnnotation.class))
.by(annotatedClass(ServiceViolatingLayerRules.class).withAnnotationParameterType(SimpleControllerAnnotation.class))
.by(annotatedClass(ServiceViolatingLayerRules.class).withAnnotationParameterType(SomeEnum.class))
Expand Down Expand Up @@ -783,23 +789,23 @@ Stream<DynamicTest> LayerDependencyRulesTest() {
+ "only depend on classes that reside in any package ['..service..', '..persistence..', 'java..', 'javax..']")
.by(callFromMethod(ServiceViolatingLayerRules.class, illegalAccessToController)
.getting().field(UseCaseOneTwoController.class, someString)
.inLine(25).asDependency())
.inLine(23).asDependency())
.by(callFromMethod(ServiceViolatingLayerRules.class, illegalAccessToController)
.toConstructor(UseCaseTwoController.class)
.inLine(26).asDependency())
.inLine(24).asDependency())
.by(callFromMethod(ServiceViolatingLayerRules.class, illegalAccessToController)
.toMethod(UseCaseTwoController.class, doSomethingTwo)
.inLine(27).asDependency())
.by(method(ServiceViolatingLayerRules.class, dependentMethod)
.withParameter(UseCaseTwoController.class))
.by(method(ServiceViolatingLayerRules.class, dependentMethod)
.withReturnType(SomeGuiController.class))
.by(field(ServiceHelper.class, "properlySecured")
.withAnnotationType(Secured.class))
.by(method(ServiceViolatingLayerRules.class, "properlySecured")
.withAnnotationType(Secured.class))
.by(constructor(ServiceHelper.class)
.withAnnotationType(Secured.class))
.inLine(25).asDependency())
.by(method(ServiceViolatingLayerRules.class, dependentMethod).withParameter(UseCaseTwoController.class))
.by(method(ServiceViolatingLayerRules.class, dependentMethod).withReturnType(SomeGuiController.class))
.by(method(ServiceViolatingLayerRules.class, dependentOnComponentTypeMethod).withParameter(UseCaseTwoController[].class))
.by(method(ServiceViolatingLayerRules.class, dependentOnComponentTypeMethod).dependingOnComponentType(UseCaseTwoController.class))
.by(method(ServiceViolatingLayerRules.class, dependentOnComponentTypeMethod).withReturnType(SomeGuiController[][].class))
.by(method(ServiceViolatingLayerRules.class, dependentOnComponentTypeMethod).dependingOnComponentType(SomeGuiController[].class))
.by(method(ServiceViolatingLayerRules.class, dependentOnComponentTypeMethod).dependingOnComponentType(SomeGuiController.class))
.by(field(ServiceHelper.class, "properlySecured").withAnnotationType(Secured.class))
.by(method(ServiceViolatingLayerRules.class, "properlySecured").withAnnotationType(Secured.class))
.by(constructor(ServiceHelper.class).withAnnotationType(Secured.class))
.by(annotatedClass(ServiceViolatingDaoRules.class).annotatedWith(MyService.class))
.by(annotatedClass(ServiceViolatingLayerRules.class).annotatedWith(MyService.class))
.by(annotatedClass(ServiceImplementation.class).annotatedWith(MyService.class))
Expand Down Expand Up @@ -839,17 +845,17 @@ Stream<DynamicTest> LayeredArchitectureTest() {

.by(callFromMethod(ServiceViolatingLayerRules.class, "illegalAccessToController")
.toConstructor(UseCaseTwoController.class)
.inLine(26)
.inLine(24)
.asDependency())

.by(callFromMethod(ServiceViolatingLayerRules.class, "illegalAccessToController")
.toMethod(UseCaseTwoController.class, "doSomethingTwo")
.inLine(27)
.inLine(25)
.asDependency())

.by(callFromMethod(ServiceViolatingLayerRules.class, "illegalAccessToController")
.getting().field(UseCaseOneTwoController.class, "someString")
.inLine(25)
.inLine(23)
.asDependency())

.by(callFromMethod(OtherJpa.class, "testConnection")
Expand All @@ -858,8 +864,11 @@ Stream<DynamicTest> LayeredArchitectureTest() {
.asDependency())

.by(method(ServiceViolatingLayerRules.class, dependentMethod).withParameter(UseCaseTwoController.class))

.by(method(ServiceViolatingLayerRules.class, dependentMethod).withReturnType(SomeGuiController.class))
.by(method(ServiceViolatingLayerRules.class, dependentOnComponentTypeMethod)
.dependingOnComponentType(UseCaseTwoController.class))
.by(method(ServiceViolatingLayerRules.class, dependentOnComponentTypeMethod)
.dependingOnComponentType(SomeGuiController.class))

.by(annotatedClass(ServiceViolatingLayerRules.class).withAnnotationParameterType(ComplexControllerAnnotation.class))
.by(annotatedClass(ServiceViolatingLayerRules.class).withAnnotationParameterType(SimpleControllerAnnotation.class))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ public ExpectedDependency withReturnType(Class<?> returnType) {
return new ExpectedDependency(owner, returnType, dependencyPattern);
}

public ExpectedDependency dependingOnComponentType(Class<?> componentType) {
String dependencyPattern = getDependencyPattern(getOriginName(), "depends on component type", componentType.getName(), 0);
return new ExpectedDependency(owner, componentType, dependencyPattern);
}

public ExpectedDependency withAnnotationType(Class<?> annotationType) {
return new ExpectedDependency(owner, annotationType, getDependencyPattern(getOriginName(), "is annotated with", annotationType.getName(), 0));
}
Expand Down
Loading