@@ -13,7 +13,7 @@ class ThemeParserTests extends AbstractTests {
1313 @ Test
1414 void test_parseTheme_ThrowsAnException_WhenThereAreTooManyTokens () {
1515 try {
16- parser .parseTheme (context (), null , tokens ("theme" , "url" , "extra" ));
16+ parser .parseTheme (context (), null , tokens ("theme" , "url" , "extra" ), false );
1717 fail ();
1818 } catch (Exception e ) {
1919 assertEquals ("Too many tokens, expected: theme <url|file>" , e .getMessage ());
@@ -23,7 +23,7 @@ void test_parseTheme_ThrowsAnException_WhenThereAreTooManyTokens() {
2323 @ Test
2424 void test_parseTheme_ThrowsAnException_WhenNoThemeIsSpecified () {
2525 try {
26- parser .parseTheme (context (), null , tokens ("theme" ));
26+ parser .parseTheme (context (), null , tokens ("theme" ), false );
2727 fail ();
2828 } catch (Exception e ) {
2929 assertEquals ("Expected: theme <url|file>" , e .getMessage ());
@@ -32,15 +32,15 @@ void test_parseTheme_ThrowsAnException_WhenNoThemeIsSpecified() {
3232
3333 @ Test
3434 void test_parseTheme_AddsTheTheme_WhenAThemeIsSpecified () {
35- parser .parseTheme (context (), null , tokens ("theme" , "http://example.com/1" ));
35+ parser .parseTheme (context (), null , tokens ("theme" , "http://example.com/1" ), false );
3636
3737 assertEquals (1 , workspace .getViews ().getConfiguration ().getThemes ().length );
3838 assertEquals ("http://example.com/1" , workspace .getViews ().getConfiguration ().getThemes ()[0 ]);
3939 }
4040
4141 @ Test
4242 void test_parseTheme_AddsTheTheme_WhenTheDefaultThemeIsSpecified () {
43- parser .parseTheme (context (), null , tokens ("theme" , "default" ));
43+ parser .parseTheme (context (), null , tokens ("theme" , "default" ), false );
4444
4545 assertEquals (1 , workspace .getViews ().getConfiguration ().getThemes ().length );
4646 assertEquals ("https://static.structurizr.com/themes/default/theme.json" , workspace .getViews ().getConfiguration ().getThemes ()[0 ]);
@@ -49,7 +49,7 @@ void test_parseTheme_AddsTheTheme_WhenTheDefaultThemeIsSpecified() {
4949 @ Test
5050 void test_parseThemes_ThrowsAnException_WhenNoThemesAreSpecified () {
5151 try {
52- parser .parseThemes (context (), null , tokens ("themes" ));
52+ parser .parseThemes (context (), null , tokens ("themes" ), false );
5353 fail ();
5454 } catch (Exception e ) {
5555 assertEquals ("Expected: themes <url|file> [url|file] ... [url|file]" , e .getMessage ());
@@ -58,15 +58,15 @@ void test_parseThemes_ThrowsAnException_WhenNoThemesAreSpecified() {
5858
5959 @ Test
6060 void test_parseThemes_AddsTheTheme_WhenOneThemeIsSpecified () {
61- parser .parseThemes (context (), null , tokens ("themes" , "http://example.com/1" ));
61+ parser .parseThemes (context (), null , tokens ("themes" , "http://example.com/1" ), false );
6262
6363 assertEquals (1 , workspace .getViews ().getConfiguration ().getThemes ().length );
6464 assertEquals ("http://example.com/1" , workspace .getViews ().getConfiguration ().getThemes ()[0 ]);
6565 }
6666
6767 @ Test
6868 void test_parseThemes_AddsTheThemes_WhenMultipleThemesAreSpecified () {
69- parser .parseThemes (context (), null , tokens ("themes" , "http://example.com/1" , "http://example.com/2" , "http://example.com/3" ));
69+ parser .parseThemes (context (), null , tokens ("themes" , "http://example.com/1" , "http://example.com/2" , "http://example.com/3" ), false );
7070
7171 assertEquals (3 , workspace .getViews ().getConfiguration ().getThemes ().length );
7272 assertEquals ("http://example.com/1" , workspace .getViews ().getConfiguration ().getThemes ()[0 ]);
@@ -76,7 +76,7 @@ void test_parseThemes_AddsTheThemes_WhenMultipleThemesAreSpecified() {
7676
7777 @ Test
7878 void test_parseThemes_AddsTheTheme_WhenTheDefaultThemeIsSpecified () {
79- parser .parseThemes (context (), null , tokens ("themes" , "default" ));
79+ parser .parseThemes (context (), null , tokens ("themes" , "default" ), false );
8080
8181 assertEquals (1 , workspace .getViews ().getConfiguration ().getThemes ().length );
8282 assertEquals ("https://static.structurizr.com/themes/default/theme.json" , workspace .getViews ().getConfiguration ().getThemes ()[0 ]);
@@ -86,7 +86,7 @@ void test_parseThemes_AddsTheTheme_WhenTheDefaultThemeIsSpecified() {
8686 void test_parseTheme_ThrowsAnException_WhenTheThemeFileDoesNotExist () {
8787 File dslFile = new File ("src/test/resources/themes/workspace.dsl" );
8888 try {
89- parser .parseTheme (context (), dslFile , tokens ("theme" , "my-theme.json" ));
89+ parser .parseTheme (context (), dslFile , tokens ("theme" , "my-theme.json" ), false );
9090 fail ();
9191 } catch (Exception e ) {
9292 assertTrue (e .getMessage ().endsWith ("/src/test/resources/themes/my-theme.json does not exist" ));
@@ -97,7 +97,7 @@ void test_parseTheme_ThrowsAnException_WhenTheThemeFileDoesNotExist() {
9797 void test_parseTheme_ThrowsAnException_WhenTheThemeFileIsADirectory () {
9898 File dslFile = new File ("src/test/resources/workspace.dsl" );
9999 try {
100- parser .parseTheme (context (), dslFile , tokens ("theme" , "themes" ));
100+ parser .parseTheme (context (), dslFile , tokens ("theme" , "themes" ), false );
101101 fail ();
102102 } catch (Exception e ) {
103103 assertTrue (e .getMessage ().endsWith ("/src/test/resources/themes is not a file" ));
@@ -107,11 +107,22 @@ void test_parseTheme_ThrowsAnException_WhenTheThemeFileIsADirectory() {
107107 @ Test
108108 void test_parseTheme_InlinesTheTheme_WhenAThemeFileIsSpecified () {
109109 File dslFile = new File ("src/test/resources/themes/workspace.dsl" );
110- parser .parseTheme (context (), dslFile , tokens ("theme" , "theme.json" ));
110+ parser .parseTheme (context (), dslFile , tokens ("theme" , "theme.json" ), false );
111111
112112 assertEquals (0 , workspace .getViews ().getConfiguration ().getThemes ().length );
113113 assertEquals ("#ff0000" , workspace .getViews ().getConfiguration ().getStyles ().getElementStyle ("Tag" ).getBackground ());
114114 assertEquals ("#00ff00" , workspace .getViews ().getConfiguration ().getStyles ().getRelationshipStyle ("Tag" ).getColor ());
115115 }
116116
117+ @ Test
118+ void test_parseTheme_ThrowsAnException_WhenAThemeFileIsSpecifiedAndTheParserIsRunningInRestrictedMode () {
119+ try {
120+ File dslFile = new File ("src/test/resources/themes/workspace.dsl" );
121+ parser .parseTheme (context (), dslFile , tokens ("theme" , "theme.json" ), true );
122+ fail ();
123+ } catch (Exception e ) {
124+ assertEquals ("File-based themes are not supported when the DSL parser is running in restricted mode" , e .getMessage ());
125+ }
126+ }
127+
117128}
0 commit comments