fix: add a check for / suffix for basyx external url in registry integration#333
fix: add a check for / suffix for basyx external url in registry integration#333aaronzi merged 50 commits intoeclipse-basyx:mainfrom ShehriyarShariq-Fraunhofer:fix-slash-check-registry-integration
Conversation
….com/ShehriyarShariq-Fraunhofer/basyx-java-server-sdk into fix-slash-check-registry-integration
….com/ShehriyarShariq-Fraunhofer/basyx-java-server-sdk into fix-slash-check-registry-integration
….com/ShehriyarShariq-Fraunhofer/basyx-java-server-sdk into fix-slash-check-registry-integration
| public void testUrlWithTrailingSlashAndPathWithLeadingSlash() { | ||
| String baseURLWithSlash = AAS_REPO_URL + "/"; | ||
|
|
||
| assertEquals(baseURLWithSlash + AAS_REPOSITORY_PATH_WITHOUT_SLASH, AasDescriptorFactory.createAasRepositoryUrl(baseURLWithSlash)); |
There was a problem hiding this comment.
The assertion is wrongly defined
| public void testUrlWithoutTrailingSlashAndPathWithoutLeadingSlash() { | ||
| String baseURLWithoutSlash = AAS_REPO_URL; | ||
|
|
||
| assertEquals(baseURLWithoutSlash + AAS_REPOSITORY_PATH_WITH_SLASH , AasDescriptorFactory.createAasRepositoryUrl(baseURLWithoutSlash)); |
There was a problem hiding this comment.
The assertion is wrongly defined
| 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"; |
There was a problem hiding this comment.
Either stick to building the withSlash/withoutSlash for both path and repo_url in the test or define them consistenly as final vars; but don't mix both approaches.
| public void testUrlWithTrailingSlashAndPathWithLeadingSlash() { | ||
| String baseURLWithSlash = SUBMODEL_REPO_URL + "/"; | ||
|
|
||
| assertEquals(baseURLWithSlash + SUBMODEL_REPOSITORY_PATH_WITHOUT_SLASH, SubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithSlash)); |
There was a problem hiding this comment.
The assertion is wrongly defined
| private static final String SUBMODEL_REPO_URL = "http://localhost:8081"; | ||
|
|
||
|
|
||
| private static final String SUBMODEL_REPOSITORY_PATH_WITH_SLASH = "/submodels"; |
There was a problem hiding this comment.
Same issue as in the TestAasDescriptorFactory
| public void testUrlWithoutTrailingSlashAndPathWithoutLeadingSlash() { | ||
| String baseURLWithoutSlash = SUBMODEL_REPO_URL; | ||
|
|
||
| assertEquals(baseURLWithoutSlash + SUBMODEL_REPOSITORY_PATH_WITH_SLASH , SubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithoutSlash)); |
There was a problem hiding this comment.
The assertion is wrongly defined
|
|
||
| public static String createRepositoryUrl(String baseUrl, String additionalPath) { | ||
| try { | ||
| // Create a URI from the base URL |
There was a problem hiding this comment.
Please the remove the comments
| import org.springframework.web.util.UriComponentsBuilder; | ||
|
|
||
|
|
||
| public class Helper { |
There was a problem hiding this comment.
change the name of the helper class. Please also change the test's name
|
|
||
| @Test | ||
| public void testUrlWithTrailingSlashAndPathNameWithNoLeadingSlash() { | ||
| 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 testUrlWithoutTrailingSlashAndPathNameWithNoLeadingSlash() { | ||
| assertEquals(BASE_URL + "/" + PATH , Helper.createRepositoryUrl(BASE_URL, PATH)); |
There was a problem hiding this comment.
make BASE_URL + "/" + PATH a private static final String EXPECTED_URL
| public void testUrlWithoutTrailingSlashAndPathNameWithLeadingSlash() { | ||
| assertEquals(BASE_URL + "/" + PATH , Helper.createRepositoryUrl(BASE_URL, "/" + PATH)); | ||
| } | ||
|
|
There was a problem hiding this comment.
Add tests for urls with a contextPath already set
….com/ShehriyarShariq-Fraunhofer/basyx-java-server-sdk into fix-slash-check-registry-integration
There was a problem hiding this comment.
The main issue is that there is no explicit test for the externalUrl URL in the registry-integration features. I was expecting tests for externalUrl in the aasrepository-feature-registry-integration and submodelrepository-feature-registry-integration features. Please find below the entry point to where the externalUrl is mapped (similarly for the submodel feature):
What happens when the / suffix is added or not added to the externalUrl there?
| @@ -0,0 +1,36 @@ | |||
| package org.eclipse.digitaltwin.basyx.core; | |||
| @@ -0,0 +1,59 @@ | |||
| package org.eclipse.digitaltwin.basyx.core; | |||
| String accessToken = getAccessToken(DummyCredentialStore.BASYX_READER_CREDENTIAL); | ||
|
|
||
| CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(createAasRepositoryUrl(aasRepositoryBaseUrl), SPECIFIC_SHELL_ID), accessToken); | ||
| CloseableHttpResponse retrievalResponse = getElementWithAuthorization(BaSyxHttpTestUtils.getThumbnailAccessURL(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), accessToken); |
There was a problem hiding this comment.
Are the calls to createRepositoryUrl(...) necessary? The second par is always null. Either remove them OR remove the shells context in aasRepositoryBaseUrl and use AAS_REPOSITORY_PATH and createRepositoryUrl(...) to generate the url.
….com/ShehriyarShariq-Fraunhofer/basyx-java-server-sdk into fix-slash-check-registry-integration
Added a trailing slash in case one was missing for the basyx external url in registry integration.
Closes #414