use of com.structurizr.model.Container in project dsl by structurizr.
the class DynamicViewParser method parse.
DynamicView parse(DslContext context, Tokens tokens) {
// dynamic <*|software system identifier|container identifier> [key] [description] {
Workspace workspace = context.getWorkspace();
String key = "";
String description = "";
DecimalFormat format = new DecimalFormat("000");
if (tokens.hasMoreThan(DESCRIPTION_INDEX)) {
throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
}
if (!tokens.includes(SCOPE_IDENTIFIER_INDEX)) {
throw new RuntimeException("Expected: " + GRAMMAR);
}
if (tokens.includes(DESCRIPTION_INDEX)) {
description = tokens.get(DESCRIPTION_INDEX);
}
DynamicView view;
String scopeIdentifier = tokens.get(SCOPE_IDENTIFIER_INDEX);
if (WILDCARD.equals(scopeIdentifier)) {
if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = VIEW_TYPE + "-" + format.format(workspace.getViews().getDynamicViews().size() + 1);
}
validateViewKey(key);
view = workspace.getViews().createDynamicView(key, description);
} else {
Element element = context.getElement(scopeIdentifier);
if (element == null) {
throw new RuntimeException("The software system or container \"" + scopeIdentifier + "\" does not exist");
}
if (element instanceof SoftwareSystem) {
if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = removeNonWordCharacters(element.getName()) + "-" + VIEW_TYPE + "-" + format.format(workspace.getViews().getDynamicViews().size() + 1);
}
validateViewKey(key);
view = workspace.getViews().createDynamicView((SoftwareSystem) element, key, description);
} else if (element instanceof Container) {
Container container = (Container) element;
if (tokens.includes(KEY_INDEX)) {
key = tokens.get(KEY_INDEX);
} else {
key = removeNonWordCharacters(container.getSoftwareSystem().getName()) + "-" + removeNonWordCharacters(container.getName()) + "-" + VIEW_TYPE + "-" + format.format(workspace.getViews().getDynamicViews().size() + 1);
}
validateViewKey(key);
view = workspace.getViews().createDynamicView((Container) element, key, description);
} else {
throw new RuntimeException("The element \"" + scopeIdentifier + "\" is not a software system or container");
}
}
view.setExternalBoundariesVisible(true);
return view;
}
use of com.structurizr.model.Container in project dsl by structurizr.
the class ContainerParserTests method test_parseTechnology_ThrowsAnException_WhenThereAreTooManyTokens.
@Test
void test_parseTechnology_ThrowsAnException_WhenThereAreTooManyTokens() {
try {
Container container = model.addSoftwareSystem("Software System").addContainer("Container");
ContainerDslContext context = new ContainerDslContext(container);
parser.parseTechnology(context, tokens("technology", "technology", "extra"));
fail();
} catch (Exception e) {
assertEquals("Too many tokens, expected: technology <technology>", e.getMessage());
}
}
use of com.structurizr.model.Container in project dsl by structurizr.
the class ContainerParserTests method test_parse_CreatesAContainerWithADescription.
@Test
void test_parse_CreatesAContainerWithADescription() {
SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "Description");
SoftwareSystemDslContext context = new SoftwareSystemDslContext(softwareSystem);
parser.parse(context, tokens("container", "Name", "Description"));
assertEquals(2, model.getElements().size());
Container container = softwareSystem.getContainerWithName("Name");
assertNotNull(container);
assertEquals("Description", container.getDescription());
assertEquals("", container.getTechnology());
assertEquals("Element,Container", container.getTags());
}
use of com.structurizr.model.Container in project dsl by structurizr.
the class ContainerParserTests method test_parseTechnology_ThrowsAnException_WhenNoDescriptionIsSpecified.
@Test
void test_parseTechnology_ThrowsAnException_WhenNoDescriptionIsSpecified() {
try {
Container container = model.addSoftwareSystem("Software System").addContainer("Container");
ContainerDslContext context = new ContainerDslContext(container);
parser.parseTechnology(context, tokens("technology"));
fail();
} catch (Exception e) {
assertEquals("Expected: technology <technology>", e.getMessage());
}
}
use of com.structurizr.model.Container in project dsl by structurizr.
the class ContainerParserTests method test_parseTechnology_SetsTheDescription_WhenADescriptionIsSpecified.
@Test
void test_parseTechnology_SetsTheDescription_WhenADescriptionIsSpecified() {
Container container = model.addSoftwareSystem("Software System").addContainer("Container");
ContainerDslContext context = new ContainerDslContext(container);
parser.parseTechnology(context, tokens("technology", "Technology"));
assertEquals("Technology", container.getTechnology());
}
Aggregations