-
-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecates
!ref
and !extend
in favour of !element
and `!relatio…
…nship`.
- Loading branch information
1 parent
bb68483
commit f26f63d
Showing
19 changed files
with
271 additions
and
53 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
48 changes: 48 additions & 0 deletions
48
structurizr-dsl/src/main/java/com/structurizr/dsl/FindElementParser.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,48 @@ | ||
package com.structurizr.dsl; | ||
|
||
import com.structurizr.model.Element; | ||
import com.structurizr.model.StaticStructureElement; | ||
|
||
final class FindElementParser extends AbstractParser { | ||
|
||
private static final String GRAMMAR = "!element <identifier|canonical name>"; | ||
|
||
private final static int IDENTIFIER_INDEX = 1; | ||
|
||
Element parse(DslContext context, Tokens tokens) { | ||
// !element <identifier|canonical name> | ||
|
||
if (tokens.hasMoreThan(IDENTIFIER_INDEX)) { | ||
throw new RuntimeException("Too many tokens, expected: " + GRAMMAR); | ||
} | ||
|
||
if (!tokens.includes(IDENTIFIER_INDEX)) { | ||
throw new RuntimeException("Expected: " + GRAMMAR); | ||
} | ||
|
||
String s = tokens.get(IDENTIFIER_INDEX); | ||
|
||
Element element; | ||
|
||
if (s.contains("://")) { | ||
element = context.getWorkspace().getModel().getElementWithCanonicalName(s); | ||
} else { | ||
element = context.getElement(s); | ||
} | ||
|
||
if (element == null) { | ||
throw new RuntimeException("An element identified by \"" + s + "\" could not be found"); | ||
} | ||
|
||
if (context instanceof GroupableDslContext && element instanceof StaticStructureElement) { | ||
GroupableDslContext groupableDslContext = (GroupableDslContext)context; | ||
StaticStructureElement staticStructureElement = (StaticStructureElement)element; | ||
if (groupableDslContext.hasGroup()) { | ||
staticStructureElement.setGroup(groupableDslContext.getGroup().getName()); | ||
} | ||
} | ||
|
||
return element; | ||
} | ||
|
||
} |
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
33 changes: 33 additions & 0 deletions
33
structurizr-dsl/src/main/java/com/structurizr/dsl/FindRelationshipParser.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,33 @@ | ||
package com.structurizr.dsl; | ||
|
||
import com.structurizr.model.Relationship; | ||
|
||
final class FindRelationshipParser extends AbstractParser { | ||
|
||
private static final String GRAMMAR = "!relationship <identifier>"; | ||
|
||
private final static int IDENTIFIER_INDEX = 1; | ||
|
||
Relationship parse(DslContext context, Tokens tokens) { | ||
// !relationship <identifier|canonical name> | ||
|
||
if (tokens.hasMoreThan(IDENTIFIER_INDEX)) { | ||
throw new RuntimeException("Too many tokens, expected: " + GRAMMAR); | ||
} | ||
|
||
if (!tokens.includes(IDENTIFIER_INDEX)) { | ||
throw new RuntimeException("Expected: " + GRAMMAR); | ||
} | ||
|
||
String s = tokens.get(IDENTIFIER_INDEX); | ||
|
||
Relationship relationship = context.getRelationship(s); | ||
|
||
if (relationship == null) { | ||
throw new RuntimeException("A relationship identified by \"" + s + "\" could not be found"); | ||
} | ||
|
||
return relationship; | ||
} | ||
|
||
} |
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
64 changes: 64 additions & 0 deletions
64
structurizr-dsl/src/test/java/com/structurizr/dsl/FindElementParserTests.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,64 @@ | ||
package com.structurizr.dsl; | ||
|
||
import com.structurizr.model.ModelItem; | ||
import com.structurizr.model.Person; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class FindElementParserTests extends AbstractTests { | ||
|
||
private final FindElementParser parser = new FindElementParser(); | ||
|
||
@Test | ||
void test_parse_ThrowsAnException_WhenThereAreTooManyTokens() { | ||
try { | ||
parser.parse(context(), tokens("!element", "name", "tokens")); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Too many tokens, expected: !element <identifier|canonical name>", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
void test_parse_ThrowsAnException_WhenTheIdentifierOrCanonicalNameIsNotSpecified() { | ||
try { | ||
parser.parse(context(), tokens("!element")); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Expected: !element <identifier|canonical name>", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
void test_parse_ThrowsAnException_WhenTheReferencedElementCannotBeFound() { | ||
try { | ||
parser.parse(context(), tokens("!element", "Person://User")); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("An element identified by \"Person://User\" could not be found", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
void test_parse_FindsAnElementByCanonicalName() { | ||
Person user = workspace.getModel().addPerson("User"); | ||
ModelItem element = parser.parse(context(), tokens("!element", "Person://User")); | ||
|
||
assertSame(user, element); | ||
} | ||
|
||
@Test | ||
void test_parse_FindsAnElementByIdentifier() { | ||
Person user = workspace.getModel().addPerson("User"); | ||
|
||
ModelDslContext context = context(); | ||
IdentifiersRegister register = new IdentifiersRegister(); | ||
register.register("user", user); | ||
context.setIdentifierRegister(register); | ||
|
||
ModelItem modelItem = parser.parse(context, tokens("!element", "user")); | ||
assertSame(modelItem, user); | ||
} | ||
|
||
} |
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
58 changes: 58 additions & 0 deletions
58
structurizr-dsl/src/test/java/com/structurizr/dsl/FindRelationshipParserTests.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,58 @@ | ||
package com.structurizr.dsl; | ||
|
||
import com.structurizr.model.ModelItem; | ||
import com.structurizr.model.Person; | ||
import com.structurizr.model.Relationship; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class FindRelationshipParserTests extends AbstractTests { | ||
|
||
private final FindRelationshipParser parser = new FindRelationshipParser(); | ||
|
||
@Test | ||
void test_parse_ThrowsAnException_WhenThereAreTooManyTokens() { | ||
try { | ||
parser.parse(context(), tokens("!relationship", "name", "tokens")); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Too many tokens, expected: !relationship <identifier>", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
void test_parse_ThrowsAnException_WhenTheIdentifierIsNotSpecified() { | ||
try { | ||
parser.parse(context(), tokens("!relationship")); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Expected: !relationship <identifier>", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
void test_parse_ThrowsAnException_WhenTheReferencedRelationshipCannotBeFound() { | ||
try { | ||
parser.parse(context(), tokens("!relationship", "rel")); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("A relationship identified by \"rel\" could not be found", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
void test_parse_FindsARelationshipByIdentifier() { | ||
Person user = workspace.getModel().addPerson("User"); | ||
Relationship relationship = user.interactsWith(user, "Description"); | ||
|
||
ModelDslContext context = context(); | ||
IdentifiersRegister register = new IdentifiersRegister(); | ||
register.register("rel", relationship); | ||
context.setIdentifierRegister(register); | ||
|
||
ModelItem modelItem = parser.parse(context, tokens("!relationship", "rel")); | ||
assertSame(modelItem, relationship); | ||
} | ||
|
||
} |
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
Oops, something went wrong.