use of org.contextmapper.dsl.contextMappingDSL.Application in project context-mapper-dsl by ContextMapper.
the class PlantUMLBoundedContextClassDiagramCreatorTest method respectEventsAndCommandsAndServicesFromApplicationLayer.
@Test
public void respectEventsAndCommandsAndServicesFromApplicationLayer() {
// given
BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
Application app = ContextMappingDSLFactory.eINSTANCE.createApplication();
boundedContext.setApplication(app);
DomainEvent testEvent = TacticdslFactory.eINSTANCE.createDomainEvent();
testEvent.setName("TestEvent");
app.getEvents().add(testEvent);
CommandEvent testCommand = TacticdslFactory.eINSTANCE.createCommandEvent();
testCommand.setName("TestCommand");
app.getCommands().add(testCommand);
Service testService = TacticdslFactory.eINSTANCE.createService();
testService.setName("TestService");
app.getServices().add(testService);
// when
String plantUML = this.creator.createDiagram(boundedContext);
// then
assertTrue(plantUML.contains("package \"'Application'\" <<Rectangle>> {" + System.lineSeparator()));
assertTrue(plantUML.contains(" class TestEvent <<(E,#ff9f4b) Domain Event>> {" + System.lineSeparator() + " }" + System.lineSeparator()));
assertTrue(plantUML.contains(" class TestCommand <<(C,#3bc5e9) Command>> {" + System.lineSeparator() + " }" + System.lineSeparator()));
assertTrue(plantUML.contains(" class TestService <<(S,DarkSeaGreen) Service>> {" + System.lineSeparator() + " }" + System.lineSeparator()));
}
use of org.contextmapper.dsl.contextMappingDSL.Application in project context-mapper-dsl by ContextMapper.
the class MDSLModelCreator method checkPreconditions.
private void checkPreconditions() {
Map<String, UpstreamAPIContext> upstreamContexts = collectUpstreamContexts();
List<Aggregate> exposedAggregates = Lists.newArrayList();
List<Application> applications = Lists.newArrayList();
for (UpstreamAPIContext context : upstreamContexts.values()) {
exposedAggregates.addAll(context.getExposedAggregates());
if (context.getApplicationLayer() != null)
applications.add(context.getApplicationLayer());
}
if (exposedAggregates.isEmpty() && applications.isEmpty())
throw new GeneratorInputException("None of your upstream-downstream relationships exposes any Aggregates or application layers. Therefore there is nothing to generate. Use the 'exposedAggregates' attribute on your upstream-downstream relationships to specify which Aggregates are exposed by the upstream or model an 'Application' in your upstream.");
boolean atLeastOneAggregateWithAnOperation = false;
for (Aggregate exposedAggregate : exposedAggregates) {
Optional<DomainObject> aggregateRoot = exposedAggregate.getDomainObjects().stream().filter(o -> o instanceof DomainObject).map(o -> (DomainObject) o).filter(o -> o.isAggregateRoot()).findFirst();
if (aggregateRoot.isPresent() && !aggregateRoot.get().getOperations().isEmpty()) {
atLeastOneAggregateWithAnOperation = true;
break;
}
List<ServiceOperation> serviceOperations = exposedAggregate.getServices().stream().flatMap(s -> s.getOperations().stream()).collect(Collectors.toList());
if (!serviceOperations.isEmpty()) {
atLeastOneAggregateWithAnOperation = true;
break;
}
}
for (Application application : applications) {
if (!application.getCommands().isEmpty()) {
atLeastOneAggregateWithAnOperation = true;
break;
}
List<ServiceOperation> serviceOperations = application.getServices().stream().flatMap(s -> s.getOperations().stream()).collect(Collectors.toList());
if (!serviceOperations.isEmpty()) {
atLeastOneAggregateWithAnOperation = true;
break;
}
}
if (!atLeastOneAggregateWithAnOperation)
throw new GeneratorInputException("None of your exposed Aggregates contains either Service or 'Aggregate Root' operations/methods. Therefore there is nothing to generate. Add at least one operation/method to the 'Aggregate Root' or to a Service in one of your exposed Aggregates to get a result.");
}
use of org.contextmapper.dsl.contextMappingDSL.Application in project context-mapper-dsl by ContextMapper.
the class MDSLModelCreator method createEndpoint.
private EndpointContract createEndpoint(Application application, ServiceSpecification specification) {
EndpointContract endpoint = new EndpointContract();
String endpointName = StringUtils.isNoneEmpty(application.getName()) ? mdslEncoder.encodeName(application.getName()) : mdslEncoder.encodeName("Application");
endpoint.setName(endpointName);
List<ServiceOperation> serviceOperations = application.getServices().stream().flatMap(s -> s.getOperations().stream()).collect(Collectors.toList());
for (ServiceOperation serviceOperation : serviceOperations) {
if (serviceOperation.getVisibility().equals(Visibility.PUBLIC))
endpoint.addOperation(createOperation(serviceOperation, specification));
}
for (CommandEvent command : application.getCommands()) {
endpoint.addOperation(createOperation(command, specification));
}
return endpoint;
}
use of org.contextmapper.dsl.contextMappingDSL.Application in project context-mapper-dsl by ContextMapper.
the class PlantUMLBoundedContextClassDiagramCreatorTest method respectApplicationLayerName.
@Test
public void respectApplicationLayerName() {
// given
BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
Application app = ContextMappingDSLFactory.eINSTANCE.createApplication();
app.setName("MyAppLayer");
boundedContext.setApplication(app);
DomainEvent testEvent = TacticdslFactory.eINSTANCE.createDomainEvent();
testEvent.setName("TestEvent");
app.getEvents().add(testEvent);
// when
String plantUML = this.creator.createDiagram(boundedContext);
// then
assertTrue(plantUML.contains("package \"'MyAppLayer'\" <<Rectangle>> {" + System.lineSeparator()));
assertTrue(plantUML.contains(" class TestEvent <<(E,#ff9f4b) Domain Event>> {" + System.lineSeparator() + " }" + System.lineSeparator()));
}
Aggregations