Skip to content
This repository was archived by the owner on Mar 28, 2026. It is now read-only.

Commit f363836

Browse files
Adds support for !elements group (#351).
1 parent cb8a407 commit f363836

5 files changed

Lines changed: 86 additions & 1 deletion

File tree

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- structurizr-dsl: Adds the ability to define a PlantUML/Mermaid image view that is an export of a workspace view.
1414
- structurizr-dsl: Adds support for `url`, `properties`, and `perspectives` nested inside `!elements` and `!relationships`.
1515
- structurizr-dsl: Fixes https://github.com/structurizr/java/issues/347 (`->container->` expression does not work as expected in deployment view).
16+
- structurizr-dsl: Adds support for `!elements group` (https://github.com/structurizr/java/issues/351).
1617

1718
## 3.0.0 (19th September 2024)
1819

structurizr-dsl/src/main/java/com/structurizr/dsl/ExpressionParser.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ private Set<ModelItem> evaluateExpression(String expr, DslContext context) {
274274
modelItems.add(relationship);
275275
}
276276
});
277+
} else {
278+
// fallback that the expression is an identifier
279+
Set<Element> elements = getElements(expr, context);
280+
if (!elements.isEmpty()) {
281+
modelItems.addAll(elements);
282+
}
277283
}
278284

279285
return modelItems;

structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ void test_findElement() throws Exception {
531531
}
532532

533533
@Test
534-
void test_findElement_Hierachical() throws Exception {
534+
void test_findElement_Hierarchical() throws Exception {
535535
File dslFile = new File("src/test/resources/dsl/find-element-hierarchical.dsl");
536536

537537
StructurizrDslParser parser = new StructurizrDslParser();
@@ -543,6 +543,33 @@ void test_findElement_Hierachical() throws Exception {
543543
assertEquals("Value3", component.getProperties().get("Name3"));
544544
}
545545

546+
@Test
547+
void test_findElements_InFlatGroup() throws Exception {
548+
StructurizrDslParser parser = new StructurizrDslParser();
549+
parser.parse(new File("src/test/resources/dsl/find-elements-in-flat-group.dsl"));
550+
551+
Person user = parser.getWorkspace().getModel().getPersonWithName("User");
552+
assertTrue(user.hasEfferentRelationshipWith(parser.getWorkspace().getModel().getSoftwareSystemWithName("A"), "Uses"));
553+
assertTrue(user.hasEfferentRelationshipWith(parser.getWorkspace().getModel().getSoftwareSystemWithName("B"), "Uses"));
554+
assertTrue(user.hasEfferentRelationshipWith(parser.getWorkspace().getModel().getSoftwareSystemWithName("C"), "Uses"));
555+
}
556+
557+
@Test
558+
void test_findElements_InNestedGroup() throws Exception {
559+
StructurizrDslParser parser = new StructurizrDslParser();
560+
parser.parse(new File("src/test/resources/dsl/find-elements-in-nested-group.dsl"));
561+
562+
Person user1 = parser.getWorkspace().getModel().getPersonWithName("User 1");
563+
assertTrue(user1.hasEfferentRelationshipWith(parser.getWorkspace().getModel().getSoftwareSystemWithName("A"), "Uses"));
564+
assertTrue(user1.hasEfferentRelationshipWith(parser.getWorkspace().getModel().getSoftwareSystemWithName("B"), "Uses"));
565+
assertTrue(user1.hasEfferentRelationshipWith(parser.getWorkspace().getModel().getSoftwareSystemWithName("C"), "Uses"));
566+
567+
Person user2 = parser.getWorkspace().getModel().getPersonWithName("User 2");
568+
assertTrue(user2.hasEfferentRelationshipWith(parser.getWorkspace().getModel().getSoftwareSystemWithName("A"), "Uses"));
569+
assertFalse(user2.hasEfferentRelationshipWith(parser.getWorkspace().getModel().getSoftwareSystemWithName("B"), "Uses"));
570+
assertFalse(user2.hasEfferentRelationshipWith(parser.getWorkspace().getModel().getSoftwareSystemWithName("C"), "Uses"));
571+
}
572+
546573
@Test
547574
void test_parallel1() throws Exception {
548575
StructurizrDslParser parser = new StructurizrDslParser();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
workspace {
2+
3+
model {
4+
user = person "User"
5+
6+
group = group "Group" {
7+
softwareSystem "A"
8+
softwareSystem "B"
9+
softwareSystem "C"
10+
}
11+
12+
!elements group {
13+
user -> this "Uses"
14+
}
15+
}
16+
17+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
workspace {
2+
3+
model {
4+
properties {
5+
"structurizr.groupSeparator" "/"
6+
}
7+
8+
user1 = person "User 1"
9+
user2 = person "User 2"
10+
11+
department1 = group "Department 1" {
12+
team1 = group "Team 1" {
13+
softwareSystem "A"
14+
}
15+
16+
team2 = group "Team 2" {
17+
softwareSystem "B"
18+
}
19+
20+
team3 = group "Team 3" {
21+
softwareSystem "C"
22+
}
23+
}
24+
25+
!elements department1 {
26+
user1 -> this "Uses"
27+
}
28+
29+
!elements team1 {
30+
user2 -> this "Uses"
31+
}
32+
}
33+
34+
}

0 commit comments

Comments
 (0)