Skip to content

Commit

Permalink
Value Impact Map generator
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-ka committed Aug 13, 2024
1 parent e9161d2 commit fe81d75
Show file tree
Hide file tree
Showing 12 changed files with 595 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ValueRegister SD_Values for SameDayDelivery {

Value WorkLifeBalance {
isCore
demonstrator "Drivers value a healthy work-life-balance"
Stakeholder Drivers {
priority HIGH
impact HIGH
consequences
bad "SDD will harm work-life-balance of drivers"
action "hire more drivers" ACT
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ void canCreatePlantUMLDiagramFiles() {

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

// then
assertTrue(filesystem.getGeneratedFilesSet().contains("testmodel_ContextMap.puml"));
Expand All @@ -85,7 +86,8 @@ void canCreateBoundedContextClassDiagramsWithoutContextMap() {

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

// then
assertTrue(filesystem.getGeneratedFilesSet().contains("testmodel_BC_TestContext.puml"));
Expand All @@ -108,7 +110,8 @@ void canCreatePlantUMLDiagrmFiles4SubdomainIfEntitiesAvailable() {

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

// then
assertFalse(filesystem.getGeneratedFilesSet().contains("testmodel_SD_TestSubdomain1.puml"));
Expand All @@ -118,100 +121,133 @@ void canCreatePlantUMLDiagrmFiles4SubdomainIfEntitiesAvailable() {
@Test
void canCreateStateDiagram4ApplicationFlowIfAvailable() throws IOException {
// given
ContextMappingModel model = getOriginalResourceOfTestCML("state-diagram-generation-flow-test.cml").getContextMappingModel();
ContextMappingModel model = getOriginalResourceOfTestCML("state-diagram-generation-flow-test.cml")
.getContextMappingModel();

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

// then
assertTrue(filesystem.getGeneratedFilesSet().contains("testmodel_BC_InsuranceQuotes_QuoteFlow_StateDiagram.puml"));
assertTrue(
filesystem.getGeneratedFilesSet().contains("testmodel_BC_InsuranceQuotes_QuoteFlow_StateDiagram.puml"));
}

@Test
void canCreateClass4AggregateIfAvailable() throws IOException {
// given
ContextMappingModel model = getOriginalResourceOfTestCML("class-diagram-generation-aggregate-test-1.cml").getContextMappingModel();
ContextMappingModel model = getOriginalResourceOfTestCML("class-diagram-generation-aggregate-test-1.cml")
.getContextMappingModel();

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

// then
assertTrue(filesystem.getGeneratedFilesSet().contains("testmodel_BC_InsuranceQuotes_QuoteRequest.puml"));
}

@Test
void canCreateClass4ModuleIfAvailable() throws IOException {
// given
ContextMappingModel model = getOriginalResourceOfTestCML("class-diagram-generation-module-test-1.cml").getContextMappingModel();
ContextMappingModel model = getOriginalResourceOfTestCML("class-diagram-generation-module-test-1.cml")
.getContextMappingModel();

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

// then
assertTrue(filesystem.getGeneratedFilesSet().contains("testmodel_BC_InsuranceQuotes_QuoteRequest.puml"));
}

@Test
void canCreateStateDiagram4AggregateIfAvailable() throws IOException {
// given
ContextMappingModel model = getOriginalResourceOfTestCML("state-diagram-generation-aggregate-test-1.cml").getContextMappingModel();
ContextMappingModel model = getOriginalResourceOfTestCML("state-diagram-generation-aggregate-test-1.cml")
.getContextMappingModel();

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

// then
assertTrue(filesystem.getGeneratedFilesSet().contains("testmodel_BC_InsuranceQuotes_QuoteRequest_StateDiagram.puml"));
assertTrue(filesystem.getGeneratedFilesSet()
.contains("testmodel_BC_InsuranceQuotes_QuoteRequest_StateDiagram.puml"));
}

@Test
void canCreateUseCaseDiagram4UseCasesIfAvailable() throws IOException {
// given
ContextMappingModel model = getOriginalResourceOfTestCML("use-case-diagram-generation-test-1.cml").getContextMappingModel();
ContextMappingModel model = getOriginalResourceOfTestCML("use-case-diagram-generation-test-1.cml")
.getContextMappingModel();

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

// then
assertTrue(filesystem.getGeneratedFilesSet().contains("testmodel_UseCases.puml"));
}

@Test
void canCreateSequenceDiagram4UseCaseInteractionsIfAvailable() throws IOException {
// given
ContextMappingModel model = getOriginalResourceOfTestCML("use-case-diagram-generation-test-1.cml").getContextMappingModel();
ContextMappingModel model = getOriginalResourceOfTestCML("use-case-diagram-generation-test-1.cml")
.getContextMappingModel();

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

// then
assertTrue(filesystem.getGeneratedFilesSet().contains("testmodel_UseCase_Get_paid_for_car_accident_Interactions.puml"));
assertTrue(filesystem.getGeneratedFilesSet()
.contains("testmodel_UseCase_Get_paid_for_car_accident_Interactions.puml"));
}

@Test
void canCreateStakeholderDiagramsIfStakeholdersAreAvailable() throws IOException {
// given
ContextMappingModel model = getOriginalResourceOfTestCML("stakeholder-diagram-generation-test-1.cml").getContextMappingModel();

ContextMappingModel model = getOriginalResourceOfTestCML("stakeholder-diagram-generation-test-1.cml")
.getContextMappingModel();

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

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

// then
assertTrue(filesystem.getGeneratedFilesSet().contains("testmodel_BC_System-of-Interest_StakeholderMap-1.puml"));
}

@Test
void canCreateValueImpactMapDiagramsIfValueRegistersAreAvailable() throws IOException {
// given
ContextMappingModel model = getOriginalResourceOfTestCML("value-impact-map-diagram-generation-test-1.cml")
.getContextMappingModel();

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

// then
assertTrue(
filesystem.getGeneratedFilesSet().contains("testmodel_ValueRegister_SD_Values_Value-Impact-Map.puml"));
}

@Test
void expectExceptionForEmptyResource() {
IFileSystemAccess2Mock filesystem = new IFileSystemAccess2Mock();
assertThrows(GeneratorInputException.class, () -> {
this.generator.doGenerate(new ContextMappingModelResourceMock(null, "testmodel", "cml"), filesystem, new IGeneratorContextMock());
this.generator.doGenerate(new ContextMappingModelResourceMock(null, "testmodel", "cml"), filesystem,
new IGeneratorContextMock());
});
}

Expand All @@ -220,7 +256,8 @@ void expectExceptionForEmptyContextMappingModel() {
ContextMappingModel model = ContextMappingDSLFactory.eINSTANCE.createContextMappingModel();
IFileSystemAccess2Mock filesystem = new IFileSystemAccess2Mock();
assertThrows(GeneratorInputException.class, () -> {
this.generator.doGenerate(new ContextMappingModelResourceMock(model, "testmodel", "cml"), filesystem, new IGeneratorContextMock());
this.generator.doGenerate(new ContextMappingModelResourceMock(model, "testmodel", "cml"), filesystem,
new IGeneratorContextMock());
});
}

Expand All @@ -232,7 +269,8 @@ void expectExceptionIfThereIsOnlyAnEmptyDomain() {
model.getDomains().add(emptyDomain);
IFileSystemAccess2Mock filesystem = new IFileSystemAccess2Mock();
assertThrows(GeneratorInputException.class, () -> {
this.generator.doGenerate(new ContextMappingModelResourceMock(model, "testmodel", "cml"), filesystem, new IGeneratorContextMock());
this.generator.doGenerate(new ContextMappingModelResourceMock(model, "testmodel", "cml"), filesystem,
new IGeneratorContextMock());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.contextmapper.dsl.contextMappingDSL.Stakeholders;
import org.contextmapper.dsl.contextMappingDSL.UseCase;
import org.contextmapper.dsl.contextMappingDSL.UserRequirement;
import org.contextmapper.dsl.contextMappingDSL.ValueRegister;
import org.contextmapper.dsl.generator.exception.GeneratorInputException;
import org.contextmapper.dsl.generator.plantuml.PlantUMLAggregateClassDiagramCreator;
import org.contextmapper.dsl.generator.plantuml.PlantUMLBoundedContextClassDiagramCreator;
Expand All @@ -38,6 +39,7 @@
import org.contextmapper.dsl.generator.plantuml.PlantUMLSubdomainClassDiagramCreator;
import org.contextmapper.dsl.generator.plantuml.PlantUMLUseCaseDiagramCreator;
import org.contextmapper.dsl.generator.plantuml.PlantUMLUseCaseInteractionsSequenceDiagramCreator;
import org.contextmapper.dsl.generator.plantuml.PlantUMLValueImpactMapGenerator;
import org.contextmapper.tactic.dsl.tacticdsl.StateTransition;
import org.eclipse.emf.common.util.URI;
import org.eclipse.xtext.EcoreUtil2;
Expand All @@ -64,6 +66,7 @@ protected void generateFromContextMappingModel(ContextMappingModel model, IFileS
generateUseCaseDiagram(model, fsa, fileName);
generateSequenceDiagramsForUseCases(model, fsa, fileName);
generateStakeholderDiagrams(model, fsa, fileName);
generateValueImpactMapsForValueRegisters(model, fsa, fileName);
}

private void generateStakeholderDiagrams(ContextMappingModel model, IFileSystemAccess2 fsa, String fileName) {
Expand All @@ -78,6 +81,18 @@ private void generateStakeholderDiagrams(ContextMappingModel model, IFileSystemA
}
}

private void generateValueImpactMapsForValueRegisters(ContextMappingModel model, IFileSystemAccess2 fsa,
String fileName) {
for (ValueRegister valueRegister : model.getValueRegisters()) {
if (!(valueRegister.getValueClusters().isEmpty() && valueRegister.getValues().isEmpty())) {
fsa.generateFile(
fileName + "_ValueRegister_" + valueRegister.getName() + "_Value-Impact-Map" + "."
+ PLANT_UML_FILE_EXT,
new PlantUMLValueImpactMapGenerator().createDiagram(valueRegister));
}
}
}

private void generateSequenceDiagramsForUseCases(ContextMappingModel model, IFileSystemAccess2 fsa,
String fileName) {
for (UserRequirement userRequirement : model.getUserRequirements()) {
Expand Down Expand Up @@ -155,7 +170,8 @@ private void generateComponentDiagramIfContextMapAvailable(ContextMappingModel m
private void checkPreconditions() {
if (this.contextMappingModel.getMap() == null && this.contextMappingModel.getBoundedContexts().isEmpty()
&& !modelHasSubdomainWithEntities() && this.contextMappingModel.getUserRequirements().isEmpty()
&& this.contextMappingModel.getStakeholders().isEmpty())
&& this.contextMappingModel.getStakeholders().isEmpty()
&& this.contextMappingModel.getValueRegisters().isEmpty())
throw new GeneratorInputException(
"Your model does not contain a) a Context Map, b) Bounded Contexts or Subdomains with domain objects (Entities, Value Objects, etc.), c) Use Cases or User Stories, or d) Stakeholders or Value Registers. Create at least one of the mentioned model elements.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2024 The Context Mapper Project Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.contextmapper.dsl.generator.plantuml;

import org.contextmapper.dsl.contextMappingDSL.ValueRegister;
import org.contextmapper.dsl.generator.plantuml.value_impact_mapping.CML2ValueImpactModelMapper;
import org.contextmapper.dsl.generator.plantuml.value_impact_mapping.ValueImpactMapPumlTextCreator;

public class PlantUMLValueImpactMapGenerator implements PlantUMLDiagramCreator<ValueRegister> {

@Override
public String createDiagram(ValueRegister valueRegister) {
return new ValueImpactMapPumlTextCreator().createText(new CML2ValueImpactModelMapper().map(valueRegister));
}

}
Loading

0 comments on commit fe81d75

Please sign in to comment.