Skip to content

Commit

Permalink
Updated ArchUnit-Example for version 0.9.0. There are now three subpr…
Browse files Browse the repository at this point in the history
…ojects, each demonstrating how to use the respective 'flavor' of ArchUnit.

Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
  • Loading branch information
codecholeric committed Aug 19, 2018
1 parent 9802e82 commit 249d837
Show file tree
Hide file tree
Showing 378 changed files with 4,551 additions and 148 deletions.
31 changes: 15 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
apply plugin: 'java'
subprojects {
apply plugin: 'java'

repositories {
mavenCentral()
}
repositories {
mavenCentral()
}

dependencies {
// These are the 'production' dependencies of the Demo src/main/java files -> just for Demo purposes, otherwise irrelevant
compile 'org.apache.geronimo.specs:geronimo-ejb_3.1_spec:1.0'
compile 'org.apache.geronimo.specs:geronimo-jpa_2.0_spec:1.0'
dependencies {
// These are the 'production' dependencies of the Demo src/main/java files -> just for Demo purposes, otherwise irrelevant
compile 'org.apache.geronimo.specs:geronimo-ejb_3.1_spec:1.0'
compile 'org.apache.geronimo.specs:geronimo-jpa_2.0_spec:1.0'
}

// This is the only dependency necessary, to run ArchUnit -> substitute 'archunit-junit' with 'archunit' if you don't use JUnit 4
testCompile 'com.tngtech.archunit:archunit-junit:0.8.3'
tasks.withType(AbstractCompile) {
options.compilerArgs += ["--add-modules", "java.xml.ws.annotation"]
}
}

task wrapper(type: Wrapper) {
gradleVersion = '4.7'
}

tasks.withType(AbstractCompile) {
options.compilerArgs += ["--add-modules", "java.xml.ws.annotation"]
}
gradleVersion = '4.9'
}
3 changes: 3 additions & 0 deletions example-junit4/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependencies {
testCompile 'com.tngtech.archunit:archunit-junit4:0.9.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.tngtech.archunit.example;

import com.tngtech.archunit.example.core.VeryCentralCore;

@SuppressWarnings("unused")
public class EvilCoreAccessor {
void iShouldNotAccessCore() {
new VeryCentralCore().doCoreStuff();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.tngtech.archunit.example;

public interface SomeOtherBusinessInterface {
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package com.tngtech.archunit.example.controller;

import com.tngtech.archunit.example.service.ServiceViolatingDaoRules;
import com.tngtech.archunit.example.service.ServiceViolatingLayerRules;

public class SomeController {
private ServiceViolatingDaoRules service;
private ServiceViolatingLayerRules otherService;

void doSthController() {
service.doSthService();
}

void doSthWithSecuredService() {
otherService.properlySecured();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.tngtech.archunit.example.controller;

import com.tngtech.archunit.example.service.ServiceHelper;

public class SomeGuiController {
void callServiceLayer() {
ServiceHelper helper = new ServiceHelper();
new ServiceHelper("this is okay");

process(helper.insecure);
process(helper.properlySecured);
}

private void process(Object object) {
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.tngtech.archunit.example.controller;

import com.tngtech.archunit.example.MyController;
import com.tngtech.archunit.example.core.HighSecurity;

@HighSecurity
@MyController
public class WronglyAnnotated {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.tngtech.archunit.example.core;

@SuppressWarnings("unused")
public class AnotherGoodCoreSatellite implements CoreSatellite {
VeryCentralCore centralCore;

void iAlsoMayAccessCore() {
centralCore.doCoreStuff();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.tngtech.archunit.example.core;

public interface CoreSatellite {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.tngtech.archunit.example.core;

@SuppressWarnings("unused")
public class GoodCoreSatellite implements CoreSatellite {
VeryCentralCore centralCore;

void iMayAccessCore() {
centralCore.doCoreStuff();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.tngtech.archunit.example.core;

import java.lang.annotation.Retention;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Retention(RUNTIME)
public @interface HighSecurity {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.tngtech.archunit.example.core;

import com.tngtech.archunit.example.SomeOtherBusinessInterface;
import com.tngtech.archunit.example.web.AnnotatedController;

@HighSecurity
@SuppressWarnings("unused")
public class VeryCentralCore implements SomeOtherBusinessInterface {
public static final String DO_CORE_STUFF_METHOD_NAME = "doCoreStuff";

public void doCoreStuff() {
}

void coreDoingIllegalStuff() {
new AnnotatedController();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.tngtech.archunit.example.cycle.complexcycles.slice1;

import com.tngtech.archunit.example.cycle.complexcycles.slice2.ClassOfMinimalCircleCallingSliceOne;
import com.tngtech.archunit.example.cycle.complexcycles.slice2.ClassOfMinimalCycleCallingSliceOne;

public class ClassOfMinimalCircleCallingSliceTwo {
private ClassOfMinimalCircleCallingSliceOne classInSliceTwo;
public class ClassOfMinimalCycleCallingSliceTwo {
private ClassOfMinimalCycleCallingSliceOne classInSliceTwo;

public void callSliceTwo() {
classInSliceTwo.callSliceOne();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.tngtech.archunit.example.cycle.complexcycles.slice2;

import com.tngtech.archunit.example.cycle.complexcycles.slice1.ClassOfMinimalCircleCallingSliceTwo;
import com.tngtech.archunit.example.cycle.complexcycles.slice1.ClassOfMinimalCycleCallingSliceTwo;

public class ClassOfMinimalCircleCallingSliceOne {
private ClassOfMinimalCircleCallingSliceTwo classInSliceOne;
public class ClassOfMinimalCycleCallingSliceOne {
private ClassOfMinimalCycleCallingSliceTwo classInSliceOne;

public void callSliceOne() {
classInSliceOne.callSliceTwo();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.tngtech.archunit.example.cycle.membercycle.slice1;

import com.tngtech.archunit.example.cycle.membercycle.slice2.SliceTwoWithMethodParameterTypeInSliceThree;

public class SliceOneWithFieldTypeInSliceTwo {
public SliceTwoWithMethodParameterTypeInSliceThree classInSliceTwo;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.tngtech.archunit.example.cycle.membercycle.slice2;

import com.tngtech.archunit.example.cycle.membercycle.slice3.SliceThreeWithMethodReturnTypeInSliceFour;

public class SliceTwoWithMethodParameterTypeInSliceThree {
public void methodWithParameterInSliceThree(SliceThreeWithMethodReturnTypeInSliceFour methodParameter) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.tngtech.archunit.example.cycle.membercycle.slice3;

import com.tngtech.archunit.example.cycle.membercycle.slice4.SliceFourWithConstructorParameterInSliceOne;

public class SliceThreeWithMethodReturnTypeInSliceFour {
public SliceFourWithConstructorParameterInSliceOne methodWithReturnTypeInSliceFour() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.tngtech.archunit.example.cycle.membercycle.slice4;

import com.tngtech.archunit.example.cycle.membercycle.slice1.SliceOneWithFieldTypeInSliceTwo;

public class SliceFourWithConstructorParameterInSliceOne {
public SliceFourWithConstructorParameterInSliceOne(SliceOneWithFieldTypeInSliceTwo fieldInSliceTwo) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.tngtech.archunit.example.security;

import java.lang.annotation.Retention;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Retention(RUNTIME)
public @interface Secured {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.tngtech.archunit.example.service;

import com.tngtech.archunit.example.security.Secured;

/**
* Well modelled code always has lots of 'helpers' ;-)
*/
public class ServiceHelper {
public Object insecure = new Object();
@Secured
public Object properlySecured = new Object();

public ServiceHelper() {
}

@Secured
public ServiceHelper(String properlySecured) {
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.tngtech.archunit.example.service;

import com.tngtech.archunit.example.MyService;
import com.tngtech.archunit.example.controller.SomeGuiController;
import com.tngtech.archunit.example.controller.one.UseCaseOneTwoController;
import com.tngtech.archunit.example.controller.two.UseCaseTwoController;
import com.tngtech.archunit.example.security.Secured;

@MyService
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 @@ -17,4 +20,12 @@ void illegalAccessToController() {

public void doSomething() {
}

public SomeGuiController dependentMethod(UseCaseTwoController otherController) {
return null;
}

@Secured
public void properlySecured() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.tngtech.archunit.example.shopping.address;

import com.tngtech.archunit.example.shopping.catalog.ProductCatalog;

public class Address {
private ProductCatalog productCatalog;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.tngtech.archunit.example.shopping.catalog;

import java.util.Set;

import com.tngtech.archunit.example.shopping.order.Order;
import com.tngtech.archunit.example.shopping.product.Product;

public class ProductCatalog {
public Set<Product> allProducts;

void gonnaDoSomethingIllegalWithOrder() {
Order order = new Order();
order.addProducts(allProducts);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.tngtech.archunit.example.shopping.customer;

import com.tngtech.archunit.example.shopping.address.Address;

public class Customer {
public Address address;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.tngtech.archunit.example.shopping.importer;

import com.tngtech.archunit.example.shopping.catalog.ProductCatalog;
import com.tngtech.archunit.example.shopping.customer.Customer;
import com.tngtech.archunit.example.shopping.xml.processor.XmlProcessor;
import com.tngtech.archunit.example.shopping.xml.types.XmlTypes;

public class ProductImport {
public ProductCatalog productCatalog;
public XmlTypes xmlType;
public XmlProcessor xmlProcessor;

public Customer getCustomer() {
return new Customer();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.tngtech.archunit.example.shopping.order;

import java.util.Set;

import com.tngtech.archunit.example.shopping.customer.Customer;
import com.tngtech.archunit.example.shopping.product.Product;

public class Order {
public Customer customer;
public Set<Product> products;

public void addProducts(Set<Product> products) {
this.products.addAll(products);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.tngtech.archunit.example.shopping.product;

import com.tngtech.archunit.example.shopping.customer.Customer;

public class Product {
public Customer customer;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.tngtech.archunit.example.shopping.xml.processor;

public class XmlProcessor {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.tngtech.archunit.example.shopping.xml.types;

public class XmlTypes {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.tngtech.archunit.example.shopping.xml.utils;

public class XmlUtils {
}
Loading

0 comments on commit 249d837

Please sign in to comment.