Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Adds support for more easily including/excluding implied relationship…
Browse files Browse the repository at this point in the history
…s in view definitions (fixes #303).
  • Loading branch information
simonbrowndotje committed Jul 17, 2023
1 parent e676975 commit 0dcf1f7
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## (unreleased to Maven Central)

- Adds support for more easily including/excluding implied relationships in view definitions (https://github.com/structurizr/dsl/issues/303).

## 1.30.3 (4th July 2023)

- Fixes https://github.com/structurizr/dsl/issues/289 (Cannot invoke "Object.equals(Object)" because "r" is null).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ protected Set<ModelItem> parseIdentifier(String identifier, DslContext context)
Relationship relationship = context.getRelationship(identifier);
if (relationship != null) {
modelItems.add(relationship);

// and also find all relationships linked to it (i.e. implied and replicated relationships)
relationship.getModel().getRelationships().stream().filter(r -> relationship.getId().equals(r.getLinkedRelationshipId())).forEach(modelItems::add);
}

if (modelItems.isEmpty()) {
Expand Down
22 changes: 22 additions & 0 deletions src/test/dsl/exclude-implied-relationship.dsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
workspace {

model {
softwareSystem "A" {
a = container "A"
}

softwareSystem "B" {
b = container "B"
}

r = a -> b
}

views {
systemLandscape {
include *
exclude r
}
}

}
23 changes: 23 additions & 0 deletions src/test/dsl/include-implied-relationship.dsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
workspace {

model {
softwareSystem "A" {
a = container "A"
}

softwareSystem "B" {
b = container "B"
}

r = a -> b
}

views {
systemLandscape {
include *
exclude *->*
include r
}
}

}
18 changes: 18 additions & 0 deletions src/test/java/com/structurizr/dsl/DslTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -1096,4 +1096,22 @@ void test_RelationshipAlreadyExists() throws Exception {
}
}

@Test
void test_ExcludeImpliedRelationship() throws Exception {
StructurizrDslParser parser = new StructurizrDslParser();
parser.parse(new File("src/test/dsl/exclude-implied-relationship.dsl"));

// check the system landscape view doesn't include any relationships
assertEquals(0, parser.getWorkspace().getViews().getSystemLandscapeViews().iterator().next().getRelationships().size());
}

@Test
void test_IncludeImpliedRelationship() throws Exception {
StructurizrDslParser parser = new StructurizrDslParser();
parser.parse(new File("src/test/dsl/include-implied-relationship.dsl"));

// check the system landscape view includes a relationship
assertEquals(1, parser.getWorkspace().getViews().getSystemLandscapeViews().iterator().next().getRelationships().size());
}

}

0 comments on commit 0dcf1f7

Please sign in to comment.