Search in sources :

Example 1 with PlantUMLComponentDiagramCreator

use of org.contextmapper.dsl.generator.plantuml.PlantUMLComponentDiagramCreator in project context-mapper-dsl by ContextMapper.

the class PlantUMLComponentDiagramCreatorTest method canAddExposedAggregatesToServiceUsageLabel.

@Test
public void canAddExposedAggregatesToServiceUsageLabel() {
    // given
    ContextMap contextMap = ContextMappingDSLFactory.eINSTANCE.createContextMap();
    BoundedContext boundedContext1 = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    boundedContext1.setName("myContext1");
    Aggregate aggregate1 = ContextMappingDSLFactory.eINSTANCE.createAggregate();
    aggregate1.setName("ExposedAggregate1");
    Aggregate aggregate2 = ContextMappingDSLFactory.eINSTANCE.createAggregate();
    aggregate2.setName("ExposedAggregate2");
    boundedContext1.getAggregates().add(aggregate1);
    boundedContext1.getAggregates().add(aggregate2);
    BoundedContext boundedContext2 = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    boundedContext2.setName("myContext2");
    contextMap.getBoundedContexts().add(boundedContext1);
    contextMap.getBoundedContexts().add(boundedContext2);
    UpstreamDownstreamRelationship relationship = ContextMappingDSLFactory.eINSTANCE.createUpstreamDownstreamRelationship();
    relationship.setUpstream(boundedContext1);
    relationship.setDownstream(boundedContext2);
    relationship.getUpstreamExposedAggregates().add(aggregate1);
    contextMap.getRelationships().add(relationship);
    // when
    String plantUML1 = this.creator.createDiagram(contextMap);
    relationship.getUpstreamExposedAggregates().add(aggregate2);
    this.creator = new PlantUMLComponentDiagramCreator();
    String plantUML2 = this.creator.createDiagram(contextMap);
    // then
    assertTrue(plantUML1.contains("component [myContext1]" + System.lineSeparator()));
    assertTrue(plantUML1.contains("component [myContext2]" + System.lineSeparator()));
    assertTrue(plantUML1.contains("interface \"Upstream-Downstream\" as myContext2_to_myContext1" + System.lineSeparator()));
    assertTrue(plantUML1.contains("[myContext1] --> myContext2_to_myContext1" + System.lineSeparator()));
    assertTrue(plantUML1.contains("myContext2_to_myContext1 <.. [myContext2] : use Aggregate ExposedAggregate1 " + System.lineSeparator()));
    assertTrue(plantUML2.contains("myContext2_to_myContext1 <.. [myContext2] : use Aggregates ExposedAggregate1, ExposedAggregate2 " + System.lineSeparator()));
}
Also used : BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) PlantUMLComponentDiagramCreator(org.contextmapper.dsl.generator.plantuml.PlantUMLComponentDiagramCreator) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) Test(org.junit.jupiter.api.Test)

Example 2 with PlantUMLComponentDiagramCreator

use of org.contextmapper.dsl.generator.plantuml.PlantUMLComponentDiagramCreator in project context-mapper-dsl by ContextMapper.

the class PlantUMLGenerator method generateFromContextMappingModel.

