-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
414 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 21 additions & 2 deletions
23
src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/sprite/ImageSprite.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,25 @@ | ||
package com.github.chriskn.structurizrextension.api.view.style.sprite | ||
|
||
import java.net.URI | ||
|
||
private val fileInUriRegex = "[^/\\\\&?]+\\.\\w{3,4}(?=([?&].*\$|\$))".toRegex() | ||
|
||
data class ImageSprite( | ||
val url: String, | ||
override val scale: Double? = null, | ||
) : Sprite | ||
val scale: Double? = null, | ||
) : Sprite(scale) { | ||
|
||
init { | ||
validateImageUrl(url) | ||
} | ||
|
||
private fun validateImageUrl(urlString: String) { | ||
val uri = URI(urlString) | ||
val mathResult = fileInUriRegex.find(uri.schemeSpecificPart) | ||
val fileWithEnding = mathResult?.groupValues?.first() | ||
require(fileWithEnding?.contains(".") == true) { | ||
"Image URI must point to a file" | ||
} | ||
require(uri.scheme == "img") { "Image URI must use img scheme" } | ||
} | ||
} |
11 changes: 9 additions & 2 deletions
11
.../kotlin/com/github/chriskn/structurizrextension/api/view/style/sprite/OpenIconicSprite.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
package com.github.chriskn.structurizrextension.api.view.style.sprite | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore | ||
import com.github.chriskn.structurizrextension.api.view.style.toValidColor | ||
|
||
data class OpenIconicSprite( | ||
val name: String, | ||
val color: String? = null, | ||
override val scale: Double? = null, | ||
) : Sprite | ||
val scale: Double? = null, | ||
) : Sprite(scale) { | ||
|
||
@get:JsonIgnore | ||
internal val validatedColor: String? = color?.let { toValidColor(color) } | ||
} |
12 changes: 9 additions & 3 deletions
12
src/main/kotlin/com/github/chriskn/structurizrextension/api/view/style/sprite/PumlSprite.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
227 changes: 119 additions & 108 deletions
227
src/test/kotlin/com/github/chriskn/structurizrextension/view/sprite/SpriteTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,119 @@ | ||
// package com.github.chriskn.structurizrextension.view.sprite | ||
// | ||
// import com.github.chriskn.structurizrextension.api.view.style.createElementStyle | ||
// import com.github.chriskn.structurizrextension.api.view.style.sprite | ||
// import org.assertj.core.api.Assertions.assertThat | ||
// import org.junit.jupiter.api.Test | ||
// import org.junit.jupiter.api.assertThrows | ||
// | ||
// class SpriteTest { | ||
// | ||
// @Test | ||
// fun `sprite is serialized and deserialized correctly when URI with scale is used`() { | ||
// val expectedSprite = SpriteOld(URI.create("img:https://plantuml.com/logo.png"), 0.4) | ||
// val style = createElementStyle("test", sprite = expectedSprite) | ||
// | ||
// assertThat(style.sprite).isEqualTo(expectedSprite) | ||
// } | ||
// | ||
// @Test | ||
// fun `sprite is serialized and deserialized correctly when URI without scale is used`() { | ||
// val expectedSprite = SpriteOld(URI.create("img:https://plantuml.com/logo.png")) | ||
// val style = createElementStyle("test", sprite = expectedSprite) | ||
// | ||
// assertThat(style.sprite).isEqualTo(expectedSprite) | ||
// } | ||
// | ||
// @Test | ||
// fun `sprite is serialized and deserialized correctly when openIconicIcon with scale is used`() { | ||
// val expectedSprite = SpriteOld("folder", scale = 0.4) | ||
// val style = createElementStyle("test", sprite = expectedSprite) | ||
// | ||
// assertThat(style.sprite).isEqualTo(expectedSprite) | ||
// } | ||
// | ||
// @Test | ||
// fun `sprite is serialized and deserialized correctly when openIconicIcon with color is used`() { | ||
// val expectedSprite = SpriteOld("folder", color = "grey") | ||
// val style = createElementStyle("test", sprite = expectedSprite) | ||
// | ||
// assertThat(style.sprite).isEqualTo(expectedSprite) | ||
// } | ||
// | ||
// @Test | ||
// fun `sprite is serialized and deserialized correctly when openIconicIcon with scale and color is used`() { | ||
// val expectedSprite = SpriteOld("folder", color = "grey", scale = 0.1) | ||
// val style = createElementStyle("test", sprite = expectedSprite) | ||
// | ||
// assertThat(style.sprite).isEqualTo(expectedSprite) | ||
// } | ||
// | ||
// @Test | ||
// fun `sprite is serialized and deserialized correctly when openIconicIcon without scale and color is used`() { | ||
// val expectedSprite = SpriteOld("folder") | ||
// val style = createElementStyle("test", sprite = expectedSprite) | ||
// | ||
// assertThat(style.sprite).isEqualTo(expectedSprite) | ||
// } | ||
// | ||
// @Test | ||
// fun `IllegalArgumentException is thrown when uri without image schema is used`() { | ||
// assertThrows<IllegalArgumentException> { | ||
// SpriteOld(URI.create("https://plantuml.com/logo.png")) | ||
// } | ||
// } | ||
// | ||
// @Test | ||
// fun `IllegalArgumentException is thrown when uri with different schema is used`() { | ||
// assertThrows<IllegalArgumentException> { | ||
// SpriteOld(URI.create("file:https://plantuml.com/logo.png")) | ||
// } | ||
// } | ||
// | ||
// @Test | ||
// fun `IllegalArgumentException is thrown when uri is not absolute`() { | ||
// assertThrows<IllegalArgumentException> { | ||
// SpriteOld(URI.create("img:https://plantuml.com/")) | ||
// } | ||
// } | ||
// | ||
// @Test | ||
// fun `IllegalArgumentException is thrown if scale is negative `() { | ||
// assertThrows<IllegalArgumentException> { | ||
// SpriteOld(URI.create("img:https://plantuml.com//logo.png"), -0.1) | ||
// } | ||
// } | ||
// | ||
// @Test | ||
// fun `IllegalArgumentException is thrown if scale is zero `() { | ||
// assertThrows<IllegalArgumentException> { | ||
// SpriteOld(URI.create("img:https://plantuml.com//logo.png"), 0.0) | ||
// } | ||
// } | ||
// | ||
// @Test | ||
// fun `sprite is serialized and deserialized correctly when openIconicIcon is used`() { | ||
// val expectedSprite = SpriteOld("iconName", 0.4) | ||
// val style = createElementStyle("test", sprite = expectedSprite) | ||
// | ||
// assertThat(style.sprite).isEqualTo(expectedSprite) | ||
// } | ||
// | ||
// @Test | ||
// fun `IllegalArgumentException is thrown for invalid sprite color color`() { | ||
// assertThrows<IllegalArgumentException> { | ||
// SpriteOld("folder", color = "123") | ||
// } | ||
// } | ||
// } | ||
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 org.junit.jupiter.api.Nested | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
|
||
class SpriteTest { | ||
|
||
@Nested | ||
inner class ImageSpriteTest { | ||
|
||
@Test | ||
fun `IllegalArgumentException is thrown when uri does not point to file`() { | ||
assertThrows<IllegalArgumentException> { | ||
ImageSprite("https://plantuml.com/logo") | ||
} | ||
} | ||
|
||
@Test | ||
fun `IllegalArgumentException is thrown when uri without image schema is used`() { | ||
assertThrows<IllegalArgumentException> { | ||
ImageSprite("https://plantuml.com/logo.png") | ||
} | ||
} | ||
|
||
@Test | ||
fun `IllegalArgumentException is thrown when uri with different schema is used`() { | ||
assertThrows<IllegalArgumentException> { | ||
ImageSprite("file:https://plantuml.com/logo.png") | ||
} | ||
} | ||
|
||
@Test | ||
fun `IllegalArgumentException is thrown if scale is negative `() { | ||
assertThrows<IllegalArgumentException> { | ||
ImageSprite("img:https://plantuml.com/logo.png", -0.1) | ||
} | ||
} | ||
|
||
@Test | ||
fun `IllegalArgumentException is thrown if scale is zero `() { | ||
assertThrows<IllegalArgumentException> { | ||
ImageSprite("img:https://plantuml.com/logo.png", 0.0) | ||
} | ||
} | ||
} | ||
|
||
@Nested | ||
inner class OpenIconicSpriteTest { | ||
|
||
@Test | ||
fun `IllegalArgumentException is thrown for invalid OpenIconicSprite color`() { | ||
assertThrows<IllegalArgumentException> { | ||
OpenIconicSprite("folder", color = "123") | ||
} | ||
} | ||
} | ||
|
||
@Nested | ||
inner class PumlSpriteTest { | ||
|
||
@Test | ||
fun `IllegalArgumentException is thrown when name is blank`() { | ||
val url = IconRegistry.iconUrlFor("kafka")!! | ||
assertThrows<IllegalArgumentException> { | ||
PumlSprite(name = "", includeUrl = url) | ||
} | ||
} | ||
|
||
@Test | ||
fun `IllegalArgumentException is thrown when url is blank`() { | ||
assertThrows<IllegalArgumentException> { | ||
PumlSprite(name = " ", includeUrl = " ") | ||
} | ||
} | ||
|
||
@Test | ||
fun `IllegalArgumentException is thrown for invalid PumlSprite color`() { | ||
val name = IconRegistry.iconFileNameFor("kafka")!! | ||
val url = IconRegistry.iconUrlFor("kafka")!! | ||
|
||
assertThrows<IllegalArgumentException> { | ||
PumlSprite(name = name, includeUrl = url, color = "123") | ||
} | ||
} | ||
|
||
@Test | ||
fun `IllegalArgumentException is thrown when url does not point to a puml file`() { | ||
assertThrows<IllegalArgumentException> { | ||
PumlSprite("test", "https://plantuml.com/logo.png") | ||
} | ||
} | ||
|
||
@Test | ||
fun `IllegalArgumentException is thrown when url is invalid`() { | ||
assertThrows<IllegalArgumentException> { | ||
PumlSprite("test", "plantuml.com/logo.png") | ||
} | ||
} | ||
|
||
@Test | ||
fun `IllegalArgumentException is thrown if scale is negative `() { | ||
assertThrows<IllegalArgumentException> { | ||
PumlSprite("test", "https://plantuml.com/logo.puml", scale = -0.1) | ||
} | ||
} | ||
|
||
@Test | ||
fun `IllegalArgumentException is thrown if scale is zero `() { | ||
assertThrows<IllegalArgumentException> { | ||
PumlSprite("test", "https://plantuml.com/logo.puml", scale = 0.0) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.