Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add a check for / suffix for basyx external url in registry integration #333

Conversation

ShehriyarShariq-Fraunhofer
Copy link
Contributor

@ShehriyarShariq-Fraunhofer ShehriyarShariq-Fraunhofer commented Jul 9, 2024

Added a trailing slash in case one was missing for the basyx external url in registry integration.

Closes #414

@ShehriyarShariq-Fraunhofer
Copy link
Contributor Author

@mateusmolina-iese

public void testUrlWithTrailingSlashAndPathWithLeadingSlash() {
String baseURLWithSlash = AAS_REPO_URL + "/";

assertEquals(baseURLWithSlash + AAS_REPOSITORY_PATH_WITHOUT_SLASH, AasDescriptorFactory.createAasRepositoryUrl(baseURLWithSlash));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assertion is wrongly defined

public void testUrlWithoutTrailingSlashAndPathWithoutLeadingSlash() {
String baseURLWithoutSlash = AAS_REPO_URL;

assertEquals(baseURLWithoutSlash + AAS_REPOSITORY_PATH_WITH_SLASH , AasDescriptorFactory.createAasRepositoryUrl(baseURLWithoutSlash));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as in the TestAasDescriptorFactory

public void testUrlWithoutTrailingSlashAndPathWithoutLeadingSlash() {
String baseURLWithoutSlash = SUBMODEL_REPO_URL;

assertEquals(baseURLWithoutSlash + SUBMODEL_REPOSITORY_PATH_WITH_SLASH , SubmodelDescriptorFactory.createSubmodelRepositoryUrl(baseURLWithoutSlash));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assertion is wrongly defined


public static String createRepositoryUrl(String baseUrl, String additionalPath) {
try {
// Create a URI from the base URL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please the remove the comments

import org.springframework.web.util.UriComponentsBuilder;


public class Helper {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tab


@Test
public void testUrlWithTrailingSlashAndPathNameWithLeadingSlash() {
assertEquals(BASE_URL + "/" + PATH, Helper.createRepositoryUrl(BASE_URL + "/", "/" + PATH));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tab


@Test
public void testUrlWithoutTrailingSlashAndPathNameWithNoLeadingSlash() {
assertEquals(BASE_URL + "/" + PATH , Helper.createRepositoryUrl(BASE_URL, PATH));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make BASE_URL + "/" + PATH a private static final String EXPECTED_URL

public void testUrlWithoutTrailingSlashAndPathNameWithLeadingSlash() {
assertEquals(BASE_URL + "/" + PATH , Helper.createRepositoryUrl(BASE_URL, "/" + PATH));
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests for urls with a contextPath already set

Copy link
Member

@mateusmolina-iese mateusmolina-iese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add license header

@@ -0,0 +1,59 @@
package org.eclipse.digitaltwin.basyx.core;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add license header

@@ -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(RepositoryUrlHelper.createRepositoryUrl(aasRepositoryBaseUrl, null), SPECIFIC_SHELL_ID), accessToken);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ShehriyarShariq-Fraunhofer ShehriyarShariq-Fraunhofer marked this pull request as ready for review November 5, 2024 06:41
@aaronzi aaronzi merged commit c9f8845 into eclipse-basyx:main Nov 5, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a check for "/" suffix for basyx external url in registry integration
3 participants