Search in sources :

Example 11 with Container

use of com.structurizr.model.Container 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)

Example 12 with Container

use of com.structurizr.model.Container in project dsl by structurizr.

the class ComponentViewParser method parse.

ComponentView parse(DslContext context, Tokens tokens) {
    if (tokens.hasMoreThan(DESCRIPTION_INDEX)) {
        throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
    }
    if (!tokens.includes(CONTAINER_IDENTIFIER_INDEX)) {
        throw new RuntimeException("Expected: " + GRAMMAR);
    }
    Workspace workspace = context.getWorkspace();
    Container container;
    String key = "";
    String description = "";
    String containerIdentifier = tokens.get(CONTAINER_IDENTIFIER_INDEX);
    Element element = context.getElement(containerIdentifier);
    if (element == null) {
        throw new RuntimeException("The container \"" + containerIdentifier + "\" does not exist");
    }
    if (element instanceof Container) {
        container = (Container) element;
    } else {
        throw new RuntimeException("The element \"" + containerIdentifier + "\" is not a container");
    }
    if (tokens.includes(KEY_INDEX)) {
        key = tokens.get(KEY_INDEX);
    } else {
        key = removeNonWordCharacters(container.getSoftwareSystem().getName()) + "-" + removeNonWordCharacters(container.getName()) + "-" + VIEW_TYPE;
    }
    validateViewKey(key);
    if (tokens.includes(DESCRIPTION_INDEX)) {
        description = tokens.get(DESCRIPTION_INDEX);
    }
    ComponentView view = workspace.getViews().createComponentView(container, key, description);
    view.setExternalSoftwareSystemBoundariesVisible(true);
    return view;
}
Also used : Container(com.structurizr.model.Container) ComponentView(com.structurizr.view.ComponentView) Element(com.structurizr.model.Element) Workspace(com.structurizr.Workspace)

Example 13 with Container

use of com.structurizr.model.Container in project java by structurizr.

the class DefaultLayoutMergeStrategyTests method test_copyLayoutInformation_WhenCanonicalNamesHaveNotChanged.

@Test
public void test_copyLayoutInformation_WhenCanonicalNamesHaveNotChanged() {
    Workspace workspace1 = new Workspace("1", "");
    SoftwareSystem softwareSystem1 = workspace1.getModel().addSoftwareSystem("Software System");
    Container container1 = softwareSystem1.addContainer("Container", "", "");
    ContainerView view1 = workspace1.getViews().createContainerView(softwareSystem1, "key", "");
    view1.add(container1);
    view1.getElementView(container1).setX(123);
    view1.getElementView(container1).setY(456);
    Workspace workspace2 = new Workspace("2", "");
    SoftwareSystem softwareSystem2 = workspace2.getModel().addSoftwareSystem("Software System");
    Container container2 = softwareSystem2.addContainer("Container", "", "");
    ContainerView view2 = workspace2.getViews().createContainerView(softwareSystem2, "key", "");
    view2.add(container2);
    DefaultLayoutMergeStrategy strategy = new DefaultLayoutMergeStrategy();
    strategy.copyLayoutInformation(view1, view2);
    assertEquals(123, view2.getElementView(container2).getX());
    assertEquals(456, view2.getElementView(container2).getY());
}
Also used : Container(com.structurizr.model.Container) SoftwareSystem(com.structurizr.model.SoftwareSystem) Workspace(com.structurizr.Workspace) Test(org.junit.Test)

Example 14 with Container

use of com.structurizr.model.Container in project java by structurizr.

the class DefaultLayoutMergeStrategyTests method test_copyLayoutInformation_WhenAnElementNameAndDescriptionAndIdHaveChanged.

@Test
public void test_copyLayoutInformation_WhenAnElementNameAndDescriptionAndIdHaveChanged() {
    Workspace workspace1 = new Workspace("1", "");
    SoftwareSystem softwareSystem1 = workspace1.getModel().addSoftwareSystem("Software System");
    Container container1 = softwareSystem1.addContainer("Container", "Container description", "");
    ContainerView view1 = workspace1.getViews().createContainerView(softwareSystem1, "key", "");
    view1.add(container1);
    view1.getElementView(container1).setX(123);
    view1.getElementView(container1).setY(456);
    Workspace workspace2 = new Workspace("2", "");
    SoftwareSystem softwareSystem2 = workspace2.getModel().addSoftwareSystem("Software System");
    // this element has ID 2
    softwareSystem2.addContainer("Web Application", "Description", "");
    Container container2 = softwareSystem2.addContainer("Database", "Description", "");
    ContainerView view2 = workspace2.getViews().createContainerView(softwareSystem2, "key", "");
    view2.add(container2);
    DefaultLayoutMergeStrategy strategy = new DefaultLayoutMergeStrategy();
    strategy.copyLayoutInformation(view1, view2);
    assertEquals(0, view2.getElementView(container2).getX());
    assertEquals(0, view2.getElementView(container2).getY());
}
Also used : Container(com.structurizr.model.Container) SoftwareSystem(com.structurizr.model.SoftwareSystem) Workspace(com.structurizr.Workspace) Test(org.junit.Test)

Example 15 with Container

use of com.structurizr.model.Container in project java by structurizr.

the class DefaultLayoutMergeStrategyTests method test_copyLayoutInformation_WhenAnElementNameHasChangedButTheDescriptionHasNotChanged.

@Test
public void test_copyLayoutInformation_WhenAnElementNameHasChangedButTheDescriptionHasNotChanged() {
    Workspace workspace1 = new Workspace("1", "");
    SoftwareSystem softwareSystem1 = workspace1.getModel().addSoftwareSystem("Software System");
    Container container1 = softwareSystem1.addContainer("Container", "Container description", "");
    ContainerView view1 = workspace1.getViews().createContainerView(softwareSystem1, "key", "");
    view1.add(container1);
    view1.getElementView(container1).setX(123);
    view1.getElementView(container1).setY(456);
    Workspace workspace2 = new Workspace("2", "");
    SoftwareSystem softwareSystem2 = workspace2.getModel().addSoftwareSystem("Software System");
    Container container2 = softwareSystem2.addContainer("Container with a new name", "Container description", "");
    ContainerView view2 = workspace2.getViews().createContainerView(softwareSystem2, "key", "");
    view2.add(container2);
    DefaultLayoutMergeStrategy strategy = new DefaultLayoutMergeStrategy();
    strategy.copyLayoutInformation(view1, view2);
    assertEquals(123, view2.getElementView(container2).getX());
    assertEquals(456, view2.getElementView(container2).getY());
}
Also used : Container(com.structurizr.model.Container) SoftwareSystem(com.structurizr.model.SoftwareSystem) Workspace(com.structurizr.Workspace) Test(org.junit.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