use of com.structurizr.model.Component 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.Component in project dsl by structurizr.
the class ComponentParserTests method test_parseTechnology_ThrowsAnException_WhenNoDescriptionIsSpecified.
@Test
void test_parseTechnology_ThrowsAnException_WhenNoDescriptionIsSpecified() {
try {
Component component = model.addSoftwareSystem("Software System").addContainer("Container").addComponent("Component");
ComponentDslContext context = new ComponentDslContext(component);
parser.parseTechnology(context, tokens("technology"));
fail();
} catch (Exception e) {
assertEquals("Expected: technology <technology>", e.getMessage());
}
}
use of com.structurizr.model.Component 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.Component in project dsl by structurizr.
the class ComponentParserTests method test_parseTechnology_ThrowsAnException_WhenThereAreTooManyTokens.
@Test
void test_parseTechnology_ThrowsAnException_WhenThereAreTooManyTokens() {
try {
Component component = model.addSoftwareSystem("Software System").addContainer("Container").addComponent("Component");
ComponentDslContext context = new ComponentDslContext(component);
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.Component in project dsl by structurizr.
the class ComponentParser method parse.
Component parse(ContainerDslContext 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);
}
Container container = context.getContainer();
Component component = null;
String name = tokens.get(NAME_INDEX);
if (context.isExtendingWorkspace()) {
component = container.getComponentWithName(name);
}
if (component == null) {
component = container.addComponent(name);
}
if (tokens.includes(DESCRIPTION_INDEX)) {
String description = tokens.get(DESCRIPTION_INDEX);
component.setDescription(description);
}
if (tokens.includes(TECHNOLOGY_INDEX)) {
String technology = tokens.get(TECHNOLOGY_INDEX);
component.setTechnology(technology);
}
if (tokens.includes(TAGS_INDEX)) {
String tags = tokens.get(TAGS_INDEX);
component.addTags(tags.split(","));
}
if (context.hasGroup()) {
component.setGroup(context.getGroup().getName());
context.getGroup().addElement(component);
}
return component;
}
Aggregations