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.
Adds the ability to specify the workspace
visibility
(private/publi…
…c) via the workspace configuration.
- Loading branch information
1 parent
58a84de
commit 4a08e44
Showing
8 changed files
with
109 additions
and
2 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
34 changes: 34 additions & 0 deletions
34
src/main/java/com/structurizr/dsl/ConfigurationParser.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,34 @@ | ||
package com.structurizr.dsl; | ||
|
||
import com.structurizr.configuration.Visibility; | ||
|
||
final class ConfigurationParser extends AbstractParser { | ||
|
||
private static final String GRAMMAR = "visibility <private|public>"; | ||
|
||
private static final int FIRST_PROPERTY_INDEX = 1; | ||
|
||
private static final String PRIVATE = "private"; | ||
private static final String PUBLIC = "public"; | ||
|
||
void parseVisibility(DslContext context, Tokens tokens) { | ||
if (tokens.hasMoreThan(FIRST_PROPERTY_INDEX)) { | ||
throw new RuntimeException("Too many tokens, expected: " + GRAMMAR); | ||
} | ||
|
||
if (tokens.includes(FIRST_PROPERTY_INDEX)) { | ||
String visibility = tokens.get(1).toLowerCase(); | ||
|
||
if (visibility.equalsIgnoreCase(PRIVATE)) { | ||
context.getWorkspace().getConfiguration().setVisibility(Visibility.Private); | ||
} else if (visibility.equalsIgnoreCase(PUBLIC)) { | ||
context.getWorkspace().getConfiguration().setVisibility(Visibility.Public); | ||
} else { | ||
throw new RuntimeException("The visibility \"" + visibility + "\" is not valid"); | ||
} | ||
} else { | ||
throw new RuntimeException("Expected: " + GRAMMAR); | ||
} | ||
} | ||
|
||
} |
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
49 changes: 49 additions & 0 deletions
49
src/test/java/com/structurizr/dsl/ConfigurationParserTests.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,49 @@ | ||
package com.structurizr.dsl; | ||
|
||
import com.structurizr.configuration.Visibility; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
class ConfigurationParserTests extends AbstractTests { | ||
|
||
private final ConfigurationParser parser = new ConfigurationParser(); | ||
|
||
@Test | ||
void test_parseVisibility_ThrowsAnException_WhenThereAreTooManyTokens() { | ||
try { | ||
parser.parseVisibility(context(), tokens("visibility", "public", "extra")); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Too many tokens, expected: visibility <private|public>", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
void test_parseVisibility_ThrowsAnException_WhenTheVisibilityIsMissing() { | ||
try { | ||
parser.parseVisibility(context(), tokens("visibility")); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("Expected: visibility <private|public>", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
void test_parseVisibility_ThrowsAnException_WhenTheVisibilityIsNotValid() { | ||
try { | ||
parser.parseVisibility(context(), tokens("visibility", "shared")); | ||
fail(); | ||
} catch (Exception e) { | ||
assertEquals("The visibility \"shared\" is not valid", e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
void test_parseVisibility_SetsTheVisibility() { | ||
parser.parseVisibility(context(), tokens("visibility", "public")); | ||
assertEquals(Visibility.Public, workspace.getConfiguration().getVisibility()); | ||
} | ||
|
||
} |