From 8d8f36ae46ba063a78c912862cdbc31c22477bbe Mon Sep 17 00:00:00 2001 From: Jaro Hartmann Date: Tue, 19 Mar 2024 16:56:04 +0100 Subject: [PATCH 1/8] chore(test): Disable flakey test --- .../DecentralDigitalTwinRegistryServiceWiremockTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryServiceWiremockTest.java b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryServiceWiremockTest.java index e0f085bab9..3086e13764 100644 --- a/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryServiceWiremockTest.java +++ b/irs-registry-client/src/test/java/org/eclipse/tractusx/irs/registryclient/decentral/DecentralDigitalTwinRegistryServiceWiremockTest.java @@ -76,6 +76,7 @@ import org.eclipse.tractusx.irs.registryclient.exceptions.RegistryServiceException; import org.eclipse.tractusx.irs.registryclient.exceptions.ShellNotFoundException; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtensionContext; @@ -303,6 +304,7 @@ public Stream provideArguments(final ExtensionContext exten } @Test + @Disabled("See GH Issue https://github.com/eclipse-tractusx/item-relationship-service/issues/431") void lookupShellIdentifiers_multipleEDCs_multipleDTRs() throws RegistryServiceException, EdcRetrieverException { // Arrange givenThat(postDiscoveryFinder200()); From 3d957b98c978dd91e7bf8f2738c0ba843ac756bc Mon Sep 17 00:00:00 2001 From: "Krzysztof Massalski (Extern)" Date: Wed, 20 Mar 2024 12:46:00 +0100 Subject: [PATCH 2/8] feat(impl):[#341] fix property name, fix readme description, move default to config --- irs-api/src/main/resources/application.yml | 2 +- .../eclipse/tractusx/irs/edc/client/EdcCallbackController.java | 2 +- irs-registry-client/README.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/irs-api/src/main/resources/application.yml b/irs-api/src/main/resources/application.yml index ca68120f0d..40721b784b 100644 --- a/irs-api/src/main/resources/application.yml +++ b/irs-api/src/main/resources/application.yml @@ -129,7 +129,7 @@ resilience4j: baseConfig: default irs-edc-client: - callback-url: ${EDC_TRANSFER_CALLBACK_URL:} # The URL where the EDR token callback will be sent to. + callback-url: ${EDC_TRANSFER_CALLBACK_URL:/internal/endpoint-data-reference} # The URL where the EDR token callback will be sent to. asyncTimeout: PT10M # Timout for future.get requests as ISO 8601 Duration controlplane: request-ttl: ${EDC_CONTROLPLANE_REQUEST_TTL:PT10M} # How long to wait for an async EDC negotiation request to finish, ISO 8601 Duration diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcCallbackController.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcCallbackController.java index ad9d64a8f3..1a1cb65837 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcCallbackController.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcCallbackController.java @@ -40,7 +40,7 @@ */ @Slf4j @RestController("irsEdcClientEdcCallbackController") -@RequestMapping("${irs-edc-client.callback.mapping:internal/endpoint-data-reference}") +@RequestMapping("/${irs-edc-client.callback-url}") @Hidden @RequiredArgsConstructor public class EdcCallbackController { diff --git a/irs-registry-client/README.md b/irs-registry-client/README.md index 449f64e032..d56a31cce7 100644 --- a/irs-registry-client/README.md +++ b/irs-registry-client/README.md @@ -38,7 +38,7 @@ digitalTwinRegistryClient: lookupShellsTemplate: /lookup/shells?assetIds={assetIds} # The path to lookup shells from the DTR. Required if type is "decentral", must contain the placeholder {assetIds} irs-edc-client: - callback-url: "" # The URL where the EDR token callback will be sent to. This defaults to {BASE_URL}/internal/endpoint-data-reference. If you want to use a different mapping, you can override it with irs-edc-client.callback.mapping. + callback-url: "" # The URL where the EDR token callback will be sent to. This defaults to {BASE_URL}/internal/endpoint-data-reference. asyncTimeout: PT10M # Timout for future.get requests as ISO 8601 Duration controlplane: request-ttl: PT10M # How long to wait for an async EDC negotiation request to finish, ISO 8601 Duration From 114fccfe0f0703e6c20204b4b316b8f6f387751b Mon Sep 17 00:00:00 2001 From: "Krzysztof Massalski (Extern)" Date: Wed, 20 Mar 2024 12:47:44 +0100 Subject: [PATCH 3/8] feat(impl):[#341] fix property name, fix readme description, move default to config --- .../eclipse/tractusx/irs/edc/client/EdcCallbackController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcCallbackController.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcCallbackController.java index 1a1cb65837..c1d70fe0b7 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcCallbackController.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcCallbackController.java @@ -40,7 +40,7 @@ */ @Slf4j @RestController("irsEdcClientEdcCallbackController") -@RequestMapping("/${irs-edc-client.callback-url}") +@RequestMapping("${irs-edc-client.callback-url}") @Hidden @RequiredArgsConstructor public class EdcCallbackController { From 77261d58ce2987efcdc9a3ea0a14bf60fee68c14 Mon Sep 17 00:00:00 2001 From: "Krzysztof Massalski (Extern)" Date: Wed, 20 Mar 2024 13:02:38 +0100 Subject: [PATCH 4/8] feat(impl):[#341] fix property name, fix readme description, move default to config --- charts/irs-helm/templates/configmap-spring-app-config.yaml | 2 ++ charts/irs-helm/values.yaml | 1 + irs-api/src/main/resources/application.yml | 4 +++- .../tractusx/irs/edc/client/EdcCallbackController.java | 2 +- irs-registry-client/README.md | 2 +- 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/charts/irs-helm/templates/configmap-spring-app-config.yaml b/charts/irs-helm/templates/configmap-spring-app-config.yaml index 2e5121cdc2..54180b10d6 100644 --- a/charts/irs-helm/templates/configmap-spring-app-config.yaml +++ b/charts/irs-helm/templates/configmap-spring-app-config.yaml @@ -99,6 +99,8 @@ data: bpnEndpoint: {{ tpl (.Values.bpdm.bpnEndpoint | default "") . | quote }} irs-edc-client: + callback: + mapping: {{ .Values.edc.callbackMapping | default "/internal/endpoint-data-reference" | quote }} callback-url: {{ tpl (.Values.edc.callbackurl | default (printf "http://%s%s" .Release.Name "-irs-helm:8181/internal/endpoint-data-reference")) . | quote }} asyncTimeout: {{ tpl .Values.edc.asyncTimeout . | default "PT10M" | quote }} controlplane: diff --git a/charts/irs-helm/values.yaml b/charts/irs-helm/values.yaml index 8d7c50c137..e48360c14e 100644 --- a/charts/irs-helm/values.yaml +++ b/charts/irs-helm/values.yaml @@ -188,6 +188,7 @@ edc: apikey: header: "X-Api-Key" # Name of the EDC api key header field secret: "" # + callbackMapping: callbackurl: asyncTimeout: PT10M # Timout for future.get requests as ISO 8601 Duration submodel: diff --git a/irs-api/src/main/resources/application.yml b/irs-api/src/main/resources/application.yml index 40721b784b..448c6acbe4 100644 --- a/irs-api/src/main/resources/application.yml +++ b/irs-api/src/main/resources/application.yml @@ -129,7 +129,9 @@ resilience4j: baseConfig: default irs-edc-client: - callback-url: ${EDC_TRANSFER_CALLBACK_URL:/internal/endpoint-data-reference} # The URL where the EDR token callback will be sent to. + callback: + mapping: ${EDC_TRANSFER_CALLBACK_MAPPING:/internal/endpoint-data-reference} # The callback endpoint mapping + callback-url: ${EDC_TRANSFER_CALLBACK_URL:} # The URL where the EDR token callback will be sent to. asyncTimeout: PT10M # Timout for future.get requests as ISO 8601 Duration controlplane: request-ttl: ${EDC_CONTROLPLANE_REQUEST_TTL:PT10M} # How long to wait for an async EDC negotiation request to finish, ISO 8601 Duration diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcCallbackController.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcCallbackController.java index c1d70fe0b7..f6a94a890f 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcCallbackController.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcCallbackController.java @@ -40,7 +40,7 @@ */ @Slf4j @RestController("irsEdcClientEdcCallbackController") -@RequestMapping("${irs-edc-client.callback-url}") +@RequestMapping("${irs-edc-client.callback.mapping}") @Hidden @RequiredArgsConstructor public class EdcCallbackController { diff --git a/irs-registry-client/README.md b/irs-registry-client/README.md index d56a31cce7..449f64e032 100644 --- a/irs-registry-client/README.md +++ b/irs-registry-client/README.md @@ -38,7 +38,7 @@ digitalTwinRegistryClient: lookupShellsTemplate: /lookup/shells?assetIds={assetIds} # The path to lookup shells from the DTR. Required if type is "decentral", must contain the placeholder {assetIds} irs-edc-client: - callback-url: "" # The URL where the EDR token callback will be sent to. This defaults to {BASE_URL}/internal/endpoint-data-reference. + callback-url: "" # The URL where the EDR token callback will be sent to. This defaults to {BASE_URL}/internal/endpoint-data-reference. If you want to use a different mapping, you can override it with irs-edc-client.callback.mapping. asyncTimeout: PT10M # Timout for future.get requests as ISO 8601 Duration controlplane: request-ttl: PT10M # How long to wait for an async EDC negotiation request to finish, ISO 8601 Duration From be29f351aa7eab4a6549573b507ba6bf404b8b1c Mon Sep 17 00:00:00 2001 From: "Krzysztof Massalski (Extern)" Date: Wed, 20 Mar 2024 16:09:31 +0100 Subject: [PATCH 5/8] feat(impl):[#341] update docs --- charts/irs-helm/values.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/irs-helm/values.yaml b/charts/irs-helm/values.yaml index e48360c14e..653b72b54f 100644 --- a/charts/irs-helm/values.yaml +++ b/charts/irs-helm/values.yaml @@ -188,8 +188,8 @@ edc: apikey: header: "X-Api-Key" # Name of the EDC api key header field secret: "" # - callbackMapping: - callbackurl: + callbackMapping: # The callback endpoint path mapping - used to expose callback endpoint + callbackurl: # The URL where the EDR token callback will be sent to. asyncTimeout: PT10M # Timout for future.get requests as ISO 8601 Duration submodel: request: From 4bfe77cc401c792713c5f903c2f53e061742ec63 Mon Sep 17 00:00:00 2001 From: ds-ext-kmassalski <100765908+ds-ext-kmassalski@users.noreply.github.com> Date: Thu, 21 Mar 2024 09:26:57 +0100 Subject: [PATCH 6/8] Update irs-api/src/main/resources/application.yml Co-authored-by: Matthias Fischer --- irs-api/src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/irs-api/src/main/resources/application.yml b/irs-api/src/main/resources/application.yml index 448c6acbe4..c65ac06a47 100644 --- a/irs-api/src/main/resources/application.yml +++ b/irs-api/src/main/resources/application.yml @@ -130,7 +130,7 @@ resilience4j: irs-edc-client: callback: - mapping: ${EDC_TRANSFER_CALLBACK_MAPPING:/internal/endpoint-data-reference} # The callback endpoint mapping + mapping: /internal/endpoint-data-reference # The callback endpoint mapping callback-url: ${EDC_TRANSFER_CALLBACK_URL:} # The URL where the EDR token callback will be sent to. asyncTimeout: PT10M # Timout for future.get requests as ISO 8601 Duration controlplane: From 0d0a9f513a60fffc98d21394a38dab882f0ab9e8 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Fri, 22 Mar 2024 08:27:36 +0100 Subject: [PATCH 7/8] feat(decentral-client-library):596-tracex add functionallity which checks if an policy already exists. --- CHANGELOG.md | 2 + .../GetEdcPolicyDefinitionException.java | 34 ++++++++++ .../service/EdcPolicyDefinitionService.java | 22 +++++++ .../EdcPolicyDefinitionServiceTest.java | 62 +++++++++++++------ 4 files changed, 101 insertions(+), 19 deletions(-) create mode 100644 irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/GetEdcPolicyDefinitionException.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a6eb265ac..4909d654fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ 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] +### Added +- Extended EdcPolicyDefinitionService to check if a policy in the edc exists ## [4.8.0] - 2024-03-18 ### Changed diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/GetEdcPolicyDefinitionException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/GetEdcPolicyDefinitionException.java new file mode 100644 index 0000000000..9f93e3a0de --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/model/exception/GetEdcPolicyDefinitionException.java @@ -0,0 +1,34 @@ +/******************************************************************************** + * Copyright (c) 2021,2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +package org.eclipse.tractusx.irs.edc.client.policy.model.exception; + +/** + * GetEdcPolicyDefinitionException used policy creation failed case + */ + +public class GetEdcPolicyDefinitionException extends Exception { + + public GetEdcPolicyDefinitionException(final String message) { + super(message); + } + + public GetEdcPolicyDefinitionException(final Throwable cause) { + super(cause); + } +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java index 1fbe9c9080..6eb6f35496 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java @@ -37,6 +37,7 @@ import org.eclipse.tractusx.irs.edc.client.policy.model.exception.CreateEdcPolicyDefinitionException; import org.eclipse.tractusx.irs.edc.client.policy.model.exception.DeleteEdcPolicyDefinitionException; import org.eclipse.tractusx.irs.edc.client.policy.model.exception.EdcPolicyDefinitionAlreadyExists; +import org.eclipse.tractusx.irs.edc.client.policy.model.exception.GetEdcPolicyDefinitionException; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; @@ -99,6 +100,27 @@ public String createAccessPolicy(final EdcCreatePolicyDefinitionRequest policyRe throw new CreateEdcPolicyDefinitionException("Failed to create EDC policy definition for asset"); } + public boolean policyDefinitionExists(final String policyName) throws GetEdcPolicyDefinitionException { + + try { + final ResponseEntity getPolicyDefinitionRequest = restTemplate.getForEntity( + config.getControlplane().getEndpoint().getPolicyDefinition() + "/" + policyName, String.class); + + final HttpStatusCode responseCode = getPolicyDefinitionRequest.getStatusCode(); + + if (responseCode.value() == HttpStatus.OK.value()) { + return true; + } + } catch (HttpClientErrorException e) { + if (e.getStatusCode().value() == HttpStatus.NOT_FOUND.value()) { + log.info(String.format("Policy with id %s not found within the edc", policyName)); + } else { + throw new GetEdcPolicyDefinitionException(e); + } + } + return false; + } + public EdcCreatePolicyDefinitionRequest createPolicyDefinition(final String policyName, final String accessPolicyId) { final EdcPolicyPermissionConstraintExpression constraint = EdcPolicyPermissionConstraintExpression.builder() diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java index 8815c33550..5d36e0b1f1 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java @@ -22,6 +22,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -34,6 +36,7 @@ import org.eclipse.tractusx.irs.edc.client.policy.model.exception.CreateEdcPolicyDefinitionException; import org.eclipse.tractusx.irs.edc.client.policy.model.exception.DeleteEdcPolicyDefinitionException; import org.eclipse.tractusx.irs.edc.client.policy.model.exception.EdcPolicyDefinitionAlreadyExists; +import org.eclipse.tractusx.irs.edc.client.policy.model.exception.GetEdcPolicyDefinitionException; import org.json.JSONException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -127,6 +130,42 @@ void givenPolicy_WhenCreateAccessPolicy_ThenCreateIt() throws CreateEdcPolicyDef assertThat(result).isNotBlank(); } + @Test + void givenPolicyName_WhenGetPolicy_ThenExists() throws GetEdcPolicyDefinitionException { + // given + when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig); + when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig); + String policyName = "policyName"; + when(endpointConfig.getPolicyDefinition()).thenReturn("/management/v2/policydefinitions" + "/" + policyName); + + ResponseEntity responseEntity = ResponseEntity.ok("Mocked response"); + when(restTemplate.getForEntity(anyString(), eq(String.class))).thenReturn(responseEntity); + + // when + boolean result = service.policyDefinitionExists(policyName); + + // then + assertThat(result).isTrue(); + } + + @Test + void givenPolicyName_WhenGetPolicy_ThenNotExists() throws GetEdcPolicyDefinitionException { + // given + when(edcConfiguration.getControlplane()).thenReturn(controlplaneConfig); + when(controlplaneConfig.getEndpoint()).thenReturn(endpointConfig); + String policyName = "policyName"; + when(endpointConfig.getPolicyDefinition()).thenReturn("/management/v2/policydefinitions" + "/" + policyName); + + ResponseEntity responseEntity = ResponseEntity.badRequest().build(); + when(restTemplate.getForEntity(anyString(), eq(String.class))).thenReturn(responseEntity); + + // when + boolean result = service.policyDefinitionExists(policyName); + + // then + assertThat(result).isFalse(); + } + @Test void givenCreatePolicy_whenConflict_thenReturnExstingPolicyId() throws CreateEdcPolicyDefinitionException { // given @@ -136,15 +175,7 @@ void givenCreatePolicy_whenConflict_thenReturnExstingPolicyId() throws CreateEdc final String policyName = "policyName"; when(restTemplate.postForEntity(any(String.class), any(EdcCreatePolicyDefinitionRequest.class), any())).thenThrow( - HttpClientErrorException.create( - "Surprise", - HttpStatus.CONFLICT, - "", - null, - null, - null - ) - ); + HttpClientErrorException.create("Surprise", HttpStatus.CONFLICT, "", null, null, null)); // when/then assertThrows(EdcPolicyDefinitionAlreadyExists.class, () -> service.createAccessPolicy(policyName)); @@ -171,14 +202,8 @@ void givenCreatePolicy_whenRestClientException_thenThrowException() { when(endpointConfig.getPolicyDefinition()).thenReturn("/management/v2/policydefinitions"); String policyName = "policyName"; when(restTemplate.postForEntity(any(String.class), any(EdcCreatePolicyDefinitionRequest.class), - any())).thenThrow(HttpClientErrorException.create( - "Surprise", - HttpStatus.EARLY_HINTS, - "", - null, - null, - null - )); + any())).thenThrow( + HttpClientErrorException.create("Surprise", HttpStatus.EARLY_HINTS, "", null, null, null)); assertThrows(CreateEdcPolicyDefinitionException.class, () -> service.createAccessPolicy(policyName)); } @@ -193,8 +218,7 @@ void givenDeletePolicy_whenRestClientException_thenThrowException() { doThrow(new RestClientException("Surprise")).when(restTemplate).delete(any(String.class)); // when/then - assertThrows(DeleteEdcPolicyDefinitionException.class, - () -> service.deleteAccessPolicy(policyName)); + assertThrows(DeleteEdcPolicyDefinitionException.class, () -> service.deleteAccessPolicy(policyName)); } @Test From 9a8710678ae7b23dfc2adc71463c631bfb4f62c6 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Fri, 22 Mar 2024 10:37:59 +0100 Subject: [PATCH 8/8] feat(decentral-client-library):596-tracex add functionallity which checks if an policy already exists. --- .../edc/client/policy/service/EdcPolicyDefinitionService.java | 1 + .../client/policy/service/EdcPolicyDefinitionServiceTest.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java index 6eb6f35496..80f88f547f 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionService.java @@ -114,6 +114,7 @@ public boolean policyDefinitionExists(final String policyName) throws GetEdcPoli } catch (HttpClientErrorException e) { if (e.getStatusCode().value() == HttpStatus.NOT_FOUND.value()) { log.info(String.format("Policy with id %s not found within the edc", policyName)); + return false; } else { throw new GetEdcPolicyDefinitionException(e); } diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java index 5d36e0b1f1..66d59878c9 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/service/EdcPolicyDefinitionServiceTest.java @@ -156,7 +156,7 @@ void givenPolicyName_WhenGetPolicy_ThenNotExists() throws GetEdcPolicyDefinition String policyName = "policyName"; when(endpointConfig.getPolicyDefinition()).thenReturn("/management/v2/policydefinitions" + "/" + policyName); - ResponseEntity responseEntity = ResponseEntity.badRequest().build(); + ResponseEntity responseEntity = ResponseEntity.notFound().build(); when(restTemplate.getForEntity(anyString(), eq(String.class))).thenReturn(responseEntity); // when