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());
}
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]));
}
}
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());
}
}
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;
}
Aggregations