diff --git a/structurizr-onpremises/build.gradle b/structurizr-onpremises/build.gradle index 29f6b5a..7e822a2 100644 --- a/structurizr-onpremises/build.gradle +++ b/structurizr-onpremises/build.gradle @@ -45,9 +45,9 @@ dependencies { implementation project(':structurizr-onpremises-plugin') - implementation 'com.structurizr:structurizr-dsl:2.0.0' - implementation 'com.structurizr:structurizr-inspection:2.0.0' - implementation 'com.structurizr:structurizr-autolayout:2.0.0' + implementation 'com.structurizr:structurizr-dsl:2.1.0' + implementation 'com.structurizr:structurizr-inspection:2.1.0' + implementation 'com.structurizr:structurizr-autolayout:2.1.0' compileOnly 'jakarta.servlet:jakarta.servlet-api:6.0.0' implementation 'jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api:3.0.0' diff --git a/structurizr-onpremises/src/integrationTest/java/com/structurizr/onpremises/component/workspace/WorkspaceComponentTests.java b/structurizr-onpremises/src/integrationTest/java/com/structurizr/onpremises/component/workspace/WorkspaceComponentTests.java index e0c81ae..b352e54 100644 --- a/structurizr-onpremises/src/integrationTest/java/com/structurizr/onpremises/component/workspace/WorkspaceComponentTests.java +++ b/structurizr-onpremises/src/integrationTest/java/com/structurizr/onpremises/component/workspace/WorkspaceComponentTests.java @@ -49,7 +49,8 @@ public void test() throws Exception { assertEquals(1, workspaceId); WorkspaceMetaData workspaceMetaData = workspaceComponent.getWorkspaceMetaData(1); - String jsonV1 = String.format("{\"id\":1,\"name\":\"Workspace 0001\",\"description\":\"Description\",\"revision\":1,\"lastModifiedDate\":\"%s\",\"configuration\":{},\"model\":{},\"documentation\":{},\"views\":{\"configuration\":{\"branding\":{},\"styles\":{},\"terminology\":{}}}}", DateUtils.formatIsoDate(workspaceMetaData.getLastModifiedDate())); + String jsonV1 = String.format(""" + {"configuration":{},"description":"Description","documentation":{},"id":1,"lastModifiedDate":"%s","model":{},"name":"Workspace 0001","revision":1,"views":{"configuration":{"branding":{},"styles":{},"terminology":{}}}}""", DateUtils.formatIsoDate(workspaceMetaData.getLastModifiedDate())); assertEquals(jsonV1, workspaceComponent.getWorkspace(1, "")); Collection workspaces = workspaceComponent.getWorkspaces(); @@ -69,7 +70,8 @@ public void test() throws Exception { workspaceComponent.putWorkspace(1, json); workspaceMetaData = workspaceComponent.getWorkspaceMetaData(1); - String jsonV2 = String.format("{\"id\":1,\"name\":\"Financial Risk System\",\"description\":\"...\",\"revision\":2,\"lastModifiedDate\":\"%s\",\"configuration\":{},\"model\":{},\"documentation\":{},\"views\":{\"configuration\":{\"branding\":{},\"styles\":{},\"terminology\":{}}}}", DateUtils.formatIsoDate(workspaceMetaData.getLastModifiedDate())); + String jsonV2 = String.format(""" + {"configuration":{},"description":"...","documentation":{},"id":1,"lastModifiedDate":"%s","model":{},"name":"Financial Risk System","revision":2,"views":{"configuration":{"branding":{},"styles":{},"terminology":{}}}}""", DateUtils.formatIsoDate(workspaceMetaData.getLastModifiedDate())); assertEquals(jsonV2, workspaceComponent.getWorkspace(1, "")); workspaceVersions = workspaceComponent.getWorkspaceVersions(1, 10); diff --git a/structurizr-onpremises/src/test/java/com/structurizr/onpremises/component/workspace/WorkspaceComponentImplTests.java b/structurizr-onpremises/src/test/java/com/structurizr/onpremises/component/workspace/WorkspaceComponentImplTests.java index 1d3029b..63ebcd1 100644 --- a/structurizr-onpremises/src/test/java/com/structurizr/onpremises/component/workspace/WorkspaceComponentImplTests.java +++ b/structurizr-onpremises/src/test/java/com/structurizr/onpremises/component/workspace/WorkspaceComponentImplTests.java @@ -184,7 +184,8 @@ public void putWorkspace(WorkspaceMetaData workspaceMetaData, String json) { long workspaceId = workspaceComponent.createWorkspace(null); assertEquals(1, workspaceId); - assertEquals(String.format("{\"id\":1,\"name\":\"Workspace 0001\",\"description\":\"Description\",\"revision\":1,\"lastModifiedDate\":\"%s\",\"configuration\":{},\"model\":{},\"documentation\":{},\"views\":{\"configuration\":{\"branding\":{},\"styles\":{},\"terminology\":{}}}}", DateUtils.formatIsoDate(workspaceMetaData.getLastModifiedDate())), jsonBuffer.toString()); + assertEquals(String.format(""" + {"configuration":{},"description":"Description","documentation":{},"id":1,"lastModifiedDate":"%s","model":{},"name":"Workspace 0001","revision":1,"views":{"configuration":{"branding":{},"styles":{},"terminology":{}}}}""", DateUtils.formatIsoDate(workspaceMetaData.getLastModifiedDate())), jsonBuffer.toString()); } @Test @@ -263,7 +264,8 @@ public String getWorkspace(long workspaceId, String version) { WorkspaceComponent workspaceComponent = new WorkspaceComponentImpl(dao, "password"); String json = workspaceComponent.getWorkspace(1, ""); - assertEquals("{\"id\":1,\"name\":\"Name\",\"description\":\"Description\",\"configuration\":{},\"model\":{},\"documentation\":{},\"views\":{\"configuration\":{\"branding\":{},\"styles\":{},\"terminology\":{}}}}", json); + assertEquals(""" + {"configuration":{},"description":"Description","documentation":{},"id":1,"model":{},"name":"Name","views":{"configuration":{"branding":{},"styles":{},"terminology":{}}}}""", json); } @Test @@ -312,15 +314,18 @@ public void putWorkspace(WorkspaceMetaData workspaceMetaData, String json) { } }; + String expectedJson = """ + {"configuration":{},"description":"Description","documentation":{},"id":1,"lastModifiedDate":"%s","model":{},"name":"Name","revision":%s,"views":{"configuration":{"branding":{},"styles":{},"terminology":{}}}}"""; + WorkspaceComponent workspaceComponent = new WorkspaceComponentImpl(dao, ""); workspaceComponent.putWorkspace(1, json); - assertEquals(String.format("{\"id\":1,\"name\":\"Name\",\"description\":\"Description\",\"revision\":1,\"lastModifiedDate\":\"%s\",\"configuration\":{},\"model\":{},\"documentation\":{},\"views\":{\"configuration\":{\"branding\":{},\"styles\":{},\"terminology\":{}}}}", DateUtils.formatIsoDate(workspaceMetaData.getLastModifiedDate())), jsonBuffer.toString()); + assertEquals(String.format(expectedJson, DateUtils.formatIsoDate(workspaceMetaData.getLastModifiedDate()), "1"), jsonBuffer.toString()); // and again, to increment the revision json = jsonBuffer.toString(); jsonBuffer.setLength(0); workspaceComponent.putWorkspace(1, json); - assertEquals(String.format("{\"id\":1,\"name\":\"Name\",\"description\":\"Description\",\"revision\":2,\"lastModifiedDate\":\"%s\",\"configuration\":{},\"model\":{},\"documentation\":{},\"views\":{\"configuration\":{\"branding\":{},\"styles\":{},\"terminology\":{}}}}", DateUtils.formatIsoDate(workspaceMetaData.getLastModifiedDate())), jsonBuffer.toString()); + assertEquals(String.format(expectedJson, DateUtils.formatIsoDate(workspaceMetaData.getLastModifiedDate()), "2"), jsonBuffer.toString()); } @Test @@ -344,14 +349,17 @@ public void putWorkspace(WorkspaceMetaData workspaceMetaData, String json) { WorkspaceComponent workspaceComponent = new WorkspaceComponentImpl(dao, "password"); workspaceComponent.putWorkspace(1, json); - assertTrue(jsonBuffer.toString().startsWith(String.format("{\"id\":1,\"name\":\"Name\",\"description\":\"Description\",\"revision\":1,\"lastModifiedDate\":\"%s\",\"configuration\":{},\"ciphertext\"", DateUtils.formatIsoDate(workspaceMetaData.getLastModifiedDate())))); + String pattern = """ + "id":1,"lastModifiedDate":"%s","name":"Name","revision":%s}"""; + assertTrue(jsonBuffer.toString().startsWith("{\"ciphertext\":\"")); + assertTrue(jsonBuffer.toString().endsWith(String.format(pattern, DateUtils.formatIsoDate(workspaceMetaData.getLastModifiedDate()), "1"))); // and again, to increment the revision json = jsonBuffer.toString(); jsonBuffer.setLength(0); workspaceComponent.putWorkspace(1, json); - System.out.println(jsonBuffer); - assertTrue(jsonBuffer.toString().startsWith(String.format("{\"id\":1,\"name\":\"Name\",\"description\":\"Description\",\"revision\":2,\"lastModifiedDate\":\"%s\",\"configuration\":{},\"ciphertext\"", DateUtils.formatIsoDate(workspaceMetaData.getLastModifiedDate())))); + assertTrue(jsonBuffer.toString().startsWith("{\"ciphertext\":\"")); + assertTrue(jsonBuffer.toString().endsWith(String.format(pattern, DateUtils.formatIsoDate(workspaceMetaData.getLastModifiedDate()), "2"))); } @Test @@ -380,15 +388,17 @@ public void putWorkspace(WorkspaceMetaData workspaceMetaData, String json) { WorkspaceComponent workspaceComponent = new WorkspaceComponentImpl(dao, ""); workspaceComponent.putWorkspace(1, json); - assertTrue(jsonBuffer.toString().startsWith(String.format("{\"id\":1,\"name\":\"Name\",\"description\":\"Description\",\"revision\":1,\"lastModifiedDate\":\"%s\",\"configuration\":{},\"ciphertext\"", DateUtils.formatIsoDate(workspaceMetaData.getLastModifiedDate())))); - assertTrue(jsonBuffer.toString().endsWith((json.substring(json.indexOf("ciphertext"))))); + String pattern = """ + "id":1,"lastModifiedDate":"%s","name":"Name","revision":%s}"""; + assertTrue(jsonBuffer.toString().startsWith("{\"ciphertext\":\"")); + assertTrue(jsonBuffer.toString().endsWith(String.format(pattern, DateUtils.formatIsoDate(workspaceMetaData.getLastModifiedDate()), "1"))); // and again, to increment the revision json = jsonBuffer.toString(); jsonBuffer.setLength(0); workspaceComponent.putWorkspace(1, json); - assertTrue(jsonBuffer.toString().startsWith(String.format("{\"id\":1,\"name\":\"Name\",\"description\":\"Description\",\"revision\":2,\"lastModifiedDate\":\"%s\",\"configuration\":{},\"ciphertext\"", DateUtils.formatIsoDate(workspaceMetaData.getLastModifiedDate())))); - assertTrue(jsonBuffer.toString().endsWith((json.substring(json.indexOf("ciphertext"))))); + assertTrue(jsonBuffer.toString().startsWith("{\"ciphertext\":\"")); + assertTrue(jsonBuffer.toString().endsWith(String.format(pattern, DateUtils.formatIsoDate(workspaceMetaData.getLastModifiedDate()), "2"))); } @Test diff --git a/structurizr-onpremises/src/test/java/com/structurizr/onpremises/web/api/ApiControllerTests.java b/structurizr-onpremises/src/test/java/com/structurizr/onpremises/web/api/ApiControllerTests.java index c1d4c0f..4a33c2f 100644 --- a/structurizr-onpremises/src/test/java/com/structurizr/onpremises/web/api/ApiControllerTests.java +++ b/structurizr-onpremises/src/test/java/com/structurizr/onpremises/web/api/ApiControllerTests.java @@ -219,7 +219,7 @@ public WorkspaceMetaData getWorkspaceMetaData(long workspaceId) { Workspace workspace = new Workspace("Name", "Description"); String json = WorkspaceUtils.toJson(workspace, false); - request.addHeader(HttpHeaders.AUTHORIZATION, "key:ZDc3MTcxNGJjYmZhNjM4NmE4ODk0MmQ5OGQ1MmIwYzUyMjk3ODVmMDZiNjI1YWFiZTdlMjZmZmYyNmFmN2QzNw=="); + request.addHeader(HttpHeaders.AUTHORIZATION, "key:YjUxOTBkNjg5NjI5MjRiMzZjNWQwZmEwYjE3ZmI4OWFmNjY4NmY3MjEzZWRkNGE5ZjJmZTFjMDhjZmU0OGNlZg=="); request.addHeader(HttpHeaders.NONCE, "1234567890"); request.addHeader(HttpHeaders.CONTENT_MD5, Base64.getEncoder().encodeToString(new Md5Digest().generate(json).getBytes())); diff --git a/structurizr-onpremises/src/test/java/com/structurizr/onpremises/web/workspace/JsonControllerTests.java b/structurizr-onpremises/src/test/java/com/structurizr/onpremises/web/workspace/JsonControllerTests.java index 5cf9b9c..40b1aa1 100644 --- a/structurizr-onpremises/src/test/java/com/structurizr/onpremises/web/workspace/JsonControllerTests.java +++ b/structurizr-onpremises/src/test/java/com/structurizr/onpremises/web/workspace/JsonControllerTests.java @@ -86,7 +86,7 @@ public String getWorkspace(long workspaceId, String version) throws WorkspaceCom String view = controller.showPublicJson(1, "version", model); assertEquals("json", view); assertEquals(""" - {"id":0,"name":"Name","description":"Description","configuration":{},"model":{},"documentation":{},"views":{"configuration":{"branding":{},"styles":{},"terminology":{}}}}""", model.getAttribute("json")); + {"configuration":{},"description":"Description","documentation":{},"id":0,"model":{},"name":"Name","views":{"configuration":{"branding":{},"styles":{},"terminology":{}}}}""", model.getAttribute("json")); } @Test @@ -160,7 +160,7 @@ public String getWorkspace(long workspaceId, String version) throws WorkspaceCom String view = controller.showSharedJson(1, "version", "token", model); assertEquals("json", view); assertEquals(""" - {"id":0,"name":"Name","description":"Description","configuration":{},"model":{},"documentation":{},"views":{"configuration":{"branding":{},"styles":{},"terminology":{}}}}""", model.getAttribute("json")); + {"configuration":{},"description":"Description","documentation":{},"id":0,"model":{},"name":"Name","views":{"configuration":{"branding":{},"styles":{},"terminology":{}}}}""", model.getAttribute("json")); } } \ No newline at end of file