From 0d8635598c8a43d2a8e4e440065596dcfd69c581 Mon Sep 17 00:00:00 2001 From: Simon Brown Date: Fri, 18 Feb 2022 15:35:34 +0000 Subject: [PATCH] Fixes #167 (ImpliedRelationship Strategy replication of URL and perspectives). --- build.gradle | 2 +- docs/changelog.md | 4 ++++ ...psUnlessAnyRelationshipExistsStrategy.java | 5 ++++- ...sUnlessSameRelationshipExistsStrategy.java | 5 ++++- .../src/com/structurizr/model/Model.java | 4 ++-- ...essAnyRelationshipExistsStrategyTests.java | 20 +++++++++++-------- ...ssSameRelationshipExistsStrategyTests.java | 20 +++++++++++-------- 7 files changed, 39 insertions(+), 21 deletions(-) diff --git a/build.gradle b/build.gradle index d45445455..241c3bc03 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ subprojects { proj -> description = 'Structurizr' group = 'com.structurizr' - version = '1.10.1' + version = '1.11.0' repositories { mavenCentral() diff --git a/docs/changelog.md b/docs/changelog.md index c5c121e70..36a92f4ae 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,9 @@ # Changelog +## 1.11.0 (unreleased to Maven Central) + +- Fixes #167 (ImpliedRelationship Strategy replication of URL and perspectives). + ## 1.10.1 (1st February 2022) - Makes the `Section.setContent()` method public, to allow pre-processing of content before workspace upload/rendering. diff --git a/structurizr-core/src/com/structurizr/model/CreateImpliedRelationshipsUnlessAnyRelationshipExistsStrategy.java b/structurizr-core/src/com/structurizr/model/CreateImpliedRelationshipsUnlessAnyRelationshipExistsStrategy.java index 309b362ab..6d2388074 100644 --- a/structurizr-core/src/com/structurizr/model/CreateImpliedRelationshipsUnlessAnyRelationshipExistsStrategy.java +++ b/structurizr-core/src/com/structurizr/model/CreateImpliedRelationshipsUnlessAnyRelationshipExistsStrategy.java @@ -19,7 +19,10 @@ public void createImpliedRelationships(Relationship relationship) { boolean createRelationship = !source.hasEfferentRelationshipWith(destination); if (createRelationship) { - model.addRelationship(source, destination, relationship.getDescription(), relationship.getTechnology(), relationship.getInteractionStyle(), relationship.getTagsAsSet().toArray(new String[0]), false); + Relationship impliedRelationship = model.addRelationship(source, destination, relationship.getDescription(), relationship.getTechnology(), false); + if (impliedRelationship != null) { + impliedRelationship.setLinkedRelationshipId(relationship.getId()); + } } } diff --git a/structurizr-core/src/com/structurizr/model/CreateImpliedRelationshipsUnlessSameRelationshipExistsStrategy.java b/structurizr-core/src/com/structurizr/model/CreateImpliedRelationshipsUnlessSameRelationshipExistsStrategy.java index ceee5e87e..4abaf94f1 100644 --- a/structurizr-core/src/com/structurizr/model/CreateImpliedRelationshipsUnlessSameRelationshipExistsStrategy.java +++ b/structurizr-core/src/com/structurizr/model/CreateImpliedRelationshipsUnlessSameRelationshipExistsStrategy.java @@ -19,7 +19,10 @@ public void createImpliedRelationships(Relationship relationship) { boolean createRelationship = !source.hasEfferentRelationshipWith(destination, relationship.getDescription()); if (createRelationship) { - model.addRelationship(source, destination, relationship.getDescription(), relationship.getTechnology(), relationship.getInteractionStyle(), relationship.getTagsAsSet().toArray(new String[0]), false); + Relationship impliedRelationship = model.addRelationship(source, destination, relationship.getDescription(), relationship.getTechnology(), false); + if (impliedRelationship != null) { + impliedRelationship.setLinkedRelationshipId(relationship.getId()); + } } } diff --git a/structurizr-core/src/com/structurizr/model/Model.java b/structurizr-core/src/com/structurizr/model/Model.java index 996bd821f..53deec472 100644 --- a/structurizr-core/src/com/structurizr/model/Model.java +++ b/structurizr-core/src/com/structurizr/model/Model.java @@ -238,8 +238,8 @@ Component addComponentOfType(Container parent, String name, String type, String } @Nullable - Relationship addRelationship(Element source, @Nonnull Element destination, String description, String technology) { - return addRelationship(source, destination, description, technology, null); + Relationship addRelationship(Element source, @Nonnull Element destination, String description, String technology, boolean createImpliedRelationships) { + return addRelationship(source, destination, description, technology, null, new String[0], createImpliedRelationships); } @Nullable diff --git a/structurizr-core/test/unit/com/structurizr/model/CreateImpliedRelationshipsUnlessAnyRelationshipExistsStrategyTests.java b/structurizr-core/test/unit/com/structurizr/model/CreateImpliedRelationshipsUnlessAnyRelationshipExistsStrategyTests.java index 5110550ab..d61147232 100644 --- a/structurizr-core/test/unit/com/structurizr/model/CreateImpliedRelationshipsUnlessAnyRelationshipExistsStrategyTests.java +++ b/structurizr-core/test/unit/com/structurizr/model/CreateImpliedRelationshipsUnlessAnyRelationshipExistsStrategyTests.java @@ -3,8 +3,9 @@ import com.structurizr.AbstractWorkspaceTestBase; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import java.util.Set; + +import static org.junit.Assert.*; public class CreateImpliedRelationshipsUnlessAnyRelationshipExistsStrategyTests extends AbstractWorkspaceTestBase { @@ -20,7 +21,7 @@ public void test_impliedRelationshipsAreCreated() { model.setImpliedRelationshipsStrategy(new CreateImpliedRelationshipsUnlessAnyRelationshipExistsStrategy()); - aaa.uses(bbb, "Uses 1", null, InteractionStyle.Asynchronous, new String[] { "Tag 1", "Tag 2" }); + Relationship explicitRelationship = aaa.uses(bbb, "Uses 1", "Technology", InteractionStyle.Asynchronous, new String[] { "Tag 1", "Tag 2" }); assertEquals(9, model.getRelationships().size()); assertTrue(aaa.hasEfferentRelationshipWith(bbb, "Uses 1")); @@ -37,11 +38,14 @@ public void test_impliedRelationshipsAreCreated() { assertTrue(a.hasEfferentRelationshipWith(bb, "Uses 1")); assertTrue(a.hasEfferentRelationshipWith(b, "Uses 1")); - // and all relationships should have the same interaction style and tags - for (Relationship r : model.getRelationships()) { - assertEquals(InteractionStyle.Asynchronous, r.getInteractionStyle()); - assertTrue(r.getTagsAsSet().contains("Tag 1")); - assertTrue(r.getTagsAsSet().contains("Tag 2")); + // all implied relationships with have a linked relationship, technology, and other properties unset + Set impliedRelationships = model.getRelationships(); + impliedRelationships.remove(explicitRelationship); + for (Relationship r : impliedRelationships) { + assertEquals(explicitRelationship.getId(), r.getLinkedRelationshipId()); + assertEquals("Technology", r.getTechnology()); + assertNull(r.getInteractionStyle()); + assertTrue(r.getTagsAsSet().isEmpty()); } // and add another relationship with a different description diff --git a/structurizr-core/test/unit/com/structurizr/model/CreateImpliedRelationshipsUnlessSameRelationshipExistsStrategyTests.java b/structurizr-core/test/unit/com/structurizr/model/CreateImpliedRelationshipsUnlessSameRelationshipExistsStrategyTests.java index 26a5952d4..0fa35ee89 100644 --- a/structurizr-core/test/unit/com/structurizr/model/CreateImpliedRelationshipsUnlessSameRelationshipExistsStrategyTests.java +++ b/structurizr-core/test/unit/com/structurizr/model/CreateImpliedRelationshipsUnlessSameRelationshipExistsStrategyTests.java @@ -3,8 +3,9 @@ import com.structurizr.AbstractWorkspaceTestBase; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import java.util.Set; + +import static org.junit.Assert.*; public class CreateImpliedRelationshipsUnlessSameRelationshipExistsStrategyTests extends AbstractWorkspaceTestBase { @@ -20,16 +21,19 @@ public void test_impliedRelationships_WhenNoSummaryRelationshipsExist() { model.setImpliedRelationshipsStrategy(new CreateImpliedRelationshipsUnlessSameRelationshipExistsStrategy()); - aaa.uses(bbb, "Uses 1", null, InteractionStyle.Asynchronous, new String[] { "Tag 1", "Tag 2" }); + Relationship explicitRelationship = aaa.uses(bbb, "Uses 1", "Technology", InteractionStyle.Asynchronous, new String[] { "Tag 1", "Tag 2" }); assertEquals(9, model.getRelationships().size()); assertTrue(aaa.hasEfferentRelationshipWith(bbb, "Uses 1")); - // and all relationships should have the same interaction style and tags - for (Relationship r : model.getRelationships()) { - assertEquals(InteractionStyle.Asynchronous, r.getInteractionStyle()); - assertTrue(r.getTagsAsSet().contains("Tag 1")); - assertTrue(r.getTagsAsSet().contains("Tag 2")); + // all implied relationships with have a linked relationship, technology, and other properties unset + Set impliedRelationships = model.getRelationships(); + impliedRelationships.remove(explicitRelationship); + for (Relationship r : impliedRelationships) { + assertEquals(explicitRelationship.getId(), r.getLinkedRelationshipId()); + assertEquals("Technology", r.getTechnology()); + assertNull(r.getInteractionStyle()); + assertTrue(r.getTagsAsSet().isEmpty()); } // AAA->BBB implies AAA->BB AAA->B AA->BBB AA->BB AA->B A->BBB A->BB A->B