Skip to content

Commit

Permalink
fix(policy-check):[eclipse-tractusx#649] correct tests to match curre…
Browse files Browse the repository at this point in the history
…nt requirements
  • Loading branch information
dsmf committed Jul 12, 2024
1 parent 66718dd commit 87c4805
Showing 1 changed file with 27 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,15 @@ void shouldRejectWhenPolicyStoreIsEmpty() {
@Test
void shouldRejectAndConstraintsWhenOnlyOneMatch() {
// given

final Constraint constraint1 = new Constraint(FRAMEWORK_AGREEMENT_TRACEABILITY,
new Operator(OperatorType.EQ), STATUS_ACTIVE);
final Constraint constraint2 = new Constraint(FRAMEWORK_AGREEMENT_DISMANTLER, new Operator(OperatorType.EQ),
STATUS_ACTIVE);

final var policyList = List.of(
new AcceptedPolicy(policy(FRAMEWORK_AGREEMENT_TRACEABILITY), OffsetDateTime.now().plusYears(1)),
new AcceptedPolicy(policy(FRAMEWORK_AGREEMENT_DISMANTLER), OffsetDateTime.now().plusYears(1)));
new AcceptedPolicy(policy("policy1", List.of(constraint1, constraint2), Collections.emptyList()),
OffsetDateTime.now().plusYears(1)));
when(policyStore.getAcceptedPolicies(any())).thenReturn(policyList);

final Policy policy = createAndConstraintPolicy(
Expand All @@ -112,7 +118,7 @@ void shouldRejectAndConstraintsWhenOnlyOneMatch() {
}

@Test
void shouldAcceptAndConstraintsWhenAcceptedPolicyContainsMoreConstraintsSuperSetOfProvidedPolicy() {
void shouldRejectAndConstraintsWhenAcceptedPolicyContainsSuperSetOfProvidedPolicy() {
// given
final Constraint constraint1 = new Constraint(FRAMEWORK_AGREEMENT_TRACEABILITY,
new Operator(OperatorType.EQ), STATUS_ACTIVE);
Expand All @@ -132,7 +138,7 @@ void shouldAcceptAndConstraintsWhenAcceptedPolicyContainsMoreConstraintsSuperSet
final boolean valid = policyCheckerService.isValid(policy, "bpn");

// then
assertThat(valid).isTrue();
assertThat(valid).isFalse();
}

@Test
Expand Down Expand Up @@ -187,31 +193,18 @@ void shouldAcceptConstraintsWithDefaultPolicy() {
@Test
void shouldRejectOrConstraintsWhenNoneMatch() {
// given
final var policyList = List.of(
new AcceptedPolicy(policy(FRAMEWORK_AGREEMENT_TEST), OffsetDateTime.now().plusYears(1)),
new AcceptedPolicy(policy(FRAMEWORK_AGREEMENT_DISMANTLER), OffsetDateTime.now().plusYears(1)));
when(policyStore.getAcceptedPolicies(any())).thenReturn(policyList);

final Policy policy = createAndConstraintPolicy(
List.of(createAtomicConstraint(FRAMEWORK_AGREEMENT_TRACEABILITY, STATUS_ACTIVE),
createAtomicConstraint(MEMBERSHIP, STATUS_ACTIVE)));

// when
final boolean valid = policyCheckerService.isValid(policy, "bpn");

// then
assertThat(valid).isFalse();
}
final Constraint constraint1 = new Constraint(FRAMEWORK_AGREEMENT_TEST, new Operator(OperatorType.EQ),
STATUS_ACTIVE);
final Constraint constraint2 = new Constraint(FRAMEWORK_AGREEMENT_DISMANTLER, new Operator(OperatorType.EQ),
STATUS_ACTIVE);

@Test
void shouldRejectXOneConstraintsWhenNoneMatch() {
// given
final var policyList = List.of(
new AcceptedPolicy(policy(FRAMEWORK_AGREEMENT_TEST), OffsetDateTime.now().plusYears(1)),
new AcceptedPolicy(policy(FRAMEWORK_AGREEMENT_DISMANTLER), OffsetDateTime.now().plusYears(1)));
new AcceptedPolicy(policy("policy1", Collections.emptyList(), List.of(constraint1, constraint2)),
OffsetDateTime.now().plusYears(1)));
when(policyStore.getAcceptedPolicies(any())).thenReturn(policyList);

final Policy policy = createXOneConstraintPolicy(
final Policy policy = createAndConstraintPolicy(
List.of(createAtomicConstraint(FRAMEWORK_AGREEMENT_TRACEABILITY, STATUS_ACTIVE),
createAtomicConstraint(MEMBERSHIP, STATUS_ACTIVE)));

Expand All @@ -223,11 +216,18 @@ void shouldRejectXOneConstraintsWhenNoneMatch() {
}

@Test
void shouldRejectXOneConstraintsWhenMoreThanOneMatch() {
void shouldRejectXOneConstraintsBecauseXOneIsNotSupported() {
// given
final Constraint constraint1 = new Constraint(FRAMEWORK_AGREEMENT_TRACEABILITY,
new Operator(OperatorType.EQ), STATUS_ACTIVE);
final Constraint constraint2 = new Constraint(FRAMEWORK_AGREEMENT_DISMANTLER, new Operator(OperatorType.EQ),
STATUS_ACTIVE);

final var policyList = List.of(
new AcceptedPolicy(policy(FRAMEWORK_AGREEMENT_TRACEABILITY), OffsetDateTime.now().plusYears(1)),
new AcceptedPolicy(policy(MEMBERSHIP), OffsetDateTime.now().plusYears(1)));
new AcceptedPolicy(policy("policy1", Collections.emptyList(), List.of(constraint1, constraint2)),
OffsetDateTime.now().plusYears(1)),
new AcceptedPolicy(policy("policy2", List.of(constraint1, constraint2), Collections.emptyList()),
OffsetDateTime.now().plusYears(1)));
when(policyStore.getAcceptedPolicies(any())).thenReturn(policyList);

final Policy policy = createXOneConstraintPolicy(
Expand All @@ -240,15 +240,7 @@ void shouldRejectXOneConstraintsWhenMoreThanOneMatch() {
// then
assertThat(valid).isFalse();
}
}

private org.eclipse.tractusx.irs.edc.client.policy.Policy policy(final String policyId) {
return org.eclipse.tractusx.irs.edc.client.policy.Policy.builder()
.policyId(policyId)
.createdOn(OffsetDateTime.now())
.validUntil(OffsetDateTime.now().plusYears(1))
.permissions(Collections.emptyList())
.build();
}

private org.eclipse.tractusx.irs.edc.client.policy.Policy policy(final String policyId,
Expand Down

0 comments on commit 87c4805

Please sign in to comment.