diff --git a/docs/changelog.md b/docs/changelog.md index eb1c82c..e727107 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,7 @@ ## 1.35.0 (26th November 2023) +- Adds workspace scope validation - see https://docs.structurizr.com/workspaces for details. - structurizr/dsl: Updated to 1.34.0 - [changelog](https://github.com/structurizr/dsl/releases/tag/v1.34.0). - structurizr/export: Updated to 1.18.0 - [changelog](https://github.com/structurizr/export/releases/tag/v1.18.0). diff --git a/src/main/java/com/structurizr/cli/AbstractCommand.java b/src/main/java/com/structurizr/cli/AbstractCommand.java index f3e27b7..f71db6d 100644 --- a/src/main/java/com/structurizr/cli/AbstractCommand.java +++ b/src/main/java/com/structurizr/cli/AbstractCommand.java @@ -3,6 +3,7 @@ import com.structurizr.Workspace; import com.structurizr.dsl.StructurizrDslParser; import com.structurizr.util.WorkspaceUtils; +import com.structurizr.validation.WorkspaceScopeValidatorFactory; import com.structurizr.view.Styles; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -90,6 +91,9 @@ protected Workspace loadWorkspace(String workspacePathAsString) throws Exception } } + // validate workspace scope + WorkspaceScopeValidatorFactory.getValidator(workspace).validate(workspace); + return workspace; } diff --git a/src/test/dsl/workspace-scope.dsl b/src/test/dsl/workspace-scope.dsl new file mode 100644 index 0000000..e30e59e --- /dev/null +++ b/src/test/dsl/workspace-scope.dsl @@ -0,0 +1,14 @@ +workspace { + model { + softwareSystem "A" { + container "API" + } + softwareSystem "B" { + container "API" + } + } + + configuration { + scope softwareSystem + } +} \ No newline at end of file diff --git a/src/test/java/com/structurizr/cli/AbstractCommandTests.java b/src/test/java/com/structurizr/cli/AbstractCommandTests.java index e0ff54f..2a13e3d 100644 --- a/src/test/java/com/structurizr/cli/AbstractCommandTests.java +++ b/src/test/java/com/structurizr/cli/AbstractCommandTests.java @@ -2,8 +2,7 @@ import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.*; public class AbstractCommandTests { @@ -17,5 +16,14 @@ public void loadWorkspace_ThrowsAnException_WhenTheWorkspacePathIsADirectory() { } } + @Test + public void loadWorkspace_ThrowsAnException_WhenWorkspaceScopeValidationFails() { + try { + new ValidateCommand().loadWorkspace("src/test/dsl/workspace-scope.dsl"); + fail(); + } catch (Exception e) { + assertEquals("Workspace is software system scoped, but multiple software systems have containers and/or documentation defined.", e.getMessage()); + } + } } \ No newline at end of file