Changesets · Branches · Tags · Compare
| Changeset | 1c970cc0d53d0a1634189a4fc69515c3a697d3c802e8f0b1f5b170fd7b8540bf |
|---|---|
| Author | Enrico Risa <enrico.risa@gmail.com> · 2024-09-06 14:42 +02:00 |
| Committer | GitHub <noreply@github.com> · 2024-09-06 14:42 +02:00 |
| Parents | 071f92dfa903 |
3 files changed
modified extensions/common/api/management-api-json-ld-context/src/main/resources/document/management-context-v1.jsonld +59 −1
| @@ -36,6 +36,16 @@ | ||
| 36 | 36 | "SuspendTransfer": "edc:SuspendTransfer", |
| 37 | 37 | "Secret": "edc:Secret", |
| 38 | 38 | "EndpointDataReferenceEntry": "edc:EndpointDataReferenceEntry", |
| 39 | + "PolicyValidationResult": "edc:PolicyValidationResult", | |
| 40 | + "PolicyEvaluationPlanRequest": "edc:PolicyEvaluationPlanRequest", | |
| 41 | + "PolicyEvaluationPlan": "edc:PolicyEvaluationPlan", | |
| 42 | + "PermissionStep": "edc:PermissionStep", | |
| 43 | + "ProhibitionStep": "edc:ProhibitionStep", | |
| 44 | + "DutyStep": "edc:DutyStep", | |
| 45 | + "OrConstraintStep": "edc:OrConstraintStep", | |
| 46 | + "AndConstraintStep": "edc:AndConstraintStep", | |
| 47 | + "XoneConstraintStep": "edc:XoneConstraintStep", | |
| 48 | + "AtomicConstraintStep": "edc:AtomicConstraintStep", | |
| 39 | 49 | "properties": { |
| 40 | 50 | "@id": "edc:properties", |
| 41 | 51 | "@context": { |
| @@ -111,6 +121,54 @@ | ||
| 111 | 121 | "transferProcessId": "edc:transferProcessId", |
| 112 | 122 | "contractNegotiationId": "edc:contractNegotiationId", |
| 113 | 123 | "agreementId": "edc:agreementId", |
| 114 | - "inForceDate": "edc:inForceDate" | |
| 124 | + "inForceDate": "edc:inForceDate", | |
| 125 | + "isValid": "edc:isValid", | |
| 126 | + "errors": { | |
| 127 | + "@id": "edc:errors", | |
| 128 | + "@container": "@set" | |
| 129 | + }, | |
| 130 | + "policyScope": "edc:policyScope", | |
| 131 | + "preValidators": { | |
| 132 | + "@id": "edc:preValidators", | |
| 133 | + "@container": "@set" | |
| 134 | + }, | |
| 135 | + "postValidators": { | |
| 136 | + "@id": "edc:postValidators", | |
| 137 | + "@container": "@set" | |
| 138 | + }, | |
| 139 | + "permissionSteps": { | |
| 140 | + "@id": "edc:permissionSteps", | |
| 141 | + "@container": "@set" | |
| 142 | + }, | |
| 143 | + "prohibitionSteps": { | |
| 144 | + "@id": "edc:prohibitionSteps", | |
| 145 | + "@container": "@set" | |
| 146 | + }, | |
| 147 | + "obligationSteps": { | |
| 148 | + "@id": "edc:obligationSteps", | |
| 149 | + "@container": "@set" | |
| 150 | + }, | |
| 151 | + "constraintSteps": { | |
| 152 | + "@id": "edc:constraintSteps", | |
| 153 | + "@container": "@set" | |
| 154 | + }, | |
| 155 | + "filteringReasons": { | |
| 156 | + "@id": "edc:filteringReasons", | |
| 157 | + "@container": "@set" | |
| 158 | + }, | |
| 159 | + "isFiltered": "edc:isFiltered", | |
| 160 | + "functionName": "edc:functionName", | |
| 161 | + "functionParams": { | |
| 162 | + "@id": "edc:functionParams", | |
| 163 | + "@container": "@set" | |
| 164 | + }, | |
| 165 | + "dutySteps": { | |
| 166 | + "@id": "edc:dutySteps", | |
| 167 | + "@container": "@set" | |
| 168 | + }, | |
| 169 | + "ruleFunctions": { | |
| 170 | + "@id": "edc:ruleFunctions", | |
| 171 | + "@container": "@set" | |
| 172 | + } | |
| 115 | 173 | } |
| 116 | 174 | } |
| No newline at the end of the file |
modified extensions/common/api/management-api-json-ld-context/src/test/java/org/eclipse/edc/connector/api/management/jsonld/serde/SerdeIntegrationTest.java +74 −0
| @@ -17,7 +17,10 @@ | ||
| 17 | 17 | import jakarta.json.Json; |
| 18 | 18 | import jakarta.json.JsonObject; |
| 19 | 19 | import jakarta.json.JsonString; |
| 20 | +import jakarta.json.JsonValue; | |
| 20 | 21 | import org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.model.NegotiationState; |
| 22 | +import org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyEvaluationPlanRequest; | |
| 23 | +import org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyValidationResult; | |
| 21 | 24 | import org.eclipse.edc.connector.controlplane.api.management.transferprocess.model.SuspendTransfer; |
| 22 | 25 | import org.eclipse.edc.connector.controlplane.api.management.transferprocess.model.TerminateTransfer; |
| 23 | 26 | import org.eclipse.edc.connector.controlplane.api.management.transferprocess.model.TransferState; |
| @@ -54,8 +57,11 @@ | ||
| 54 | 57 | import org.junit.jupiter.params.provider.ArgumentsProvider; |
| 55 | 58 | import org.junit.jupiter.params.provider.ArgumentsSource; |
| 56 | 59 | |
| 60 | +import java.util.List; | |
| 57 | 61 | import java.util.Map; |
| 58 | 62 | import java.util.Optional; |
| 63 | +import java.util.function.BiFunction; | |
| 64 | +import java.util.function.Consumer; | |
| 59 | 65 | import java.util.function.Function; |
| 60 | 66 | import java.util.stream.Collectors; |
| 61 | 67 | import java.util.stream.Stream; |
| @@ -69,9 +75,11 @@ | ||
| 69 | 75 | import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.createContractAgreement; |
| 70 | 76 | import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.createContractNegotiation; |
| 71 | 77 | import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.createEdrEntry; |
| 78 | +import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.createPolicyEvaluationPlan; | |
| 72 | 79 | import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.createTransferProcess; |
| 73 | 80 | import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.inForceDatePermission; |
| 74 | 81 | import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.policyDefinitionObject; |
| 82 | +import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.policyEvaluationPlanRequest; | |
| 75 | 83 | import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.querySpecObject; |
| 76 | 84 | import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.secretObject; |
| 77 | 85 | import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.suspendTransferObject; |
| @@ -208,6 +216,62 @@ | ||
| 208 | 216 | |
| 209 | 217 | } |
| 210 | 218 | |
| 219 | + @Test | |
| 220 | + void ser_PolicyValidationResult() { | |
| 221 | + var result = new PolicyValidationResult(false, List.of("error1", "error2")); | |
| 222 | + var compactResult = serialize(result); | |
| 223 | + | |
| 224 | + assertThat(compactResult).isNotNull(); | |
| 225 | + assertThat(compactResult.getString(TYPE)).isEqualTo("PolicyValidationResult"); | |
| 226 | + assertThat(compactResult.getBoolean("isValid")).isEqualTo(false); | |
| 227 | + assertThat(compactResult.getJsonArray("errors")).contains(Json.createValue("error1"), Json.createValue("error2")); | |
| 228 | + | |
| 229 | + } | |
| 230 | + | |
| 231 | + @Test | |
| 232 | + void ser_PolicyEvaluationPlan() { | |
| 233 | + var plan = createPolicyEvaluationPlan(); | |
| 234 | + var compactResult = serialize(plan); | |
| 235 | + | |
| 236 | + assertThat(compactResult).isNotNull(); | |
| 237 | + assertThat(compactResult.getString(TYPE)).isEqualTo("PolicyEvaluationPlan"); | |
| 238 | + assertThat(compactResult.getJsonArray("preValidators")).hasSize(1); | |
| 239 | + assertThat(compactResult.getJsonArray("postValidators")).hasSize(1); | |
| 240 | + | |
| 241 | + | |
| 242 | + BiFunction<String, String, Consumer<JsonValue>> ruleAsser = (ruleType, multiplicityType) -> (ruleValue) -> { | |
| 243 | + var rule = ruleValue.asJsonObject(); | |
| 244 | + assertThat(rule.getString(TYPE)).isEqualTo(ruleType); | |
| 245 | + assertThat(rule.getJsonArray("ruleFunctions")).hasSize(0); | |
| 246 | + assertThat(rule.getJsonArray("constraintSteps")).hasSize(1); | |
| 247 | + | |
| 248 | + var constraint = rule.getJsonArray("constraintSteps").get(0).asJsonObject(); | |
| 249 | + assertThat(constraint.getString(TYPE)).isEqualTo(multiplicityType); | |
| 250 | + assertThat(constraint.getJsonArray("constraintSteps")).hasSize(2) | |
| 251 | + .allSatisfy(value -> { | |
| 252 | + var atomicConstraint = value.asJsonObject(); | |
| 253 | + assertThat(atomicConstraint.getString(TYPE)).isEqualTo("AtomicConstraintStep"); | |
| 254 | + assertThat(atomicConstraint.getJsonArray("filteringReasons")).hasSize(1); | |
| 255 | + assertThat(atomicConstraint.getBoolean("isFiltered")).isTrue(); | |
| 256 | + assertThat(atomicConstraint.getString("functionName")).isEqualTo("AtomicConstraintFunction"); | |
| 257 | + assertThat(atomicConstraint.getJsonArray("functionParams")).hasSize(3); | |
| 258 | + }); | |
| 259 | + }; | |
| 260 | + | |
| 261 | + assertThat(compactResult.getJsonArray("permissionSteps")).hasSize(1) | |
| 262 | + .first() | |
| 263 | + .satisfies(ruleAsser.apply("PermissionStep", "OrConstraintStep")); | |
| 264 | + | |
| 265 | + assertThat(compactResult.getJsonArray("prohibitionSteps")).hasSize(1) | |
| 266 | + .first() | |
| 267 | + .satisfies(ruleAsser.apply("ProhibitionStep", "AndConstraintStep")); | |
| 268 | + | |
| 269 | + assertThat(compactResult.getJsonArray("obligationSteps")).hasSize(1) | |
| 270 | + .first() | |
| 271 | + .satisfies(ruleAsser.apply("DutyStep", "XoneConstraintStep")); | |
| 272 | + | |
| 273 | + } | |
| 274 | + | |
| 211 | 275 | @Test |
| 212 | 276 | void de_ContractRequest() { |
| 213 | 277 | var inputObject = contractRequestObject(); |
| @@ -293,6 +357,16 @@ | ||
| 293 | 357 | |
| 294 | 358 | } |
| 295 | 359 | |
| 360 | + @Test | |
| 361 | + void de_PolicyEvaluationPlanRequest() { | |
| 362 | + var inputObject = policyEvaluationPlanRequest(); | |
| 363 | + var terminateTransfer = deserialize(inputObject, PolicyEvaluationPlanRequest.class); | |
| 364 | + | |
| 365 | + assertThat(terminateTransfer).isNotNull(); | |
| 366 | + assertThat(terminateTransfer.policyScope()).isEqualTo(inputObject.getString("policyScope")); | |
| 367 | + | |
| 368 | + } | |
| 369 | + | |
| 296 | 370 | /** |
| 297 | 371 | * Tests for entities that supports transformation from/to JsonObject |
| 298 | 372 | */ |
modified extensions/common/api/management-api-json-ld-context/src/test/java/org/eclipse/edc/connector/api/management/jsonld/serde/TestFunctions.java +65 −0
| @@ -22,7 +22,21 @@ | ||
| 22 | 22 | import org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractNegotiation; |
| 23 | 23 | import org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcess; |
| 24 | 24 | import org.eclipse.edc.edr.spi.types.EndpointDataReferenceEntry; |
| 25 | +import org.eclipse.edc.policy.engine.spi.AtomicConstraintFunction; | |
| 26 | +import org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan; | |
| 27 | +import org.eclipse.edc.policy.engine.spi.plan.step.AndConstraintStep; | |
| 28 | +import org.eclipse.edc.policy.engine.spi.plan.step.AtomicConstraintStep; | |
| 29 | +import org.eclipse.edc.policy.engine.spi.plan.step.ConstraintStep; | |
| 30 | +import org.eclipse.edc.policy.engine.spi.plan.step.DutyStep; | |
| 31 | +import org.eclipse.edc.policy.engine.spi.plan.step.OrConstraintStep; | |
| 32 | +import org.eclipse.edc.policy.engine.spi.plan.step.PermissionStep; | |
| 33 | +import org.eclipse.edc.policy.engine.spi.plan.step.ProhibitionStep; | |
| 34 | +import org.eclipse.edc.policy.engine.spi.plan.step.ValidatorStep; | |
| 35 | +import org.eclipse.edc.policy.engine.spi.plan.step.XoneConstraintStep; | |
| 36 | +import org.eclipse.edc.policy.model.AtomicConstraint; | |
| 37 | +import org.eclipse.edc.policy.model.LiteralExpression; | |
| 25 | 38 | import org.eclipse.edc.policy.model.Policy; |
| 39 | +import org.eclipse.edc.policy.model.Rule; | |
| 26 | 40 | import org.eclipse.edc.spi.types.domain.DataAddress; |
| 27 | 41 | import org.eclipse.edc.spi.types.domain.callback.CallbackAddress; |
| 28 | 42 | |
| @@ -42,10 +56,13 @@ | ||
| 42 | 56 | import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; |
| 43 | 57 | import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; |
| 44 | 58 | import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_SCHEMA; |
| 59 | +import static org.eclipse.edc.policy.model.Operator.EQ; | |
| 45 | 60 | import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; |
| 46 | 61 | import static org.eclipse.edc.spi.types.domain.callback.CallbackAddress.EVENTS; |
| 47 | 62 | import static org.eclipse.edc.spi.types.domain.callback.CallbackAddress.IS_TRANSACTIONAL; |
| 48 | 63 | import static org.eclipse.edc.spi.types.domain.callback.CallbackAddress.URI; |
| 64 | +import static org.mockito.Mockito.mock; | |
| 65 | +import static org.mockito.Mockito.when; | |
| 49 | 66 | |
| 50 | 67 | public class TestFunctions { |
| 51 | 68 | |
| @@ -225,6 +242,30 @@ | ||
| 225 | 242 | .build(); |
| 226 | 243 | } |
| 227 | 244 | |
| 245 | + public static PolicyEvaluationPlan createPolicyEvaluationPlan() { | |
| 246 | + | |
| 247 | + var firstConstraint = atomicConstraintStep(atomicConstraint("foo", "bar")); | |
| 248 | + var secondConstraint = atomicConstraintStep(atomicConstraint("baz", "bar")); | |
| 249 | + | |
| 250 | + List<ConstraintStep> constraints = List.of(firstConstraint, secondConstraint); | |
| 251 | + | |
| 252 | + var orConstraintStep = new OrConstraintStep(constraints, mock()); | |
| 253 | + var andConstraintStep = new AndConstraintStep(constraints, mock()); | |
| 254 | + var xoneConstraintStep = new XoneConstraintStep(constraints, mock()); | |
| 255 | + | |
| 256 | + var permission = PermissionStep.Builder.newInstance().constraint(orConstraintStep).rule(mock()).build(); | |
| 257 | + var duty = DutyStep.Builder.newInstance().constraint(xoneConstraintStep).rule(mock()).build(); | |
| 258 | + var prohibition = ProhibitionStep.Builder.newInstance().constraint(andConstraintStep).rule(mock()).build(); | |
| 259 | + | |
| 260 | + return PolicyEvaluationPlan.Builder.newInstance() | |
| 261 | + .postValidator(new ValidatorStep(mock())) | |
| 262 | + .prohibition(prohibition) | |
| 263 | + .permission(permission) | |
| 264 | + .duty(duty) | |
| 265 | + .preValidator(new ValidatorStep(mock())) | |
| 266 | + .build(); | |
| 267 | + } | |
| 268 | + | |
| 228 | 269 | public static JsonObject policyDefinitionObject() { |
| 229 | 270 | return createObjectBuilder() |
| 230 | 271 | .add(CONTEXT, createContextBuilder().build()) |
| @@ -312,4 +353,28 @@ | ||
| 312 | 353 | .build()) |
| 313 | 354 | .build(); |
| 314 | 355 | } |
| 356 | + | |
| 357 | + public static JsonObject policyEvaluationPlanRequest() { | |
| 358 | + return Json.createObjectBuilder() | |
| 359 | + .add(CONTEXT, createContextBuilder().build()) | |
| 360 | + .add(TYPE, "PolicyEvaluationPlanRequest") | |
| 361 | + .add("policyScope", "catalog") | |
| 362 | + .build(); | |
| 363 | + } | |
| 364 | + | |
| 365 | + private static AtomicConstraintStep atomicConstraintStep(AtomicConstraint atomicConstraint) { | |
| 366 | + AtomicConstraintFunction<Rule> function = mock(); | |
| 367 | + when(function.name()).thenReturn("AtomicConstraintFunction"); | |
| 368 | + return new AtomicConstraintStep(atomicConstraint, List.of("filtered constraint"), mock(), function); | |
| 369 | + } | |
| 370 | + | |
| 371 | + private static AtomicConstraint atomicConstraint(String key, String value) { | |
| 372 | + var left = new LiteralExpression(key); | |
| 373 | + var right = new LiteralExpression(value); | |
| 374 | + return AtomicConstraint.Builder.newInstance() | |
| 375 | + .leftExpression(left) | |
| 376 | + .operator(EQ) | |
| 377 | + .rightExpression(right) | |
| 378 | + .build(); | |
| 379 | + } | |
| 315 | 380 | } |