From c64e1a06d26c0dfa5d00744bd8cf9bc2aa8a8d4b Mon Sep 17 00:00:00 2001 From: klu2 <172195+klu2@users.noreply.github.com> Date: Sun, 4 Aug 2024 10:45:50 +0200 Subject: [PATCH] #236 return default value Unspecified for the C4Location --- .../api/model/LocationExtension.kt | 6 +-- .../view/StructurizrCompatibilityTest.kt | 48 +++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 src/test/kotlin/com/github/chriskn/structurizrextension/view/StructurizrCompatibilityTest.kt diff --git a/src/main/kotlin/com/github/chriskn/structurizrextension/api/model/LocationExtension.kt b/src/main/kotlin/com/github/chriskn/structurizrextension/api/model/LocationExtension.kt index 03319ea..f35634b 100644 --- a/src/main/kotlin/com/github/chriskn/structurizrextension/api/model/LocationExtension.kt +++ b/src/main/kotlin/com/github/chriskn/structurizrextension/api/model/LocationExtension.kt @@ -11,7 +11,7 @@ var SoftwareSystem.c4Location: Location /** * Returns the [Location] of the SoftwareSystem. */ - get() = Location.valueOf(this.properties.getValue(LOCATION_PROPERTY)) + get() = Location.valueOf(this.properties.getOrDefault(LOCATION_PROPERTY, Location.Unspecified.name)) /** * Sets the [Location] of the SoftwareSystem. @@ -24,7 +24,7 @@ var Container.c4Location: Location /** * Returns the [Location] of the container. */ - get() = Location.valueOf(this.properties.getValue(LOCATION_PROPERTY)) + get() = Location.valueOf(this.properties.getOrDefault(LOCATION_PROPERTY, Location.Unspecified.name)) /** * Sets the [Location] of the container. @@ -37,7 +37,7 @@ var Person.c4Location: Location /** * Returns the [Location] of the Component. */ - get() = Location.valueOf(this.properties.getValue(LOCATION_PROPERTY)) + get() = Location.valueOf(this.properties.getOrDefault(LOCATION_PROPERTY, Location.Unspecified.name)) /** * Sets the [Location] of the Component. diff --git a/src/test/kotlin/com/github/chriskn/structurizrextension/view/StructurizrCompatibilityTest.kt b/src/test/kotlin/com/github/chriskn/structurizrextension/view/StructurizrCompatibilityTest.kt new file mode 100644 index 0000000..e6d0c3a --- /dev/null +++ b/src/test/kotlin/com/github/chriskn/structurizrextension/view/StructurizrCompatibilityTest.kt @@ -0,0 +1,48 @@ +package com.github.chriskn.structurizrextension.view + +import com.github.chriskn.structurizrextension.api.writeDiagrams +import com.structurizr.Workspace +import com.structurizr.model.Model +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import java.io.File + +/** + * Tests the combination of models created directly from Structurizr and models created with the extension. This + * is especially required as the Location has been removed from the Structurizr API and is now part of the extension. + * + * @see https://github.com/chriskn/structurizr-c4puml-extension/issues/236 + */ +class StructurizrCompatibilityTest { + + private lateinit var workspace: Workspace + private lateinit var model: Model + + @BeforeEach + fun setUp() { + workspace = Workspace("", "") + model = workspace.model + } + + @Test + fun `addPerson can be called directly on the Structurizr Methods`() { + model.addPerson("Person 1", "Description") + workspace.views.createSystemLandscapeView("SystemLandscape", "Description").addAllElements() + workspace.writeDiagrams(File("build/structurizr")) + } + + @Test + fun `addSoftwareSystem can be called directly on the Structurizr Methods`() { + model.addSoftwareSystem("Software System") + workspace.views.createSystemLandscapeView("SystemLandscape", "Description").addAllElements() + workspace.writeDiagrams(File("build/structurizr")) + } + + @Test + fun `addContainer can be called directly on the Structurizr Methods`() { + val softwareSystem = model.addSoftwareSystem("Software System") + softwareSystem.addContainer("Container") + workspace.views.createContainerView(softwareSystem, "Container", "Container").addAllElements() + workspace.writeDiagrams(File("build/structurizr")) + } +} \ No newline at end of file