Skip to content

Commit

Permalink
Closes #347.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Oct 9, 2024
1 parent b507b5d commit 1e6c2a3
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- structurizr-dsl: Adds a way to configure whether the DSL source is retained via a workspace property named `structurizr.dsl.source` - `true` (default) or `false`.
- structurizr-dsl: Adds the ability to define a PlantUML/Mermaid image view that is an export of a workspace view.
- structurizr-dsl: Adds support for `url`, `properties`, and `perspectives` nested inside `!elements` and `!relationships`.
- structurizr-dsl: Fixes https://github.com/structurizr/java/issues/347 (`->container->` expression does not work as expected in deployment view).

## 3.0.0 (19th September 2024)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.util.LinkedHashSet;
import java.util.Set;
import java.util.stream.Collectors;

import static com.structurizr.dsl.StructurizrDslExpressions.ELEMENT_TYPE_EQUALS_EXPRESSION;

Expand Down Expand Up @@ -43,6 +44,24 @@ protected Set<Element> evaluateElementTypeExpression(String expr, DslContext con
return elements;
}

@Override
protected Set<Element> getElements(String identifier, DslContext context) {
Set<Element> elements = new LinkedHashSet<>();
for (Element element : super.getElements(identifier, context)) {
if (element instanceof SoftwareSystem) {
Set<SoftwareSystemInstance> elementInstances = context.getWorkspace().getModel().getElements().stream().filter(e -> e instanceof SoftwareSystemInstance).map(e -> (SoftwareSystemInstance) e).filter(ssi -> ssi.getSoftwareSystem().equals(element)).collect(Collectors.toSet());
elements.addAll(elementInstances);
} else if (element instanceof Container) {
Set<ContainerInstance> elementInstances = context.getWorkspace().getModel().getElements().stream().filter(e -> e instanceof ContainerInstance).map(e -> (ContainerInstance)e).filter(ci -> ci.getContainer().equals(element)).collect(Collectors.toSet());
elements.addAll(elementInstances);
} else {
elements.add(element);
}
}

return elements;
}

protected Set<Element> findAfferentCouplings(Element element) {
Set<Element> elements = new LinkedHashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ protected Set<ModelItem> parseIdentifier(String identifier, DslContext context)
}
}

private Set<Element> getElements(String identifier, DslContext context) {
protected Set<Element> getElements(String identifier, DslContext context) {
Set<Element> elements = new HashSet<>();

Element element = context.getElement(identifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,57 @@ void test_parseExpression_ReturnsElements_WhenBooleanOrUsed() {
assertTrue(elements.contains(containerInstance));
}

@Test
void test_parseExpression_ReturnsSoftwareSystemInstanceDependencies_WhenASoftwareSystemExpressionIsUsed() {
SoftwareSystem a = model.addSoftwareSystem("A");
SoftwareSystem b = model.addSoftwareSystem("B");
a.uses(b, "");

DeploymentNode deploymentNode = model.addDeploymentNode("Live", "Deployment Node", "Description", "Technology");
InfrastructureNode infrastructureNode = deploymentNode.addInfrastructureNode("Infrastructure Node");
SoftwareSystemInstance softwareSystemInstanceA = deploymentNode.add(a);
SoftwareSystemInstance softwareSystemInstanceB = deploymentNode.add(b);
infrastructureNode.uses(softwareSystemInstanceA, "", "");

DeploymentViewDslContext context = new DeploymentViewDslContext(null);
context.setWorkspace(workspace);

IdentifiersRegister identifiersRegister = new IdentifiersRegister();
identifiersRegister.register("a", a);
context.setIdentifierRegister(identifiersRegister);

Set<ModelItem> elements = parser.parseExpression("->a->", context);
assertEquals(3, elements.size());
assertTrue(elements.contains(infrastructureNode));
assertTrue(elements.contains(softwareSystemInstanceA));
assertTrue(elements.contains(softwareSystemInstanceB));
}

@Test
void test_parseExpression_ReturnsContainerInstanceDependencies_WhenAContainerExpressionIsUsed() {
SoftwareSystem softwareSystem = model.addSoftwareSystem("Software System");
Container container1 = softwareSystem.addContainer("Container 1");
Container container2 = softwareSystem.addContainer("Container 2");
container1.uses(container2, "");

DeploymentNode deploymentNode = model.addDeploymentNode("Live", "Deployment Node", "Description", "Technology");
InfrastructureNode infrastructureNode = deploymentNode.addInfrastructureNode("Infrastructure Node");
ContainerInstance containerInstance1 = deploymentNode.add(container1);
ContainerInstance containerInstance2 = deploymentNode.add(container2);
infrastructureNode.uses(containerInstance1, "", "");

DeploymentViewDslContext context = new DeploymentViewDslContext(null);
context.setWorkspace(workspace);

IdentifiersRegister identifiersRegister = new IdentifiersRegister();
identifiersRegister.register("c1", container1);
context.setIdentifierRegister(identifiersRegister);

Set<ModelItem> elements = parser.parseExpression("->c1->", context);
assertEquals(3, elements.size());
assertTrue(elements.contains(infrastructureNode));
assertTrue(elements.contains(containerInstance1));
assertTrue(elements.contains(containerInstance2));
}

}

0 comments on commit 1e6c2a3

Please sign in to comment.