Search in sources :

Example 6 with Container

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

Example 7 with Container

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

Example 8 with Container

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

Example 9 with Container

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

Example 10 with Container

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

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