diff --git a/structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java b/structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java index 41c50e88..62125ba9 100644 --- a/structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java +++ b/structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java @@ -1031,13 +1031,13 @@ void test_imageViews_ViaFiles() throws Exception { ImageView plantumlView = (ImageView)workspace.getViews().getViewWithKey("plantuml"); assertEquals("diagram.puml", plantumlView.getTitle()); - assertEquals("http://localhost:7777/png/SoWkIImgAStDuNBAJrBGjLDmpCbCJbMmKiX8pSd9vt98pKi1IW80", plantumlView.getContent()); - assertEquals("image/png", plantumlView.getContentType()); + assertEquals("http://localhost:7777/svg/SoWkIImgAStDuNBAJrBGjLDmpCbCJbMmKiX8pSd9vt98pKi1IW80", plantumlView.getContent()); + assertEquals("image/svg+xml", plantumlView.getContentType()); ImageView mermaidView = (ImageView)workspace.getViews().getViewWithKey("mermaid"); assertEquals("diagram.mmd", mermaidView.getTitle()); - assertEquals("http://localhost:8888/img/Zmxvd2NoYXJ0IFRECiAgICBTdGFydCAtLT4gU3RvcA==?type=png", mermaidView.getContent()); - assertEquals("image/png", mermaidView.getContentType()); + assertEquals("http://localhost:8888/svg/Zmxvd2NoYXJ0IFRECiAgICBTdGFydCAtLT4gU3RvcA==", mermaidView.getContent()); + assertEquals("image/svg+xml", mermaidView.getContentType()); ImageView krokiView = (ImageView)workspace.getViews().getViewWithKey("kroki"); assertEquals("diagram.dot", krokiView.getTitle()); diff --git a/structurizr-dsl/src/test/java/com/structurizr/dsl/ImageViewContentParserTests.java b/structurizr-dsl/src/test/java/com/structurizr/dsl/ImageViewContentParserTests.java index 4e693973..fe2eef5e 100644 --- a/structurizr-dsl/src/test/java/com/structurizr/dsl/ImageViewContentParserTests.java +++ b/structurizr-dsl/src/test/java/com/structurizr/dsl/ImageViewContentParserTests.java @@ -20,8 +20,10 @@ void setUp() { @Test void test_parsePlantUML_ThrowsAnException_WhenUsingAFileNameInRestrictedMode() { try { + ImageViewDslContext context = new ImageViewDslContext(imageView); + context.setWorkspace(workspace); parser = new ImageViewContentParser(true); - parser.parsePlantUML(new ImageViewDslContext(imageView), null, tokens("plantuml", "image.puml")); + parser.parsePlantUML(context, null, tokens("plantuml", "image.puml")); fail(); } catch (Exception e) { assertEquals("PlantUML source must be specified as a URL when running in restricted mode", e.getMessage()); @@ -31,8 +33,10 @@ void test_parsePlantUML_ThrowsAnException_WhenUsingAFileNameInRestrictedMode() { @Test void test_parseMermaid_ThrowsAnException_WhenUsingAFileNameInRestrictedMode() { try { + ImageViewDslContext context = new ImageViewDslContext(imageView); + context.setWorkspace(workspace); parser = new ImageViewContentParser(true); - parser.parseMermaid(new ImageViewDslContext(imageView), null, tokens("mermaid", "image.puml")); + parser.parseMermaid(context, null, tokens("mermaid", "image.puml")); fail(); } catch (Exception e) { assertEquals("Mermaid source must be specified as a URL when running in restricted mode", e.getMessage()); diff --git a/structurizr-dsl/src/test/resources/dsl/image-views/workspace-via-file.dsl b/structurizr-dsl/src/test/resources/dsl/image-views/workspace-via-file.dsl index 93ec34d3..3cfeed7e 100644 --- a/structurizr-dsl/src/test/resources/dsl/image-views/workspace-via-file.dsl +++ b/structurizr-dsl/src/test/resources/dsl/image-views/workspace-via-file.dsl @@ -4,6 +4,7 @@ workspace { properties { "plantuml.url" "http://localhost:7777" "mermaid.url" "http://localhost:8888" + "mermaid.compress" "false" "kroki.url" "http://localhost:9999" } diff --git a/structurizr-dsl/src/test/resources/dsl/image-views/workspace-via-url.dsl b/structurizr-dsl/src/test/resources/dsl/image-views/workspace-via-url.dsl index 99fe3859..f42f657a 100644 --- a/structurizr-dsl/src/test/resources/dsl/image-views/workspace-via-url.dsl +++ b/structurizr-dsl/src/test/resources/dsl/image-views/workspace-via-url.dsl @@ -6,6 +6,7 @@ workspace { "plantuml.format" "svg" "mermaid.url" "http://localhost:8888" "mermaid.format" "svg" + "mermaid.compress" "false" "kroki.url" "http://localhost:9999" "kroki.format" "svg" } diff --git a/structurizr-export/src/main/java/com/structurizr/export/mermaid/MermaidEncoder.java b/structurizr-export/src/main/java/com/structurizr/export/mermaid/MermaidEncoder.java deleted file mode 100644 index 3f1e9fe9..00000000 --- a/structurizr-export/src/main/java/com/structurizr/export/mermaid/MermaidEncoder.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.structurizr.export.mermaid; - -import java.nio.charset.StandardCharsets; -import java.util.Base64; - -/** - * Encodes a Mermaid diagram definition to base64 format, for use with image URLs, etc. - */ -public class MermaidEncoder { - - private static final String TEMPLATE = "{ \"code\":\"%s\", \"mermaid\":{\"theme\":\"default\", \"securityLevel\": \"loose\"}}"; - - public String encode(String mermaidDefinition) { - String s = String.format(TEMPLATE, mermaidDefinition.replaceAll("\n", "\\\\n").replaceAll("\"", "\\\\\"")); - return Base64.getEncoder().encodeToString(s.getBytes(StandardCharsets.UTF_8)); - } - -} \ No newline at end of file diff --git a/structurizr-export/src/main/java/com/structurizr/export/plantuml/PlantUMLEncoder.java b/structurizr-export/src/main/java/com/structurizr/export/plantuml/PlantUMLEncoder.java deleted file mode 100644 index 1b5d24da..00000000 --- a/structurizr-export/src/main/java/com/structurizr/export/plantuml/PlantUMLEncoder.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.structurizr.export.plantuml; - -import java.io.ByteArrayOutputStream; -import java.nio.charset.StandardCharsets; -import java.util.zip.Deflater; -import java.util.zip.DeflaterOutputStream; - -/** - * A Java implementation of http://plantuml.com/code-javascript-synchronous - * that uses Java's built-in Deflate algorithm. - */ -public class PlantUMLEncoder { - - public String encode(String plantUMLDefinition) throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION, true); - - DeflaterOutputStream dos = new DeflaterOutputStream(baos, deflater, true); - dos.write(plantUMLDefinition.getBytes(StandardCharsets.UTF_8)); - dos.finish(); - - return encode(baos.toByteArray()); - } - - private String encode(byte[] bytes) { - StringBuilder buf = new StringBuilder(); - for (int i = 0; i < bytes.length; i += 3) { - int b1 = (bytes[i]) & 0xFF; - int b2 = (i + 1 < bytes.length ? bytes[i + 1] : (byte)0) & 0xFF; - int b3 = (i + 2 < bytes.length ? bytes[i + 2] : (byte)0) & 0xFF; - - append3bytes(buf, b1, b2, b3); - } - - return buf.toString(); - } - - private char encode6bit(byte b) { - if (b < 10) { - return (char) ('0' + b); - } - b -= 10; - if (b < 26) { - return (char) ('A' + b); - } - b -= 26; - if (b < 26) { - return (char) ('a' + b); - } - b -= 26; - if (b == 0) { - return '-'; - } - if (b == 1) { - return '_'; - } - - return '?'; - } - - private void append3bytes(StringBuilder buf, int b1, int b2, int b3) { - int c1 = b1 >> 2; - int c2 = (b1 & 0x3) << 4 | b2 >> 4; - int c3 = (b2 & 0xF) << 2 | b3 >> 6; - int c4 = b3 & 0x3F; - - buf.append(encode6bit((byte)(c1 & 0x3F))); - buf.append(encode6bit((byte)(c2 & 0x3F))); - buf.append(encode6bit((byte)(c3 & 0x3F))); - buf.append(encode6bit((byte)(c4 & 0x3F))); - } - -} \ No newline at end of file diff --git a/structurizr-import/src/main/java/com/structurizr/importer/diagrams/mermaid/MermaidEncoder.java b/structurizr-import/src/main/java/com/structurizr/importer/diagrams/mermaid/MermaidEncoder.java index 8bbc4bc9..553d33d7 100644 --- a/structurizr-import/src/main/java/com/structurizr/importer/diagrams/mermaid/MermaidEncoder.java +++ b/structurizr-import/src/main/java/com/structurizr/importer/diagrams/mermaid/MermaidEncoder.java @@ -1,15 +1,45 @@ package com.structurizr.importer.diagrams.mermaid; +import java.io.ByteArrayOutputStream; import java.nio.charset.StandardCharsets; import java.util.Base64; +import java.util.zip.Deflater; +import java.util.zip.DeflaterOutputStream; /** * Encodes a Mermaid diagram definition to base64 format, for use with image URLs, etc. */ -public class MermaidEncoder { +public final class MermaidEncoder { + + private static final String TEMPLATE = "{ \"code\":\"%s\", \"mermaid\":{\"theme\":\"default\"}}"; public String encode(String mermaidDefinition) { + return this.encode(mermaidDefinition, false); + } + + public String encode(String mermaidDefinition, boolean compress) { + if (compress) { + try { + String content = String.format(TEMPLATE, mermaidDefinition.replaceAll("\n", "\\\\n").replaceAll("\"", "\\\\\"")); + byte[] compressedDefinition = compress(content); + return "pako:" + Base64.getUrlEncoder().encodeToString(compressedDefinition); + } catch(Exception e) { + e.printStackTrace(); + } + } + return Base64.getUrlEncoder().encodeToString(mermaidDefinition.getBytes(StandardCharsets.UTF_8)); } + private byte[] compress(String content) throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Deflater deflater = new Deflater(); + + DeflaterOutputStream dos = new DeflaterOutputStream(baos, deflater, true); + dos.write(content.getBytes(StandardCharsets.UTF_8)); + dos.finish(); + + return baos.toByteArray(); + } + } \ No newline at end of file diff --git a/structurizr-import/src/main/java/com/structurizr/importer/diagrams/mermaid/MermaidImporter.java b/structurizr-import/src/main/java/com/structurizr/importer/diagrams/mermaid/MermaidImporter.java index 9168fff7..c7fa23b4 100644 --- a/structurizr-import/src/main/java/com/structurizr/importer/diagrams/mermaid/MermaidImporter.java +++ b/structurizr-import/src/main/java/com/structurizr/importer/diagrams/mermaid/MermaidImporter.java @@ -10,8 +10,9 @@ public class MermaidImporter extends AbstractDiagramImporter { - private static final String MERMAID_URL_PROPERTY = "mermaid.url"; - private static final String MERMAID_FORMAT_PROPERTY = "mermaid.format"; + public static final String MERMAID_URL_PROPERTY = "mermaid.url"; + public static final String MERMAID_FORMAT_PROPERTY = "mermaid.format"; + public static final String MERMAID_COMPRESS_PROPERTY = "mermaid.compress"; public void importDiagram(ImageView view, File file) throws Exception { String content = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8); @@ -28,14 +29,19 @@ public void importDiagram(ImageView view, String content) { String format = getViewOrViewSetProperty(view, MERMAID_FORMAT_PROPERTY); if (StringUtils.isNullOrEmpty(format)) { - format = PNG_FORMAT; + format = SVG_FORMAT; } if (!format.equals(PNG_FORMAT) && !format.equals(SVG_FORMAT)) { throw new IllegalArgumentException(String.format("Expected a format of %s or %s", PNG_FORMAT, SVG_FORMAT)); } - String encodedMermaid = new MermaidEncoder().encode(content); + String compress = getViewOrViewSetProperty(view, MERMAID_COMPRESS_PROPERTY); + if (StringUtils.isNullOrEmpty(compress)) { + compress = "true"; + } + + String encodedMermaid = new MermaidEncoder().encode(content, compress.equalsIgnoreCase("true")); String url; if (format.equals(PNG_FORMAT)) { url = String.format("%s/img/%s?type=png", mermaidServer, encodedMermaid); diff --git a/structurizr-import/src/main/java/com/structurizr/importer/diagrams/plantuml/PlantUMLEncoder.java b/structurizr-import/src/main/java/com/structurizr/importer/diagrams/plantuml/PlantUMLEncoder.java index 20238926..96088b15 100644 --- a/structurizr-import/src/main/java/com/structurizr/importer/diagrams/plantuml/PlantUMLEncoder.java +++ b/structurizr-import/src/main/java/com/structurizr/importer/diagrams/plantuml/PlantUMLEncoder.java @@ -9,9 +9,9 @@ * A Java implementation of http://plantuml.com/code-javascript-synchronous * that uses Java's built-in Deflate algorithm. */ -class PlantUMLEncoder { +public final class PlantUMLEncoder { - String encode(String plantUMLDefinition) throws Exception { + public String encode(String plantUMLDefinition) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION, true); diff --git a/structurizr-import/src/main/java/com/structurizr/importer/diagrams/plantuml/PlantUMLImporter.java b/structurizr-import/src/main/java/com/structurizr/importer/diagrams/plantuml/PlantUMLImporter.java index 56ed5a83..3ed7651e 100644 --- a/structurizr-import/src/main/java/com/structurizr/importer/diagrams/plantuml/PlantUMLImporter.java +++ b/structurizr-import/src/main/java/com/structurizr/importer/diagrams/plantuml/PlantUMLImporter.java @@ -10,8 +10,8 @@ public class PlantUMLImporter extends AbstractDiagramImporter { - private static final String PLANTUML_URL_PROPERTY = "plantuml.url"; - private static final String PLANTUML_FORMAT_PROPERTY = "plantuml.format"; + public static final String PLANTUML_URL_PROPERTY = "plantuml.url"; + public static final String PLANTUML_FORMAT_PROPERTY = "plantuml.format"; private static final String TITLE_STRING = "title "; private static final String NEWLINE = "\n"; @@ -30,7 +30,7 @@ public void importDiagram(ImageView view, String content) throws Exception { String format = getViewOrViewSetProperty(view, PLANTUML_FORMAT_PROPERTY); if (StringUtils.isNullOrEmpty(format)) { - format = PNG_FORMAT; + format = SVG_FORMAT; } if (!format.equals(PNG_FORMAT) && !format.equals(SVG_FORMAT)) { diff --git a/structurizr-import/src/test/java/com/structurizr/importer/diagrams/mermaid/MermaidEncoderTests.java b/structurizr-import/src/test/java/com/structurizr/importer/diagrams/mermaid/MermaidEncoderTests.java index b249e45f..b4b69190 100644 --- a/structurizr-import/src/test/java/com/structurizr/importer/diagrams/mermaid/MermaidEncoderTests.java +++ b/structurizr-import/src/test/java/com/structurizr/importer/diagrams/mermaid/MermaidEncoderTests.java @@ -3,7 +3,6 @@ import org.junit.jupiter.api.Test; import java.io.File; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -14,7 +13,16 @@ public class MermaidEncoderTests { public void encode_flowchart() throws Exception { File file = new File("./src/test/resources/diagrams/mermaid/flowchart.mmd"); String mermaid = Files.readString(file.toPath()); - assertEquals("Zmxvd2NoYXJ0IFRECiAgICBBW0NocmlzdG1hc10gLS0-fEdldCBtb25leXwgQihHbyBzaG9wcGluZykKICAgIEIgLS0-IEN7TGV0IG1lIHRoaW5rfQogICAgQyAtLT58T25lfCBEW0xhcHRvcF0KICAgIEMgLS0-fFR3b3wgRVtpUGhvbmVdCiAgICBDIC0tPnxUaHJlZXwgRltmYTpmYS1jYXIgQ2FyXQ==", new MermaidEncoder().encode(mermaid)); + String encodedMermaid = new MermaidEncoder().encode(mermaid); + assertEquals("Zmxvd2NoYXJ0IFRECiAgICBBW0NocmlzdG1hc10gLS0-fEdldCBtb25leXwgQihHbyBzaG9wcGluZykKICAgIEIgLS0-IEN7TGV0IG1lIHRoaW5rfQogICAgQyAtLT58T25lfCBEW0xhcHRvcF0KICAgIEMgLS0-fFR3b3wgRVtpUGhvbmVdCiAgICBDIC0tPnxUaHJlZXwgRltmYTpmYS1jYXIgQ2FyXQ==", encodedMermaid); + } + + @Test + public void encode_flowchart_compressed() throws Exception { + File file = new File("./src/test/resources/diagrams/mermaid/flowchart.mmd"); + String mermaid = Files.readString(file.toPath()); + String encodedMermaid = new MermaidEncoder().encode(mermaid, true); + assertEquals("pako:eJxVj70OgjAUhV_lppMm8gIMJlKUhUQHtspwAxfbSH9SaoihvLsgi571-85JzgSssS2xlHW9HRuJPkCV3w0sOQkuvRqCxqGGJDnGggJoa-gdIdsVFgZpnVPmsd_8bJWAT-WqEQSpzHPeEP_2r4Yi5KJEF6yrf0k12ghnoW5ymf8n0tPSuogO0w6TBj1w9DU7ANPkNaqWpRMLkvR6oqUOX31g8_wBLY9E1w==", encodedMermaid); } @Test @@ -22,7 +30,6 @@ public void encode_class() throws Exception { File file = new File("./src/test/resources/diagrams/mermaid/class.mmd"); String mermaid = Files.readString(file.toPath()); assertEquals("Y2xhc3NEaWFncmFtCiAgICBBbmltYWwgPHwtLSBEdWNrCiAgICBBbmltYWwgPHwtLSBGaXNoCiAgICBBbmltYWwgPHwtLSBaZWJyYQogICAgQW5pbWFsIDogK2ludCBhZ2UKICAgIEFuaW1hbCA6ICtTdHJpbmcgZ2VuZGVyCiAgICBBbmltYWw6ICtpc01hbW1hbCgpCiAgICBBbmltYWw6ICttYXRlKCkKICAgIGNsYXNzIER1Y2t7CiAgICAgICtTdHJpbmcgYmVha0NvbG9yCiAgICAgICtzd2ltKCkKICAgICAgK3F1YWNrKCkKICAgIH0KICAgIGNsYXNzIEZpc2h7CiAgICAgIC1pbnQgc2l6ZUluRmVldAogICAgICAtY2FuRWF0KCkKICAgIH0KICAgIGNsYXNzIFplYnJhewogICAgICArYm9vbCBpc193aWxkCiAgICAgICtydW4oKQogICAgfQo=", new MermaidEncoder().encode(mermaid)); - } } \ No newline at end of file diff --git a/structurizr-import/src/test/java/com/structurizr/importer/diagrams/mermaid/MermaidImporterTests.java b/structurizr-import/src/test/java/com/structurizr/importer/diagrams/mermaid/MermaidImporterTests.java index 3cccf9ac..5293f6c8 100644 --- a/structurizr-import/src/test/java/com/structurizr/importer/diagrams/mermaid/MermaidImporterTests.java +++ b/structurizr-import/src/test/java/com/structurizr/importer/diagrams/mermaid/MermaidImporterTests.java @@ -13,7 +13,8 @@ public class MermaidImporterTests { @Test public void importDiagram() throws Exception { Workspace workspace = new Workspace("Name", "Description"); - workspace.getViews().getConfiguration().addProperty("mermaid.url", "https://mermaid.ink"); + workspace.getViews().getConfiguration().addProperty(MermaidImporter.MERMAID_URL_PROPERTY, "https://mermaid.ink"); + workspace.getViews().getConfiguration().addProperty(MermaidImporter.MERMAID_COMPRESS_PROPERTY, "false"); ImageView view = workspace.getViews().createImageView("key"); new MermaidImporter().importDiagram(view, new File("./src/test/resources/diagrams/mermaid/flowchart.mmd")); @@ -21,15 +22,16 @@ public void importDiagram() throws Exception { assertNull(view.getElement()); assertNull(view.getElementId()); assertEquals("flowchart.mmd", view.getTitle()); - assertEquals("https://mermaid.ink/img/Zmxvd2NoYXJ0IFRECiAgICBBW0NocmlzdG1hc10gLS0-fEdldCBtb25leXwgQihHbyBzaG9wcGluZykKICAgIEIgLS0-IEN7TGV0IG1lIHRoaW5rfQogICAgQyAtLT58T25lfCBEW0xhcHRvcF0KICAgIEMgLS0-fFR3b3wgRVtpUGhvbmVdCiAgICBDIC0tPnxUaHJlZXwgRltmYTpmYS1jYXIgQ2FyXQ==?type=png", view.getContent()); - assertEquals("image/png", view.getContentType()); + assertEquals("https://mermaid.ink/svg/Zmxvd2NoYXJ0IFRECiAgICBBW0NocmlzdG1hc10gLS0-fEdldCBtb25leXwgQihHbyBzaG9wcGluZykKICAgIEIgLS0-IEN7TGV0IG1lIHRoaW5rfQogICAgQyAtLT58T25lfCBEW0xhcHRvcF0KICAgIEMgLS0-fFR3b3wgRVtpUGhvbmVdCiAgICBDIC0tPnxUaHJlZXwgRltmYTpmYS1jYXIgQ2FyXQ==", view.getContent()); + assertEquals("image/svg+xml", view.getContentType()); } @Test public void importDiagram_AsPNG() throws Exception { Workspace workspace = new Workspace("Name", "Description"); - workspace.getViews().getConfiguration().addProperty("mermaid.url", "https://mermaid.ink"); - workspace.getViews().getConfiguration().addProperty("mermaid.format", "png"); + workspace.getViews().getConfiguration().addProperty(MermaidImporter.MERMAID_URL_PROPERTY, "https://mermaid.ink"); + workspace.getViews().getConfiguration().addProperty(MermaidImporter.MERMAID_FORMAT_PROPERTY, "png"); + workspace.getViews().getConfiguration().addProperty(MermaidImporter.MERMAID_COMPRESS_PROPERTY, "false"); ImageView view = workspace.getViews().createImageView("key"); new MermaidImporter().importDiagram(view, new File("./src/test/resources/diagrams/mermaid/flowchart.mmd")); @@ -44,8 +46,9 @@ public void importDiagram_AsPNG() throws Exception { @Test public void importDiagram_AsSVG() throws Exception { Workspace workspace = new Workspace("Name", "Description"); - workspace.getViews().getConfiguration().addProperty("mermaid.url", "https://mermaid.ink"); - workspace.getViews().getConfiguration().addProperty("mermaid.format", "svg"); + workspace.getViews().getConfiguration().addProperty(MermaidImporter.MERMAID_URL_PROPERTY, "https://mermaid.ink"); + workspace.getViews().getConfiguration().addProperty(MermaidImporter.MERMAID_FORMAT_PROPERTY, "svg"); + workspace.getViews().getConfiguration().addProperty(MermaidImporter.MERMAID_COMPRESS_PROPERTY, "false"); ImageView view = workspace.getViews().createImageView("key"); new MermaidImporter().importDiagram(view, new File("./src/test/resources/diagrams/mermaid/flowchart.mmd")); @@ -73,8 +76,8 @@ public void importDiagram_WhenTheMermaidUrlIsNotDefined() throws Exception { @Test public void importDiagram_WhenAnInvalidFormatIsSpecified() throws Exception { Workspace workspace = new Workspace("Name", "Description"); - workspace.getViews().getConfiguration().addProperty("mermaid.url", "https://mermaid.ink"); - workspace.getViews().getConfiguration().addProperty("mermaid.format", "jpg"); + workspace.getViews().getConfiguration().addProperty(MermaidImporter.MERMAID_URL_PROPERTY, "https://mermaid.ink"); + workspace.getViews().getConfiguration().addProperty(MermaidImporter.MERMAID_FORMAT_PROPERTY, "jpg"); ImageView view = workspace.getViews().createImageView("key"); try { diff --git a/structurizr-import/src/test/java/com/structurizr/importer/diagrams/plantuml/PlantUMLImporterTests.java b/structurizr-import/src/test/java/com/structurizr/importer/diagrams/plantuml/PlantUMLImporterTests.java index 7e51dcd5..ea21bf2a 100644 --- a/structurizr-import/src/test/java/com/structurizr/importer/diagrams/plantuml/PlantUMLImporterTests.java +++ b/structurizr-import/src/test/java/com/structurizr/importer/diagrams/plantuml/PlantUMLImporterTests.java @@ -13,7 +13,7 @@ public class PlantUMLImporterTests { @Test public void importDiagram_WhenATitleIsDefined() throws Exception { Workspace workspace = new Workspace("Name", "Description"); - workspace.getViews().getConfiguration().addProperty("plantuml.url", "https://plantuml.com/plantuml"); + workspace.getViews().getConfiguration().addProperty(PlantUMLImporter.PLANTUML_URL_PROPERTY, "https://plantuml.com/plantuml"); ImageView view = workspace.getViews().createImageView("key"); new PlantUMLImporter().importDiagram(view, new File("./src/test/resources/diagrams/plantuml/with-title.puml")); @@ -21,14 +21,14 @@ public void importDiagram_WhenATitleIsDefined() throws Exception { assertNull(view.getElement()); assertNull(view.getElementId()); assertEquals("Sequence diagram example", view.getTitle()); - assertEquals("https://plantuml.com/plantuml/png/SoWkIImgAStDuIh9BCb9LGXEBInDpKjELKZ9J4mlIinLIAr8p2t8IULooazIqBLJSCp914fQAMIavkJaSpcavgK0zG80", view.getContent()); - assertEquals("image/png", view.getContentType()); + assertEquals("https://plantuml.com/plantuml/svg/SoWkIImgAStDuIh9BCb9LGXEBInDpKjELKZ9J4mlIinLIAr8p2t8IULooazIqBLJSCp914fQAMIavkJaSpcavgK0zG80", view.getContent()); + assertEquals("image/svg+xml", view.getContentType()); } @Test public void importDiagram_WhenATitleIsNotDefined() throws Exception { Workspace workspace = new Workspace("Name", "Description"); - workspace.getViews().getConfiguration().addProperty("plantuml.url", "https://plantuml.com/plantuml"); + workspace.getViews().getConfiguration().addProperty(PlantUMLImporter.PLANTUML_URL_PROPERTY, "https://plantuml.com/plantuml"); ImageView view = workspace.getViews().createImageView("key"); new PlantUMLImporter().importDiagram(view, new File("./src/test/resources/diagrams/plantuml/without-title.puml")); @@ -36,15 +36,15 @@ public void importDiagram_WhenATitleIsNotDefined() throws Exception { assertNull(view.getElement()); assertNull(view.getElementId()); assertEquals("without-title.puml", view.getTitle()); - assertEquals("https://plantuml.com/plantuml/png/SoWkIImgAStDuNBAJrBGjLDmpCbCJbMmKiX8pSd9vt98pKi1IW80", view.getContent()); - assertEquals("image/png", view.getContentType()); + assertEquals("https://plantuml.com/plantuml/svg/SoWkIImgAStDuNBAJrBGjLDmpCbCJbMmKiX8pSd9vt98pKi1IW80", view.getContent()); + assertEquals("image/svg+xml", view.getContentType()); } @Test public void importDiagram_AsPNG() throws Exception { Workspace workspace = new Workspace("Name", "Description"); - workspace.getViews().getConfiguration().addProperty("plantuml.url", "https://plantuml.com/plantuml"); - workspace.getViews().getConfiguration().addProperty("plantuml.format", "png"); + workspace.getViews().getConfiguration().addProperty(PlantUMLImporter.PLANTUML_URL_PROPERTY, "https://plantuml.com/plantuml"); + workspace.getViews().getConfiguration().addProperty(PlantUMLImporter.PLANTUML_FORMAT_PROPERTY, "png"); ImageView view = workspace.getViews().createImageView("key"); new PlantUMLImporter().importDiagram(view, new File("./src/test/resources/diagrams/plantuml/with-title.puml")); @@ -55,8 +55,8 @@ public void importDiagram_AsPNG() throws Exception { @Test public void importDiagram_AsSVG() throws Exception { Workspace workspace = new Workspace("Name", "Description"); - workspace.getViews().getConfiguration().addProperty("plantuml.url", "https://plantuml.com/plantuml"); - workspace.getViews().getConfiguration().addProperty("plantuml.format", "svg"); + workspace.getViews().getConfiguration().addProperty(PlantUMLImporter.PLANTUML_URL_PROPERTY, "https://plantuml.com/plantuml"); + workspace.getViews().getConfiguration().addProperty(PlantUMLImporter.PLANTUML_FORMAT_PROPERTY, "svg"); ImageView view = workspace.getViews().createImageView("key"); new PlantUMLImporter().importDiagram(view, new File("./src/test/resources/diagrams/plantuml/with-title.puml")); @@ -80,8 +80,8 @@ public void importDiagram_WhenThePlantUMLURLIsNotSpecified() throws Exception { @Test public void importDiagram_WhenAnInvalidFormatIsSpecified() throws Exception { Workspace workspace = new Workspace("Name", "Description"); - workspace.getViews().getConfiguration().addProperty("plantuml.url", "https://plantuml.com/plantuml"); - workspace.getViews().getConfiguration().addProperty("plantuml.format", "jpg"); + workspace.getViews().getConfiguration().addProperty(PlantUMLImporter.PLANTUML_URL_PROPERTY, "https://plantuml.com/plantuml"); + workspace.getViews().getConfiguration().addProperty(PlantUMLImporter.PLANTUML_FORMAT_PROPERTY, "jpg"); ImageView view = workspace.getViews().createImageView("key"); try {