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