Search in sources :

Example 46 with SoftwareSystem

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

the class DeploymentViewParser method parse.

DeploymentView parse(DslContext context, Tokens tokens) {
    if (tokens.hasMoreThan(DESCRIPTION_INDEX)) {
        throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
    }
    if (!tokens.includes(ENVIRONMENT_INDEX)) {
        throw new RuntimeException("Expected: " + GRAMMAR);
    }
    Workspace workspace = context.getWorkspace();
    String key = "";
    String scopeIdentifier = tokens.get(SCOPE_IDENTIFIER_INDEX);
    String environment = tokens.get(ENVIRONMENT_INDEX);
    if (context.getElement(environment) != null && context.getElement(environment) instanceof DeploymentEnvironment) {
        environment = context.getElement(environment).getName();
    }
    // check that the deployment environment exists in the model
    final String env = environment;
    if (context.getWorkspace().getModel().getDeploymentNodes().stream().noneMatch(dn -> dn.getEnvironment().equals(env))) {
        throw new RuntimeException("The environment \"" + environment + "\" does not exist");
    }
    String description = "";
    if (tokens.includes(DESCRIPTION_INDEX)) {
        description = tokens.get(DESCRIPTION_INDEX);
    }
    DeploymentView view;
    if ("*".equals(scopeIdentifier)) {
        if (tokens.includes(KEY_INDEX)) {
            key = tokens.get(KEY_INDEX);
        } else {
            key = removeNonWordCharacters(environment) + "-" + VIEW_TYPE;
        }
        validateViewKey(key);
        view = workspace.getViews().createDeploymentView(key, description);
    } else {
        Element element = context.getElement(scopeIdentifier);
        if (element == null) {
            throw new RuntimeException("The software system \"" + scopeIdentifier + "\" does not exist");
        }
        if (element instanceof SoftwareSystem) {
            if (tokens.includes(KEY_INDEX)) {
                key = tokens.get(KEY_INDEX);
            } else {
                key = removeNonWordCharacters(element.getName()) + "-" + removeNonWordCharacters(environment) + "-" + VIEW_TYPE;
            }
            validateViewKey(key);
            view = workspace.getViews().createDeploymentView((SoftwareSystem) element, key, description);
        } else {
            throw new RuntimeException("The element \"" + scopeIdentifier + "\" is not a software system");
        }
    }
    view.setEnvironment(environment);
    return view;
}
Also used : Element(com.structurizr.model.Element) SoftwareSystem(com.structurizr.model.SoftwareSystem) Workspace(com.structurizr.Workspace) DeploymentView(com.structurizr.view.DeploymentView)

Example 47 with SoftwareSystem

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

the class HealthCheckParserTests method setUp.

@BeforeEach
void setUp() {
    SoftwareSystem softwareSystem = model.addSoftwareSystem("Name");
    DeploymentNode deploymentNode = model.addDeploymentNode("Deployment Node");
    softwareSystemInstance = deploymentNode.add(softwareSystem);
}
Also used : DeploymentNode(com.structurizr.model.DeploymentNode) SoftwareSystem(com.structurizr.model.SoftwareSystem) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 48 with SoftwareSystem

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

the class IdentifierRegisterTests method test_register_ThrowsAnException_WhenTheElementHasAlreadyBeenRegisteredWithADifferentIdentifier.

@Test
void test_register_ThrowsAnException_WhenTheElementHasAlreadyBeenRegisteredWithADifferentIdentifier() {
    SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System");
    try {
        register.register("a", softwareSystem);
        register.register("x", softwareSystem);
        fail();
    } catch (Exception e) {
        assertEquals("The element is already registered with an identifier of \"a\"", e.getMessage());
    }
}
Also used : SoftwareSystem(com.structurizr.model.SoftwareSystem) Test(org.junit.jupiter.api.Test)

Example 49 with SoftwareSystem

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

the class IdentifierRegisterTests method test_register_ThrowsAnException_WhenTheElementHasAlreadyBeenRegisteredWithAnInternalIdentifier.

@Test
void test_register_ThrowsAnException_WhenTheElementHasAlreadyBeenRegisteredWithAnInternalIdentifier() {
    SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System");
    try {
        register.register("", softwareSystem);
        register.register("x", softwareSystem);
        fail();
    } catch (Exception e) {
        assertEquals("Please assign an identifier to \"SoftwareSystem://Software System\" before using it with !ref", e.getMessage());
    }
}
Also used : SoftwareSystem(com.structurizr.model.SoftwareSystem) Test(org.junit.jupiter.api.Test)

Example 50 with SoftwareSystem

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

the class DeploymentViewParserTests method test_parse_CreatesADeploymentViewWithSoftwareSystemScopeAndKey.

@Test
void test_parse_CreatesADeploymentViewWithSoftwareSystemScopeAndKey() {
    DslContext context = context();
    context.getWorkspace().getModel().addDeploymentNode("Live", "Deployment Node", "Description", "Technology");
    IdentifiersRegister elements = new IdentifiersRegister();
    SoftwareSystem softwareSystem = model.addSoftwareSystem("Name", "Description");
    elements.register("softwaresystem", softwareSystem);
    context.setIdentifierRegister(elements);
    parser.parse(context, tokens("deployment", "softwareSystem", "Live", "key"));
    List<DeploymentView> views = new ArrayList<>(this.views.getDeploymentViews());
    assertEquals(1, views.size());
    assertEquals("key", views.get(0).getKey());
    assertEquals("", views.get(0).getDescription());
    assertSame(softwareSystem, views.get(0).getSoftwareSystem());
}
Also used : ArrayList(java.util.ArrayList) SoftwareSystem(com.structurizr.model.SoftwareSystem) DeploymentView(com.structurizr.view.DeploymentView) Test(org.junit.jupiter.api.Test)

Aggregations

SoftwareSystem (com.structurizr.model.SoftwareSystem)69 Test (org.junit.jupiter.api.Test)38 Container (com.structurizr.model.Container)23 Workspace (com.structurizr.Workspace)22 Test (org.junit.Test)17 Person (com.structurizr.model.Person)9 Component (com.structurizr.model.Component)8 DynamicView (com.structurizr.view.DynamicView)8 ArrayList (java.util.ArrayList)8 Model (com.structurizr.model.Model)7 DeploymentView (com.structurizr.view.DeploymentView)6 SystemContextView (com.structurizr.view.SystemContextView)6 ViewSet (com.structurizr.view.ViewSet)5 Element (com.structurizr.model.Element)4 Relationship (com.structurizr.model.Relationship)4 ContainerView (com.structurizr.view.ContainerView)4 RelationshipView (com.structurizr.view.RelationshipView)4 DeploymentNode (com.structurizr.model.DeploymentNode)3 ComponentView (com.structurizr.view.ComponentView)3 EncryptedWorkspace (com.structurizr.encryption.EncryptedWorkspace)2