From 25c464dda36e42862d93b7420e3854589346fb49 Mon Sep 17 00:00:00 2001 From: chris kn Date: Sun, 27 Oct 2024 12:01:01 +0100 Subject: [PATCH] dependency styles --- .../api/icons/IconRegistry.kt | 8 +- .../api/view/style/C4PUmlShape.kt | 7 + .../api/view/style/C4Shape.kt | 7 - .../api/view/style/ViewSetStyleExtension.kt | 16 +- .../api/view/style/ViewStyleExtension.kt | 12 ++ .../sprite/{PumlSprite.kt => PUmlSprite.kt} | 3 +- .../api/view/style/sprite/Sprite.kt | 2 +- .../api/view/style/styles/BoundaryStyle.kt | 21 ++- .../api/view/style/styles/C4PUmlLineStyle.kt | 8 + .../api/view/style/styles/DependencyStyle.kt | 44 +++++ .../api/view/style/styles/ElementStyle.kt | 21 ++- .../{C4PumlStyle.kt => ModelElementStyle.kt} | 11 +- .../api/view/style/styles/PersonStyle.kt | 21 ++- .../view/style/ElementStyleJsonExtension.kt | 5 + .../internal/export/writer/HeaderWriter.kt | 50 +++--- .../internal/export/writer/StyleWriter.kt | 101 ++++++----- .../writer/relationship/RelationshipWriter.kt | 23 ++- .../ViewSetConfigurationPropertyExtions.kt | 7 + .../view/sprite/SpriteTest.kt | 26 +-- .../view/style/StyleIntegrationTest.kt | 108 ++++++++--- .../boundary/BoundaryStyleExtensionTest.kt | 37 ++-- .../style/boundary/BoundaryStyleJsonTest.kt | 12 +- .../DependencyStyleExtensionTest.kt | 169 ++++++++++++++++++ .../dependency/DependencyStyleJsonTest.kt | 51 ++++++ .../element/ElementStyleExtensionTest.kt | 36 ++-- .../style/element/ElementStyleJsonTest.kt | 14 +- .../style/person/PersonStyleExtensionTest.kt | 34 ++-- .../view/style/person/PersonStyleJsonTest.kt | 16 +- .../view/style/ComponentStyleTest.puml | 9 +- .../view/style/ContainerStyleTest.puml | 7 +- .../view/style/DeploymentStyleTest.puml | 4 +- .../view/style/DynamicStyleSequenceTest.puml | 7 +- .../expected/view/style/DynamicStyleTest.puml | 7 +- .../expected/view/style/SystemStyleTest.puml | 7 +- .../view/style/ViewStyleTestWithStyle.puml | 7 +- 35 files changed, 661 insertions(+), 257 deletions(-) create mode 100644 src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/C4PUmlShape.kt delete mode 100644 src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/C4Shape.kt rename src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/sprite/{PumlSprite.kt => PUmlSprite.kt} (90%) create mode 100644 src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/C4PUmlLineStyle.kt create mode 100644 src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/DependencyStyle.kt rename src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/{C4PumlStyle.kt => ModelElementStyle.kt} (76%) create mode 100644 src/test/kotlin/com/github/chriskn/structurizrextension/view/style/dependency/DependencyStyleExtensionTest.kt create mode 100644 src/test/kotlin/com/github/chriskn/structurizrextension/view/style/dependency/DependencyStyleJsonTest.kt diff --git a/src/main/kotlin/com/github/chriskn/structurizrextension/api/icons/IconRegistry.kt b/src/main/kotlin/com/github/chriskn/structurizrextension/api/icons/IconRegistry.kt index 00868ed..453a439 100644 --- a/src/main/kotlin/com/github/chriskn/structurizrextension/api/icons/IconRegistry.kt +++ b/src/main/kotlin/com/github/chriskn/structurizrextension/api/icons/IconRegistry.kt @@ -7,8 +7,7 @@ import java.net.URL internal const val AWS_ICON_URL = "https://raw.githubusercontent.com/awslabs/aws-icons-for-plantuml/v11.1/dist/" internal const val AWS_ICON_COMMONS = "${AWS_ICON_URL}AWSCommon.puml" -// TODO sprites and image parsings - +// TODO deprecate /** * Registry containing the available icons. * @@ -26,12 +25,13 @@ object IconRegistry { /** * Adds a new icon with the given name (case-insensitive) and URL to the registry. * - * @throws IllegalArgumentException if url does not point to puml file + * @throws IllegalArgumentException if url does not point to puml file or name is blank * @throws MalformedURLException if url is invalid */ fun addIcon(name: String, url: String) { + require(name.isNotBlank()) { "Icon name cannot be blank" } require(url.endsWith(PUML_FILE_EXTENSION)) { - "Icon URL needs to point to .puml file" + "Icon URL needs to point to .puml file but was $url" } iconNameToIconUrl[name.lowercase()] = URI(url).toURL() } diff --git a/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/C4PUmlShape.kt b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/C4PUmlShape.kt new file mode 100644 index 0000000..ac00ec4 --- /dev/null +++ b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/C4PUmlShape.kt @@ -0,0 +1,7 @@ +package com.github.chriskn.structurizrextension.api.view.style + +// TODO doucment + +enum class C4PUmlShape(val pUmlString: String) { + ROUNDED_BOX("RoundedBoxShape()"), EIGHT_SIDED("EightSidedShape()") +} diff --git a/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/C4Shape.kt b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/C4Shape.kt deleted file mode 100644 index 7a4d6f9..0000000 --- a/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/C4Shape.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.chriskn.structurizrextension.api.view.style - -// TODO doucment - -enum class C4Shape { - ROUNDED_BOX, EIGHT_SIDED -} diff --git a/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/ViewSetStyleExtension.kt b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/ViewSetStyleExtension.kt index 0a1ef80..c8c6dd6 100644 --- a/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/ViewSetStyleExtension.kt +++ b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/ViewSetStyleExtension.kt @@ -1,16 +1,17 @@ package com.github.chriskn.structurizrextension.api.view.style import com.github.chriskn.structurizrextension.api.view.style.styles.BoundaryStyle +import com.github.chriskn.structurizrextension.api.view.style.styles.DependencyStyle import com.github.chriskn.structurizrextension.api.view.style.styles.ElementStyle import com.github.chriskn.structurizrextension.api.view.style.styles.PersonStyle import com.github.chriskn.structurizrextension.internal.export.view.style.boundaryStyleFromJson +import com.github.chriskn.structurizrextension.internal.export.view.style.dependencyStyleFromJson import com.github.chriskn.structurizrextension.internal.export.view.style.elementStyleFromJson import com.github.chriskn.structurizrextension.internal.export.view.style.personStyleFromJson import com.github.chriskn.structurizrextension.internal.export.view.style.toJson import com.structurizr.view.ViewSet import com.structurizr.view.clearBoundaryStyles import com.structurizr.view.clearElementStyles -import com.structurizr.view.clearPersonStyles fun ViewSet.addElementStyle(elementStyle: ElementStyle) { this.configuration.addProperty("$ELEMENT_STYLE_PROPERTY_NAME_PREFIX:${elementStyle.tag}", elementStyle.toJson()) @@ -21,6 +22,7 @@ fun ViewSet.getElementStyles(): List = .filter { it.key.startsWith(ELEMENT_STYLE_PROPERTY_NAME_PREFIX) } .map { elementStyleFromJson(it.value) } +// TODO remove? internal fun ViewSet.clearElementStyles() { this.configuration.clearElementStyles() } @@ -47,6 +49,14 @@ fun ViewSet.getPersonStyles(): List = .filter { it.key.startsWith(PERSON_STYLE_PROPERTY_NAME_PREFIX) } .map { personStyleFromJson(it.value) } -internal fun ViewSet.clearPersonStyles() { - this.configuration.clearPersonStyles() +fun ViewSet.addDependencyStyle(dependencyStyle: DependencyStyle) { + this.configuration.addProperty( + "$DEPENDENCY_STYLE_PROPERTY_NAME_PREFIX:${dependencyStyle.tag}", + dependencyStyle.toJson() + ) } + +fun ViewSet.getDependencyStyles(): List = + this.configuration.properties + .filter { it.key.startsWith(DEPENDENCY_STYLE_PROPERTY_NAME_PREFIX) } + .map { dependencyStyleFromJson(it.value) } diff --git a/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/ViewStyleExtension.kt b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/ViewStyleExtension.kt index 5ad4ab0..4e69e07 100644 --- a/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/ViewStyleExtension.kt +++ b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/ViewStyleExtension.kt @@ -1,9 +1,11 @@ package com.github.chriskn.structurizrextension.api.view.style import com.github.chriskn.structurizrextension.api.view.style.styles.BoundaryStyle +import com.github.chriskn.structurizrextension.api.view.style.styles.DependencyStyle import com.github.chriskn.structurizrextension.api.view.style.styles.ElementStyle import com.github.chriskn.structurizrextension.api.view.style.styles.PersonStyle import com.github.chriskn.structurizrextension.internal.export.view.style.boundaryStyleFromJson +import com.github.chriskn.structurizrextension.internal.export.view.style.dependencyStyleFromJson import com.github.chriskn.structurizrextension.internal.export.view.style.elementStyleFromJson import com.github.chriskn.structurizrextension.internal.export.view.style.personStyleFromJson import com.github.chriskn.structurizrextension.internal.export.view.style.toJson @@ -12,6 +14,7 @@ import com.structurizr.view.View internal const val ELEMENT_STYLE_PROPERTY_NAME_PREFIX = "c4:elementStyle" internal const val BOUNDARY_STYLE_PROPERTY_NAME_PREFIX = "c4:boundaryStyle" internal const val PERSON_STYLE_PROPERTY_NAME_PREFIX = "c4:personStyle" +internal const val DEPENDENCY_STYLE_PROPERTY_NAME_PREFIX = "c4:dependencyStyle" fun View.addElementStyle(elementStyle: ElementStyle) { this.addProperty("$ELEMENT_STYLE_PROPERTY_NAME_PREFIX:${elementStyle.tag}", elementStyle.toJson()) @@ -39,3 +42,12 @@ fun View.getPersonStyles(): List = this.properties .filter { it.key.startsWith(PERSON_STYLE_PROPERTY_NAME_PREFIX) } .map { personStyleFromJson(it.value) } + +fun View.addDependencyStyle(dependencyStyle: DependencyStyle) { + this.addProperty("$DEPENDENCY_STYLE_PROPERTY_NAME_PREFIX:${dependencyStyle.tag}", dependencyStyle.toJson()) +} + +fun View.getDependencyStyles(): List = + this.properties + .filter { it.key.startsWith(DEPENDENCY_STYLE_PROPERTY_NAME_PREFIX) } + .map { dependencyStyleFromJson(it.value) } diff --git a/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/sprite/PumlSprite.kt b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/sprite/PUmlSprite.kt similarity index 90% rename from src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/sprite/PumlSprite.kt rename to src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/sprite/PUmlSprite.kt index 121b703..593fef4 100644 --- a/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/sprite/PumlSprite.kt +++ b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/sprite/PUmlSprite.kt @@ -5,7 +5,7 @@ import com.github.chriskn.structurizrextension.api.icons.IconRegistry import com.github.chriskn.structurizrextension.api.view.style.toValidColor import java.net.MalformedURLException -data class PumlSprite( +data class PUmlSprite( val name: String, /** * Url used for include statement @@ -22,7 +22,6 @@ data class PumlSprite( internal val validatedColor: String? = color?.let { toValidColor(color) } init { - require(name.isNotBlank()) { "name cannot be blank" } // TODO is the registry still needed? IconRegistry.addIcon(name, includeUrl) } diff --git a/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/sprite/Sprite.kt b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/sprite/Sprite.kt index 46debff..740b43f 100644 --- a/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/sprite/Sprite.kt +++ b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/sprite/Sprite.kt @@ -13,7 +13,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo value = [ Type(value = ImageSprite::class, name = "ImageSprite"), Type(value = OpenIconicSprite::class, name = "OpenIconicSprite"), - Type(value = PumlSprite::class, name = "PumlSprite"), + Type(value = PUmlSprite::class, name = "PUmlSprite"), ] ) abstract class Sprite(scale: Double?) { diff --git a/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/BoundaryStyle.kt b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/BoundaryStyle.kt index 2ffd2b6..f2dc1e4 100644 --- a/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/BoundaryStyle.kt +++ b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/BoundaryStyle.kt @@ -1,9 +1,8 @@ package com.github.chriskn.structurizrextension.api.view.style.styles -import com.github.chriskn.structurizrextension.api.view.style.C4Shape +import com.github.chriskn.structurizrextension.api.view.style.C4PUmlShape import com.github.chriskn.structurizrextension.api.view.style.sprite.Sprite import com.github.chriskn.structurizrextension.api.view.style.toValidColor -import com.structurizr.view.Border // TODO doucment @@ -12,26 +11,26 @@ class BoundaryStyle internal constructor( override val tag: String, override val backgroundColor: String?, override val fontColor: String?, - override val border: Border?, - override val borderWith: Int?, + override val borderStyle: C4PUmlLineStyle?, + override val borderWidth: Int?, override val borderColor: String?, override val shadowing: Boolean, - override val c4Shape: C4Shape?, + override val c4Shape: C4PUmlShape?, override val sprite: Sprite?, override val legendText: String?, override val legendSprite: Sprite?, -) : C4PumlStyle +) : ModelElementStyle @Suppress("LongParameterList") fun createBoundaryStyle( tag: String, backgroundColor: String? = null, fontColor: String? = null, - border: Border? = null, - borderWith: Int? = null, + border: C4PUmlLineStyle? = null, + borderWidth: Int? = null, borderColor: String? = null, shadowing: Boolean = false, - c4Shape: C4Shape? = null, + c4Shape: C4PUmlShape? = null, sprite: Sprite? = null, legendText: String? = null, legendSprite: Sprite? = null, @@ -41,8 +40,8 @@ fun createBoundaryStyle( tag = tag, backgroundColor = toValidColor(backgroundColor), fontColor = toValidColor(fontColor), - border = border, - borderWith = borderWith, + borderStyle = border, + borderWidth = borderWidth, borderColor = toValidColor(borderColor), shadowing = shadowing, c4Shape = c4Shape, diff --git a/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/C4PUmlLineStyle.kt b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/C4PUmlLineStyle.kt new file mode 100644 index 0000000..302f4c9 --- /dev/null +++ b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/C4PUmlLineStyle.kt @@ -0,0 +1,8 @@ +package com.github.chriskn.structurizrextension.api.view.style.styles + +enum class C4PUmlLineStyle(val pUmlString: String) { + DASHED("DashedLine()"), + DOTTED("DottedLine()"), + BOLD("BoldLine()"), + SOLID("SolidLine()"), +} diff --git a/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/DependencyStyle.kt b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/DependencyStyle.kt new file mode 100644 index 0000000..bf144a1 --- /dev/null +++ b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/DependencyStyle.kt @@ -0,0 +1,44 @@ +package com.github.chriskn.structurizrextension.api.view.style.styles + +import com.github.chriskn.structurizrextension.api.view.style.sprite.Sprite +import com.github.chriskn.structurizrextension.api.view.style.toValidColor + +// TODO document + +data class DependencyStyle internal constructor( + val tag: String, + val fontColor: String?, + val sprite: Sprite?, + val legendText: String?, + val legendSprite: Sprite?, + val technology: String?, + val lineColor: String?, + val lineStyle: C4PUmlLineStyle?, + val lineWidth: Int?, +) + +@Suppress("LongParameterList") +fun createDependencyStyle( + tag: String, + fontColor: String? = null, + sprite: Sprite? = null, + legendText: String? = null, + legendSprite: Sprite? = null, + technology: String? = null, + lineColor: String? = null, + lineStyle: C4PUmlLineStyle? = null, + lineWidth: Int? = null, +): DependencyStyle { + require(tag.isNotBlank()) { "tag must not be blank" } + return DependencyStyle( + tag = tag, + fontColor = toValidColor(fontColor), + sprite = sprite, + legendText = legendText, + legendSprite = legendSprite, + technology = technology, + lineColor = toValidColor(lineColor), + lineStyle = lineStyle, + lineWidth = lineWidth, + ) +} diff --git a/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/ElementStyle.kt b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/ElementStyle.kt index f4a65db..091c641 100644 --- a/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/ElementStyle.kt +++ b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/ElementStyle.kt @@ -1,9 +1,8 @@ package com.github.chriskn.structurizrextension.api.view.style.styles -import com.github.chriskn.structurizrextension.api.view.style.C4Shape +import com.github.chriskn.structurizrextension.api.view.style.C4PUmlShape import com.github.chriskn.structurizrextension.api.view.style.sprite.Sprite import com.github.chriskn.structurizrextension.api.view.style.toValidColor -import com.structurizr.view.Border // TODO document @@ -11,27 +10,27 @@ data class ElementStyle internal constructor( override val tag: String, override val backgroundColor: String?, override val fontColor: String?, - override val border: Border?, - override val borderWith: Int?, + override val borderStyle: C4PUmlLineStyle?, + override val borderWidth: Int?, override val borderColor: String?, override val shadowing: Boolean, - override val c4Shape: C4Shape?, + override val c4Shape: C4PUmlShape?, override val sprite: Sprite?, override val legendText: String?, override val legendSprite: Sprite?, val technology: String?, -) : C4PumlStyle +) : ModelElementStyle @Suppress("LongParameterList") fun createElementStyle( tag: String, backgroundColor: String? = null, fontColor: String? = null, - border: Border? = null, - borderWith: Int? = null, + borderStyle: C4PUmlLineStyle? = null, + borderWidth: Int? = null, borderColor: String? = null, shadowing: Boolean = false, - c4Shape: C4Shape? = null, + c4Shape: C4PUmlShape? = null, sprite: Sprite? = null, legendText: String? = null, legendSprite: Sprite? = null, @@ -42,8 +41,8 @@ fun createElementStyle( tag = tag, backgroundColor = toValidColor(backgroundColor), fontColor = toValidColor(fontColor), - border = border, - borderWith = borderWith, + borderStyle = borderStyle, + borderWidth = borderWidth, borderColor = toValidColor(borderColor), shadowing = shadowing, c4Shape = c4Shape, diff --git a/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/C4PumlStyle.kt b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/ModelElementStyle.kt similarity index 76% rename from src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/C4PumlStyle.kt rename to src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/ModelElementStyle.kt index 3f366f1..59a20fd 100644 --- a/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/C4PumlStyle.kt +++ b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/ModelElementStyle.kt @@ -1,19 +1,18 @@ package com.github.chriskn.structurizrextension.api.view.style.styles -import com.github.chriskn.structurizrextension.api.view.style.C4Shape +import com.github.chriskn.structurizrextension.api.view.style.C4PUmlShape import com.github.chriskn.structurizrextension.api.view.style.sprite.Sprite -import com.structurizr.view.Border // TODO move to internal package -interface C4PumlStyle { +interface ModelElementStyle { val tag: String val backgroundColor: String? val fontColor: String? - val border: Border? - val borderWith: Int? + val borderStyle: C4PUmlLineStyle? + val borderWidth: Int? val borderColor: String? val shadowing: Boolean - val c4Shape: C4Shape? + val c4Shape: C4PUmlShape? val sprite: Sprite? val legendText: String? val legendSprite: Sprite? diff --git a/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/PersonStyle.kt b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/PersonStyle.kt index 763a60e..a10fc5b 100644 --- a/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/PersonStyle.kt +++ b/src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/styles/PersonStyle.kt @@ -1,9 +1,8 @@ package com.github.chriskn.structurizrextension.api.view.style.styles -import com.github.chriskn.structurizrextension.api.view.style.C4Shape +import com.github.chriskn.structurizrextension.api.view.style.C4PUmlShape import com.github.chriskn.structurizrextension.api.view.style.sprite.Sprite import com.github.chriskn.structurizrextension.api.view.style.toValidColor -import com.structurizr.view.Border // TODO document @@ -11,26 +10,26 @@ data class PersonStyle internal constructor( override val tag: String, override val backgroundColor: String?, override val fontColor: String?, - override val border: Border?, - override val borderWith: Int?, + override val borderStyle: C4PUmlLineStyle?, + override val borderWidth: Int?, override val borderColor: String?, override val shadowing: Boolean, - override val c4Shape: C4Shape?, + override val c4Shape: C4PUmlShape?, override val sprite: Sprite?, override val legendText: String?, override val legendSprite: Sprite?, -) : C4PumlStyle +) : ModelElementStyle @Suppress("LongParameterList") fun createPersonStyle( tag: String, backgroundColor: String? = null, fontColor: String? = null, - border: Border? = null, - borderWith: Int? = null, + borderStyle: C4PUmlLineStyle? = null, + borderWidth: Int? = null, borderColor: String? = null, shadowing: Boolean = false, - c4Shape: C4Shape? = null, + c4Shape: C4PUmlShape? = null, sprite: Sprite? = null, legendText: String? = null, legendSprite: Sprite? = null, @@ -40,8 +39,8 @@ fun createPersonStyle( tag = tag, backgroundColor = toValidColor(backgroundColor), fontColor = toValidColor(fontColor), - border = border, - borderWith = borderWith, + borderStyle = borderStyle, + borderWidth = borderWidth, borderColor = toValidColor(borderColor), shadowing = shadowing, c4Shape = c4Shape, diff --git a/src/main/kotlin/com/github/chriskn/structurizrextension/internal/export/view/style/ElementStyleJsonExtension.kt b/src/main/kotlin/com/github/chriskn/structurizrextension/internal/export/view/style/ElementStyleJsonExtension.kt index 9a5feca..16593b2 100644 --- a/src/main/kotlin/com/github/chriskn/structurizrextension/internal/export/view/style/ElementStyleJsonExtension.kt +++ b/src/main/kotlin/com/github/chriskn/structurizrextension/internal/export/view/style/ElementStyleJsonExtension.kt @@ -3,6 +3,7 @@ package com.github.chriskn.structurizrextension.internal.export.view.style import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import com.fasterxml.jackson.module.kotlin.readValue import com.github.chriskn.structurizrextension.api.view.style.styles.BoundaryStyle +import com.github.chriskn.structurizrextension.api.view.style.styles.DependencyStyle import com.github.chriskn.structurizrextension.api.view.style.styles.ElementStyle import com.github.chriskn.structurizrextension.api.view.style.styles.PersonStyle @@ -19,3 +20,7 @@ internal fun boundaryStyleFromJson(json: String): BoundaryStyle = mapper.readVal internal fun PersonStyle.toJson(): String = mapper.writeValueAsString(this) internal fun personStyleFromJson(json: String): PersonStyle = mapper.readValue(json) + +internal fun DependencyStyle.toJson(): String = mapper.writeValueAsString(this) + +internal fun dependencyStyleFromJson(json: String): DependencyStyle = mapper.readValue(json) diff --git a/src/main/kotlin/com/github/chriskn/structurizrextension/internal/export/writer/HeaderWriter.kt b/src/main/kotlin/com/github/chriskn/structurizrextension/internal/export/writer/HeaderWriter.kt index c49c719..aef53fd 100644 --- a/src/main/kotlin/com/github/chriskn/structurizrextension/internal/export/writer/HeaderWriter.kt +++ b/src/main/kotlin/com/github/chriskn/structurizrextension/internal/export/writer/HeaderWriter.kt @@ -6,9 +6,9 @@ import com.github.chriskn.structurizrextension.api.icons.IconRegistry import com.github.chriskn.structurizrextension.api.model.icon import com.github.chriskn.structurizrextension.api.view.dynamic.renderAsSequenceDiagram import com.github.chriskn.structurizrextension.api.view.layout.LayoutRegistry -import com.github.chriskn.structurizrextension.api.view.style.sprite.PumlSprite -import com.github.chriskn.structurizrextension.api.view.style.styles.BoundaryStyle -import com.github.chriskn.structurizrextension.api.view.style.styles.ElementStyle +import com.github.chriskn.structurizrextension.api.view.style.sprite.PUmlSprite +import com.github.chriskn.structurizrextension.api.view.style.styles.DependencyStyle +import com.github.chriskn.structurizrextension.api.view.style.styles.ModelElementStyle import com.structurizr.export.IndentingWriter import com.structurizr.model.DeploymentNode import com.structurizr.model.InteractionStyle @@ -38,11 +38,16 @@ internal class HeaderWriter(private val styleWriter: StyleWriter) { fun writeHeader(view: ModelView, writer: IndentingWriter) { includes.clear() addIconIncludeUrls(view) - val elementsStyles = styleWriter.collectAppliedElementStyles(view) - val boundaryStyles = styleWriter.collectAppliedBoundaryStyles(view) val personStyles = styleWriter.collectAppliedPersonStyles(view) + val boundaryStyles = styleWriter.collectAppliedBoundaryStyles(view) + val elementsStyles = styleWriter.collectAppliedElementStyles(view) + val dependencyStyles = styleWriter.collectAppliedDependencyStyles(view) + + addSpriteIncludeUrls( + modelElementStyles = elementsStyles + boundaryStyles + personStyles, + dependencyStyles = dependencyStyles + ) - addSpriteIncludeUrls(elementsStyles, boundaryStyles) // Spaces in PlantUML ids can cause issues. Alternatively, id can be surrounded with double quotes writer.writeLine("@startuml(id=${view.key.replace(' ', '_')})") includes.forEach { @@ -52,6 +57,7 @@ internal class HeaderWriter(private val styleWriter: StyleWriter) { if (viewTitle.isNullOrBlank()) { viewTitle = view.name } + writer.writeLine("title $viewTitle") if (!view.description.isNullOrBlank()) { writer.writeLine("caption " + view.description) @@ -69,6 +75,9 @@ internal class HeaderWriter(private val styleWriter: StyleWriter) { if (view.relationships.any { it.relationship.interactionStyle == InteractionStyle.Asynchronous }) { writeAsyncRelTag(writer) } + dependencyStyles.forEach { style -> + styleWriter.writeDependencyStyle(style, writer) + } elementsStyles.forEach { style -> styleWriter.writeElementStyle(style, writer) } @@ -81,27 +90,26 @@ internal class HeaderWriter(private val styleWriter: StyleWriter) { } private fun addSpriteIncludeUrls( - elementStyles: List, - boundaryStyles: List, + modelElementStyles: List, + dependencyStyles: List ) { - val spriteIncludeUrls = elementStyles + val elementIncludeUrls = modelElementStyles .asSequence() .map { listOf(it.sprite, it.legendSprite) } .flatten() - .filterIsInstance() + .filterIsInstance() .map { it.includeUrl } - .toMutableList() - spriteIncludeUrls.addAll( - boundaryStyles - .asSequence() - .map { listOf(it.sprite, it.legendSprite) } - .flatten() - .filterIsInstance() - .map { it.includeUrl } - .toMutableList() - ) + + val dependencyIncludeUrls = dependencyStyles + .asSequence() + .map { listOf(it.sprite, it.legendSprite) } + .flatten() + .filterIsInstance() + .map { it.includeUrl } + + val spriteIncludeUrls = (elementIncludeUrls + dependencyIncludeUrls).toSortedSet() if (spriteIncludeUrls.any { it.startsWith(AWS_ICON_URL) }) { - spriteIncludeUrls.add(0, AWS_ICON_COMMONS) + spriteIncludeUrls.addFirst(AWS_ICON_COMMONS) } includes.addAll(spriteIncludeUrls.map { URI.create(it) }) } diff --git a/src/main/kotlin/com/github/chriskn/structurizrextension/internal/export/writer/StyleWriter.kt b/src/main/kotlin/com/github/chriskn/structurizrextension/internal/export/writer/StyleWriter.kt index 4bc676e..74cd998 100644 --- a/src/main/kotlin/com/github/chriskn/structurizrextension/internal/export/writer/StyleWriter.kt +++ b/src/main/kotlin/com/github/chriskn/structurizrextension/internal/export/writer/StyleWriter.kt @@ -1,18 +1,17 @@ package com.github.chriskn.structurizrextension.internal.export.writer -import com.github.chriskn.structurizrextension.api.view.style.C4Shape -import com.github.chriskn.structurizrextension.api.view.style.C4Shape.EIGHT_SIDED -import com.github.chriskn.structurizrextension.api.view.style.C4Shape.ROUNDED_BOX import com.github.chriskn.structurizrextension.api.view.style.getBoundaryStyles +import com.github.chriskn.structurizrextension.api.view.style.getDependencyStyles import com.github.chriskn.structurizrextension.api.view.style.getElementStyles import com.github.chriskn.structurizrextension.api.view.style.getPersonStyles import com.github.chriskn.structurizrextension.api.view.style.sprite.ImageSprite import com.github.chriskn.structurizrextension.api.view.style.sprite.OpenIconicSprite -import com.github.chriskn.structurizrextension.api.view.style.sprite.PumlSprite +import com.github.chriskn.structurizrextension.api.view.style.sprite.PUmlSprite import com.github.chriskn.structurizrextension.api.view.style.sprite.Sprite import com.github.chriskn.structurizrextension.api.view.style.styles.BoundaryStyle -import com.github.chriskn.structurizrextension.api.view.style.styles.C4PumlStyle +import com.github.chriskn.structurizrextension.api.view.style.styles.DependencyStyle import com.github.chriskn.structurizrextension.api.view.style.styles.ElementStyle +import com.github.chriskn.structurizrextension.api.view.style.styles.ModelElementStyle import com.github.chriskn.structurizrextension.api.view.style.styles.PersonStyle import com.github.chriskn.structurizrextension.internal.export.view.getBoundaryContainer import com.github.chriskn.structurizrextension.internal.export.view.getBoundaryElements @@ -20,10 +19,6 @@ import com.github.chriskn.structurizrextension.internal.export.view.getBoundaryS import com.structurizr.export.IndentingWriter import com.structurizr.model.ModelItem import com.structurizr.model.Person -import com.structurizr.view.Border -import com.structurizr.view.Border.Dashed -import com.structurizr.view.Border.Dotted -import com.structurizr.view.Border.Solid import com.structurizr.view.ComponentView import com.structurizr.view.ContainerView import com.structurizr.view.DynamicView @@ -54,23 +49,29 @@ internal object StyleWriter { } fun collectAppliedPersonStyles(view: ModelView): List { - val person: MutableSet = view.elements.map { it.element }.filterIsInstance().toMutableSet() + val person = view.elements.map { it.element }.filterIsInstance().toSet() val usedTags = person.map { it.tagsAsSet }.flatten().toSet() val stylesForTags = view.viewSet.getPersonStyles().filter { usedTags.contains(it.tag) } + view.getPersonStyles().filter { usedTags.contains(it.tag) } return stylesForTags.distinctBy { it.tag }.sortedBy { it.tag } } + fun collectAppliedDependencyStyles(view: ModelView): List { + val usedTags = view.relationships.map { it.relationship.tagsAsSet }.flatten().toSet() + val stylesForTags = view.viewSet.getDependencyStyles().filter { usedTags.contains(it.tag) } + + view.getDependencyStyles().filter { usedTags.contains(it.tag) } + return stylesForTags.distinctBy { it.tag }.sortedBy { it.tag } + } + fun writeElementStyle(elementStyle: ElementStyle, writer: IndentingWriter) { val bgColor = elementStyle.backgroundColor val fontColor = elementStyle.fontColor val borderColor = elementStyle.borderColor - val borderStyle = borderStyleString(elementStyle.border) - val borderThickness = elementStyle.borderWith?.toString() + val borderStyle = elementStyle.borderStyle?.pUmlString + val borderThickness = elementStyle.borderWidth?.toString() val shadow = elementStyle.shadowing val technology = elementStyle.technology - val shapeValue = elementStyle.c4Shape - val shape = shapeString(shapeValue) + val shape = elementStyle.c4Shape?.pUmlString val sprite = elementStyle.sprite?.toPlantUmlString() val legendSprite = elementStyle.legendSprite?.toPlantUmlString() val legendText = elementStyle.legendText @@ -101,20 +102,19 @@ internal object StyleWriter { ) } - fun writeC4PumlStyle(c4PumlStyle: C4PumlStyle, writer: IndentingWriter, tagType: String) { - val bgColor = c4PumlStyle.backgroundColor - val fontColor = c4PumlStyle.fontColor - val borderColor = c4PumlStyle.borderColor - val borderStyle = borderStyleString(c4PumlStyle.border) - val borderThickness = c4PumlStyle.borderWith?.toString() - val shadow = c4PumlStyle.shadowing - val shapeValue = c4PumlStyle.c4Shape - val shape = shapeString(shapeValue) - val sprite = c4PumlStyle.sprite?.toPlantUmlString() - val legendSprite = c4PumlStyle.legendSprite?.toPlantUmlString() - val legendText = c4PumlStyle.legendText + fun writeC4PumlStyle(modelElementStyle: ModelElementStyle, writer: IndentingWriter, tagType: String) { + val bgColor = modelElementStyle.backgroundColor + val fontColor = modelElementStyle.fontColor + val borderColor = modelElementStyle.borderColor + val borderStyle = modelElementStyle.borderStyle?.pUmlString + val borderThickness = modelElementStyle.borderWidth?.toString() + val shadow = modelElementStyle.shadowing + val shape = modelElementStyle.c4Shape?.pUmlString + val sprite = modelElementStyle.sprite?.toPlantUmlString() + val legendSprite = modelElementStyle.legendSprite?.toPlantUmlString() + val legendText = modelElementStyle.legendText writer.writeLine( - """Add${tagType}Tag(${c4PumlStyle.tag}${ + """Add${tagType}Tag(${modelElementStyle.tag}${ addIfNotNull("sprite", sprite) }${ addIfNotNull("bgColor", bgColor) @@ -138,23 +138,34 @@ internal object StyleWriter { ) } - private fun borderStyleString(border: Border?): String? { - val borderStyle = when (border) { - Solid -> "SolidLine()" - Dashed -> "DashedLine()" - Dotted -> "DottedLine()" - else -> null - } - return borderStyle - } - - private fun shapeString(shapeValue: C4Shape?): String? { - val shape = when (shapeValue) { - EIGHT_SIDED -> "EightSidedShape()" - ROUNDED_BOX -> "RoundedBoxShape()" - else -> null - } - return shape + fun writeDependencyStyle(dependencyStyle: DependencyStyle, writer: IndentingWriter) { + val fontColor = dependencyStyle.fontColor + val sprite = dependencyStyle.sprite?.toPlantUmlString() + val legendSprite = dependencyStyle.legendSprite?.toPlantUmlString() + val legendText = dependencyStyle.legendText + val technology = dependencyStyle.technology + val lineColor = dependencyStyle.lineColor + val lineStyle = dependencyStyle.lineStyle?.pUmlString + val lineWidth = dependencyStyle.lineWidth + writer.writeLine( + """AddRelTag(${dependencyStyle.tag}${ + addIfNotNull("sprite", sprite) + }${ + addIfNotNull("lineColor", lineColor) + }${ + addIfNotNull("textColor", fontColor) + }${ + addIfNotNull("techn", technology) + }${ + addIfNotNull("lineStyle", lineStyle) + }${ + addIfNotNull("lineThickness", lineWidth) + }${ + addIfNotNull("legendSprite", legendSprite) + }${ + addIfNotNull("legendText", legendText) + })""" + ) } private fun addIfNotNull(name: String, value: Any?) = if (value != null) { @@ -164,7 +175,7 @@ internal object StyleWriter { } private fun Sprite.toPlantUmlString(): String = when (this) { - is PumlSprite -> """"${spriteString(this.name, scale, validatedColor)}"""" + is PUmlSprite -> """"${spriteString(this.name, scale, validatedColor)}"""" is OpenIconicSprite -> """"&${spriteString(this.name, scale, validatedColor)}"""" is ImageSprite -> { val scaleString = scaleString(this.scale) diff --git a/src/main/kotlin/com/github/chriskn/structurizrextension/internal/export/writer/relationship/RelationshipWriter.kt b/src/main/kotlin/com/github/chriskn/structurizrextension/internal/export/writer/relationship/RelationshipWriter.kt index 25b2388..20ffbb8 100644 --- a/src/main/kotlin/com/github/chriskn/structurizrextension/internal/export/writer/relationship/RelationshipWriter.kt +++ b/src/main/kotlin/com/github/chriskn/structurizrextension/internal/export/writer/relationship/RelationshipWriter.kt @@ -12,6 +12,7 @@ import com.github.chriskn.structurizrextension.internal.export.writer.PropertyWr import com.github.chriskn.structurizrextension.internal.export.writer.linkString import com.structurizr.export.IndentingWriter import com.structurizr.model.InteractionStyle +import com.structurizr.model.Relationship import com.structurizr.view.DynamicView import com.structurizr.view.ModelView import com.structurizr.view.RelationshipView @@ -92,9 +93,8 @@ internal class RelationshipWriter( if (!relationship.link.isNullOrBlank()) { relationshipBuilder.append(linkString(relationship.link)) } - if (relationship.interactionStyle == InteractionStyle.Asynchronous) { - relationshipBuilder.append(""", ${'$'}tags="$ASYNC_REL_TAG_NAME"""") - } + relationshipBuilder.append(relationship.tagsToPlantUmlSting()) + relationshipBuilder.append(")") propertyWriter.writeProperties(relationshipView.relationship, writer) @@ -128,9 +128,7 @@ internal class RelationshipWriter( relationshipBuilder.append(""", ${'$'}sprite="$sprite"""") } - if (relationship.interactionStyle == InteractionStyle.Asynchronous) { - relationshipBuilder.append(""", ${'$'}tags="$ASYNC_REL_TAG_NAME" """) - } + relationshipBuilder.append(relationship.tagsToPlantUmlSting()) if (!relationship.link.isNullOrBlank()) { relationshipBuilder.append(linkString(relationship.link)) @@ -184,4 +182,17 @@ internal class RelationshipWriter( else -> "Rel_${mode.macro}" } } + + private fun Relationship.tagsToPlantUmlSting(): String { + // dont add structurizr default tags + val tagList = (this.tagsAsSet - this.defaultTags).toMutableSet() + if (this.interactionStyle == InteractionStyle.Asynchronous) { + tagList.add(ASYNC_REL_TAG_NAME) + } + return if (tagList.isEmpty()) { + "" + } else { + """, ${'$'}tags="${tagList.joinToString("+")}"""" + } + } } diff --git a/src/main/kotlin/com/structurizr/view/ViewSetConfigurationPropertyExtions.kt b/src/main/kotlin/com/structurizr/view/ViewSetConfigurationPropertyExtions.kt index bc0c3cb..7832e7e 100644 --- a/src/main/kotlin/com/structurizr/view/ViewSetConfigurationPropertyExtions.kt +++ b/src/main/kotlin/com/structurizr/view/ViewSetConfigurationPropertyExtions.kt @@ -1,6 +1,7 @@ package com.structurizr.view import com.github.chriskn.structurizrextension.api.view.style.BOUNDARY_STYLE_PROPERTY_NAME_PREFIX +import com.github.chriskn.structurizrextension.api.view.style.DEPENDENCY_STYLE_PROPERTY_NAME_PREFIX import com.github.chriskn.structurizrextension.api.view.style.ELEMENT_STYLE_PROPERTY_NAME_PREFIX import com.github.chriskn.structurizrextension.api.view.style.PERSON_STYLE_PROPERTY_NAME_PREFIX @@ -21,3 +22,9 @@ fun Configuration.clearElementStyles() { .properties .filterKeys { !it.startsWith(ELEMENT_STYLE_PROPERTY_NAME_PREFIX) } } + +fun Configuration.clearDependencyStyles() { + this.properties = this + .properties + .filterKeys { !it.startsWith(DEPENDENCY_STYLE_PROPERTY_NAME_PREFIX) } +} diff --git a/src/test/kotlin/com/github/chriskn/structurizrextension/view/sprite/SpriteTest.kt b/src/test/kotlin/com/github/chriskn/structurizrextension/view/sprite/SpriteTest.kt index ea5ccf6..2b2d289 100644 --- a/src/test/kotlin/com/github/chriskn/structurizrextension/view/sprite/SpriteTest.kt +++ b/src/test/kotlin/com/github/chriskn/structurizrextension/view/sprite/SpriteTest.kt @@ -3,7 +3,7 @@ package com.github.chriskn.structurizrextension.view.sprite import com.github.chriskn.structurizrextension.api.icons.IconRegistry import com.github.chriskn.structurizrextension.api.view.style.sprite.ImageSprite import com.github.chriskn.structurizrextension.api.view.style.sprite.OpenIconicSprite -import com.github.chriskn.structurizrextension.api.view.style.sprite.PumlSprite +import com.github.chriskn.structurizrextension.api.view.style.sprite.PUmlSprite import com.github.chriskn.structurizrextension.api.view.style.styles.createElementStyle import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Nested @@ -17,7 +17,7 @@ class SpriteTest { @Test fun `PumlSprite is serialized and deserialized correctly`() { - val expectedSprite = PumlSprite( + val expectedSprite = PUmlSprite( name = "android", includeUrl = "https://test.com/sprites/android-icon.puml", ) @@ -28,7 +28,7 @@ class SpriteTest { @Test fun `PumlSprite is serialized and deserialized correctly when color is used`() { - val expectedSprite = PumlSprite( + val expectedSprite = PUmlSprite( name = "android", includeUrl = "https://test.com/sprites/android-icon.puml", color = "green" @@ -40,7 +40,7 @@ class SpriteTest { @Test fun `PumlSprite is serialized and deserialized correctly when scale is used`() { - val expectedSprite = PumlSprite( + val expectedSprite = PUmlSprite( name = "android", includeUrl = "https://test.com/sprites/android-icon.puml", scale = 0.4 @@ -52,7 +52,7 @@ class SpriteTest { @Test fun `PumlSprite is serialized and deserialized correctly when scale and color is used`() { - val expectedSprite = PumlSprite( + val expectedSprite = PUmlSprite( name = "android", includeUrl = "https://test.com/sprites/android-icon.puml", scale = 0.4, @@ -147,20 +147,20 @@ class SpriteTest { } @Nested - inner class PumlSpriteTest { + inner class PUmlSpriteTest { @Test fun `IllegalArgumentException is thrown when name is blank`() { val url = IconRegistry.iconUrlFor("kafka")!! assertThrows { - PumlSprite(name = "", includeUrl = url) + PUmlSprite(name = "", includeUrl = url) } } @Test fun `IllegalArgumentException is thrown when url is blank`() { assertThrows { - PumlSprite(name = " ", includeUrl = " ") + PUmlSprite(name = " ", includeUrl = " ") } } @@ -170,35 +170,35 @@ class SpriteTest { val url = IconRegistry.iconUrlFor("kafka")!! assertThrows { - PumlSprite(name = name, includeUrl = url, color = "123") + PUmlSprite(name = name, includeUrl = url, color = "123") } } @Test fun `IllegalArgumentException is thrown when url does not point to a puml file`() { assertThrows { - PumlSprite("test", "https://plantuml.com/logo.png") + PUmlSprite("test", "https://plantuml.com/logo.png") } } @Test fun `IllegalArgumentException is thrown when url is invalid`() { assertThrows { - PumlSprite("test", "plantuml.com/logo.png") + PUmlSprite("test", "plantuml.com/logo.png") } } @Test fun `IllegalArgumentException is thrown if scale is negative `() { assertThrows { - PumlSprite("test", "https://plantuml.com/logo.puml", scale = -0.1) + PUmlSprite("test", "https://plantuml.com/logo.puml", scale = -0.1) } } @Test fun `IllegalArgumentException is thrown if scale is zero `() { assertThrows { - PumlSprite("test", "https://plantuml.com/logo.puml", scale = 0.0) + PUmlSprite("test", "https://plantuml.com/logo.puml", scale = 0.0) } } } diff --git a/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/StyleIntegrationTest.kt b/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/StyleIntegrationTest.kt index 4c21277..01056b1 100644 --- a/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/StyleIntegrationTest.kt +++ b/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/StyleIntegrationTest.kt @@ -17,23 +17,26 @@ import com.github.chriskn.structurizrextension.api.view.dynamicView import com.github.chriskn.structurizrextension.api.view.showExternalBoundaries import com.github.chriskn.structurizrextension.api.view.showExternalContainerBoundaries import com.github.chriskn.structurizrextension.api.view.showExternalSoftwareSystemBoundaries -import com.github.chriskn.structurizrextension.api.view.style.C4Shape.EIGHT_SIDED -import com.github.chriskn.structurizrextension.api.view.style.C4Shape.ROUNDED_BOX +import com.github.chriskn.structurizrextension.api.view.style.C4PUmlShape.EIGHT_SIDED +import com.github.chriskn.structurizrextension.api.view.style.C4PUmlShape.ROUNDED_BOX import com.github.chriskn.structurizrextension.api.view.style.addBoundaryStyle +import com.github.chriskn.structurizrextension.api.view.style.addDependencyStyle import com.github.chriskn.structurizrextension.api.view.style.addElementStyle import com.github.chriskn.structurizrextension.api.view.style.addPersonStyle import com.github.chriskn.structurizrextension.api.view.style.clearElementStyles import com.github.chriskn.structurizrextension.api.view.style.sprite.ImageSprite import com.github.chriskn.structurizrextension.api.view.style.sprite.OpenIconicSprite -import com.github.chriskn.structurizrextension.api.view.style.sprite.PumlSprite +import com.github.chriskn.structurizrextension.api.view.style.sprite.PUmlSprite +import com.github.chriskn.structurizrextension.api.view.style.styles.C4PUmlLineStyle.BOLD +import com.github.chriskn.structurizrextension.api.view.style.styles.C4PUmlLineStyle.DASHED +import com.github.chriskn.structurizrextension.api.view.style.styles.C4PUmlLineStyle.DOTTED import com.github.chriskn.structurizrextension.api.view.style.styles.createBoundaryStyle +import com.github.chriskn.structurizrextension.api.view.style.styles.createDependencyStyle import com.github.chriskn.structurizrextension.api.view.style.styles.createElementStyle import com.github.chriskn.structurizrextension.api.view.style.styles.createPersonStyle import com.github.chriskn.structurizrextension.api.view.systemContextView import com.github.chriskn.structurizrextension.assertExpectedDiagramWasWrittenForView import com.structurizr.Workspace -import com.structurizr.view.Border.Dashed -import com.structurizr.view.Border.Dotted import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -50,6 +53,7 @@ class StyleIntegrationTest { private val containerTag = "Container Style" private val componentTag = "Component Style" private val personTag = "Person Style" + private val dependencyTag = "Dependency Style" private val system = model.softwareSystem("My Software System", "system", tags = listOf(systemTag, boundaryTag)) @@ -60,9 +64,9 @@ class StyleIntegrationTest { name = "Person", tags = listOf(personTag), uses = listOf( - Dependency(system, "uses system"), - Dependency(container, "uses container"), - Dependency(component, "uses component"), + Dependency(system, "uses system", tags = listOf(dependencyTag)), + Dependency(container, "uses container", tags = listOf(dependencyTag)), + Dependency(component, "uses component", tags = listOf(dependencyTag)), ) ) @@ -71,8 +75,8 @@ class StyleIntegrationTest { private val systemStyle = createElementStyle( tag = systemTag, backgroundColor = "#000000", - border = Dashed, - borderWith = 4, + borderStyle = DASHED, + borderWidth = 4, borderColor = "green", fontColor = "yellow", shadowing = true, @@ -84,26 +88,32 @@ class StyleIntegrationTest { ) private val personStyle = createPersonStyle( tag = personTag, + sprite = PUmlSprite( + includeUrl = IconRegistry.iconUrlFor("apple")!!, + name = IconRegistry.iconFileNameFor("apple")!!, + scale = 0.5, + color = "green" + ), backgroundColor = "#00FF00", - border = Dashed, - borderWith = 4, + borderStyle = DASHED, + borderWidth = 4, borderColor = "red", fontColor = "blue", c4Shape = EIGHT_SIDED, - legendText = "this is a person" + legendText = "this is a apple" ) private val containerStyle = createElementStyle( tag = containerTag, backgroundColor = "#ffffff", - border = Dotted, - borderWith = 5, + borderStyle = DOTTED, + borderWidth = 5, borderColor = "purple", fontColor = "red", technology = "REST", c4Shape = ROUNDED_BOX, - sprite = PumlSprite( + sprite = PUmlSprite( includeUrl = IconRegistry.iconUrlFor("postgresql")!!, - name = "postgresql", + name = IconRegistry.iconFileNameFor("postgresql")!!, scale = 0.5, color = "green" ), @@ -113,8 +123,8 @@ class StyleIntegrationTest { private val boundaryStyle = createBoundaryStyle( tag = boundaryTag, backgroundColor = "#00FFFF", - border = Dotted, - borderWith = 4, + border = DOTTED, + borderWidth = 4, borderColor = "red", fontColor = "green", legendText = "this is a system" @@ -122,8 +132,8 @@ class StyleIntegrationTest { private val componentStyle = createElementStyle( tag = componentTag, backgroundColor = "#ffffff", - border = Dotted, - borderWith = 5, + borderStyle = BOLD, + borderWidth = 5, borderColor = "purple", fontColor = "red", shadowing = false, @@ -133,6 +143,23 @@ class StyleIntegrationTest { legendSprite = OpenIconicSprite("compass"), legendText = "this is a legend text" ) + private val androidSprite = PUmlSprite( + name = IconRegistry.iconFileNameFor("android")!!, + includeUrl = IconRegistry.iconUrlFor("android")!!, + color = "green", + scale = 1.3 + ) + private val dependencyStyle = createDependencyStyle( + tag = dependencyTag, + fontColor = "#aa9999", + sprite = androidSprite, + legendText = "Android user uses", + legendSprite = androidSprite.copy(scale = 0.3), + technology = "Android", + lineColor = "green", + lineStyle = DOTTED, + lineWidth = 2 + ) @BeforeEach fun resetStyles() { @@ -145,6 +172,7 @@ class StyleIntegrationTest { views.addElementStyle(systemStyle) views.addPersonStyle(personStyle) + views.addDependencyStyle(dependencyStyle) val view = workspace.views.systemContextView(system, diagramKey, "SystemStyleTest") view.addAllPeople() @@ -158,6 +186,7 @@ class StyleIntegrationTest { views.addElementStyle(containerStyle) views.addPersonStyle(personStyle) views.addBoundaryStyle(boundaryStyle) + views.addDependencyStyle(dependencyStyle) val containerView = workspace.views.containerView(system, diagramKey, "ContainerStyleTest") containerView.addAllContainers() @@ -173,6 +202,7 @@ class StyleIntegrationTest { views.addElementStyle(componentStyle) views.addPersonStyle(personStyle) views.addBoundaryStyle(boundaryStyle) + views.addDependencyStyle(dependencyStyle) val componentView = workspace.views.componentView(container, diagramKey, "ComponentStyleTest") componentView.addAllComponents() @@ -188,6 +218,7 @@ class StyleIntegrationTest { views.addElementStyle(containerStyle) views.addPersonStyle(personStyle) views.addBoundaryStyle(boundaryStyle) + views.addDependencyStyle(dependencyStyle) val dynamicView = workspace.views.dynamicView(system, diagramKey, diagramKey) dynamicView.add(person, container, "uses") @@ -202,6 +233,7 @@ class StyleIntegrationTest { views.addElementStyle(containerStyle) views.addPersonStyle(personStyle) views.addBoundaryStyle(boundaryStyle) + views.addDependencyStyle(dependencyStyle) val dynamicView = workspace.views.dynamicView(system, diagramKey, diagramKey) dynamicView.add(person, container, "uses") @@ -219,14 +251,14 @@ class StyleIntegrationTest { val deploymentNodeStyle = createElementStyle( tag = deploymentNodeTag, backgroundColor = "#00EEFF", - borderWith = 4, + borderWidth = 4, ) val infrastructureNodeStyle = createElementStyle( tag = infrastructureNodeTag, backgroundColor = "#bcaadd", borderColor = "green", - borderWith = 3, + borderWidth = 3, ) val aws = model.deploymentNode( @@ -248,7 +280,7 @@ class StyleIntegrationTest { description = "", tags = listOf(infrastructureNodeTag), usedBy = listOf( - Dependency(nodeWithoutStyle, "uses"), + Dependency(nodeWithoutStyle, "uses", tags = listOf(dependencyTag)), Dependency(nodeWithStyle, "uses") ), ) @@ -257,6 +289,7 @@ class StyleIntegrationTest { views.addElementStyle(containerStyle) views.addElementStyle(deploymentNodeStyle) views.addElementStyle(infrastructureNodeStyle) + views.addDependencyStyle(dependencyStyle) val deploymentView = workspace.views.deploymentView(system, diagramKey, diagramKey) deploymentView.addAllDeploymentNodes() @@ -280,6 +313,7 @@ class StyleIntegrationTest { containerViewWithStyle.addElementStyle(containerStyle.copy(legendText = "this is a container")) containerViewWithStyle.addPersonStyle(personStyle.copy(legendText = "this is a legend")) containerViewWithStyle.addBoundaryStyle(boundaryStyle) + containerViewWithStyle.addDependencyStyle(dependencyStyle) val containerViewWithoutStyle = workspace.views.containerView( system, @@ -293,18 +327,36 @@ class StyleIntegrationTest { } @Test - fun `element style for unused tags are not exported`() { + fun `styles for unused tags are not exported`() { val diagramKey = "ViewStyleTestUnusedTag" - val unusedStyle = createElementStyle( - tag = "someUnusedTag", + val unusedElementStyle = createElementStyle( + tag = "someUnusedTag1", backgroundColor = "#ffffff", legendText = "this is a legend text" ) + val unusedPersonStyle = createPersonStyle( + tag = "someUnusedTag2", + backgroundColor = "#ffffff", + legendText = "this is a legend text" + ) + val unusedBoundaryStyle = createBoundaryStyle( + tag = "someUnusedTag3", + backgroundColor = "#ffffff", + legendText = "this is a legend text" + ) + val unusedDependencyStyle = createDependencyStyle( + tag = "someUnusedTag4", + lineColor = "#ffffff", + legendText = "this is a legend text" + ) val containerViewWithStyle = workspace.views.containerView(system, diagramKey, "ViewStyleTestWithStyle") containerViewWithStyle.addAllContainers() - containerViewWithStyle.addElementStyle(unusedStyle) + containerViewWithStyle.addElementStyle(unusedElementStyle) + containerViewWithStyle.addPersonStyle(unusedPersonStyle) + containerViewWithStyle.addBoundaryStyle(unusedBoundaryStyle) + containerViewWithStyle.addDependencyStyle(unusedDependencyStyle) assertExpectedDiagramWasWrittenForView(workspace, pathToExpectedDiagrams, diagramKey) } diff --git a/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/boundary/BoundaryStyleExtensionTest.kt b/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/boundary/BoundaryStyleExtensionTest.kt index d935267..135d5c3 100644 --- a/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/boundary/BoundaryStyleExtensionTest.kt +++ b/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/boundary/BoundaryStyleExtensionTest.kt @@ -3,18 +3,19 @@ package com.github.chriskn.structurizrextension.view.style.boundary import com.github.chriskn.structurizrextension.api.icons.IconRegistry import com.github.chriskn.structurizrextension.api.model.softwareSystem import com.github.chriskn.structurizrextension.api.view.containerView -import com.github.chriskn.structurizrextension.api.view.style.C4Shape.EIGHT_SIDED -import com.github.chriskn.structurizrextension.api.view.style.C4Shape.ROUNDED_BOX +import com.github.chriskn.structurizrextension.api.view.style.C4PUmlShape.EIGHT_SIDED +import com.github.chriskn.structurizrextension.api.view.style.C4PUmlShape.ROUNDED_BOX import com.github.chriskn.structurizrextension.api.view.style.addBoundaryStyle import com.github.chriskn.structurizrextension.api.view.style.getBoundaryStyles import com.github.chriskn.structurizrextension.api.view.style.sprite.ImageSprite import com.github.chriskn.structurizrextension.api.view.style.sprite.OpenIconicSprite -import com.github.chriskn.structurizrextension.api.view.style.sprite.PumlSprite +import com.github.chriskn.structurizrextension.api.view.style.sprite.PUmlSprite +import com.github.chriskn.structurizrextension.api.view.style.styles.C4PUmlLineStyle.BOLD +import com.github.chriskn.structurizrextension.api.view.style.styles.C4PUmlLineStyle.DASHED +import com.github.chriskn.structurizrextension.api.view.style.styles.C4PUmlLineStyle.DOTTED import com.github.chriskn.structurizrextension.api.view.style.styles.createBoundaryStyle import com.github.chriskn.structurizrextension.internal.export.view.style.toJson import com.structurizr.Workspace -import com.structurizr.view.Border.Dashed -import com.structurizr.view.Border.Dotted import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test @@ -23,13 +24,13 @@ import org.junit.jupiter.api.assertThrows class BoundaryStyleExtensionTest { @Test - fun `boundary style values are correctly set`() { + fun `boundary style values are correctly set`() { val expSprite = ImageSprite("img:https://plantuml.com/logo3.png", 0.4) val expLegendSprite = OpenIconicSprite("compass", scale = 3.0, color = "blue") val expTag = "styleTag" val expBackgroundColor = "#000000" - val expBorder = Dashed - val expBorderWith = 4 + val expBorder = DASHED + val expBorderWidth = 4 val expBorderColor = "#008000" val expFontColor = "#ffffff" val expShadowing = true @@ -40,7 +41,7 @@ class BoundaryStyleExtensionTest { tag = expTag, backgroundColor = expBackgroundColor, border = expBorder, - borderWith = expBorderWith, + borderWidth = expBorderWidth, borderColor = expBorderColor, fontColor = expFontColor, shadowing = expShadowing, @@ -52,8 +53,8 @@ class BoundaryStyleExtensionTest { assertThat(style.tag).isEqualTo(expTag) assertThat(style.backgroundColor).isEqualTo(expBackgroundColor) - assertThat(style.border).isEqualTo(expBorder) - assertThat(style.borderWith).isEqualTo(expBorderWith) + assertThat(style.borderStyle).isEqualTo(expBorder) + assertThat(style.borderWidth).isEqualTo(expBorderWidth) assertThat(style.borderColor).isEqualTo(expBorderColor) assertThat(style.fontColor).isEqualTo(expFontColor) assertThat(style.shadowing).isEqualTo(expShadowing) @@ -65,7 +66,7 @@ class BoundaryStyleExtensionTest { @Test fun `boundary style can be added to ViewSet`() { - val sprite = PumlSprite( + val sprite = PUmlSprite( includeUrl = IconRegistry.iconUrlFor("postgresql")!!, name = "postgresql", scale = 0.5, @@ -75,8 +76,8 @@ class BoundaryStyleExtensionTest { val style1 = createBoundaryStyle( tag = "tag", backgroundColor = "#ffffff", - border = Dotted, - borderWith = 5, + border = DOTTED, + borderWidth = 5, borderColor = "purple", fontColor = "red", shadowing = false, @@ -103,8 +104,8 @@ class BoundaryStyleExtensionTest { val style1 = createBoundaryStyle( tag = "tag", backgroundColor = "#ffffff", - border = Dotted, - borderWith = 5, + border = BOLD, + borderWidth = 5, ) val style2 = createBoundaryStyle("tag1") @@ -136,8 +137,8 @@ class BoundaryStyleExtensionTest { assertThat(style.tag).isEqualTo(expTag) assertThat(style.backgroundColor).isNull() - assertThat(style.border).isNull() - assertThat(style.borderWith).isNull() + assertThat(style.borderStyle).isNull() + assertThat(style.borderWidth).isNull() assertThat(style.borderColor).isNull() assertThat(style.fontColor).isNull() assertThat(style.shadowing).isFalse() diff --git a/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/boundary/BoundaryStyleJsonTest.kt b/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/boundary/BoundaryStyleJsonTest.kt index dba5faa..a79c08a 100644 --- a/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/boundary/BoundaryStyleJsonTest.kt +++ b/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/boundary/BoundaryStyleJsonTest.kt @@ -1,12 +1,12 @@ package com.github.chriskn.structurizrextension.view.style.boundary -import com.github.chriskn.structurizrextension.api.view.style.C4Shape.EIGHT_SIDED +import com.github.chriskn.structurizrextension.api.view.style.C4PUmlShape.EIGHT_SIDED import com.github.chriskn.structurizrextension.api.view.style.sprite.ImageSprite import com.github.chriskn.structurizrextension.api.view.style.sprite.OpenIconicSprite +import com.github.chriskn.structurizrextension.api.view.style.styles.C4PUmlLineStyle.SOLID import com.github.chriskn.structurizrextension.api.view.style.styles.createBoundaryStyle import com.github.chriskn.structurizrextension.internal.export.view.style.elementStyleFromJson import com.github.chriskn.structurizrextension.internal.export.view.style.toJson -import com.structurizr.view.Border.Dashed import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -18,7 +18,7 @@ class BoundaryStyleJsonTest { val expLegendSprite = OpenIconicSprite("compass", scale = 3.0, color = "blue") val expTag = "styleTag" val expBackgroundColor = "#000000" - val expBorder = Dashed + val expBorder = SOLID val expBorderWith = 4 val expBorderColor = "#008000" val expFontColor = "#ffffff" @@ -30,7 +30,7 @@ class BoundaryStyleJsonTest { tag = expTag, backgroundColor = expBackgroundColor, border = expBorder, - borderWith = expBorderWith, + borderWidth = expBorderWith, borderColor = expBorderColor, fontColor = expFontColor, shadowing = expShadowing, @@ -45,8 +45,8 @@ class BoundaryStyleJsonTest { assertThat(deserializedStyle.tag).isEqualTo(expTag) assertThat(deserializedStyle.backgroundColor).isEqualTo(expBackgroundColor) - assertThat(deserializedStyle.border).isEqualTo(expBorder) - assertThat(deserializedStyle.borderWith).isEqualTo(expBorderWith) + assertThat(deserializedStyle.borderStyle).isEqualTo(expBorder) + assertThat(deserializedStyle.borderWidth).isEqualTo(expBorderWith) assertThat(deserializedStyle.borderColor).isEqualTo(expBorderColor) assertThat(deserializedStyle.fontColor).isEqualTo(expFontColor) assertThat(deserializedStyle.shadowing).isEqualTo(expShadowing) diff --git a/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/dependency/DependencyStyleExtensionTest.kt b/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/dependency/DependencyStyleExtensionTest.kt new file mode 100644 index 0000000..8e5d196 --- /dev/null +++ b/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/dependency/DependencyStyleExtensionTest.kt @@ -0,0 +1,169 @@ +package com.github.chriskn.structurizrextension.view.style.dependency + +import com.github.chriskn.structurizrextension.api.icons.IconRegistry +import com.github.chriskn.structurizrextension.api.model.softwareSystem +import com.github.chriskn.structurizrextension.api.view.containerView +import com.github.chriskn.structurizrextension.api.view.style.addDependencyStyle +import com.github.chriskn.structurizrextension.api.view.style.getDependencyStyles +import com.github.chriskn.structurizrextension.api.view.style.sprite.ImageSprite +import com.github.chriskn.structurizrextension.api.view.style.sprite.OpenIconicSprite +import com.github.chriskn.structurizrextension.api.view.style.sprite.PUmlSprite +import com.github.chriskn.structurizrextension.api.view.style.styles.C4PUmlLineStyle.BOLD +import com.github.chriskn.structurizrextension.api.view.style.styles.C4PUmlLineStyle.DASHED +import com.github.chriskn.structurizrextension.api.view.style.styles.C4PUmlLineStyle.DOTTED +import com.github.chriskn.structurizrextension.api.view.style.styles.createDependencyStyle +import com.github.chriskn.structurizrextension.internal.export.view.style.toJson +import com.structurizr.Workspace +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Nested +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows + +class DependencyStyleExtensionTest { + + @Test + fun `dependency style values are correctly set`() { + val expSprite = ImageSprite("img:https://plantuml.com/logo3.png", 0.4) + val expLegendSprite = OpenIconicSprite("compass", scale = 3.0, color = "blue") + val expTag = "styleTag" + val expLineColor = "#00ff00" + val expLineStyle = DASHED + val expLineWidth = 4 + val expFontColor = "#ffffff" + val expTechnology = "Kafka" + val expLegendText = "this is a legend" + + val style = createDependencyStyle( + tag = expTag, + lineColor = expLineColor, + lineStyle = expLineStyle, + lineWidth = expLineWidth, + fontColor = expFontColor, + technology = expTechnology, + sprite = expSprite, + legendSprite = expLegendSprite, + legendText = expLegendText, + ) + + assertThat(style.tag).isEqualTo(expTag) + assertThat(style.lineStyle).isEqualTo(expLineStyle) + assertThat(style.lineWidth).isEqualTo(expLineWidth) + assertThat(style.lineColor).isEqualTo(expLineColor) + assertThat(style.fontColor).isEqualTo(expFontColor) + assertThat(style.technology).isEqualTo(expTechnology) + assertThat(style.sprite).isEqualTo(expSprite) + assertThat(style.legendSprite).isEqualTo(expLegendSprite) + assertThat(style.legendText).isEqualTo(expLegendText) + } + + @Test + fun `dependency style can be added to ViewSet`() { + val sprite = PUmlSprite( + includeUrl = IconRegistry.iconUrlFor("postgresql")!!, + name = "postgresql", + scale = 0.5, + color = "green" + ) + val legendSprite = OpenIconicSprite("compass") + val style1 = createDependencyStyle( + tag = "tag", + lineColor = "#ffffff", + lineStyle = DOTTED, + lineWidth = 5, + fontColor = "red", + technology = "REST", + sprite = sprite, + legendSprite = legendSprite, + legendText = "this is a legend text" + ) + val style2 = createDependencyStyle("tag1") + + val workspace = Workspace("test", "test") + val views = workspace.views + + views.addDependencyStyle(style1) + views.addDependencyStyle(style2) + + val dependencyStyles = views.getDependencyStyles() + assertThat(dependencyStyles).hasSize(2) + assertThat(dependencyStyles.firstOrNull { it.tag == style1.tag }).isEqualTo(style1) + assertThat(dependencyStyles.firstOrNull { it.tag == style2.tag }).isEqualTo(style2) + } + + @Test + fun `dependency style can be added to View`() { + val style1 = createDependencyStyle( + tag = "tag", + lineColor = "#ffffff", + lineStyle = BOLD, + lineWidth = 5, + ) + val style2 = createDependencyStyle("tag1") + + val workspace = Workspace("test", "test") + val views = workspace.views + + val system = workspace.model.softwareSystem("test", "test") + val view = views.containerView(system, "testview", "desc") + view.addDependencyStyle(style1) + view.addDependencyStyle(style2) + + val elementStyles = view.getDependencyStyles() + assertThat(elementStyles).hasSize(2) + assertThat(elementStyles.map { it.toJson() }).contains(style1.toJson(), style2.toJson()) + } + + @Test + fun `IllegalArgumentException is thrown when tag is blank`() { + assertThrows { + createDependencyStyle(" ") + } + } + + @Test + fun `dependency style can be initialized with null values`() { + val expTag = "tag" + + val style = createDependencyStyle(tag = expTag) + + assertThat(style.tag).isEqualTo(expTag) + assertThat(style.lineColor).isNull() + assertThat(style.lineStyle).isNull() + assertThat(style.lineWidth).isNull() + assertThat(style.fontColor).isNull() + assertThat(style.technology).isNull() + assertThat(style.sprite).isNull() + assertThat(style.legendSprite).isNull() + assertThat(style.legendText).isNull() + } + + @Nested + inner class Color { + + @Test + fun `IllegalArgumentException is thrown for invalid line color`() { + assertThrows { + createDependencyStyle("test", lineColor = "ABC") + } + } + + @Test + fun `IllegalArgumentException is thrown for invalid font color`() { + assertThrows { + createDependencyStyle("test", fontColor = "jellow") + } + } + + @Test + fun `named line color is translated to hex color`() { + val elementStyle = createDependencyStyle("test", lineColor = "green") + assertThat(elementStyle.lineColor).isEqualTo("#008000") + } + + @Test + fun `named font color is translated to hex color`() { + val elementStyle = createDependencyStyle("test", fontColor = "black") + assertThat(elementStyle.fontColor).isEqualTo("#000000") + } + } +} diff --git a/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/dependency/DependencyStyleJsonTest.kt b/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/dependency/DependencyStyleJsonTest.kt new file mode 100644 index 0000000..3896bb7 --- /dev/null +++ b/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/dependency/DependencyStyleJsonTest.kt @@ -0,0 +1,51 @@ +package com.github.chriskn.structurizrextension.view.style.dependency + +import com.github.chriskn.structurizrextension.api.view.style.sprite.ImageSprite +import com.github.chriskn.structurizrextension.api.view.style.sprite.OpenIconicSprite +import com.github.chriskn.structurizrextension.api.view.style.styles.C4PUmlLineStyle.DASHED +import com.github.chriskn.structurizrextension.api.view.style.styles.createDependencyStyle +import com.github.chriskn.structurizrextension.internal.export.view.style.dependencyStyleFromJson +import com.github.chriskn.structurizrextension.internal.export.view.style.toJson +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +class DependencyStyleJsonTest { + + @Test + fun `dependency style is serialized and deserialized correctly`() { + val expSprite = ImageSprite("img:https://plantuml.com/logo3.png", 0.4) + val expLegendSprite = OpenIconicSprite("compass", scale = 3.0, color = "blue") + val expTag = "styleTag" + val expBackgroundColor = "#000000" + val expBorder = DASHED + val expBorderWith = 4 + val expFontColor = "#ffffff" + val expTechnology = "Kafka" + val expLegendText = "this is a legend" + + val style = createDependencyStyle( + tag = expTag, + lineColor = expBackgroundColor, + lineStyle = expBorder, + lineWidth = expBorderWith, + fontColor = expFontColor, + technology = expTechnology, + sprite = expSprite, + legendSprite = expLegendSprite, + legendText = expLegendText + ) + + val styleJson = style.toJson() + val deserializedStyle = dependencyStyleFromJson(styleJson) + + assertThat(deserializedStyle.tag).isEqualTo(expTag) + assertThat(deserializedStyle.lineColor).isEqualTo(expBackgroundColor) + assertThat(deserializedStyle.lineStyle).isEqualTo(expBorder) + assertThat(deserializedStyle.lineWidth).isEqualTo(expBorderWith) + assertThat(deserializedStyle.fontColor).isEqualTo(expFontColor) + assertThat(deserializedStyle.technology).isEqualTo(expTechnology) + assertThat(deserializedStyle.sprite).isEqualTo(expSprite) + assertThat(deserializedStyle.legendSprite).isEqualTo(expLegendSprite) + assertThat(deserializedStyle.legendText).isEqualTo(expLegendText) + } +} diff --git a/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/element/ElementStyleExtensionTest.kt b/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/element/ElementStyleExtensionTest.kt index 25c06d7..ba56464 100644 --- a/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/element/ElementStyleExtensionTest.kt +++ b/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/element/ElementStyleExtensionTest.kt @@ -3,18 +3,18 @@ package com.github.chriskn.structurizrextension.view.style.element import com.github.chriskn.structurizrextension.api.icons.IconRegistry import com.github.chriskn.structurizrextension.api.model.softwareSystem import com.github.chriskn.structurizrextension.api.view.containerView -import com.github.chriskn.structurizrextension.api.view.style.C4Shape.EIGHT_SIDED -import com.github.chriskn.structurizrextension.api.view.style.C4Shape.ROUNDED_BOX +import com.github.chriskn.structurizrextension.api.view.style.C4PUmlShape.EIGHT_SIDED +import com.github.chriskn.structurizrextension.api.view.style.C4PUmlShape.ROUNDED_BOX import com.github.chriskn.structurizrextension.api.view.style.addElementStyle import com.github.chriskn.structurizrextension.api.view.style.getElementStyles import com.github.chriskn.structurizrextension.api.view.style.sprite.ImageSprite import com.github.chriskn.structurizrextension.api.view.style.sprite.OpenIconicSprite -import com.github.chriskn.structurizrextension.api.view.style.sprite.PumlSprite +import com.github.chriskn.structurizrextension.api.view.style.sprite.PUmlSprite +import com.github.chriskn.structurizrextension.api.view.style.styles.C4PUmlLineStyle.DASHED +import com.github.chriskn.structurizrextension.api.view.style.styles.C4PUmlLineStyle.DOTTED import com.github.chriskn.structurizrextension.api.view.style.styles.createElementStyle import com.github.chriskn.structurizrextension.internal.export.view.style.toJson import com.structurizr.Workspace -import com.structurizr.view.Border.Dashed -import com.structurizr.view.Border.Dotted import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test @@ -28,8 +28,8 @@ class ElementStyleExtensionTest { val expLegendSprite = OpenIconicSprite("compass", scale = 3.0, color = "blue") val expTag = "styleTag" val expBackgroundColor = "#000000" - val expBorder = Dashed - val expBorderWith = 4 + val expBorder = DASHED + val expBorderWidth = 4 val expBorderColor = "#008000" val expFontColor = "#ffffff" val expShadowing = true @@ -40,8 +40,8 @@ class ElementStyleExtensionTest { val style = createElementStyle( tag = expTag, backgroundColor = expBackgroundColor, - border = expBorder, - borderWith = expBorderWith, + borderStyle = expBorder, + borderWidth = expBorderWidth, borderColor = expBorderColor, fontColor = expFontColor, shadowing = expShadowing, @@ -54,8 +54,8 @@ class ElementStyleExtensionTest { assertThat(style.tag).isEqualTo(expTag) assertThat(style.backgroundColor).isEqualTo(expBackgroundColor) - assertThat(style.border).isEqualTo(expBorder) - assertThat(style.borderWith).isEqualTo(expBorderWith) + assertThat(style.borderStyle).isEqualTo(expBorder) + assertThat(style.borderWidth).isEqualTo(expBorderWidth) assertThat(style.borderColor).isEqualTo(expBorderColor) assertThat(style.fontColor).isEqualTo(expFontColor) assertThat(style.shadowing).isEqualTo(expShadowing) @@ -68,7 +68,7 @@ class ElementStyleExtensionTest { @Test fun `element style can be added to ViewSet`() { - val sprite = PumlSprite( + val sprite = PUmlSprite( includeUrl = IconRegistry.iconUrlFor("postgresql")!!, name = "postgresql", scale = 0.5, @@ -78,8 +78,8 @@ class ElementStyleExtensionTest { val style1 = createElementStyle( tag = "tag", backgroundColor = "#ffffff", - border = Dotted, - borderWith = 5, + borderStyle = DOTTED, + borderWidth = 5, borderColor = "purple", fontColor = "red", shadowing = false, @@ -107,8 +107,8 @@ class ElementStyleExtensionTest { val style1 = createElementStyle( tag = "tag", backgroundColor = "#ffffff", - border = Dotted, - borderWith = 5, + borderStyle = DOTTED, + borderWidth = 5, ) val style2 = createElementStyle("tag1") @@ -140,8 +140,8 @@ class ElementStyleExtensionTest { assertThat(style.tag).isEqualTo(expTag) assertThat(style.backgroundColor).isNull() - assertThat(style.border).isNull() - assertThat(style.borderWith).isNull() + assertThat(style.borderStyle).isNull() + assertThat(style.borderWidth).isNull() assertThat(style.borderColor).isNull() assertThat(style.fontColor).isNull() assertThat(style.shadowing).isFalse() diff --git a/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/element/ElementStyleJsonTest.kt b/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/element/ElementStyleJsonTest.kt index c9ddeba..ad39c29 100644 --- a/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/element/ElementStyleJsonTest.kt +++ b/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/element/ElementStyleJsonTest.kt @@ -1,12 +1,12 @@ package com.github.chriskn.structurizrextension.view.style.element -import com.github.chriskn.structurizrextension.api.view.style.C4Shape.EIGHT_SIDED +import com.github.chriskn.structurizrextension.api.view.style.C4PUmlShape.EIGHT_SIDED import com.github.chriskn.structurizrextension.api.view.style.sprite.ImageSprite import com.github.chriskn.structurizrextension.api.view.style.sprite.OpenIconicSprite +import com.github.chriskn.structurizrextension.api.view.style.styles.C4PUmlLineStyle.DASHED import com.github.chriskn.structurizrextension.api.view.style.styles.createElementStyle import com.github.chriskn.structurizrextension.internal.export.view.style.elementStyleFromJson import com.github.chriskn.structurizrextension.internal.export.view.style.toJson -import com.structurizr.view.Border.Dashed import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -18,7 +18,7 @@ class ElementStyleJsonTest { val expLegendSprite = OpenIconicSprite("compass", scale = 3.0, color = "blue") val expTag = "styleTag" val expBackgroundColor = "#000000" - val expBorder = Dashed + val expBorder = DASHED val expBorderWith = 4 val expBorderColor = "#008000" val expFontColor = "#ffffff" @@ -30,8 +30,8 @@ class ElementStyleJsonTest { val style = createElementStyle( tag = expTag, backgroundColor = expBackgroundColor, - border = expBorder, - borderWith = expBorderWith, + borderStyle = expBorder, + borderWidth = expBorderWith, borderColor = expBorderColor, fontColor = expFontColor, shadowing = expShadowing, @@ -47,8 +47,8 @@ class ElementStyleJsonTest { assertThat(deserializedStyle.tag).isEqualTo(expTag) assertThat(deserializedStyle.backgroundColor).isEqualTo(expBackgroundColor) - assertThat(deserializedStyle.border).isEqualTo(expBorder) - assertThat(deserializedStyle.borderWith).isEqualTo(expBorderWith) + assertThat(deserializedStyle.borderStyle).isEqualTo(expBorder) + assertThat(deserializedStyle.borderWidth).isEqualTo(expBorderWith) assertThat(deserializedStyle.borderColor).isEqualTo(expBorderColor) assertThat(deserializedStyle.fontColor).isEqualTo(expFontColor) assertThat(deserializedStyle.shadowing).isEqualTo(expShadowing) diff --git a/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/person/PersonStyleExtensionTest.kt b/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/person/PersonStyleExtensionTest.kt index 5bc05f8..49c1be7 100644 --- a/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/person/PersonStyleExtensionTest.kt +++ b/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/person/PersonStyleExtensionTest.kt @@ -3,18 +3,18 @@ package com.github.chriskn.structurizrextension.view.style.person import com.github.chriskn.structurizrextension.api.icons.IconRegistry import com.github.chriskn.structurizrextension.api.model.softwareSystem import com.github.chriskn.structurizrextension.api.view.containerView -import com.github.chriskn.structurizrextension.api.view.style.C4Shape.EIGHT_SIDED -import com.github.chriskn.structurizrextension.api.view.style.C4Shape.ROUNDED_BOX +import com.github.chriskn.structurizrextension.api.view.style.C4PUmlShape.EIGHT_SIDED +import com.github.chriskn.structurizrextension.api.view.style.C4PUmlShape.ROUNDED_BOX import com.github.chriskn.structurizrextension.api.view.style.addPersonStyle import com.github.chriskn.structurizrextension.api.view.style.getPersonStyles import com.github.chriskn.structurizrextension.api.view.style.sprite.ImageSprite import com.github.chriskn.structurizrextension.api.view.style.sprite.OpenIconicSprite -import com.github.chriskn.structurizrextension.api.view.style.sprite.PumlSprite +import com.github.chriskn.structurizrextension.api.view.style.sprite.PUmlSprite +import com.github.chriskn.structurizrextension.api.view.style.styles.C4PUmlLineStyle.DASHED +import com.github.chriskn.structurizrextension.api.view.style.styles.C4PUmlLineStyle.DOTTED import com.github.chriskn.structurizrextension.api.view.style.styles.createPersonStyle import com.github.chriskn.structurizrextension.internal.export.view.style.toJson import com.structurizr.Workspace -import com.structurizr.view.Border.Dashed -import com.structurizr.view.Border.Dotted import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test @@ -28,7 +28,7 @@ class PersonStyleExtensionTest { val expLegendSprite = OpenIconicSprite("compass", scale = 3.0, color = "blue") val expTag = "styleTag" val expBackgroundColor = "#000000" - val expBorder = Dashed + val expBorder = DASHED val expBorderWith = 4 val expBorderColor = "#008000" val expFontColor = "#ffffff" @@ -39,8 +39,8 @@ class PersonStyleExtensionTest { val style = createPersonStyle( tag = expTag, backgroundColor = expBackgroundColor, - border = expBorder, - borderWith = expBorderWith, + borderStyle = expBorder, + borderWidth = expBorderWith, borderColor = expBorderColor, fontColor = expFontColor, shadowing = expShadowing, @@ -52,8 +52,8 @@ class PersonStyleExtensionTest { assertThat(style.tag).isEqualTo(expTag) assertThat(style.backgroundColor).isEqualTo(expBackgroundColor) - assertThat(style.border).isEqualTo(expBorder) - assertThat(style.borderWith).isEqualTo(expBorderWith) + assertThat(style.borderStyle).isEqualTo(expBorder) + assertThat(style.borderWidth).isEqualTo(expBorderWith) assertThat(style.borderColor).isEqualTo(expBorderColor) assertThat(style.fontColor).isEqualTo(expFontColor) assertThat(style.shadowing).isEqualTo(expShadowing) @@ -65,7 +65,7 @@ class PersonStyleExtensionTest { @Test fun `person style can be added to ViewSet`() { - val sprite = PumlSprite( + val sprite = PUmlSprite( includeUrl = IconRegistry.iconUrlFor("postgresql")!!, name = "postgresql", scale = 0.5, @@ -75,8 +75,8 @@ class PersonStyleExtensionTest { val style1 = createPersonStyle( tag = "tag", backgroundColor = "#ffffff", - border = Dotted, - borderWith = 5, + borderStyle = DOTTED, + borderWidth = 5, borderColor = "purple", fontColor = "red", shadowing = false, @@ -104,8 +104,8 @@ class PersonStyleExtensionTest { val style1 = createPersonStyle( tag = "tag", backgroundColor = "#ffffff", - border = Dotted, - borderWith = 5, + borderStyle = DOTTED, + borderWidth = 5, ) val style2 = createPersonStyle("tag1") @@ -137,8 +137,8 @@ class PersonStyleExtensionTest { assertThat(style.tag).isEqualTo(expTag) assertThat(style.backgroundColor).isNull() - assertThat(style.border).isNull() - assertThat(style.borderWith).isNull() + assertThat(style.borderStyle).isNull() + assertThat(style.borderWidth).isNull() assertThat(style.borderColor).isNull() assertThat(style.fontColor).isNull() assertThat(style.shadowing).isFalse() diff --git a/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/person/PersonStyleJsonTest.kt b/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/person/PersonStyleJsonTest.kt index 1d7abe0..4b38ed3 100644 --- a/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/person/PersonStyleJsonTest.kt +++ b/src/test/kotlin/com/github/chriskn/structurizrextension/view/style/person/PersonStyleJsonTest.kt @@ -1,12 +1,12 @@ package com.github.chriskn.structurizrextension.view.style.person -import com.github.chriskn.structurizrextension.api.view.style.C4Shape.EIGHT_SIDED +import com.github.chriskn.structurizrextension.api.view.style.C4PUmlShape.EIGHT_SIDED import com.github.chriskn.structurizrextension.api.view.style.sprite.ImageSprite import com.github.chriskn.structurizrextension.api.view.style.sprite.OpenIconicSprite +import com.github.chriskn.structurizrextension.api.view.style.styles.C4PUmlLineStyle.SOLID import com.github.chriskn.structurizrextension.api.view.style.styles.createPersonStyle import com.github.chriskn.structurizrextension.internal.export.view.style.elementStyleFromJson import com.github.chriskn.structurizrextension.internal.export.view.style.toJson -import com.structurizr.view.Border.Dashed import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -18,8 +18,8 @@ class PersonStyleJsonTest { val expLegendSprite = OpenIconicSprite("compass", scale = 3.0, color = "blue") val expTag = "styleTag" val expBackgroundColor = "#000000" - val expBorder = Dashed - val expBorderWith = 4 + val expBorder = SOLID + val expBorderWidth = 4 val expBorderColor = "#008000" val expFontColor = "#ffffff" val expShadowing = true @@ -29,8 +29,8 @@ class PersonStyleJsonTest { val style = createPersonStyle( tag = expTag, backgroundColor = expBackgroundColor, - border = expBorder, - borderWith = expBorderWith, + borderStyle = expBorder, + borderWidth = expBorderWidth, borderColor = expBorderColor, fontColor = expFontColor, shadowing = expShadowing, @@ -45,8 +45,8 @@ class PersonStyleJsonTest { assertThat(deserializedStyle.tag).isEqualTo(expTag) assertThat(deserializedStyle.backgroundColor).isEqualTo(expBackgroundColor) - assertThat(deserializedStyle.border).isEqualTo(expBorder) - assertThat(deserializedStyle.borderWith).isEqualTo(expBorderWith) + assertThat(deserializedStyle.borderStyle).isEqualTo(expBorder) + assertThat(deserializedStyle.borderWidth).isEqualTo(expBorderWidth) assertThat(deserializedStyle.borderColor).isEqualTo(expBorderColor) assertThat(deserializedStyle.fontColor).isEqualTo(expFontColor) assertThat(deserializedStyle.shadowing).isEqualTo(expShadowing) diff --git a/src/test/resources/expected/view/style/ComponentStyleTest.puml b/src/test/resources/expected/view/style/ComponentStyleTest.puml index cf73919..94ccf58 100644 --- a/src/test/resources/expected/view/style/ComponentStyleTest.puml +++ b/src/test/resources/expected/view/style/ComponentStyleTest.puml @@ -1,19 +1,22 @@ @startuml(id=ComponentStyleTest) !includeurl https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Component.puml +!includeurl https://raw.githubusercontent.com/plantuml-stdlib/gilbarbara-plantuml-sprites/master/sprites/android-icon.puml +!includeurl https://raw.githubusercontent.com/plantuml-stdlib/gilbarbara-plantuml-sprites/master/sprites/apple.puml title My Software System - My Container - Components caption ComponentStyleTest SHOW_PERSON_OUTLINE() LAYOUT_TOP_DOWN() -AddElementTag(Component Style, $sprite="&compass", $bgColor=#ffffff, $fontColor=#ff0000, $borderColor=#800080, $borderStyle=DottedLine(), $borderThickness=5, $shadowing=false, $shape=RoundedBoxShape(), $techn=REST, $legendSprite="&compass", $legendText=this is a legend text) +AddRelTag(Dependency Style, $sprite="android-icon{scale=1.3,color=#008000}", $lineColor=#008000, $textColor=#aa9999, $techn=Android, $lineStyle=DottedLine(), $lineThickness=2, $legendSprite="android-icon{scale=0.3,color=#008000}", $legendText=Android user uses) +AddElementTag(Component Style, $sprite="&compass", $bgColor=#ffffff, $fontColor=#ff0000, $borderColor=#800080, $borderStyle=BoldLine(), $borderThickness=5, $shadowing=false, $shape=RoundedBoxShape(), $techn=REST, $legendSprite="&compass", $legendText=this is a legend text) AddBoundaryTag(Boundary Style, $bgColor=#00ffff, $fontColor=#008000, $borderColor=#ff0000, $borderStyle=DottedLine(), $borderThickness=4, $shadowing=false, $legendText=this is a system) -AddPersonTag(Person Style, $bgColor=#00ff00, $fontColor=#0000ff, $borderColor=#ff0000, $borderStyle=DashedLine(), $borderThickness=4, $shadowing=false, $shape=EightSidedShape(), $legendText=this is a person) +AddPersonTag(Person Style, $sprite="apple{scale=0.5,color=#008000}", $bgColor=#00ff00, $fontColor=#0000ff, $borderColor=#ff0000, $borderStyle=DashedLine(), $borderThickness=4, $shadowing=false, $shape=EightSidedShape(), $legendText=this is a apple) Container_Boundary("MySoftwareSystem.MyContainer_boundary", "My Container" , $tags="Container Style+Boundary Style"){ Component(MySoftwareSystem.MyContainer.MyComponent, "My Component", "", "component", "", $tags="Component Style") } Person(Person, "Person", "", "", $tags="Person Style") -Rel(Person, MySoftwareSystem.MyContainer.MyComponent, "uses component") +Rel(Person, MySoftwareSystem.MyContainer.MyComponent, "uses component", $tags="Dependency Style") SHOW_LEGEND(true) diff --git a/src/test/resources/expected/view/style/ContainerStyleTest.puml b/src/test/resources/expected/view/style/ContainerStyleTest.puml index 1bb55e7..649c60c 100644 --- a/src/test/resources/expected/view/style/ContainerStyleTest.puml +++ b/src/test/resources/expected/view/style/ContainerStyleTest.puml @@ -1,5 +1,7 @@ @startuml(id=ContainerStyleTest) !includeurl https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml +!includeurl https://raw.githubusercontent.com/plantuml-stdlib/gilbarbara-plantuml-sprites/master/sprites/android-icon.puml +!includeurl https://raw.githubusercontent.com/plantuml-stdlib/gilbarbara-plantuml-sprites/master/sprites/apple.puml !includeurl https://raw.githubusercontent.com/plantuml-stdlib/gilbarbara-plantuml-sprites/master/sprites/postgresql.puml title My Software System - Containers caption ContainerStyleTest @@ -7,15 +9,16 @@ caption ContainerStyleTest SHOW_PERSON_OUTLINE() LAYOUT_TOP_DOWN() +AddRelTag(Dependency Style, $sprite="android-icon{scale=1.3,color=#008000}", $lineColor=#008000, $textColor=#aa9999, $techn=Android, $lineStyle=DottedLine(), $lineThickness=2, $legendSprite="android-icon{scale=0.3,color=#008000}", $legendText=Android user uses) AddElementTag(Container Style, $sprite="postgresql{scale=0.5,color=#008000}", $bgColor=#ffffff, $fontColor=#ff0000, $borderColor=#800080, $borderStyle=DottedLine(), $borderThickness=5, $shadowing=false, $shape=RoundedBoxShape(), $techn=REST, $legendSprite="&compass", $legendText=this is a legend container) AddBoundaryTag(Boundary Style, $bgColor=#00ffff, $fontColor=#008000, $borderColor=#ff0000, $borderStyle=DottedLine(), $borderThickness=4, $shadowing=false, $legendText=this is a system) -AddPersonTag(Person Style, $bgColor=#00ff00, $fontColor=#0000ff, $borderColor=#ff0000, $borderStyle=DashedLine(), $borderThickness=4, $shadowing=false, $shape=EightSidedShape(), $legendText=this is a person) +AddPersonTag(Person Style, $sprite="apple{scale=0.5,color=#008000}", $bgColor=#00ff00, $fontColor=#0000ff, $borderColor=#ff0000, $borderStyle=DashedLine(), $borderThickness=4, $shadowing=false, $shape=EightSidedShape(), $legendText=this is a apple) System_Boundary(MySoftwareSystem, My Software System, $tags="System Style+Boundary Style") { Container(MySoftwareSystem.MyContainer, "My Container", "", "container", "", $tags="Container Style+Boundary Style") } Person(Person, "Person", "", "", $tags="Person Style") -Rel(Person, MySoftwareSystem.MyContainer, "uses container") +Rel(Person, MySoftwareSystem.MyContainer, "uses container", $tags="Dependency Style") SHOW_LEGEND(true) diff --git a/src/test/resources/expected/view/style/DeploymentStyleTest.puml b/src/test/resources/expected/view/style/DeploymentStyleTest.puml index 0361479..de19fa8 100644 --- a/src/test/resources/expected/view/style/DeploymentStyleTest.puml +++ b/src/test/resources/expected/view/style/DeploymentStyleTest.puml @@ -2,6 +2,7 @@ !includeurl https://raw.githubusercontent.com/awslabs/aws-icons-for-plantuml/v11.1/dist/AWSCommon.puml !includeurl https://raw.githubusercontent.com/awslabs/aws-icons-for-plantuml/v11.1/dist/GroupIcons/Cloudalt.puml !includeurl https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Deployment.puml +!includeurl https://raw.githubusercontent.com/plantuml-stdlib/gilbarbara-plantuml-sprites/master/sprites/android-icon.puml !includeurl https://raw.githubusercontent.com/plantuml-stdlib/gilbarbara-plantuml-sprites/master/sprites/postgresql.puml title My Software System - Deployment - Default caption DeploymentStyleTest @@ -9,6 +10,7 @@ caption DeploymentStyleTest SHOW_PERSON_OUTLINE() LAYOUT_TOP_DOWN() +AddRelTag(Dependency Style, $sprite="android-icon{scale=1.3,color=#008000}", $lineColor=#008000, $textColor=#aa9999, $techn=Android, $lineStyle=DottedLine(), $lineThickness=2, $legendSprite="android-icon{scale=0.3,color=#008000}", $legendText=Android user uses) AddElementTag(Container Style, $sprite="postgresql{scale=0.5,color=#008000}", $bgColor=#ffffff, $fontColor=#ff0000, $borderColor=#800080, $borderStyle=DottedLine(), $borderThickness=5, $shadowing=false, $shape=RoundedBoxShape(), $techn=REST, $legendSprite="&compass", $legendText=this is a legend container) AddElementTag(Deployment Node Tag, $bgColor=#00eeff, $borderThickness=4, $shadowing=false) AddElementTag(Infrastructure Node Tag, $bgColor=#bcaadd, $borderColor=#008000, $borderThickness=3, $shadowing=false) @@ -22,7 +24,7 @@ Node(Default.AWS, "AWS", "", "Production AWS environment", "Cloudalt") { Node(Default.AWS.SomeInfrastructureNode, "Some Infrastructure Node", "", "", "", $tags="Infrastructure Node Tag") } Rel(Default.AWS.Nodewithstyle, Default.AWS.SomeInfrastructureNode, "uses") -Rel(Default.AWS.Nodewithoutstyle, Default.AWS.SomeInfrastructureNode, "uses") +Rel(Default.AWS.Nodewithoutstyle, Default.AWS.SomeInfrastructureNode, "uses", $tags="Dependency Style") SHOW_LEGEND(true) diff --git a/src/test/resources/expected/view/style/DynamicStyleSequenceTest.puml b/src/test/resources/expected/view/style/DynamicStyleSequenceTest.puml index d6ef859..fa4e4e3 100644 --- a/src/test/resources/expected/view/style/DynamicStyleSequenceTest.puml +++ b/src/test/resources/expected/view/style/DynamicStyleSequenceTest.puml @@ -1,19 +1,22 @@ @startuml(id=DynamicStyleSequenceTest) !includeurl https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Sequence.puml +!includeurl https://raw.githubusercontent.com/plantuml-stdlib/gilbarbara-plantuml-sprites/master/sprites/android-icon.puml +!includeurl https://raw.githubusercontent.com/plantuml-stdlib/gilbarbara-plantuml-sprites/master/sprites/apple.puml !includeurl https://raw.githubusercontent.com/plantuml-stdlib/gilbarbara-plantuml-sprites/master/sprites/postgresql.puml title My Software System - Dynamic caption DynamicStyleSequenceTest SHOW_PERSON_OUTLINE() +AddRelTag(Dependency Style, $sprite="android-icon{scale=1.3,color=#008000}", $lineColor=#008000, $textColor=#aa9999, $techn=Android, $lineStyle=DottedLine(), $lineThickness=2, $legendSprite="android-icon{scale=0.3,color=#008000}", $legendText=Android user uses) AddElementTag(Container Style, $sprite="postgresql{scale=0.5,color=#008000}", $bgColor=#ffffff, $fontColor=#ff0000, $borderColor=#800080, $borderStyle=DottedLine(), $borderThickness=5, $shadowing=false, $shape=RoundedBoxShape(), $techn=REST, $legendSprite="&compass", $legendText=this is a legend container) AddBoundaryTag(Boundary Style, $bgColor=#00ffff, $fontColor=#008000, $borderColor=#ff0000, $borderStyle=DottedLine(), $borderThickness=4, $shadowing=false, $legendText=this is a system) -AddPersonTag(Person Style, $bgColor=#00ff00, $fontColor=#0000ff, $borderColor=#ff0000, $borderStyle=DashedLine(), $borderThickness=4, $shadowing=false, $shape=EightSidedShape(), $legendText=this is a person) +AddPersonTag(Person Style, $sprite="apple{scale=0.5,color=#008000}", $bgColor=#00ff00, $fontColor=#0000ff, $borderColor=#ff0000, $borderStyle=DashedLine(), $borderThickness=4, $shadowing=false, $shape=EightSidedShape(), $legendText=this is a apple) System_Boundary(MySoftwareSystem, My Software System, $tags="System Style+Boundary Style") Container(MySoftwareSystem.MyContainer, "My Container", "", "container", "", $tags="Container Style+Boundary Style") Boundary_End() Person(Person, "Person", "", "", $tags="Person Style") -Rel(Person, MySoftwareSystem.MyContainer, "1 uses" ) +Rel(Person, MySoftwareSystem.MyContainer, "1 uses" , $tags="Dependency Style") SHOW_LEGEND(true) diff --git a/src/test/resources/expected/view/style/DynamicStyleTest.puml b/src/test/resources/expected/view/style/DynamicStyleTest.puml index ef43a34..cf49c7d 100644 --- a/src/test/resources/expected/view/style/DynamicStyleTest.puml +++ b/src/test/resources/expected/view/style/DynamicStyleTest.puml @@ -1,5 +1,7 @@ @startuml(id=DynamicStyleTest) !includeurl https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Dynamic.puml +!includeurl https://raw.githubusercontent.com/plantuml-stdlib/gilbarbara-plantuml-sprites/master/sprites/android-icon.puml +!includeurl https://raw.githubusercontent.com/plantuml-stdlib/gilbarbara-plantuml-sprites/master/sprites/apple.puml !includeurl https://raw.githubusercontent.com/plantuml-stdlib/gilbarbara-plantuml-sprites/master/sprites/postgresql.puml title My Software System - Dynamic caption DynamicStyleTest @@ -7,14 +9,15 @@ caption DynamicStyleTest SHOW_PERSON_OUTLINE() LAYOUT_TOP_DOWN() +AddRelTag(Dependency Style, $sprite="android-icon{scale=1.3,color=#008000}", $lineColor=#008000, $textColor=#aa9999, $techn=Android, $lineStyle=DottedLine(), $lineThickness=2, $legendSprite="android-icon{scale=0.3,color=#008000}", $legendText=Android user uses) AddElementTag(Container Style, $sprite="postgresql{scale=0.5,color=#008000}", $bgColor=#ffffff, $fontColor=#ff0000, $borderColor=#800080, $borderStyle=DottedLine(), $borderThickness=5, $shadowing=false, $shape=RoundedBoxShape(), $techn=REST, $legendSprite="&compass", $legendText=this is a legend container) AddBoundaryTag(Boundary Style, $bgColor=#00ffff, $fontColor=#008000, $borderColor=#ff0000, $borderStyle=DottedLine(), $borderThickness=4, $shadowing=false, $legendText=this is a system) -AddPersonTag(Person Style, $bgColor=#00ff00, $fontColor=#0000ff, $borderColor=#ff0000, $borderStyle=DashedLine(), $borderThickness=4, $shadowing=false, $shape=EightSidedShape(), $legendText=this is a person) +AddPersonTag(Person Style, $sprite="apple{scale=0.5,color=#008000}", $bgColor=#00ff00, $fontColor=#0000ff, $borderColor=#ff0000, $borderStyle=DashedLine(), $borderThickness=4, $shadowing=false, $shape=EightSidedShape(), $legendText=this is a apple) System_Boundary(MySoftwareSystem, My Software System, $tags="System Style+Boundary Style") { Container(MySoftwareSystem.MyContainer, "My Container", "", "container", "", $tags="Container Style+Boundary Style") } Person(Person, "Person", "", "", $tags="Person Style") -RelIndex(1,Person, MySoftwareSystem.MyContainer, "uses") +RelIndex(1,Person, MySoftwareSystem.MyContainer, "uses", $tags="Dependency Style") SHOW_LEGEND(true) diff --git a/src/test/resources/expected/view/style/SystemStyleTest.puml b/src/test/resources/expected/view/style/SystemStyleTest.puml index f4de72b..1cbc0d9 100644 --- a/src/test/resources/expected/view/style/SystemStyleTest.puml +++ b/src/test/resources/expected/view/style/SystemStyleTest.puml @@ -1,17 +1,20 @@ @startuml(id=SystemStyleTest) !includeurl https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Context.puml +!includeurl https://raw.githubusercontent.com/plantuml-stdlib/gilbarbara-plantuml-sprites/master/sprites/android-icon.puml +!includeurl https://raw.githubusercontent.com/plantuml-stdlib/gilbarbara-plantuml-sprites/master/sprites/apple.puml title My Software System - System Context caption SystemStyleTest SHOW_PERSON_OUTLINE() LAYOUT_TOP_DOWN() +AddRelTag(Dependency Style, $sprite="android-icon{scale=1.3,color=#008000}", $lineColor=#008000, $textColor=#aa9999, $techn=Android, $lineStyle=DottedLine(), $lineThickness=2, $legendSprite="android-icon{scale=0.3,color=#008000}", $legendText=Android user uses) AddElementTag(System Style, $sprite="img:https://plantuml.com/logo3.png{scale=0.4}", $bgColor=#000000, $fontColor=#ffff00, $borderColor=#008000, $borderStyle=DashedLine(), $borderThickness=4, $shadowing=true, $shape=EightSidedShape(), $techn=Kafka, $legendSprite="&compass{scale=3.0}", $legendText=this is a legend) -AddPersonTag(Person Style, $bgColor=#00ff00, $fontColor=#0000ff, $borderColor=#ff0000, $borderStyle=DashedLine(), $borderThickness=4, $shadowing=false, $shape=EightSidedShape(), $legendText=this is a person) +AddPersonTag(Person Style, $sprite="apple{scale=0.5,color=#008000}", $bgColor=#00ff00, $fontColor=#0000ff, $borderColor=#ff0000, $borderStyle=DashedLine(), $borderThickness=4, $shadowing=false, $shape=EightSidedShape(), $legendText=this is a apple) System(MySoftwareSystem, "My Software System", "system", "", $tags="System Style+Boundary Style") Person(Person, "Person", "", "", $tags="Person Style") -Rel(Person, MySoftwareSystem, "uses system") +Rel(Person, MySoftwareSystem, "uses system", $tags="Dependency Style") SHOW_LEGEND(true) diff --git a/src/test/resources/expected/view/style/ViewStyleTestWithStyle.puml b/src/test/resources/expected/view/style/ViewStyleTestWithStyle.puml index 51b1865..c614bde 100644 --- a/src/test/resources/expected/view/style/ViewStyleTestWithStyle.puml +++ b/src/test/resources/expected/view/style/ViewStyleTestWithStyle.puml @@ -1,5 +1,7 @@ @startuml(id=ViewStyleTestWithStyle) !includeurl https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml +!includeurl https://raw.githubusercontent.com/plantuml-stdlib/gilbarbara-plantuml-sprites/master/sprites/android-icon.puml +!includeurl https://raw.githubusercontent.com/plantuml-stdlib/gilbarbara-plantuml-sprites/master/sprites/apple.puml !includeurl https://raw.githubusercontent.com/plantuml-stdlib/gilbarbara-plantuml-sprites/master/sprites/postgresql.puml title My Software System - Containers caption ViewStyleTestWithStyle @@ -7,15 +9,16 @@ caption ViewStyleTestWithStyle SHOW_PERSON_OUTLINE() LAYOUT_TOP_DOWN() +AddRelTag(Dependency Style, $sprite="android-icon{scale=1.3,color=#008000}", $lineColor=#008000, $textColor=#aa9999, $techn=Android, $lineStyle=DottedLine(), $lineThickness=2, $legendSprite="android-icon{scale=0.3,color=#008000}", $legendText=Android user uses) AddElementTag(Container Style, $sprite="postgresql{scale=0.5,color=#008000}", $bgColor=#ffffff, $fontColor=#ff0000, $borderColor=#800080, $borderStyle=DottedLine(), $borderThickness=5, $shadowing=false, $shape=RoundedBoxShape(), $techn=REST, $legendSprite="&compass", $legendText=this is a container) AddBoundaryTag(Boundary Style, $bgColor=#00ffff, $fontColor=#008000, $borderColor=#ff0000, $borderStyle=DottedLine(), $borderThickness=4, $shadowing=false, $legendText=this is a system) -AddPersonTag(Person Style, $bgColor=#00ff00, $fontColor=#0000ff, $borderColor=#ff0000, $borderStyle=DashedLine(), $borderThickness=4, $shadowing=false, $shape=EightSidedShape(), $legendText=this is a person) +AddPersonTag(Person Style, $sprite="apple{scale=0.5,color=#008000}", $bgColor=#00ff00, $fontColor=#0000ff, $borderColor=#ff0000, $borderStyle=DashedLine(), $borderThickness=4, $shadowing=false, $shape=EightSidedShape(), $legendText=this is a apple) System_Boundary(MySoftwareSystem, My Software System, $tags="System Style+Boundary Style") { Container(MySoftwareSystem.MyContainer, "My Container", "", "container", "", $tags="Container Style+Boundary Style") } Person(Person, "Person", "", "", $tags="Person Style") -Rel(Person, MySoftwareSystem.MyContainer, "uses container") +Rel(Person, MySoftwareSystem.MyContainer, "uses container", $tags="Dependency Style") SHOW_LEGEND(true)