TSK-963: Add architecture tests to taskana core

This commit is contained in:
Benjamin Eckstein 2019-11-20 14:24:15 +01:00
parent 82fb6bba3d
commit 655740fc77
3 changed files with 78 additions and 0 deletions

View File

@ -114,6 +114,18 @@
<version>${version.openpojo}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5-api</artifactId>
<version>${version.archunit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5-engine</artifactId>
<version>${version.archunit}</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- this repository is needed to fetch com.ibm.db2.jcc -->

View File

@ -0,0 +1,65 @@
package pro.taskana;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static com.tngtech.archunit.library.GeneralCodingRules.NO_CLASSES_SHOULD_ACCESS_STANDARD_STREAMS;
import static com.tngtech.archunit.library.GeneralCodingRules.NO_CLASSES_SHOULD_THROW_GENERIC_EXCEPTIONS;
import static com.tngtech.archunit.library.dependencies.SlicesRuleDefinition.slices;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.importer.ClassFileImporter;
import com.tngtech.archunit.lang.ArchRule;
/**
* Test architecture of classes in taskana.
* For more info and examples see https://www.archunit.org/userguide/html/000_Index.html
*/
class ArchitectureTest {
private static JavaClasses importedClasses;
@BeforeAll
static void init() {
//time intensive operation should only be done once
importedClasses = new ClassFileImporter().importPackages("pro.taskana");
}
@Test
void mapperShouldBePlacedInMappingsPackage() {
ArchRule myRule = classes()
.that().haveSimpleNameEndingWith("Mapper")
.should().resideInAPackage("..mappings..");
myRule.check(importedClasses);
}
@Test
@Disabled
void noClassShouldThrowGenericException() {
NO_CLASSES_SHOULD_THROW_GENERIC_EXCEPTIONS.check(importedClasses);
}
@Test
@Disabled
void noClassShouldAccessStandardStreams() {
NO_CLASSES_SHOULD_ACCESS_STANDARD_STREAMS.check(importedClasses);
}
@Test
@Disabled
void freeOfCycles() {
ArchRule myRule = slices().matching("pro.taskana.(*)..").should().beFreeOfCycles();
myRule.check(importedClasses);
}
@Test
@Disabled
void freeOfCyclicDependencies() {
ArchRule myRule = slices().matching("pro.taskana.(*)..").should().notDependOnEachOther();
myRule.check(importedClasses);
}
}

View File

@ -66,6 +66,7 @@
<!-- test dependencies -->
<version.junit.jupiter>5.5.2</version.junit.jupiter>
<version.log4j>2.8.1</version.log4j>
<version.archunit>0.12.0</version.archunit>
<version.mockito>2.8.47</version.mockito>
<version.powermock>1.7.1</version.powermock>
<version.hamcrest>1.3</version.hamcrest>