Search in sources :

Example 16 with Workspace

use of com.structurizr.Workspace in project dsl by structurizr.

the class ContainerViewParser method parse.

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

Example 17 with Workspace

use of com.structurizr.Workspace 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 18 with Workspace

use of com.structurizr.Workspace in project java by structurizr.

the class WorkspaceUtilsTests method test_saveWorkspaceToJson_and_loadWorkspaceFromJson.

@Test
public void test_saveWorkspaceToJson_and_loadWorkspaceFromJson() throws Exception {
    File file = new File("build/workspace-utils.json");
    Workspace workspace = new Workspace("Name", "Description");
    WorkspaceUtils.saveWorkspaceToJson(workspace, file);
    workspace = WorkspaceUtils.loadWorkspaceFromJson(file);
    assertEquals("Name", workspace.getName());
}
Also used : File(java.io.File) Workspace(com.structurizr.Workspace) Test(org.junit.Test)

Example 19 with Workspace

use of com.structurizr.Workspace in project java by structurizr.

the class ThemeUtilsTests method test_findRelationshipStyle_WithThemes.

@Test
public void test_findRelationshipStyle_WithThemes() {
    Workspace workspace = new Workspace("Name", "Description");
    SoftwareSystem softwareSystem = workspace.getModel().addSoftwareSystem("Name");
    Relationship relationship = softwareSystem.uses(softwareSystem, "Uses");
    workspace.getViews().getConfiguration().getStyles().addRelationshipStyle("Relationship").dashed(false);
    // theme 1
    Collection<ElementStyle> elementStyles = new ArrayList<>();
    Collection<RelationshipStyle> relationshipStyles = new ArrayList<>();
    relationshipStyles.add(new RelationshipStyle("Relationship").color("#ff0000").thickness(4));
    workspace.getViews().getConfiguration().getStyles().addStylesFromTheme("url1", elementStyles, relationshipStyles);
    // theme 2
    elementStyles = new ArrayList<>();
    relationshipStyles = new ArrayList<>();
    relationshipStyles.add(new RelationshipStyle("Relationship").color("#0000ff"));
    workspace.getViews().getConfiguration().getStyles().addStylesFromTheme("url2", elementStyles, relationshipStyles);
    RelationshipStyle style = workspace.getViews().getConfiguration().getStyles().findRelationshipStyle(relationship);
    // from theme 1
    assertEquals(new Integer(4), style.getThickness());
    // from theme 2
    assertEquals("#0000ff", style.getColor());
    // from workspace
    Assert.assertFalse(style.getDashed());
    assertEquals(Routing.Direct, style.getRouting());
    assertEquals(new Integer(24), style.getFontSize());
    assertEquals(new Integer(200), style.getWidth());
    assertEquals(new Integer(50), style.getPosition());
    assertEquals(new Integer(100), style.getOpacity());
}
Also used : Relationship(com.structurizr.model.Relationship) ArrayList(java.util.ArrayList) SoftwareSystem(com.structurizr.model.SoftwareSystem) Workspace(com.structurizr.Workspace) Test(org.junit.Test)

Example 20 with Workspace

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

Aggregations

Workspace (com.structurizr.Workspace)155 Test (org.junit.Test)98 Test (org.junit.jupiter.api.Test)36 File (java.io.File)23 Container (com.structurizr.model.Container)22 SoftwareSystem (com.structurizr.model.SoftwareSystem)22 Component (com.structurizr.model.Component)12 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)12 ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)12 Application (org.archifacts.core.model.Application)12 ArtifactContainer (org.archifacts.core.model.ArtifactContainer)10 ArrayList (java.util.ArrayList)6 EncryptedWorkspace (com.structurizr.encryption.EncryptedWorkspace)5 Element (com.structurizr.model.Element)5 Model (com.structurizr.model.Model)5 Artifact (org.archifacts.core.model.Artifact)5 MiscArtifact (org.archifacts.core.model.MiscArtifact)5 Person (com.structurizr.model.Person)4 Relationship (com.structurizr.model.Relationship)4 SystemContextView (com.structurizr.view.SystemContextView)4