-
-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
structurizr-dsl: Adds the ability to use the
group
keyword inside a…
… component definition, to set the group name of that component.
- Loading branch information
1 parent
4e27be6
commit 5b64d91
Showing
7 changed files
with
134 additions
and
25 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
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
84 changes: 71 additions & 13 deletions
84
structurizr-dsl/src/test/java/com/structurizr/dsl/GroupParserTests.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 |
---|---|---|
@@ -1,72 +1,130 @@ | ||
package com.structurizr.dsl; | ||
|
||
import com.structurizr.model.Component; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class GroupParserTests extends AbstractTests { | ||
|
||
private GroupParser parser = new GroupParser(); | ||
private final GroupParser parser = new GroupParser(); | ||
|
||
@Test | ||
void parse_ThrowsAnException_WhenThereAreTooManyTokens() { | ||
void parseContext_ThrowsAnException_WhenThereAreTooManyTokens() { | ||
try { | ||
parser.parse(null, tokens("group", "name", "{", "extra")); | ||
parser.parseContext(null, tokens("group", "name", "{", "extra")); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Too many tokens, expected: group <name> {", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
void parse_ThrowsAnException_WhenTheNameIsMissing() { | ||
void parseContext_ThrowsAnException_WhenTheNameIsMissing() { | ||
try { | ||
parser.parse(null, tokens("group")); | ||
parser.parseContext(null, tokens("group")); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Expected: group <name> {", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
void parse_ThrowsAnException_WhenTheBraceIsMissing() { | ||
void parseContext_ThrowsAnException_WhenTheBraceIsMissing() { | ||
try { | ||
parser.parse(null, tokens("group", "Name", "foo")); | ||
parser.parseContext(null, tokens("group", "Name", "foo")); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Expected: group <name> {", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
void parse() { | ||
ElementGroup group = parser.parse(context(), tokens("group", "Group 1", "{")); | ||
void parseContext() { | ||
ElementGroup group = parser.parseContext(context(), tokens("group", "Group 1", "{")); | ||
assertEquals("Group 1", group.getName()); | ||
assertTrue(group.getElements().isEmpty()); | ||
} | ||
|
||
@Test | ||
void parse_NestedGroup_ThrowsAnExceptionWhenNestedGroupsAreNotConfigured() { | ||
void parseContext_NestedGroup_ThrowsAnExceptionWhenNestedGroupsAreNotConfigured() { | ||
ModelDslContext context = new ModelDslContext(new ElementGroup("Group 1")); | ||
context.setWorkspace(workspace); | ||
|
||
try { | ||
parser.parse(context, tokens("group", "Group 2", "{")); | ||
parser.parseContext(context, tokens("group", "Group 2", "{")); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("To use nested groups, please define a model property named structurizr.groupSeparator", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
void parse_NestedGroup() { | ||
void parseContext_NestedGroup() { | ||
workspace.getModel().addProperty("structurizr.groupSeparator", "/"); | ||
ModelDslContext context = new ModelDslContext(new ElementGroup("Group 1")); | ||
context.setWorkspace(workspace); | ||
|
||
ElementGroup group = parser.parse(context, tokens("group", "Group 2", "{")); | ||
ElementGroup group = parser.parseContext(context, tokens("group", "Group 2", "{")); | ||
assertEquals("Group 1/Group 2", group.getName()); | ||
assertTrue(group.getElements().isEmpty()); | ||
} | ||
|
||
@Test | ||
void parseProperty_ThrowsAnException_WhenThereAreTooManyTokens() { | ||
try { | ||
parser.parseProperty(null, tokens("group", "name", "extra")); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Too many tokens, expected: group <name>", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
void parseProperty_ThrowsAnException_WhenTheNameIsMissing() { | ||
try { | ||
parser.parseProperty(null, tokens("group")); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Expected: group <name>", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
void parseProperty() { | ||
Component component = workspace.getModel().addSoftwareSystem("Name").addContainer("Name").addComponent("Name"); | ||
ComponentDslContext context = new ComponentDslContext(component); | ||
context.setWorkspace(workspace); | ||
|
||
parser.parseProperty(context, tokens("group", "Group 1")); | ||
assertEquals("Group 1", component.getGroup()); | ||
} | ||
|
||
@Test | ||
void parseProperty_NestedGroup_ThrowsAnExceptionWhenNestedGroupsAreNotConfigured() { | ||
Component component = workspace.getModel().addSoftwareSystem("Name").addContainer("Name").addComponent("Name"); | ||
component.setGroup("Group 1"); | ||
ComponentDslContext context = new ComponentDslContext(component); | ||
context.setWorkspace(workspace); | ||
|
||
try { | ||
parser.parseProperty(context, tokens("group", "Group 2")); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("To use nested groups, please define a model property named structurizr.groupSeparator", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
void parseProperty_NestedGroup() { | ||
workspace.getModel().addProperty("structurizr.groupSeparator", "/"); | ||
Component component = workspace.getModel().addSoftwareSystem("Name").addContainer("Name").addComponent("Name"); | ||
component.setGroup("Group 1"); | ||
ComponentDslContext context = new ComponentDslContext(component); | ||
context.setWorkspace(workspace); | ||
|
||
parser.parseProperty(context, tokens("group", "Group 2")); | ||
assertEquals("Group 1/Group 2", component.getGroup()); | ||
} | ||
|
||
} |
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