use of com.structurizr.view.DynamicView in project dsl by structurizr.
the class ViewParserTests method test_parseTitle_SetsTheTitleOfADynamicView.
@Test
void test_parseTitle_SetsTheTitleOfADynamicView() {
DynamicView view = workspace.getViews().createDynamicView("key", "description");
DynamicViewDslContext context = new DynamicViewDslContext(view);
context.setWorkspace(workspace);
assertNull(view.getTitle());
parser.parseTitle(context, tokens("title", "A new title"));
assertEquals("A new title", view.getTitle());
}
use of com.structurizr.view.DynamicView in project kroki by yuzutech.
the class Structurizr method convert.
static byte[] convert(String source, FileFormat fileFormat, StructurizrPlantUMLExporter structurizrPlantUMLExporter, JsonObject options) {
StructurizrDslParser parser = new StructurizrDslParser();
try {
parser.parse(source);
Collection<View> views = parser.getWorkspace().getViews().getViews();
if (views.isEmpty()) {
throw new BadRequestException("Empty diagram, does not have any view.");
}
View selectedView;
String viewKey = options.getString("view-key");
if (viewKey != null && !viewKey.trim().isEmpty()) {
Optional<View> viewFound = views.stream().filter(view -> Objects.equals(view.getKey(), viewKey)).findFirst();
if (!viewFound.isPresent()) {
throw new BadRequestException("Unable to find view for key: " + viewKey + ".");
}
selectedView = viewFound.get();
} else {
// take the first view if not specified
selectedView = views.iterator().next();
}
final Diagram diagram;
if (selectedView instanceof DynamicView) {
diagram = structurizrPlantUMLExporter.export((DynamicView) selectedView);
} else if (selectedView instanceof DeploymentView) {
diagram = structurizrPlantUMLExporter.export((DeploymentView) selectedView);
} else if (selectedView instanceof ComponentView) {
diagram = structurizrPlantUMLExporter.export((ComponentView) selectedView);
} else if (selectedView instanceof ContainerView) {
diagram = structurizrPlantUMLExporter.export((ContainerView) selectedView);
} else if (selectedView instanceof SystemContextView) {
diagram = structurizrPlantUMLExporter.export((SystemContextView) selectedView);
} else if (selectedView instanceof SystemLandscapeView) {
diagram = structurizrPlantUMLExporter.export((SystemLandscapeView) selectedView);
} else {
throw new BadRequestException("View type is not supported: " + selectedView.getClass().getSimpleName() + ", must be a DynamicView, DeploymentView, ComponentView, ContainerView, SystemContextView or SystemLandscapeView.");
}
return Plantuml.convert(diagram.getDefinition(), fileFormat, new JsonObject());
} catch (StructurizrDslParserException e) {
String cause = e.getMessage();
final String message;
if (cause != null && !cause.trim().isEmpty()) {
message = "Unable to parse the Structurizr DSL. " + cause + ".";
} else {
message = "Unable to parse the Structurizr DSL.";
}
throw new BadRequestException(message, e);
}
}
use of com.structurizr.view.DynamicView in project dsl by structurizr.
the class DynamicViewParserTests method test_parse_CreatesADynamicViewWithContainerScope.
@Test
void test_parse_CreatesADynamicViewWithContainerScope() {
DslContext context = context();
IdentifiersRegister elements = new IdentifiersRegister();
Container container = model.addSoftwareSystem("Name", "Description").addContainer("Container", "Description", "Technology");
elements.register("container", container);
context.setIdentifierRegister(elements);
parser.parse(context, tokens("dynamic", "container"));
List<DynamicView> views = new ArrayList<>(this.views.getDynamicViews());
assertEquals(1, views.size());
assertEquals("Name-Container-Dynamic-001", views.get(0).getKey());
assertEquals("", views.get(0).getDescription());
assertSame(container, views.get(0).getElement());
}
use of com.structurizr.view.DynamicView in project dsl by structurizr.
the class DynamicViewParserTests method test_parse_CreatesADynamicViewWithSoftwareSystemScope.
@Test
void test_parse_CreatesADynamicViewWithSoftwareSystemScope() {
DslContext context = context();
IdentifiersRegister elements = new IdentifiersRegister();
SoftwareSystem softwareSystem = model.addSoftwareSystem("Name", "Description");
elements.register("softwaresystem", softwareSystem);
context.setIdentifierRegister(elements);
parser.parse(context, tokens("dynamic", "softwareSystem"));
List<DynamicView> views = new ArrayList<>(this.views.getDynamicViews());
assertEquals(1, views.size());
assertEquals("Name-Dynamic-001", views.get(0).getKey());
assertEquals("", views.get(0).getDescription());
assertSame(softwareSystem, views.get(0).getElement());
}
use of com.structurizr.view.DynamicView in project dsl by structurizr.
the class DynamicViewContentParserTests method test_parseRelationship_AddsTheRelationshipWithTheSpecifiedTechnologyToTheView_WhenItAlreadyExistsInTheModel.
@Test
void test_parseRelationship_AddsTheRelationshipWithTheSpecifiedTechnologyToTheView_WhenItAlreadyExistsInTheModel() {
Person user = model.addPerson("User", "Description");
SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "Description");
Relationship r1 = user.uses(softwareSystem, "Uses 1", "Tech 1");
Relationship r2 = user.uses(softwareSystem, "Uses 2", "Tech 2");
DynamicView view = views.createDynamicView("key", "Description");
DynamicViewDslContext context = new DynamicViewDslContext(view);
IdentifiersRegister elements = new IdentifiersRegister();
elements.register("source", user);
elements.register("destination", softwareSystem);
context.setIdentifierRegister(elements);
parser.parseRelationship(context, tokens("source", "->", "destination", "Description", "Tech 2"));
assertEquals(1, view.getRelationships().size());
RelationshipView rv = view.getRelationships().iterator().next();
assertSame(r2, rv.getRelationship());
assertSame(user, rv.getRelationship().getSource());
assertSame(softwareSystem, rv.getRelationship().getDestination());
assertEquals("Description", rv.getDescription());
assertEquals("1", rv.getOrder());
}
Aggregations