Search in sources :

Example 11 with Flow

use of org.contextmapper.dsl.contextMappingDSL.Flow in project context-mapper-dsl by ContextMapper.

the class SketchMinerModelCreatorTest method canAddStateTransitionCommentWithMultipleStates.

@Test
public void canAddStateTransitionCommentWithMultipleStates() throws IOException {
    // given
    ContextMappingModel model = getOriginalResourceOfTestCML("state-transition-comment-test-2.cml").getContextMappingModel();
    Flow flow = EcoreUtil2.eAllOfType(model, Flow.class).get(0);
    // when
    String output = new SketchMinerModelCreator().createText(flow);
    // then
    assertEquals("TestContext Application:" + System.lineSeparator() + System.lineSeparator() + "(StartEvent)" + System.lineSeparator() + "// TestAggregate [STATE1, STATE2 -> STATE3 X STATE4]" + System.lineSeparator() + "service Command1" + System.lineSeparator() + "(EndEvent)" + System.lineSeparator() + System.lineSeparator(), output);
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) SketchMinerModelCreator(org.contextmapper.dsl.generator.sketchminer.SketchMinerModelCreator) Flow(org.contextmapper.dsl.contextMappingDSL.Flow) Test(org.junit.jupiter.api.Test) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with Flow

use of org.contextmapper.dsl.contextMappingDSL.Flow in project context-mapper-dsl by ContextMapper.

the class SketchMinerModelCreatorTest method canRespectOrderOfSeparateSequences.

@Test
public void canRespectOrderOfSeparateSequences() throws IOException {
    // given
    ContextMappingModel model = getOriginalResourceOfTestCML("order-of-separate-sequences-test-1.cml").getContextMappingModel();
    Flow flow = EcoreUtil.copy(EcoreUtil2.eAllOfType(model, Flow.class).get(0));
    // when
    String output = new SketchMinerModelCreator().createText(flow);
    // then
    assertEquals("Application:" + System.lineSeparator() + System.lineSeparator() + "service appop1" + System.lineSeparator() + "(DE1)" + System.lineSeparator() + System.lineSeparator() + "service appop2" + System.lineSeparator() + "(DE2)" + System.lineSeparator() + System.lineSeparator(), output);
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) SketchMinerModelCreator(org.contextmapper.dsl.generator.sketchminer.SketchMinerModelCreator) Flow(org.contextmapper.dsl.contextMappingDSL.Flow) Test(org.junit.jupiter.api.Test) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with Flow

use of org.contextmapper.dsl.contextMappingDSL.Flow in project context-mapper-dsl by ContextMapper.

the class SketchMinerModelCreatorTest method canGenerateSimpleSequenceStartingWithCommand.

@ParameterizedTest
@ValueSource(strings = { "simple-sequence-test-1", "simple-sequence-test-2" })
public void canGenerateSimpleSequenceStartingWithCommand(String inputFileName) throws IOException {
    // given
    ContextMappingModel model = getOriginalResourceOfTestCML(inputFileName + ".cml").getContextMappingModel();
    Flow flow = EcoreUtil2.eAllOfType(model, Flow.class).get(0);
    // when
    String output = new SketchMinerModelCreator().createText(flow);
    // then
    assertEquals("TestContext Application:" + System.lineSeparator() + System.lineSeparator() + "service StartCommand" + System.lineSeparator() + "(FirstEvent)" + System.lineSeparator() + "service EndCommand" + System.lineSeparator() + System.lineSeparator(), output);
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) SketchMinerModelCreator(org.contextmapper.dsl.generator.sketchminer.SketchMinerModelCreator) Flow(org.contextmapper.dsl.contextMappingDSL.Flow) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with Flow

use of org.contextmapper.dsl.contextMappingDSL.Flow in project context-mapper-dsl by ContextMapper.

the class MDSLModelCreator method createServiceSpecification.

