Skip to content

Commit

Permalink
Adds support for !elements group (#351).
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Oct 23, 2024
1 parent cb8a407 commit f363836
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- 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).
- structurizr-dsl: Adds support for `!elements group` (https://github.com/structurizr/java/issues/351).

## 3.0.0 (19th September 2024)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ private Set<ModelItem> evaluateExpression(String expr, DslContext context) {
modelItems.add(relationship);
}
});
} else {
// fallback that the expression is an identifier
Set<Element> elements = getElements(expr, context);
if (!elements.isEmpty()) {
modelItems.addAll(elements);
}
}

return modelItems;
Expand Down
29 changes: 28 additions & 1 deletion structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ void test_findElement() throws Exception {
}

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

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

@Test
void test_findElements_InFlatGroup() throws Exception {
StructurizrDslParser parser = new StructurizrDslParser();
parser.parse(new File("src/test/resources/dsl/find-elements-in-flat-group.dsl"));

Person user = parser.getWorkspace().getModel().getPersonWithName("User");
assertTrue(user.hasEfferentRelationshipWith(parser.getWorkspace().getModel().getSoftwareSystemWithName("A"), "Uses"));
assertTrue(user.hasEfferentRelationshipWith(parser.getWorkspace().getModel().getSoftwareSystemWithName("B"), "Uses"));
assertTrue(user.hasEfferentRelationshipWith(parser.getWorkspace().getModel().getSoftwareSystemWithName("C"), "Uses"));
}

@Test
void test_findElements_InNestedGroup() throws Exception {
StructurizrDslParser parser = new StructurizrDslParser();
parser.parse(new File("src/test/resources/dsl/find-elements-in-nested-group.dsl"));

Person user1 = parser.getWorkspace().getModel().getPersonWithName("User 1");
assertTrue(user1.hasEfferentRelationshipWith(parser.getWorkspace().getModel().getSoftwareSystemWithName("A"), "Uses"));
assertTrue(user1.hasEfferentRelationshipWith(parser.getWorkspace().getModel().getSoftwareSystemWithName("B"), "Uses"));
assertTrue(user1.hasEfferentRelationshipWith(parser.getWorkspace().getModel().getSoftwareSystemWithName("C"), "Uses"));

Person user2 = parser.getWorkspace().getModel().getPersonWithName("User 2");
assertTrue(user2.hasEfferentRelationshipWith(parser.getWorkspace().getModel().getSoftwareSystemWithName("A"), "Uses"));
assertFalse(user2.hasEfferentRelationshipWith(parser.getWorkspace().getModel().getSoftwareSystemWithName("B"), "Uses"));
assertFalse(user2.hasEfferentRelationshipWith(parser.getWorkspace().getModel().getSoftwareSystemWithName("C"), "Uses"));
}

@Test
void test_parallel1() throws Exception {
StructurizrDslParser parser = new StructurizrDslParser();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
workspace {

model {
user = person "User"

group = group "Group" {
softwareSystem "A"
softwareSystem "B"
softwareSystem "C"
}

!elements group {
user -> this "Uses"
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
workspace {

model {
properties {
"structurizr.groupSeparator" "/"
}

user1 = person "User 1"
user2 = person "User 2"

department1 = group "Department 1" {
team1 = group "Team 1" {
softwareSystem "A"
}

team2 = group "Team 2" {
softwareSystem "B"
}

team3 = group "Team 3" {
softwareSystem "C"
}
}

!elements department1 {
user1 -> this "Uses"
}

!elements team1 {
user2 -> this "Uses"
}
}

}

0 comments on commit f363836

Please sign in to comment.