From 82a79d28ce649b496581c1348791cd76692a938b Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Tue, 9 Jul 2024 09:06:53 +0200 Subject: [PATCH 01/37] =?UTF-8?q?fix:=20=C2=96add=20a=20check=20for=20/=20?= =?UTF-8?q?suffix=20for=20basyx=20external=20url=20in=20registry=20integra?= =?UTF-8?q?tion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../integration/AasDescriptorFactory.java | 11 +++++++- .../AasRepositoryRegistryTestLink.java | 26 ++++++++++++++++++- .../DummyAasDescriptorFactory.java | 11 +++++++- .../SubmodelDescriptorFactory.java | 11 +++++++- .../DummySubmodelDescriptorFactory.java | 11 +++++++- .../SubmodelRepositoryRegistryTestLink.java | 26 ++++++++++++++++++- 6 files changed, 90 insertions(+), 6 deletions(-) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java index fa26f48a2..22e7b78a5 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java @@ -195,7 +195,16 @@ private String getProtocol(String endpoint) { private String createAasRepositoryUrl(String aasRepositoryBaseURL) { try { - return new URL(new URL(aasRepositoryBaseURL), AAS_REPOSITORY_PATH).toString(); + URL url = new URL(aasRepositoryBaseURL); + String path = url.getPath(); + + if (path.endsWith("/")) { + path = path.substring(0, path.length() - 1); + } else { + path += "/"; + } + + return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + AAS_REPOSITORY_PATH).toString(); } catch (MalformedURLException e) { throw new RuntimeException("The AAS Repository Base url is malformed.\n" + e.getMessage()); } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLink.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLink.java index 1762f7bc0..6e2f5dcc5 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLink.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLink.java @@ -87,6 +87,21 @@ public void deleteAas() throws FileNotFoundException, IOException, ApiException assertDescriptionDeletionAtRegistry(); } + + @Test + public void testDummyAasDescriptorFactoryUrlWithTrailingSlash() { + String baseURLWithSlash = aasRepoBaseUrl + "/context/"; + String AAS_REPOSITORY_PATH_WITHOUT_SLASH = AAS_REPOSITORY_PATH.substring(1); + + assertEquals(baseURLWithSlash + AAS_REPOSITORY_PATH_WITHOUT_SLASH, createAasRepositoryUrl(baseURLWithSlash)); + } + + @Test + public void testDummyAasDescriptorFactoryUrlWithoutTrailingSlash() { + String baseURLWithoutSlash = aasRepoBaseUrl + "/context"; + + assertEquals(baseURLWithoutSlash + "/" + AAS_REPOSITORY_PATH , createAasRepositoryUrl(baseURLWithoutSlash)); + } private AssetAdministrationShellDescriptor retrieveDescriptorFromRegistry() throws ApiException { RegistryAndDiscoveryInterfaceApi api = new RegistryAndDiscoveryInterfaceApi(aasRegistryUrl); @@ -129,7 +144,16 @@ private String getSpecificAasAccessURL(String aasId) { private static String createAasRepositoryUrl(String aasRepositoryBaseURL) { try { - return new URL(new URL(aasRepositoryBaseURL), AAS_REPOSITORY_PATH).toString(); + URL url = new URL(aasRepositoryBaseURL); + String path = url.getPath(); + + if (path.endsWith("/")) { + path = path.substring(0, path.length() - 1); + } else { + path += "/"; + } + + return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + AAS_REPOSITORY_PATH).toString(); } catch (MalformedURLException e) { throw new RuntimeException("The AAS Repository Base url is malformed. " + e.getMessage()); } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java index 9a832d3c6..bca8a86bd 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java @@ -89,7 +89,16 @@ private static String getProtocol(String endpoint) { private static String createAasRepositoryUrl(String aasRepositoryBaseURL) { try { - return new URL(new URL(aasRepositoryBaseURL), AAS_REPOSITORY_PATH).toString(); + URL url = new URL(aasRepositoryBaseURL); + String path = url.getPath(); + + if (path.endsWith("/")) { + path = path.substring(0, path.length() - 1); + } else { + path += "/"; + } + + return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + AAS_REPOSITORY_PATH).toString(); } catch (MalformedURLException e) { throw new RuntimeException("The AAS Repository Base url is malformed. " + e.getMessage()); } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java index fc96f639e..ca6680898 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java @@ -185,7 +185,16 @@ private String getProtocol(String endpoint) { private String createSubmodelRepositoryUrl(String submodelRepositoryBaseURL) { try { - return new URL(new URL(submodelRepositoryBaseURL), SUBMODEL_REPOSITORY_PATH).toString(); + URL url = new URL(submodelRepositoryBaseURL); + String path = url.getPath(); + + if (path.endsWith("/")) { + path = path.substring(0, path.length() - 1); + } else { + path += "/"; + } + + return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); } catch (MalformedURLException e) { throw new RuntimeException("The Submodel Repository Base url is malformed.\n" + e.getMessage()); } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java index 4e821bc9b..14cf8f780 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java @@ -96,7 +96,16 @@ private static String getProtocol(String endpoint) { private static String createSubmodelRepositoryUrl(String smRepositoryBaseURL) { try { - return new URL(new URL(smRepositoryBaseURL), SUBMODEL_REPOSITORY_PATH).toString(); + URL url = new URL(smRepositoryBaseURL); + String path = url.getPath(); + + if (path.endsWith("/")) { + path = path.substring(0, path.length() - 1); + } else { + path += "/"; + } + + return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); } catch (MalformedURLException e) { throw new RuntimeException("The Submodel Repository Base url is malformed.\n " + e.getMessage()); } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java index e0db76372..995cef6b7 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java @@ -105,6 +105,21 @@ public void deleteSubmodel() throws FileNotFoundException, IOException, ApiExcep assertDescriptionDeletionAtRegistry(); } + @Test + public void testDummyAasDescriptorFactoryUrlWithTrailingSlash() { + String baseURLWithSlash = submodelRepoBaseUrl + "/context/"; + String SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH = SUBMODEL_REPOSITORY_PATH.substring(1); + + assertEquals(baseURLWithSlash + SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH, createSubmodelRepositoryUrl(baseURLWithSlash)); + } + + @Test + public void testDummyAasDescriptorFactoryUrlWithoutTrailingSlash() { + String baseURLWithoutSlash = submodelRepoBaseUrl + "/context"; + + assertEquals(baseURLWithoutSlash + SUBMODEL_REPOSITORY_PATH , createSubmodelRepositoryUrl(baseURLWithoutSlash)); + } + private SubmodelDescriptor retrieveDescriptorFromRegistry() throws ApiException { SubmodelRegistryApi api = new SubmodelRegistryApi(submodelRegistryUrl); @@ -160,7 +175,16 @@ private String getSpecificSubmodelAccessURL(String submodelId) { private static String createSubmodelRepositoryUrl(String smRepositoryBaseURL) { try { - return new URL(new URL(smRepositoryBaseURL), SUBMODEL_REPOSITORY_PATH).toString(); + URL url = new URL(smRepositoryBaseURL); + String path = url.getPath(); + + if (path.endsWith("/")) { + path = path.substring(0, path.length() - 1); + } else { + path += "/"; + } + + return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); } catch (MalformedURLException e) { throw new RuntimeException("The Submodel Repository Base url is malformed.\n " + e.getMessage()); } From 4a7a8aabe7354184ffd43ef45903a4e90eacce39 Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Tue, 9 Jul 2024 09:25:19 +0200 Subject: [PATCH 02/37] fix: submodal integration test --- .../AasRepositoryRegistryTestLink.java | 27 +++---------------- .../DummyAasDescriptorFactory.java | 2 +- .../DummySubmodelDescriptorFactory.java | 2 +- .../SubmodelRepositoryRegistryTestLink.java | 26 +++--------------- 4 files changed, 10 insertions(+), 47 deletions(-) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLink.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLink.java index 6e2f5dcc5..c981f503c 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLink.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLink.java @@ -93,14 +93,14 @@ public void testDummyAasDescriptorFactoryUrlWithTrailingSlash() { String baseURLWithSlash = aasRepoBaseUrl + "/context/"; String AAS_REPOSITORY_PATH_WITHOUT_SLASH = AAS_REPOSITORY_PATH.substring(1); - assertEquals(baseURLWithSlash + AAS_REPOSITORY_PATH_WITHOUT_SLASH, createAasRepositoryUrl(baseURLWithSlash)); + assertEquals(baseURLWithSlash + AAS_REPOSITORY_PATH_WITHOUT_SLASH, DummyAasDescriptorFactory.createAasRepositoryUrl(baseURLWithSlash)); } @Test public void testDummyAasDescriptorFactoryUrlWithoutTrailingSlash() { String baseURLWithoutSlash = aasRepoBaseUrl + "/context"; - assertEquals(baseURLWithoutSlash + "/" + AAS_REPOSITORY_PATH , createAasRepositoryUrl(baseURLWithoutSlash)); + assertEquals(baseURLWithoutSlash + "/" + AAS_REPOSITORY_PATH , DummyAasDescriptorFactory.createAasRepositoryUrl(baseURLWithoutSlash)); } private AssetAdministrationShellDescriptor retrieveDescriptorFromRegistry() throws ApiException { @@ -134,29 +134,10 @@ private String getAas1JSONString() throws FileNotFoundException, IOException { } private CloseableHttpResponse createAasOnRepo(String aasJsonContent) throws IOException { - return BaSyxHttpTestUtils.executePostOnURL(createAasRepositoryUrl(aasRepoBaseUrl), aasJsonContent); + return BaSyxHttpTestUtils.executePostOnURL(DummyAasDescriptorFactory.createAasRepositoryUrl(aasRepoBaseUrl), aasJsonContent); } private String getSpecificAasAccessURL(String aasId) { - return createAasRepositoryUrl(aasRepoBaseUrl) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(aasId); + return DummyAasDescriptorFactory.createAasRepositoryUrl(aasRepoBaseUrl) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(aasId); } - - private static String createAasRepositoryUrl(String aasRepositoryBaseURL) { - - try { - URL url = new URL(aasRepositoryBaseURL); - String path = url.getPath(); - - if (path.endsWith("/")) { - path = path.substring(0, path.length() - 1); - } else { - path += "/"; - } - - return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + AAS_REPOSITORY_PATH).toString(); - } catch (MalformedURLException e) { - throw new RuntimeException("The AAS Repository Base url is malformed. " + e.getMessage()); - } - } - } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java index bca8a86bd..c3586327b 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java @@ -86,7 +86,7 @@ private static String getProtocol(String endpoint) { } } - private static String createAasRepositoryUrl(String aasRepositoryBaseURL) { + static String createAasRepositoryUrl(String aasRepositoryBaseURL) { try { URL url = new URL(aasRepositoryBaseURL); diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java index 14cf8f780..bbcd8d284 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java @@ -93,7 +93,7 @@ private static String getProtocol(String endpoint) { } } - private static String createSubmodelRepositoryUrl(String smRepositoryBaseURL) { + static String createSubmodelRepositoryUrl(String smRepositoryBaseURL) { try { URL url = new URL(smRepositoryBaseURL); diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java index 995cef6b7..742d923d7 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java @@ -110,14 +110,14 @@ public void testDummyAasDescriptorFactoryUrlWithTrailingSlash() { String baseURLWithSlash = submodelRepoBaseUrl + "/context/"; String SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH = SUBMODEL_REPOSITORY_PATH.substring(1); - assertEquals(baseURLWithSlash + SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH, createSubmodelRepositoryUrl(baseURLWithSlash)); + assertEquals(baseURLWithSlash + SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH, DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithSlash)); } @Test public void testDummyAasDescriptorFactoryUrlWithoutTrailingSlash() { String baseURLWithoutSlash = submodelRepoBaseUrl + "/context"; - assertEquals(baseURLWithoutSlash + SUBMODEL_REPOSITORY_PATH , createSubmodelRepositoryUrl(baseURLWithoutSlash)); + assertEquals(baseURLWithoutSlash + "/" + SUBMODEL_REPOSITORY_PATH , DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithoutSlash)); } private SubmodelDescriptor retrieveDescriptorFromRegistry() throws ApiException { @@ -159,7 +159,7 @@ private String getExpectedSubmodel() throws FileNotFoundException, IOException { } private CloseableHttpResponse createSubmodelOnRepo(String submodelJsonContent) throws IOException { - return BaSyxHttpTestUtils.executePostOnURL(createSubmodelRepositoryUrl(submodelRepoBaseUrl), submodelJsonContent); + return BaSyxHttpTestUtils.executePostOnURL(DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(submodelRepoBaseUrl), submodelJsonContent); } private CloseableHttpResponse createSubmodelElementOnRepo(String submodelElementJsonContent) throws IOException { @@ -169,25 +169,7 @@ private CloseableHttpResponse createSubmodelElementOnRepo(String submodelElement } private String getSpecificSubmodelAccessURL(String submodelId) { - return createSubmodelRepositoryUrl(submodelRepoBaseUrl) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId); - } - - private static String createSubmodelRepositoryUrl(String smRepositoryBaseURL) { - - try { - URL url = new URL(smRepositoryBaseURL); - String path = url.getPath(); - - if (path.endsWith("/")) { - path = path.substring(0, path.length() - 1); - } else { - path += "/"; - } - - return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); - } catch (MalformedURLException e) { - throw new RuntimeException("The Submodel Repository Base url is malformed.\n " + e.getMessage()); - } + return DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(submodelRepoBaseUrl) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId); } } From 62d44d17fe47478f43166edb2629b16dc8058826 Mon Sep 17 00:00:00 2001 From: Mateus Molina Date: Tue, 9 Jul 2024 09:34:01 +0200 Subject: [PATCH 03/37] Empty commit for the CI to run --- .../feature/registry/integration/SubmodelDescriptorFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java index ca6680898..a525107e4 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java @@ -194,7 +194,7 @@ private String createSubmodelRepositoryUrl(String submodelRepositoryBaseURL) { path += "/"; } - return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); + return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); } catch (MalformedURLException e) { throw new RuntimeException("The Submodel Repository Base url is malformed.\n" + e.getMessage()); } From 13868a97698ab880094d6f9d5d0f6421d3a8233f Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Tue, 9 Jul 2024 13:35:00 +0200 Subject: [PATCH 04/37] fix: registry integration create url logic --- .../feature/registry/integration/AasDescriptorFactory.java | 2 -- .../registry/integration/AasRepositoryRegistryTestLink.java | 2 +- .../feature/registry/integration/DummyAasDescriptorFactory.java | 2 -- .../feature/registry/integration/SubmodelDescriptorFactory.java | 2 -- .../registry/integration/DummySubmodelDescriptorFactory.java | 2 -- .../integration/SubmodelRepositoryRegistryTestLink.java | 2 +- 6 files changed, 2 insertions(+), 10 deletions(-) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java index 22e7b78a5..9571b926d 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java @@ -200,8 +200,6 @@ private String createAasRepositoryUrl(String aasRepositoryBaseURL) { if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); - } else { - path += "/"; } return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + AAS_REPOSITORY_PATH).toString(); diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLink.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLink.java index c981f503c..625136831 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLink.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryTestLink.java @@ -100,7 +100,7 @@ public void testDummyAasDescriptorFactoryUrlWithTrailingSlash() { public void testDummyAasDescriptorFactoryUrlWithoutTrailingSlash() { String baseURLWithoutSlash = aasRepoBaseUrl + "/context"; - assertEquals(baseURLWithoutSlash + "/" + AAS_REPOSITORY_PATH , DummyAasDescriptorFactory.createAasRepositoryUrl(baseURLWithoutSlash)); + assertEquals(baseURLWithoutSlash + AAS_REPOSITORY_PATH , DummyAasDescriptorFactory.createAasRepositoryUrl(baseURLWithoutSlash)); } private AssetAdministrationShellDescriptor retrieveDescriptorFromRegistry() throws ApiException { diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java index c3586327b..8d437b162 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java @@ -94,8 +94,6 @@ static String createAasRepositoryUrl(String aasRepositoryBaseURL) { if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); - } else { - path += "/"; } return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + AAS_REPOSITORY_PATH).toString(); diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java index ca6680898..203f4fb28 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java @@ -190,8 +190,6 @@ private String createSubmodelRepositoryUrl(String submodelRepositoryBaseURL) { if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); - } else { - path += "/"; } return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java index bbcd8d284..a2118b1a4 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java @@ -101,8 +101,6 @@ static String createSubmodelRepositoryUrl(String smRepositoryBaseURL) { if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); - } else { - path += "/"; } return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java index 742d923d7..f590c281a 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryTestLink.java @@ -117,7 +117,7 @@ public void testDummyAasDescriptorFactoryUrlWithTrailingSlash() { public void testDummyAasDescriptorFactoryUrlWithoutTrailingSlash() { String baseURLWithoutSlash = submodelRepoBaseUrl + "/context"; - assertEquals(baseURLWithoutSlash + "/" + SUBMODEL_REPOSITORY_PATH , DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithoutSlash)); + assertEquals(baseURLWithoutSlash + SUBMODEL_REPOSITORY_PATH , DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithoutSlash)); } private SubmodelDescriptor retrieveDescriptorFromRegistry() throws ApiException { From bb3e3e9ba3bf7b3ec83893de13114248d80225bd Mon Sep 17 00:00:00 2001 From: Mateus Molina Date: Tue, 9 Jul 2024 14:49:09 +0200 Subject: [PATCH 05/37] Empty commit for the CI to run --- .../feature/registry/integration/SubmodelDescriptorFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java index 166d279dd..203f4fb28 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java @@ -192,7 +192,7 @@ private String createSubmodelRepositoryUrl(String submodelRepositoryBaseURL) { path = path.substring(0, path.length() - 1); } - return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); + return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); } catch (MalformedURLException e) { throw new RuntimeException("The Submodel Repository Base url is malformed.\n" + e.getMessage()); } From 9bdb684ef595bc41c29e84459239da0d67ead8bc Mon Sep 17 00:00:00 2001 From: Mateus Molina Date: Tue, 16 Jul 2024 09:45:01 +0200 Subject: [PATCH 06/37] Empty commit for the CI to run --- .../feature/registry/integration/SubmodelDescriptorFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java index 203f4fb28..166d279dd 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java @@ -192,7 +192,7 @@ private String createSubmodelRepositoryUrl(String submodelRepositoryBaseURL) { path = path.substring(0, path.length() - 1); } - return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); + return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); } catch (MalformedURLException e) { throw new RuntimeException("The Submodel Repository Base url is malformed.\n" + e.getMessage()); } From c410c6aa968ded4da1d47da41dfb975d2855edee Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Tue, 16 Jul 2024 10:09:07 +0200 Subject: [PATCH 07/37] fix: feature-registry-integration createURL remove static reference in tests --- .../AasRepositoryRegistryLinkTestSuite.java | 24 +++++++++++++++---- ...bmodelRepositoryRegistryLinkTestSuite.java | 23 ++++++++++++++---- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java index 0ac043f57..9695877f6 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java @@ -94,14 +94,14 @@ public void testDummyAasDescriptorFactoryUrlWithTrailingSlash() { String baseURLWithSlash = getAasRepoBaseUrl() + "/context/"; String AAS_REPOSITORY_PATH_WITHOUT_SLASH = AAS_REPOSITORY_PATH.substring(1); - assertEquals(baseURLWithSlash + AAS_REPOSITORY_PATH_WITHOUT_SLASH, DummyAasDescriptorFactory.createAasRepositoryUrl(baseURLWithSlash)); + assertEquals(baseURLWithSlash + AAS_REPOSITORY_PATH_WITHOUT_SLASH, createAasRepositoryUrl(baseURLWithSlash)); } @Test public void testDummyAasDescriptorFactoryUrlWithoutTrailingSlash() { String baseURLWithoutSlash = getAasRepoBaseUrl() + "/context"; - assertEquals(baseURLWithoutSlash + AAS_REPOSITORY_PATH , DummyAasDescriptorFactory.createAasRepositoryUrl(baseURLWithoutSlash)); + assertEquals(baseURLWithoutSlash + AAS_REPOSITORY_PATH , createAasRepositoryUrl(baseURLWithoutSlash)); } private AssetAdministrationShellDescriptor retrieveDescriptorFromRegistry() throws ApiException { @@ -135,10 +135,26 @@ private String getAas1JSONString() throws FileNotFoundException, IOException { } private CloseableHttpResponse createAasOnRepo(String aasJsonContent) throws IOException { - return BaSyxHttpTestUtils.executePostOnURL(DummyAasDescriptorFactory.createAasRepositoryUrl(getAasRepoBaseUrl()), aasJsonContent); + return BaSyxHttpTestUtils.executePostOnURL(createAasRepositoryUrl(getAasRepoBaseUrl()), aasJsonContent); } private String getSpecificAasAccessURL(String aasId) { - return DummyAasDescriptorFactory.createAasRepositoryUrl(getAasRepoBaseUrl()) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(aasId); + return createAasRepositoryUrl(getAasRepoBaseUrl()) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(aasId); + } + + private String createAasRepositoryUrl(String aasRepositoryBaseURL) { + + try { + URL url = new URL(aasRepositoryBaseURL); + String path = url.getPath(); + + if (path.endsWith("/")) { + path = path.substring(0, path.length() - 1); + } + + return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + AAS_REPOSITORY_PATH).toString(); + } catch (MalformedURLException e) { + throw new RuntimeException("The AAS Repository Base url is malformed. " + e.getMessage()); + } } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkTestSuite.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkTestSuite.java index cf1e0accf..0f37fc54e 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkTestSuite.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkTestSuite.java @@ -111,14 +111,14 @@ public void testDummyAasDescriptorFactoryUrlWithTrailingSlash() { String baseURLWithSlash = getSubmodelRepoBaseUrl() + "/context/"; String SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH = SUBMODEL_REPOSITORY_PATH.substring(1); - assertEquals(baseURLWithSlash + SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH, DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithSlash)); + assertEquals(baseURLWithSlash + SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH, createSubmodelRepositoryUrl(baseURLWithSlash)); } @Test public void testDummyAasDescriptorFactoryUrlWithoutTrailingSlash() { String baseURLWithoutSlash = getSubmodelRepoBaseUrl() + "/context"; - assertEquals(baseURLWithoutSlash + SUBMODEL_REPOSITORY_PATH , DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithoutSlash)); + assertEquals(baseURLWithoutSlash + SUBMODEL_REPOSITORY_PATH , createSubmodelRepositoryUrl(baseURLWithoutSlash)); } private SubmodelDescriptor retrieveDescriptorFromRegistry() throws ApiException { @@ -160,7 +160,7 @@ private String getExpectedSubmodel() throws FileNotFoundException, IOException { } private CloseableHttpResponse createSubmodelOnRepo(String submodelJsonContent) throws IOException { - return BaSyxHttpTestUtils.executePostOnURL(DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(getSubmodelRepoBaseUrl()), submodelJsonContent); + return BaSyxHttpTestUtils.executePostOnURL(createSubmodelRepositoryUrl(getSubmodelRepoBaseUrl()), submodelJsonContent); } private CloseableHttpResponse createSubmodelElementOnRepo(String submodelElementJsonContent) throws IOException { @@ -170,7 +170,22 @@ private CloseableHttpResponse createSubmodelElementOnRepo(String submodelElement } private String getSpecificSubmodelAccessURL(String submodelId) { - return DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(getSubmodelRepoBaseUrl()) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId); + return createSubmodelRepositoryUrl(getSubmodelRepoBaseUrl()) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId); } + + private String createSubmodelRepositoryUrl(String smRepositoryBaseURL) { + + try { + URL url = new URL(smRepositoryBaseURL); + String path = url.getPath(); + if (path.endsWith("/")) { + path = path.substring(0, path.length() - 1); + } + + return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); + } catch (MalformedURLException e) { + throw new RuntimeException("The Submodel Repository Base url is malformed.\n " + e.getMessage()); + } + } } From dae87d71e7c4235b61b60374b5d4cef4366566cb Mon Sep 17 00:00:00 2001 From: Mateus Molina Date: Tue, 23 Jul 2024 08:41:57 +0200 Subject: [PATCH 08/37] Triggering the CI --- .../feature/registry/integration/SubmodelDescriptorFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java index 166d279dd..203f4fb28 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java @@ -192,7 +192,7 @@ private String createSubmodelRepositoryUrl(String submodelRepositoryBaseURL) { path = path.substring(0, path.length() - 1); } - return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); + return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); } catch (MalformedURLException e) { throw new RuntimeException("The Submodel Repository Base url is malformed.\n" + e.getMessage()); } From ba08cbdad688a43bf27ea10fb305abc3a37617ac Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Tue, 23 Jul 2024 12:14:55 +0200 Subject: [PATCH 09/37] fix: createUrl method issue with path without leading slash resolved --- .../integration/AasDescriptorFactory.java | 6 +- .../AasRepositoryRegistryLinkTestSuite.java | 38 +----------- .../AasRepositoryUrlTestSuite.java | 61 +++++++++++++++++++ .../DummyAasDescriptorFactory.java | 4 +- .../SubmodelDescriptorFactory.java | 4 +- .../DummySubmodelDescriptorFactory.java | 4 +- ...bmodelRepositoryRegistryLinkTestSuite.java | 40 +----------- .../SubmodelRepositoryUrlTestSuite.java | 59 ++++++++++++++++++ 8 files changed, 137 insertions(+), 79 deletions(-) create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryUrlTestSuite.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryUrlTestSuite.java diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java index 9571b926d..8a97d72c9 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java @@ -197,9 +197,11 @@ private String createAasRepositoryUrl(String aasRepositoryBaseURL) { try { URL url = new URL(aasRepositoryBaseURL); String path = url.getPath(); - - if (path.endsWith("/")) { + + if (path.endsWith("/") && AAS_REPOSITORY_PATH.startsWith("/")) { path = path.substring(0, path.length() - 1); + } else if (!path.endsWith("/") && !AAS_REPOSITORY_PATH.startsWith("/")) { + path += "/"; } return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + AAS_REPOSITORY_PATH).toString(); diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java index 9695877f6..8ccd4d22a 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java @@ -30,8 +30,6 @@ import java.io.FileNotFoundException; import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; import java.util.List; import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; @@ -51,7 +49,6 @@ */ public abstract class AasRepositoryRegistryLinkTestSuite { - private static final String AAS_REPOSITORY_PATH = "/shells"; private static final String DUMMY_GLOBAL_ASSETID = "globalAssetId"; private static final String DUMMY_IDSHORT = "ExampleMotor"; private static final String DUMMY_AAS_ID = "customIdentifier"; @@ -88,21 +85,6 @@ public void deleteAas() throws FileNotFoundException, IOException, ApiException assertDescriptionDeletionAtRegistry(); } - - @Test - public void testDummyAasDescriptorFactoryUrlWithTrailingSlash() { - String baseURLWithSlash = getAasRepoBaseUrl() + "/context/"; - String AAS_REPOSITORY_PATH_WITHOUT_SLASH = AAS_REPOSITORY_PATH.substring(1); - - assertEquals(baseURLWithSlash + AAS_REPOSITORY_PATH_WITHOUT_SLASH, createAasRepositoryUrl(baseURLWithSlash)); - } - - @Test - public void testDummyAasDescriptorFactoryUrlWithoutTrailingSlash() { - String baseURLWithoutSlash = getAasRepoBaseUrl() + "/context"; - - assertEquals(baseURLWithoutSlash + AAS_REPOSITORY_PATH , createAasRepositoryUrl(baseURLWithoutSlash)); - } private AssetAdministrationShellDescriptor retrieveDescriptorFromRegistry() throws ApiException { RegistryAndDiscoveryInterfaceApi api = getAasRegistryApi(); @@ -135,26 +117,10 @@ private String getAas1JSONString() throws FileNotFoundException, IOException { } private CloseableHttpResponse createAasOnRepo(String aasJsonContent) throws IOException { - return BaSyxHttpTestUtils.executePostOnURL(createAasRepositoryUrl(getAasRepoBaseUrl()), aasJsonContent); + return BaSyxHttpTestUtils.executePostOnURL(DummyAasDescriptorFactory.createAasRepositoryUrl(getAasRepoBaseUrl()), aasJsonContent); } private String getSpecificAasAccessURL(String aasId) { - return createAasRepositoryUrl(getAasRepoBaseUrl()) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(aasId); - } - - private String createAasRepositoryUrl(String aasRepositoryBaseURL) { - - try { - URL url = new URL(aasRepositoryBaseURL); - String path = url.getPath(); - - if (path.endsWith("/")) { - path = path.substring(0, path.length() - 1); - } - - return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + AAS_REPOSITORY_PATH).toString(); - } catch (MalformedURLException e) { - throw new RuntimeException("The AAS Repository Base url is malformed. " + e.getMessage()); - } + return DummyAasDescriptorFactory.createAasRepositoryUrl(getAasRepoBaseUrl()) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(aasId); } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryUrlTestSuite.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryUrlTestSuite.java new file mode 100644 index 000000000..b56c46909 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryUrlTestSuite.java @@ -0,0 +1,61 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import static org.junit.Assert.assertEquals; + +import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; +import org.junit.Test; + +public class AasRepositoryUrlTestSuite extends AasRepositoryRegistryLinkTestSuite { + + private static final String AAS_REPO_URL = "http://localhost:8081"; + private static final String AAS_REGISTRY_BASE_URL = "http://localhost:8050"; + private static AasRepositoryRegistryLink aasRepositoryRegistryLink; + + + private static final String AAS_REPOSITORY_PATH_WITH_SLASH = "/shells"; + private static final String AAS_REPOSITORY_PATH_WITHOUT_SLASH = "shells"; + + @Test + public void testUrlWithTrailingSlashAndPathWithoutLeadingSlash() { + String baseURLWithSlash = getAasRepoBaseUrl() + "/"; + + assertEquals(baseURLWithSlash + AAS_REPOSITORY_PATH_WITHOUT_SLASH, DummyAasDescriptorFactory.createAasRepositoryUrl(baseURLWithSlash)); + } + + @Test + public void testUrlWithTrailingSlashAndPathWithLeadingSlash() { + String baseURLWithSlash = getAasRepoBaseUrl() + "/"; + + assertEquals(baseURLWithSlash + AAS_REPOSITORY_PATH_WITHOUT_SLASH, DummyAasDescriptorFactory.createAasRepositoryUrl(baseURLWithSlash)); + } + + @Test + public void testUrlWithoutTrailingSlashAndPathWithoutLeadingSlash() { + String baseURLWithoutSlash = getAasRepoBaseUrl(); + + assertEquals(baseURLWithoutSlash + AAS_REPOSITORY_PATH_WITH_SLASH , DummyAasDescriptorFactory.createAasRepositoryUrl(baseURLWithoutSlash)); + } + + @Test + public void testUrlWithoutTrailingSlashAndPathWithLeadingSlash() { + String baseURLWithoutSlash = getAasRepoBaseUrl(); + + assertEquals(baseURLWithoutSlash + AAS_REPOSITORY_PATH_WITH_SLASH , DummyAasDescriptorFactory.createAasRepositoryUrl(baseURLWithoutSlash)); + } + + @Override + protected String getAasRepoBaseUrl() { + return AAS_REPO_URL; + } + + @Override + protected String getAasRegistryUrl() { + return AAS_REGISTRY_BASE_URL; + } + + @Override + protected RegistryAndDiscoveryInterfaceApi getAasRegistryApi() { + + return aasRepositoryRegistryLink.getRegistryApi(); + } +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java index 8d437b162..e21306eb3 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java @@ -92,8 +92,10 @@ static String createAasRepositoryUrl(String aasRepositoryBaseURL) { URL url = new URL(aasRepositoryBaseURL); String path = url.getPath(); - if (path.endsWith("/")) { + if (path.endsWith("/") && AAS_REPOSITORY_PATH.startsWith("/")) { path = path.substring(0, path.length() - 1); + } else if (!path.endsWith("/") && !AAS_REPOSITORY_PATH.startsWith("/")) { + path += "/"; } return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + AAS_REPOSITORY_PATH).toString(); diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java index 166d279dd..c74dad5c3 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java @@ -188,8 +188,10 @@ private String createSubmodelRepositoryUrl(String submodelRepositoryBaseURL) { URL url = new URL(submodelRepositoryBaseURL); String path = url.getPath(); - if (path.endsWith("/")) { + if (path.endsWith("/") && SUBMODEL_REPOSITORY_PATH.startsWith("/")) { path = path.substring(0, path.length() - 1); + } else if (!path.endsWith("/") && !SUBMODEL_REPOSITORY_PATH.startsWith("/")) { + path += "/"; } return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java index a2118b1a4..3dd7e317f 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java @@ -99,8 +99,10 @@ static String createSubmodelRepositoryUrl(String smRepositoryBaseURL) { URL url = new URL(smRepositoryBaseURL); String path = url.getPath(); - if (path.endsWith("/")) { + if (path.endsWith("/") && SUBMODEL_REPOSITORY_PATH.startsWith("/")) { path = path.substring(0, path.length() - 1); + } else if (!path.endsWith("/") && !SUBMODEL_REPOSITORY_PATH.startsWith("/")) { + path += "/"; } return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkTestSuite.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkTestSuite.java index 0f37fc54e..2a7c06eda 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkTestSuite.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkTestSuite.java @@ -30,8 +30,6 @@ import java.io.FileNotFoundException; import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; import java.util.List; import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; @@ -51,9 +49,6 @@ * @author danish */ public abstract class SubmodelRepositoryRegistryLinkTestSuite { - - private static final String SUBMODEL_REPOSITORY_PATH = "/submodels"; - private static final String DUMMY_SUBMODEL_IDSHORT = "TechnicalData"; private static final String DUMMY_SUBMODEL_ID = "7A7104BDAB57E184"; @@ -106,21 +101,6 @@ public void deleteSubmodel() throws FileNotFoundException, IOException, ApiExcep assertDescriptionDeletionAtRegistry(); } - @Test - public void testDummyAasDescriptorFactoryUrlWithTrailingSlash() { - String baseURLWithSlash = getSubmodelRepoBaseUrl() + "/context/"; - String SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH = SUBMODEL_REPOSITORY_PATH.substring(1); - - assertEquals(baseURLWithSlash + SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH, createSubmodelRepositoryUrl(baseURLWithSlash)); - } - - @Test - public void testDummyAasDescriptorFactoryUrlWithoutTrailingSlash() { - String baseURLWithoutSlash = getSubmodelRepoBaseUrl() + "/context"; - - assertEquals(baseURLWithoutSlash + SUBMODEL_REPOSITORY_PATH , createSubmodelRepositoryUrl(baseURLWithoutSlash)); - } - private SubmodelDescriptor retrieveDescriptorFromRegistry() throws ApiException { SubmodelRegistryApi api = getSubmodelRegistryApi(); @@ -160,7 +140,7 @@ private String getExpectedSubmodel() throws FileNotFoundException, IOException { } private CloseableHttpResponse createSubmodelOnRepo(String submodelJsonContent) throws IOException { - return BaSyxHttpTestUtils.executePostOnURL(createSubmodelRepositoryUrl(getSubmodelRepoBaseUrl()), submodelJsonContent); + return BaSyxHttpTestUtils.executePostOnURL(DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(getSubmodelRepoBaseUrl()), submodelJsonContent); } private CloseableHttpResponse createSubmodelElementOnRepo(String submodelElementJsonContent) throws IOException { @@ -170,22 +150,6 @@ private CloseableHttpResponse createSubmodelElementOnRepo(String submodelElement } private String getSpecificSubmodelAccessURL(String submodelId) { - return createSubmodelRepositoryUrl(getSubmodelRepoBaseUrl()) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId); - } - - private String createSubmodelRepositoryUrl(String smRepositoryBaseURL) { - - try { - URL url = new URL(smRepositoryBaseURL); - String path = url.getPath(); - - if (path.endsWith("/")) { - path = path.substring(0, path.length() - 1); - } - - return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); - } catch (MalformedURLException e) { - throw new RuntimeException("The Submodel Repository Base url is malformed.\n " + e.getMessage()); - } + return DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(getSubmodelRepoBaseUrl()) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId); } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryUrlTestSuite.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryUrlTestSuite.java new file mode 100644 index 000000000..8024a5dc4 --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryUrlTestSuite.java @@ -0,0 +1,59 @@ +package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration; + +import static org.junit.Assert.assertEquals; + +import org.eclipse.digitaltwin.basyx.submodelregistry.client.api.SubmodelRegistryApi; +import org.junit.Test; + +public class SubmodelRepositoryUrlTestSuite extends SubmodelRepositoryRegistryLinkTestSuite { + + private static final String SUBMODEL_REPO_URL = "http://localhost:8081"; + private static final String SUBMODEL_REGISTRY_BASE_URL = "http://localhost:8060"; + private static SubmodelRepositoryRegistryLink submodelRepositoryRegistryLink; + + + private static final String SUBMODEL_REPOSITORY_PATH_WITH_SLASH = "/submodels"; + private static final String SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH = "submodels"; + + @Test + public void testUrlWithTrailingSlashAndPathWithoutLeadingSlash() { + String baseURLWithSlash = getSubmodelRepoBaseUrl() + "/"; + + assertEquals(baseURLWithSlash + SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH, DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithSlash)); + } + + @Test + public void testUrlWithTrailingSlashAndPathWithLeadingSlash() { + String baseURLWithSlash = getSubmodelRepoBaseUrl() + "/"; + + assertEquals(baseURLWithSlash + SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH, DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithSlash)); + } + + @Test + public void testUrlWithoutTrailingSlashAndPathWithoutLeadingSlash() { + String baseURLWithoutSlash = getSubmodelRepoBaseUrl(); + + assertEquals(baseURLWithoutSlash + SUBMODEL_REPOSITORY_PATH_WITH_SLASH , DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithoutSlash)); + } + + @Test + public void testUrlWithoutTrailingSlashAndPathWithLeadingSlash() { + String baseURLWithoutSlash = getSubmodelRepoBaseUrl(); + + assertEquals(baseURLWithoutSlash + SUBMODEL_REPOSITORY_PATH_WITH_SLASH , DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithoutSlash)); + } + + @Override + protected String getSubmodelRepoBaseUrl() { + return SUBMODEL_REPO_URL; + } + @Override + protected String getSubmodelRegistryUrl() { + return SUBMODEL_REGISTRY_BASE_URL; + } + @Override + protected SubmodelRegistryApi getSubmodelRegistryApi() { + + return submodelRepositoryRegistryLink.getRegistryApi(); + } +} From 9d86f9e379ab08f91f0941b7d9de183e02118577 Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Tue, 23 Jul 2024 14:59:18 +0200 Subject: [PATCH 10/37] fix: use main static createUrl method in DescriptorFactory test cases --- .../integration/AasDescriptorFactory.java | 2 +- .../AasRepositoryRegistryLinkTestSuite.java | 4 +- .../AasRepositoryUrlTestSuite.java | 61 ------------------- .../integration/TestAasDescriptorFactory.java | 41 +++++++++++++ .../TestAuthorizedSubmodelRepository.java | 14 ++++- .../SubmodelDescriptorFactory.java | 2 +- .../DummySubmodelDescriptorFactory.java | 2 +- ...bmodelRepositoryRegistryLinkTestSuite.java | 4 +- .../SubmodelRepositoryUrlTestSuite.java | 59 ------------------ .../TestSubmodelDescriptorFactory.java | 42 +++++++++++++ 10 files changed, 101 insertions(+), 130 deletions(-) delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryUrlTestSuite.java create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAasDescriptorFactory.java delete mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryUrlTestSuite.java create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/TestSubmodelDescriptorFactory.java diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java index 8a97d72c9..9afbb61e3 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java @@ -192,7 +192,7 @@ private String getProtocol(String endpoint) { } } - private String createAasRepositoryUrl(String aasRepositoryBaseURL) { + public static String createAasRepositoryUrl(String aasRepositoryBaseURL) { try { URL url = new URL(aasRepositoryBaseURL); diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java index 8ccd4d22a..f79eb2e8e 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java @@ -117,10 +117,10 @@ private String getAas1JSONString() throws FileNotFoundException, IOException { } private CloseableHttpResponse createAasOnRepo(String aasJsonContent) throws IOException { - return BaSyxHttpTestUtils.executePostOnURL(DummyAasDescriptorFactory.createAasRepositoryUrl(getAasRepoBaseUrl()), aasJsonContent); + return BaSyxHttpTestUtils.executePostOnURL(AasDescriptorFactory.createAasRepositoryUrl(getAasRepoBaseUrl()), aasJsonContent); } private String getSpecificAasAccessURL(String aasId) { - return DummyAasDescriptorFactory.createAasRepositoryUrl(getAasRepoBaseUrl()) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(aasId); + return AasDescriptorFactory.createAasRepositoryUrl(getAasRepoBaseUrl()) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(aasId); } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryUrlTestSuite.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryUrlTestSuite.java deleted file mode 100644 index b56c46909..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryUrlTestSuite.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; - -import static org.junit.Assert.assertEquals; - -import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; -import org.junit.Test; - -public class AasRepositoryUrlTestSuite extends AasRepositoryRegistryLinkTestSuite { - - private static final String AAS_REPO_URL = "http://localhost:8081"; - private static final String AAS_REGISTRY_BASE_URL = "http://localhost:8050"; - private static AasRepositoryRegistryLink aasRepositoryRegistryLink; - - - private static final String AAS_REPOSITORY_PATH_WITH_SLASH = "/shells"; - private static final String AAS_REPOSITORY_PATH_WITHOUT_SLASH = "shells"; - - @Test - public void testUrlWithTrailingSlashAndPathWithoutLeadingSlash() { - String baseURLWithSlash = getAasRepoBaseUrl() + "/"; - - assertEquals(baseURLWithSlash + AAS_REPOSITORY_PATH_WITHOUT_SLASH, DummyAasDescriptorFactory.createAasRepositoryUrl(baseURLWithSlash)); - } - - @Test - public void testUrlWithTrailingSlashAndPathWithLeadingSlash() { - String baseURLWithSlash = getAasRepoBaseUrl() + "/"; - - assertEquals(baseURLWithSlash + AAS_REPOSITORY_PATH_WITHOUT_SLASH, DummyAasDescriptorFactory.createAasRepositoryUrl(baseURLWithSlash)); - } - - @Test - public void testUrlWithoutTrailingSlashAndPathWithoutLeadingSlash() { - String baseURLWithoutSlash = getAasRepoBaseUrl(); - - assertEquals(baseURLWithoutSlash + AAS_REPOSITORY_PATH_WITH_SLASH , DummyAasDescriptorFactory.createAasRepositoryUrl(baseURLWithoutSlash)); - } - - @Test - public void testUrlWithoutTrailingSlashAndPathWithLeadingSlash() { - String baseURLWithoutSlash = getAasRepoBaseUrl(); - - assertEquals(baseURLWithoutSlash + AAS_REPOSITORY_PATH_WITH_SLASH , DummyAasDescriptorFactory.createAasRepositoryUrl(baseURLWithoutSlash)); - } - - @Override - protected String getAasRepoBaseUrl() { - return AAS_REPO_URL; - } - - @Override - protected String getAasRegistryUrl() { - return AAS_REGISTRY_BASE_URL; - } - - @Override - protected RegistryAndDiscoveryInterfaceApi getAasRegistryApi() { - - return aasRepositoryRegistryLink.getRegistryApi(); - } -} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAasDescriptorFactory.java new file mode 100644 index 000000000..d27bbff71 --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAasDescriptorFactory.java @@ -0,0 +1,41 @@ +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class TestAasDescriptorFactory { + + private static final String AAS_REPO_URL = "http://localhost:8081"; + + private static final String AAS_REPOSITORY_PATH_WITH_SLASH = "/shells"; + private static final String AAS_REPOSITORY_PATH_WITHOUT_SLASH = "shells"; + + @Test + public void testUrlWithTrailingSlashAndPathWithoutLeadingSlash() { + String baseURLWithSlash = AAS_REPO_URL + "/"; + + assertEquals(baseURLWithSlash + AAS_REPOSITORY_PATH_WITHOUT_SLASH, AasDescriptorFactory.createAasRepositoryUrl(baseURLWithSlash)); + } + + @Test + public void testUrlWithTrailingSlashAndPathWithLeadingSlash() { + String baseURLWithSlash = AAS_REPO_URL + "/"; + + assertEquals(baseURLWithSlash + AAS_REPOSITORY_PATH_WITHOUT_SLASH, AasDescriptorFactory.createAasRepositoryUrl(baseURLWithSlash)); + } + + @Test + public void testUrlWithoutTrailingSlashAndPathWithoutLeadingSlash() { + String baseURLWithoutSlash = AAS_REPO_URL; + + assertEquals(baseURLWithoutSlash + AAS_REPOSITORY_PATH_WITH_SLASH , AasDescriptorFactory.createAasRepositoryUrl(baseURLWithoutSlash)); + } + + @Test + public void testUrlWithoutTrailingSlashAndPathWithLeadingSlash() { + String baseURLWithoutSlash = AAS_REPO_URL; + + assertEquals(baseURLWithoutSlash + AAS_REPOSITORY_PATH_WITH_SLASH , AasDescriptorFactory.createAasRepositoryUrl(baseURLWithoutSlash)); + } +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/TestAuthorizedSubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/TestAuthorizedSubmodelRepository.java index d22e2d39e..0824f9652 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/TestAuthorizedSubmodelRepository.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/TestAuthorizedSubmodelRepository.java @@ -1303,11 +1303,19 @@ private static String getAdminAccessToken() { } private static String createSubmodelRepositoryUrl(String submodelRepositoryBaseURL) { - try { - return new URL(new URL(submodelRepositoryBaseURL), SUBMODEL_REPOSITORY_PATH).toString(); + URL url = new URL(submodelRepositoryBaseURL); + String path = url.getPath(); + + if (path.endsWith("/") && SUBMODEL_REPOSITORY_PATH.startsWith("/")) { + path = path.substring(0, path.length() - 1); + } else if (!path.endsWith("/") && !SUBMODEL_REPOSITORY_PATH.startsWith("/")) { + path += "/"; + } + + return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); } catch (MalformedURLException e) { - throw new RuntimeException("The Submodel Repository Base url is malformed. " + e.getMessage()); + throw new RuntimeException("The Submodel Repository Base url is malformed.\n " + e.getMessage()); } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java index cc969e9fd..38996c0e0 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java @@ -182,7 +182,7 @@ private String getProtocol(String endpoint) { } } - private String createSubmodelRepositoryUrl(String submodelRepositoryBaseURL) { + public static String createSubmodelRepositoryUrl(String submodelRepositoryBaseURL) { try { URL url = new URL(submodelRepositoryBaseURL); diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java index 3dd7e317f..4d00db7f4 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java @@ -93,7 +93,7 @@ private static String getProtocol(String endpoint) { } } - static String createSubmodelRepositoryUrl(String smRepositoryBaseURL) { + public static String createSubmodelRepositoryUrl(String smRepositoryBaseURL) { try { URL url = new URL(smRepositoryBaseURL); diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkTestSuite.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkTestSuite.java index 2a7c06eda..425ef96f5 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkTestSuite.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkTestSuite.java @@ -140,7 +140,7 @@ private String getExpectedSubmodel() throws FileNotFoundException, IOException { } private CloseableHttpResponse createSubmodelOnRepo(String submodelJsonContent) throws IOException { - return BaSyxHttpTestUtils.executePostOnURL(DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(getSubmodelRepoBaseUrl()), submodelJsonContent); + return BaSyxHttpTestUtils.executePostOnURL(SubmodelDescriptorFactory.createSubmodelRepositoryUrl(getSubmodelRepoBaseUrl()), submodelJsonContent); } private CloseableHttpResponse createSubmodelElementOnRepo(String submodelElementJsonContent) throws IOException { @@ -150,6 +150,6 @@ private CloseableHttpResponse createSubmodelElementOnRepo(String submodelElement } private String getSpecificSubmodelAccessURL(String submodelId) { - return DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(getSubmodelRepoBaseUrl()) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId); + return SubmodelDescriptorFactory.createSubmodelRepositoryUrl(getSubmodelRepoBaseUrl()) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId); } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryUrlTestSuite.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryUrlTestSuite.java deleted file mode 100644 index 8024a5dc4..000000000 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryUrlTestSuite.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration; - -import static org.junit.Assert.assertEquals; - -import org.eclipse.digitaltwin.basyx.submodelregistry.client.api.SubmodelRegistryApi; -import org.junit.Test; - -public class SubmodelRepositoryUrlTestSuite extends SubmodelRepositoryRegistryLinkTestSuite { - - private static final String SUBMODEL_REPO_URL = "http://localhost:8081"; - private static final String SUBMODEL_REGISTRY_BASE_URL = "http://localhost:8060"; - private static SubmodelRepositoryRegistryLink submodelRepositoryRegistryLink; - - - private static final String SUBMODEL_REPOSITORY_PATH_WITH_SLASH = "/submodels"; - private static final String SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH = "submodels"; - - @Test - public void testUrlWithTrailingSlashAndPathWithoutLeadingSlash() { - String baseURLWithSlash = getSubmodelRepoBaseUrl() + "/"; - - assertEquals(baseURLWithSlash + SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH, DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithSlash)); - } - - @Test - public void testUrlWithTrailingSlashAndPathWithLeadingSlash() { - String baseURLWithSlash = getSubmodelRepoBaseUrl() + "/"; - - assertEquals(baseURLWithSlash + SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH, DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithSlash)); - } - - @Test - public void testUrlWithoutTrailingSlashAndPathWithoutLeadingSlash() { - String baseURLWithoutSlash = getSubmodelRepoBaseUrl(); - - assertEquals(baseURLWithoutSlash + SUBMODEL_REPOSITORY_PATH_WITH_SLASH , DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithoutSlash)); - } - - @Test - public void testUrlWithoutTrailingSlashAndPathWithLeadingSlash() { - String baseURLWithoutSlash = getSubmodelRepoBaseUrl(); - - assertEquals(baseURLWithoutSlash + SUBMODEL_REPOSITORY_PATH_WITH_SLASH , DummySubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithoutSlash)); - } - - @Override - protected String getSubmodelRepoBaseUrl() { - return SUBMODEL_REPO_URL; - } - @Override - protected String getSubmodelRegistryUrl() { - return SUBMODEL_REGISTRY_BASE_URL; - } - @Override - protected SubmodelRegistryApi getSubmodelRegistryApi() { - - return submodelRepositoryRegistryLink.getRegistryApi(); - } -} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/TestSubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/TestSubmodelDescriptorFactory.java new file mode 100644 index 000000000..d6284753f --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/TestSubmodelDescriptorFactory.java @@ -0,0 +1,42 @@ +package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class TestSubmodelDescriptorFactory { + + private static final String SUBMODEL_REPO_URL = "http://localhost:8081"; + + + private static final String SUBMODEL_REPOSITORY_PATH_WITH_SLASH = "/submodels"; + private static final String SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH = "submodels"; + + @Test + public void testUrlWithTrailingSlashAndPathWithoutLeadingSlash() { + String baseURLWithSlash = SUBMODEL_REPO_URL + "/"; + + assertEquals(baseURLWithSlash + SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH, SubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithSlash)); + } + + @Test + public void testUrlWithTrailingSlashAndPathWithLeadingSlash() { + String baseURLWithSlash = SUBMODEL_REPO_URL + "/"; + + assertEquals(baseURLWithSlash + SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH, SubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithSlash)); + } + + @Test + public void testUrlWithoutTrailingSlashAndPathWithoutLeadingSlash() { + String baseURLWithoutSlash = SUBMODEL_REPO_URL; + + assertEquals(baseURLWithoutSlash + SUBMODEL_REPOSITORY_PATH_WITH_SLASH , SubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithoutSlash)); + } + + @Test + public void testUrlWithoutTrailingSlashAndPathWithLeadingSlash() { + String baseURLWithoutSlash = SUBMODEL_REPO_URL; + + assertEquals(baseURLWithoutSlash + SUBMODEL_REPOSITORY_PATH_WITH_SLASH , SubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithoutSlash)); + } +} From c75b166ebdeb4874ba6884f3852b50f03aa4116e Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Thu, 25 Jul 2024 11:19:12 +0200 Subject: [PATCH 11/37] refactor: remove create*Url method from Dummy*DescriptorFactory --- .../DummyAasDescriptorFactory.java | 23 +------------------ .../DummySubmodelDescriptorFactory.java | 22 +----------------- 2 files changed, 2 insertions(+), 43 deletions(-) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java index e21306eb3..51b6acca2 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java @@ -41,8 +41,6 @@ * */ public class DummyAasDescriptorFactory { - private static final String AAS_REPOSITORY_PATH = "/shells"; - public static AssetAdministrationShellDescriptor createDummyDescriptor(String aasId, String idShort, String globalAssetId, String aasRepoBaseUrl) { AssetAdministrationShellDescriptor descriptor = new AssetAdministrationShellDescriptor(); @@ -75,7 +73,7 @@ private static ProtocolInformation createProtocolInformation(String aasId, Strin } private static String createHref(String aasId, String aasRepoBaseUrl) { - return String.format("%s/%s", createAasRepositoryUrl(aasRepoBaseUrl), Base64UrlEncodedIdentifier.encodeIdentifier(aasId)); + return String.format("%s/%s", AasDescriptorFactory.createAasRepositoryUrl(aasRepoBaseUrl), Base64UrlEncodedIdentifier.encodeIdentifier(aasId)); } private static String getProtocol(String endpoint) { @@ -85,23 +83,4 @@ private static String getProtocol(String endpoint) { throw new RuntimeException(); } } - - static String createAasRepositoryUrl(String aasRepositoryBaseURL) { - - try { - URL url = new URL(aasRepositoryBaseURL); - String path = url.getPath(); - - if (path.endsWith("/") && AAS_REPOSITORY_PATH.startsWith("/")) { - path = path.substring(0, path.length() - 1); - } else if (!path.endsWith("/") && !AAS_REPOSITORY_PATH.startsWith("/")) { - path += "/"; - } - - return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + AAS_REPOSITORY_PATH).toString(); - } catch (MalformedURLException e) { - throw new RuntimeException("The AAS Repository Base url is malformed. " + e.getMessage()); - } - } - } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java index 4d00db7f4..8a08b54ac 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java @@ -45,8 +45,6 @@ * */ public class DummySubmodelDescriptorFactory { - private static final String SUBMODEL_REPOSITORY_PATH = "/submodels"; - public static SubmodelDescriptor createDummyDescriptor(String smId, String idShort, String smRepoBaseUrl, Reference semanticId) { SubmodelDescriptor descriptor = new SubmodelDescriptor(); @@ -82,7 +80,7 @@ private static ProtocolInformation createProtocolInformation(String smId, String } private static String createHref(String smId, String smRepoBaseUrl) { - return String.format("%s/%s", createSubmodelRepositoryUrl(smRepoBaseUrl), Base64UrlEncodedIdentifier.encodeIdentifier(smId)); + return String.format("%s/%s", SubmodelDescriptorFactory.createSubmodelRepositoryUrl(smRepoBaseUrl), Base64UrlEncodedIdentifier.encodeIdentifier(smId)); } private static String getProtocol(String endpoint) { @@ -92,22 +90,4 @@ private static String getProtocol(String endpoint) { throw new RuntimeException(); } } - - public static String createSubmodelRepositoryUrl(String smRepositoryBaseURL) { - - try { - URL url = new URL(smRepositoryBaseURL); - String path = url.getPath(); - - if (path.endsWith("/") && SUBMODEL_REPOSITORY_PATH.startsWith("/")) { - path = path.substring(0, path.length() - 1); - } else if (!path.endsWith("/") && !SUBMODEL_REPOSITORY_PATH.startsWith("/")) { - path += "/"; - } - - return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); - } catch (MalformedURLException e) { - throw new RuntimeException("The Submodel Repository Base url is malformed.\n " + e.getMessage()); - } - } } From 9272437a380e781b423ff5c08645c7aae57ff0fd Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Thu, 25 Jul 2024 11:51:33 +0200 Subject: [PATCH 12/37] fix: Test*DescriptorFactory refactor tests --- .../integration/TestAasDescriptorFactory.java | 30 ++++--------------- .../TestSubmodelDescriptorFactory.java | 30 ++++--------------- 2 files changed, 11 insertions(+), 49 deletions(-) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAasDescriptorFactory.java index d27bbff71..b8ebc0ff6 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAasDescriptorFactory.java @@ -7,35 +7,17 @@ public class TestAasDescriptorFactory { private static final String AAS_REPO_URL = "http://localhost:8081"; - - private static final String AAS_REPOSITORY_PATH_WITH_SLASH = "/shells"; - private static final String AAS_REPOSITORY_PATH_WITHOUT_SLASH = "shells"; + + private static final String AAS_REPOSITORY_PATH = "shells"; @Test - public void testUrlWithTrailingSlashAndPathWithoutLeadingSlash() { - String baseURLWithSlash = AAS_REPO_URL + "/"; - - assertEquals(baseURLWithSlash + AAS_REPOSITORY_PATH_WITHOUT_SLASH, AasDescriptorFactory.createAasRepositoryUrl(baseURLWithSlash)); + public void testUrlWithTrailingSlash() { + assertEquals(AAS_REPO_URL + "/" + AAS_REPOSITORY_PATH, AasDescriptorFactory.createAasRepositoryUrl(AAS_REPO_URL + "/")); } - @Test - public void testUrlWithTrailingSlashAndPathWithLeadingSlash() { - String baseURLWithSlash = AAS_REPO_URL + "/"; - - assertEquals(baseURLWithSlash + AAS_REPOSITORY_PATH_WITHOUT_SLASH, AasDescriptorFactory.createAasRepositoryUrl(baseURLWithSlash)); - } - @Test - public void testUrlWithoutTrailingSlashAndPathWithoutLeadingSlash() { - String baseURLWithoutSlash = AAS_REPO_URL; - - assertEquals(baseURLWithoutSlash + AAS_REPOSITORY_PATH_WITH_SLASH , AasDescriptorFactory.createAasRepositoryUrl(baseURLWithoutSlash)); + public void testUrlWithoutTrailingSlash() { + assertEquals(AAS_REPO_URL + "/" + AAS_REPOSITORY_PATH , AasDescriptorFactory.createAasRepositoryUrl(AAS_REPO_URL)); } - @Test - public void testUrlWithoutTrailingSlashAndPathWithLeadingSlash() { - String baseURLWithoutSlash = AAS_REPO_URL; - - assertEquals(baseURLWithoutSlash + AAS_REPOSITORY_PATH_WITH_SLASH , AasDescriptorFactory.createAasRepositoryUrl(baseURLWithoutSlash)); - } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/TestSubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/TestSubmodelDescriptorFactory.java index d6284753f..cc2b8a293 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/TestSubmodelDescriptorFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/TestSubmodelDescriptorFactory.java @@ -8,35 +8,15 @@ public class TestSubmodelDescriptorFactory { private static final String SUBMODEL_REPO_URL = "http://localhost:8081"; + private static final String SUBMODEL_REPOSITORY_PATH = "submodels"; - private static final String SUBMODEL_REPOSITORY_PATH_WITH_SLASH = "/submodels"; - private static final String SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH = "submodels"; - - @Test - public void testUrlWithTrailingSlashAndPathWithoutLeadingSlash() { - String baseURLWithSlash = SUBMODEL_REPO_URL + "/"; - - assertEquals(baseURLWithSlash + SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH, SubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithSlash)); - } - @Test - public void testUrlWithTrailingSlashAndPathWithLeadingSlash() { - String baseURLWithSlash = SUBMODEL_REPO_URL + "/"; - - assertEquals(baseURLWithSlash + SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH, SubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithSlash)); + public void testUrlWithTrailingSlash() { + assertEquals(SUBMODEL_REPO_URL + "/" + SUBMODEL_REPOSITORY_PATH, SubmodelDescriptorFactory.createSubmodelRepositoryUrl(SUBMODEL_REPO_URL + "/")); } @Test - public void testUrlWithoutTrailingSlashAndPathWithoutLeadingSlash() { - String baseURLWithoutSlash = SUBMODEL_REPO_URL; - - assertEquals(baseURLWithoutSlash + SUBMODEL_REPOSITORY_PATH_WITH_SLASH , SubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithoutSlash)); - } - - @Test - public void testUrlWithoutTrailingSlashAndPathWithLeadingSlash() { - String baseURLWithoutSlash = SUBMODEL_REPO_URL; - - assertEquals(baseURLWithoutSlash + SUBMODEL_REPOSITORY_PATH_WITH_SLASH , SubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithoutSlash)); + public void testUrlWithoutTrailingSlash() { + assertEquals(SUBMODEL_REPO_URL + "/" + SUBMODEL_REPOSITORY_PATH , SubmodelDescriptorFactory.createSubmodelRepositoryUrl(SUBMODEL_REPO_URL)); } } From 27e19d431cbeae2e3a3a6776c5492ffdd39367fd Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Wed, 31 Jul 2024 09:01:42 +0200 Subject: [PATCH 13/37] refactor: make createRepositoryUrl common + refactor implementation --- .../TestAuthorizedAasRepository.java | 54 ++++++------- .../integration/AasDescriptorFactory.java | 25 ++---- .../AasRepositoryRegistryLinkTestSuite.java | 6 +- .../DummyAasDescriptorFactory.java | 5 +- .../integration/TestAasDescriptorFactory.java | 23 ------ basyx.common/basyx.core/pom.xml | 4 + .../digitaltwin/basyx/core/Helper.java | 34 ++++++++ .../digitaltwin/basyx/core/TestHelper.java | 33 ++++++++ .../TestAuthorizedSubmodelRepository.java | 78 ++++++++----------- .../SubmodelDescriptorFactory.java | 22 +----- .../DummySubmodelDescriptorFactory.java | 5 +- ...bmodelRepositoryRegistryLinkTestSuite.java | 7 +- .../TestSubmodelDescriptorFactory.java | 22 ------ 13 files changed, 149 insertions(+), 169 deletions(-) delete mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAasDescriptorFactory.java create mode 100644 basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/Helper.java create mode 100644 basyx.common/basyx.core/src/test/java/org/eclipse/digitaltwin/basyx/core/TestHelper.java delete mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/TestSubmodelDescriptorFactory.java diff --git a/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java b/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java index 65e6cd52d..1981a134d 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java @@ -53,6 +53,7 @@ import org.eclipse.digitaltwin.basyx.authorization.DummyCredentialStore; import org.eclipse.digitaltwin.basyx.authorization.jwt.JwtTokenDecoder; import org.eclipse.digitaltwin.basyx.authorization.jwt.PublicKeyUtils; +import org.eclipse.digitaltwin.basyx.core.Helper; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; import org.eclipse.digitaltwin.basyx.http.serialization.BaSyxHttpTestUtils; import org.junit.AfterClass; @@ -529,10 +530,10 @@ public void getThumbnailWithCorrectRoleAndPermission() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_READER_CREDENTIAL); - CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test @@ -541,17 +542,17 @@ public void getThumbnailWithCorrectRoleAndSpecificAasPermission() throws IOExcep String accessToken = getAccessToken(DummyCredentialStore.BASYX_READER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test public void getThumbnailWithCorrectRoleAndUnauthorizedSpecificAas() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_READER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID_2), accessToken); + CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID_2), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @@ -559,13 +560,13 @@ public void getThumbnailWithCorrectRoleAndUnauthorizedSpecificAas() throws IOExc public void getThumbnailWithInsufficientPermissionRole() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_DELETER_CREDENTIAL); - CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @Test public void getThumbnailWithNoAuthorization() throws IOException { - CloseableHttpResponse retrievalResponse = getElementWithNoAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID)); + CloseableHttpResponse retrievalResponse = getElementWithNoAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID)); assertEquals(HttpStatus.UNAUTHORIZED.value(), retrievalResponse.getCode()); } @@ -577,7 +578,7 @@ public void setThumbnailWithCorrectRoleAndPermission() throws IOException { CloseableHttpResponse retrievalResponse = setThumbnailToAasWithAuthorization(SPECIFIC_SHELL_ID, accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test @@ -587,7 +588,7 @@ public void setThumbnailWithCorrectRoleAndSpecificAasPermission() throws IOExcep CloseableHttpResponse retrievalResponse = setThumbnailToAasWithAuthorization(SPECIFIC_SHELL_ID, accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test @@ -619,10 +620,10 @@ public void deleteThumbnailWithCorrectRoleAndPermission() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_ASSET_UPDATER_CREDENTIAL); - CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - assertElementIsNotOnServer(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + assertElementIsNotOnServer(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test @@ -633,10 +634,10 @@ public void deleteThumbnailWithCorrectRoleAndSpecificAasPermission() throws IOEx String accessToken = getAccessToken(DummyCredentialStore.BASYX_ASSET_UPDATER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID_2), accessToken); + CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID_2), accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - assertElementIsNotOnServer(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID_2), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + assertElementIsNotOnServer(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID_2), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); deleteElementWithAuthorization(getSpecificAasAccessURL(SPECIFIC_SHELL_ID_2), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @@ -644,7 +645,7 @@ public void deleteThumbnailWithCorrectRoleAndSpecificAasPermission() throws IOEx public void deleteThumbnailWithCorrectRoleAndUnauthorizedSpecificAas() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_ASSET_UPDATER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @@ -652,13 +653,13 @@ public void deleteThumbnailWithCorrectRoleAndUnauthorizedSpecificAas() throws IO public void deleteThumbnailWithInsufficientPermissionRole() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_CREATOR_CREDENTIAL); - CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @Test public void deleteThumbnailWithNoAuthorization() throws IOException { - CloseableHttpResponse retrievalResponse = deleteElementWithNoAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID)); + CloseableHttpResponse retrievalResponse = deleteElementWithNoAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID)); assertEquals(HttpStatus.UNAUTHORIZED.value(), retrievalResponse.getCode()); } @@ -716,11 +717,11 @@ private String getAccessToken(DummyCredential dummyCredential) { } protected CloseableHttpResponse getAllAasWithAuthorization(String accessToken) throws IOException { - return BaSyxHttpTestUtils.executeAuthorizedGetOnURL(createAasRepositoryUrl(aasRepositoryBaseUrl), accessToken); + return BaSyxHttpTestUtils.executeAuthorizedGetOnURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), accessToken); } protected CloseableHttpResponse getAllAasNoAuthorization() throws IOException { - return BaSyxHttpTestUtils.executeGetOnURL(createAasRepositoryUrl(aasRepositoryBaseUrl)); + return BaSyxHttpTestUtils.executeGetOnURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH)); } protected CloseableHttpResponse getElementWithAuthorization(String url, String accessToken) throws IOException { @@ -732,11 +733,11 @@ protected CloseableHttpResponse getElementWithNoAuthorization(String url) throws } protected String getSpecificAasAccessURL(String shellId) { - return createAasRepositoryUrl(createAasRepositoryUrl(aasRepositoryBaseUrl)) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(shellId); + return Helper.createRepositoryUrl(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), AAS_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(shellId); } private static CloseableHttpResponse createAasOnRepositoryWithAuthorization(String aasJsonContent, String accessToken) throws IOException { - return BaSyxHttpTestUtils.executeAuthorizedPostOnURL(createAasRepositoryUrl(aasRepositoryBaseUrl), aasJsonContent, accessToken); + return BaSyxHttpTestUtils.executeAuthorizedPostOnURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), aasJsonContent, accessToken); } private CloseableHttpResponse setThumbnailToAasWithAuthorization(String shellId, String accessToken) throws IOException { @@ -752,7 +753,7 @@ private CloseableHttpResponse setThumbnailToAasWithNoAuthorization(String shellI } private static CloseableHttpResponse createAasOnRepositoryWithNoAuthorization(String aasJsonContent) throws IOException { - return BaSyxHttpTestUtils.executePostOnURL(createAasRepositoryUrl(aasRepositoryBaseUrl), aasJsonContent); + return BaSyxHttpTestUtils.executePostOnURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), aasJsonContent); } private CloseableHttpResponse updateElementWithAuthorizationPutRequest(String url, String aasJsonContent, String accessToken) throws IOException { @@ -812,15 +813,6 @@ private String getSpecificSubmodelReferenceUrl(String shellId, String submodelId private static String getThumbnailAccessURL(String aasId) { Base64UrlEncodedIdentifier identifier = new Base64UrlEncodedIdentifier(aasId); - return createAasRepositoryUrl(aasRepositoryBaseUrl) + "/" + identifier.getEncodedIdentifier() + "/asset-information/thumbnail"; - } - - private static String createAasRepositoryUrl(String aasRepositoryBaseURL) { - - try { - return new URL(new URL(aasRepositoryBaseURL), AAS_REPOSITORY_PATH).toString(); - } catch (MalformedURLException e) { - throw new RuntimeException("The AAS Repository Base url is malformed. " + e.getMessage()); - } + return Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH) + "/" + identifier.getEncodedIdentifier() + "/asset-information/thumbnail"; } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java index 9afbb61e3..f6bab0874 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java @@ -26,6 +26,8 @@ package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.util.List; @@ -39,7 +41,9 @@ import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Endpoint; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ProtocolInformation; import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.AttributeMapper; +import org.eclipse.digitaltwin.basyx.core.Helper; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; +import org.springframework.web.util.UriComponentsBuilder; /** * Factory for creating the {@link AssetAdministrationShellDescriptor} @@ -59,7 +63,7 @@ public class AasDescriptorFactory { public AasDescriptorFactory(AssetAdministrationShell shell, String aasRepositoryBaseURL, AttributeMapper attributeMapper) { super(); this.shell = shell; - this.aasRepositoryURL = createAasRepositoryUrl(aasRepositoryBaseURL); + this.aasRepositoryURL = Helper.createRepositoryUrl(aasRepositoryBaseURL, AAS_REPOSITORY_PATH); this.attributeMapper = attributeMapper; } @@ -191,23 +195,4 @@ private String getProtocol(String endpoint) { throw new RuntimeException(); } } - - public static String createAasRepositoryUrl(String aasRepositoryBaseURL) { - - try { - URL url = new URL(aasRepositoryBaseURL); - String path = url.getPath(); - - if (path.endsWith("/") && AAS_REPOSITORY_PATH.startsWith("/")) { - path = path.substring(0, path.length() - 1); - } else if (!path.endsWith("/") && !AAS_REPOSITORY_PATH.startsWith("/")) { - path += "/"; - } - - return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + AAS_REPOSITORY_PATH).toString(); - } catch (MalformedURLException e) { - throw new RuntimeException("The AAS Repository Base url is malformed.\n" + e.getMessage()); - } - } - } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java index f79eb2e8e..c7442a669 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java @@ -37,6 +37,7 @@ import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.GetAssetAdministrationShellDescriptorsResult; +import org.eclipse.digitaltwin.basyx.core.Helper; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; import org.eclipse.digitaltwin.basyx.http.serialization.BaSyxHttpTestUtils; import org.junit.Test; @@ -48,6 +49,7 @@ * @author danish */ public abstract class AasRepositoryRegistryLinkTestSuite { + private static final String AAS_REPOSITORY_PATH = "shells"; private static final String DUMMY_GLOBAL_ASSETID = "globalAssetId"; private static final String DUMMY_IDSHORT = "ExampleMotor"; @@ -117,10 +119,10 @@ private String getAas1JSONString() throws FileNotFoundException, IOException { } private CloseableHttpResponse createAasOnRepo(String aasJsonContent) throws IOException { - return BaSyxHttpTestUtils.executePostOnURL(AasDescriptorFactory.createAasRepositoryUrl(getAasRepoBaseUrl()), aasJsonContent); + return BaSyxHttpTestUtils.executePostOnURL(Helper.createRepositoryUrl(getAasRepoBaseUrl(), AAS_REPOSITORY_PATH), aasJsonContent); } private String getSpecificAasAccessURL(String aasId) { - return AasDescriptorFactory.createAasRepositoryUrl(getAasRepoBaseUrl()) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(aasId); + return Helper.createRepositoryUrl(getAasRepoBaseUrl(), AAS_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(aasId); } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java index 51b6acca2..b01be193d 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java @@ -32,6 +32,7 @@ import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Endpoint; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ProtocolInformation; +import org.eclipse.digitaltwin.basyx.core.Helper; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; /** @@ -41,6 +42,8 @@ * */ public class DummyAasDescriptorFactory { + private static final String AAS_REPOSITORY_PATH = "shells"; + public static AssetAdministrationShellDescriptor createDummyDescriptor(String aasId, String idShort, String globalAssetId, String aasRepoBaseUrl) { AssetAdministrationShellDescriptor descriptor = new AssetAdministrationShellDescriptor(); @@ -73,7 +76,7 @@ private static ProtocolInformation createProtocolInformation(String aasId, Strin } private static String createHref(String aasId, String aasRepoBaseUrl) { - return String.format("%s/%s", AasDescriptorFactory.createAasRepositoryUrl(aasRepoBaseUrl), Base64UrlEncodedIdentifier.encodeIdentifier(aasId)); + return String.format("%s/%s", Helper.createRepositoryUrl(aasRepoBaseUrl, AAS_REPOSITORY_PATH), Base64UrlEncodedIdentifier.encodeIdentifier(aasId)); } private static String getProtocol(String endpoint) { diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAasDescriptorFactory.java deleted file mode 100644 index b8ebc0ff6..000000000 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/TestAasDescriptorFactory.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class TestAasDescriptorFactory { - - private static final String AAS_REPO_URL = "http://localhost:8081"; - - private static final String AAS_REPOSITORY_PATH = "shells"; - - @Test - public void testUrlWithTrailingSlash() { - assertEquals(AAS_REPO_URL + "/" + AAS_REPOSITORY_PATH, AasDescriptorFactory.createAasRepositoryUrl(AAS_REPO_URL + "/")); - } - - @Test - public void testUrlWithoutTrailingSlash() { - assertEquals(AAS_REPO_URL + "/" + AAS_REPOSITORY_PATH , AasDescriptorFactory.createAasRepositoryUrl(AAS_REPO_URL)); - } - -} diff --git a/basyx.common/basyx.core/pom.xml b/basyx.common/basyx.core/pom.xml index e0c89f549..f7d0cb95b 100644 --- a/basyx.common/basyx.core/pom.xml +++ b/basyx.common/basyx.core/pom.xml @@ -18,6 +18,10 @@ org.springframework spring-context + + org.springframework + spring-web + org.springframework.boot spring-boot-starter diff --git a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/Helper.java b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/Helper.java new file mode 100644 index 000000000..d686f1bae --- /dev/null +++ b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/Helper.java @@ -0,0 +1,34 @@ +package org.eclipse.digitaltwin.basyx.core; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; + +import org.springframework.web.util.UriComponentsBuilder; + + +public class Helper { + + public static String createRepositoryUrl(String baseUrl, String additionalPath) { + try { + // Create a URI from the base URL + URI baseUri = new URI(baseUrl); + + // Use UriComponentsBuilder to construct the new URL + URI finalUri = UriComponentsBuilder.newInstance() + .scheme(baseUri.getScheme()) + .host(baseUri.getHost()) + .port(baseUri.getPort()) + .pathSegment(baseUri.getPath().replaceAll("^/|/$", "").split("/")) + .pathSegment(additionalPath.replaceAll("^/|/$", "").split("/")) + .build() + .toUri(); + + // Convert the URI to a URL and return its string representation + return finalUri.toURL().toString(); + } catch (URISyntaxException | MalformedURLException e) { + throw new RuntimeException("The Base URL or additional path is malformed.\n" + e.getMessage(), e); + } + } + +} diff --git a/basyx.common/basyx.core/src/test/java/org/eclipse/digitaltwin/basyx/core/TestHelper.java b/basyx.common/basyx.core/src/test/java/org/eclipse/digitaltwin/basyx/core/TestHelper.java new file mode 100644 index 000000000..0d505af46 --- /dev/null +++ b/basyx.common/basyx.core/src/test/java/org/eclipse/digitaltwin/basyx/core/TestHelper.java @@ -0,0 +1,33 @@ +package org.eclipse.digitaltwin.basyx.core; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class TestHelper { + +private static final String BASE_URL = "http://localhost:8081"; + + private static final String PATH = "shells"; + + @Test + public void testUrlWithTrailingSlashAndPathNameWithNoLeadingSlash() { + assertEquals(BASE_URL + "/" + PATH, Helper.createRepositoryUrl(BASE_URL + "/", PATH)); + } + + @Test + public void testUrlWithoutTrailingSlashAndPathNameWithNoLeadingSlash() { + assertEquals(BASE_URL + "/" + PATH , Helper.createRepositoryUrl(BASE_URL, PATH)); + } + + @Test + public void testUrlWithTrailingSlashAndPathNameWithLeadingSlash() { + assertEquals(BASE_URL + "/" + PATH, Helper.createRepositoryUrl(BASE_URL + "/", "/" + PATH)); + } + + @Test + public void testUrlWithoutTrailingSlashAndPathNameWithLeadingSlash() { + assertEquals(BASE_URL + "/" + PATH , Helper.createRepositoryUrl(BASE_URL, "/" + PATH)); + } + +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/TestAuthorizedSubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/TestAuthorizedSubmodelRepository.java index 0824f9652..a2773ad1b 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/TestAuthorizedSubmodelRepository.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/TestAuthorizedSubmodelRepository.java @@ -46,6 +46,7 @@ import org.eclipse.digitaltwin.basyx.authorization.DummyCredentialStore; import org.eclipse.digitaltwin.basyx.authorization.jwt.JwtTokenDecoder; import org.eclipse.digitaltwin.basyx.authorization.jwt.PublicKeyUtils; +import org.eclipse.digitaltwin.basyx.core.Helper; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; import org.eclipse.digitaltwin.basyx.http.serialization.BaSyxHttpTestUtils; import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepository; @@ -200,7 +201,7 @@ public void getSubmodelWithCorrectRoleAndSpecificSubmodelElementPermission() thr public void createSubmodelWithCorrectRoleAndPermission() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_CREATOR_CREDENTIAL); - CloseableHttpResponse retrievalResponse = createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), accessToken); + CloseableHttpResponse retrievalResponse = createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), accessToken); assertEquals(HttpStatus.CREATED.value(), retrievalResponse.getCode()); deleteElementWithAuthorization(getSpecificSubmodelAccessURL(SPECIFIC_SUBMODEL_ID_2), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); @@ -210,13 +211,13 @@ public void createSubmodelWithCorrectRoleAndPermission() throws IOException { public void createSubmodelWithInsufficientPermissionRole() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_READER_CREDENTIAL); - CloseableHttpResponse retrievalResponse = createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), accessToken); + CloseableHttpResponse retrievalResponse = createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @Test public void createSubmodelWithNoAuthorization() throws IOException { - CloseableHttpResponse retrievalResponse = createElementOnRepositoryWithNoAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON)); + CloseableHttpResponse retrievalResponse = createElementOnRepositoryWithNoAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON)); assertEquals(HttpStatus.UNAUTHORIZED.value(), retrievalResponse.getCode()); } @@ -262,7 +263,7 @@ public void updateSubmodelWithNoAuthorization() throws IOException { @Test public void deleteSubmodelWithCorrectRoleAndPermission() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); String accessToken = getAccessToken(DummyCredentialStore.BASYX_DELETER_CREDENTIAL); @@ -276,7 +277,7 @@ public void deleteSubmodelWithCorrectRoleAndPermission() throws IOException { @Test public void deleteSubmodelWithCorrectRoleAndSpecificSubmodelPermission() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); String accessToken = getAccessToken(DummyCredentialStore.BASYX_DELETER_TWO_CREDENTIAL); @@ -627,7 +628,7 @@ public void updateSubmodelElementWithNoAuthorization() throws IOException { @Test public void deleteSubmodelElementWithCorrectRoleAndPermission() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); String accessToken = getAccessToken(DummyCredentialStore.BASYX_UPDATER_CREDENTIAL); @@ -641,7 +642,7 @@ public void deleteSubmodelElementWithCorrectRoleAndPermission() throws IOExcepti @Test public void deleteSubmodelElementWithCorrectRoleAndSpecificSMEPermission() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); String accessToken = getAccessToken(DummyCredentialStore.BASYX_SME_UPDATER_THREE_CREDENTIAL); @@ -655,7 +656,7 @@ public void deleteSubmodelElementWithCorrectRoleAndSpecificSMEPermission() throw @Test public void deleteSubmodelElementWithCorrectRoleAndUnauthorizedSpecificSME() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); String accessToken = getAccessToken(DummyCredentialStore.BASYX_SME_UPDATER_THREE_CREDENTIAL); @@ -669,7 +670,7 @@ public void deleteSubmodelElementWithCorrectRoleAndUnauthorizedSpecificSME() thr @Test public void deleteSubmodelElementWithInsufficientPermissionRole() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); String accessToken = getAccessToken(DummyCredentialStore.BASYX_CREATOR_CREDENTIAL); @@ -683,7 +684,7 @@ public void deleteSubmodelElementWithInsufficientPermissionRole() throws IOExcep @Test public void deleteSubmodelElementWithNoAuthorization() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); CloseableHttpResponse retrievalResponse = deleteElementWithNoAuthorization(getSpecificSubmodelElementAccessURL(SPECIFIC_SUBMODEL_ID_2, SUBMODEL_ELEMENT_IDSHORT_PATH_2)); @@ -851,7 +852,7 @@ public void getSubmodelByMetadataWithNoAuthorization() throws IOException { @Test public void getFileWithCorrectRoleAndPermission() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -869,7 +870,7 @@ public void getFileWithCorrectRoleAndPermission() throws IOException { @Test public void getFileWithAuthorizedSpecificSubmodelAndSpecificSME() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -887,7 +888,7 @@ public void getFileWithAuthorizedSpecificSubmodelAndSpecificSME() throws IOExcep @Test public void getFileWithInsufficientPermissionRole() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -905,7 +906,7 @@ public void getFileWithInsufficientPermissionRole() throws IOException { @Test public void getFileWithUnauthorizedSpecificSME() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); DummyCredential dummyCredential = DummyCredentialStore.BASYX_FILE_SME_READER_CREDENTIAL; @@ -919,7 +920,7 @@ public void getFileWithUnauthorizedSpecificSME() throws IOException { @Test public void getFileWithNoAuthorization() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); CloseableHttpResponse retrievalResponse = getElementWithNoAuthorization(getSMEFileDownloadURL(SPECIFIC_SUBMODEL_ID_2, FILE_SUBMODEL_ELEMENT_IDSHORT_PATH)); assertEquals(HttpStatus.UNAUTHORIZED.value(), retrievalResponse.getCode()); @@ -929,7 +930,7 @@ public void getFileWithNoAuthorization() throws IOException { @Test public void setFileWithCorrectRoleAndPermission() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -945,7 +946,7 @@ public void setFileWithCorrectRoleAndPermission() throws IOException { @Test public void setFileWithAuthorizedSpecificSubmodelAndSpecificSME() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -961,7 +962,7 @@ public void setFileWithAuthorizedSpecificSubmodelAndSpecificSME() throws IOExcep @Test public void setFileWithInsufficientPermissionRole() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -977,7 +978,7 @@ public void setFileWithInsufficientPermissionRole() throws IOException { @Test public void setFileWithUnauthorizedSpecificSME() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -993,7 +994,7 @@ public void setFileWithUnauthorizedSpecificSME() throws IOException { @Test public void setFileWithNoAuthorization() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -1005,7 +1006,7 @@ public void setFileWithNoAuthorization() throws IOException { @Test public void deleteFileWithCorrectRoleAndPermission() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -1023,7 +1024,7 @@ public void deleteFileWithCorrectRoleAndPermission() throws IOException { @Test public void deleteFileWithAuthorizedSpecificSubmodelAndSpecificSME() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -1041,7 +1042,7 @@ public void deleteFileWithAuthorizedSpecificSubmodelAndSpecificSME() throws IOEx @Test public void deleteFileWithInsufficientPermissionRole() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -1059,7 +1060,7 @@ public void deleteFileWithInsufficientPermissionRole() throws IOException { @Test public void deleteFileWithUnauthorizedSpecificSME() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -1077,7 +1078,7 @@ public void deleteFileWithUnauthorizedSpecificSME() throws IOException { @Test public void deleteFileWithNoAuthorization() throws IOException { - createElementOnRepositoryWithAuthorization(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); CloseableHttpResponse retrievalResponse = deleteElementWithNoAuthorization(getSMEFileDownloadURL(SPECIFIC_SUBMODEL_ID_2, FILE_SUBMODEL_ELEMENT_IDSHORT_PATH)); assertEquals(HttpStatus.UNAUTHORIZED.value(), retrievalResponse.getCode()); @@ -1185,7 +1186,7 @@ private String getAccessToken(DummyCredential dummyCredential) { } private CloseableHttpResponse getAllSubmodelsWithAuthorization(String accessToken) throws IOException { - return BaSyxHttpTestUtils.executeAuthorizedGetOnURL(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl), accessToken); + return BaSyxHttpTestUtils.executeAuthorizedGetOnURL(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), accessToken); } private CloseableHttpResponse getAllSubmodelElementsWithAuthorization(String submodelId, String accessToken) throws IOException { @@ -1193,7 +1194,7 @@ private CloseableHttpResponse getAllSubmodelElementsWithAuthorization(String sub } private CloseableHttpResponse getAllSubmodelsNoAuthorization() throws IOException { - return BaSyxHttpTestUtils.executeGetOnURL(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl)); + return BaSyxHttpTestUtils.executeGetOnURL(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH)); } private CloseableHttpResponse getSpecificSubmodelElementNoAuthorization(String submodelId, String submodelElementIdShortPath) throws IOException { @@ -1217,7 +1218,7 @@ private CloseableHttpResponse getElementWithNoAuthorization(String url) throws I } private String getSpecificSubmodelAccessURL(String submodelId) { - return createSubmodelRepositoryUrl(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl)) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId); + return Helper.createRepositoryUrl(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), SUBMODEL_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId); } private String getSpecificSubmodelValueOnlyAccessURL(String submodelId) { @@ -1229,7 +1230,7 @@ private String getSpecificSubmodelMetadataAccessURL(String submodelId) { } private String getSpecificSubmodelElementAccessURL(String submodelId, String submodelElementIdShortPath) { - return createSubmodelRepositoryUrl(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl)) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId) + "/submodel-elements/" + submodelElementIdShortPath; + return Helper.createRepositoryUrl(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), SUBMODEL_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId) + "/submodel-elements/" + submodelElementIdShortPath; } private String getSpecificSubmodelElementValueAccessURL(String submodelId, String submodelElementIdShortPath) { @@ -1257,7 +1258,7 @@ private CloseableHttpResponse requestOperationInvocationNoAuthorization(String u } protected String getAllSubmodelElementsAccessURL(String submodelId) { - return createSubmodelRepositoryUrl(createSubmodelRepositoryUrl(submodelRepositoryBaseUrl)) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId) + "/submodel-elements"; + return Helper.createRepositoryUrl(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), SUBMODEL_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId) + "/submodel-elements"; } private static CloseableHttpResponse createElementOnRepositoryWithAuthorization(String url, String submodelJsonContent, String accessToken) throws IOException { @@ -1302,23 +1303,6 @@ private static String getAdminAccessToken() { return tokenProvider.getAccessToken(dummyCredential.getUsername(), dummyCredential.getPassword()); } - private static String createSubmodelRepositoryUrl(String submodelRepositoryBaseURL) { - try { - URL url = new URL(submodelRepositoryBaseURL); - String path = url.getPath(); - - if (path.endsWith("/") && SUBMODEL_REPOSITORY_PATH.startsWith("/")) { - path = path.substring(0, path.length() - 1); - } else if (!path.endsWith("/") && !SUBMODEL_REPOSITORY_PATH.startsWith("/")) { - path += "/"; - } - - return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); - } catch (MalformedURLException e) { - throw new RuntimeException("The Submodel Repository Base url is malformed.\n " + e.getMessage()); - } - } - private String getJSONValueAsString(String fileName) throws FileNotFoundException, IOException { return BaSyxHttpTestUtils.readJSONStringFromClasspath(fileName); } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java index 38996c0e0..89687a9b1 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java @@ -35,6 +35,7 @@ import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; import org.eclipse.digitaltwin.aas4j.v3.model.Reference; import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; +import org.eclipse.digitaltwin.basyx.core.Helper; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Endpoint; import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.ProtocolInformation; @@ -59,7 +60,7 @@ public class SubmodelDescriptorFactory { public SubmodelDescriptorFactory(Submodel submodel, String submodelRepositoryBaseURL, AttributeMapper attributeMapper) { super(); this.submodel = submodel; - this.submodelRepositoryURL = createSubmodelRepositoryUrl(submodelRepositoryBaseURL); + this.submodelRepositoryURL = Helper.createRepositoryUrl(submodelRepositoryBaseURL, SUBMODEL_REPOSITORY_PATH); this.attributeMapper = attributeMapper; } @@ -181,23 +182,4 @@ private String getProtocol(String endpoint) { throw new RuntimeException(); } } - - public static String createSubmodelRepositoryUrl(String submodelRepositoryBaseURL) { - - try { - URL url = new URL(submodelRepositoryBaseURL); - String path = url.getPath(); - - if (path.endsWith("/") && SUBMODEL_REPOSITORY_PATH.startsWith("/")) { - path = path.substring(0, path.length() - 1); - } else if (!path.endsWith("/") && !SUBMODEL_REPOSITORY_PATH.startsWith("/")) { - path += "/"; - } - - return new URL(url.getProtocol(), url.getHost(), url.getPort(), path + SUBMODEL_REPOSITORY_PATH).toString(); - } catch (MalformedURLException e) { - throw new RuntimeException("The Submodel Repository Base url is malformed.\n" + e.getMessage()); - } - } - } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java index 8a08b54ac..cb5d82c68 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java @@ -29,6 +29,7 @@ import java.net.URL; import java.util.Arrays; +import org.eclipse.digitaltwin.basyx.core.Helper; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Endpoint; import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Key; @@ -45,6 +46,8 @@ * */ public class DummySubmodelDescriptorFactory { + private static final String SUBMODEL_REPOSITORY_PATH = "submodels"; + public static SubmodelDescriptor createDummyDescriptor(String smId, String idShort, String smRepoBaseUrl, Reference semanticId) { SubmodelDescriptor descriptor = new SubmodelDescriptor(); @@ -80,7 +83,7 @@ private static ProtocolInformation createProtocolInformation(String smId, String } private static String createHref(String smId, String smRepoBaseUrl) { - return String.format("%s/%s", SubmodelDescriptorFactory.createSubmodelRepositoryUrl(smRepoBaseUrl), Base64UrlEncodedIdentifier.encodeIdentifier(smId)); + return String.format("%s/%s", Helper.createRepositoryUrl(smRepoBaseUrl, SUBMODEL_REPOSITORY_PATH), Base64UrlEncodedIdentifier.encodeIdentifier(smId)); } private static String getProtocol(String endpoint) { diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkTestSuite.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkTestSuite.java index 425ef96f5..c4f0985d3 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkTestSuite.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkTestSuite.java @@ -34,6 +34,7 @@ import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.hc.core5.http.ParseException; +import org.eclipse.digitaltwin.basyx.core.Helper; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; import org.eclipse.digitaltwin.basyx.http.serialization.BaSyxHttpTestUtils; import org.eclipse.digitaltwin.basyx.submodelregistry.client.ApiException; @@ -49,6 +50,8 @@ * @author danish */ public abstract class SubmodelRepositoryRegistryLinkTestSuite { + private static final String SUBMODEL_REPOSITORY_PATH = "submodels"; + private static final String DUMMY_SUBMODEL_IDSHORT = "TechnicalData"; private static final String DUMMY_SUBMODEL_ID = "7A7104BDAB57E184"; @@ -140,7 +143,7 @@ private String getExpectedSubmodel() throws FileNotFoundException, IOException { } private CloseableHttpResponse createSubmodelOnRepo(String submodelJsonContent) throws IOException { - return BaSyxHttpTestUtils.executePostOnURL(SubmodelDescriptorFactory.createSubmodelRepositoryUrl(getSubmodelRepoBaseUrl()), submodelJsonContent); + return BaSyxHttpTestUtils.executePostOnURL(Helper.createRepositoryUrl(getSubmodelRepoBaseUrl(), SUBMODEL_REPOSITORY_PATH), submodelJsonContent); } private CloseableHttpResponse createSubmodelElementOnRepo(String submodelElementJsonContent) throws IOException { @@ -150,6 +153,6 @@ private CloseableHttpResponse createSubmodelElementOnRepo(String submodelElement } private String getSpecificSubmodelAccessURL(String submodelId) { - return SubmodelDescriptorFactory.createSubmodelRepositoryUrl(getSubmodelRepoBaseUrl()) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId); + return Helper.createRepositoryUrl(getSubmodelRepoBaseUrl(), SUBMODEL_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId); } } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/TestSubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/TestSubmodelDescriptorFactory.java deleted file mode 100644 index cc2b8a293..000000000 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/TestSubmodelDescriptorFactory.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class TestSubmodelDescriptorFactory { - - private static final String SUBMODEL_REPO_URL = "http://localhost:8081"; - - private static final String SUBMODEL_REPOSITORY_PATH = "submodels"; - - @Test - public void testUrlWithTrailingSlash() { - assertEquals(SUBMODEL_REPO_URL + "/" + SUBMODEL_REPOSITORY_PATH, SubmodelDescriptorFactory.createSubmodelRepositoryUrl(SUBMODEL_REPO_URL + "/")); - } - - @Test - public void testUrlWithoutTrailingSlash() { - assertEquals(SUBMODEL_REPO_URL + "/" + SUBMODEL_REPOSITORY_PATH , SubmodelDescriptorFactory.createSubmodelRepositoryUrl(SUBMODEL_REPO_URL)); - } -} From da4b87b86ce30291c122872482431d4bf3a84be2 Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Thu, 1 Aug 2024 12:18:59 +0200 Subject: [PATCH 14/37] fix: RepositoryUrlHelper - add tests with context path in url --- .../TestAuthorizedAasRepository.java | 46 +++++++------- .../integration/AasDescriptorFactory.java | 4 +- .../AasRepositoryRegistryLinkTestSuite.java | 6 +- .../DummyAasDescriptorFactory.java | 4 +- .../{Helper.java => RepositoryUrlHelper.java} | 6 +- .../digitaltwin/basyx/core/TestHelper.java | 33 ---------- .../basyx/core/TestRepositoryUrlHelper.java | 55 ++++++++++++++++ .../TestAuthorizedSubmodelRepository.java | 62 +++++++++---------- .../SubmodelDescriptorFactory.java | 4 +- .../DummySubmodelDescriptorFactory.java | 4 +- ...bmodelRepositoryRegistryLinkTestSuite.java | 6 +- 11 files changed, 124 insertions(+), 106 deletions(-) rename basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/{Helper.java => RepositoryUrlHelper.java} (82%) delete mode 100644 basyx.common/basyx.core/src/test/java/org/eclipse/digitaltwin/basyx/core/TestHelper.java create mode 100644 basyx.common/basyx.core/src/test/java/org/eclipse/digitaltwin/basyx/core/TestRepositoryUrlHelper.java diff --git a/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java b/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java index 1981a134d..f516d5001 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java @@ -53,7 +53,7 @@ import org.eclipse.digitaltwin.basyx.authorization.DummyCredentialStore; import org.eclipse.digitaltwin.basyx.authorization.jwt.JwtTokenDecoder; import org.eclipse.digitaltwin.basyx.authorization.jwt.PublicKeyUtils; -import org.eclipse.digitaltwin.basyx.core.Helper; +import org.eclipse.digitaltwin.basyx.core.RepositoryUrlHelper; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; import org.eclipse.digitaltwin.basyx.http.serialization.BaSyxHttpTestUtils; import org.junit.AfterClass; @@ -530,10 +530,10 @@ public void getThumbnailWithCorrectRoleAndPermission() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_READER_CREDENTIAL); - CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test @@ -542,17 +542,17 @@ public void getThumbnailWithCorrectRoleAndSpecificAasPermission() throws IOExcep String accessToken = getAccessToken(DummyCredentialStore.BASYX_READER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test public void getThumbnailWithCorrectRoleAndUnauthorizedSpecificAas() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_READER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID_2), accessToken); + CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID_2), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @@ -560,13 +560,13 @@ public void getThumbnailWithCorrectRoleAndUnauthorizedSpecificAas() throws IOExc public void getThumbnailWithInsufficientPermissionRole() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_DELETER_CREDENTIAL); - CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @Test public void getThumbnailWithNoAuthorization() throws IOException { - CloseableHttpResponse retrievalResponse = getElementWithNoAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID)); + CloseableHttpResponse retrievalResponse = getElementWithNoAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID)); assertEquals(HttpStatus.UNAUTHORIZED.value(), retrievalResponse.getCode()); } @@ -578,7 +578,7 @@ public void setThumbnailWithCorrectRoleAndPermission() throws IOException { CloseableHttpResponse retrievalResponse = setThumbnailToAasWithAuthorization(SPECIFIC_SHELL_ID, accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test @@ -588,7 +588,7 @@ public void setThumbnailWithCorrectRoleAndSpecificAasPermission() throws IOExcep CloseableHttpResponse retrievalResponse = setThumbnailToAasWithAuthorization(SPECIFIC_SHELL_ID, accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test @@ -620,10 +620,10 @@ public void deleteThumbnailWithCorrectRoleAndPermission() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_ASSET_UPDATER_CREDENTIAL); - CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - assertElementIsNotOnServer(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + assertElementIsNotOnServer(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test @@ -634,10 +634,10 @@ public void deleteThumbnailWithCorrectRoleAndSpecificAasPermission() throws IOEx String accessToken = getAccessToken(DummyCredentialStore.BASYX_ASSET_UPDATER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID_2), accessToken); + CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID_2), accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - assertElementIsNotOnServer(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID_2), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + assertElementIsNotOnServer(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID_2), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); deleteElementWithAuthorization(getSpecificAasAccessURL(SPECIFIC_SHELL_ID_2), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @@ -645,7 +645,7 @@ public void deleteThumbnailWithCorrectRoleAndSpecificAasPermission() throws IOEx public void deleteThumbnailWithCorrectRoleAndUnauthorizedSpecificAas() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_ASSET_UPDATER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @@ -653,13 +653,13 @@ public void deleteThumbnailWithCorrectRoleAndUnauthorizedSpecificAas() throws IO public void deleteThumbnailWithInsufficientPermissionRole() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_CREATOR_CREDENTIAL); - CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @Test public void deleteThumbnailWithNoAuthorization() throws IOException { - CloseableHttpResponse retrievalResponse = deleteElementWithNoAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID)); + CloseableHttpResponse retrievalResponse = deleteElementWithNoAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID)); assertEquals(HttpStatus.UNAUTHORIZED.value(), retrievalResponse.getCode()); } @@ -717,11 +717,11 @@ private String getAccessToken(DummyCredential dummyCredential) { } protected CloseableHttpResponse getAllAasWithAuthorization(String accessToken) throws IOException { - return BaSyxHttpTestUtils.executeAuthorizedGetOnURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), accessToken); + return BaSyxHttpTestUtils.executeAuthorizedGetOnURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), accessToken); } protected CloseableHttpResponse getAllAasNoAuthorization() throws IOException { - return BaSyxHttpTestUtils.executeGetOnURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH)); + return BaSyxHttpTestUtils.executeGetOnURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH)); } protected CloseableHttpResponse getElementWithAuthorization(String url, String accessToken) throws IOException { @@ -733,11 +733,11 @@ protected CloseableHttpResponse getElementWithNoAuthorization(String url) throws } protected String getSpecificAasAccessURL(String shellId) { - return Helper.createRepositoryUrl(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), AAS_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(shellId); + return RepositoryUrlHelper.createRepositoryUrl(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), AAS_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(shellId); } private static CloseableHttpResponse createAasOnRepositoryWithAuthorization(String aasJsonContent, String accessToken) throws IOException { - return BaSyxHttpTestUtils.executeAuthorizedPostOnURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), aasJsonContent, accessToken); + return BaSyxHttpTestUtils.executeAuthorizedPostOnURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), aasJsonContent, accessToken); } private CloseableHttpResponse setThumbnailToAasWithAuthorization(String shellId, String accessToken) throws IOException { @@ -753,7 +753,7 @@ private CloseableHttpResponse setThumbnailToAasWithNoAuthorization(String shellI } private static CloseableHttpResponse createAasOnRepositoryWithNoAuthorization(String aasJsonContent) throws IOException { - return BaSyxHttpTestUtils.executePostOnURL(Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), aasJsonContent); + return BaSyxHttpTestUtils.executePostOnURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), aasJsonContent); } private CloseableHttpResponse updateElementWithAuthorizationPutRequest(String url, String aasJsonContent, String accessToken) throws IOException { @@ -813,6 +813,6 @@ private String getSpecificSubmodelReferenceUrl(String shellId, String submodelId private static String getThumbnailAccessURL(String aasId) { Base64UrlEncodedIdentifier identifier = new Base64UrlEncodedIdentifier(aasId); - return Helper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH) + "/" + identifier.getEncodedIdentifier() + "/asset-information/thumbnail"; + return RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH) + "/" + identifier.getEncodedIdentifier() + "/asset-information/thumbnail"; } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java index f6bab0874..0373551a8 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasDescriptorFactory.java @@ -41,7 +41,7 @@ import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Endpoint; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ProtocolInformation; import org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration.mapper.AttributeMapper; -import org.eclipse.digitaltwin.basyx.core.Helper; +import org.eclipse.digitaltwin.basyx.core.RepositoryUrlHelper; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; import org.springframework.web.util.UriComponentsBuilder; @@ -63,7 +63,7 @@ public class AasDescriptorFactory { public AasDescriptorFactory(AssetAdministrationShell shell, String aasRepositoryBaseURL, AttributeMapper attributeMapper) { super(); this.shell = shell; - this.aasRepositoryURL = Helper.createRepositoryUrl(aasRepositoryBaseURL, AAS_REPOSITORY_PATH); + this.aasRepositoryURL = RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseURL, AAS_REPOSITORY_PATH); this.attributeMapper = attributeMapper; } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java index c7442a669..f3cc3cd56 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java @@ -37,7 +37,7 @@ import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.GetAssetAdministrationShellDescriptorsResult; -import org.eclipse.digitaltwin.basyx.core.Helper; +import org.eclipse.digitaltwin.basyx.core.RepositoryUrlHelper; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; import org.eclipse.digitaltwin.basyx.http.serialization.BaSyxHttpTestUtils; import org.junit.Test; @@ -119,10 +119,10 @@ private String getAas1JSONString() throws FileNotFoundException, IOException { } private CloseableHttpResponse createAasOnRepo(String aasJsonContent) throws IOException { - return BaSyxHttpTestUtils.executePostOnURL(Helper.createRepositoryUrl(getAasRepoBaseUrl(), AAS_REPOSITORY_PATH), aasJsonContent); + return BaSyxHttpTestUtils.executePostOnURL(RepositoryUrlHelper.createRepositoryUrl(getAasRepoBaseUrl(), AAS_REPOSITORY_PATH), aasJsonContent); } private String getSpecificAasAccessURL(String aasId) { - return Helper.createRepositoryUrl(getAasRepoBaseUrl(), AAS_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(aasId); + return RepositoryUrlHelper.createRepositoryUrl(getAasRepoBaseUrl(), AAS_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(aasId); } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java index b01be193d..f7aaf50e1 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/DummyAasDescriptorFactory.java @@ -32,7 +32,7 @@ import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetKind; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Endpoint; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ProtocolInformation; -import org.eclipse.digitaltwin.basyx.core.Helper; +import org.eclipse.digitaltwin.basyx.core.RepositoryUrlHelper; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; /** @@ -76,7 +76,7 @@ private static ProtocolInformation createProtocolInformation(String aasId, Strin } private static String createHref(String aasId, String aasRepoBaseUrl) { - return String.format("%s/%s", Helper.createRepositoryUrl(aasRepoBaseUrl, AAS_REPOSITORY_PATH), Base64UrlEncodedIdentifier.encodeIdentifier(aasId)); + return String.format("%s/%s", RepositoryUrlHelper.createRepositoryUrl(aasRepoBaseUrl, AAS_REPOSITORY_PATH), Base64UrlEncodedIdentifier.encodeIdentifier(aasId)); } private static String getProtocol(String endpoint) { diff --git a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/Helper.java b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java similarity index 82% rename from basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/Helper.java rename to basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java index d686f1bae..eb33a3be8 100644 --- a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/Helper.java +++ b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java @@ -6,15 +6,12 @@ import org.springframework.web.util.UriComponentsBuilder; - -public class Helper { +public class RepositoryUrlHelper { public static String createRepositoryUrl(String baseUrl, String additionalPath) { try { - // Create a URI from the base URL URI baseUri = new URI(baseUrl); - // Use UriComponentsBuilder to construct the new URL URI finalUri = UriComponentsBuilder.newInstance() .scheme(baseUri.getScheme()) .host(baseUri.getHost()) @@ -24,7 +21,6 @@ public static String createRepositoryUrl(String baseUrl, String additionalPath) .build() .toUri(); - // Convert the URI to a URL and return its string representation return finalUri.toURL().toString(); } catch (URISyntaxException | MalformedURLException e) { throw new RuntimeException("The Base URL or additional path is malformed.\n" + e.getMessage(), e); diff --git a/basyx.common/basyx.core/src/test/java/org/eclipse/digitaltwin/basyx/core/TestHelper.java b/basyx.common/basyx.core/src/test/java/org/eclipse/digitaltwin/basyx/core/TestHelper.java deleted file mode 100644 index 0d505af46..000000000 --- a/basyx.common/basyx.core/src/test/java/org/eclipse/digitaltwin/basyx/core/TestHelper.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.eclipse.digitaltwin.basyx.core; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class TestHelper { - -private static final String BASE_URL = "http://localhost:8081"; - - private static final String PATH = "shells"; - - @Test - public void testUrlWithTrailingSlashAndPathNameWithNoLeadingSlash() { - assertEquals(BASE_URL + "/" + PATH, Helper.createRepositoryUrl(BASE_URL + "/", PATH)); - } - - @Test - public void testUrlWithoutTrailingSlashAndPathNameWithNoLeadingSlash() { - assertEquals(BASE_URL + "/" + PATH , Helper.createRepositoryUrl(BASE_URL, PATH)); - } - - @Test - public void testUrlWithTrailingSlashAndPathNameWithLeadingSlash() { - assertEquals(BASE_URL + "/" + PATH, Helper.createRepositoryUrl(BASE_URL + "/", "/" + PATH)); - } - - @Test - public void testUrlWithoutTrailingSlashAndPathNameWithLeadingSlash() { - assertEquals(BASE_URL + "/" + PATH , Helper.createRepositoryUrl(BASE_URL, "/" + PATH)); - } - -} diff --git a/basyx.common/basyx.core/src/test/java/org/eclipse/digitaltwin/basyx/core/TestRepositoryUrlHelper.java b/basyx.common/basyx.core/src/test/java/org/eclipse/digitaltwin/basyx/core/TestRepositoryUrlHelper.java new file mode 100644 index 000000000..7b9fdf570 --- /dev/null +++ b/basyx.common/basyx.core/src/test/java/org/eclipse/digitaltwin/basyx/core/TestRepositoryUrlHelper.java @@ -0,0 +1,55 @@ +package org.eclipse.digitaltwin.basyx.core; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class TestRepositoryUrlHelper { + + private static final String BASE_URL = "http://localhost:8081"; + private static final String BASE_URL_WITH_CONTEXT = "http://localhost:8081/context"; + private static final String ADDITIONAL_PATH = "shells"; + + private static final String EXPECTED_URL = BASE_URL + "/" + ADDITIONAL_PATH; + private static final String EXPECTED_URL_WITH_CONTEXT = BASE_URL_WITH_CONTEXT + "/" + ADDITIONAL_PATH; + + @Test + public void testUrlWithTrailingSlashAndPathNameWithNoLeadingSlash() { + assertEquals(EXPECTED_URL, RepositoryUrlHelper.createRepositoryUrl(BASE_URL + "/", ADDITIONAL_PATH)); + } + + @Test + public void testUrlWithoutTrailingSlashAndPathNameWithNoLeadingSlash() { + assertEquals(EXPECTED_URL, RepositoryUrlHelper.createRepositoryUrl(BASE_URL, ADDITIONAL_PATH)); + } + + @Test + public void testUrlWithTrailingSlashAndPathNameWithLeadingSlash() { + assertEquals(EXPECTED_URL, RepositoryUrlHelper.createRepositoryUrl(BASE_URL + "/", "/" + ADDITIONAL_PATH)); + } + + @Test + public void testUrlWithoutTrailingSlashAndPathNameWithLeadingSlash() { + assertEquals(EXPECTED_URL, RepositoryUrlHelper.createRepositoryUrl(BASE_URL, "/" + ADDITIONAL_PATH)); + } + + @Test + public void testUrlWithContextAndTrailingSlashAndPathNameWithLeadingSlash() { + assertEquals(EXPECTED_URL_WITH_CONTEXT, RepositoryUrlHelper.createRepositoryUrl(BASE_URL_WITH_CONTEXT + "/", "/" + ADDITIONAL_PATH)); + } + + @Test + public void testUrlWithContextAndNoTrailingSlashAndPathNameWithLeadingSlash() { + assertEquals(EXPECTED_URL_WITH_CONTEXT, RepositoryUrlHelper.createRepositoryUrl(BASE_URL_WITH_CONTEXT, "/" + ADDITIONAL_PATH)); + } + + @Test + public void testUrlWithContextAndTrailingSlashAndPathNameWithNoLeadingSlash() { + assertEquals(EXPECTED_URL_WITH_CONTEXT, RepositoryUrlHelper.createRepositoryUrl(BASE_URL_WITH_CONTEXT + "/", ADDITIONAL_PATH)); + } + + @Test + public void testUrlWithContextAndNoTrailingSlashAndPathNameWithNoLeadingSlash() { + assertEquals(EXPECTED_URL_WITH_CONTEXT, RepositoryUrlHelper.createRepositoryUrl(BASE_URL_WITH_CONTEXT, ADDITIONAL_PATH)); + } +} diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/TestAuthorizedSubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/TestAuthorizedSubmodelRepository.java index a2773ad1b..b98819c6a 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/TestAuthorizedSubmodelRepository.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/TestAuthorizedSubmodelRepository.java @@ -46,7 +46,7 @@ import org.eclipse.digitaltwin.basyx.authorization.DummyCredentialStore; import org.eclipse.digitaltwin.basyx.authorization.jwt.JwtTokenDecoder; import org.eclipse.digitaltwin.basyx.authorization.jwt.PublicKeyUtils; -import org.eclipse.digitaltwin.basyx.core.Helper; +import org.eclipse.digitaltwin.basyx.core.RepositoryUrlHelper; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; import org.eclipse.digitaltwin.basyx.http.serialization.BaSyxHttpTestUtils; import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepository; @@ -201,7 +201,7 @@ public void getSubmodelWithCorrectRoleAndSpecificSubmodelElementPermission() thr public void createSubmodelWithCorrectRoleAndPermission() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_CREATOR_CREDENTIAL); - CloseableHttpResponse retrievalResponse = createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), accessToken); + CloseableHttpResponse retrievalResponse = createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), accessToken); assertEquals(HttpStatus.CREATED.value(), retrievalResponse.getCode()); deleteElementWithAuthorization(getSpecificSubmodelAccessURL(SPECIFIC_SUBMODEL_ID_2), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); @@ -211,13 +211,13 @@ public void createSubmodelWithCorrectRoleAndPermission() throws IOException { public void createSubmodelWithInsufficientPermissionRole() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_READER_CREDENTIAL); - CloseableHttpResponse retrievalResponse = createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), accessToken); + CloseableHttpResponse retrievalResponse = createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @Test public void createSubmodelWithNoAuthorization() throws IOException { - CloseableHttpResponse retrievalResponse = createElementOnRepositoryWithNoAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON)); + CloseableHttpResponse retrievalResponse = createElementOnRepositoryWithNoAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON)); assertEquals(HttpStatus.UNAUTHORIZED.value(), retrievalResponse.getCode()); } @@ -263,7 +263,7 @@ public void updateSubmodelWithNoAuthorization() throws IOException { @Test public void deleteSubmodelWithCorrectRoleAndPermission() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); String accessToken = getAccessToken(DummyCredentialStore.BASYX_DELETER_CREDENTIAL); @@ -277,7 +277,7 @@ public void deleteSubmodelWithCorrectRoleAndPermission() throws IOException { @Test public void deleteSubmodelWithCorrectRoleAndSpecificSubmodelPermission() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); String accessToken = getAccessToken(DummyCredentialStore.BASYX_DELETER_TWO_CREDENTIAL); @@ -628,7 +628,7 @@ public void updateSubmodelElementWithNoAuthorization() throws IOException { @Test public void deleteSubmodelElementWithCorrectRoleAndPermission() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); String accessToken = getAccessToken(DummyCredentialStore.BASYX_UPDATER_CREDENTIAL); @@ -642,7 +642,7 @@ public void deleteSubmodelElementWithCorrectRoleAndPermission() throws IOExcepti @Test public void deleteSubmodelElementWithCorrectRoleAndSpecificSMEPermission() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); String accessToken = getAccessToken(DummyCredentialStore.BASYX_SME_UPDATER_THREE_CREDENTIAL); @@ -656,7 +656,7 @@ public void deleteSubmodelElementWithCorrectRoleAndSpecificSMEPermission() throw @Test public void deleteSubmodelElementWithCorrectRoleAndUnauthorizedSpecificSME() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); String accessToken = getAccessToken(DummyCredentialStore.BASYX_SME_UPDATER_THREE_CREDENTIAL); @@ -670,7 +670,7 @@ public void deleteSubmodelElementWithCorrectRoleAndUnauthorizedSpecificSME() thr @Test public void deleteSubmodelElementWithInsufficientPermissionRole() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); String accessToken = getAccessToken(DummyCredentialStore.BASYX_CREATOR_CREDENTIAL); @@ -684,7 +684,7 @@ public void deleteSubmodelElementWithInsufficientPermissionRole() throws IOExcep @Test public void deleteSubmodelElementWithNoAuthorization() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); CloseableHttpResponse retrievalResponse = deleteElementWithNoAuthorization(getSpecificSubmodelElementAccessURL(SPECIFIC_SUBMODEL_ID_2, SUBMODEL_ELEMENT_IDSHORT_PATH_2)); @@ -852,7 +852,7 @@ public void getSubmodelByMetadataWithNoAuthorization() throws IOException { @Test public void getFileWithCorrectRoleAndPermission() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -870,7 +870,7 @@ public void getFileWithCorrectRoleAndPermission() throws IOException { @Test public void getFileWithAuthorizedSpecificSubmodelAndSpecificSME() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -888,7 +888,7 @@ public void getFileWithAuthorizedSpecificSubmodelAndSpecificSME() throws IOExcep @Test public void getFileWithInsufficientPermissionRole() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -906,7 +906,7 @@ public void getFileWithInsufficientPermissionRole() throws IOException { @Test public void getFileWithUnauthorizedSpecificSME() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); DummyCredential dummyCredential = DummyCredentialStore.BASYX_FILE_SME_READER_CREDENTIAL; @@ -920,7 +920,7 @@ public void getFileWithUnauthorizedSpecificSME() throws IOException { @Test public void getFileWithNoAuthorization() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); CloseableHttpResponse retrievalResponse = getElementWithNoAuthorization(getSMEFileDownloadURL(SPECIFIC_SUBMODEL_ID_2, FILE_SUBMODEL_ELEMENT_IDSHORT_PATH)); assertEquals(HttpStatus.UNAUTHORIZED.value(), retrievalResponse.getCode()); @@ -930,7 +930,7 @@ public void getFileWithNoAuthorization() throws IOException { @Test public void setFileWithCorrectRoleAndPermission() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -946,7 +946,7 @@ public void setFileWithCorrectRoleAndPermission() throws IOException { @Test public void setFileWithAuthorizedSpecificSubmodelAndSpecificSME() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -962,7 +962,7 @@ public void setFileWithAuthorizedSpecificSubmodelAndSpecificSME() throws IOExcep @Test public void setFileWithInsufficientPermissionRole() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -978,7 +978,7 @@ public void setFileWithInsufficientPermissionRole() throws IOException { @Test public void setFileWithUnauthorizedSpecificSME() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -994,7 +994,7 @@ public void setFileWithUnauthorizedSpecificSME() throws IOException { @Test public void setFileWithNoAuthorization() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -1006,7 +1006,7 @@ public void setFileWithNoAuthorization() throws IOException { @Test public void deleteFileWithCorrectRoleAndPermission() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -1024,7 +1024,7 @@ public void deleteFileWithCorrectRoleAndPermission() throws IOException { @Test public void deleteFileWithAuthorizedSpecificSubmodelAndSpecificSME() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -1042,7 +1042,7 @@ public void deleteFileWithAuthorizedSpecificSubmodelAndSpecificSME() throws IOEx @Test public void deleteFileWithInsufficientPermissionRole() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -1060,7 +1060,7 @@ public void deleteFileWithInsufficientPermissionRole() throws IOException { @Test public void deleteFileWithUnauthorizedSpecificSME() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); java.io.File file = ResourceUtils.getFile("classpath:" + FILE_NAME); @@ -1078,7 +1078,7 @@ public void deleteFileWithUnauthorizedSpecificSME() throws IOException { @Test public void deleteFileWithNoAuthorization() throws IOException { - createElementOnRepositoryWithAuthorization(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + createElementOnRepositoryWithAuthorization(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), getStringFromFile(SUBMODEL_SIMPLE_2_JSON), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); CloseableHttpResponse retrievalResponse = deleteElementWithNoAuthorization(getSMEFileDownloadURL(SPECIFIC_SUBMODEL_ID_2, FILE_SUBMODEL_ELEMENT_IDSHORT_PATH)); assertEquals(HttpStatus.UNAUTHORIZED.value(), retrievalResponse.getCode()); @@ -1186,7 +1186,7 @@ private String getAccessToken(DummyCredential dummyCredential) { } private CloseableHttpResponse getAllSubmodelsWithAuthorization(String accessToken) throws IOException { - return BaSyxHttpTestUtils.executeAuthorizedGetOnURL(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), accessToken); + return BaSyxHttpTestUtils.executeAuthorizedGetOnURL(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), accessToken); } private CloseableHttpResponse getAllSubmodelElementsWithAuthorization(String submodelId, String accessToken) throws IOException { @@ -1194,7 +1194,7 @@ private CloseableHttpResponse getAllSubmodelElementsWithAuthorization(String sub } private CloseableHttpResponse getAllSubmodelsNoAuthorization() throws IOException { - return BaSyxHttpTestUtils.executeGetOnURL(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH)); + return BaSyxHttpTestUtils.executeGetOnURL(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH)); } private CloseableHttpResponse getSpecificSubmodelElementNoAuthorization(String submodelId, String submodelElementIdShortPath) throws IOException { @@ -1218,7 +1218,7 @@ private CloseableHttpResponse getElementWithNoAuthorization(String url) throws I } private String getSpecificSubmodelAccessURL(String submodelId) { - return Helper.createRepositoryUrl(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), SUBMODEL_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId); + return RepositoryUrlHelper.createRepositoryUrl(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), SUBMODEL_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId); } private String getSpecificSubmodelValueOnlyAccessURL(String submodelId) { @@ -1230,7 +1230,7 @@ private String getSpecificSubmodelMetadataAccessURL(String submodelId) { } private String getSpecificSubmodelElementAccessURL(String submodelId, String submodelElementIdShortPath) { - return Helper.createRepositoryUrl(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), SUBMODEL_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId) + "/submodel-elements/" + submodelElementIdShortPath; + return RepositoryUrlHelper.createRepositoryUrl(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), SUBMODEL_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId) + "/submodel-elements/" + submodelElementIdShortPath; } private String getSpecificSubmodelElementValueAccessURL(String submodelId, String submodelElementIdShortPath) { @@ -1258,7 +1258,7 @@ private CloseableHttpResponse requestOperationInvocationNoAuthorization(String u } protected String getAllSubmodelElementsAccessURL(String submodelId) { - return Helper.createRepositoryUrl(Helper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), SUBMODEL_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId) + "/submodel-elements"; + return RepositoryUrlHelper.createRepositoryUrl(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), SUBMODEL_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId) + "/submodel-elements"; } private static CloseableHttpResponse createElementOnRepositoryWithAuthorization(String url, String submodelJsonContent, String accessToken) throws IOException { diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java index 89687a9b1..d758275f0 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelDescriptorFactory.java @@ -35,7 +35,7 @@ import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; import org.eclipse.digitaltwin.aas4j.v3.model.Reference; import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; -import org.eclipse.digitaltwin.basyx.core.Helper; +import org.eclipse.digitaltwin.basyx.core.RepositoryUrlHelper; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Endpoint; import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.ProtocolInformation; @@ -60,7 +60,7 @@ public class SubmodelDescriptorFactory { public SubmodelDescriptorFactory(Submodel submodel, String submodelRepositoryBaseURL, AttributeMapper attributeMapper) { super(); this.submodel = submodel; - this.submodelRepositoryURL = Helper.createRepositoryUrl(submodelRepositoryBaseURL, SUBMODEL_REPOSITORY_PATH); + this.submodelRepositoryURL = RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseURL, SUBMODEL_REPOSITORY_PATH); this.attributeMapper = attributeMapper; } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java index cb5d82c68..e23dce5f2 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/DummySubmodelDescriptorFactory.java @@ -29,7 +29,7 @@ import java.net.URL; import java.util.Arrays; -import org.eclipse.digitaltwin.basyx.core.Helper; +import org.eclipse.digitaltwin.basyx.core.RepositoryUrlHelper; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Endpoint; import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Key; @@ -83,7 +83,7 @@ private static ProtocolInformation createProtocolInformation(String smId, String } private static String createHref(String smId, String smRepoBaseUrl) { - return String.format("%s/%s", Helper.createRepositoryUrl(smRepoBaseUrl, SUBMODEL_REPOSITORY_PATH), Base64UrlEncodedIdentifier.encodeIdentifier(smId)); + return String.format("%s/%s", RepositoryUrlHelper.createRepositoryUrl(smRepoBaseUrl, SUBMODEL_REPOSITORY_PATH), Base64UrlEncodedIdentifier.encodeIdentifier(smId)); } private static String getProtocol(String endpoint) { diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkTestSuite.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkTestSuite.java index c4f0985d3..ea1e368bc 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkTestSuite.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkTestSuite.java @@ -34,7 +34,7 @@ import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.hc.core5.http.ParseException; -import org.eclipse.digitaltwin.basyx.core.Helper; +import org.eclipse.digitaltwin.basyx.core.RepositoryUrlHelper; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; import org.eclipse.digitaltwin.basyx.http.serialization.BaSyxHttpTestUtils; import org.eclipse.digitaltwin.basyx.submodelregistry.client.ApiException; @@ -143,7 +143,7 @@ private String getExpectedSubmodel() throws FileNotFoundException, IOException { } private CloseableHttpResponse createSubmodelOnRepo(String submodelJsonContent) throws IOException { - return BaSyxHttpTestUtils.executePostOnURL(Helper.createRepositoryUrl(getSubmodelRepoBaseUrl(), SUBMODEL_REPOSITORY_PATH), submodelJsonContent); + return BaSyxHttpTestUtils.executePostOnURL(RepositoryUrlHelper.createRepositoryUrl(getSubmodelRepoBaseUrl(), SUBMODEL_REPOSITORY_PATH), submodelJsonContent); } private CloseableHttpResponse createSubmodelElementOnRepo(String submodelElementJsonContent) throws IOException { @@ -153,6 +153,6 @@ private CloseableHttpResponse createSubmodelElementOnRepo(String submodelElement } private String getSpecificSubmodelAccessURL(String submodelId) { - return Helper.createRepositoryUrl(getSubmodelRepoBaseUrl(), SUBMODEL_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId); + return RepositoryUrlHelper.createRepositoryUrl(getSubmodelRepoBaseUrl(), SUBMODEL_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId); } } From 3306f65a9d86f3b1cc05c26beeec8ffe19b5bbe6 Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Thu, 1 Aug 2024 12:23:21 +0200 Subject: [PATCH 15/37] refactor: reformat RepositoryUrlHelper + Test --- .../basyx/core/RepositoryUrlHelper.java | 29 +++---- .../basyx/core/TestRepositoryUrlHelper.java | 80 ++++++++++--------- 2 files changed, 54 insertions(+), 55 deletions(-) diff --git a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java index eb33a3be8..e5abea3f6 100644 --- a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java +++ b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java @@ -9,22 +9,17 @@ public class RepositoryUrlHelper { public static String createRepositoryUrl(String baseUrl, String additionalPath) { - try { - URI baseUri = new URI(baseUrl); - - URI finalUri = UriComponentsBuilder.newInstance() - .scheme(baseUri.getScheme()) - .host(baseUri.getHost()) - .port(baseUri.getPort()) - .pathSegment(baseUri.getPath().replaceAll("^/|/$", "").split("/")) - .pathSegment(additionalPath.replaceAll("^/|/$", "").split("/")) - .build() - .toUri(); - - return finalUri.toURL().toString(); - } catch (URISyntaxException | MalformedURLException e) { - throw new RuntimeException("The Base URL or additional path is malformed.\n" + e.getMessage(), e); - } + try { + URI baseUri = new URI(baseUrl); + + URI finalUri = UriComponentsBuilder.newInstance().scheme(baseUri.getScheme()).host(baseUri.getHost()) + .port(baseUri.getPort()).pathSegment(baseUri.getPath().replaceAll("^/|/$", "").split("/")) + .pathSegment(additionalPath.replaceAll("^/|/$", "").split("/")).build().toUri(); + + return finalUri.toURL().toString(); + } catch (URISyntaxException | MalformedURLException e) { + throw new RuntimeException("The Base URL or additional path is malformed.\n" + e.getMessage(), e); + } } - + } diff --git a/basyx.common/basyx.core/src/test/java/org/eclipse/digitaltwin/basyx/core/TestRepositoryUrlHelper.java b/basyx.common/basyx.core/src/test/java/org/eclipse/digitaltwin/basyx/core/TestRepositoryUrlHelper.java index 7b9fdf570..aa2de783d 100644 --- a/basyx.common/basyx.core/src/test/java/org/eclipse/digitaltwin/basyx/core/TestRepositoryUrlHelper.java +++ b/basyx.common/basyx.core/src/test/java/org/eclipse/digitaltwin/basyx/core/TestRepositoryUrlHelper.java @@ -9,47 +9,51 @@ public class TestRepositoryUrlHelper { private static final String BASE_URL = "http://localhost:8081"; private static final String BASE_URL_WITH_CONTEXT = "http://localhost:8081/context"; private static final String ADDITIONAL_PATH = "shells"; - + private static final String EXPECTED_URL = BASE_URL + "/" + ADDITIONAL_PATH; private static final String EXPECTED_URL_WITH_CONTEXT = BASE_URL_WITH_CONTEXT + "/" + ADDITIONAL_PATH; @Test - public void testUrlWithTrailingSlashAndPathNameWithNoLeadingSlash() { + public void testUrlWithTrailingSlashAndPathNameWithNoLeadingSlash() { assertEquals(EXPECTED_URL, RepositoryUrlHelper.createRepositoryUrl(BASE_URL + "/", ADDITIONAL_PATH)); - } - - @Test - public void testUrlWithoutTrailingSlashAndPathNameWithNoLeadingSlash() { - assertEquals(EXPECTED_URL, RepositoryUrlHelper.createRepositoryUrl(BASE_URL, ADDITIONAL_PATH)); - } - - @Test - public void testUrlWithTrailingSlashAndPathNameWithLeadingSlash() { - assertEquals(EXPECTED_URL, RepositoryUrlHelper.createRepositoryUrl(BASE_URL + "/", "/" + ADDITIONAL_PATH)); - } - - @Test - public void testUrlWithoutTrailingSlashAndPathNameWithLeadingSlash() { - assertEquals(EXPECTED_URL, RepositoryUrlHelper.createRepositoryUrl(BASE_URL, "/" + ADDITIONAL_PATH)); - } - - @Test - public void testUrlWithContextAndTrailingSlashAndPathNameWithLeadingSlash() { - assertEquals(EXPECTED_URL_WITH_CONTEXT, RepositoryUrlHelper.createRepositoryUrl(BASE_URL_WITH_CONTEXT + "/", "/" + ADDITIONAL_PATH)); - } - - @Test - public void testUrlWithContextAndNoTrailingSlashAndPathNameWithLeadingSlash() { - assertEquals(EXPECTED_URL_WITH_CONTEXT, RepositoryUrlHelper.createRepositoryUrl(BASE_URL_WITH_CONTEXT, "/" + ADDITIONAL_PATH)); - } - - @Test - public void testUrlWithContextAndTrailingSlashAndPathNameWithNoLeadingSlash() { - assertEquals(EXPECTED_URL_WITH_CONTEXT, RepositoryUrlHelper.createRepositoryUrl(BASE_URL_WITH_CONTEXT + "/", ADDITIONAL_PATH)); - } - - @Test - public void testUrlWithContextAndNoTrailingSlashAndPathNameWithNoLeadingSlash() { - assertEquals(EXPECTED_URL_WITH_CONTEXT, RepositoryUrlHelper.createRepositoryUrl(BASE_URL_WITH_CONTEXT, ADDITIONAL_PATH)); - } + } + + @Test + public void testUrlWithoutTrailingSlashAndPathNameWithNoLeadingSlash() { + assertEquals(EXPECTED_URL, RepositoryUrlHelper.createRepositoryUrl(BASE_URL, ADDITIONAL_PATH)); + } + + @Test + public void testUrlWithTrailingSlashAndPathNameWithLeadingSlash() { + assertEquals(EXPECTED_URL, RepositoryUrlHelper.createRepositoryUrl(BASE_URL + "/", "/" + ADDITIONAL_PATH)); + } + + @Test + public void testUrlWithoutTrailingSlashAndPathNameWithLeadingSlash() { + assertEquals(EXPECTED_URL, RepositoryUrlHelper.createRepositoryUrl(BASE_URL, "/" + ADDITIONAL_PATH)); + } + + @Test + public void testUrlWithContextAndTrailingSlashAndPathNameWithLeadingSlash() { + assertEquals(EXPECTED_URL_WITH_CONTEXT, + RepositoryUrlHelper.createRepositoryUrl(BASE_URL_WITH_CONTEXT + "/", "/" + ADDITIONAL_PATH)); + } + + @Test + public void testUrlWithContextAndNoTrailingSlashAndPathNameWithLeadingSlash() { + assertEquals(EXPECTED_URL_WITH_CONTEXT, + RepositoryUrlHelper.createRepositoryUrl(BASE_URL_WITH_CONTEXT, "/" + ADDITIONAL_PATH)); + } + + @Test + public void testUrlWithContextAndTrailingSlashAndPathNameWithNoLeadingSlash() { + assertEquals(EXPECTED_URL_WITH_CONTEXT, + RepositoryUrlHelper.createRepositoryUrl(BASE_URL_WITH_CONTEXT + "/", ADDITIONAL_PATH)); + } + + @Test + public void testUrlWithContextAndNoTrailingSlashAndPathNameWithNoLeadingSlash() { + assertEquals(EXPECTED_URL_WITH_CONTEXT, + RepositoryUrlHelper.createRepositoryUrl(BASE_URL_WITH_CONTEXT, ADDITIONAL_PATH)); + } } From 7b303c4bec365a8e7cbd0cfaba6c2306a61df3a6 Mon Sep 17 00:00:00 2001 From: Mateus Molina Date: Tue, 27 Aug 2024 09:06:27 +0200 Subject: [PATCH 16/37] Empty commit to trigger the CI --- .../aasregistry/main/client/factory/AasDescriptorFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basyx.aasregistry/basyx.aasregistry-client-native/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/main/client/factory/AasDescriptorFactory.java b/basyx.aasregistry/basyx.aasregistry-client-native/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/main/client/factory/AasDescriptorFactory.java index 2e08b3d94..0e1e6bdd2 100644 --- a/basyx.aasregistry/basyx.aasregistry-client-native/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/main/client/factory/AasDescriptorFactory.java +++ b/basyx.aasregistry/basyx.aasregistry-client-native/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/main/client/factory/AasDescriptorFactory.java @@ -40,7 +40,7 @@ import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Endpoint; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ProtocolInformation; import org.eclipse.digitaltwin.basyx.aasregistry.main.client.mapper.AttributeMapper; -import org.eclipse.digitaltwin.basyx.core.RepositoryUrlHelper; +import org.eclipse.digitaltwin.basyx.core.RepositoryUrlHelper; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; /** From bcdef6ea660c90a38422e3e68a4a33db53770dbb Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Mon, 2 Sep 2024 15:24:52 +0200 Subject: [PATCH 17/37] fix: refactor utility url functions --- .../authorization/TestAuthorizedSubmodelRepository.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/TestAuthorizedSubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/TestAuthorizedSubmodelRepository.java index 21a874813..b65f1e8ce 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/TestAuthorizedSubmodelRepository.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/authorization/TestAuthorizedSubmodelRepository.java @@ -425,7 +425,7 @@ public void getSubmodelElementValueWithCorrectRoleAndPermission() throws IOExcep DummyCredential dummyCredential = DummyCredentialStore.BASYX_READER_CREDENTIAL; String accessToken = tokenProvider.getAccessToken(dummyCredential.getUsername(), dummyCredential.getPassword()); - + CloseableHttpResponse retrievalResponse = getElementWithAuthorization(getSpecificSubmodelElementValueAccessURL(SPECIFIC_SUBMODEL_ID, SUBMODEL_ELEMENT_IDSHORT_PATH), accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); } @@ -1218,7 +1218,7 @@ private CloseableHttpResponse getElementWithNoAuthorization(String url) throws I } private String getSpecificSubmodelAccessURL(String submodelId) { - return RepositoryUrlHelper.createRepositoryUrl(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), SUBMODEL_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId); + return RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId); } private String getSpecificSubmodelValueOnlyAccessURL(String submodelId) { @@ -1230,7 +1230,7 @@ private String getSpecificSubmodelMetadataAccessURL(String submodelId) { } private String getSpecificSubmodelElementAccessURL(String submodelId, String submodelElementIdShortPath) { - return RepositoryUrlHelper.createRepositoryUrl(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), SUBMODEL_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId) + "/submodel-elements/" + submodelElementIdShortPath; + return RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId) + "/submodel-elements/" + submodelElementIdShortPath; } private String getSpecificSubmodelElementValueAccessURL(String submodelId, String submodelElementIdShortPath) { @@ -1258,7 +1258,7 @@ private CloseableHttpResponse requestOperationInvocationNoAuthorization(String u } protected String getAllSubmodelElementsAccessURL(String submodelId) { - return RepositoryUrlHelper.createRepositoryUrl(RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH), SUBMODEL_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId) + "/submodel-elements"; + return RepositoryUrlHelper.createRepositoryUrl(submodelRepositoryBaseUrl, SUBMODEL_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(submodelId) + "/submodel-elements"; } private static CloseableHttpResponse createElementOnRepositoryWithAuthorization(String url, String submodelJsonContent, String accessToken) throws IOException { From d30b22800e4d23f3e1aab2c2a8dc4c326aa7c36a Mon Sep 17 00:00:00 2001 From: Mateus Molina Date: Tue, 3 Sep 2024 08:22:00 +0200 Subject: [PATCH 18/37] Triggering the CI --- .../aasregistry/main/client/factory/AasDescriptorFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basyx.aasregistry/basyx.aasregistry-client-native/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/main/client/factory/AasDescriptorFactory.java b/basyx.aasregistry/basyx.aasregistry-client-native/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/main/client/factory/AasDescriptorFactory.java index 0e1e6bdd2..2e08b3d94 100644 --- a/basyx.aasregistry/basyx.aasregistry-client-native/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/main/client/factory/AasDescriptorFactory.java +++ b/basyx.aasregistry/basyx.aasregistry-client-native/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/main/client/factory/AasDescriptorFactory.java @@ -40,7 +40,7 @@ import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Endpoint; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.ProtocolInformation; import org.eclipse.digitaltwin.basyx.aasregistry.main.client.mapper.AttributeMapper; -import org.eclipse.digitaltwin.basyx.core.RepositoryUrlHelper; +import org.eclipse.digitaltwin.basyx.core.RepositoryUrlHelper; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; /** From 37bc55ecc3379f8e4e575abe289a8c9ccd8bcb49 Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Tue, 3 Sep 2024 10:34:51 +0200 Subject: [PATCH 19/37] fix: aas repository feature auth url function fix --- .../TestAuthorizedAasRepository.java | 46 +++++++++---------- .../basyx/core/RepositoryUrlHelper.java | 2 +- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java b/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java index 92033b70b..867b85266 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java @@ -74,7 +74,7 @@ */ public class TestAuthorizedAasRepository { - private static final String AAS_REPOSITORY_PATH = "/shells"; +// private static final String AAS_REPOSITORY_PATH = "/shells"; private static final String AAS_SIMPLE_2_JSON = "authorization/AasSimple_2.json"; private static final String AAS_SIMPLE_1_JSON = "authorization/AasSimple_1.json"; private static final String SPECIFIC_SHELL_ID_2 = "specificAasId-2"; @@ -530,10 +530,10 @@ public void getThumbnailWithCorrectRoleAndPermission() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_READER_CREDENTIAL); - CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test @@ -542,17 +542,17 @@ public void getThumbnailWithCorrectRoleAndSpecificAasPermission() throws IOExcep String accessToken = getAccessToken(DummyCredentialStore.BASYX_READER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test public void getThumbnailWithCorrectRoleAndUnauthorizedSpecificAas() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_READER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID_2), accessToken); + CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID_2), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @@ -560,13 +560,13 @@ public void getThumbnailWithCorrectRoleAndUnauthorizedSpecificAas() throws IOExc public void getThumbnailWithInsufficientPermissionRole() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_DELETER_CREDENTIAL); - CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @Test public void getThumbnailWithNoAuthorization() throws IOException { - CloseableHttpResponse retrievalResponse = getElementWithNoAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID)); + CloseableHttpResponse retrievalResponse = getElementWithNoAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID)); assertEquals(HttpStatus.UNAUTHORIZED.value(), retrievalResponse.getCode()); } @@ -578,7 +578,7 @@ public void setThumbnailWithCorrectRoleAndPermission() throws IOException { CloseableHttpResponse retrievalResponse = setThumbnailToAasWithAuthorization(SPECIFIC_SHELL_ID, accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test @@ -588,7 +588,7 @@ public void setThumbnailWithCorrectRoleAndSpecificAasPermission() throws IOExcep CloseableHttpResponse retrievalResponse = setThumbnailToAasWithAuthorization(SPECIFIC_SHELL_ID, accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test @@ -620,10 +620,10 @@ public void deleteThumbnailWithCorrectRoleAndPermission() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_ASSET_UPDATER_CREDENTIAL); - CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - assertElementIsNotOnServer(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + assertElementIsNotOnServer(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test @@ -634,10 +634,10 @@ public void deleteThumbnailWithCorrectRoleAndSpecificAasPermission() throws IOEx String accessToken = getAccessToken(DummyCredentialStore.BASYX_ASSET_UPDATER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID_2), accessToken); + CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID_2), accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - assertElementIsNotOnServer(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID_2), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + assertElementIsNotOnServer(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID_2), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); deleteElementWithAuthorization(getSpecificAasAccessURL(SPECIFIC_SHELL_ID_2), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @@ -645,7 +645,7 @@ public void deleteThumbnailWithCorrectRoleAndSpecificAasPermission() throws IOEx public void deleteThumbnailWithCorrectRoleAndUnauthorizedSpecificAas() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_ASSET_UPDATER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @@ -653,13 +653,13 @@ public void deleteThumbnailWithCorrectRoleAndUnauthorizedSpecificAas() throws IO public void deleteThumbnailWithInsufficientPermissionRole() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_CREATOR_CREDENTIAL); - CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @Test public void deleteThumbnailWithNoAuthorization() throws IOException { - CloseableHttpResponse retrievalResponse = deleteElementWithNoAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), SPECIFIC_SHELL_ID)); + CloseableHttpResponse retrievalResponse = deleteElementWithNoAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID)); assertEquals(HttpStatus.UNAUTHORIZED.value(), retrievalResponse.getCode()); } @@ -717,11 +717,11 @@ private String getAccessToken(DummyCredential dummyCredential) { } protected CloseableHttpResponse getAllAasWithAuthorization(String accessToken) throws IOException { - return BaSyxHttpTestUtils.executeAuthorizedGetOnURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), accessToken); + return BaSyxHttpTestUtils.executeAuthorizedGetOnURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), accessToken); } protected CloseableHttpResponse getAllAasNoAuthorization() throws IOException { - return BaSyxHttpTestUtils.executeGetOnURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH)); + return BaSyxHttpTestUtils.executeGetOnURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null)); } protected CloseableHttpResponse getElementWithAuthorization(String url, String accessToken) throws IOException { @@ -733,11 +733,11 @@ protected CloseableHttpResponse getElementWithNoAuthorization(String url) throws } protected String getSpecificAasAccessURL(String shellId) { - return RepositoryUrlHelper.createRepositoryUrl(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), AAS_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(shellId); + return RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(shellId); } private static CloseableHttpResponse createAasOnRepositoryWithAuthorization(String aasJsonContent, String accessToken) throws IOException { - return BaSyxHttpTestUtils.executeAuthorizedPostOnURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), aasJsonContent, accessToken); + return BaSyxHttpTestUtils.executeAuthorizedPostOnURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), aasJsonContent, accessToken); } private CloseableHttpResponse setThumbnailToAasWithAuthorization(String shellId, String accessToken) throws IOException { @@ -753,7 +753,7 @@ private CloseableHttpResponse setThumbnailToAasWithNoAuthorization(String shellI } private static CloseableHttpResponse createAasOnRepositoryWithNoAuthorization(String aasJsonContent) throws IOException { - return BaSyxHttpTestUtils.executePostOnURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH), aasJsonContent); + return BaSyxHttpTestUtils.executePostOnURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), aasJsonContent); } private CloseableHttpResponse updateElementWithAuthorizationPutRequest(String url, String aasJsonContent, String accessToken) throws IOException { @@ -813,6 +813,6 @@ private String getSpecificSubmodelReferenceUrl(String shellId, String submodelId private static String getThumbnailAccessURL(String aasId) { Base64UrlEncodedIdentifier identifier = new Base64UrlEncodedIdentifier(aasId); - return RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, AAS_REPOSITORY_PATH) + "/" + identifier.getEncodedIdentifier() + "/asset-information/thumbnail"; + return RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null) + "/" + identifier.getEncodedIdentifier() + "/asset-information/thumbnail"; } } diff --git a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java index e5abea3f6..96d632b9e 100644 --- a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java +++ b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java @@ -14,7 +14,7 @@ public static String createRepositoryUrl(String baseUrl, String additionalPath) URI finalUri = UriComponentsBuilder.newInstance().scheme(baseUri.getScheme()).host(baseUri.getHost()) .port(baseUri.getPort()).pathSegment(baseUri.getPath().replaceAll("^/|/$", "").split("/")) - .pathSegment(additionalPath.replaceAll("^/|/$", "").split("/")).build().toUri(); + .pathSegment((additionalPath != null ? additionalPath : "").replaceAll("^/|/$", "").split("/")).build().toUri(); return finalUri.toURL().toString(); } catch (URISyntaxException | MalformedURLException e) { From 66b63546713f776cb50f1b8b7cc240be233911a5 Mon Sep 17 00:00:00 2001 From: Mateus Molina Date: Tue, 3 Sep 2024 10:52:13 +0200 Subject: [PATCH 20/37] Triggering the CI --- .../client/factory/SubmodelDescriptorFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basyx.submodelregistry/basyx.submodelregistry-client-native/src/main/java/org/eclipse/digitaltwin/basyx/submodelregistry/client/factory/SubmodelDescriptorFactory.java b/basyx.submodelregistry/basyx.submodelregistry-client-native/src/main/java/org/eclipse/digitaltwin/basyx/submodelregistry/client/factory/SubmodelDescriptorFactory.java index bf0dcfc70..e5487241c 100644 --- a/basyx.submodelregistry/basyx.submodelregistry-client-native/src/main/java/org/eclipse/digitaltwin/basyx/submodelregistry/client/factory/SubmodelDescriptorFactory.java +++ b/basyx.submodelregistry/basyx.submodelregistry-client-native/src/main/java/org/eclipse/digitaltwin/basyx/submodelregistry/client/factory/SubmodelDescriptorFactory.java @@ -36,7 +36,7 @@ import org.eclipse.digitaltwin.aas4j.v3.model.LangStringTextType; import org.eclipse.digitaltwin.aas4j.v3.model.Reference; import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; -import org.eclipse.digitaltwin.basyx.core.RepositoryUrlHelper; +import org.eclipse.digitaltwin.basyx.core.RepositoryUrlHelper; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; import org.eclipse.digitaltwin.basyx.submodelregistry.client.mapper.AttributeMapper; import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.Endpoint; From 581e6417f4bfc52ec5471d0a25a60250608140b8 Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Tue, 17 Sep 2024 00:43:22 +0200 Subject: [PATCH 21/37] fix: revert pom + update createRepositoryUrl functionality --- basyx.common/basyx.core/pom.xml | 4 --- .../basyx/core/RepositoryUrlHelper.java | 25 +++++++++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/basyx.common/basyx.core/pom.xml b/basyx.common/basyx.core/pom.xml index f7d0cb95b..e0c89f549 100644 --- a/basyx.common/basyx.core/pom.xml +++ b/basyx.common/basyx.core/pom.xml @@ -18,10 +18,6 @@ org.springframework spring-context - - org.springframework - spring-web - org.springframework.boot spring-boot-starter diff --git a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java index 96d632b9e..bab621119 100644 --- a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java +++ b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java @@ -4,19 +4,30 @@ import java.net.URI; import java.net.URISyntaxException; -import org.springframework.web.util.UriComponentsBuilder; - public class RepositoryUrlHelper { public static String createRepositoryUrl(String baseUrl, String additionalPath) { try { - URI baseUri = new URI(baseUrl); + URI baseUri = new URI(baseUrl); + + String[] basePathSegments = baseUri.getPath().replaceAll("^/|/$", "").split("/"); + String[] additionalPathSegments = additionalPath != null ? additionalPath.replaceAll("^/|/$", "").split("/") : new String[0]; + + StringBuilder fullPath = new StringBuilder(); + for (String segment : basePathSegments) { + if (!segment.isEmpty()) { + fullPath.append("/").append(segment); + } + } + for (String segment : additionalPathSegments) { + if (!segment.isEmpty()) { + fullPath.append("/").append(segment); + } + } - URI finalUri = UriComponentsBuilder.newInstance().scheme(baseUri.getScheme()).host(baseUri.getHost()) - .port(baseUri.getPort()).pathSegment(baseUri.getPath().replaceAll("^/|/$", "").split("/")) - .pathSegment((additionalPath != null ? additionalPath : "").replaceAll("^/|/$", "").split("/")).build().toUri(); + URI finalUri = new URI(baseUri.getScheme(), null, baseUri.getHost(), baseUri.getPort(), fullPath.toString(), null, null); - return finalUri.toURL().toString(); + return finalUri.toURL().toString(); } catch (URISyntaxException | MalformedURLException e) { throw new RuntimeException("The Base URL or additional path is malformed.\n" + e.getMessage(), e); } From dedc173ac2eb557e608076d9523394efa48f4638 Mon Sep 17 00:00:00 2001 From: Mateus Molina Date: Tue, 17 Sep 2024 08:33:50 +0200 Subject: [PATCH 22/37] Triggering the CI --- .../org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java index bab621119..b9b0ea154 100644 --- a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java +++ b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java @@ -29,7 +29,7 @@ public static String createRepositoryUrl(String baseUrl, String additionalPath) return finalUri.toURL().toString(); } catch (URISyntaxException | MalformedURLException e) { - throw new RuntimeException("The Base URL or additional path is malformed.\n" + e.getMessage(), e); + throw new RuntimeException("The Base URL or additional path is malformed.\n" + e.getMessage(), e); } } From 3ccbec3438caf744a17c787c85ab2f69d40e58ab Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Tue, 24 Sep 2024 09:11:54 +0200 Subject: [PATCH 23/37] fix: add license headers --- .../basyx/core/RepositoryUrlHelper.java | 25 +++++++++++++++++++ .../basyx/core/TestRepositoryUrlHelper.java | 25 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java index b9b0ea154..00bd3d841 100644 --- a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java +++ b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java @@ -1,3 +1,28 @@ +/******************************************************************************* + * Copyright (C) 2024 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + package org.eclipse.digitaltwin.basyx.core; import java.net.MalformedURLException; diff --git a/basyx.common/basyx.core/src/test/java/org/eclipse/digitaltwin/basyx/core/TestRepositoryUrlHelper.java b/basyx.common/basyx.core/src/test/java/org/eclipse/digitaltwin/basyx/core/TestRepositoryUrlHelper.java index aa2de783d..5a7a473a9 100644 --- a/basyx.common/basyx.core/src/test/java/org/eclipse/digitaltwin/basyx/core/TestRepositoryUrlHelper.java +++ b/basyx.common/basyx.core/src/test/java/org/eclipse/digitaltwin/basyx/core/TestRepositoryUrlHelper.java @@ -1,3 +1,28 @@ +/******************************************************************************* + * Copyright (C) 2024 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + package org.eclipse.digitaltwin.basyx.core; import static org.junit.Assert.assertEquals; From 9c118a4131a37c3bf7730cb4dd6a53af36c1e56a Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Tue, 1 Oct 2024 00:40:52 +0200 Subject: [PATCH 24/37] fix: update test for external url --- .../dummyImgA.jpeg | Bin 0 -> 631 bytes .../dummyImgB.jpeg | Bin 0 -> 631 bytes .../TestAuthorizedAasRepository.java | 45 +++++++++--------- .../AasRepositoryRegistryLinkTest.java | 2 + .../AasRepositoryRegistryLinkTestSuite.java | 7 ++- 5 files changed, 30 insertions(+), 24 deletions(-) create mode 100644 basyx.aasrepository/basyx.aasrepository-backend-mongodb/dummyImgA.jpeg create mode 100644 basyx.aasrepository/basyx.aasrepository-backend-mongodb/dummyImgB.jpeg diff --git a/basyx.aasrepository/basyx.aasrepository-backend-mongodb/dummyImgA.jpeg b/basyx.aasrepository/basyx.aasrepository-backend-mongodb/dummyImgA.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..b40ab4c36d0626a29db3ff931d04642236af521e GIT binary patch literal 631 zcmex=^(PF6}rMnOeST|r4lSw=>~TvNxu(8R<uA z0}~@NGZPClD=P~NP<1U(o`FS>RY=j$kxe)-kzJ`!#HexNLJno8jR!@8E`CrkPAY2R z|V^&07y2J$~}^+4C1KUw!=a`ODXD-+%o41@ado12e>1Koa6HG=B*K{l&z>!py=B z@)sjhIS?}oval)|vI#i`vL_Y_D;YI%h&WALxbYyTvT@J{(WIh_Tw*FF4^=;cyax6e kaUN?T%V%(pA^dfVfrpt97^(PF6}rMnOeST|r4lSw=>~TvNxu(8R<uA z0}~@NGZPClD=P~NP<1U(o`FS>RY=j$kxe)-kzJ`!#HexNLJno8jR!@8E`CrkPAY2R z|V^&07y2J$~}^+4C1KUw!=a`ODXD-+%o41@ado12e>1Koa6HG=B*K{l&z>!py=B z@)sjhIS?}oval)|vI#i`vL_Y_D;YI%h&WALxbYyTvT@J{(WIh_Tw*FF4^=;cyax6e kaUN?T%V%(pA^dfVfrpt97XG(0P8=_ga7~l literal 0 HcmV?d00001 diff --git a/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java b/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java index 867b85266..7c7916e2a 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java @@ -53,7 +53,6 @@ import org.eclipse.digitaltwin.basyx.authorization.DummyCredentialStore; import org.eclipse.digitaltwin.basyx.authorization.jwt.JwtTokenDecoder; import org.eclipse.digitaltwin.basyx.authorization.jwt.PublicKeyUtils; -import org.eclipse.digitaltwin.basyx.core.RepositoryUrlHelper; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; import org.eclipse.digitaltwin.basyx.http.serialization.BaSyxHttpTestUtils; import org.junit.AfterClass; @@ -530,10 +529,10 @@ public void getThumbnailWithCorrectRoleAndPermission() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_READER_CREDENTIAL); - CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test @@ -542,17 +541,17 @@ public void getThumbnailWithCorrectRoleAndSpecificAasPermission() throws IOExcep String accessToken = getAccessToken(DummyCredentialStore.BASYX_READER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test public void getThumbnailWithCorrectRoleAndUnauthorizedSpecificAas() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_READER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID_2), accessToken); + CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID_2), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @@ -560,13 +559,13 @@ public void getThumbnailWithCorrectRoleAndUnauthorizedSpecificAas() throws IOExc public void getThumbnailWithInsufficientPermissionRole() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_DELETER_CREDENTIAL); - CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @Test public void getThumbnailWithNoAuthorization() throws IOException { - CloseableHttpResponse retrievalResponse = getElementWithNoAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID)); + CloseableHttpResponse retrievalResponse = getElementWithNoAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID)); assertEquals(HttpStatus.UNAUTHORIZED.value(), retrievalResponse.getCode()); } @@ -578,7 +577,7 @@ public void setThumbnailWithCorrectRoleAndPermission() throws IOException { CloseableHttpResponse retrievalResponse = setThumbnailToAasWithAuthorization(SPECIFIC_SHELL_ID, accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test @@ -588,7 +587,7 @@ public void setThumbnailWithCorrectRoleAndSpecificAasPermission() throws IOExcep CloseableHttpResponse retrievalResponse = setThumbnailToAasWithAuthorization(SPECIFIC_SHELL_ID, accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test @@ -620,10 +619,10 @@ public void deleteThumbnailWithCorrectRoleAndPermission() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_ASSET_UPDATER_CREDENTIAL); - CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - assertElementIsNotOnServer(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + assertElementIsNotOnServer(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test @@ -634,10 +633,10 @@ public void deleteThumbnailWithCorrectRoleAndSpecificAasPermission() throws IOEx String accessToken = getAccessToken(DummyCredentialStore.BASYX_ASSET_UPDATER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID_2), accessToken); + CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID_2), accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - assertElementIsNotOnServer(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID_2), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + assertElementIsNotOnServer(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID_2), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); deleteElementWithAuthorization(getSpecificAasAccessURL(SPECIFIC_SHELL_ID_2), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @@ -645,7 +644,7 @@ public void deleteThumbnailWithCorrectRoleAndSpecificAasPermission() throws IOEx public void deleteThumbnailWithCorrectRoleAndUnauthorizedSpecificAas() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_ASSET_UPDATER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @@ -653,13 +652,13 @@ public void deleteThumbnailWithCorrectRoleAndUnauthorizedSpecificAas() throws IO public void deleteThumbnailWithInsufficientPermissionRole() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_CREATOR_CREDENTIAL); - CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @Test public void deleteThumbnailWithNoAuthorization() throws IOException { - CloseableHttpResponse retrievalResponse = deleteElementWithNoAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID)); + CloseableHttpResponse retrievalResponse = deleteElementWithNoAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID)); assertEquals(HttpStatus.UNAUTHORIZED.value(), retrievalResponse.getCode()); } @@ -717,11 +716,11 @@ private String getAccessToken(DummyCredential dummyCredential) { } protected CloseableHttpResponse getAllAasWithAuthorization(String accessToken) throws IOException { - return BaSyxHttpTestUtils.executeAuthorizedGetOnURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), accessToken); + return BaSyxHttpTestUtils.executeAuthorizedGetOnURL(aasRepositoryBaseUrl, accessToken); } protected CloseableHttpResponse getAllAasNoAuthorization() throws IOException { - return BaSyxHttpTestUtils.executeGetOnURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null)); + return BaSyxHttpTestUtils.executeGetOnURL(aasRepositoryBaseUrl); } protected CloseableHttpResponse getElementWithAuthorization(String url, String accessToken) throws IOException { @@ -733,11 +732,11 @@ protected CloseableHttpResponse getElementWithNoAuthorization(String url) throws } protected String getSpecificAasAccessURL(String shellId) { - return RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(shellId); + return aasRepositoryBaseUrl + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(shellId); } private static CloseableHttpResponse createAasOnRepositoryWithAuthorization(String aasJsonContent, String accessToken) throws IOException { - return BaSyxHttpTestUtils.executeAuthorizedPostOnURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), aasJsonContent, accessToken); + return BaSyxHttpTestUtils.executeAuthorizedPostOnURL(aasRepositoryBaseUrl, aasJsonContent, accessToken); } private CloseableHttpResponse setThumbnailToAasWithAuthorization(String shellId, String accessToken) throws IOException { @@ -753,7 +752,7 @@ private CloseableHttpResponse setThumbnailToAasWithNoAuthorization(String shellI } private static CloseableHttpResponse createAasOnRepositoryWithNoAuthorization(String aasJsonContent) throws IOException { - return BaSyxHttpTestUtils.executePostOnURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), aasJsonContent); + return BaSyxHttpTestUtils.executePostOnURL(aasRepositoryBaseUrl, aasJsonContent); } private CloseableHttpResponse updateElementWithAuthorizationPutRequest(String url, String aasJsonContent, String accessToken) throws IOException { @@ -813,6 +812,6 @@ private String getSpecificSubmodelReferenceUrl(String shellId, String submodelId private static String getThumbnailAccessURL(String aasId) { Base64UrlEncodedIdentifier identifier = new Base64UrlEncodedIdentifier(aasId); - return RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null) + "/" + identifier.getEncodedIdentifier() + "/asset-information/thumbnail"; + return aasRepositoryBaseUrl + "/" + identifier.getEncodedIdentifier() + "/asset-information/thumbnail"; } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java index e35a8130a..9826b146e 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java @@ -48,6 +48,7 @@ public class AasRepositoryRegistryLinkTest extends AasRepositoryRegistryLinkTest @BeforeClass public static void setUp() throws FileNotFoundException, IOException { + System.setProperty("basyx.externalurl", AAS_REPO_URL); appContext = new SpringApplication(DummyAasRepositoryIntegrationComponent.class).run(new String[] {}); aasRepositoryRegistryLink = appContext.getBean(AasRepositoryRegistryLink.class); @@ -55,6 +56,7 @@ public static void setUp() throws FileNotFoundException, IOException { @AfterClass public static void tearDown() { + System.clearProperty("basyx.externalurl"); appContext.close(); } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java index 84b410b2c..f0c9e097a 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java @@ -36,6 +36,7 @@ import org.eclipse.digitaltwin.basyx.aasregistry.client.ApiException; import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Endpoint; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.GetAssetAdministrationShellDescriptorsResult; import org.eclipse.digitaltwin.basyx.core.RepositoryUrlHelper; import org.eclipse.digitaltwin.basyx.aasregistry.main.client.mapper.DummyAasDescriptorFactory; @@ -77,7 +78,11 @@ public void createAas() throws FileNotFoundException, IOException, ApiException AssetAdministrationShellDescriptor actualDescriptor = retrieveDescriptorFromRegistry(); assertEquals(DUMMY_DESCRIPTOR, actualDescriptor); - + + Endpoint firstEndpoint = actualDescriptor.getEndpoints().get(0); + String firstEndpointUrl = firstEndpoint.getProtocolInformation().getHref(); + assertTrue("Endpoint address should start with externalUrl", firstEndpointUrl.startsWith(getFirstAasRepoBaseUrl())); + resetRepository(); } } From 27bdb4540ac8814230e0ae8aabb97a860c20737b Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Tue, 1 Oct 2024 10:07:39 +0200 Subject: [PATCH 25/37] stash --- .../dummyImgA.jpeg | Bin 631 -> 0 bytes .../dummyImgB.jpeg | Bin 631 -> 0 bytes ...yRegistryLinkDescriptorGenerationTest.java | 61 ++++++++++++++++++ .../AasRepositoryRegistryLinkTest.java | 2 - 4 files changed, 61 insertions(+), 2 deletions(-) delete mode 100644 basyx.aasrepository/basyx.aasrepository-backend-mongodb/dummyImgA.jpeg delete mode 100644 basyx.aasrepository/basyx.aasrepository-backend-mongodb/dummyImgB.jpeg create mode 100644 basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java diff --git a/basyx.aasrepository/basyx.aasrepository-backend-mongodb/dummyImgA.jpeg b/basyx.aasrepository/basyx.aasrepository-backend-mongodb/dummyImgA.jpeg deleted file mode 100644 index b40ab4c36d0626a29db3ff931d04642236af521e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 631 zcmex=^(PF6}rMnOeST|r4lSw=>~TvNxu(8R<uA z0}~@NGZPClD=P~NP<1U(o`FS>RY=j$kxe)-kzJ`!#HexNLJno8jR!@8E`CrkPAY2R z|V^&07y2J$~}^+4C1KUw!=a`ODXD-+%o41@ado12e>1Koa6HG=B*K{l&z>!py=B z@)sjhIS?}oval)|vI#i`vL_Y_D;YI%h&WALxbYyTvT@J{(WIh_Tw*FF4^=;cyax6e kaUN?T%V%(pA^dfVfrpt97^(PF6}rMnOeST|r4lSw=>~TvNxu(8R<uA z0}~@NGZPClD=P~NP<1U(o`FS>RY=j$kxe)-kzJ`!#HexNLJno8jR!@8E`CrkPAY2R z|V^&07y2J$~}^+4C1KUw!=a`ODXD-+%o41@ado12e>1Koa6HG=B*K{l&z>!py=B z@)sjhIS?}oval)|vI#i`vL_Y_D;YI%h&WALxbYyTvT@J{(WIh_Tw*FF4^=;cyax6e kaUN?T%V%(pA^dfVfrpt97XG(0P8=_ga7~l diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java new file mode 100644 index 000000000..ebe1c4bfd --- /dev/null +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; + +import java.io.FileNotFoundException; +import java.io.IOException; + +import org.eclipse.digitaltwin.basyx.aasregistry.client.ApiException; +import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; +import org.eclipse.digitaltwin.basyx.aasrepository.backend.AasBackendProvider; +import org.eclipse.digitaltwin.basyx.aasrepository.backend.SimpleAasRepositoryFactory; +import org.eclipse.digitaltwin.basyx.aasrepository.backend.inmemory.AasInMemoryBackendProvider; +import org.eclipse.digitaltwin.basyx.aasservice.backend.InMemoryAasServiceFactory; +import org.eclipse.digitaltwin.basyx.core.filerepository.InMemoryFileRepository; +import org.junit.Test; + +/** + * Test suite for {@link RegistryIntegrationAasRepository} feature + * + * @author danish + */ +public class AasRepositoryRegistryLinkDescriptorGenerationTest { + private static final String AAS_REPOSITORY_PATH = "shells"; + + private static final String DUMMY_GLOBAL_ASSETID = "globalAssetId"; + private static final String DUMMY_IDSHORT = "ExampleMotor"; + private static final String DUMMY_AAS_ID = "customIdentifier"; + + @Test + public void aasRepositoryRegistryLinkDescriptorGenerationTest() throws FileNotFoundException, IOException, ApiException { + RegistryIntegrationAasRepository registryIntRepo = new RegistryIntegrationAasRepository(getAasRepository()); + } + + protected AasRepository getAasRepository() { + return new SimpleAasRepositoryFactory(new AasInMemoryBackendProvider(), new InMemoryAasServiceFactory(new InMemoryFileRepository())).create(); + } + +} diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java index 9826b146e..e35a8130a 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java @@ -48,7 +48,6 @@ public class AasRepositoryRegistryLinkTest extends AasRepositoryRegistryLinkTest @BeforeClass public static void setUp() throws FileNotFoundException, IOException { - System.setProperty("basyx.externalurl", AAS_REPO_URL); appContext = new SpringApplication(DummyAasRepositoryIntegrationComponent.class).run(new String[] {}); aasRepositoryRegistryLink = appContext.getBean(AasRepositoryRegistryLink.class); @@ -56,7 +55,6 @@ public static void setUp() throws FileNotFoundException, IOException { @AfterClass public static void tearDown() { - System.clearProperty("basyx.externalurl"); appContext.close(); } From c7f3d55e231c8d3954c93246c2e030f052711ff9 Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Tue, 15 Oct 2024 07:54:24 +0200 Subject: [PATCH 26/37] feat: AasRepositoryRegistryLinkDescriptorGenerationTest --- ...yRegistryLinkDescriptorGenerationTest.java | 115 ++++++++++++++++-- .../AasRepositoryRegistryLinkTestSuite.java | 28 +++-- 2 files changed, 119 insertions(+), 24 deletions(-) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java index ebe1c4bfd..dfc5d0659 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java @@ -25,35 +25,124 @@ package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; + import java.io.FileNotFoundException; import java.io.IOException; +import java.util.List; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetAdministrationShell; import org.eclipse.digitaltwin.basyx.aasregistry.client.ApiException; +import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; +import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.eclipse.digitaltwin.basyx.aasregistry.main.client.factory.AasDescriptorFactory; +import org.eclipse.digitaltwin.basyx.aasregistry.main.client.mapper.AttributeMapper; +import org.eclipse.digitaltwin.basyx.aasregistry.main.client.mapper.DummyAasDescriptorFactory; import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; -import org.eclipse.digitaltwin.basyx.aasrepository.backend.AasBackendProvider; import org.eclipse.digitaltwin.basyx.aasrepository.backend.SimpleAasRepositoryFactory; import org.eclipse.digitaltwin.basyx.aasrepository.backend.inmemory.AasInMemoryBackendProvider; import org.eclipse.digitaltwin.basyx.aasservice.backend.InMemoryAasServiceFactory; import org.eclipse.digitaltwin.basyx.core.filerepository.InMemoryFileRepository; -import org.junit.Test; /** * Test suite for {@link RegistryIntegrationAasRepository} feature - * - * @author danish */ -public class AasRepositoryRegistryLinkDescriptorGenerationTest { - private static final String AAS_REPOSITORY_PATH = "shells"; - - private static final String DUMMY_GLOBAL_ASSETID = "globalAssetId"; +public class AasRepositoryRegistryLinkDescriptorGenerationTest { private static final String DUMMY_IDSHORT = "ExampleMotor"; private static final String DUMMY_AAS_ID = "customIdentifier"; + + private static final String BASE_URL = "http://localhost:8081"; - @Test - public void aasRepositoryRegistryLinkDescriptorGenerationTest() throws FileNotFoundException, IOException, ApiException { - RegistryIntegrationAasRepository registryIntRepo = new RegistryIntegrationAasRepository(getAasRepository()); - } - + // Mock dependencies + private RegistryIntegrationAasRepository registryIntegrationAasRepository; + private AasRepository mockedAasRepository; + private AasRepositoryRegistryLink mockedRegistryLink; + private AttributeMapper mockedAttributeMapper; + private RegistryAndDiscoveryInterfaceApi mockedRegistryApi; + + @Before + public void setUp() { + mockedAasRepository = getAasRepository(); + mockedRegistryLink = Mockito.mock(AasRepositoryRegistryLink.class); + mockedAttributeMapper = Mockito.mock(AttributeMapper.class); + mockedRegistryApi = Mockito.mock(RegistryAndDiscoveryInterfaceApi.class); + + Mockito.when(mockedRegistryLink.getRegistryApi()).thenReturn(mockedRegistryApi); + + registryIntegrationAasRepository = new RegistryIntegrationAasRepository(mockedAasRepository, mockedRegistryLink, mockedAttributeMapper); + } + + @Test + public void testExternalUrlWithTrailingSlashReflectedInDescriptor() throws FileNotFoundException, IOException, ApiException { + String externalUrl = BASE_URL + "/"; + Mockito.when(mockedRegistryLink.getAasRepositoryBaseURLs()).thenReturn(List.of(externalUrl)); + + AssetAdministrationShellDescriptor descriptor = createAndRetrieveDescriptor(createDummyAas()); + + assertTrue("Endpoint address should start with externalUrl", descriptor.getEndpoints().get(0) + .getProtocolInformation().getHref().startsWith(externalUrl)); + } + + @Test + public void testExternalUrlWithoutTrailingSlashReflectedInDescriptor() throws FileNotFoundException, IOException, ApiException { + String externalUrl = BASE_URL; + Mockito.when(mockedRegistryLink.getAasRepositoryBaseURLs()).thenReturn(List.of(externalUrl)); + + AssetAdministrationShellDescriptor descriptor = createAndRetrieveDescriptor(createDummyAas()); + + String expectedUrl = externalUrl + "/"; + assertTrue("Endpoint address should start with externalUrl", descriptor.getEndpoints().get(0) + .getProtocolInformation().getHref().startsWith(expectedUrl)); + } + + @Test + public void testExternalUrlWithContextPathWithoutTrailingSlashReflectedInDescriptor() throws FileNotFoundException, IOException, ApiException { + String externalUrl = BASE_URL + "/context"; + Mockito.when(mockedRegistryLink.getAasRepositoryBaseURLs()).thenReturn(List.of(externalUrl)); + + AssetAdministrationShellDescriptor descriptor = createAndRetrieveDescriptor(createDummyAas()); + + String expectedUrl = externalUrl; + assertTrue("Endpoint address should start with externalUrl including context path", descriptor.getEndpoints().get(0) + .getProtocolInformation().getHref().startsWith(expectedUrl)); + } + + @Test + public void testExternalUrlWithContextPathWithTrailingSlashReflectedInDescriptor() throws FileNotFoundException, IOException, ApiException { + String externalUrl = BASE_URL + "/context"; + Mockito.when(mockedRegistryLink.getAasRepositoryBaseURLs()).thenReturn(List.of(externalUrl)); + + AssetAdministrationShellDescriptor descriptor = createAndRetrieveDescriptor(createDummyAas()); + + String expectedUrl = externalUrl + "/"; + assertTrue("Endpoint address should start with externalUrl including context path", descriptor.getEndpoints().get(0) + .getProtocolInformation().getHref().startsWith(expectedUrl)); + } + + private AssetAdministrationShellDescriptor createAndRetrieveDescriptor(AssetAdministrationShell shell) throws ApiException { + // Simulate the process of creating an AAS in the repository + registryIntegrationAasRepository.createAas(shell); + + // Simulate retrieving the descriptor from the registry after creation + AasDescriptorFactory descriptorFactory = new AasDescriptorFactory(shell, mockedRegistryLink.getAasRepositoryBaseURLs(), mockedAttributeMapper); + return descriptorFactory.create(); + } + + private AssetAdministrationShell createDummyAas() { + // You can create a mock or a real AAS object + return new DefaultAssetAdministrationShell.Builder() + .id(DUMMY_AAS_ID) + .idShort(DUMMY_IDSHORT) + .build(); + } + protected AasRepository getAasRepository() { return new SimpleAasRepositoryFactory(new AasInMemoryBackendProvider(), new InMemoryAasServiceFactory(new InMemoryFileRepository())).create(); } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java index f0c9e097a..a68fd6d3c 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java @@ -30,15 +30,15 @@ import java.io.FileNotFoundException; import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; import java.util.List; import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.eclipse.digitaltwin.basyx.aasregistry.client.ApiException; import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor; -import org.eclipse.digitaltwin.basyx.aasregistry.client.model.Endpoint; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.GetAssetAdministrationShellDescriptorsResult; -import org.eclipse.digitaltwin.basyx.core.RepositoryUrlHelper; import org.eclipse.digitaltwin.basyx.aasregistry.main.client.mapper.DummyAasDescriptorFactory; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; import org.eclipse.digitaltwin.basyx.http.serialization.BaSyxHttpTestUtils; @@ -53,8 +53,8 @@ * @author danish */ public abstract class AasRepositoryRegistryLinkTestSuite { - private static final String AAS_REPOSITORY_PATH = "shells"; + private static final String AAS_REPOSITORY_PATH = "/shells"; private static final String DUMMY_GLOBAL_ASSETID = "globalAssetId"; private static final String DUMMY_IDSHORT = "ExampleMotor"; private static final String DUMMY_AAS_ID = "customIdentifier"; @@ -78,11 +78,7 @@ public void createAas() throws FileNotFoundException, IOException, ApiException AssetAdministrationShellDescriptor actualDescriptor = retrieveDescriptorFromRegistry(); assertEquals(DUMMY_DESCRIPTOR, actualDescriptor); - - Endpoint firstEndpoint = actualDescriptor.getEndpoints().get(0); - String firstEndpointUrl = firstEndpoint.getProtocolInformation().getHref(); - assertTrue("Endpoint address should start with externalUrl", firstEndpointUrl.startsWith(getFirstAasRepoBaseUrl())); - + resetRepository(); } } @@ -133,15 +129,25 @@ private String getAas1JSONString() throws FileNotFoundException, IOException { } private CloseableHttpResponse createAasOnRepo(String aasJsonContent) throws IOException { - return BaSyxHttpTestUtils.executePostOnURL(RepositoryUrlHelper.createRepositoryUrl(getFirstAasRepoBaseUrl(), AAS_REPOSITORY_PATH), aasJsonContent); + return BaSyxHttpTestUtils.executePostOnURL(createAasRepositoryUrl(getFirstAasRepoBaseUrl()), aasJsonContent); } private String getSpecificAasAccessURL(String aasId) { - return RepositoryUrlHelper.createRepositoryUrl(getFirstAasRepoBaseUrl(), AAS_REPOSITORY_PATH) + "/" + return createAasRepositoryUrl(getFirstAasRepoBaseUrl()) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(aasId); } private String getFirstAasRepoBaseUrl() { return getAasRepoBaseUrls()[0]; } -} + + private static String createAasRepositoryUrl(String aasRepositoryBaseURL) { + + try { + return new URL(new URL(aasRepositoryBaseURL), AAS_REPOSITORY_PATH).toString(); + } catch (MalformedURLException e) { + throw new RuntimeException("The AAS Repository Base url is malformed. " + e.getMessage()); + } + } + +} \ No newline at end of file From 5bd2f772c5669d3957279972a17a957440c7daec Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Sun, 27 Oct 2024 18:38:16 +0100 Subject: [PATCH 27/37] stash --- .../main/client/factory/AasDescriptorFactory.java | 9 --------- .../integration/AasRepositoryRegistryLink.java | 9 +++++++++ .../integration/AasRepositoryRegistryLinkTest.java | 10 ++++++++-- .../AasRepositoryRegistryLinkTestSuite.java | 14 +++----------- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/basyx.aasregistry/basyx.aasregistry-client-native/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/main/client/factory/AasDescriptorFactory.java b/basyx.aasregistry/basyx.aasregistry-client-native/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/main/client/factory/AasDescriptorFactory.java index 2e08b3d94..723b6fbea 100644 --- a/basyx.aasregistry/basyx.aasregistry-client-native/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/main/client/factory/AasDescriptorFactory.java +++ b/basyx.aasregistry/basyx.aasregistry-client-native/src/main/java/org/eclipse/digitaltwin/basyx/aasregistry/main/client/factory/AasDescriptorFactory.java @@ -201,13 +201,4 @@ private List createAasRepositoryUrls(List aasRepositoryBaseURLs) } return toReturn; } - - private String createAasRepositoryUrl(String aasRepositoryBaseURL) { - - try { - return new URL(new URL(aasRepositoryBaseURL), AAS_REPOSITORY_PATH).toString(); - } catch (MalformedURLException e) { - throw new RuntimeException("The AAS Repository Base url is malformed.\n" + e.getMessage()); - } - } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java index d22a91eb6..e8e1bcf71 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java @@ -44,6 +44,15 @@ public AasRepositoryRegistryLink(RegistryAndDiscoveryInterfaceApi registryApi, L super(); this.registryApi = registryApi; this.aasRepositoryBaseURLs = aasRepositoryBaseURLs; + + for (int i = 0; i < this.aasRepositoryBaseURLs.size(); i++) { + String url = this.aasRepositoryBaseURLs.get(i); + int slashCount = url.length() - url.replace("/", "").length(); + if (!url.endsWith("/") && slashCount >= 3) { + url += "/"; + this.aasRepositoryBaseURLs.set(i, url); + } + } } public RegistryAndDiscoveryInterfaceApi getRegistryApi() { diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java index e35a8130a..4c03d985c 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java @@ -41,7 +41,7 @@ */ public class AasRepositoryRegistryLinkTest extends AasRepositoryRegistryLinkTestSuite { - private static final String AAS_REPO_URL = "http://localhost:8081"; + private static final String AAS_REPO_URL = "http://localhost:8081/context"; private static final String AAS_REGISTRY_BASE_URL = "http://localhost:8050"; private static ConfigurableApplicationContext appContext; private static AasRepositoryRegistryLink aasRepositoryRegistryLink; @@ -60,7 +60,13 @@ public static void tearDown() { @Override protected String[] getAasRepoBaseUrls() { - return new String[] { AAS_REPO_URL}; + String url = AAS_REPO_URL; + int slashCount = url.length() - url.replace("/", "").length(); + if (!url.endsWith("/") && slashCount >= 3) { + url += "/"; + } + + return new String[] { url }; } @Override diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java index a68fd6d3c..206e20e14 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java @@ -40,6 +40,7 @@ import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.GetAssetAdministrationShellDescriptorsResult; import org.eclipse.digitaltwin.basyx.aasregistry.main.client.mapper.DummyAasDescriptorFactory; +import org.eclipse.digitaltwin.basyx.core.RepositoryUrlHelper; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; import org.eclipse.digitaltwin.basyx.http.serialization.BaSyxHttpTestUtils; import org.junit.After; @@ -129,11 +130,11 @@ private String getAas1JSONString() throws FileNotFoundException, IOException { } private CloseableHttpResponse createAasOnRepo(String aasJsonContent) throws IOException { - return BaSyxHttpTestUtils.executePostOnURL(createAasRepositoryUrl(getFirstAasRepoBaseUrl()), aasJsonContent); + return BaSyxHttpTestUtils.executePostOnURL(RepositoryUrlHelper.createRepositoryUrl(getFirstAasRepoBaseUrl(), AAS_REPOSITORY_PATH), aasJsonContent); } private String getSpecificAasAccessURL(String aasId) { - return createAasRepositoryUrl(getFirstAasRepoBaseUrl()) + "/" + return RepositoryUrlHelper.createRepositoryUrl(getFirstAasRepoBaseUrl(), AAS_REPOSITORY_PATH) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(aasId); } @@ -141,13 +142,4 @@ private String getFirstAasRepoBaseUrl() { return getAasRepoBaseUrls()[0]; } - private static String createAasRepositoryUrl(String aasRepositoryBaseURL) { - - try { - return new URL(new URL(aasRepositoryBaseURL), AAS_REPOSITORY_PATH).toString(); - } catch (MalformedURLException e) { - throw new RuntimeException("The AAS Repository Base url is malformed. " + e.getMessage()); - } - } - } \ No newline at end of file From 493f17704a86ee799e5f23e0a859adfc7e15e223 Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Sun, 27 Oct 2024 18:58:24 +0100 Subject: [PATCH 28/37] stash --- .../integration/AasRepositoryRegistryLinkTestSuite.java | 1 + .../src/test/resources/application.properties | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java index 206e20e14..09c55e696 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java @@ -130,6 +130,7 @@ private String getAas1JSONString() throws FileNotFoundException, IOException { } private CloseableHttpResponse createAasOnRepo(String aasJsonContent) throws IOException { + String url = RepositoryUrlHelper.createRepositoryUrl(getFirstAasRepoBaseUrl(), AAS_REPOSITORY_PATH); return BaSyxHttpTestUtils.executePostOnURL(RepositoryUrlHelper.createRepositoryUrl(getFirstAasRepoBaseUrl(), AAS_REPOSITORY_PATH), aasJsonContent); } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/application.properties b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/application.properties index 4c42a98bc..07d064649 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/application.properties +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/application.properties @@ -7,7 +7,7 @@ basyx.aasrepo.name=aas-repo basyx.backend = InMemory basyx.aasrepository.feature.registryintegration=http://localhost:8050 -basyx.externalurl=http://localhost:8081 +basyx.externalurl=http://localhost:8081/context/ #basyx.backend = MongoDB #spring.data.mongodb.host=127.0.0.1 From d0ba025a165c7521eb3f395add8b68b0eda9af36 Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Tue, 29 Oct 2024 00:00:26 +0100 Subject: [PATCH 29/37] stash --- .../AasRepositoryRegistryLink.java | 16 +++---- ...yRegistryLinkDescriptorGenerationTest.java | 42 ++----------------- .../AasRepositoryRegistryLinkTest.java | 10 ++--- .../AasRepositoryRegistryLinkTestSuite.java | 2 +- .../src/test/resources/application.properties | 2 +- 5 files changed, 19 insertions(+), 53 deletions(-) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java index e8e1bcf71..1297c2bb5 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java @@ -45,14 +45,14 @@ public AasRepositoryRegistryLink(RegistryAndDiscoveryInterfaceApi registryApi, L this.registryApi = registryApi; this.aasRepositoryBaseURLs = aasRepositoryBaseURLs; - for (int i = 0; i < this.aasRepositoryBaseURLs.size(); i++) { - String url = this.aasRepositoryBaseURLs.get(i); - int slashCount = url.length() - url.replace("/", "").length(); - if (!url.endsWith("/") && slashCount >= 3) { - url += "/"; - this.aasRepositoryBaseURLs.set(i, url); - } - } +// for (int i = 0; i < this.aasRepositoryBaseURLs.size(); i++) { +// String url = this.aasRepositoryBaseURLs.get(i); +// int slashCount = url.length() - url.replace("/", "").length(); +// if (!url.endsWith("/") && slashCount >= 3) { +// url += "/"; +// this.aasRepositoryBaseURLs.set(i, url); +// } +// } } public RegistryAndDiscoveryInterfaceApi getRegistryApi() { diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java index dfc5d0659..2b7cc3794 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java @@ -42,6 +42,8 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; +import org.springframework.boot.SpringApplication; +import org.springframework.context.ConfigurableApplicationContext; import org.eclipse.digitaltwin.basyx.aasregistry.main.client.factory.AasDescriptorFactory; import org.eclipse.digitaltwin.basyx.aasregistry.main.client.mapper.AttributeMapper; import org.eclipse.digitaltwin.basyx.aasregistry.main.client.mapper.DummyAasDescriptorFactory; @@ -60,7 +62,6 @@ public class AasRepositoryRegistryLinkDescriptorGenerationTest { private static final String BASE_URL = "http://localhost:8081"; - // Mock dependencies private RegistryIntegrationAasRepository registryIntegrationAasRepository; private AasRepository mockedAasRepository; private AasRepositoryRegistryLink mockedRegistryLink; @@ -68,9 +69,9 @@ public class AasRepositoryRegistryLinkDescriptorGenerationTest { private RegistryAndDiscoveryInterfaceApi mockedRegistryApi; @Before - public void setUp() { + public void setUp() { mockedAasRepository = getAasRepository(); - mockedRegistryLink = Mockito.mock(AasRepositoryRegistryLink.class); + mockedRegistryLink = Mockito.mock(AasRepositoryRegistryLink.class); mockedAttributeMapper = Mockito.mock(AttributeMapper.class); mockedRegistryApi = Mockito.mock(RegistryAndDiscoveryInterfaceApi.class); @@ -79,29 +80,6 @@ public void setUp() { registryIntegrationAasRepository = new RegistryIntegrationAasRepository(mockedAasRepository, mockedRegistryLink, mockedAttributeMapper); } - @Test - public void testExternalUrlWithTrailingSlashReflectedInDescriptor() throws FileNotFoundException, IOException, ApiException { - String externalUrl = BASE_URL + "/"; - Mockito.when(mockedRegistryLink.getAasRepositoryBaseURLs()).thenReturn(List.of(externalUrl)); - - AssetAdministrationShellDescriptor descriptor = createAndRetrieveDescriptor(createDummyAas()); - - assertTrue("Endpoint address should start with externalUrl", descriptor.getEndpoints().get(0) - .getProtocolInformation().getHref().startsWith(externalUrl)); - } - - @Test - public void testExternalUrlWithoutTrailingSlashReflectedInDescriptor() throws FileNotFoundException, IOException, ApiException { - String externalUrl = BASE_URL; - Mockito.when(mockedRegistryLink.getAasRepositoryBaseURLs()).thenReturn(List.of(externalUrl)); - - AssetAdministrationShellDescriptor descriptor = createAndRetrieveDescriptor(createDummyAas()); - - String expectedUrl = externalUrl + "/"; - assertTrue("Endpoint address should start with externalUrl", descriptor.getEndpoints().get(0) - .getProtocolInformation().getHref().startsWith(expectedUrl)); - } - @Test public void testExternalUrlWithContextPathWithoutTrailingSlashReflectedInDescriptor() throws FileNotFoundException, IOException, ApiException { String externalUrl = BASE_URL + "/context"; @@ -114,18 +92,6 @@ public void testExternalUrlWithContextPathWithoutTrailingSlashReflectedInDescrip .getProtocolInformation().getHref().startsWith(expectedUrl)); } - @Test - public void testExternalUrlWithContextPathWithTrailingSlashReflectedInDescriptor() throws FileNotFoundException, IOException, ApiException { - String externalUrl = BASE_URL + "/context"; - Mockito.when(mockedRegistryLink.getAasRepositoryBaseURLs()).thenReturn(List.of(externalUrl)); - - AssetAdministrationShellDescriptor descriptor = createAndRetrieveDescriptor(createDummyAas()); - - String expectedUrl = externalUrl + "/"; - assertTrue("Endpoint address should start with externalUrl including context path", descriptor.getEndpoints().get(0) - .getProtocolInformation().getHref().startsWith(expectedUrl)); - } - private AssetAdministrationShellDescriptor createAndRetrieveDescriptor(AssetAdministrationShell shell) throws ApiException { // Simulate the process of creating an AAS in the repository registryIntegrationAasRepository.createAas(shell); diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java index 4c03d985c..f33f7e252 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java @@ -41,7 +41,7 @@ */ public class AasRepositoryRegistryLinkTest extends AasRepositoryRegistryLinkTestSuite { - private static final String AAS_REPO_URL = "http://localhost:8081/context"; + private static final String AAS_REPO_URL = "http://localhost:8081/"; private static final String AAS_REGISTRY_BASE_URL = "http://localhost:8050"; private static ConfigurableApplicationContext appContext; private static AasRepositoryRegistryLink aasRepositoryRegistryLink; @@ -61,10 +61,10 @@ public static void tearDown() { @Override protected String[] getAasRepoBaseUrls() { String url = AAS_REPO_URL; - int slashCount = url.length() - url.replace("/", "").length(); - if (!url.endsWith("/") && slashCount >= 3) { - url += "/"; - } +// int slashCount = url.length() - url.replace("/", "").length(); +// if (!url.endsWith("/") && slashCount >= 3) { +// url += "/"; +// } return new String[] { url }; } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java index 09c55e696..a2c28cd6e 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java @@ -74,7 +74,7 @@ public void createAas() throws FileNotFoundException, IOException, ApiException String aasJsonContent = getAas1JSONString(); try (CloseableHttpResponse creationResponse = createAasOnRepo(aasJsonContent)) { - assertEquals(HttpStatus.CREATED.value(), creationResponse.getCode()); +// assertEquals(HttpStatus.CREATED.value(), creationResponse.getCode()); AssetAdministrationShellDescriptor actualDescriptor = retrieveDescriptorFromRegistry(); diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/application.properties b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/application.properties index 07d064649..f04bd82d7 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/application.properties +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/application.properties @@ -7,7 +7,7 @@ basyx.aasrepo.name=aas-repo basyx.backend = InMemory basyx.aasrepository.feature.registryintegration=http://localhost:8050 -basyx.externalurl=http://localhost:8081/context/ +basyx.externalurl=http://localhost:8081/context #basyx.backend = MongoDB #spring.data.mongodb.host=127.0.0.1 From 2b5163f2b309449efe3704296ce7cd316114a2eb Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Tue, 29 Oct 2024 11:07:37 +0100 Subject: [PATCH 30/37] stash --- ...yRegistryLinkDescriptorGenerationTest.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java index 2b7cc3794..d1280a303 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java @@ -52,6 +52,7 @@ import org.eclipse.digitaltwin.basyx.aasrepository.backend.inmemory.AasInMemoryBackendProvider; import org.eclipse.digitaltwin.basyx.aasservice.backend.InMemoryAasServiceFactory; import org.eclipse.digitaltwin.basyx.core.filerepository.InMemoryFileRepository; +import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; /** * Test suite for {@link RegistryIntegrationAasRepository} feature @@ -81,15 +82,22 @@ public void setUp() { } @Test - public void testExternalUrlWithContextPathWithoutTrailingSlashReflectedInDescriptor() throws FileNotFoundException, IOException, ApiException { - String externalUrl = BASE_URL + "/context"; + public void testExternalUrlWithContextPathWithoutTrailingSlash() throws FileNotFoundException, IOException, ApiException { + String externalUrl = BASE_URL + "/context/"; + +// int slashCount = externalUrl.length() - externalUrl.replace("/", "").length(); +// if (!externalUrl.endsWith("/") && slashCount >= 3) { +// externalUrl += "/"; +// } + Mockito.when(mockedRegistryLink.getAasRepositoryBaseURLs()).thenReturn(List.of(externalUrl)); - + AssetAdministrationShellDescriptor descriptor = createAndRetrieveDescriptor(createDummyAas()); - String expectedUrl = externalUrl; - assertTrue("Endpoint address should start with externalUrl including context path", descriptor.getEndpoints().get(0) - .getProtocolInformation().getHref().startsWith(expectedUrl)); + String expectedUrl = BASE_URL + "/context/shells/" + Base64UrlEncodedIdentifier.encodeIdentifier(DUMMY_AAS_ID); + String actualUrl = descriptor.getEndpoints().get(0).getProtocolInformation().getHref(); + + assertEquals(expectedUrl, actualUrl); } private AssetAdministrationShellDescriptor createAndRetrieveDescriptor(AssetAdministrationShell shell) throws ApiException { From 0de2d33f9e8bc9f1d9e3f8934944a5b51e1647ae Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Tue, 29 Oct 2024 11:34:54 +0100 Subject: [PATCH 31/37] fix: working registry url slash test --- .../AasRepositoryRegistryLinkDescriptorGenerationTest.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java index d1280a303..53d570262 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java @@ -83,13 +83,8 @@ public void setUp() { @Test public void testExternalUrlWithContextPathWithoutTrailingSlash() throws FileNotFoundException, IOException, ApiException { - String externalUrl = BASE_URL + "/context/"; + String externalUrl = BASE_URL + "/context"; -// int slashCount = externalUrl.length() - externalUrl.replace("/", "").length(); -// if (!externalUrl.endsWith("/") && slashCount >= 3) { -// externalUrl += "/"; -// } - Mockito.when(mockedRegistryLink.getAasRepositoryBaseURLs()).thenReturn(List.of(externalUrl)); AssetAdministrationShellDescriptor descriptor = createAndRetrieveDescriptor(createDummyAas()); From b1babf67f7124d207605909c2501051e9072fcd8 Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Tue, 29 Oct 2024 15:14:57 +0100 Subject: [PATCH 32/37] feat: working test --- .../registry/integration/AasRepositoryRegistryLink.java | 9 --------- .../integration/AasRepositoryRegistryLinkTest.java | 4 ---- .../integration/AasRepositoryRegistryLinkTestSuite.java | 2 +- .../src/test/resources/application.properties | 2 +- 4 files changed, 2 insertions(+), 15 deletions(-) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java index 1297c2bb5..d22a91eb6 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/main/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLink.java @@ -44,15 +44,6 @@ public AasRepositoryRegistryLink(RegistryAndDiscoveryInterfaceApi registryApi, L super(); this.registryApi = registryApi; this.aasRepositoryBaseURLs = aasRepositoryBaseURLs; - -// for (int i = 0; i < this.aasRepositoryBaseURLs.size(); i++) { -// String url = this.aasRepositoryBaseURLs.get(i); -// int slashCount = url.length() - url.replace("/", "").length(); -// if (!url.endsWith("/") && slashCount >= 3) { -// url += "/"; -// this.aasRepositoryBaseURLs.set(i, url); -// } -// } } public RegistryAndDiscoveryInterfaceApi getRegistryApi() { diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java index f33f7e252..c1abfc732 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java @@ -61,10 +61,6 @@ public static void tearDown() { @Override protected String[] getAasRepoBaseUrls() { String url = AAS_REPO_URL; -// int slashCount = url.length() - url.replace("/", "").length(); -// if (!url.endsWith("/") && slashCount >= 3) { -// url += "/"; -// } return new String[] { url }; } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java index a2c28cd6e..09c55e696 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTestSuite.java @@ -74,7 +74,7 @@ public void createAas() throws FileNotFoundException, IOException, ApiException String aasJsonContent = getAas1JSONString(); try (CloseableHttpResponse creationResponse = createAasOnRepo(aasJsonContent)) { -// assertEquals(HttpStatus.CREATED.value(), creationResponse.getCode()); + assertEquals(HttpStatus.CREATED.value(), creationResponse.getCode()); AssetAdministrationShellDescriptor actualDescriptor = retrieveDescriptorFromRegistry(); diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/application.properties b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/application.properties index f04bd82d7..4c42a98bc 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/application.properties +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/resources/application.properties @@ -7,7 +7,7 @@ basyx.aasrepo.name=aas-repo basyx.backend = InMemory basyx.aasrepository.feature.registryintegration=http://localhost:8050 -basyx.externalurl=http://localhost:8081/context +basyx.externalurl=http://localhost:8081 #basyx.backend = MongoDB #spring.data.mongodb.host=127.0.0.1 From ae3c9280989de3a02fcf47eb68a714dd84ad07f3 Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Tue, 29 Oct 2024 16:12:38 +0100 Subject: [PATCH 33/37] feat: add Submodel Repo Registry Test --- .../core/SubmodelRepositorySuite.java | 2 +- ...yRegistryLinkDescriptorGenerationTest.java | 110 ++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkDescriptorGenerationTest.java diff --git a/basyx.submodelrepository/basyx.submodelrepository-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/core/SubmodelRepositorySuite.java b/basyx.submodelrepository/basyx.submodelrepository-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/core/SubmodelRepositorySuite.java index 82fa5b6b5..e7276dfb0 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/core/SubmodelRepositorySuite.java +++ b/basyx.submodelrepository/basyx.submodelrepository-core/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/core/SubmodelRepositorySuite.java @@ -95,7 +95,7 @@ public void getAllSubmodelsBySemanticIDPreconfigured() { Collection expectedSubmodels = DummySubmodelFactory.getSubmodelsBySemanticid(DummySubmodelFactory.SUBMODEL_TECHNICAL_DATA_SEMANTIC_ID); SubmodelRepository repo = getSubmodelRepository(expectedSubmodels); - Collection submodels = repo.getAllSubmodels(DummySubmodelFactory.SUBMODEL_TECHNICAL_DATA_SEMANTIC_ID, NO_LIMIT_PAGINATION_INFO).getResult(); + Collection submodels = repo.getAllSubmodels(DummySubmodelFactory.SUBMODEL_TECHNICAL_DATA_SEMANTIC_ID, PaginationInfo.NO_LIMIT).getResult(); assertSubmodelsAreContained(expectedSubmodels, submodels); } diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkDescriptorGenerationTest.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkDescriptorGenerationTest.java new file mode 100644 index 000000000..88caba30d --- /dev/null +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkDescriptorGenerationTest.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (C) 2023 the Eclipse BaSyx Authors + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * SPDX-License-Identifier: MIT + ******************************************************************************/ + +package org.eclipse.digitaltwin.basyx.submodelrepository.feature.registry.integration; + +import static org.junit.Assert.assertEquals; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.List; + +import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultSubmodel; +import org.eclipse.digitaltwin.basyx.client.internal.ApiException; +import org.eclipse.digitaltwin.basyx.core.filerepository.InMemoryFileRepository; +import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.api.SubmodelRegistryApi; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.factory.SubmodelDescriptorFactory; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.mapper.AttributeMapper; +import org.eclipse.digitaltwin.basyx.submodelregistry.client.model.SubmodelDescriptor; +import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelInMemoryBackendProvider; +import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepository; +import org.eclipse.digitaltwin.basyx.submodelrepository.backend.SimpleSubmodelRepositoryFactory; +import org.eclipse.digitaltwin.basyx.submodelservice.InMemorySubmodelServiceFactory; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +/** + * Test suite for {@link RegistryIntegrationAasRepository} feature + */ +public class SubmodelRepositoryRegistryLinkDescriptorGenerationTest { + private static final String DUMMY_SUBMODEL_IDSHORT = "TechnicalData"; + private static final String DUMMY_SUBMODEL_ID = "7A7104BDAB57E184"; + + private static final String BASE_URL = "http://localhost:8081"; + + private RegistryIntegrationSubmodelRepository registryIntegrationSubmodelRepository; + private SubmodelRepository mockedSubmodelRepository; + private SubmodelRepositoryRegistryLink mockedRegistryLink; + private AttributeMapper mockedAttributeMapper; + private SubmodelRegistryApi mockedRegistryApi; + + @Before + public void setUp() { + mockedSubmodelRepository = getSubmodelRepository(); + mockedRegistryLink = Mockito.mock(SubmodelRepositoryRegistryLink.class); + mockedAttributeMapper = Mockito.mock(AttributeMapper.class); + mockedRegistryApi = Mockito.mock(SubmodelRegistryApi.class); + + Mockito.when(mockedRegistryLink.getRegistryApi()).thenReturn(mockedRegistryApi); + + registryIntegrationSubmodelRepository = new RegistryIntegrationSubmodelRepository(mockedSubmodelRepository, mockedRegistryLink, mockedAttributeMapper); + } + + @Test + public void testExternalUrlWithContextPathWithoutTrailingSlash() throws FileNotFoundException, IOException, ApiException { + String externalUrl = BASE_URL + "/context"; + + Mockito.when(mockedRegistryLink.getSubmodelRepositoryBaseURLs()).thenReturn(List.of(externalUrl)); + + SubmodelDescriptor descriptor = createAndRetrieveDescriptor(createDummySubmodel()); + + String expectedUrl = BASE_URL + "/context/submodels/" + Base64UrlEncodedIdentifier.encodeIdentifier(DUMMY_SUBMODEL_ID); + String actualUrl = descriptor.getEndpoints().get(0).getProtocolInformation().getHref(); + + assertEquals(expectedUrl, actualUrl); + } + + private SubmodelDescriptor createAndRetrieveDescriptor(Submodel submodel) throws ApiException { + // Simulate the process of creating an AAS in the repository + registryIntegrationSubmodelRepository.createSubmodel(submodel); + + // Simulate retrieving the descriptor from the registry after creation + SubmodelDescriptorFactory descriptorFactory = new SubmodelDescriptorFactory(submodel, mockedRegistryLink.getSubmodelRepositoryBaseURLs(), mockedAttributeMapper); + return descriptorFactory.create(); + } + + private Submodel createDummySubmodel() { + // You can create a mock or a real AAS object + return new DefaultSubmodel.Builder().id(DUMMY_SUBMODEL_ID).idShort(DUMMY_SUBMODEL_IDSHORT).build(); + } + + protected SubmodelRepository getSubmodelRepository() { + return new SimpleSubmodelRepositoryFactory(new SubmodelInMemoryBackendProvider(), new InMemorySubmodelServiceFactory(new InMemoryFileRepository())).create(); + } + +} From a9f4ad27d08f20b6de61970db5668fb9bff5b60e Mon Sep 17 00:00:00 2001 From: ShehriyarShariq-Fraunhofer Date: Tue, 29 Oct 2024 17:03:48 +0100 Subject: [PATCH 34/37] fix: revert pom.xml --- .../basyx.submodelrepository-backend-inmemory/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basyx.submodelrepository/basyx.submodelrepository-backend-inmemory/pom.xml b/basyx.submodelrepository/basyx.submodelrepository-backend-inmemory/pom.xml index 07c7e8b88..1edfa7be2 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-backend-inmemory/pom.xml +++ b/basyx.submodelrepository/basyx.submodelrepository-backend-inmemory/pom.xml @@ -25,7 +25,7 @@ org.eclipse.digitaltwin.basyx basyx.submodelservice-core - + org.eclipse.digitaltwin.basyx basyx.backend.inmemory.core From ed11d33d567612a1a1c6be2b437e8fe5824fce33 Mon Sep 17 00:00:00 2001 From: mateusmolina Date: Mon, 4 Nov 2024 14:18:06 +0100 Subject: [PATCH 35/37] style: code clean-up --- .../TestAuthorizedAasRepository.java | 55 +++++++++++-------- ...yRegistryLinkDescriptorGenerationTest.java | 22 ++------ .../AasRepositoryRegistryLinkTest.java | 6 +- .../inmemory/core/InMemoryCrudRepository.java | 2 +- .../basyx/core/RepositoryUrlHelper.java | 5 +- .../backend/CrudSubmodelRepository.java | 5 ++ ...yRegistryLinkDescriptorGenerationTest.java | 7 +-- 7 files changed, 50 insertions(+), 52 deletions(-) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java b/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java index b6e71e699..83c561788 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-authorization/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/authorization/TestAuthorizedAasRepository.java @@ -73,7 +73,7 @@ */ public class TestAuthorizedAasRepository { -// private static final String AAS_REPOSITORY_PATH = "/shells"; + private static final String AAS_REPOSITORY_PATH = "/shells"; private static final String AAS_SIMPLE_2_JSON = "authorization/AasSimple_2.json"; private static final String AAS_SIMPLE_1_JSON = "authorization/AasSimple_1.json"; private static final String SPECIFIC_SHELL_ID_2 = "specificAasId-2"; @@ -559,10 +559,10 @@ public void getThumbnailWithCorrectRoleAndPermission() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_READER_CREDENTIAL); - CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test @@ -571,17 +571,17 @@ public void getThumbnailWithCorrectRoleAndSpecificAasPermission() throws IOExcep String accessToken = getAccessToken(DummyCredentialStore.BASYX_READER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test public void getThumbnailWithCorrectRoleAndUnauthorizedSpecificAas() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_READER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID_2), accessToken); + CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID_2), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @@ -589,13 +589,13 @@ public void getThumbnailWithCorrectRoleAndUnauthorizedSpecificAas() throws IOExc public void getThumbnailWithInsufficientPermissionRole() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_DELETER_CREDENTIAL); - CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @Test public void getThumbnailWithNoAuthorization() throws IOException { - CloseableHttpResponse retrievalResponse = getElementWithNoAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID)); + CloseableHttpResponse retrievalResponse = getElementWithNoAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID)); assertEquals(HttpStatus.UNAUTHORIZED.value(), retrievalResponse.getCode()); } @@ -607,7 +607,7 @@ public void setThumbnailWithCorrectRoleAndPermission() throws IOException { CloseableHttpResponse retrievalResponse = setThumbnailToAasWithAuthorization(SPECIFIC_SHELL_ID, accessToken); assertEquals(HttpStatus.NO_CONTENT.value(), retrievalResponse.getCode()); - deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test @@ -617,7 +617,7 @@ public void setThumbnailWithCorrectRoleAndSpecificAasPermission() throws IOExcep CloseableHttpResponse retrievalResponse = setThumbnailToAasWithAuthorization(SPECIFIC_SHELL_ID, accessToken); assertEquals(HttpStatus.NO_CONTENT.value(), retrievalResponse.getCode()); - deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test @@ -649,10 +649,10 @@ public void deleteThumbnailWithCorrectRoleAndPermission() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_ASSET_UPDATER_CREDENTIAL); - CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - assertElementIsNotOnServer(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + assertElementIsNotOnServer(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @Test @@ -663,10 +663,10 @@ public void deleteThumbnailWithCorrectRoleAndSpecificAasPermission() throws IOEx String accessToken = getAccessToken(DummyCredentialStore.BASYX_ASSET_UPDATER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID_2), accessToken); + CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID_2), accessToken); assertEquals(HttpStatus.OK.value(), retrievalResponse.getCode()); - assertElementIsNotOnServer(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID_2), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); + assertElementIsNotOnServer(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID_2), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); deleteElementWithAuthorization(getSpecificAasAccessURL(SPECIFIC_SHELL_ID_2), getAccessToken(DummyCredentialStore.ADMIN_CREDENTIAL)); } @@ -674,7 +674,7 @@ public void deleteThumbnailWithCorrectRoleAndSpecificAasPermission() throws IOEx public void deleteThumbnailWithCorrectRoleAndUnauthorizedSpecificAas() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_ASSET_UPDATER_TWO_CREDENTIAL); - CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @@ -682,13 +682,13 @@ public void deleteThumbnailWithCorrectRoleAndUnauthorizedSpecificAas() throws IO public void deleteThumbnailWithInsufficientPermissionRole() throws IOException { String accessToken = getAccessToken(DummyCredentialStore.BASYX_CREATOR_CREDENTIAL); - CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID), accessToken); + CloseableHttpResponse retrievalResponse = deleteElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), accessToken); assertEquals(HttpStatus.FORBIDDEN.value(), retrievalResponse.getCode()); } @Test public void deleteThumbnailWithNoAuthorization() throws IOException { - CloseableHttpResponse retrievalResponse = deleteElementWithNoAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(aasRepositoryBaseUrl, SPECIFIC_SHELL_ID)); + CloseableHttpResponse retrievalResponse = deleteElementWithNoAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID)); assertEquals(HttpStatus.UNAUTHORIZED.value(), retrievalResponse.getCode()); } @@ -746,11 +746,11 @@ private String getAccessToken(DummyCredential dummyCredential) { } protected CloseableHttpResponse getAllAasWithAuthorization(String accessToken) throws IOException { - return BaSyxHttpTestUtils.executeAuthorizedGetOnURL(aasRepositoryBaseUrl, accessToken); + return BaSyxHttpTestUtils.executeAuthorizedGetOnURL(createAasRepositoryUrl(aasRepositoryBaseUrl), accessToken); } protected CloseableHttpResponse getAllAasNoAuthorization() throws IOException { - return BaSyxHttpTestUtils.executeGetOnURL(aasRepositoryBaseUrl); + return BaSyxHttpTestUtils.executeGetOnURL(createAasRepositoryUrl(aasRepositoryBaseUrl)); } protected CloseableHttpResponse getElementWithAuthorization(String url, String accessToken) throws IOException { @@ -762,11 +762,11 @@ protected CloseableHttpResponse getElementWithNoAuthorization(String url) throws } protected String getSpecificAasAccessURL(String shellId) { - return aasRepositoryBaseUrl + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(shellId); + return createAasRepositoryUrl(createAasRepositoryUrl(aasRepositoryBaseUrl)) + "/" + Base64UrlEncodedIdentifier.encodeIdentifier(shellId); } private static CloseableHttpResponse createAasOnRepositoryWithAuthorization(String aasJsonContent, String accessToken) throws IOException { - return BaSyxHttpTestUtils.executeAuthorizedPostOnURL(aasRepositoryBaseUrl, aasJsonContent, accessToken); + return BaSyxHttpTestUtils.executeAuthorizedPostOnURL(createAasRepositoryUrl(aasRepositoryBaseUrl), aasJsonContent, accessToken); } private CloseableHttpResponse setThumbnailToAasWithAuthorization(String shellId, String accessToken) throws IOException { @@ -782,7 +782,7 @@ private CloseableHttpResponse setThumbnailToAasWithNoAuthorization(String shellI } private static CloseableHttpResponse createAasOnRepositoryWithNoAuthorization(String aasJsonContent) throws IOException { - return BaSyxHttpTestUtils.executePostOnURL(aasRepositoryBaseUrl, aasJsonContent); + return BaSyxHttpTestUtils.executePostOnURL(createAasRepositoryUrl(aasRepositoryBaseUrl), aasJsonContent); } private CloseableHttpResponse updateElementWithAuthorizationPutRequest(String url, String aasJsonContent, String accessToken) throws IOException { @@ -842,6 +842,15 @@ private String getSpecificSubmodelReferenceUrl(String shellId, String submodelId private static String getThumbnailAccessURL(String aasId) { Base64UrlEncodedIdentifier identifier = new Base64UrlEncodedIdentifier(aasId); - return aasRepositoryBaseUrl + "/" + identifier.getEncodedIdentifier() + "/asset-information/thumbnail"; + return createAasRepositoryUrl(aasRepositoryBaseUrl) + "/" + identifier.getEncodedIdentifier() + "/asset-information/thumbnail"; + } + + private static String createAasRepositoryUrl(String aasRepositoryBaseURL) { + + try { + return new URL(new URL(aasRepositoryBaseURL), AAS_REPOSITORY_PATH).toString(); + } catch (MalformedURLException e) { + throw new RuntimeException("The AAS Repository Base url is malformed. " + e.getMessage()); + } } } diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java index 53d570262..0c5aa5932 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java @@ -26,33 +26,24 @@ package org.eclipse.digitaltwin.basyx.aasrepository.feature.registry.integration; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; -import java.io.FileNotFoundException; -import java.io.IOException; import java.util.List; import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetAdministrationShell; -import org.eclipse.digitaltwin.basyx.aasregistry.client.ApiException; import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.springframework.boot.SpringApplication; -import org.springframework.context.ConfigurableApplicationContext; import org.eclipse.digitaltwin.basyx.aasregistry.main.client.factory.AasDescriptorFactory; import org.eclipse.digitaltwin.basyx.aasregistry.main.client.mapper.AttributeMapper; -import org.eclipse.digitaltwin.basyx.aasregistry.main.client.mapper.DummyAasDescriptorFactory; import org.eclipse.digitaltwin.basyx.aasrepository.AasRepository; import org.eclipse.digitaltwin.basyx.aasrepository.backend.SimpleAasRepositoryFactory; import org.eclipse.digitaltwin.basyx.aasrepository.backend.inmemory.AasInMemoryBackendProvider; import org.eclipse.digitaltwin.basyx.aasservice.backend.InMemoryAasServiceFactory; import org.eclipse.digitaltwin.basyx.core.filerepository.InMemoryFileRepository; import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; /** * Test suite for {@link RegistryIntegrationAasRepository} feature @@ -82,7 +73,7 @@ public void setUp() { } @Test - public void testExternalUrlWithContextPathWithoutTrailingSlash() throws FileNotFoundException, IOException, ApiException { + public void testExternalUrlWithContextPathWithoutTrailingSlash() { String externalUrl = BASE_URL + "/context"; Mockito.when(mockedRegistryLink.getAasRepositoryBaseURLs()).thenReturn(List.of(externalUrl)); @@ -95,17 +86,14 @@ public void testExternalUrlWithContextPathWithoutTrailingSlash() throws FileNotF assertEquals(expectedUrl, actualUrl); } - private AssetAdministrationShellDescriptor createAndRetrieveDescriptor(AssetAdministrationShell shell) throws ApiException { - // Simulate the process of creating an AAS in the repository + private AssetAdministrationShellDescriptor createAndRetrieveDescriptor(AssetAdministrationShell shell) { registryIntegrationAasRepository.createAas(shell); - // Simulate retrieving the descriptor from the registry after creation AasDescriptorFactory descriptorFactory = new AasDescriptorFactory(shell, mockedRegistryLink.getAasRepositoryBaseURLs(), mockedAttributeMapper); return descriptorFactory.create(); } private AssetAdministrationShell createDummyAas() { - // You can create a mock or a real AAS object return new DefaultAssetAdministrationShell.Builder() .id(DUMMY_AAS_ID) .idShort(DUMMY_IDSHORT) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java index c1abfc732..ebafe20d1 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java @@ -41,7 +41,7 @@ */ public class AasRepositoryRegistryLinkTest extends AasRepositoryRegistryLinkTestSuite { - private static final String AAS_REPO_URL = "http://localhost:8081/"; + private static final String AAS_REPO_URL = "http://localhost:8081"; private static final String AAS_REGISTRY_BASE_URL = "http://localhost:8050"; private static ConfigurableApplicationContext appContext; private static AasRepositoryRegistryLink aasRepositoryRegistryLink; @@ -60,9 +60,7 @@ public static void tearDown() { @Override protected String[] getAasRepoBaseUrls() { - String url = AAS_REPO_URL; - - return new String[] { url }; + return new String[] { AAS_REPO_URL }; } @Override diff --git a/basyx.common/basyx.backend.inmemory.core/src/main/java/org/eclipse/digitaltwin/basyx/common/backend/inmemory/core/InMemoryCrudRepository.java b/basyx.common/basyx.backend.inmemory.core/src/main/java/org/eclipse/digitaltwin/basyx/common/backend/inmemory/core/InMemoryCrudRepository.java index 44a3eb020..8c5267266 100644 --- a/basyx.common/basyx.backend.inmemory.core/src/main/java/org/eclipse/digitaltwin/basyx/common/backend/inmemory/core/InMemoryCrudRepository.java +++ b/basyx.common/basyx.backend.inmemory.core/src/main/java/org/eclipse/digitaltwin/basyx/common/backend/inmemory/core/InMemoryCrudRepository.java @@ -122,4 +122,4 @@ public void deleteAll() { } -} \ No newline at end of file +} diff --git a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java index 00bd3d841..a046bfcc2 100644 --- a/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java +++ b/basyx.common/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java @@ -29,7 +29,10 @@ import java.net.URI; import java.net.URISyntaxException; -public class RepositoryUrlHelper { +public final class RepositoryUrlHelper { + + private RepositoryUrlHelper() { + } public static String createRepositoryUrl(String baseUrl, String additionalPath) { try { diff --git a/basyx.submodelrepository/basyx.submodelrepository-backend/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/backend/CrudSubmodelRepository.java b/basyx.submodelrepository/basyx.submodelrepository-backend/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/backend/CrudSubmodelRepository.java index 305b8ad94..5f6f91ed8 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-backend/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/backend/CrudSubmodelRepository.java +++ b/basyx.submodelrepository/basyx.submodelrepository-backend/src/main/java/org/eclipse/digitaltwin/basyx/submodelrepository/backend/CrudSubmodelRepository.java @@ -26,6 +26,7 @@ package org.eclipse.digitaltwin.basyx.submodelrepository.backend; import java.io.InputStream; +import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -35,8 +36,10 @@ import java.util.stream.StreamSupport; import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement; +import org.eclipse.digitaltwin.basyx.client.internal.ApiException; import org.eclipse.digitaltwin.basyx.core.exceptions.CollidingIdentifierException; import org.eclipse.digitaltwin.basyx.core.exceptions.ElementDoesNotExistException; import org.eclipse.digitaltwin.basyx.core.exceptions.ElementNotAFileException; @@ -46,6 +49,7 @@ import org.eclipse.digitaltwin.basyx.core.pagination.CursorResult; import org.eclipse.digitaltwin.basyx.core.pagination.PaginationInfo; import org.eclipse.digitaltwin.basyx.core.pagination.PaginationSupport; +import org.eclipse.digitaltwin.basyx.http.Base64UrlEncoder; import org.eclipse.digitaltwin.basyx.serialization.SubmodelMetadataUtil; import org.eclipse.digitaltwin.basyx.submodelrepository.SubmodelRepository; import org.eclipse.digitaltwin.basyx.submodelservice.SubmodelService; @@ -55,6 +59,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.repository.CrudRepository; +import org.springframework.http.HttpStatus; /** * Default Implementation for the {@link SubmodelRepository} based on Spring diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkDescriptorGenerationTest.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkDescriptorGenerationTest.java index 88caba30d..607b0e866 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkDescriptorGenerationTest.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkDescriptorGenerationTest.java @@ -27,8 +27,6 @@ import static org.junit.Assert.assertEquals; -import java.io.FileNotFoundException; -import java.io.IOException; import java.util.List; import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; @@ -76,7 +74,7 @@ public void setUp() { } @Test - public void testExternalUrlWithContextPathWithoutTrailingSlash() throws FileNotFoundException, IOException, ApiException { + public void testExternalUrlWithContextPathWithoutTrailingSlash() throws ApiException { String externalUrl = BASE_URL + "/context"; Mockito.when(mockedRegistryLink.getSubmodelRepositoryBaseURLs()).thenReturn(List.of(externalUrl)); @@ -90,16 +88,13 @@ public void testExternalUrlWithContextPathWithoutTrailingSlash() throws FileNotF } private SubmodelDescriptor createAndRetrieveDescriptor(Submodel submodel) throws ApiException { - // Simulate the process of creating an AAS in the repository registryIntegrationSubmodelRepository.createSubmodel(submodel); - // Simulate retrieving the descriptor from the registry after creation SubmodelDescriptorFactory descriptorFactory = new SubmodelDescriptorFactory(submodel, mockedRegistryLink.getSubmodelRepositoryBaseURLs(), mockedAttributeMapper); return descriptorFactory.create(); } private Submodel createDummySubmodel() { - // You can create a mock or a real AAS object return new DefaultSubmodel.Builder().id(DUMMY_SUBMODEL_ID).idShort(DUMMY_SUBMODEL_IDSHORT).build(); } From 4913629983c1bc3dabb2a8662b168e162dc882b2 Mon Sep 17 00:00:00 2001 From: mateusmolina Date: Mon, 4 Nov 2024 14:29:09 +0100 Subject: [PATCH 36/37] test: refactor *RepositoryRegistryLink tests to be parameterized --- ...yRegistryLinkDescriptorGenerationTest.java | 30 ++++++++++++++----- ...yRegistryLinkDescriptorGenerationTest.java | 30 ++++++++++++++----- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java index 0c5aa5932..fc5991214 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java @@ -27,6 +27,8 @@ import static org.junit.Assert.assertEquals; +import java.util.Arrays; +import java.util.Collection; import java.util.List; import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; @@ -43,11 +45,14 @@ import org.eclipse.digitaltwin.basyx.http.Base64UrlEncodedIdentifier; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import org.mockito.Mockito; /** * Test suite for {@link RegistryIntegrationAasRepository} feature */ +@RunWith(Parameterized.class) public class AasRepositoryRegistryLinkDescriptorGenerationTest { private static final String DUMMY_IDSHORT = "ExampleMotor"; private static final String DUMMY_AAS_ID = "customIdentifier"; @@ -72,20 +77,29 @@ public void setUp() { registryIntegrationAasRepository = new RegistryIntegrationAasRepository(mockedAasRepository, mockedRegistryLink, mockedAttributeMapper); } + @Parameterized.Parameter(0) + public String externalUrl; + + @Parameterized.Parameter(1) + public String expectedUrl; + + @Parameterized.Parameters + public static Collection data() { + return Arrays.asList(new Object[][] { { BASE_URL + "/context", BASE_URL + "/context/shells/" + Base64UrlEncodedIdentifier.encodeIdentifier(DUMMY_AAS_ID) }, + { BASE_URL, BASE_URL + "/shells/" + Base64UrlEncodedIdentifier.encodeIdentifier(DUMMY_AAS_ID) }, { BASE_URL + "/", BASE_URL + "/shells/" + Base64UrlEncodedIdentifier.encodeIdentifier(DUMMY_AAS_ID) }, + { BASE_URL + "/context/", BASE_URL + "/context/shells/" + Base64UrlEncodedIdentifier.encodeIdentifier(DUMMY_AAS_ID) } }); + } + @Test - public void testExternalUrlWithContextPathWithoutTrailingSlash() { - String externalUrl = BASE_URL + "/context"; - + public void testExternalUrl() { Mockito.when(mockedRegistryLink.getAasRepositoryBaseURLs()).thenReturn(List.of(externalUrl)); - - AssetAdministrationShellDescriptor descriptor = createAndRetrieveDescriptor(createDummyAas()); - String expectedUrl = BASE_URL + "/context/shells/" + Base64UrlEncodedIdentifier.encodeIdentifier(DUMMY_AAS_ID); + AssetAdministrationShellDescriptor descriptor = createAndRetrieveDescriptor(createDummyAas()); String actualUrl = descriptor.getEndpoints().get(0).getProtocolInformation().getHref(); - + assertEquals(expectedUrl, actualUrl); } - + private AssetAdministrationShellDescriptor createAndRetrieveDescriptor(AssetAdministrationShell shell) { registryIntegrationAasRepository.createAas(shell); diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkDescriptorGenerationTest.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkDescriptorGenerationTest.java index 607b0e866..51777d217 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkDescriptorGenerationTest.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkDescriptorGenerationTest.java @@ -27,6 +27,8 @@ import static org.junit.Assert.assertEquals; +import java.util.Arrays; +import java.util.Collection; import java.util.List; import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; @@ -44,11 +46,14 @@ import org.eclipse.digitaltwin.basyx.submodelservice.InMemorySubmodelServiceFactory; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import org.mockito.Mockito; /** * Test suite for {@link RegistryIntegrationAasRepository} feature */ +@RunWith(Parameterized.class) public class SubmodelRepositoryRegistryLinkDescriptorGenerationTest { private static final String DUMMY_SUBMODEL_IDSHORT = "TechnicalData"; private static final String DUMMY_SUBMODEL_ID = "7A7104BDAB57E184"; @@ -73,20 +78,29 @@ public void setUp() { registryIntegrationSubmodelRepository = new RegistryIntegrationSubmodelRepository(mockedSubmodelRepository, mockedRegistryLink, mockedAttributeMapper); } + @Parameterized.Parameter(0) + public String externalUrl; + + @Parameterized.Parameter(1) + public String expectedUrl; + + @Parameterized.Parameters + public static Collection data() { + return Arrays.asList(new Object[][] { { BASE_URL + "/context", BASE_URL + "/context/submodels/" + Base64UrlEncodedIdentifier.encodeIdentifier(DUMMY_SUBMODEL_ID) }, + { BASE_URL, BASE_URL + "/submodels/" + Base64UrlEncodedIdentifier.encodeIdentifier(DUMMY_SUBMODEL_ID) }, { BASE_URL + "/", BASE_URL + "/submodels/" + Base64UrlEncodedIdentifier.encodeIdentifier(DUMMY_SUBMODEL_ID) }, + { BASE_URL + "/context/", BASE_URL + "/context/submodels/" + Base64UrlEncodedIdentifier.encodeIdentifier(DUMMY_SUBMODEL_ID) } }); + } + @Test - public void testExternalUrlWithContextPathWithoutTrailingSlash() throws ApiException { - String externalUrl = BASE_URL + "/context"; - + public void testExternalUrl() throws ApiException { Mockito.when(mockedRegistryLink.getSubmodelRepositoryBaseURLs()).thenReturn(List.of(externalUrl)); - - SubmodelDescriptor descriptor = createAndRetrieveDescriptor(createDummySubmodel()); - String expectedUrl = BASE_URL + "/context/submodels/" + Base64UrlEncodedIdentifier.encodeIdentifier(DUMMY_SUBMODEL_ID); + SubmodelDescriptor descriptor = createAndRetrieveDescriptor(createDummySubmodel()); String actualUrl = descriptor.getEndpoints().get(0).getProtocolInformation().getHref(); - + assertEquals(expectedUrl, actualUrl); } - + private SubmodelDescriptor createAndRetrieveDescriptor(Submodel submodel) throws ApiException { registryIntegrationSubmodelRepository.createSubmodel(submodel); From 1119feba9bbc16b11b1152a0f0644637353b3684 Mon Sep 17 00:00:00 2001 From: mateusmolina Date: Mon, 4 Nov 2024 14:35:55 +0100 Subject: [PATCH 37/37] style: minor fixes --- .../AasRepositoryRegistryLinkDescriptorGenerationTest.java | 2 +- .../registry/integration/AasRepositoryRegistryLinkTest.java | 2 +- .../SubmodelRepositoryRegistryLinkDescriptorGenerationTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java index fc5991214..7c751945b 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors + * Copyright (C) 2024 the Eclipse BaSyx Authors * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java index ebafe20d1..e35a8130a 100644 --- a/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java +++ b/basyx.aasrepository/basyx.aasrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/aasrepository/feature/registry/integration/AasRepositoryRegistryLinkTest.java @@ -60,7 +60,7 @@ public static void tearDown() { @Override protected String[] getAasRepoBaseUrls() { - return new String[] { AAS_REPO_URL }; + return new String[] { AAS_REPO_URL}; } @Override diff --git a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkDescriptorGenerationTest.java b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkDescriptorGenerationTest.java index 51777d217..a414b8108 100644 --- a/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkDescriptorGenerationTest.java +++ b/basyx.submodelrepository/basyx.submodelrepository-feature-registry-integration/src/test/java/org/eclipse/digitaltwin/basyx/submodelrepository/feature/registry/integration/SubmodelRepositoryRegistryLinkDescriptorGenerationTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (C) 2023 the Eclipse BaSyx Authors + * Copyright (C) 2024 the Eclipse BaSyx Authors * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the