@Override
protected void generateFromContextMappingModel(ContextMappingModel model, IFileSystemAccess2 fsa, URI inputFileURI) {
    checkPreconditions();
    String fileName = inputFileURI.trimFileExtension().lastSegment();
    // generate component diagram, if Context Map available
    if (model.getMap() != null)
        fsa.generateFile(fileName + "_ContextMap." + PLANT_UML_FILE_EXT, new PlantUMLComponentDiagramCreator().createDiagram(model.getMap()));
    // generate class and state diagrams for Bounded Contexts
    for (BoundedContext boundedContext : model.getBoundedContexts()) {
        // class diagram for complete BC
        fsa.generateFile(fileName + "_BC_" + boundedContext.getName() + "." + PLANT_UML_FILE_EXT, new PlantUMLBoundedContextClassDiagramCreator().createDiagram(boundedContext));
        // class diagram for aggregates
        for (Aggregate aggregate : boundedContext.getAggregates()) {
            fsa.generateFile(fileName + "_BC_" + boundedContext.getName() + "_" + aggregate.getName() + "." + PLANT_UML_FILE_EXT, new PlantUMLAggregateClassDiagramCreator().createDiagram(aggregate));
        }
        // class diagram for modules
        for (SculptorModule module : boundedContext.getModules()) {
            fsa.generateFile(fileName + "_BC_" + boundedContext.getName() + "_" + module.getName() + "." + PLANT_UML_FILE_EXT, new PlantUMLModuleClassDiagramCreator().createDiagram(module));
        }
        // state diagram for aggregates
        List<Aggregate> aggregatesWithStates = getAggregatesWithStatesAndTransitions(boundedContext);
        for (Aggregate aggregate : aggregatesWithStates) {
            fsa.generateFile(fileName + "_BC_" + boundedContext.getName() + "_" + aggregate.getName() + "_StateDiagram" + "." + PLANT_UML_FILE_EXT, new PlantUMLStateDiagramCreator4Aggregate().createDiagram(aggregate));
        }
        // state diagram for flows
        for (Flow flow : getFlowsWithStates(boundedContext)) {
            fsa.generateFile(fileName + "_BC_" + boundedContext.getName() + "_" + flow.getName() + "_StateDiagram." + PLANT_UML_FILE_EXT, new PlantUMLStateDiagramCreator4Flow().createDiagram(flow));
        }
    }
    // generate class diagrams for subdomains (that have entities)
    for (Domain domain : model.getDomains()) {
        domain.getSubdomains().stream().filter(subdomain -> !subdomain.getEntities().isEmpty()).forEach(subdomain -> {
            fsa.generateFile(fileName + "_SD_" + subdomain.getName() + "." + PLANT_UML_FILE_EXT, new PlantUMLSubdomainClassDiagramCreator(domain.getName()).createDiagram(subdomain));
        });
    }
}
Also used : PlantUMLModuleClassDiagramCreator(org.contextmapper.dsl.generator.plantuml.PlantUMLModuleClassDiagramCreator) IFileSystemAccess2(org.eclipse.xtext.generator.IFileSystemAccess2) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) URI(org.eclipse.emf.common.util.URI) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) StateTransition(org.contextmapper.tactic.dsl.tacticdsl.StateTransition) PlantUMLSubdomainClassDiagramCreator(org.contextmapper.dsl.generator.plantuml.PlantUMLSubdomainClassDiagramCreator) PlantUMLBoundedContextClassDiagramCreator(org.contextmapper.dsl.generator.plantuml.PlantUMLBoundedContextClassDiagramCreator) List(java.util.List) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) GeneratorInputException(org.contextmapper.dsl.generator.exception.GeneratorInputException) PlantUMLStateDiagramCreator4Flow(org.contextmapper.dsl.generator.plantuml.PlantUMLStateDiagramCreator4Flow) Lists(com.google.common.collect.Lists) PlantUMLAggregateClassDiagramCreator(org.contextmapper.dsl.generator.plantuml.PlantUMLAggregateClassDiagramCreator) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) PlantUMLComponentDiagramCreator(org.contextmapper.dsl.generator.plantuml.PlantUMLComponentDiagramCreator) Flow(org.contextmapper.dsl.contextMappingDSL.Flow) Optional(java.util.Optional) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) PlantUMLStateDiagramCreator4Aggregate(org.contextmapper.dsl.generator.plantuml.PlantUMLStateDiagramCreator4Aggregate) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) PlantUMLModuleClassDiagramCreator(org.contextmapper.dsl.generator.plantuml.PlantUMLModuleClassDiagramCreator) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) PlantUMLComponentDiagramCreator(org.contextmapper.dsl.generator.plantuml.PlantUMLComponentDiagramCreator) PlantUMLStateDiagramCreator4Flow(org.contextmapper.dsl.generator.plantuml.PlantUMLStateDiagramCreator4Flow) Flow(org.contextmapper.dsl.contextMappingDSL.Flow) PlantUMLSubdomainClassDiagramCreator(org.contextmapper.dsl.generator.plantuml.PlantUMLSubdomainClassDiagramCreator) PlantUMLAggregateClassDiagramCreator(org.contextmapper.dsl.generator.plantuml.PlantUMLAggregateClassDiagramCreator) PlantUMLStateDiagramCreator4Aggregate(org.contextmapper.dsl.generator.plantuml.PlantUMLStateDiagramCreator4Aggregate) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) PlantUMLBoundedContextClassDiagramCreator(org.contextmapper.dsl.generator.plantuml.PlantUMLBoundedContextClassDiagramCreator) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) PlantUMLStateDiagramCreator4Aggregate(org.contextmapper.dsl.generator.plantuml.PlantUMLStateDiagramCreator4Aggregate) PlantUMLStateDiagramCreator4Flow(org.contextmapper.dsl.generator.plantuml.PlantUMLStateDiagramCreator4Flow) Domain(org.contextmapper.dsl.contextMappingDSL.Domain)

Example 3 with PlantUMLComponentDiagramCreator

