diff --git a/extensions/control-plane/api/management-api/management-api-test-fixtures/src/testFixtures/java/org/eclipse/edc/connector/controlplane/test/system/utils/Participant.java b/extensions/control-plane/api/management-api/management-api-test-fixtures/src/testFixtures/java/org/eclipse/edc/connector/controlplane/test/system/utils/Participant.java index f7f336ecb9..d05c6e59bd 100644 --- a/extensions/control-plane/api/management-api/management-api-test-fixtures/src/testFixtures/java/org/eclipse/edc/connector/controlplane/test/system/utils/Participant.java +++ b/extensions/control-plane/api/management-api/management-api-test-fixtures/src/testFixtures/java/org/eclipse/edc/connector/controlplane/test/system/utils/Participant.java @@ -23,6 +23,7 @@ import org.eclipse.edc.connector.controlplane.catalog.spi.Dataset; import org.eclipse.edc.connector.controlplane.contract.spi.types.offer.ContractDefinition; import org.eclipse.edc.connector.controlplane.policy.spi.PolicyDefinition; +import org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcessStates; import org.eclipse.edc.jsonld.TitaniumJsonLd; import org.eclipse.edc.jsonld.spi.JsonLd; import org.eclipse.edc.jsonld.util.JacksonJsonLd; @@ -498,6 +499,10 @@ public String getContractNegotiationState(String id) { return getContractNegotiationField(id, "state"); } + public void awaitTransferToBeInState(String transferProcessId, TransferProcessStates state) { + await().atMost(timeout).until(() -> getTransferProcessState(transferProcessId), it -> Objects.equals(it, state.name())); + } + protected String getContractNegotiationField(String negotiationId, String fieldName) { return managementEndpoint.baseRequest() .contentType(JSON) diff --git a/spi/control-plane/transfer-spi/src/test/java/org/eclipse/edc/connector/controlplane/transfer/spi/types/TransferProcessTest.java b/spi/control-plane/transfer-spi/src/test/java/org/eclipse/edc/connector/controlplane/transfer/spi/types/TransferProcessTest.java index 7fb191ca0c..66388ff9bc 100644 --- a/spi/control-plane/transfer-spi/src/test/java/org/eclipse/edc/connector/controlplane/transfer/spi/types/TransferProcessTest.java +++ b/spi/control-plane/transfer-spi/src/test/java/org/eclipse/edc/connector/controlplane/transfer/spi/types/TransferProcessTest.java @@ -20,7 +20,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; -import org.junit.jupiter.params.provider.ValueSource; import java.io.IOException; import java.io.StringWriter; @@ -32,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcess.Type.CONSUMER; +import static org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcessStates.STARTED; import static org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcessStates.TERMINATING; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -87,9 +87,8 @@ void verifyCopy() { assertThat(process).usingRecursiveComparison().isEqualTo(copy); } - @ParameterizedTest - @ValueSource(strings = { "STARTED", "SUSPENDED"}) - void verifyConsumerTransitions(String state) { + @Test + void verifyConsumerTransitions() { var process = TransferProcess.Builder.newInstance().id(UUID.randomUUID().toString()).type(CONSUMER).build(); process.transitionProvisioning(ResourceManifest.Builder.newInstance().build()); @@ -100,24 +99,31 @@ void verifyConsumerTransitions(String state) { assertThrows(IllegalStateException.class, process::transitionStarting, "STARTING is not a valid state for consumer"); process.transitionStarted("dataPlaneId"); - // should not set the data plane id - assertThat(process.getDataPlaneId()).isNull(); - switch (state) { - case "STARTED": - process.transitionCompleting(); - process.transitionCompleted(); - - process.transitionDeprovisioning(); - process.transitionDeprovisioned(); - break; - case "SUSPENDED": - process.transitionSuspending("suspension"); - process.transitionSuspended(); - break; - default: - throw new IllegalArgumentException("Unsupported state: " + state); - } + process.transitionSuspending("suspension"); + process.transitionSuspended(); + + process.transitionStarted("dataPlaneId"); + + process.transitionCompleting(); + process.transitionCompleted(); + + process.transitionDeprovisioning(); + process.transitionDeprovisioned(); + } + + @ParameterizedTest + @EnumSource(value = TransferProcessStates.class, mode = INCLUDE, names = { "STARTING", "SUSPENDED" }) + void shouldNotSetDataPlaneIdOnStart_whenTransferIsConsumer(TransferProcessStates fromState) { + var process = TransferProcess.Builder.newInstance() + .id(UUID.randomUUID().toString()).type(CONSUMER) + .state(fromState.code()) + .build(); + + process.transitionStarted("dataPlaneId"); + + assertThat(process.stateAsString()).isEqualTo(STARTED.name()); + assertThat(process.getDataPlaneId()).isNull(); } @Test diff --git a/system-tests/e2e-transfer-test/runner/src/test/java/org/eclipse/edc/test/e2e/TransferEndToEndParticipant.java b/system-tests/e2e-transfer-test/runner/src/test/java/org/eclipse/edc/test/e2e/TransferEndToEndParticipant.java index 096281bd54..1631449066 100644 --- a/system-tests/e2e-transfer-test/runner/src/test/java/org/eclipse/edc/test/e2e/TransferEndToEndParticipant.java +++ b/system-tests/e2e-transfer-test/runner/src/test/java/org/eclipse/edc/test/e2e/TransferEndToEndParticipant.java @@ -17,20 +17,17 @@ import io.restassured.common.mapper.TypeRef; import org.assertj.core.api.ThrowingConsumer; import org.eclipse.edc.connector.controlplane.test.system.utils.Participant; -import org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcessStates; import org.eclipse.edc.spi.types.domain.DataAddress; import org.jetbrains.annotations.NotNull; import java.net.URI; import java.util.HashMap; import java.util.Map; -import java.util.Objects; import static io.restassured.RestAssured.given; import static io.restassured.http.ContentType.JSON; import static java.io.File.separator; import static org.assertj.core.api.Assertions.assertThat; -import static org.awaitility.Awaitility.await; import static org.eclipse.edc.boot.BootServicesExtension.PARTICIPANT_ID; import static org.eclipse.edc.sql.testfixtures.PostgresqlEndToEndInstance.defaultDatasourceConfiguration; import static org.eclipse.edc.util.io.Ports.getFreePort; @@ -175,10 +172,6 @@ public void pullData(DataAddress edr, Map queryParams, ThrowingC assertThat(data).satisfies(bodyAssertion); } - protected void awaitTransferToBeInState(String transferProcessId, TransferProcessStates state) { - await().atMost(timeout).until(() -> getTransferProcessState(transferProcessId), it -> Objects.equals(it, state.name())); - } - @NotNull private String resourceAbsolutePath(String filename) { return System.getProperty("user.dir") + separator + "build" + separator + "resources" + separator + "test" + separator + filename;