-
-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the ability to scope and validate a workspace.
- Loading branch information
1 parent
7d55bbb
commit c73ecff
Showing
13 changed files
with
276 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.structurizr; | ||
|
||
public enum WorkspaceScope { | ||
|
||
Landscape, | ||
SoftwareSystem | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
structurizr-core/src/com/structurizr/validation/LandscapeWorkspaceScopeValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.structurizr.validation; | ||
|
||
import com.structurizr.Workspace; | ||
import com.structurizr.model.Model; | ||
import com.structurizr.model.SoftwareSystem; | ||
|
||
/** | ||
* Validates that the workspace does not define containers and software system level documentation. | ||
*/ | ||
public class LandscapeWorkspaceScopeValidator implements WorkspaceScopeValidator { | ||
|
||
@Override | ||
public void validate(Workspace workspace) throws WorkspaceScopeValidationException { | ||
Model model = workspace.getModel(); | ||
for (SoftwareSystem softwareSystem : model.getSoftwareSystems()) { | ||
if (softwareSystem.getContainers().size() > 0) { | ||
throw new WorkspaceScopeValidationException("Workspace is landscape scoped, but the software system named " + softwareSystem.getName() + " has containers."); | ||
} | ||
|
||
if (!softwareSystem.getDocumentation().isEmpty()) { | ||
throw new WorkspaceScopeValidationException("Workspace is landscape scoped, but the software system named " + softwareSystem.getName() + " has documentation."); | ||
} | ||
} | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
structurizr-core/src/com/structurizr/validation/SoftwareSystemWorkspaceScopeValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.structurizr.validation; | ||
|
||
import com.structurizr.Workspace; | ||
import com.structurizr.model.Model; | ||
|
||
/** | ||
* Validates that the workspace only defines detail (containers and documentation) for a single software system. | ||
*/ | ||
public class SoftwareSystemWorkspaceScopeValidator implements WorkspaceScopeValidator { | ||
|
||
@Override | ||
public void validate(Workspace workspace) throws WorkspaceScopeValidationException { | ||
Model model = workspace.getModel(); | ||
long softwareSystemsWithContainersOrDocumentation = model.getSoftwareSystems().stream().filter(ss -> ss.getContainers().size() > 0 || !ss.getDocumentation().isEmpty()).count(); | ||
|
||
if (softwareSystemsWithContainersOrDocumentation > 1) { | ||
throw new WorkspaceScopeValidationException("Workspace is software system scoped, but multiple software systems have containers and/or documentation defined."); | ||
} | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
structurizr-core/src/com/structurizr/validation/UndefinedWorkspaceScopeValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.structurizr.validation; | ||
|
||
import com.structurizr.Workspace; | ||
|
||
public class UndefinedWorkspaceScopeValidator implements WorkspaceScopeValidator { | ||
|
||
@Override | ||
public void validate(Workspace workspace) throws WorkspaceScopeValidationException { | ||
// no-op | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
structurizr-core/src/com/structurizr/validation/WorkspaceScopeValidationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.structurizr.validation; | ||
|
||
public class WorkspaceScopeValidationException extends Exception { | ||
|
||
public WorkspaceScopeValidationException(String message) { | ||
super(message); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
structurizr-core/src/com/structurizr/validation/WorkspaceScopeValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.structurizr.validation; | ||
|
||
import com.structurizr.Workspace; | ||
|
||
public interface WorkspaceScopeValidator { | ||
|
||
void validate(Workspace workspace) throws WorkspaceScopeValidationException; | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
structurizr-core/src/com/structurizr/validation/WorkspaceScopeValidatorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.structurizr.validation; | ||
|
||
import com.structurizr.Workspace; | ||
import com.structurizr.WorkspaceScope; | ||
|
||
public final class WorkspaceScopeValidatorFactory { | ||
|
||
public static WorkspaceScopeValidator getValidator(Workspace workspace) { | ||
if (workspace.getScope() == WorkspaceScope.Landscape) { | ||
return new LandscapeWorkspaceScopeValidator(); | ||
} else if (workspace.getScope() == WorkspaceScope.SoftwareSystem) { | ||
return new SoftwareSystemWorkspaceScopeValidator(); | ||
} else { | ||
return new UndefinedWorkspaceScopeValidator(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...rizr-core/test/unit/com/structurizr/validation/LandscapeWorkspaceScopeValidatorTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.structurizr.validation; | ||
|
||
import com.structurizr.Workspace; | ||
import com.structurizr.documentation.Format; | ||
import com.structurizr.documentation.Section; | ||
import com.structurizr.validation.LandscapeWorkspaceScopeValidator; | ||
import com.structurizr.validation.WorkspaceScopeValidationException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
public class LandscapeWorkspaceScopeValidatorTests { | ||
|
||
private final LandscapeWorkspaceScopeValidator validator = new LandscapeWorkspaceScopeValidator(); | ||
|
||
@Test | ||
void validate() throws Exception { | ||
Workspace workspace = new Workspace("Name", "Description"); | ||
validator.validate(workspace); | ||
|
||
workspace.getModel().addPerson("User"); | ||
validator.validate(workspace); | ||
|
||
workspace.getModel().addSoftwareSystem("A"); | ||
validator.validate(workspace); | ||
|
||
workspace.getModel().addSoftwareSystem("B"); | ||
validator.validate(workspace); | ||
} | ||
|
||
@Test | ||
void validate_ThrowsAnException_WhenContainersAreDefined() { | ||
Workspace workspace = new Workspace("Name", "Description"); | ||
workspace.getModel().addSoftwareSystem("A").addContainer("AA"); | ||
try { | ||
validator.validate(workspace); | ||
fail(); | ||
} catch (WorkspaceScopeValidationException e) { | ||
assertEquals("Workspace is landscape scoped, but the software system named A has containers.", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
void validate_ThrowsAnException_WhenSoftwareSystemDocumentationIsDefined() { | ||
Workspace workspace = new Workspace("Name", "Description"); | ||
workspace.getModel().addSoftwareSystem("A").getDocumentation().addSection(new Section(Format.Markdown, "## Heading 1")); | ||
try { | ||
validator.validate(workspace); | ||
fail(); | ||
} catch (WorkspaceScopeValidationException e) { | ||
assertEquals("Workspace is landscape scoped, but the software system named A has documentation.", e.getMessage()); | ||
} | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
...core/test/unit/com/structurizr/validation/SoftwareSystemWorkspaceScopeValidatorTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.structurizr.validation; | ||
|
||
import com.structurizr.Workspace; | ||
import com.structurizr.documentation.Format; | ||
import com.structurizr.documentation.Section; | ||
import com.structurizr.model.SoftwareSystem; | ||
import com.structurizr.validation.SoftwareSystemWorkspaceScopeValidator; | ||
import com.structurizr.validation.WorkspaceScopeValidationException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
public class SoftwareSystemWorkspaceScopeValidatorTests { | ||
|
||
private final SoftwareSystemWorkspaceScopeValidator validator = new SoftwareSystemWorkspaceScopeValidator(); | ||
|
||
@Test | ||
void validate() throws Exception { | ||
Workspace workspace = new Workspace("Name", "Description"); | ||
validator.validate(workspace); | ||
|
||
workspace.getModel().addPerson("User"); | ||
validator.validate(workspace); | ||
|
||
SoftwareSystem a = workspace.getModel().addSoftwareSystem("A"); | ||
a.addContainer("AA"); | ||
a.getDocumentation().addSection(new Section(Format.Markdown, "## Heading 1")); | ||
validator.validate(workspace); | ||
|
||
workspace.getModel().addSoftwareSystem("B"); | ||
validator.validate(workspace); | ||
} | ||
|
||
@Test | ||
void validate_ThrowsAnException_WhenMultipleSoftwareSystemsDefineContainers() { | ||
Workspace workspace = new Workspace("Name", "Description"); | ||
workspace.getModel().addSoftwareSystem("A").addContainer("AA"); | ||
workspace.getModel().addSoftwareSystem("B").addContainer("BB"); | ||
try { | ||
validator.validate(workspace); | ||
fail(); | ||
} catch (WorkspaceScopeValidationException e) { | ||
assertEquals("Workspace is software system scoped, but multiple software systems have containers and/or documentation defined.", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
void validate_ThrowsAnException_WhenMultipleSoftwareSystemsDefineDocumentation() { | ||
Workspace workspace = new Workspace("Name", "Description"); | ||
workspace.getModel().addSoftwareSystem("A").getDocumentation().addSection(new Section(Format.Markdown, "## Heading 1")); | ||
workspace.getModel().addSoftwareSystem("B").getDocumentation().addSection(new Section(Format.Markdown, "## Heading 1")); | ||
try { | ||
validator.validate(workspace); | ||
fail(); | ||
} catch (WorkspaceScopeValidationException e) { | ||
assertEquals("Workspace is software system scoped, but multiple software systems have containers and/or documentation defined.", e.getMessage()); | ||
} | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...turizr-core/test/unit/com/structurizr/validation/WorkspaceScopeValidatorFactoryTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.structurizr.validation; | ||
|
||
import com.structurizr.Workspace; | ||
import com.structurizr.WorkspaceScope; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class WorkspaceScopeValidatorFactoryTests { | ||
|
||
@Test | ||
void getValidator() { | ||
Workspace workspace = new Workspace("Name", "Description"); | ||
assertTrue(WorkspaceScopeValidatorFactory.getValidator(workspace) instanceof UndefinedWorkspaceScopeValidator); | ||
|
||
workspace.setScope(WorkspaceScope.Landscape); | ||
assertTrue(WorkspaceScopeValidatorFactory.getValidator(workspace) instanceof LandscapeWorkspaceScopeValidator); | ||
|
||
workspace.setScope(WorkspaceScope.SoftwareSystem); | ||
assertTrue(WorkspaceScopeValidatorFactory.getValidator(workspace) instanceof SoftwareSystemWorkspaceScopeValidator); | ||
} | ||
|
||
} |