Search in sources :

Example 6 with InfrastructureNode

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

the class InfrastructureNodeParserTests method test_parse_CreatesAnInfrastructureNodeWithADescriptionAndTechnologyAndTags.

@Test
void test_parse_CreatesAnInfrastructureNodeWithADescriptionAndTechnologyAndTags() {
    DeploymentNode deploymentNode = model.addDeploymentNode("Live", "Deployment Node", "Description", "Technology");
    DeploymentNodeDslContext context = new DeploymentNodeDslContext(deploymentNode);
    parser.parse(context, tokens("infrastructureNode", "Name", "Description", "Technology", "Tag 1, Tag 2"));
    assertEquals(2, model.getElements().size());
    assertEquals(1, deploymentNode.getInfrastructureNodes().size());
    InfrastructureNode infrastructureNode = deploymentNode.getInfrastructureNodeWithName("Name");
    assertNotNull(infrastructureNode);
    assertEquals("Description", infrastructureNode.getDescription());
    assertEquals("Technology", infrastructureNode.getTechnology());
    assertEquals("Element,Infrastructure Node,Tag 1,Tag 2", infrastructureNode.getTags());
    assertEquals("Live", infrastructureNode.getEnvironment());
}
Also used : DeploymentNode(com.structurizr.model.DeploymentNode) InfrastructureNode(com.structurizr.model.InfrastructureNode) Test(org.junit.jupiter.api.Test)

Example 7 with InfrastructureNode

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

the class DeploymentViewAnimationStepParser method parse.

void parse(DslContext context, DeploymentView view, Tokens tokens, int startIndex) {
    List<StaticStructureElementInstance> staticStructureElementInstances = new ArrayList<>();
    List<InfrastructureNode> infrastructureNodes = new ArrayList<>();
    for (int i = startIndex; i < tokens.size(); i++) {
        String identifier = tokens.get(i);
        Element element = context.getElement(identifier);
        if (element == null) {
            throw new RuntimeException("The element \"" + identifier + "\" does not exist");
        }
        if (element instanceof StaticStructureElementInstance) {
            staticStructureElementInstances.add((StaticStructureElementInstance) element);
        }
        if (element instanceof InfrastructureNode) {
            infrastructureNodes.add((InfrastructureNode) element);
        }
    }
    if (!(staticStructureElementInstances.isEmpty() && infrastructureNodes.isEmpty())) {
        view.addAnimation(staticStructureElementInstances.toArray(new StaticStructureElementInstance[0]), infrastructureNodes.toArray(new InfrastructureNode[0]));
    }
}
Also used : StaticStructureElementInstance(com.structurizr.model.StaticStructureElementInstance) Element(com.structurizr.model.Element) ArrayList(java.util.ArrayList) InfrastructureNode(com.structurizr.model.InfrastructureNode)

Example 8 with InfrastructureNode

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

the class InfrastructureNodeParserTests method test_parseTechnology_ThrowsAnException_WhenNoDescriptionIsSpecified.

@Test
void test_parseTechnology_ThrowsAnException_WhenNoDescriptionIsSpecified() {
    try {
        InfrastructureNode infrastructureNode = model.addDeploymentNode("Deployment Node").addInfrastructureNode("Infrastructure Node");
        InfrastructureNodeDslContext context = new InfrastructureNodeDslContext(infrastructureNode);
        parser.parseTechnology(context, tokens("technology"));
        fail();
    } catch (Exception e) {
        assertEquals("Expected: technology <technology>", e.getMessage());
    }
}
Also used : InfrastructureNode(com.structurizr.model.InfrastructureNode) Test(org.junit.jupiter.api.Test)

Example 9 with InfrastructureNode

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

the class InfrastructureNodeParser method parse.

InfrastructureNode parse(DeploymentNodeDslContext 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);
    }
    DeploymentNode deploymentNode = context.getDeploymentNode();
    InfrastructureNode infrastructureNode;
    String name = tokens.get(NAME_INDEX);
    String description = "";
    if (tokens.includes(DESCRIPTION_INDEX)) {
        description = tokens.get(DESCRIPTION_INDEX);
    }
    String technology = "";
    if (tokens.includes(TECHNOLOGY_INDEX)) {
        technology = tokens.get(TECHNOLOGY_INDEX);
    }
    infrastructureNode = deploymentNode.addInfrastructureNode(name, description, technology);
    if (tokens.includes(TAGS_INDEX)) {
        String tags = tokens.get(TAGS_INDEX);
        infrastructureNode.addTags(tags.split(","));
    }
    return infrastructureNode;
}
Also used : DeploymentNode(com.structurizr.model.DeploymentNode) InfrastructureNode(com.structurizr.model.InfrastructureNode)

Aggregations

InfrastructureNode (com.structurizr.model.InfrastructureNode)9 Test (org.junit.jupiter.api.Test)7 DeploymentNode (com.structurizr.model.DeploymentNode)5 Element (com.structurizr.model.Element)1 StaticStructureElementInstance (com.structurizr.model.StaticStructureElementInstance)1 ArrayList (java.util.ArrayList)1