From 7185d0cb91bab0113243ba6aa9721d9584284c85 Mon Sep 17 00:00:00 2001 From: Jan Peter Meyer <102802985+janpmeyer@users.noreply.github.com> Date: Mon, 8 May 2023 16:36:05 +0200 Subject: [PATCH] feat: add dataAddress, code and reason fields to Transfer-Process-Transformer (#2812) * chore(dsp-transfer-process-transform): add code and reason field to transformer * chore(dsp-transfer-process-transform): add data Address to TransferTermination[to|from]Transformer * chore(dsp-transfer-process-transform): fix unit Test Bug * chore(dsp-transfer-process-transform): remove duplicated JsonObjectToDataAddressTransformer.java * chore(dsp-transfer-process-transform): refactor if clauses * chore(dsp-transfer-process-transform): refactor tests * chore(dsp-transfer-process-transform): refactor tests --- ...spTransferProcessPropertyAndTypeNames.java | 4 ++ ...ctFromTransferStartMessageTransformer.java | 6 ++- ...TransferTerminationMessageTransformer.java | 10 +++- ...jectToTransferStartMessageTransformer.java | 7 ++- ...TransferTerminationMessageTransformer.java | 18 ++++++- ...sferTerminationMessageTransformerTest.java | 7 ++- ...ToTransferStartMessageTransformerTest.java | 54 ++++++++++++++++++- ...sferTerminationMessageTransformerTest.java | 17 ++++-- .../protocol/TransferTerminationMessage.java | 1 + 9 files changed, 112 insertions(+), 12 deletions(-) diff --git a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/DspTransferProcessPropertyAndTypeNames.java b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/DspTransferProcessPropertyAndTypeNames.java index b7883247da7..05011356e52 100644 --- a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/DspTransferProcessPropertyAndTypeNames.java +++ b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/DspTransferProcessPropertyAndTypeNames.java @@ -44,4 +44,8 @@ public interface DspTransferProcessPropertyAndTypeNames { String DSPACE_CORRELATIONID_TYPE = DSPACE_SCHEMA + "correlationId"; String DSPACE_STATE_TYPE = DSPACE_SCHEMA + "state"; + + String DSPACE_REASON_TYPE = DSPACE_SCHEMA + "reason"; + + String DSPACE_CODE_TYPE = DSPACE_SCHEMA + "code"; } diff --git a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/type/from/JsonObjectFromTransferStartMessageTransformer.java b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/type/from/JsonObjectFromTransferStartMessageTransformer.java index ba836a8b48e..4c0ce74b829 100644 --- a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/type/from/JsonObjectFromTransferStartMessageTransformer.java +++ b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/type/from/JsonObjectFromTransferStartMessageTransformer.java @@ -26,6 +26,7 @@ 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.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_DATAADDRESS_TYPE; import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_PROCESSID_TYPE; import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFER_START_TYPE; @@ -45,8 +46,9 @@ public JsonObjectFromTransferStartMessageTransformer(JsonBuilderFactory jsonBuil builder.add(ID, UUID.randomUUID().toString()); builder.add(TYPE, DSPACE_TRANSFER_START_TYPE); builder.add(DSPACE_PROCESSID_TYPE, transferStartMessage.getProcessId()); - - //TODO ADD missing fields dataAddress from spec issue https://github.com/eclipse-edc/Connector/issues/2727 + if (transferStartMessage.getDataAddress() != null) { + builder.add(DSPACE_DATAADDRESS_TYPE, context.transform(transferStartMessage, JsonObject.class)); + } return builder.build(); } diff --git a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/type/from/JsonObjectFromTransferTerminationMessageTransformer.java b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/type/from/JsonObjectFromTransferTerminationMessageTransformer.java index df373bcdd61..8778b9f6cd6 100644 --- a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/type/from/JsonObjectFromTransferTerminationMessageTransformer.java +++ b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/type/from/JsonObjectFromTransferTerminationMessageTransformer.java @@ -26,7 +26,9 @@ 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.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_CODE_TYPE; import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_PROCESSID_TYPE; +import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_REASON_TYPE; import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFER_TERMINATION_TYPE; public class JsonObjectFromTransferTerminationMessageTransformer extends AbstractJsonLdTransformer { @@ -45,8 +47,12 @@ public JsonObjectFromTransferTerminationMessageTransformer(JsonBuilderFactory js builder.add(ID, String.valueOf(UUID.randomUUID())); builder.add(TYPE, DSPACE_TRANSFER_TERMINATION_TYPE); builder.add(DSPACE_PROCESSID_TYPE, transferTerminationMessage.getProcessId()); - - //TODO Add field when Message is evolved (code, reason) issue https://github.com/eclipse-edc/Connector/issues/2764 + if (transferTerminationMessage.getCode() != null) { + builder.add(DSPACE_CODE_TYPE, transferTerminationMessage.getCode()); + } + if (transferTerminationMessage.getReason() != null) { + builder.add(DSPACE_REASON_TYPE, transferTerminationMessage.getReason()); + } return builder.build(); diff --git a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/type/to/JsonObjectToTransferStartMessageTransformer.java b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/type/to/JsonObjectToTransferStartMessageTransformer.java index 08c7ba27cf0..627c73cf24b 100644 --- a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/type/to/JsonObjectToTransferStartMessageTransformer.java +++ b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/type/to/JsonObjectToTransferStartMessageTransformer.java @@ -18,10 +18,12 @@ import org.eclipse.edc.connector.transfer.spi.types.protocol.TransferStartMessage; import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; import org.eclipse.edc.protocol.dsp.spi.types.HttpMessageProtocol; +import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.transform.spi.TransformerContext; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_DATAADDRESS_TYPE; import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_PROCESSID_TYPE; public class JsonObjectToTransferStartMessageTransformer extends AbstractJsonLdTransformer { @@ -37,7 +39,10 @@ public JsonObjectToTransferStartMessageTransformer() { transferStartMessageBuilder.protocol(HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP); transformString(jsonObject.get(DSPACE_PROCESSID_TYPE), transferStartMessageBuilder::processId, context); - //TODO ADD missing fields dataAddress from spec issue https://github.com/eclipse-edc/Connector/issues/2727 + + if (jsonObject.containsKey(DSPACE_DATAADDRESS_TYPE) && !jsonObject.get(DSPACE_DATAADDRESS_TYPE).asJsonObject().isEmpty()) { + transferStartMessageBuilder.dataAddress(context.transform(jsonObject.get(DSPACE_DATAADDRESS_TYPE), DataAddress.class)); + } return transferStartMessageBuilder.build(); } diff --git a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/type/to/JsonObjectToTransferTerminationMessageTransformer.java b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/type/to/JsonObjectToTransferTerminationMessageTransformer.java index cd64c9d1838..fedd5651df1 100644 --- a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/type/to/JsonObjectToTransferTerminationMessageTransformer.java +++ b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/type/to/JsonObjectToTransferTerminationMessageTransformer.java @@ -22,7 +22,10 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import static java.lang.String.format; +import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_CODE_TYPE; import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_PROCESSID_TYPE; +import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_REASON_TYPE; public class JsonObjectToTransferTerminationMessageTransformer extends AbstractJsonLdTransformer { @@ -37,7 +40,20 @@ public JsonObjectToTransferTerminationMessageTransformer() { transferTerminationMessageBuilder.protocol(HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP); transformString(jsonObject.get(DSPACE_PROCESSID_TYPE), transferTerminationMessageBuilder::processId, context); - //TODO ADD missing fields (code, reason) from spec issue https://github.com/eclipse-edc/Connector/issues/2764 + + if (jsonObject.containsKey(DSPACE_CODE_TYPE)) { + transformString(jsonObject.get(DSPACE_CODE_TYPE), transferTerminationMessageBuilder::code, context); + } + + var reasons = jsonObject.get(DSPACE_REASON_TYPE); + if (reasons != null) { + var result = typeValueArray(reasons, context); + if (result == null) { + context.reportProblem(format("Cannot transform property %s in ContractNegotiationTerminationMessage", DSPACE_REASON_TYPE)); + } else if (result.size() > 0) { + transferTerminationMessageBuilder.reason(String.valueOf(result.get(0))); + } + } return transferTerminationMessageBuilder.build(); diff --git a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/test/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/from/JsonObjectFromTransferTerminationMessageTransformerTest.java b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/test/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/from/JsonObjectFromTransferTerminationMessageTransformerTest.java index c41e6beba04..d7bbc9b8f6f 100644 --- a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/test/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/from/JsonObjectFromTransferTerminationMessageTransformerTest.java +++ b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/test/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/from/JsonObjectFromTransferTerminationMessageTransformerTest.java @@ -26,7 +26,9 @@ import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_CODE_TYPE; import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_PROCESSID_TYPE; +import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_REASON_TYPE; import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFER_TERMINATION_TYPE; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; @@ -51,6 +53,8 @@ void transformTransferTerminationMessage() { var message = TransferTerminationMessage.Builder.newInstance() .processId("TestID") .protocol("dsp") + .code("testCode") + .reason("testReason") .build(); var result = transformer.transform(message, context); @@ -58,7 +62,8 @@ void transformTransferTerminationMessage() { assertThat(result).isNotNull(); assertThat(result.getJsonString(JsonLdKeywords.TYPE).getString()).isEqualTo(DSPACE_TRANSFER_TERMINATION_TYPE); assertThat(result.getJsonString(DSPACE_PROCESSID_TYPE).getString()).isEqualTo("TestID"); - //TODO Add missing fields (code, reason) from Spec issue https://github.com/eclipse-edc/Connector/issues/2764 + assertThat(result.getJsonString(DSPACE_CODE_TYPE).getString()).isEqualTo("testCode"); + assertThat(result.getJsonString(DSPACE_REASON_TYPE).getString()).isEqualTo("testReason"); verify(context, never()).reportProblem(anyString()); } diff --git a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/test/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/to/JsonObjectToTransferStartMessageTransformerTest.java b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/test/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/to/JsonObjectToTransferStartMessageTransformerTest.java index c99d3ce2520..03fdb8c2f72 100644 --- a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/test/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/to/JsonObjectToTransferStartMessageTransformerTest.java +++ b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/test/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/to/JsonObjectToTransferStartMessageTransformerTest.java @@ -15,8 +15,10 @@ package org.eclipse.edc.protocol.dsp.transferprocess.transformer.to; import jakarta.json.Json; +import jakarta.json.JsonObject; import org.eclipse.edc.protocol.dsp.spi.types.HttpMessageProtocol; import org.eclipse.edc.protocol.dsp.transferprocess.transformer.type.to.JsonObjectToTransferStartMessageTransformer; +import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.transform.spi.TransformerContext; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -24,13 +26,17 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.CONTEXT; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; +import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_DATAADDRESS_TYPE; import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_PROCESSID_TYPE; import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_SCHEMA; import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFER_START_TYPE; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; class JsonObjectToTransferStartMessageTransformerTest { @@ -47,12 +53,57 @@ void setUp() { @Test void jsonObjectToTransferStartMessage() { - //TODO Add missing DataAddress from Spec Issue https://github.com/eclipse-edc/Connector/issues/2727 + var json = Json.createObjectBuilder() + .add(CONTEXT, DSPACE_SCHEMA) + .add(TYPE, DSPACE_TRANSFER_START_TYPE) + .add(DSPACE_PROCESSID_TYPE, processId) + .build(); + + var result = transformer.transform(json, context); + + assertThat(result).isNotNull(); + assertThat(result.getProcessId()).isEqualTo(processId); + assertThat(result.getProtocol()).isEqualTo(HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP); + + verify(context, never()).reportProblem(anyString()); + } + + @Test + void jsonObjectToTransferStartMessageWithDataAddress() { + var json = Json.createObjectBuilder() + .add(CONTEXT, DSPACE_SCHEMA) + .add(TYPE, DSPACE_TRANSFER_START_TYPE) + .add(DSPACE_PROCESSID_TYPE, processId) + .add(DSPACE_DATAADDRESS_TYPE, Json.createObjectBuilder() + .add("type", "AWS") + .build()) + .build(); + + var dataAddress = DataAddress.Builder.newInstance() + .type("AWS") + .build(); + when(context.transform(isA(JsonObject.class), eq(DataAddress.class))).thenReturn(dataAddress); + + var result = transformer.transform(json, context); + + assertThat(result).isNotNull(); + + assertThat(result.getProcessId()).isEqualTo(processId); + assertThat(result.getProtocol()).isEqualTo(HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP); + assertThat(result.getDataAddress()).isSameAs(dataAddress); + + verify(context, never()).reportProblem(anyString()); + } + + @Test + void jsonObjectToTransferStartMessageWithEmptyDataAddress() { var json = Json.createObjectBuilder() .add(CONTEXT, DSPACE_SCHEMA) .add(TYPE, DSPACE_TRANSFER_START_TYPE) .add(DSPACE_PROCESSID_TYPE, processId) + .add(DSPACE_DATAADDRESS_TYPE, Json.createObjectBuilder() + .build()) .build(); var result = transformer.transform(json, context); @@ -61,6 +112,7 @@ void jsonObjectToTransferStartMessage() { assertThat(result.getProcessId()).isEqualTo(processId); assertThat(result.getProtocol()).isEqualTo(HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP); + assertThat(result.getDataAddress()).isNull(); verify(context, never()).reportProblem(anyString()); } diff --git a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/test/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/to/JsonObjectToTransferTerminationMessageTransformerTest.java b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/test/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/to/JsonObjectToTransferTerminationMessageTransformerTest.java index bdb3ba0f5d4..db4c3b8d01b 100644 --- a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/test/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/to/JsonObjectToTransferTerminationMessageTransformerTest.java +++ b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/test/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/to/JsonObjectToTransferTerminationMessageTransformerTest.java @@ -21,10 +21,14 @@ 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.CONTEXT; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; +import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_CODE_TYPE; import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_PROCESSID_TYPE; +import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_REASON_TYPE; import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_SCHEMA; import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFER_TERMINATION_TYPE; import static org.mockito.ArgumentMatchers.anyString; @@ -36,6 +40,8 @@ class JsonObjectToTransferTerminationMessageTransformerTest { private final String processId = "TestProcessId"; + private final String code = "testCode"; + private TransformerContext context = mock(TransformerContext.class); private JsonObjectToTransferTerminationMessageTransformer transformer; @@ -47,21 +53,24 @@ void setUp() { @Test void jsonObjectToTransferTerminationMessage() { - - //TODO Add missing (code,reason) attributes from Spec issue https://github.com/eclipse-edc/Connector/issues/2764 + var reason = Json.createBuilderFactory(Map.of()).createObjectBuilder().add("foo", "bar"); var json = Json.createObjectBuilder() .add(CONTEXT, DSPACE_SCHEMA) .add(TYPE, DSPACE_TRANSFER_TERMINATION_TYPE) - .add(DSPACE_PROCESSID_TYPE, processId) + .add(DSPACE_PROCESSID_TYPE, "TestProcessId") + .add(DSPACE_CODE_TYPE, "testCode") + .add(DSPACE_REASON_TYPE, Json.createBuilderFactory(Map.of()).createArrayBuilder().add(reason).build()) .build(); var result = transformer.transform(json, context); assertThat(result).isNotNull(); - assertThat(result.getProcessId()).isEqualTo(processId); + assertThat(result.getProcessId()).isEqualTo("TestProcessId"); assertThat(result.getProtocol()).isEqualTo(HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP); + assertThat(result.getReason()).isEqualTo("{\"foo\":\"bar\"}"); + assertThat(result.getCode()).isEqualTo("testCode"); verify(context, never()).reportProblem(anyString()); } diff --git a/spi/control-plane/transfer-spi/src/main/java/org/eclipse/edc/connector/transfer/spi/types/protocol/TransferTerminationMessage.java b/spi/control-plane/transfer-spi/src/main/java/org/eclipse/edc/connector/transfer/spi/types/protocol/TransferTerminationMessage.java index 340ef7e174e..d0a7070dd4f 100644 --- a/spi/control-plane/transfer-spi/src/main/java/org/eclipse/edc/connector/transfer/spi/types/protocol/TransferTerminationMessage.java +++ b/spi/control-plane/transfer-spi/src/main/java/org/eclipse/edc/connector/transfer/spi/types/protocol/TransferTerminationMessage.java @@ -98,6 +98,7 @@ public Builder reason(String reason) { public TransferTerminationMessage build() { Objects.requireNonNull(message.protocol, "The protocol must be specified"); Objects.requireNonNull(message.processId, "The processId must be specified"); + //TODO add Nullcheck for message.code Issue https://github.com/eclipse-edc/Connector/issues/2810 return message; } }