From fca758177b64e72a7e23f17525cd01eae4f70984 Mon Sep 17 00:00:00 2001 From: Julia Pampus <72392527+juliapampus@users.noreply.github.com> Date: Wed, 26 Apr 2023 15:25:41 +0200 Subject: [PATCH] feat: dataspace protocol negotiation transformer (#2771) --------- Co-authored-by: Jan Peter Meyer Co-authored-by: Ronja Quensel --- .../dsp-negotiation-spi/build.gradle.kts | 21 --- .../DspNegotiationTransformExtension.java | 74 +++++++++ ...omContractAgreementMessageTransformer.java | 64 ++++++++ ...reementVerificationMessageTransformer.java | 54 +++++++ ...actNegotiationEventMessageTransformer.java | 81 ++++++++++ ...otiationTerminationMessageTransformer.java | 58 +++++++ ...ectFromContractNegotiationTransformer.java | 87 +++++++++++ ...nObjectFromContractRequestTransformer.java | 68 +++++++++ ...ToContractAgreementMessageTransformer.java | 81 ++++++++++ ...reementVerificationMessageTransformer.java | 46 ++++++ ...actNegotiationEventMessageTransformer.java | 66 ++++++++ ...otiationTerminationMessageTransformer.java | 58 +++++++ ...ctToContractRequestMessageTransformer.java | 72 +++++++++ ...ntractAgreementMessageTransformerTest.java | 126 ++++++++++++++++ ...entVerificationMessageTransformerTest.java | 71 +++++++++ ...egotiationEventMessageTransformerTest.java | 75 +++++++++ ...tionTerminationMessageTransformerTest.java | 73 +++++++++ ...romContractNegotiationTransformerTest.java | 76 ++++++++++ ...ContractRequestMessageTransformerTest.java | 129 ++++++++++++++++ ...ntractAgreementMessageTransformerTest.java | 142 ++++++++++++++++++ ...entVerificationMessageTransformerTest.java | 65 ++++++++ ...egotiationEventMessageTransformerTest.java | 72 +++++++++ ...tionTerminationMessageTransformerTest.java | 74 +++++++++ ...ContractRequestMessageTransformerTest.java | 129 ++++++++++++++++ .../agreement/ContractAgreementMessage.java | 1 - .../ContractNegotiationEventMessage.java | 11 ++ .../negotiation/ContractNegotiation.java | 10 ++ ...ContractNegotiationTerminationMessage.java | 11 +- .../spi/types/offer/ContractOffer.java | 12 +- .../spi/types/offer/ContractOfferTest.java | 22 --- 30 files changed, 1882 insertions(+), 47 deletions(-) delete mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-spi/build.gradle.kts create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/DspNegotiationTransformExtension.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractAgreementMessageTransformer.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractAgreementVerificationMessageTransformer.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractNegotiationEventMessageTransformer.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractNegotiationTerminationMessageTransformer.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractNegotiationTransformer.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractRequestTransformer.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/to/JsonObjectToContractAgreementMessageTransformer.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/to/JsonObjectToContractAgreementVerificationMessageTransformer.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/to/JsonObjectToContractNegotiationEventMessageTransformer.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/to/JsonObjectToContractNegotiationTerminationMessageTransformer.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/to/JsonObjectToContractRequestMessageTransformer.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractAgreementMessageTransformerTest.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractAgreementVerificationMessageTransformerTest.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractNegotiationEventMessageTransformerTest.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractNegotiationTerminationMessageTransformerTest.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractNegotiationTransformerTest.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractRequestMessageTransformerTest.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractAgreementMessageTransformerTest.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractAgreementVerificationMessageTransformerTest.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractNegotiationEventMessageTransformerTest.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractNegotiationTerminationMessageTransformerTest.java create mode 100644 data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractRequestMessageTransformerTest.java diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-spi/build.gradle.kts b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-spi/build.gradle.kts deleted file mode 100644 index 08711cf15f7..00000000000 --- a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-spi/build.gradle.kts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering - * - * 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 - * - * SPDX-License-Identifier: Apache-2.0 - * - * Contributors: - * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation - * - */ - -plugins { - `java-library` -} - -dependencies { - api(project(":spi:common:core-spi")) -} \ No newline at end of file diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/DspNegotiationTransformExtension.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/DspNegotiationTransformExtension.java new file mode 100644 index 00000000000..ac074f248d4 --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/DspNegotiationTransformExtension.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform; + +import jakarta.json.Json; +import org.eclipse.edc.jsonld.spi.transformer.JsonLdTransformerRegistry; +import org.eclipse.edc.protocol.dsp.negotiation.transform.from.JsonObjectFromContractAgreementMessageTransformer; +import org.eclipse.edc.protocol.dsp.negotiation.transform.from.JsonObjectFromContractAgreementVerificationMessageTransformer; +import org.eclipse.edc.protocol.dsp.negotiation.transform.from.JsonObjectFromContractNegotiationEventMessageTransformer; +import org.eclipse.edc.protocol.dsp.negotiation.transform.from.JsonObjectFromContractNegotiationTerminationMessageTransformer; +import org.eclipse.edc.protocol.dsp.negotiation.transform.from.JsonObjectFromContractNegotiationTransformer; +import org.eclipse.edc.protocol.dsp.negotiation.transform.from.JsonObjectFromContractRequestTransformer; +import org.eclipse.edc.protocol.dsp.negotiation.transform.to.JsonObjectToContractAgreementMessageTransformer; +import org.eclipse.edc.protocol.dsp.negotiation.transform.to.JsonObjectToContractAgreementVerificationMessageTransformer; +import org.eclipse.edc.protocol.dsp.negotiation.transform.to.JsonObjectToContractNegotiationEventMessageTransformer; +import org.eclipse.edc.protocol.dsp.negotiation.transform.to.JsonObjectToContractNegotiationTerminationMessageTransformer; +import org.eclipse.edc.protocol.dsp.negotiation.transform.to.JsonObjectToContractRequestMessageTransformer; +import org.eclipse.edc.runtime.metamodel.annotation.Extension; +import org.eclipse.edc.runtime.metamodel.annotation.Inject; +import org.eclipse.edc.spi.system.ServiceExtension; +import org.eclipse.edc.spi.system.ServiceExtensionContext; +import org.eclipse.edc.spi.types.TypeManager; + +import java.util.Map; + +/** + * Provides the transformers for negotiation message types via the {@link JsonLdTransformerRegistry}. + */ +@Extension(value = DspNegotiationTransformExtension.NAME) +public class DspNegotiationTransformExtension implements ServiceExtension { + + public static final String NAME = "Dataspace Protocol Negotiation Transform Extension"; + + @Inject + private TypeManager typeManager; + + @Inject + private JsonLdTransformerRegistry registry; + + @Override + public String name() { + return NAME; + } + + @Override + public void initialize(ServiceExtensionContext context) { + var builderFactory = Json.createBuilderFactory(Map.of()); + + registry.register(new JsonObjectFromContractAgreementMessageTransformer(builderFactory)); + registry.register(new JsonObjectFromContractAgreementVerificationMessageTransformer(builderFactory)); + registry.register(new JsonObjectFromContractNegotiationEventMessageTransformer(builderFactory)); + registry.register(new JsonObjectFromContractNegotiationTerminationMessageTransformer(builderFactory)); + registry.register(new JsonObjectFromContractNegotiationTransformer(builderFactory)); + registry.register(new JsonObjectFromContractRequestTransformer(builderFactory)); + + registry.register(new JsonObjectToContractAgreementMessageTransformer()); + registry.register(new JsonObjectToContractAgreementVerificationMessageTransformer()); + registry.register(new JsonObjectToContractNegotiationEventMessageTransformer()); + registry.register(new JsonObjectToContractRequestMessageTransformer()); + registry.register(new JsonObjectToContractNegotiationTerminationMessageTransformer()); + } +} diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractAgreementMessageTransformer.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractAgreementMessageTransformer.java new file mode 100644 index 00000000000..62362f11ab2 --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractAgreementMessageTransformer.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.from; + +import jakarta.json.JsonBuilderFactory; +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreementMessage; +import org.eclipse.edc.jsonld.spi.JsonLdKeywords; +import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.UUID; + +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_AGREEMENT_MESSAGE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_AGREEMENT; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; + + +/** + * Creates a dspace:ContractAgreementMessage as {@link JsonObject} from {@link ContractAgreementMessage}. + */ +public class JsonObjectFromContractAgreementMessageTransformer extends AbstractJsonLdTransformer { + + private final JsonBuilderFactory jsonFactory; + + public JsonObjectFromContractAgreementMessageTransformer(JsonBuilderFactory jsonFactory) { + super(ContractAgreementMessage.class, JsonObject.class); + this.jsonFactory = jsonFactory; + } + + @Override + public @Nullable JsonObject transform(@NotNull ContractAgreementMessage object, @NotNull TransformerContext context) { + var builder = jsonFactory.createObjectBuilder(); + builder.add(JsonLdKeywords.ID, String.valueOf(UUID.randomUUID())); + builder.add(JsonLdKeywords.TYPE, DSPACE_NEGOTIATION_AGREEMENT_MESSAGE); + + builder.add(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID, object.getProcessId()); + + var policy = context.transform(object.getContractAgreement().getPolicy(), JsonObject.class); + if (policy == null) { + context.reportProblem("Cannot transform from ContractAgreementMessage with null policy"); + return null; + } + + builder.add(DSPACE_NEGOTIATION_PROPERTY_AGREEMENT, policy); + + return builder.build(); + } + +} diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractAgreementVerificationMessageTransformer.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractAgreementVerificationMessageTransformer.java new file mode 100644 index 00000000000..a996b1efd27 --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractAgreementVerificationMessageTransformer.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.from; + +import jakarta.json.JsonBuilderFactory; +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreementVerificationMessage; +import org.eclipse.edc.jsonld.spi.JsonLdKeywords; +import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.UUID; + +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_AGREEMENT_VERIFICATION_MESSAGE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; + +/** + * Creates a {@link JsonObject} from a {@link ContractAgreementVerificationMessage}. + */ +public class JsonObjectFromContractAgreementVerificationMessageTransformer extends AbstractJsonLdTransformer { + + private final JsonBuilderFactory jsonFactory; + + public JsonObjectFromContractAgreementVerificationMessageTransformer(JsonBuilderFactory jsonFactory) { + super(ContractAgreementVerificationMessage.class, JsonObject.class); + this.jsonFactory = jsonFactory; + } + + @Override + public @Nullable JsonObject transform(@NotNull ContractAgreementVerificationMessage object, @NotNull TransformerContext context) { + var builder = jsonFactory.createObjectBuilder(); + builder.add(JsonLdKeywords.ID, String.valueOf(UUID.randomUUID())); + builder.add(JsonLdKeywords.TYPE, DSPACE_NEGOTIATION_AGREEMENT_VERIFICATION_MESSAGE); + + builder.add(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID, object.getProcessId()); + // TODO add mapping of cred:credentialSubject for signature processes + + return builder.build(); + } +} diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractNegotiationEventMessageTransformer.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractNegotiationEventMessageTransformer.java new file mode 100644 index 00000000000..92ad131c6c8 --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractNegotiationEventMessageTransformer.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.from; + +import jakarta.json.JsonBuilderFactory; +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractNegotiationEventMessage; +import org.eclipse.edc.jsonld.spi.JsonLdKeywords; +import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.UUID; + +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_EVENT_MESSAGE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_CHECKSUM; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_ACCEPTED; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_FINALIZED; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; + + +/** + * Creates a {@link JsonObject} from a {@link ContractNegotiationEventMessage}. + */ +public class JsonObjectFromContractNegotiationEventMessageTransformer extends AbstractJsonLdTransformer { + + private final JsonBuilderFactory jsonFactory; + + public JsonObjectFromContractNegotiationEventMessageTransformer(JsonBuilderFactory jsonFactory) { + super(ContractNegotiationEventMessage.class, JsonObject.class); + this.jsonFactory = jsonFactory; + } + + @Override + public @Nullable JsonObject transform(@NotNull ContractNegotiationEventMessage object, @NotNull TransformerContext context) { + var builder = jsonFactory.createObjectBuilder(); + builder.add(JsonLdKeywords.ID, String.valueOf(UUID.randomUUID())); + builder.add(JsonLdKeywords.TYPE, DSPACE_NEGOTIATION_EVENT_MESSAGE); + + builder.add(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID, object.getProcessId()); + builder.add(DSPACE_NEGOTIATION_PROPERTY_CHECKSUM, object.getChecksum()); + + var eventType = eventType(object, context); + if (eventType == null) { + return null; + } + + builder.add(DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE, eventType); + + + return builder.build(); + } + + private String eventType(ContractNegotiationEventMessage message, TransformerContext context) { + switch (message.getType()) { + case ACCEPTED: + return DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_ACCEPTED; + case FINALIZED: + return DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_FINALIZED; + default: + context.reportProblem(String.format("Could not map eventType %s to %s or %s in ContractNegotiationEventMessage", message.getType(), + DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_ACCEPTED, DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_FINALIZED)); + return null; + } + } + +} diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractNegotiationTerminationMessageTransformer.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractNegotiationTerminationMessageTransformer.java new file mode 100644 index 00000000000..099226b5657 --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractNegotiationTerminationMessageTransformer.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.from; + +import jakarta.json.JsonBuilderFactory; +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationTerminationMessage; +import org.eclipse.edc.jsonld.spi.JsonLdKeywords; +import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.UUID; + +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_CODE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_REASON; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_TERMINATION_MESSAGE; + +/** + * Creates a {@link JsonObject} from a {@link ContractNegotiationTerminationMessage}. + */ +public class JsonObjectFromContractNegotiationTerminationMessageTransformer extends AbstractJsonLdTransformer { + + private final JsonBuilderFactory jsonFactory; + + public JsonObjectFromContractNegotiationTerminationMessageTransformer(JsonBuilderFactory jsonFactory) { + super(ContractNegotiationTerminationMessage.class, JsonObject.class); + this.jsonFactory = jsonFactory; + } + + @Override + public @Nullable JsonObject transform(@NotNull ContractNegotiationTerminationMessage object, @NotNull TransformerContext context) { + var builder = jsonFactory.createObjectBuilder(); + builder.add(JsonLdKeywords.ID, String.valueOf(UUID.randomUUID())); + builder.add(JsonLdKeywords.TYPE, DSPACE_NEGOTIATION_TERMINATION_MESSAGE); + + builder.add(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID, object.getProcessId()); + builder.add(DSPACE_NEGOTIATION_PROPERTY_REASON, object.getRejectionReason()); + builder.add(DSPACE_NEGOTIATION_PROPERTY_CODE, object.getCode()); + + return builder.build(); + } + +} diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractNegotiationTransformer.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractNegotiationTransformer.java new file mode 100644 index 00000000000..2e5bd4d6351 --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractNegotiationTransformer.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.from; + +import jakarta.json.JsonBuilderFactory; +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates; +import org.eclipse.edc.jsonld.spi.JsonLdKeywords; +import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_CONTRACT_NEGOTIATION; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_CHECKSUM; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_STATE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_STATE_ACCEPTED; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_STATE_AGREED; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_STATE_FINALIZED; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_STATE_OFFERED; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_STATE_REQUESTED; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_STATE_TERMINATED; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_STATE_VERIFIED; + + +/** + * Creates a {@link JsonObject} from a {@link ContractNegotiation}. + */ +public class JsonObjectFromContractNegotiationTransformer extends AbstractJsonLdTransformer { + + private final JsonBuilderFactory jsonFactory; + + public JsonObjectFromContractNegotiationTransformer(JsonBuilderFactory jsonFactory) { + super(ContractNegotiation.class, JsonObject.class); + this.jsonFactory = jsonFactory; + } + + @Override + public @Nullable JsonObject transform(@NotNull ContractNegotiation object, @NotNull TransformerContext context) { + var builder = jsonFactory.createObjectBuilder(); + builder.add(JsonLdKeywords.ID, object.getCorrelationId()); + builder.add(JsonLdKeywords.TYPE, DSPACE_CONTRACT_NEGOTIATION); + + builder.add(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID, object.getCorrelationId()); + builder.add(DSPACE_NEGOTIATION_PROPERTY_STATE, state(object.getState(), context)); + builder.add(DSPACE_NEGOTIATION_PROPERTY_CHECKSUM, object.getChecksum()); + + return builder.build(); + } + + private String state(Integer state, TransformerContext context) { + switch (ContractNegotiationStates.from(state)) { + case REQUESTED: + return DSPACE_NEGOTIATION_STATE_REQUESTED; + case OFFERED: + return DSPACE_NEGOTIATION_STATE_OFFERED; + case ACCEPTED: + return DSPACE_NEGOTIATION_STATE_ACCEPTED; + case AGREED: + return DSPACE_NEGOTIATION_STATE_AGREED; + case VERIFIED: + return DSPACE_NEGOTIATION_STATE_VERIFIED; + case FINALIZED: + return DSPACE_NEGOTIATION_STATE_FINALIZED; + case TERMINATED: + return DSPACE_NEGOTIATION_STATE_TERMINATED; + default: + context.reportProblem(String.format("Could not map state %s in ContractNegotiation", state)); + return null; + } + } + +} diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractRequestTransformer.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractRequestTransformer.java new file mode 100644 index 00000000000..727c074e4d9 --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/from/JsonObjectFromContractRequestTransformer.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.from; + +import jakarta.json.JsonBuilderFactory; +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequestMessage; +import org.eclipse.edc.jsonld.spi.JsonLdKeywords; +import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.UUID; + +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_CONTRACT_REQUEST_MESSAGE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_CALLBACK_ADDRESS; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_DATASET; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_OFFER; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; + + +/** + * Creates a {@link JsonObject} from a {@link ContractRequestMessage}. + */ +public class JsonObjectFromContractRequestTransformer extends AbstractJsonLdTransformer { + + private final JsonBuilderFactory jsonFactory; + + public JsonObjectFromContractRequestTransformer(JsonBuilderFactory jsonFactory) { + super(ContractRequestMessage.class, JsonObject.class); + this.jsonFactory = jsonFactory; + } + + @Override + public @Nullable JsonObject transform(@NotNull ContractRequestMessage object, @NotNull TransformerContext context) { + var builder = jsonFactory.createObjectBuilder(); + builder.add(JsonLdKeywords.ID, String.valueOf(UUID.randomUUID())); + builder.add(JsonLdKeywords.TYPE, DSPACE_NEGOTIATION_CONTRACT_REQUEST_MESSAGE); + + builder.add(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID, object.getProcessId()); + builder.add(DSPACE_NEGOTIATION_PROPERTY_DATASET, object.getContractOffer().getAsset().getId()); + builder.add(DSPACE_NEGOTIATION_PROPERTY_CALLBACK_ADDRESS, object.getCallbackAddress()); + + var policy = context.transform(object.getContractOffer().getPolicy(), JsonObject.class); + if (policy == null) { + context.reportProblem("Cannot transform from ContractRequestMessage with null policy"); + return null; + } + + builder.add(DSPACE_NEGOTIATION_PROPERTY_OFFER, policy); + + return builder.build(); + } + +} diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/to/JsonObjectToContractAgreementMessageTransformer.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/to/JsonObjectToContractAgreementMessageTransformer.java new file mode 100644 index 00000000000..fe61bf18f71 --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/to/JsonObjectToContractAgreementMessageTransformer.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.to; + +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreementMessage; +import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; +import org.eclipse.edc.policy.model.Policy; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_AGREEMENT; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_TIMESTAMP; +import static org.eclipse.edc.protocol.dsp.spi.types.HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP; + +/** + * Creates a {@link ContractAgreementMessage} from a {@link JsonObject}. + */ +public class JsonObjectToContractAgreementMessageTransformer extends AbstractJsonLdTransformer { + + public JsonObjectToContractAgreementMessageTransformer() { + super(JsonObject.class, ContractAgreementMessage.class); + } + + @Override + public @Nullable ContractAgreementMessage transform(@NotNull JsonObject object, @NotNull TransformerContext context) { + var builder = ContractAgreementMessage.Builder.newInstance(); + builder.protocol(DATASPACE_PROTOCOL_HTTP); + transformString(object.get(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID), builder::processId, context); + + var policy = context.transform(object.getJsonObject(DSPACE_NEGOTIATION_PROPERTY_AGREEMENT), Policy.class); + if (policy == null) { + context.reportProblem("Cannot transform to ContractAgreementMessage with null policy"); + return null; + } + + var agreement = contractAgreement(object, policy, context); + if (agreement == null) { + context.reportProblem("Cannot transform to ContractAgreementMessage with null agreement"); + return null; + } + + builder.contractAgreement(agreement); + + return builder.build(); + } + + private ContractAgreement contractAgreement(JsonObject object, Policy policy, TransformerContext context) { + var builder = ContractAgreement.Builder.newInstance(); + builder.id(nodeId(object)); + builder.providerAgentId(""); // TODO + builder.consumerAgentId(""); // TODO + builder.policy(policy); + builder.assetId(policy.getTarget()); + + var timestamp = object.getString(DSPACE_NEGOTIATION_PROPERTY_TIMESTAMP); + try { + builder.contractSigningDate(Long.parseLong(timestamp)); + } catch (NumberFormatException exception) { + context.reportProblem(String.format("Cannot transform %s to long in ContractAgreementMessage", timestamp)); + return null; + } + + return builder.build(); + } +} diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/to/JsonObjectToContractAgreementVerificationMessageTransformer.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/to/JsonObjectToContractAgreementVerificationMessageTransformer.java new file mode 100644 index 00000000000..28852055e15 --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/to/JsonObjectToContractAgreementVerificationMessageTransformer.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.to; + +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreementVerificationMessage; +import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; +import static org.eclipse.edc.protocol.dsp.spi.types.HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP; + +/** + * Creates a {@link ContractAgreementVerificationMessage} from a {@link JsonObject}. + */ +public class JsonObjectToContractAgreementVerificationMessageTransformer extends AbstractJsonLdTransformer { + + public JsonObjectToContractAgreementVerificationMessageTransformer() { + super(JsonObject.class, ContractAgreementVerificationMessage.class); + } + + @Override + public @Nullable ContractAgreementVerificationMessage transform(@NotNull JsonObject object, @NotNull TransformerContext context) { + var builder = ContractAgreementVerificationMessage.Builder.newInstance(); + builder.protocol(DATASPACE_PROTOCOL_HTTP); + transformString(object.get(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID), builder::processId, context); + // TODO add mapping of cred:credentialSubject with signature processes + + return builder.build(); + } + +} diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/to/JsonObjectToContractNegotiationEventMessageTransformer.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/to/JsonObjectToContractNegotiationEventMessageTransformer.java new file mode 100644 index 00000000000..5492a750510 --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/to/JsonObjectToContractNegotiationEventMessageTransformer.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.to; + +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractNegotiationEventMessage; +import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractNegotiationEventMessage.Type.ACCEPTED; +import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractNegotiationEventMessage.Type.FINALIZED; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_CHECKSUM; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_ACCEPTED; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_FINALIZED; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; +import static org.eclipse.edc.protocol.dsp.spi.types.HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP; + +/** + * Creates a {@link ContractNegotiationEventMessage} from a {@link JsonObject}. + */ +public class JsonObjectToContractNegotiationEventMessageTransformer extends AbstractJsonLdTransformer { + + public JsonObjectToContractNegotiationEventMessageTransformer() { + super(JsonObject.class, ContractNegotiationEventMessage.class); + } + + @Override + public @Nullable ContractNegotiationEventMessage transform(@NotNull JsonObject object, @NotNull TransformerContext context) { + + var builder = ContractNegotiationEventMessage.Builder.newInstance(); + builder.protocol(DATASPACE_PROTOCOL_HTTP); + transformString(object.get(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID), builder::processId, context); + transformString(object.get(DSPACE_NEGOTIATION_PROPERTY_CHECKSUM), builder::checksum, context); + + transformString(object.get(DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE), (value) -> { + switch (value) { + case DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_ACCEPTED: + builder.type(ACCEPTED); + break; + case DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_FINALIZED: + builder.type(FINALIZED); + break; + default: + context.reportProblem(String.format("Could not map type %s in ContractNegotiationEventMessage", value)); + } + }, context); + + return builder.build(); + } + +} diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/to/JsonObjectToContractNegotiationTerminationMessageTransformer.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/to/JsonObjectToContractNegotiationTerminationMessageTransformer.java new file mode 100644 index 00000000000..096383e938d --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/to/JsonObjectToContractNegotiationTerminationMessageTransformer.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.to; + +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationTerminationMessage; +import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import static java.lang.String.format; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_CODE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_REASON; +import static org.eclipse.edc.protocol.dsp.spi.types.HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP; + +/** + * Creates a {@link ContractNegotiationTerminationMessage} from a {@link JsonObject}. + */ +public class JsonObjectToContractNegotiationTerminationMessageTransformer extends AbstractJsonLdTransformer { + + public JsonObjectToContractNegotiationTerminationMessageTransformer() { + super(JsonObject.class, ContractNegotiationTerminationMessage.class); + } + + @Override + public @Nullable ContractNegotiationTerminationMessage transform(@NotNull JsonObject object, @NotNull TransformerContext context) { + var builder = ContractNegotiationTerminationMessage.Builder.newInstance(); + builder.protocol(DATASPACE_PROTOCOL_HTTP); + transformString(object.get(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID), builder::processId, context); + transformString(object.get(DSPACE_NEGOTIATION_PROPERTY_CODE), builder::code, context); + + var reasons = object.get(DSPACE_NEGOTIATION_PROPERTY_REASON); + if (reasons != null) { + var result = typeValueArray(reasons, context); + if (result == null) { + context.reportProblem(format("Cannot transform property %s in ContractNegotiationTerminationMessage", DSPACE_NEGOTIATION_PROPERTY_REASON)); + } else { + if (result.size() > 0) builder.rejectionReason(String.valueOf(result.get(0))); + } + } + + return builder.build(); + } +} diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/to/JsonObjectToContractRequestMessageTransformer.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/to/JsonObjectToContractRequestMessageTransformer.java new file mode 100644 index 00000000000..0ab47b89539 --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/main/java/org.eclipse.edc.protocol.dsp.negotiation.transform/to/JsonObjectToContractRequestMessageTransformer.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.to; + +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequestMessage; +import org.eclipse.edc.connector.contract.spi.types.offer.ContractOffer; +import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; +import org.eclipse.edc.policy.model.Policy; +import org.eclipse.edc.spi.types.domain.asset.Asset; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequestMessage.Type.INITIAL; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_CALLBACK_ADDRESS; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_DATASET; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_OFFER; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; +import static org.eclipse.edc.protocol.dsp.spi.types.HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP; + +/** + * Creates a {@link ContractRequestMessage} from a {@link JsonObject}. + */ +public class JsonObjectToContractRequestMessageTransformer extends AbstractJsonLdTransformer { + + public JsonObjectToContractRequestMessageTransformer() { + super(JsonObject.class, ContractRequestMessage.class); + } + + @Override + public @Nullable ContractRequestMessage transform(@NotNull JsonObject object, @NotNull TransformerContext context) { + var builder = ContractRequestMessage.Builder.newInstance() + .protocol(DATASPACE_PROTOCOL_HTTP) + .type(INITIAL); + + transformString(object.get(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID), builder::processId, context); + transformString(object.get(DSPACE_NEGOTIATION_PROPERTY_CALLBACK_ADDRESS), builder::callbackAddress, context); + transformString(object.get(DSPACE_NEGOTIATION_PROPERTY_DATASET), builder::dataSet, context); + + var policy = context.transform(object.getJsonObject(DSPACE_NEGOTIATION_PROPERTY_OFFER), Policy.class); + if (policy == null) { + context.reportProblem("Cannot transform to ContractRequestMessage with null policy"); + return null; + } + + builder.contractOffer(contractOffer(object, policy)); + + return builder.build(); + } + + private ContractOffer contractOffer(JsonObject offer, Policy policy) { + var builder = ContractOffer.Builder.newInstance(); + builder.id(nodeId(offer)); + builder.asset(Asset.Builder.newInstance().id(policy.getTarget()).build()); + builder.policy(policy); + + return builder.build(); + } +} diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractAgreementMessageTransformerTest.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractAgreementMessageTransformerTest.java new file mode 100644 index 00000000000..bd64362c2c0 --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractAgreementMessageTransformerTest.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.from; + +import jakarta.json.Json; +import jakarta.json.JsonBuilderFactory; +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreementMessage; +import org.eclipse.edc.policy.model.Action; +import org.eclipse.edc.policy.model.Duty; +import org.eclipse.edc.policy.model.Permission; +import org.eclipse.edc.policy.model.Policy; +import org.eclipse.edc.policy.model.Prohibition; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Map; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_AGREEMENT_MESSAGE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_AGREEMENT; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +class JsonObjectFromContractAgreementMessageTransformerTest { + + private final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(Map.of()); + private final TransformerContext context = mock(TransformerContext.class); + + private JsonObjectFromContractAgreementMessageTransformer transformer; + + @BeforeEach + void setUp() { + transformer = new JsonObjectFromContractAgreementMessageTransformer(jsonFactory); + } + + @Test + void transform() { + var value = "example"; + var agreement = contractAgreement(); + var message = ContractAgreementMessage.Builder.newInstance() + .protocol(value) + .processId(value) + .callbackAddress(value) + .contractAgreement(agreement) + .build(); + + var obj = jsonFactory.createObjectBuilder().build(); + + when(context.transform(any(Policy.class), eq(JsonObject.class))).thenReturn(obj); + + var result = transformer.transform(message, context); + + assertThat(result).isNotNull(); + assertThat(result.getJsonString(ID).getString()).isNotNull(); + assertThat(result.getJsonString(ID).getString()).isNotEmpty(); + assertThat(result.getJsonString(TYPE).getString()).isEqualTo(DSPACE_NEGOTIATION_AGREEMENT_MESSAGE); + assertThat(result.getJsonString(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID).getString()).isEqualTo(value); + assertThat(result.getJsonObject(DSPACE_NEGOTIATION_PROPERTY_AGREEMENT)).isNotNull(); + + verify(context, never()).reportProblem(anyString()); + } + + @Test + void transform_nullPolicy() { + var value = "example"; + var agreement = contractAgreement(); + var message = ContractAgreementMessage.Builder.newInstance() + .protocol(value) + .processId(value) + .callbackAddress(value) + .contractAgreement(agreement) + .build(); + + when(context.transform(any(Policy.class), eq(JsonObject.class))).thenReturn(null); + + assertThat(transformer.transform(message, context)).isNull(); + + verify(context, times(1)).reportProblem(anyString()); + } + + private ContractAgreement contractAgreement() { + return ContractAgreement.Builder.newInstance() + .id(String.valueOf(UUID.randomUUID())) + .providerAgentId("agentId") + .consumerAgentId("agentId") + .assetId("assetId") + .policy(policy()).build(); + } + + private Policy policy() { + var action = Action.Builder.newInstance().type("USE").build(); + var permission = Permission.Builder.newInstance().action(action).build(); + var prohibition = Prohibition.Builder.newInstance().action(action).build(); + var duty = Duty.Builder.newInstance().action(action).build(); + return Policy.Builder.newInstance() + .permission(permission) + .prohibition(prohibition) + .duty(duty) + .build(); + } +} \ No newline at end of file diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractAgreementVerificationMessageTransformerTest.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractAgreementVerificationMessageTransformerTest.java new file mode 100644 index 00000000000..66feb791de5 --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractAgreementVerificationMessageTransformerTest.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.from; + +import jakarta.json.Json; +import jakarta.json.JsonBuilderFactory; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreementVerificationMessage; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.CRED_CREDENTIAL_SUBJECT; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_AGREEMENT_VERIFICATION_MESSAGE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.SEC_PROOF; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +class JsonObjectFromContractAgreementVerificationMessageTransformerTest { + + private final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(Map.of()); + private final TransformerContext context = mock(TransformerContext.class); + + private JsonObjectFromContractAgreementVerificationMessageTransformer transformer; + + @BeforeEach + void setUp() { + transformer = new JsonObjectFromContractAgreementVerificationMessageTransformer(jsonFactory); + } + + @Test + void transform() { + var value = "example"; + var message = ContractAgreementVerificationMessage.Builder.newInstance() + .protocol(value) + .processId(value) + .callbackAddress(value) + .build(); + + var result = transformer.transform(message, context); + + assertThat(result).isNotNull(); + assertThat(result.getJsonString(ID).getString()).isNotNull(); + assertThat(result.getJsonString(ID).getString()).isNotEmpty(); + assertThat(result.getJsonString(TYPE).getString()).isEqualTo(DSPACE_NEGOTIATION_AGREEMENT_VERIFICATION_MESSAGE); + assertThat(result.getJsonString(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID).getString()).isEqualTo(value); + assertThat(result.getJsonString(CRED_CREDENTIAL_SUBJECT)).isNull(); + assertThat(result.getJsonString(SEC_PROOF)).isNull(); + + verify(context, never()).reportProblem(anyString()); + } +} \ No newline at end of file diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractNegotiationEventMessageTransformerTest.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractNegotiationEventMessageTransformerTest.java new file mode 100644 index 00000000000..19cfc3d0ec8 --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractNegotiationEventMessageTransformerTest.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.from; + +import jakarta.json.Json; +import jakarta.json.JsonBuilderFactory; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractNegotiationEventMessage; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractNegotiationEventMessage.Type.ACCEPTED; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_EVENT_MESSAGE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_CHECKSUM; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_ACCEPTED; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +class JsonObjectFromContractNegotiationEventMessageTransformerTest { + + private final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(Map.of()); + private final TransformerContext context = mock(TransformerContext.class); + + private JsonObjectFromContractNegotiationEventMessageTransformer transformer; + + @BeforeEach + void setUp() { + transformer = new JsonObjectFromContractNegotiationEventMessageTransformer(jsonFactory); + } + + @Test + void transform() { + var value = "example"; + var message = ContractNegotiationEventMessage.Builder.newInstance() + .protocol(value) + .processId(value) + .callbackAddress(value) + .type(ACCEPTED) + .checksum(value) + .build(); + + var result = transformer.transform(message, context); + + assertThat(result).isNotNull(); + assertThat(result.getJsonString(ID).getString()).isNotNull(); + assertThat(result.getJsonString(ID).getString()).isNotEmpty(); + assertThat(result.getJsonString(TYPE).getString()).isEqualTo(DSPACE_NEGOTIATION_EVENT_MESSAGE); + assertThat(result.getJsonString(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID).getString()).isEqualTo(value); + assertThat(result.getJsonString(DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE).getString()).isEqualTo(DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_ACCEPTED); + assertThat(result.getJsonString(DSPACE_NEGOTIATION_PROPERTY_CHECKSUM).getString()).isEqualTo(value); + + verify(context, never()).reportProblem(anyString()); + } +} \ No newline at end of file diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractNegotiationTerminationMessageTransformerTest.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractNegotiationTerminationMessageTransformerTest.java new file mode 100644 index 00000000000..e007f3fd900 --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractNegotiationTerminationMessageTransformerTest.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.from; + +import jakarta.json.Json; +import jakarta.json.JsonBuilderFactory; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationTerminationMessage; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_CODE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_REASON; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_TERMINATION_MESSAGE; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +class JsonObjectFromContractNegotiationTerminationMessageTransformerTest { + + private final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(Map.of()); + private final TransformerContext context = mock(TransformerContext.class); + + private JsonObjectFromContractNegotiationTerminationMessageTransformer transformer; + + @BeforeEach + void setUp() { + transformer = new JsonObjectFromContractNegotiationTerminationMessageTransformer(jsonFactory); + } + + @Test + void transform() { + var value = "example"; + var message = ContractNegotiationTerminationMessage.Builder.newInstance() + .protocol(value) + .processId(value) + .callbackAddress(value) + .rejectionReason(value) + .code(value) + .build(); + + var result = transformer.transform(message, context); + + assertThat(result).isNotNull(); + assertThat(result.getJsonString(ID).getString()).isNotNull(); + assertThat(result.getJsonString(ID).getString()).isNotEmpty(); + assertThat(result.getJsonString(TYPE).getString()).isEqualTo(DSPACE_NEGOTIATION_TERMINATION_MESSAGE); + assertThat(result.getJsonString(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID).getString()).isEqualTo(value); + assertThat(result.getJsonString(DSPACE_NEGOTIATION_PROPERTY_CODE).getString()).isEqualTo(value); + assertThat(result.getJsonString(DSPACE_NEGOTIATION_PROPERTY_REASON).getString()).isEqualTo(value); + + verify(context, never()).reportProblem(anyString()); + } +} \ No newline at end of file diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractNegotiationTransformerTest.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractNegotiationTransformerTest.java new file mode 100644 index 00000000000..d6b005a15fd --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractNegotiationTransformerTest.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.from; + +import jakarta.json.Json; +import jakarta.json.JsonBuilderFactory; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates.REQUESTED; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_CONTRACT_NEGOTIATION; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_CHECKSUM; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_STATE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_STATE_REQUESTED; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +class JsonObjectFromContractNegotiationTransformerTest { + + private final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(Map.of()); + private final TransformerContext context = mock(TransformerContext.class); + + private JsonObjectFromContractNegotiationTransformer transformer; + + @BeforeEach + void setUp() { + transformer = new JsonObjectFromContractNegotiationTransformer(jsonFactory); + } + + @Test + void transform() { + var value = "example"; + var negotiation = ContractNegotiation.Builder.newInstance() + .id(value) + .correlationId(value) + .counterPartyId("counterPartyId") + .counterPartyAddress("counterPartyAddress") + .protocol("protocol") + .state(REQUESTED.code()) + .checksum(value) + .build(); + + var result = transformer.transform(negotiation, context); + + assertThat(result).isNotNull(); + assertThat(result.getJsonString(ID).getString()).isEqualTo(value); + assertThat(result.getJsonString(TYPE).getString()).isEqualTo(DSPACE_CONTRACT_NEGOTIATION); + assertThat(result.getJsonString(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID).getString()).isEqualTo(value); + assertThat(result.getJsonString(DSPACE_NEGOTIATION_PROPERTY_STATE).getString()).isEqualTo(DSPACE_NEGOTIATION_STATE_REQUESTED); + assertThat(result.getJsonString(DSPACE_NEGOTIATION_PROPERTY_CHECKSUM).getString()).isEqualTo(value); + + verify(context, never()).reportProblem(anyString()); + } +} \ No newline at end of file diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractRequestMessageTransformerTest.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractRequestMessageTransformerTest.java new file mode 100644 index 00000000000..be9d0f49601 --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/from/JsonObjectFromContractRequestMessageTransformerTest.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.from; + +import jakarta.json.Json; +import jakarta.json.JsonBuilderFactory; +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequestMessage; +import org.eclipse.edc.connector.contract.spi.types.offer.ContractOffer; +import org.eclipse.edc.policy.model.Action; +import org.eclipse.edc.policy.model.Duty; +import org.eclipse.edc.policy.model.Permission; +import org.eclipse.edc.policy.model.Policy; +import org.eclipse.edc.policy.model.Prohibition; +import org.eclipse.edc.spi.types.domain.asset.Asset; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Map; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_CONTRACT_REQUEST_MESSAGE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_CALLBACK_ADDRESS; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_DATASET; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_OFFER; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +class JsonObjectFromContractRequestMessageTransformerTest { + + private final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(Map.of()); + private final TransformerContext context = mock(TransformerContext.class); + + private JsonObjectFromContractRequestTransformer transformer; + + @BeforeEach + void setUp() { + transformer = new JsonObjectFromContractRequestTransformer(jsonFactory); + } + + @Test + void transform() { + var value = "example"; + var message = ContractRequestMessage.Builder.newInstance() + .protocol(value) + .processId(value) + .callbackAddress(value) + .dataSet(value) + .contractOffer(contractOffer()) + .build(); + + var obj = jsonFactory.createObjectBuilder().build(); + + when(context.transform(any(Policy.class), eq(JsonObject.class))).thenReturn(obj); + + var result = transformer.transform(message, context); + + assertThat(result).isNotNull(); + assertThat(result.getJsonString(ID).getString()).isNotNull(); + assertThat(result.getJsonString(ID).getString()).isNotEmpty(); + assertThat(result.getJsonString(TYPE).getString()).isEqualTo(DSPACE_NEGOTIATION_CONTRACT_REQUEST_MESSAGE); + assertThat(result.getJsonString(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID).getString()).isEqualTo(value); + assertThat(result.getJsonString(DSPACE_NEGOTIATION_PROPERTY_DATASET).getString()).isEqualTo("assetId"); + assertThat(result.getJsonString(DSPACE_NEGOTIATION_PROPERTY_CALLBACK_ADDRESS).getString()).isEqualTo(value); + assertThat(result.getJsonObject(DSPACE_NEGOTIATION_PROPERTY_OFFER)).isNotNull(); + + verify(context, never()).reportProblem(anyString()); + } + + @Test + void transform_nullPolicy() { + var value = "example"; + var message = ContractRequestMessage.Builder.newInstance() + .protocol(value) + .processId(value) + .callbackAddress(value) + .dataSet(value) + .contractOffer(contractOffer()) + .build(); + + when(context.transform(any(Policy.class), eq(JsonObject.class))).thenReturn(null); + + assertThat(transformer.transform(message, context)).isNull(); + + verify(context, times(1)).reportProblem(anyString()); + } + + private ContractOffer contractOffer() { + return ContractOffer.Builder.newInstance() + .id(String.valueOf(UUID.randomUUID())) + .asset(Asset.Builder.newInstance().id("assetId").build()) + .policy(policy()).build(); + } + + private Policy policy() { + var action = Action.Builder.newInstance().type("USE").build(); + var permission = Permission.Builder.newInstance().action(action).build(); + var prohibition = Prohibition.Builder.newInstance().action(action).build(); + var duty = Duty.Builder.newInstance().action(action).build(); + return Policy.Builder.newInstance() + .permission(permission) + .prohibition(prohibition) + .duty(duty) + .build(); + } +} \ No newline at end of file diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractAgreementMessageTransformerTest.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractAgreementMessageTransformerTest.java new file mode 100644 index 00000000000..a97bf6f625e --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractAgreementMessageTransformerTest.java @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.to; + +import jakarta.json.Json; +import jakarta.json.JsonBuilderFactory; +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreementMessage; +import org.eclipse.edc.jsonld.spi.JsonLdKeywords; +import org.eclipse.edc.policy.model.Action; +import org.eclipse.edc.policy.model.Duty; +import org.eclipse.edc.policy.model.Permission; +import org.eclipse.edc.policy.model.Policy; +import org.eclipse.edc.policy.model.Prohibition; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_POLICY_TYPE_AGREEMENT; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_AGREEMENT_MESSAGE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_AGREEMENT; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_TIMESTAMP; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +class JsonObjectToContractAgreementMessageTransformerTest { + + private final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(Map.of()); + private final TransformerContext context = mock(TransformerContext.class); + + private JsonObjectToContractAgreementMessageTransformer transformer; + + @BeforeEach + void setUp() { + transformer = new JsonObjectToContractAgreementMessageTransformer(); + } + + @Test + void transform() { + var value = "example"; + var message = jsonFactory.createObjectBuilder() + .add(JsonLdKeywords.ID, value) + .add(JsonLdKeywords.TYPE, DSPACE_NEGOTIATION_AGREEMENT_MESSAGE) + .add(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID, value) + .add(DSPACE_NEGOTIATION_PROPERTY_AGREEMENT, contractAgreement()) + .add(DSPACE_NEGOTIATION_PROPERTY_TIMESTAMP, "123") + .build(); + + when(context.transform(any(JsonObject.class), eq(Policy.class))).thenReturn(policy()); + + var result = transformer.transform(message, context); + + assertThat(result).isNotNull(); + assertThat(result.getClass()).isEqualTo(ContractAgreementMessage.class); + assertThat(result.getProtocol()).isNotEmpty(); + assertThat(result.getProcessId()).isEqualTo(value); + assertThat(result.getContractAgreement()).isNotNull(); + assertThat(result.getContractAgreement().getClass()).isEqualTo(ContractAgreement.class); + assertThat(result.getContractAgreement().getId()).isEqualTo(value); + assertThat(result.getContractAgreement().getAssetId()).isEqualTo("target"); + + verify(context, never()).reportProblem(anyString()); + } + + @Test + void transform_nullPolicy() { + var value = "example"; + var message = jsonFactory.createObjectBuilder() + .add(JsonLdKeywords.ID, value) + .add(JsonLdKeywords.TYPE, DSPACE_NEGOTIATION_AGREEMENT_MESSAGE) + .add(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID, value) + .add(DSPACE_NEGOTIATION_PROPERTY_AGREEMENT, contractAgreement()) + .add(DSPACE_NEGOTIATION_PROPERTY_TIMESTAMP, "123") + .build(); + + when(context.transform(any(JsonObject.class), eq(Policy.class))).thenReturn(null); + + assertThat(transformer.transform(message, context)).isNull(); + + verify(context, times(1)).reportProblem(anyString()); + } + + @Test + void transform_invalidTimestamp() { + var value = "example"; + var message = jsonFactory.createObjectBuilder() + .add(JsonLdKeywords.ID, value) + .add(JsonLdKeywords.TYPE, DSPACE_NEGOTIATION_AGREEMENT_MESSAGE) + .add(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID, value) + .add(DSPACE_NEGOTIATION_PROPERTY_AGREEMENT, contractAgreement()) + .add(DSPACE_NEGOTIATION_PROPERTY_TIMESTAMP, value) + .build(); + + when(context.transform(any(JsonObject.class), eq(Policy.class))).thenReturn(policy()); + + assertThat(transformer.transform(message, context)).isNull(); + + verify(context, times(2)).reportProblem(anyString()); + } + + private JsonObject contractAgreement() { + return jsonFactory.createObjectBuilder() + .add(JsonLdKeywords.TYPE, ODRL_POLICY_TYPE_AGREEMENT) + .build(); + } + + private Policy policy() { + var action = Action.Builder.newInstance().type("USE").build(); + var permission = Permission.Builder.newInstance().action(action).build(); + var prohibition = Prohibition.Builder.newInstance().action(action).build(); + var duty = Duty.Builder.newInstance().action(action).build(); + return Policy.Builder.newInstance() + .permission(permission) + .prohibition(prohibition) + .duty(duty) + .target("target") + .build(); + } +} \ No newline at end of file diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractAgreementVerificationMessageTransformerTest.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractAgreementVerificationMessageTransformerTest.java new file mode 100644 index 00000000000..4ae5981eed2 --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractAgreementVerificationMessageTransformerTest.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.to; + +import jakarta.json.Json; +import jakarta.json.JsonBuilderFactory; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreementVerificationMessage; +import org.eclipse.edc.jsonld.spi.JsonLdKeywords; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_AGREEMENT_VERIFICATION_MESSAGE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +class JsonObjectToContractAgreementVerificationMessageTransformerTest { + + private final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(Map.of()); + private final TransformerContext context = mock(TransformerContext.class); + + private JsonObjectToContractAgreementVerificationMessageTransformer transformer; + + @BeforeEach + void setUp() { + transformer = new JsonObjectToContractAgreementVerificationMessageTransformer(); + } + + @Test + void transform() { + var value = "example"; + var message = jsonFactory.createObjectBuilder() + .add(JsonLdKeywords.ID, value) + .add(JsonLdKeywords.TYPE, DSPACE_NEGOTIATION_AGREEMENT_VERIFICATION_MESSAGE) + .add(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID, value) + .build(); + + var result = transformer.transform(message, context); + + assertThat(result).isNotNull(); + assertThat(result.getClass()).isEqualTo(ContractAgreementVerificationMessage.class); + assertThat(result.getProtocol()).isNotEmpty(); + assertThat(result.getProcessId()).isEqualTo(value); + + verify(context, never()).reportProblem(anyString()); + } +} \ No newline at end of file diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractNegotiationEventMessageTransformerTest.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractNegotiationEventMessageTransformerTest.java new file mode 100644 index 00000000000..be14488e31d --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractNegotiationEventMessageTransformerTest.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.to; + +import jakarta.json.Json; +import jakarta.json.JsonBuilderFactory; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractNegotiationEventMessage; +import org.eclipse.edc.jsonld.spi.JsonLdKeywords; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_EVENT_MESSAGE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_CHECKSUM; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_ACCEPTED; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +class JsonObjectToContractNegotiationEventMessageTransformerTest { + + private final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(Map.of()); + private final TransformerContext context = mock(TransformerContext.class); + + private JsonObjectToContractNegotiationEventMessageTransformer transformer; + + @BeforeEach + void setUp() { + transformer = new JsonObjectToContractNegotiationEventMessageTransformer(); + } + + @Test + void transform() { + var value = "example"; + var message = jsonFactory.createObjectBuilder() + .add(JsonLdKeywords.ID, value) + .add(JsonLdKeywords.TYPE, DSPACE_NEGOTIATION_EVENT_MESSAGE) + .add(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID, value) + .add(DSPACE_NEGOTIATION_PROPERTY_CHECKSUM, value) + .add(DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE, DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_ACCEPTED) + .build(); + + var result = transformer.transform(message, context); + + assertThat(result).isNotNull(); + assertThat(result.getClass()).isEqualTo(ContractNegotiationEventMessage.class); + assertThat(result.getProtocol()).isNotEmpty(); + assertThat(result.getProcessId()).isEqualTo(value); + assertThat(result.getChecksum()).isEqualTo(value); + assertThat(result.getType()).isEqualTo(ContractNegotiationEventMessage.Type.ACCEPTED); + + verify(context, never()).reportProblem(anyString()); + } +} \ No newline at end of file diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractNegotiationTerminationMessageTransformerTest.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractNegotiationTerminationMessageTransformerTest.java new file mode 100644 index 00000000000..57598ecb3b6 --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractNegotiationTerminationMessageTransformerTest.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.to; + +import jakarta.json.Json; +import jakarta.json.JsonBuilderFactory; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationTerminationMessage; +import org.eclipse.edc.jsonld.spi.JsonLdKeywords; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_CODE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_REASON; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_TERMINATION_MESSAGE; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +class JsonObjectToContractNegotiationTerminationMessageTransformerTest { + + private final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(Map.of()); + private final TransformerContext context = mock(TransformerContext.class); + + private JsonObjectToContractNegotiationTerminationMessageTransformer transformer; + + @BeforeEach + void setUp() { + transformer = new JsonObjectToContractNegotiationTerminationMessageTransformer(); + } + + @Test + void transform() { + var value = "example"; + var reason = Json.createBuilderFactory(Map.of()).createObjectBuilder().add("foo", "bar"); + + var message = jsonFactory.createObjectBuilder() + .add(JsonLdKeywords.ID, value) + .add(JsonLdKeywords.TYPE, DSPACE_NEGOTIATION_TERMINATION_MESSAGE) + .add(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID, value) + .add(DSPACE_NEGOTIATION_PROPERTY_CODE, value) + .add(DSPACE_NEGOTIATION_PROPERTY_REASON, Json.createBuilderFactory(Map.of()).createArrayBuilder().add(reason).build()) + .build(); + + var result = transformer.transform(message, context); + + assertThat(result).isNotNull(); + assertThat(result.getClass()).isEqualTo(ContractNegotiationTerminationMessage.class); + assertThat(result.getProtocol()).isNotNull(); + assertThat(result.getCallbackAddress()).isNull(); + assertThat(result.getProcessId()).isEqualTo(value); + assertThat(result.getRejectionReason()).isNotNull(); + assertThat(result.getRejectionReason()).isEqualTo("{\"foo\":\"bar\"}"); + + verify(context, never()).reportProblem(anyString()); + } +} \ No newline at end of file diff --git a/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractRequestMessageTransformerTest.java b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractRequestMessageTransformerTest.java new file mode 100644 index 00000000000..1c22699a5ac --- /dev/null +++ b/data-protocols/dsp/dsp-negotiation/dsp-negotiation-transform/src/test/java/org/eclipse/edc/protocol/dsp/negotiation/transform/to/JsonObjectToContractRequestMessageTransformerTest.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering + * + * 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 + * + * SPDX-License-Identifier: Apache-2.0 + * + * Contributors: + * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation + * + */ + +package org.eclipse.edc.protocol.dsp.negotiation.transform.to; + +import jakarta.json.Json; +import jakarta.json.JsonBuilderFactory; +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractRequestMessage; +import org.eclipse.edc.connector.contract.spi.types.offer.ContractOffer; +import org.eclipse.edc.jsonld.spi.JsonLdKeywords; +import org.eclipse.edc.policy.model.Action; +import org.eclipse.edc.policy.model.Duty; +import org.eclipse.edc.policy.model.Permission; +import org.eclipse.edc.policy.model.Policy; +import org.eclipse.edc.policy.model.Prohibition; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_POLICY_TYPE_OFFER; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_CONTRACT_REQUEST_MESSAGE; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_CALLBACK_ADDRESS; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_DATASET; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_OFFER; +import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +class JsonObjectToContractRequestMessageTransformerTest { + + private final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(Map.of()); + private final TransformerContext context = mock(TransformerContext.class); + + private JsonObjectToContractRequestMessageTransformer transformer; + + @BeforeEach + void setUp() { + transformer = new JsonObjectToContractRequestMessageTransformer(); + } + + @Test + void transform() { + var value = "example"; + var message = jsonFactory.createObjectBuilder() + .add(JsonLdKeywords.ID, value) + .add(JsonLdKeywords.TYPE, DSPACE_NEGOTIATION_CONTRACT_REQUEST_MESSAGE) + .add(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID, value) + .add(DSPACE_NEGOTIATION_PROPERTY_DATASET, value) + .add(DSPACE_NEGOTIATION_PROPERTY_CALLBACK_ADDRESS, value) + .add(DSPACE_NEGOTIATION_PROPERTY_OFFER, contractOffer()) + .build(); + + when(context.transform(any(JsonObject.class), eq(Policy.class))).thenReturn(policy()); + + var result = transformer.transform(message, context); + + assertThat(result).isNotNull(); + assertThat(result.getClass()).isEqualTo(ContractRequestMessage.class); + assertThat(result.getProtocol()).isNotEmpty(); + assertThat(result.getProcessId()).isEqualTo(value); + assertThat(result.getCallbackAddress()).isEqualTo(value); + assertThat(result.getDataSet()).isEqualTo(value); + assertThat(result.getContractOffer()).isNotNull(); + assertThat(result.getContractOffer().getClass()).isEqualTo(ContractOffer.class); + assertThat(result.getContractOffer().getPolicy()).isNotNull(); + assertThat(result.getContractOffer().getAsset().getId()).isEqualTo("target"); + + verify(context, never()).reportProblem(anyString()); + } + + @Test + void transform_nullPolicy() { + var value = "example"; + var message = jsonFactory.createObjectBuilder() + .add(JsonLdKeywords.ID, value) + .add(JsonLdKeywords.TYPE, DSPACE_NEGOTIATION_CONTRACT_REQUEST_MESSAGE) + .add(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID, value) + .add(DSPACE_NEGOTIATION_PROPERTY_DATASET, value) + .add(DSPACE_NEGOTIATION_PROPERTY_CALLBACK_ADDRESS, value) + .add(DSPACE_NEGOTIATION_PROPERTY_OFFER, contractOffer()) + .build(); + + when(context.transform(any(JsonObject.class), eq(Policy.class))).thenReturn(null); + + assertThat(transformer.transform(message, context)).isNull(); + + verify(context, times(1)).reportProblem(anyString()); + } + + private JsonObject contractOffer() { + return jsonFactory.createObjectBuilder() + .add(JsonLdKeywords.TYPE, ODRL_POLICY_TYPE_OFFER) + .build(); + } + + private Policy policy() { + var action = Action.Builder.newInstance().type("USE").build(); + var permission = Permission.Builder.newInstance().action(action).build(); + var prohibition = Prohibition.Builder.newInstance().action(action).build(); + var duty = Duty.Builder.newInstance().action(action).build(); + return Policy.Builder.newInstance() + .permission(permission) + .prohibition(prohibition) + .duty(duty) + .target("target") + .build(); + } +} \ No newline at end of file diff --git a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/agreement/ContractAgreementMessage.java b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/agreement/ContractAgreementMessage.java index fdf144228e8..a15211e98ec 100644 --- a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/agreement/ContractAgreementMessage.java +++ b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/agreement/ContractAgreementMessage.java @@ -103,7 +103,6 @@ public Builder policy(Policy policy) { public ContractAgreementMessage build() { Objects.requireNonNull(contractAgreementMessage.protocol, "protocol"); - Objects.requireNonNull(contractAgreementMessage.callbackAddress, "callbackAddress"); Objects.requireNonNull(contractAgreementMessage.contractAgreement, "contractAgreement"); Objects.requireNonNull(contractAgreementMessage.processId, "processId"); return contractAgreementMessage; diff --git a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/agreement/ContractNegotiationEventMessage.java b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/agreement/ContractNegotiationEventMessage.java index 8240b0f5fe3..d918553c84e 100644 --- a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/agreement/ContractNegotiationEventMessage.java +++ b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/agreement/ContractNegotiationEventMessage.java @@ -25,6 +25,8 @@ public class ContractNegotiationEventMessage implements ContractRemoteMessage { private String processId; private Type type; + private String checksum; + @Override public String getProtocol() { return protocol; @@ -44,6 +46,10 @@ public Type getType() { return type; } + public String getChecksum() { + return checksum; + } + public static class Builder { private final ContractNegotiationEventMessage message; @@ -75,6 +81,11 @@ public Builder type(Type type) { return this; } + public Builder checksum(String checksum) { + this.message.checksum = checksum; + return this; + } + public ContractNegotiationEventMessage build() { Objects.requireNonNull(message.protocol, "protocol"); Objects.requireNonNull(message.processId, "processId"); diff --git a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractNegotiation.java b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractNegotiation.java index 3e552166cc4..162f3271138 100644 --- a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractNegotiation.java +++ b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractNegotiation.java @@ -66,6 +66,7 @@ public class ContractNegotiation extends StatefulEntity { private String correlationId; private String counterPartyId; private String counterPartyAddress; + private String checksum; private String protocol; private Type type = CONSUMER; private ContractAgreement contractAgreement; @@ -83,6 +84,10 @@ public String getCounterPartyAddress() { return counterPartyAddress; } + public String getChecksum() { + return checksum; + } + /** * Returns the correlation id sent by the client or null if this is a client-side negotiation. */ @@ -416,6 +421,11 @@ public Builder counterPartyAddress(String address) { return this; } + public Builder checksum(String checksum) { + entity.checksum = checksum; + return this; + } + public Builder correlationId(String id) { entity.correlationId = id; return this; diff --git a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractNegotiationTerminationMessage.java b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractNegotiationTerminationMessage.java index 46e084ac165..e63ca048642 100644 --- a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractNegotiationTerminationMessage.java +++ b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/negotiation/ContractNegotiationTerminationMessage.java @@ -26,6 +26,7 @@ public class ContractNegotiationTerminationMessage implements ContractRemoteMess private String callbackAddress; private String processId; private String rejectionReason; // TODO change to list https://github.com/eclipse-edc/Connector/issues/2729 + private String code; @Override public String getProtocol() { @@ -51,6 +52,10 @@ public String getRejectionReason() { return rejectionReason; } + public String getCode() { + return code; + } + public static class Builder { private final ContractNegotiationTerminationMessage contractNegotiationTerminationMessage; @@ -88,10 +93,14 @@ public Builder rejectionReason(String rejectionReason) { return this; } + public Builder code(String code) { + this.contractNegotiationTerminationMessage.code = code; + return this; + } + public ContractNegotiationTerminationMessage build() { Objects.requireNonNull(contractNegotiationTerminationMessage.protocol, "protocol"); Objects.requireNonNull(contractNegotiationTerminationMessage.processId, "processId"); - Objects.requireNonNull(contractNegotiationTerminationMessage.rejectionReason, "rejectionReason"); return contractNegotiationTerminationMessage; } } diff --git a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/offer/ContractOffer.java b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/offer/ContractOffer.java index ff6023b93a9..d92427e17f3 100644 --- a/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/offer/ContractOffer.java +++ b/spi/control-plane/contract-spi/src/main/java/org/eclipse/edc/connector/contract/spi/types/offer/ContractOffer.java @@ -61,11 +61,17 @@ public class ContractOffer { private ZonedDateTime offerEnd; /** * Timestamp defining the start date when the contract becomes effective + * + * @deprecated replaced with policy implementation */ + @Deprecated(forRemoval = true) private ZonedDateTime contractStart; /** * Timestamp defining the end date when the contract becomes terminated + * + * @deprecated replaced with policy implementation */ + @Deprecated(forRemoval = true) private ZonedDateTime contractEnd; @@ -94,11 +100,13 @@ public ZonedDateTime getOfferEnd() { return offerEnd; } + @Deprecated @NotNull public ZonedDateTime getContractStart() { return contractStart; } + @Deprecated @NotNull public ZonedDateTime getContractEnd() { return contractEnd; @@ -177,11 +185,13 @@ public Builder offerEnd(ZonedDateTime date) { return this; } + @Deprecated public Builder contractStart(ZonedDateTime date) { contractOffer.contractStart = date; return this; } + @Deprecated public Builder contractEnd(ZonedDateTime date) { contractOffer.contractEnd = date; return this; @@ -196,8 +206,6 @@ public ContractOffer build() { Objects.requireNonNull(contractOffer.id); Objects.requireNonNull(contractOffer.asset, "Asset must not be null"); Objects.requireNonNull(contractOffer.policy, "Policy must not be null"); - Objects.requireNonNull(contractOffer.contractStart, "Contract start must not be null"); - Objects.requireNonNull(contractOffer.contractEnd, "Contract end must not be null"); return contractOffer; } } diff --git a/spi/control-plane/contract-spi/src/test/java/org/eclipse/edc/connector/contract/spi/types/offer/ContractOfferTest.java b/spi/control-plane/contract-spi/src/test/java/org/eclipse/edc/connector/contract/spi/types/offer/ContractOfferTest.java index 5d33564e790..e88b109bf28 100644 --- a/spi/control-plane/contract-spi/src/test/java/org/eclipse/edc/connector/contract/spi/types/offer/ContractOfferTest.java +++ b/spi/control-plane/contract-spi/src/test/java/org/eclipse/edc/connector/contract/spi/types/offer/ContractOfferTest.java @@ -50,26 +50,4 @@ void verifyAssetNotNull() { .isInstanceOf(NullPointerException.class) .hasMessage("Asset must not be null"); } - - @Test - void verifyContractStartNotNull() { - assertThatThrownBy(() -> ContractOffer.Builder.newInstance().id("some-id") - .asset(Asset.Builder.newInstance().id("test-assetId").build()) - .policy(Policy.Builder.newInstance().build()) - .contractEnd(ZonedDateTime.now().plusMonths(1)) - .build()) - .isInstanceOf(NullPointerException.class) - .hasMessage("Contract start must not be null"); - } - - @Test - void verifyContractEndNotNull() { - assertThatThrownBy(() -> ContractOffer.Builder.newInstance().id("some-id") - .asset(Asset.Builder.newInstance().id("test-assetId").build()) - .policy(Policy.Builder.newInstance().build()) - .contractStart(ZonedDateTime.now()) - .build()) - .isInstanceOf(NullPointerException.class) - .hasMessage("Contract end must not be null"); - } }