Skip to content

Commit

Permalink
Fixes #167 (ImpliedRelationship Strategy replication of URL and persp…
Browse files Browse the repository at this point in the history
…ectives).
  • Loading branch information
simonbrowndotje committed Feb 18, 2022
1 parent edb1cc6 commit 0d86355
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ subprojects { proj ->

description = 'Structurizr'
group = 'com.structurizr'
version = '1.10.1'
version = '1.11.0'

repositories {
mavenCentral()
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions structurizr-core/src/com/structurizr/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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"));
Expand All @@ -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<Relationship> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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<Relationship> 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
Expand Down

0 comments on commit 0d86355

Please sign in to comment.