diff --git a/src/main/cml/TLAs-context.cml b/src/main/cml/TLAs-context.cml index b073f6b..f11cce9 100644 --- a/src/main/cml/TLAs-context.cml +++ b/src/main/cml/TLAs-context.cml @@ -18,7 +18,7 @@ BoundedContext TLA_Resolver { String meaning; Set alternativeMeanings; String link; - - TLAState status; + - TLAStatus status; def ThreeLetterAbbreviation() : write [ -> PROPOSED ]; def accept() : write [ PROPOSED -> ACCEPTED ]; @@ -37,10 +37,10 @@ BoundedContext TLA_Resolver { String name; } - enum TLAState { + enum TLAStatus { aggregateLifecycle - PROPOSED, ACCEPTED, DECLINED, ARCHIVED; + DRAFTED, PROPOSED, ACCEPTED, DECLINED, ARCHIVED; } } diff --git a/src/main/java/org/contextmapper/sample/tlas/domain/tla/TLAStatus.java b/src/main/java/org/contextmapper/sample/tlas/domain/tla/TLAStatus.java index 1f70ba6..7bcbce6 100644 --- a/src/main/java/org/contextmapper/sample/tlas/domain/tla/TLAStatus.java +++ b/src/main/java/org/contextmapper/sample/tlas/domain/tla/TLAStatus.java @@ -18,6 +18,6 @@ public enum TLAStatus { - PROPOSED, ACCEPTED, DECLINED, ARCHIVED + DRAFTED, PROPOSED, ACCEPTED, DECLINED, ARCHIVED } diff --git a/src/test/java/org/contextmapper/sample/tlas/domain/TacticDDDModelTest.java b/src/test/java/org/contextmapper/sample/tlas/domain/TacticDDDModelTest.java index 9200f12..58ec7f7 100644 --- a/src/test/java/org/contextmapper/sample/tlas/domain/TacticDDDModelTest.java +++ b/src/test/java/org/contextmapper/sample/tlas/domain/TacticDDDModelTest.java @@ -16,9 +16,19 @@ package org.contextmapper.sample.tlas.domain; +import com.tngtech.archunit.core.domain.JavaClass; +import com.tngtech.archunit.core.domain.JavaEnumConstant; +import com.tngtech.archunit.lang.ArchCondition; +import com.tngtech.archunit.lang.ConditionEvents; +import com.tngtech.archunit.lang.SimpleConditionEvent; import org.contextmapper.archunit.AbstractTacticArchUnitTest; +import org.contextmapper.tactic.dsl.tacticdsl.Enum; +import org.contextmapper.tactic.dsl.tacticdsl.EnumValue; +import org.eclipse.xtext.EcoreUtil2; import org.junit.jupiter.api.Test; +import java.util.Optional; + import static com.tngtech.archunit.core.domain.JavaClass.Predicates.resideInAPackage; import static com.tngtech.archunit.core.domain.properties.HasType.Predicates.rawType; import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; @@ -56,4 +66,34 @@ void domainModelClassesShouldBeAnnotatedWithJMolecules() { .check(classes); } + @Test + void statusEnumsShouldBeModelledInCML() { + classes().that() + .areEnums() + .and().haveSimpleNameEndingWith("Status") + .should(new ArchCondition<>("adhere to CML enum values") { + @Override + public void check(JavaClass statusEnum, ConditionEvents events) { + Optional optionalCmlStatus = EcoreUtil2.eAllOfType(context, Enum.class).stream() + .filter(o -> o.getName().equals(statusEnum.getSimpleName())) + .findAny(); + events.add(new SimpleConditionEvent(optionalCmlStatus, optionalCmlStatus.isPresent(), + String.format("The Status enum '%s' is not modelled in CML.", statusEnum.getSimpleName()))); + + if (optionalCmlStatus.isPresent()) { + Enum cmlStatus = optionalCmlStatus.get(); + for (JavaEnumConstant javaEnumConstant : statusEnum.getEnumConstants()) { + Optional cmlEnumValue = cmlStatus.getValues().stream() + .filter(v -> v.getName().equals(javaEnumConstant.name())) + .findAny(); + events.add(new SimpleConditionEvent(statusEnum, cmlEnumValue.isPresent(), + String.format("The status enum '%s' does not have a value called '%s' in CML.", + cmlStatus.getName(), javaEnumConstant.name()))); + } + } + } + }) + .check(classes); + } + }