use of org.contextmapper.dsl.generator.plantuml.PlantUMLComponentDiagramCreator in project context-mapper-dsl by ContextMapper.

the class PlantUMLComponentDiagramCreatorTest method canAddExposedAggregatesToCustomerSupplierUsageLabel.

@Test
public void canAddExposedAggregatesToCustomerSupplierUsageLabel() {
    // given
    ContextMap contextMap = ContextMappingDSLFactory.eINSTANCE.createContextMap();
    BoundedContext boundedContext1 = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    boundedContext1.setName("myContext1");
    Aggregate aggregate1 = ContextMappingDSLFactory.eINSTANCE.createAggregate();
    aggregate1.setName("ExposedAggregate1");
    Aggregate aggregate2 = ContextMappingDSLFactory.eINSTANCE.createAggregate();
    aggregate2.setName("ExposedAggregate2");
    boundedContext1.getAggregates().add(aggregate1);
    boundedContext1.getAggregates().add(aggregate2);
    BoundedContext boundedContext2 = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    boundedContext2.setName("myContext2");
    contextMap.getBoundedContexts().add(boundedContext1);
    contextMap.getBoundedContexts().add(boundedContext2);
    UpstreamDownstreamRelationship relationship = ContextMappingDSLFactory.eINSTANCE.createCustomerSupplierRelationship();
    relationship.setUpstream(boundedContext1);
    relationship.setDownstream(boundedContext2);
    relationship.getUpstreamExposedAggregates().add(aggregate1);
    contextMap.getRelationships().add(relationship);
    // when
    String plantUML1 = this.creator.createDiagram(contextMap);
    relationship.getUpstreamExposedAggregates().add(aggregate2);
    this.creator = new PlantUMLComponentDiagramCreator();
    String plantUML2 = this.creator.createDiagram(contextMap);
    // then
    assertTrue(plantUML1.contains("component [myContext1]" + System.lineSeparator()));
    assertTrue(plantUML1.contains("component [myContext2]" + System.lineSeparator()));
    assertTrue(plantUML1.contains("interface \"Customer-Supplier\" as myContext2_to_myContext1" + System.lineSeparator()));
    assertTrue(plantUML1.contains("[myContext1] --> myContext2_to_myContext1 : Supplier" + System.lineSeparator()));
    assertTrue(plantUML1.contains("myContext2_to_myContext1 <.. [myContext2] : Customer of Aggregate ExposedAggregate1 " + System.lineSeparator()));
    assertTrue(plantUML2.contains("myContext2_to_myContext1 <.. [myContext2] : Customer of Aggregates ExposedAggregate1, ExposedAggregate2 " + System.lineSeparator()));
}
Also used : BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) PlantUMLComponentDiagramCreator(org.contextmapper.dsl.generator.plantuml.PlantUMLComponentDiagramCreator) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) Test(org.junit.jupiter.api.Test)

Aggregations

Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)3 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)3 PlantUMLComponentDiagramCreator (org.contextmapper.dsl.generator.plantuml.PlantUMLComponentDiagramCreator)3 ContextMap (org.contextmapper.dsl.contextMappingDSL.ContextMap)2 UpstreamDownstreamRelationship (org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship)2 Test (org.junit.jupiter.api.Test)2 Lists (com.google.common.collect.Lists)1 List (java.util.List)1 Optional (java.util.Optional)1 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)1 Domain (org.contextmapper.dsl.contextMappingDSL.Domain)1 Flow (org.contextmapper.dsl.contextMappingDSL.Flow)1 SculptorModule (org.contextmapper.dsl.contextMappingDSL.SculptorModule)1 Subdomain (org.contextmapper.dsl.contextMappingDSL.Subdomain)1 GeneratorInputException (org.contextmapper.dsl.generator.exception.GeneratorInputException)1 PlantUMLAggregateClassDiagramCreator (org.contextmapper.dsl.generator.plantuml.PlantUMLAggregateClassDiagramCreator)1 PlantUMLBoundedContextClassDiagramCreator (org.contextmapper.dsl.generator.plantuml.PlantUMLBoundedContextClassDiagramCreator)1 PlantUMLModuleClassDiagramCreator (org.contextmapper.dsl.generator.plantuml.PlantUMLModuleClassDiagramCreator)1 PlantUMLStateDiagramCreator4Aggregate (org.contextmapper.dsl.generator.plantuml.PlantUMLStateDiagramCreator4Aggregate)1 PlantUMLStateDiagramCreator4Flow (org.contextmapper.dsl.generator.plantuml.PlantUMLStateDiagramCreator4Flow)1