use of com.structurizr.model.Container in project dsl by structurizr.
the class DynamicViewParserTests method test_parse_CreatesADynamicViewWithContainerScopeAndKey.
@Test
void test_parse_CreatesADynamicViewWithContainerScopeAndKey() {
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", "key"));
List<DynamicView> views = new ArrayList<>(this.views.getDynamicViews());
assertEquals(1, views.size());
assertEquals("key", views.get(0).getKey());
assertEquals("", views.get(0).getDescription());
assertSame(container, views.get(0).getElement());
}
use of com.structurizr.model.Container in project dsl by structurizr.
the class DynamicViewParserTests method test_parse_CreatesADynamicViewWithContainerScopeAndKeyAndDescription.
@Test
void test_parse_CreatesADynamicViewWithContainerScopeAndKeyAndDescription() {
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", "key", "Description"));
List<DynamicView> views = new ArrayList<>(this.views.getDynamicViews());
assertEquals(1, views.size());
assertEquals("key", views.get(0).getKey());
assertEquals("Description", views.get(0).getDescription());
assertSame(container, views.get(0).getElement());
}
use of com.structurizr.model.Container in project dsl by structurizr.
the class ComponentParserTests method test_parse_CreatesAComponentWithADescription.
@Test
void test_parse_CreatesAComponentWithADescription() {
SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "Description");
Container container = softwareSystem.addContainer("Container", "Description", "Technology");
ContainerDslContext context = new ContainerDslContext(container);
parser.parse(context, tokens("component", "Name", "Description"));
assertEquals(3, model.getElements().size());
Component component = container.getComponentWithName("Name");
assertNotNull(component);
assertEquals("Description", component.getDescription());
assertEquals(null, component.getTechnology());
assertEquals("Element,Component", component.getTags());
}
use of com.structurizr.model.Container in project dsl by structurizr.
the class ComponentParserTests method test_parse_CreatesAComponent.
@Test
void test_parse_CreatesAComponent() {
SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System", "Description");
Container container = softwareSystem.addContainer("Container", "Description", "Technology");
ContainerDslContext context = new ContainerDslContext(container);
parser.parse(context, tokens("component", "Name"));
assertEquals(3, model.getElements().size());
Component component = container.getComponentWithName("Name");
assertNotNull(component);
assertEquals("", component.getDescription());
assertEquals(null, component.getTechnology());
assertEquals("Element,Component", component.getTags());
}
use of com.structurizr.model.Container in project dsl by structurizr.
the class ContainerParser method parse.
Container parse(SoftwareSystemDslContext context, Tokens tokens) {
if (tokens.hasMoreThan(TAGS_INDEX)) {
throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
}
if (!tokens.includes(NAME_INDEX)) {
throw new RuntimeException("Expected: " + GRAMMAR);
}
SoftwareSystem softwareSystem = context.getSoftwareSystem();
Container container = null;
String name = tokens.get(NAME_INDEX);
if (context.isExtendingWorkspace()) {
container = softwareSystem.getContainerWithName(name);
}
if (container == null) {
container = softwareSystem.addContainer(name);
}
if (tokens.includes(DESCRIPTION_INDEX)) {
String description = tokens.get(DESCRIPTION_INDEX);
container.setDescription(description);
}
if (tokens.includes(TECHNOLOGY_INDEX)) {
String technology = tokens.get(TECHNOLOGY_INDEX);
container.setTechnology(technology);
}
if (tokens.includes(TAGS_INDEX)) {
String tags = tokens.get(TAGS_INDEX);
container.addTags(tags.split(","));
}
if (context.hasGroup()) {
container.setGroup(context.getGroup().getName());
context.getGroup().addElement(container);
}
return container;
}
Aggregations