Skip to content

Added test case and fix for generating imported bounded contexts #368

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -0,0 +1,16 @@
/* Simple bounded contexts */
BoundedContext ImportedContext1 {
Module importedModule1 {
Aggregate ImportedAggregate1 {
Entity ImportedEntity1
}
}
}

BoundedContext ImportedContext2 {
Module importedModule2 {
Aggregate ImportedAggregate2 {
Entity ImportedEntity2
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* Import other contexts */
import "./imported-contexts.cml"

/* Define the context map that includes imported contexts */
ContextMap TestMap {
contains ImportedContext1
contains ImportedContext2

ImportedContext1 [U]->[D] ImportedContext2
}
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,23 @@ void expectExceptionIfThereIsOnlyAnEmptyDomain() {
});
}

@Test
void canGeneratePlantUMLWithImportedBoundedContexts() throws IOException {
// given
ContextMappingModel model = getOriginalResourceOfTestCML("plantuml-generator-import-test.cml")
.getContextMappingModel();

// when
IFileSystemAccess2Mock filesystem = new IFileSystemAccess2Mock();
this.generator.doGenerate(new ContextMappingModelResourceMock(model, "testmodel", "cml"), filesystem,
new IGeneratorContextMock());

// then
assertTrue(filesystem.getGeneratedFilesSet().contains("testmodel_ContextMap.puml"));
assertTrue(filesystem.getGeneratedFilesSet().contains("testmodel_BC_ImportedContext1.puml"));
assertTrue(filesystem.getGeneratedFilesSet().contains("testmodel_BC_ImportedContext2.puml"));
}

private Entity createTestEntity(String name) {
Entity testEntity = TacticdslFactory.eINSTANCE.createEntity();
testEntity.setName(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.HashSet;

import org.contextmapper.dsl.cml.CMLModelDomainAndSubdomainResolver;
import org.contextmapper.dsl.contextMappingDSL.Aggregate;
Expand Down Expand Up @@ -126,8 +128,14 @@ private void generateClassDiagramsForSubdomains(IFileSystemAccess2 fsa, String f

private void generateClassAndStateDiagramsForBoundedContexts(ContextMappingModel model, IFileSystemAccess2 fsa,
String fileName) {
for (BoundedContext boundedContext : model.getBoundedContexts()) {
// Get all bounded contexts, including those referenced in the context map
Set<BoundedContext> boundedContexts = new HashSet<>();
boundedContexts.addAll(model.getBoundedContexts());
if (model.getMap() != null) {
boundedContexts.addAll(model.getMap().getBoundedContexts());
}

for (BoundedContext boundedContext : boundedContexts) {
// class diagram for complete BC
fsa.generateFile(fileName + "_BC_" + boundedContext.getName() + "." + PLANT_UML_FILE_EXT,
new PlantUMLBoundedContextClassDiagramCreator().createDiagram(boundedContext));
Expand Down