Search in sources :

Example 1 with Container

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;
}
Also used : Container(com.structurizr.model.Container) DecimalFormat(java.text.DecimalFormat) Element(com.structurizr.model.Element) SoftwareSystem(com.structurizr.model.SoftwareSystem) DynamicView(com.structurizr.view.DynamicView) Workspace(com.structurizr.Workspace)

Example 2 with Container

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

Example 3 with Container

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

Example 4 with Container

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

Example 5 with Container

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

Aggregations

Container (com.structurizr.model.Container)44 Test (org.junit.jupiter.api.Test)25 SoftwareSystem (com.structurizr.model.SoftwareSystem)23 Workspace (com.structurizr.Workspace)22 Component (com.structurizr.model.Component)21 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)10 ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)10 Application (org.archifacts.core.model.Application)10 ArtifactContainer (org.archifacts.core.model.ArtifactContainer)10 Model (com.structurizr.model.Model)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)5 Set (java.util.Set)5 Stream (java.util.stream.Stream)5 DynamicView (com.structurizr.view.DynamicView)4 Relationship (com.structurizr.model.Relationship)3 ComponentView (com.structurizr.view.ComponentView)3 JavaClass (com.tngtech.archunit.core.domain.JavaClass)3 JavaField (com.tngtech.archunit.core.domain.JavaField)3 File (java.io.File)3