Search in sources :

Example 1 with Component

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());
}
Also used : Container(com.structurizr.model.Container) SoftwareSystem(com.structurizr.model.SoftwareSystem) Component(com.structurizr.model.Component) Test(org.junit.jupiter.api.Test)

Example 2 with Component

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());
    }
}
Also used : Component(com.structurizr.model.Component) Test(org.junit.jupiter.api.Test)

Example 3 with Component

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());
}
Also used : Container(com.structurizr.model.Container) SoftwareSystem(com.structurizr.model.SoftwareSystem) Component(com.structurizr.model.Component) Test(org.junit.jupiter.api.Test)

Example 4 with Component

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());
    }
}
Also used : Component(com.structurizr.model.Component) Test(org.junit.jupiter.api.Test)

Example 5 with Component

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;
}
Also used : Container(com.structurizr.model.Container) Component(com.structurizr.model.Component)

Aggregations

Component (com.structurizr.model.Component)32 Container (com.structurizr.model.Container)23 Test (org.junit.jupiter.api.Test)17 Workspace (com.structurizr.Workspace)15 SoftwareSystem (com.structurizr.model.SoftwareSystem)12 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)9 ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)9 Application (org.archifacts.core.model.Application)9 ArtifactContainer (org.archifacts.core.model.ArtifactContainer)9 Model (com.structurizr.model.Model)8 Stream (java.util.stream.Stream)7 File (java.io.File)6 Relationship (com.structurizr.model.Relationship)5 ComponentView (com.structurizr.view.ComponentView)5 JavaClass (com.tngtech.archunit.core.domain.JavaClass)5 IOException (java.io.IOException)5 Collectors (java.util.stream.Collectors)5 Element (com.structurizr.model.Element)4 Path (java.nio.file.Path)4 Function (java.util.function.Function)4