diff --git a/CHANGELOG.md b/CHANGELOG.md index bb92758c1d..69d68ac03d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). _**For better traceability add the corresponding GitHub issue number in each changelog entry, please.**_ ## [UNRELEASED - DD.MM.YYYY] +### Changed +- #778 return empty PageResult when no contract agreement Ids are found instead of http 404 in /contacts API + ## [11.0.0 - 08.05.2024] ### Added - #844 Validation for BPN to Notification API (Create / Edit), Fixed pagination diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImpl.java index 22b9ba0102..bcec335d6e 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImpl.java @@ -70,7 +70,8 @@ public PageResult getContractsByPageable(Pageable pageable, SearchCrit Page contractAgreementInfoViews = contractAgreementInfoViewRepository.findAll(specification, pageable); if (contractAgreementInfoViews.getContent().isEmpty()) { - throw new ContractException("Cannot find contract agreement Ids for asset ids in searchCriteria: " + searchCriteria.getSearchCriteriaFilterList()); + log.warn("Cannot find contract agreement Ids for asset ids in searchCriteria: " + searchCriteria.getSearchCriteriaFilterList()); + return new PageResult<>(List.of(), 0, 0, 0, 0L); } return new PageResult<>(fetchEdcContractAgreements(contractAgreementInfoViews), diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractControllerIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractControllerIT.java index c43af62c09..5b6d427303 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractControllerIT.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractControllerIT.java @@ -142,14 +142,14 @@ void shouldReturnOnlyOneContract() throws JoseException { } @Test - void shouldReturn404IfAssetIdIsUnknown() throws JoseException { + void shouldReturnEmptyIfAssetIdIsUnknown() throws JoseException { //GIVEN edcSupport.edcWillReturnOnlyOneContractAgreement(); edcSupport.edcWillReturnContractAgreementNegotiation(); assetsSupport.defaultAssetsStored(); //WHEN//THEN - given() + PageResult contractResponsePageResult = given() .header(oAuth2Support.jwtAuthorization(ADMIN)) .contentType(ContentType.JSON) .log().all() @@ -158,7 +158,11 @@ void shouldReturn404IfAssetIdIsUnknown() throws JoseException { .post("/api/contracts") .then() .log().all() - .statusCode(404); + .statusCode(200) + .extract().body().as(new TypeRef<>() { + }); + //THEN + assertThat(contractResponsePageResult.content()).isEmpty(); } }