private ServiceSpecification createServiceSpecification(String apiName, UpstreamAPIContext context) {
    ServiceSpecification specification = new ServiceSpecification();
    specification.setName(mdslEncoder.encodeName(apiName));
    if (context.getUpstreamRoles().contains(UpstreamRole.OPEN_HOST_SERVICE) && context.getUpstreamRoles().contains(UpstreamRole.PUBLISHED_LANGUAGE)) {
        specification.setUsageContext(APIUsageContext.PUBLIC_API);
    } else if (context.getUpstreamRoles().contains(UpstreamRole.OPEN_HOST_SERVICE)) {
        specification.setUsageContext(APIUsageContext.COMMUNITY_API);
    }
    if (context.getApplicationLayer() != null) {
        specification.addEndpoint(createEndpoint(context.getApplicationLayer(), specification));
        for (DomainEvent de : context.getApplicationLayer().getEvents()) {
            specification.addEventType(de.getName());
        // TODO map data structure, not just name (if present)
        }
        // add event types for all domain events in all exposed aggregates
        for (Aggregate exposedAggregate : context.getExposedAggregates()) {
            for (SimpleDomainObject objectInAggregate : exposedAggregate.getDomainObjects()) {
                // check type of domain object (entity? event?...?):
                if (objectInAggregate instanceof DomainEvent) {
                    DomainEvent de = (DomainEvent) objectInAggregate;
                    // TODO make sure names are unique/do not add duplicates
                    specification.addEventType(de.getName());
                }
            }
        }
        for (CommandEvent ce : context.getApplicationLayer().getCommands()) {
            specification.addCommandType(ce.getName());
        }
        EList<Flow> flows = context.getApplicationLayer().getFlows();
        for (Flow cmlFlow : flows) {
            OrchestrationFlow mdslFlow = new OrchestrationFlow();
            mdslFlow.setName(cmlFlow.getName());
            for (FlowStep step : cmlFlow.getSteps()) {
                mapFlowStep(mdslFlow, step);
            }
            specification.addFlow(mdslFlow);
        }
    }
    for (Aggregate aggregate : context.getExposedAggregates()) {
        specification.addEndpoint(createEndpoint(aggregate, specification));
    }
    for (DataType dataType : dataTypeCreator.getAllDataTypes()) {
        specification.addDataType(dataType);
    }
    specification.addProvider(createProvider(context, specification.getEndpoints()));
    for (DownstreamContext downstreamContext : context.getDownstreamContexts()) {
        specification.addClient(createClient(downstreamContext));
    }
    return specification;
}
Also used : ServiceSpecification(org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification) DomainEvent(org.contextmapper.tactic.dsl.tacticdsl.DomainEvent) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) CommandEvent(org.contextmapper.tactic.dsl.tacticdsl.CommandEvent) OrchestrationFlow(org.contextmapper.dsl.generator.mdsl.model.OrchestrationFlow) DataType(org.contextmapper.dsl.generator.mdsl.model.DataType) FlowStep(org.contextmapper.dsl.contextMappingDSL.FlowStep) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) DownstreamContext(org.contextmapper.dsl.generator.mdsl.generatorcontext.DownstreamContext) OrchestrationFlow(org.contextmapper.dsl.generator.mdsl.model.OrchestrationFlow) Flow(org.contextmapper.dsl.contextMappingDSL.Flow)

Example 15 with Flow

use of org.contextmapper.dsl.contextMappingDSL.Flow 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)

Aggregations

Flow (org.contextmapper.dsl.contextMappingDSL.Flow)30 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)26 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)21 SketchMinerModelCreator (org.contextmapper.dsl.generator.sketchminer.SketchMinerModelCreator)21 Test (org.junit.jupiter.api.Test)21 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 SketchMinerLinkCreator (org.contextmapper.dsl.generator.sketchminer.SketchMinerLinkCreator)5 DisabledOnOs (org.junit.jupiter.api.condition.DisabledOnOs)4 ValueSource (org.junit.jupiter.params.provider.ValueSource)4 List (java.util.List)2 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)2 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)2 PlantUMLStateDiagramCreator4Flow (org.contextmapper.dsl.generator.plantuml.PlantUMLStateDiagramCreator4Flow)2 StateTransition (org.contextmapper.tactic.dsl.tacticdsl.StateTransition)2 EObject (org.eclipse.emf.ecore.EObject)2 Lists (com.google.common.collect.Lists)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Domain (org.contextmapper.dsl.contextMappingDSL.Domain)1 DomainEventProductionStep (org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep)1