-
Notifications
You must be signed in to change notification settings - Fork 56
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
Merged
aaronzi
merged 50 commits into
eclipse-basyx:main
from
ShehriyarShariq-Fraunhofer:fix-slash-check-registry-integration
Nov 5, 2024
Merged
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
82a79d2
fix: add a check for / suffix for basyx external url in registry int…
ShehriyarShariq-Fraunhofer 4a7a8aa
fix: submodal integration test
ShehriyarShariq-Fraunhofer 62d44d1
Empty commit for the CI to run
MateusMolina 13868a9
fix: registry integration create url logic
ShehriyarShariq-Fraunhofer 94923af
Merge branch 'fix-slash-check-registry-integration' of https://github…
ShehriyarShariq-Fraunhofer bb3e3e9
Empty commit for the CI to run
MateusMolina 437ac16
fix: latest merge
ShehriyarShariq-Fraunhofer 9bdb684
Empty commit for the CI to run
MateusMolina c410c6a
fix: feature-registry-integration createURL remove static reference i…
ShehriyarShariq-Fraunhofer 245bae2
Merge branch 'fix-slash-check-registry-integration' of https://github…
ShehriyarShariq-Fraunhofer dae87d7
Triggering the CI
MateusMolina ba08cbd
fix: createUrl method issue with path without leading slash resolved
ShehriyarShariq-Fraunhofer 99a47de
Merge branch 'fix-slash-check-registry-integration' of https://github…
ShehriyarShariq-Fraunhofer 9d86f9e
fix: use main static createUrl method in DescriptorFactory test cases
ShehriyarShariq-Fraunhofer c75b166
refactor: remove create*Url method from Dummy*DescriptorFactory
ShehriyarShariq-Fraunhofer 9272437
fix: Test*DescriptorFactory refactor tests
ShehriyarShariq-Fraunhofer ad5b8a1
Merge branch 'main' into fix-slash-check-registry-integration
ShehriyarShariq-Fraunhofer 27e19d4
refactor: make createRepositoryUrl common + refactor implementation
ShehriyarShariq-Fraunhofer da4b87b
fix: RepositoryUrlHelper - add tests with context path in url
ShehriyarShariq-Fraunhofer 3306f65
refactor: reformat RepositoryUrlHelper + Test
ShehriyarShariq-Fraunhofer 2be64c0
fix: resolve merge conflicts with latest updates from main
ShehriyarShariq-Fraunhofer 7b303c4
Empty commit to trigger the CI
MateusMolina b4afd85
Merge branch 'main' into fix-slash-check-registry-integration
ShehriyarShariq-Fraunhofer bcdef6e
fix: refactor utility url functions
ShehriyarShariq-Fraunhofer d30b228
Triggering the CI
MateusMolina 37bc55e
fix: aas repository feature auth url function fix
ShehriyarShariq-Fraunhofer a29ab5a
Merge branch 'fix-slash-check-registry-integration' of https://github…
ShehriyarShariq-Fraunhofer 66b6354
Triggering the CI
MateusMolina 581e641
fix: revert pom + update createRepositoryUrl functionality
ShehriyarShariq-Fraunhofer dedc173
Triggering the CI
MateusMolina 3ccbec3
fix: add license headers
ShehriyarShariq-Fraunhofer 9c118a4
fix: update test for external url
ShehriyarShariq-Fraunhofer 27bdb45
stash
ShehriyarShariq-Fraunhofer ec7e126
Merge branch 'main' into fix-slash-check-registry-integration
ShehriyarShariq-Fraunhofer c7f3d55
feat: AasRepositoryRegistryLinkDescriptorGenerationTest
ShehriyarShariq-Fraunhofer 5bd2f77
stash
ShehriyarShariq-Fraunhofer 09f00d0
Merge branch 'main' into fix-slash-check-registry-integration
ShehriyarShariq-Fraunhofer 493f177
stash
ShehriyarShariq-Fraunhofer d0ba025
stash
ShehriyarShariq-Fraunhofer 2b5163f
stash
ShehriyarShariq-Fraunhofer 0de2d33
fix: working registry url slash test
ShehriyarShariq-Fraunhofer b1babf6
feat: working test
ShehriyarShariq-Fraunhofer ec123aa
fix: merge from main
ShehriyarShariq-Fraunhofer ae3c928
feat: add Submodel Repo Registry Test
ShehriyarShariq-Fraunhofer d15ef4d
fix: merge with main
ShehriyarShariq-Fraunhofer f03d036
Merge branch 'fix-slash-check-registry-integration' of https://github…
ShehriyarShariq-Fraunhofer a9f4ad2
fix: revert pom.xml
ShehriyarShariq-Fraunhofer ed11d33
style: code clean-up
MateusMolina 4913629
test: refactor *RepositoryRegistryLink tests to be parameterized
MateusMolina 1119feb
style: minor fixes
MateusMolina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
...itory/feature/registry/integration/AasRepositoryRegistryLinkDescriptorGenerationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/******************************************************************************* | ||
* 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.aasrepository.feature.registry.integration; | ||
|
||
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; | ||
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAssetAdministrationShell; | ||
import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi; | ||
import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor; | ||
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.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.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"; | ||
|
||
private static final String BASE_URL = "http://localhost:8081"; | ||
|
||
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); | ||
} | ||
|
||
@Parameterized.Parameter(0) | ||
public String externalUrl; | ||
|
||
@Parameterized.Parameter(1) | ||
public String expectedUrl; | ||
|
||
@Parameterized.Parameters | ||
public static Collection<Object[]> 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 testExternalUrl() { | ||
Mockito.when(mockedRegistryLink.getAasRepositoryBaseURLs()).thenReturn(List.of(externalUrl)); | ||
|
||
AssetAdministrationShellDescriptor descriptor = createAndRetrieveDescriptor(createDummyAas()); | ||
String actualUrl = descriptor.getEndpoints().get(0).getProtocolInformation().getHref(); | ||
|
||
assertEquals(expectedUrl, actualUrl); | ||
} | ||
|
||
private AssetAdministrationShellDescriptor createAndRetrieveDescriptor(AssetAdministrationShell shell) { | ||
registryIntegrationAasRepository.createAas(shell); | ||
|
||
AasDescriptorFactory descriptorFactory = new AasDescriptorFactory(shell, mockedRegistryLink.getAasRepositoryBaseURLs(), mockedAttributeMapper); | ||
return descriptorFactory.create(); | ||
} | ||
|
||
private AssetAdministrationShell createDummyAas() { | ||
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...mmon/basyx.core/src/main/java/org/eclipse/digitaltwin/basyx/core/RepositoryUrlHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/******************************************************************************* | ||
* 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; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
public final class RepositoryUrlHelper { | ||
|
||
private RepositoryUrlHelper() { | ||
} | ||
|
||
public static String createRepositoryUrl(String baseUrl, String additionalPath) { | ||
try { | ||
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 = new URI(baseUri.getScheme(), null, baseUri.getHost(), baseUri.getPort(), fullPath.toString(), null, null); | ||
|
||
return finalUri.toURL().toString(); | ||
} catch (URISyntaxException | MalformedURLException e) { | ||
throw new RuntimeException("The Base URL or additional path is malformed.\n" + e.getMessage(), e); | ||
} | ||
} | ||
|
||
} |
84 changes: 84 additions & 0 deletions
84
.../basyx.core/src/test/java/org/eclipse/digitaltwin/basyx/core/TestRepositoryUrlHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/******************************************************************************* | ||
* 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add license header |
||
|
||
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add license header