From 56f8ebd71d7a090e05680f99c0e932fa06675ea0 Mon Sep 17 00:00:00 2001 From: "Krzysztof Massalski (Extern)" Date: Mon, 25 Mar 2024 10:46:41 +0100 Subject: [PATCH] feat(impl):[#359] support new encoded endpoint --- CHANGELOG.md | 5 ++-- .../irs/IrsWireMockIntegrationTest.java | 6 +++-- .../eclipse/tractusx/irs/WiremockSupport.java | 27 +++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6512090241..3fd8c5411e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 _**For better traceability add the corresponding GitHub issue number in each changelog entry, please.**_ ## [Unreleased] +### Changed +- IRS now supports Asset Administration Shell v3.1 - adjusted lookup shells endpoint changes (assetIds query param is encoded) ## [4.8.0] - 2024-03-18 ### Changed - Improved maintainability in EdcSubmodelClientImpl by reduced method visibility and better naming (in context of #448). -- EdcPolicyDefinitionService, EdcContractDefinitionService and EdcAssetService return throw AlreadyExist exceptions when Conflict is returned from - EDC +- EdcPolicyDefinitionService, EdcContractDefinitionService and EdcAssetService return throw AlreadyExist exceptions when Conflict is returned from EDC - Added AssetAdministrationShellDescriptor specificAssetIds support for externalSubjectId required for data provisioning - Registering a job - aspects array is now accepting full urn of aspect model instead of name only, eg. 'urn:bamm:io.catenax.single_level_bom_as_built:2.0.0#SingleLevelBomAsBuilt' instead 'SingleLevelBomAsBuilt'. #439 - Changed the version of irs-registry-client from 1.6.0-SNAPSHOT to 1.6.0 diff --git a/irs-api/src/test/java/org/eclipse/tractusx/irs/IrsWireMockIntegrationTest.java b/irs-api/src/test/java/org/eclipse/tractusx/irs/IrsWireMockIntegrationTest.java index 185d74a8b4..4ff1a14453 100644 --- a/irs-api/src/test/java/org/eclipse/tractusx/irs/IrsWireMockIntegrationTest.java +++ b/irs-api/src/test/java/org/eclipse/tractusx/irs/IrsWireMockIntegrationTest.java @@ -20,12 +20,14 @@ package org.eclipse.tractusx.irs; import static com.github.tomakehurst.wiremock.client.WireMock.containing; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor; import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.verify; import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.tractusx.irs.WiremockSupport.createEndpointDataReference; +import static org.eclipse.tractusx.irs.WiremockSupport.encodedAssetIds; import static org.eclipse.tractusx.irs.WiremockSupport.randomUUID; import static org.eclipse.tractusx.irs.testing.wiremock.DiscoveryServiceWiremockSupport.DISCOVERY_FINDER_PATH; import static org.eclipse.tractusx.irs.testing.wiremock.DiscoveryServiceWiremockSupport.DISCOVERY_FINDER_URL; @@ -158,7 +160,7 @@ void shouldStartApplicationAndCollectSemanticModels() throws SchemaNotFoundExcep void shouldStopJobAfterDepthIsReached() { // Arrange final String globalAssetIdLevel1 = "globalAssetId"; - final String globalAssetIdLevel2 = "urn:uuid:6d505432-8b31-4966-9514-4b753372683f"; + final String globalAssetIdLevel2 = "urn:uuid:7e4541ea-bb0f-464c-8cb3-021abccbfaf5"; WiremockSupport.successfulSemanticModelRequest(); WiremockSupport.successfulSemanticHubRequests(); @@ -297,7 +299,7 @@ private void successfulRegistryAndDataRequest(final String globalAssetId, final final String registryEdcAssetId = "registry-asset"; successfulNegotiation(registryEdcAssetId); stubFor(getLookupShells200(PUBLIC_LOOKUP_SHELLS_PATH, List.of(shellId)).withQueryParam("assetIds", - containing(globalAssetId))); + equalTo(encodedAssetIds(globalAssetId)))); stubFor(getShellDescriptor200(PUBLIC_SHELL_DESCRIPTORS_PATH + WiremockSupport.encodedId(shellId), bpn, submodelDescriptors, globalAssetId, shellId, idShort)); successfulNegotiation(edcAssetId); diff --git a/irs-api/src/test/java/org/eclipse/tractusx/irs/WiremockSupport.java b/irs-api/src/test/java/org/eclipse/tractusx/irs/WiremockSupport.java index 5146e44de5..cd65821189 100644 --- a/irs-api/src/test/java/org/eclipse/tractusx/irs/WiremockSupport.java +++ b/irs-api/src/test/java/org/eclipse/tractusx/irs/WiremockSupport.java @@ -34,15 +34,21 @@ import static org.eclipse.tractusx.irs.util.TestMother.batchAspectName; import static org.eclipse.tractusx.irs.util.TestMother.singleLevelBomAsBuiltAspectName; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.List; import java.util.Map; import java.util.UUID; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference; import org.eclipse.tractusx.irs.component.PartChainIdentificationKey; import org.eclipse.tractusx.irs.component.RegisterJob; +import org.eclipse.tractusx.irs.component.assetadministrationshell.IdentifierKeyValuePair; import org.eclipse.tractusx.irs.component.enums.Direction; import org.eclipse.tractusx.irs.data.StringMapper; import org.eclipse.tractusx.irs.edc.client.configuration.JsonLdConfiguration; @@ -97,6 +103,27 @@ static String encodedId(final String shellId) { return encodeBase64String(shellId.getBytes(StandardCharsets.UTF_8)); } + static String encodedAssetIds(final String assetIds) { + final IdentifierKeyValuePair globalAssetId = IdentifierKeyValuePair.builder() + .name("globalAssetId") + .value(assetIds) + .build(); + return Base64.getEncoder().encodeToString(serialize(globalAssetId)); + } + + private static byte[] serialize(final IdentifierKeyValuePair assetIds) { + final ByteArrayOutputStream stream = new ByteArrayOutputStream(); + try { + final ObjectMapper mapper = new ObjectMapper(); + mapper.enable(SerializationFeature.INDENT_OUTPUT); + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + mapper.writeValue(stream, assetIds); + return stream.toByteArray(); + } catch (final IOException e) { + return new byte[0]; + } + } + static void verifyDiscoveryCalls(final int times) { verify(times, postRequestedFor(urlPathEqualTo(DiscoveryServiceWiremockSupport.DISCOVERY_FINDER_PATH))); verify(times, postRequestedFor(urlPathEqualTo(DiscoveryServiceWiremockSupport.EDC_DISCOVERY_PATH)));