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

Commit

Permalink
Fixes #289.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Jun 29, 2023
1 parent 51fc8d2 commit 2d6a38e
Show file tree
Hide file tree
Showing 4 changed files with 34 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)

- Fixes https://github.com/structurizr/dsl/issues/289 (Cannot invoke "Object.equals(Object)" because "r" is null).

## 1.30.2 (20th June 2023)

- Fixes https://github.com/structurizr/dsl/issues/242 (deploymentViews hierarchical identifiers issue).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ protected Relationship createRelationship(Element sourceElement, String descript
throw new RuntimeException("A relationship between \"" + sourceElement.getCanonicalName() + "\" and \"" + destinationElement.getCanonicalName() + "\" is not permitted");
}

if (relationship == null) {
if (sourceElement.hasEfferentRelationshipWith(destinationElement, description) || sourceElement.hasEfferentRelationshipWith(destinationElement)) {
throw new RuntimeException("A relationship between \"" + sourceElement.getCanonicalName() + "\" and \"" + destinationElement.getCanonicalName() + "\" already exists");
}
}

return relationship;
}

Expand Down
13 changes: 13 additions & 0 deletions src/test/dsl/relationship-already-exists.dsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
workspace {

model {
a = softwareSystem "A"
b = softwareSystem "B" {
c = container "C"
}

c -> a
b -> a
}

}
11 changes: 11 additions & 0 deletions src/test/java/com/structurizr/dsl/DslTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -1085,4 +1085,15 @@ void test_MultiLineWithError() {
}
}

@Test
void test_RelationshipAlreadyExists() throws Exception {
try {
StructurizrDslParser parser = new StructurizrDslParser();
parser.parse(new File("src/test/dsl/relationship-already-exists.dsl"));
fail();
} catch (StructurizrDslParserException e) {
assertEquals("A relationship between \"SoftwareSystem://B\" and \"SoftwareSystem://A\" already exists at line 10: b -> a", e.getMessage());
}
}

}

0 comments on commit 2d6a38e

Please sign in to comment.