Skip to content

Commit

Permalink
Adds workspace scope validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Nov 26, 2023
1 parent c5acb8a commit ab85d83
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/structurizr/cli/AbstractCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,6 +91,9 @@ protected Workspace loadWorkspace(String workspacePathAsString) throws Exception
}
}

// validate workspace scope
WorkspaceScopeValidatorFactory.getValidator(workspace).validate(workspace);

return workspace;
}

Expand Down
14 changes: 14 additions & 0 deletions src/test/dsl/workspace-scope.dsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
workspace {
model {
softwareSystem "A" {
container "API"
}
softwareSystem "B" {
container "API"
}
}

configuration {
scope softwareSystem
}
}
12 changes: 10 additions & 2 deletions src/test/java/com/structurizr/cli/AbstractCommandTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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());
}
}

}

0 comments on commit ab85d83

Please sign in to comment.