From be349ac6d96e635c4ae3311b504da24d4dbe2ea9 Mon Sep 17 00:00:00 2001 From: Matthias Fischer Date: Wed, 10 Jul 2024 18:58:08 +0200 Subject: [PATCH] fix(policy-validation):[#649] trial to fix - but results in failures in PolicyCheckerServiceTest --- .../policy/ConstraintCheckerService.java | 2 +- .../policy/ConstraintCheckerServiceTest.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/ConstraintCheckerService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/ConstraintCheckerService.java index 6178de2b8b..bd9f4a2fc4 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/ConstraintCheckerService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/policy/ConstraintCheckerService.java @@ -54,7 +54,7 @@ public boolean hasAllConstraint(final Policy acceptedPolicy, final List acceptedConstraintsList) { return acceptedConstraintsList.stream() - .anyMatch(acceptedConstraints -> isSameAs(constraint, acceptedConstraints)); + .allMatch(acceptedConstraints -> isSameAs(constraint, acceptedConstraints)); } private boolean isSameAs(final Constraint constraint, final Constraints acceptedConstraints) { diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/ConstraintCheckerServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/ConstraintCheckerServiceTest.java index 1cf3ef0111..42527f837c 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/ConstraintCheckerServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/policy/ConstraintCheckerServiceTest.java @@ -113,6 +113,25 @@ void shouldNotAcceptAndConstraintWithOneLessElement() { assertThat(result).isFalse(); } + @Test + void shouldNotAcceptSubsetOfAndConstraints() { + + final AndConstraint andConstraint = createAndConstraint( + List.of(createAtomicConstraint(TestConstants.FRAMEWORK_AGREEMENT_TRACEABILITY, + TestConstants.STATUS_ACTIVE), + createAtomicConstraint(TestConstants.MEMBERSHIP, TestConstants.STATUS_ACTIVE), + createAtomicConstraint(TestConstants.PURPOSE, TestConstants.ID_3_1_TRACE))); + + final Policy acceptedPolicy = createPolicyWithAndConstraint( + List.of(new Operand(TestConstants.FRAMEWORK_AGREEMENT_TRACEABILITY, TestConstants.STATUS_ACTIVE), + // new Operand(TestConstants.MEMBERSHIP, TestConstants.STATUS_ACTIVE), + new Operand(TestConstants.PURPOSE, TestConstants.ID_3_1_TRACE))); + + boolean result = cut.hasAllConstraint(acceptedPolicy, List.of(andConstraint)); + + assertThat(result).isFalse(); + } + @Test void shouldRejectAndConstraintWhenOneIsDifferent() { final AndConstraint andConstraint = createAndConstraint(