Skip to content

Commit

Permalink
Merge pull request #174 from spanierm/master
Browse files Browse the repository at this point in the history
Add "onion architecture" builder
  • Loading branch information
codecholeric authored Jul 19, 2019
2 parents ec5df46 + 75b6097 commit 89e6004
Show file tree
Hide file tree
Showing 235 changed files with 1,882 additions and 748 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.tngtech.archunit.exampletest.junit4;

import java.util.logging.Logger;

import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.domain.JavaModifier;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.junit.ArchUnitRunner;
Expand All @@ -10,8 +11,6 @@
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.util.logging.Logger;

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.fields;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
import static com.tngtech.archunit.library.GeneralCodingRules.ACCESS_STANDARD_STREAMS;
Expand All @@ -22,7 +21,7 @@

@Category(Example.class)
@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(packages = "com.tngtech.archunit.example")
@AnalyzeClasses(packages = "com.tngtech.archunit.example.layers")
public class CodingRulesTest {

@ArchTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.tngtech.archunit.base.PackageMatchers;
import com.tngtech.archunit.core.domain.JavaClass;
import com.tngtech.archunit.core.domain.JavaMember;
import com.tngtech.archunit.example.security.Secured;
import com.tngtech.archunit.example.layers.security.Secured;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.junit.ArchUnitRunner;
Expand All @@ -20,7 +20,7 @@

@Category(Example.class)
@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(packages = "com.tngtech.archunit.example")
@AnalyzeClasses(packages = "com.tngtech.archunit.example.layers")
public class ControllerRulesTest {

@ArchTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.tngtech.archunit.base.DescribedPredicate;
import com.tngtech.archunit.core.domain.JavaClass;
import com.tngtech.archunit.example.cycle.complexcycles.slice1.SliceOneCallingConstructorInSliceTwoAndMethodInSliceThree;
import com.tngtech.archunit.example.cycle.complexcycles.slice3.ClassCallingConstructorInSliceFive;
import com.tngtech.archunit.example.cycles.complexcycles.slice1.SliceOneCallingConstructorInSliceTwoAndMethodInSliceThree;
import com.tngtech.archunit.example.cycles.complexcycles.slice3.ClassCallingConstructorInSliceFive;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.junit.ArchUnitRunner;
Expand All @@ -18,7 +18,7 @@

@Category(Example.class)
@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(packages = "com.tngtech.archunit.example.cycle")
@AnalyzeClasses(packages = "com.tngtech.archunit.example.cycles")
public class CyclicDependencyRulesTest {

@ArchTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@Category(Example.class)
@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(packages = "com.tngtech.archunit.example")
@AnalyzeClasses(packages = "com.tngtech.archunit.example.layers")
public class DaoRulesTest {
@ArchTest
public static final ArchRule DAOs_must_reside_in_a_dao_package =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
@Category(Example.class)
@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(packages = "com.tngtech.archunit.example")
@AnalyzeClasses(packages = "com.tngtech.archunit.example.layers")
public class FrozenRulesTest {

@ArchTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import com.tngtech.archunit.core.importer.Location;
import com.tngtech.archunit.core.importer.Locations;
import com.tngtech.archunit.example.SomeBusinessInterface;
import com.tngtech.archunit.example.persistence.first.dao.SomeDao;
import com.tngtech.archunit.example.service.impl.SomeInterfacePlacedInTheWrongPackage;
import com.tngtech.archunit.example.layers.SomeBusinessInterface;
import com.tngtech.archunit.example.layers.persistence.first.dao.SomeDao;
import com.tngtech.archunit.example.layers.service.impl.SomeInterfacePlacedInTheWrongPackage;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.junit.ArchUnitRunner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@Category(Example.class)
@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(packages = "com.tngtech.archunit.example")
@AnalyzeClasses(packages = "com.tngtech.archunit.example.layers")
public class LayerDependencyRulesTest {

// 'access' catches only violations by real accesses, i.e. accessing a field, calling a method; compare 'dependOn' further down
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.tngtech.archunit.exampletest.junit4;

import com.tngtech.archunit.example.SomeMediator;
import com.tngtech.archunit.example.service.ServiceViolatingLayerRules;
import com.tngtech.archunit.example.layers.SomeMediator;
import com.tngtech.archunit.example.layers.service.ServiceViolatingLayerRules;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.junit.ArchUnitRunner;
Expand All @@ -13,14 +13,14 @@

@Category(Example.class)
@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(packages = "com.tngtech.archunit.example")
@AnalyzeClasses(packages = "com.tngtech.archunit.example.layers")
public class LayeredArchitectureTest {
@ArchTest
public static final ArchRule layer_dependencies_are_respected = layeredArchitecture()

.layer("Controllers").definedBy("com.tngtech.archunit.example.controller..")
.layer("Services").definedBy("com.tngtech.archunit.example.service..")
.layer("Persistence").definedBy("com.tngtech.archunit.example.persistence..")
.layer("Controllers").definedBy("com.tngtech.archunit.example.layers.controller..")
.layer("Services").definedBy("com.tngtech.archunit.example.layers.service..")
.layer("Persistence").definedBy("com.tngtech.archunit.example.layers.persistence..")

.whereLayer("Controllers").mayNotBeAccessedByAnyLayer()
.whereLayer("Services").mayOnlyBeAccessedByLayers("Controllers")
Expand All @@ -29,9 +29,9 @@ public class LayeredArchitectureTest {
@ArchTest
public static final ArchRule layer_dependencies_are_respected_with_exception = layeredArchitecture()

.layer("Controllers").definedBy("com.tngtech.archunit.example.controller..")
.layer("Services").definedBy("com.tngtech.archunit.example.service..")
.layer("Persistence").definedBy("com.tngtech.archunit.example.persistence..")
.layer("Controllers").definedBy("com.tngtech.archunit.example.layers.controller..")
.layer("Services").definedBy("com.tngtech.archunit.example.layers.service..")
.layer("Persistence").definedBy("com.tngtech.archunit.example.layers.persistence..")

.whereLayer("Controllers").mayNotBeAccessedByAnyLayer()
.whereLayer("Services").mayOnlyBeAccessedByLayers("Controllers")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.tngtech.archunit.exampletest.junit4;

import com.tngtech.archunit.example.anticorruption.WrappedResult;
import com.tngtech.archunit.example.security.Secured;
import com.tngtech.archunit.example.layers.anticorruption.WrappedResult;
import com.tngtech.archunit.example.layers.security.Secured;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.junit.ArchUnitRunner;
Expand All @@ -14,7 +14,7 @@

@Category(Example.class)
@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(packages = "com.tngtech.archunit.example")
@AnalyzeClasses(packages = "com.tngtech.archunit.example.layers")
public class MethodsTest {

@ArchTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.tngtech.archunit.exampletest.junit4;

import com.tngtech.archunit.example.AbstractController;
import com.tngtech.archunit.example.MyController;
import com.tngtech.archunit.example.MyService;
import com.tngtech.archunit.example.layers.AbstractController;
import com.tngtech.archunit.example.layers.MyController;
import com.tngtech.archunit.example.layers.MyService;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.junit.ArchUnitRunner;
Expand All @@ -14,7 +14,7 @@

@Category(Example.class)
@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(packages = "com.tngtech.archunit.example")
@AnalyzeClasses(packages = "com.tngtech.archunit.example.layers")
public class NamingConventionTest {

@ArchTest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.tngtech.archunit.exampletest.junit4;

import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.junit.ArchUnitRunner;
import com.tngtech.archunit.lang.ArchRule;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

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

@Category(Example.class)
@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(packages = "com.tngtech.archunit.example.onionarchitecture")
public class OnionArchitectureTest {

@ArchTest
static final ArchRule onion_architecture_is_respected = onionArchitecture()
.domainModels("..domain.model..")
.domainServices("..domain.service..")
.applicationServices("..application..")
.adapter("cli", "..adapter.cli..")
.adapter("persistence", "..adapter.persistence..")
.adapter("rest", "..adapter.rest..");
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.net.URL;

import com.tngtech.archunit.base.PackageMatchers;
import com.tngtech.archunit.example.shopping.catalog.ProductCatalog;
import com.tngtech.archunit.example.shopping.order.Order;
import com.tngtech.archunit.example.shopping.product.Product;
import com.tngtech.archunit.example.plantuml.catalog.ProductCatalog;
import com.tngtech.archunit.example.plantuml.order.Order;
import com.tngtech.archunit.example.plantuml.product.Product;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.junit.ArchUnitRunner;
Expand All @@ -24,7 +24,7 @@

@Category(Example.class)
@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(packages = "com.tngtech.archunit.example.shopping")
@AnalyzeClasses(packages = "com.tngtech.archunit.example.plantuml")
public class PlantUmlArchitectureTest {
private static final URL plantUmlDiagram = PlantUmlArchitectureTest.class.getResource("shopping_example.puml");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.tngtech.archunit.exampletest.junit4;

import com.tngtech.archunit.example.SomeBusinessInterface;
import com.tngtech.archunit.example.SomeOtherBusinessInterface;
import com.tngtech.archunit.example.layers.SomeBusinessInterface;
import com.tngtech.archunit.example.layers.SomeOtherBusinessInterface;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.junit.ArchUnitRunner;
Expand All @@ -14,7 +14,7 @@

@Category(Example.class)
@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(packages = "com.tngtech.archunit.example")
@AnalyzeClasses(packages = "com.tngtech.archunit.example.layers")
public class RestrictNumberOfClassesWithACertainPropertyTest {
@ArchTest
public static final ArchRule no_new_classes_should_implement_SomeBusinessInterface =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@Category(Example.class)
@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(packages = "com.tngtech.archunit.example")
@AnalyzeClasses(packages = "com.tngtech.archunit.example.layers")
public class RuleLibraryTest {
@ArchTest
public static final ArchRules LIBRARY = ArchRules.in(RuleSetsTest.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

@Category(Example.class)
@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(packages = "com.tngtech.archunit.example")
@AnalyzeClasses(packages = "com.tngtech.archunit.example.layers")
public class RuleSetsTest {
@ArchTest
private final ArchRules CODING_RULES = ArchRules.in(CodingRulesTest.class);

@ArchTest
private final ArchRules CYCLIC_DEPENDENCY_RULES = ArchRules.in(CyclicDependencyRulesTest.class);
private final ArchRules NAMING_CONVENTION_RULES = ArchRules.in(NamingConventionTest.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

@Category(Example.class)
@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(packages = "com.tngtech.archunit.example")
@AnalyzeClasses(packages = "com.tngtech.archunit.example.layers")
public class SessionBeanRulesTest {

@ArchTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.tngtech.archunit.exampletest.junit4;

import com.tngtech.archunit.example.SomeOtherBusinessInterface;
import com.tngtech.archunit.example.core.CoreSatellite;
import com.tngtech.archunit.example.core.HighSecurity;
import com.tngtech.archunit.example.core.VeryCentralCore;
import com.tngtech.archunit.example.layers.SomeOtherBusinessInterface;
import com.tngtech.archunit.example.layers.core.CoreSatellite;
import com.tngtech.archunit.example.layers.core.HighSecurity;
import com.tngtech.archunit.example.layers.core.VeryCentralCore;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.junit.ArchUnitRunner;
Expand All @@ -17,7 +17,7 @@

@Category(Example.class)
@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(packages = "com.tngtech.archunit.example")
@AnalyzeClasses(packages = "com.tngtech.archunit.example.layers")
public class SingleClassTest {

@ArchTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.tngtech.archunit.base.DescribedPredicate;
import com.tngtech.archunit.core.domain.JavaClass;
import com.tngtech.archunit.example.controller.one.UseCaseOneTwoController;
import com.tngtech.archunit.example.controller.two.UseCaseTwoController;
import com.tngtech.archunit.example.layers.controller.one.UseCaseOneTwoController;
import com.tngtech.archunit.example.layers.controller.two.UseCaseTwoController;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.junit.ArchUnitRunner;
Expand All @@ -17,7 +17,7 @@

@Category(Example.class)
@RunWith(ArchUnitRunner.class)
@AnalyzeClasses(packages = "com.tngtech.archunit.example")
@AnalyzeClasses(packages = "com.tngtech.archunit.example.layers")
public class SlicesIsolationTest {
@ArchTest
public static final ArchRule controllers_should_only_use_their_own_slice =
Expand Down
Loading

0 comments on commit 89e6004

Please sign in to comment.