This repository has been archived by the owner on Jan 10, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8ae7cf
commit 2fcd0ee
Showing
7 changed files
with
121 additions
and
7 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
26 changes: 26 additions & 0 deletions
26
src/main/java/com/structurizr/dsl/DynamicViewRelationshipContext.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.dsl; | ||
|
||
import com.structurizr.view.RelationshipView; | ||
|
||
class DynamicViewRelationshipContext extends DslContext { | ||
|
||
private final RelationshipView relationshipView; | ||
|
||
DynamicViewRelationshipContext(RelationshipView relationshipView) { | ||
super(); | ||
|
||
this.relationshipView = relationshipView; | ||
} | ||
|
||
RelationshipView getRelationshipView() { | ||
return relationshipView; | ||
} | ||
|
||
@Override | ||
protected String[] getPermittedTokens() { | ||
return new String[] { | ||
StructurizrDslTokens.URL_TOKEN | ||
}; | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/structurizr/dsl/DynamicViewRelationshipParser.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.dsl; | ||
|
||
final class DynamicViewRelationshipParser extends AbstractParser { | ||
|
||
private final static int URL_INDEX = 1; | ||
|
||
void parseUrl(DynamicViewRelationshipContext context, Tokens tokens) { | ||
// url <url> | ||
if (tokens.hasMoreThan(URL_INDEX)) { | ||
throw new RuntimeException("Too many tokens, expected: url <url>"); | ||
} | ||
|
||
if (!tokens.includes(URL_INDEX)) { | ||
throw new RuntimeException("Expected: url <url>"); | ||
} | ||
|
||
String url = tokens.get(URL_INDEX); | ||
context.getRelationshipView().setUrl(url); | ||
} | ||
|
||
} |
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
52 changes: 52 additions & 0 deletions
52
src/test/java/com/structurizr/dsl/DynamicViewRelationshipParserTests.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,52 @@ | ||
package com.structurizr.dsl; | ||
|
||
import com.structurizr.model.Relationship; | ||
import com.structurizr.model.SoftwareSystem; | ||
import com.structurizr.view.DynamicView; | ||
import com.structurizr.view.RelationshipView; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
class DynamicViewRelationshipParserTests extends AbstractTests { | ||
|
||
private final DynamicViewRelationshipParser parser = new DynamicViewRelationshipParser(); | ||
|
||
@Test | ||
void test_parseUrl_ThrowsAnException_WhenThereAreTooManyTokens() { | ||
try { | ||
DynamicViewRelationshipContext context = new DynamicViewRelationshipContext(null); | ||
parser.parseUrl(context, tokens("url", "url", "extra")); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Too many tokens, expected: url <url>", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
void test_parseUrl_ThrowsAnException_WhenNoUrlIsSpecified() { | ||
try { | ||
DynamicViewRelationshipContext context = new DynamicViewRelationshipContext(null); | ||
parser.parseUrl(context, tokens("url")); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Expected: url <url>", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
void test_parseUrl_SetsTheUrl_WhenAUrlIsSpecified() { | ||
SoftwareSystem a = model.addSoftwareSystem("A"); | ||
SoftwareSystem b = model.addSoftwareSystem("B"); | ||
Relationship r = a.uses(b, "Uses"); | ||
|
||
DynamicView dynamicView = workspace.getViews().createDynamicView("key", "Description"); | ||
RelationshipView rv = dynamicView.add(r); | ||
DynamicViewRelationshipContext context = new DynamicViewRelationshipContext(rv); | ||
parser.parseUrl(context, tokens("url", "http://example.com")); | ||
|
||
assertEquals("http://example.com", rv.getUrl()); | ||
} | ||
|
||
} |