diff --git a/extensions/common/http/jersey-core/src/testFixtures/java/org/eclipse/edc/web/jersey/testfixtures/RestControllerTestBase.java b/extensions/common/http/jersey-core/src/testFixtures/java/org/eclipse/edc/web/jersey/testfixtures/RestControllerTestBase.java index e902864dc7f..692f4ea47e7 100644 --- a/extensions/common/http/jersey-core/src/testFixtures/java/org/eclipse/edc/web/jersey/testfixtures/RestControllerTestBase.java +++ b/extensions/common/http/jersey-core/src/testFixtures/java/org/eclipse/edc/web/jersey/testfixtures/RestControllerTestBase.java @@ -34,7 +34,7 @@ * Base utility class that permits to test Rest controllers deploying a bare bone instance of Jetty * with Jersey. The controller returned by the {@link #controller()} method gets registered on a test api context. */ -public abstract class RestControllerTestBase { // TODO: can it be started once for class? +public abstract class RestControllerTestBase { protected final int port = getFreePort(); protected final Monitor monitor = mock(Monitor.class); diff --git a/extensions/data-plane-selector/data-plane-selector-client/build.gradle.kts b/extensions/data-plane-selector/data-plane-selector-client/build.gradle.kts index ce73feb14b3..b50d587662f 100644 --- a/extensions/data-plane-selector/data-plane-selector-client/build.gradle.kts +++ b/extensions/data-plane-selector/data-plane-selector-client/build.gradle.kts @@ -25,14 +25,6 @@ dependencies { implementation(project(":extensions:common:json-ld")) testImplementation(project(":core:common:junit")) - testImplementation(project(":extensions:common:api:api-core")) - testImplementation(project(":extensions:common:http")) - testImplementation(project(":extensions:common:http:lib:jersey-providers-lib")) - testImplementation(project(":extensions:data-plane-selector:data-plane-selector-api")) - testImplementation(project(":extensions:data-plane-selector:data-plane-selector-control-api")) - - testImplementation(testFixtures(project(":core:common:lib:http-lib"))) - testImplementation(testFixtures(project(":extensions:common:http:jersey-core"))) } diff --git a/extensions/data-plane-selector/data-plane-selector-client/src/main/java/org/eclipse/edc/connector/dataplane/selector/DataPlaneSelectorClientExtension.java b/extensions/data-plane-selector/data-plane-selector-client/src/main/java/org/eclipse/edc/connector/dataplane/selector/DataPlaneSelectorClientExtension.java index efa2fdf58ed..cd396708296 100644 --- a/extensions/data-plane-selector/data-plane-selector-client/src/main/java/org/eclipse/edc/connector/dataplane/selector/DataPlaneSelectorClientExtension.java +++ b/extensions/data-plane-selector/data-plane-selector-client/src/main/java/org/eclipse/edc/connector/dataplane/selector/DataPlaneSelectorClientExtension.java @@ -17,6 +17,7 @@ import jakarta.json.Json; import org.eclipse.edc.connector.dataplane.selector.spi.DataPlaneSelectorService; import org.eclipse.edc.http.spi.ControlApiHttpClient; +import org.eclipse.edc.jsonld.spi.JsonLd; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; import org.eclipse.edc.runtime.metamodel.annotation.Provider; @@ -25,7 +26,11 @@ import org.eclipse.edc.spi.system.ServiceExtensionContext; import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; +import org.eclipse.edc.transform.transformer.edc.from.JsonObjectFromDataAddressTransformer; import org.eclipse.edc.transform.transformer.edc.from.JsonObjectFromDataPlaneInstanceTransformer; +import org.eclipse.edc.transform.transformer.edc.to.JsonObjectToDataAddressTransformer; +import org.eclipse.edc.transform.transformer.edc.to.JsonObjectToDataPlaneInstanceTransformer; +import org.eclipse.edc.transform.transformer.edc.to.JsonValueToGenericTypeTransformer; import static java.util.Collections.emptyMap; import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; @@ -50,6 +55,9 @@ public class DataPlaneSelectorClientExtension implements ServiceExtension { @Inject private TypeTransformerRegistry typeTransformerRegistry; + @Inject + private JsonLd jsonLd; + @Override public String name() { return NAME; @@ -60,6 +68,10 @@ public void initialize(ServiceExtensionContext context) { var builderFactory = Json.createBuilderFactory(emptyMap()); var objectMapper = typeManager.getMapper(JSON_LD); typeTransformerRegistry.register(new JsonObjectFromDataPlaneInstanceTransformer(builderFactory, objectMapper)); + typeTransformerRegistry.register(new JsonObjectFromDataAddressTransformer(builderFactory)); + typeTransformerRegistry.register(new JsonObjectToDataPlaneInstanceTransformer()); + typeTransformerRegistry.register(new JsonObjectToDataAddressTransformer()); + typeTransformerRegistry.register(new JsonValueToGenericTypeTransformer(objectMapper)); } @Provider @@ -67,7 +79,7 @@ public DataPlaneSelectorService dataPlaneSelectorService(ServiceExtensionContext var config = context.getConfig(); var url = config.getString(DPF_SELECTOR_URL_SETTING); var selectionStrategy = config.getString(DPF_SELECTOR_STRATEGY, DataPlaneSelectorService.DEFAULT_STRATEGY); - return new RemoteDataPlaneSelectorService(httpClient, url, typeManager.getMapper(), typeTransformerRegistry, - selectionStrategy); + return new RemoteDataPlaneSelectorService(httpClient, url, typeManager.getMapper(JSON_LD), typeTransformerRegistry, + selectionStrategy, jsonLd); } } diff --git a/extensions/data-plane-selector/data-plane-selector-client/src/main/java/org/eclipse/edc/connector/dataplane/selector/RemoteDataPlaneSelectorService.java b/extensions/data-plane-selector/data-plane-selector-client/src/main/java/org/eclipse/edc/connector/dataplane/selector/RemoteDataPlaneSelectorService.java index 89ccbcbbe6e..00e83af70fe 100644 --- a/extensions/data-plane-selector/data-plane-selector-client/src/main/java/org/eclipse/edc/connector/dataplane/selector/RemoteDataPlaneSelectorService.java +++ b/extensions/data-plane-selector/data-plane-selector-client/src/main/java/org/eclipse/edc/connector/dataplane/selector/RemoteDataPlaneSelectorService.java @@ -19,12 +19,14 @@ import jakarta.json.Json; import jakarta.json.JsonArray; import jakarta.json.JsonObject; +import jakarta.json.JsonValue; import okhttp3.MediaType; import okhttp3.Request; import okhttp3.RequestBody; import org.eclipse.edc.connector.dataplane.selector.spi.DataPlaneSelectorService; import org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance; import org.eclipse.edc.http.spi.ControlApiHttpClient; +import org.eclipse.edc.jsonld.spi.JsonLd; import org.eclipse.edc.spi.EdcException; import org.eclipse.edc.spi.result.Result; import org.eclipse.edc.spi.result.ServiceResult; @@ -52,14 +54,17 @@ public class RemoteDataPlaneSelectorService implements DataPlaneSelectorService private final ObjectMapper mapper; private final TypeTransformerRegistry typeTransformerRegistry; private final String selectionStrategy; + private final JsonLd jsonLd; public RemoteDataPlaneSelectorService(ControlApiHttpClient controlClient, String url, ObjectMapper mapper, - TypeTransformerRegistry typeTransformerRegistry, String selectionStrategy) { + TypeTransformerRegistry typeTransformerRegistry, String selectionStrategy, + JsonLd jsonLd) { this.httpClient = controlClient; this.url = url; this.mapper = mapper; this.typeTransformerRegistry = typeTransformerRegistry; this.selectionStrategy = selectionStrategy; + this.jsonLd = jsonLd; } @Override @@ -69,7 +74,8 @@ public ServiceResult> getAll() { return httpClient.request(requestBuilder) .compose(this::toJsonArray) .map(it -> it.stream() - .map(j -> typeTransformerRegistry.transform(j, DataPlaneInstance.class)) + .map(JsonValue::asJsonObject) + .map(jo -> jsonLd.expand(jo).compose(joo -> typeTransformerRegistry.transform(joo, DataPlaneInstance.class))) .filter(Result::succeeded) .map(Result::getContent) .toList() @@ -92,6 +98,7 @@ public ServiceResult select(DataAddress source, String transf var requestBuilder = new Request.Builder().post(body).url(url + SELECT_PATH); return httpClient.request(requestBuilder).compose(this::toJsonObject) + .compose(it -> jsonLd.expand(it).flatMap(ServiceResult::from)) .map(it -> typeTransformerRegistry.transform(it, DataPlaneInstance.class)) .compose(ServiceResult::from); } @@ -132,6 +139,7 @@ public ServiceResult findById(String id) { var requestBuilder = new Request.Builder().get().url(url + "/" + id); return httpClient.request(requestBuilder).compose(this::toJsonObject) + .compose(it -> jsonLd.expand(it).flatMap(ServiceResult::from)) .map(it -> typeTransformerRegistry.transform(it, DataPlaneInstance.class).getContent()); } @@ -151,5 +159,4 @@ private ServiceResult toJsonArray(String it) { } } - } diff --git a/extensions/data-plane-selector/data-plane-selector-client/src/test/java/org/eclipse/edc/connector/dataplane/selector/RemoteDataPlaneSelectorServiceTest.java b/extensions/data-plane-selector/data-plane-selector-client/src/test/java/org/eclipse/edc/connector/dataplane/selector/RemoteDataPlaneSelectorServiceTest.java index e42e5e1b350..a6d606f8561 100644 --- a/extensions/data-plane-selector/data-plane-selector-client/src/test/java/org/eclipse/edc/connector/dataplane/selector/RemoteDataPlaneSelectorServiceTest.java +++ b/extensions/data-plane-selector/data-plane-selector-client/src/test/java/org/eclipse/edc/connector/dataplane/selector/RemoteDataPlaneSelectorServiceTest.java @@ -14,40 +14,28 @@ package org.eclipse.edc.connector.dataplane.selector; -import jakarta.json.Json; -import org.eclipse.edc.api.transformer.JsonObjectFromIdResponseTransformer; -import org.eclipse.edc.connector.dataplane.selector.control.api.DataplaneSelectorControlApiController; import org.eclipse.edc.connector.dataplane.selector.spi.DataPlaneSelectorService; import org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance; -import org.eclipse.edc.connector.dataplane.selector.transformer.JsonObjectToSelectionRequestTransformer; -import org.eclipse.edc.http.client.ControlApiHttpClientImpl; -import org.eclipse.edc.jsonld.util.JacksonJsonLd; import org.eclipse.edc.junit.annotations.ComponentTest; +import org.eclipse.edc.junit.extensions.EmbeddedRuntime; +import org.eclipse.edc.junit.extensions.RuntimeExtension; +import org.eclipse.edc.junit.extensions.RuntimePerMethodExtension; import org.eclipse.edc.spi.result.ServiceFailure; import org.eclipse.edc.spi.result.ServiceResult; import org.eclipse.edc.spi.types.domain.DataAddress; -import org.eclipse.edc.transform.TypeTransformerRegistryImpl; -import org.eclipse.edc.transform.spi.TypeTransformerRegistry; -import org.eclipse.edc.transform.transformer.edc.from.JsonObjectFromDataAddressTransformer; -import org.eclipse.edc.transform.transformer.edc.from.JsonObjectFromDataPlaneInstanceTransformer; -import org.eclipse.edc.transform.transformer.edc.to.JsonObjectToDataAddressTransformer; -import org.eclipse.edc.transform.transformer.edc.to.JsonObjectToDataPlaneInstanceTransformer; -import org.eclipse.edc.transform.transformer.edc.to.JsonValueToGenericTypeTransformer; import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry; import org.eclipse.edc.validator.spi.ValidationResult; -import org.eclipse.edc.web.jersey.testfixtures.RestControllerTestBase; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; -import java.time.Clock; import java.util.Map; import java.util.UUID; -import static org.eclipse.edc.http.client.testfixtures.HttpTestUtils.testHttpClient; import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; import static org.eclipse.edc.spi.result.ServiceFailure.Reason.CONFLICT; import static org.eclipse.edc.spi.result.ServiceFailure.Reason.NOT_FOUND; +import static org.eclipse.edc.util.io.Ports.getFreePort; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; @@ -55,30 +43,38 @@ import static org.mockito.Mockito.when; @ComponentTest -class RemoteDataPlaneSelectorServiceTest extends RestControllerTestBase { +class RemoteDataPlaneSelectorServiceTest { + private final int port = getFreePort(); private static final String[] FIELDS_TO_BE_IGNORED = {"createdAt", "stateTimestamp", "updatedAt"}; - private final String url = "http://localhost:%d/v1/dataplanes".formatted(port); private final DataPlaneSelectorService serverService = mock(); - private final TypeTransformerRegistry typeTransformerRegistry = new TypeTransformerRegistryImpl(); private final JsonObjectValidatorRegistry validator = mock(); - private final ControlApiHttpClientImpl controlClient = new ControlApiHttpClientImpl(testHttpClient(), mock()); - private final RemoteDataPlaneSelectorService service = new RemoteDataPlaneSelectorService(controlClient, url, - JacksonJsonLd.createObjectMapper(), typeTransformerRegistry, "selectionStrategy"); - - @BeforeEach - void setUp() { - var factory = Json.createBuilderFactory(Map.of()); - var objectMapper = JacksonJsonLd.createObjectMapper(); - typeTransformerRegistry.register(new JsonObjectFromDataAddressTransformer(factory)); - typeTransformerRegistry.register(new JsonObjectToDataAddressTransformer()); - typeTransformerRegistry.register(new JsonObjectToSelectionRequestTransformer()); - typeTransformerRegistry.register(new JsonObjectFromDataPlaneInstanceTransformer(factory, JacksonJsonLd.createObjectMapper())); - typeTransformerRegistry.register(new JsonObjectToDataPlaneInstanceTransformer()); - typeTransformerRegistry.register(new JsonObjectFromIdResponseTransformer(factory)); - typeTransformerRegistry.register(new org.eclipse.edc.connector.dataplane.selector.control.api.transformer.JsonObjectToSelectionRequestTransformer()); - typeTransformerRegistry.register(new JsonValueToGenericTypeTransformer(objectMapper)); - } + + @RegisterExtension + public final RuntimeExtension client = new RuntimePerMethodExtension(new EmbeddedRuntime( + "client", + Map.of( + "edc.dpf.selector.url", "http://localhost:%d/control/v1/dataplanes".formatted(port), + "edc.core.retry.retries.max", "0" + ), + ":core:common:connector-core", + ":extensions:common:http" + )); + + @RegisterExtension + public final RuntimeExtension server = new RuntimePerMethodExtension(new EmbeddedRuntime( + "server", + Map.of( + "edc.dpf.selector.url", "http://not-used-but-mandatory", + "web.http.control.port", port + "", + "web.http.control.path", "/control" + ), + ":extensions:data-plane-selector:data-plane-selector-control-api", + ":extensions:common:api:control-api-configuration", + ":core:common:connector-core", + ":extensions:common:http")) + .registerServiceMock(DataPlaneSelectorService.class, serverService) + .registerServiceMock(JsonObjectValidatorRegistry.class, validator); @Test void addInstance() { @@ -86,7 +82,7 @@ void addInstance() { when(serverService.addInstance(any())).thenReturn(ServiceResult.success()); var instance = createInstance("dataPlaneId"); - var result = service.addInstance(instance); + var result = service().addInstance(instance); assertThat(result).isSucceeded(); verify(serverService).addInstance(any()); @@ -97,7 +93,7 @@ void select() { var expected = createInstance("some-instance"); when(serverService.select(any(), eq("transferType"), eq("random"))).thenReturn(ServiceResult.success(expected)); - var result = service.select(DataAddress.Builder.newInstance().type("test1").build(), "transferType", "random"); + var result = service().select(DataAddress.Builder.newInstance().type("test1").build(), "transferType", "random"); assertThat(result).isSucceeded().usingRecursiveComparison() .ignoringFields(FIELDS_TO_BE_IGNORED).isEqualTo(expected); @@ -105,12 +101,13 @@ void select() { @Nested class Unregister { + @Test void shouldUnregister() { var instanceId = UUID.randomUUID().toString(); when(serverService.unregister(any())).thenReturn(ServiceResult.success()); - var result = service.unregister(instanceId); + var result = service().unregister(instanceId); assertThat(result).isSucceeded(); verify(serverService).unregister(instanceId); @@ -121,10 +118,11 @@ void shouldFail_whenServiceFails() { var instanceId = UUID.randomUUID().toString(); when(serverService.unregister(any())).thenReturn(ServiceResult.conflict("conflict")); - var result = service.unregister(instanceId); + var result = service().unregister(instanceId); assertThat(result).isFailed().extracting(ServiceFailure::getReason).isEqualTo(CONFLICT); } + } @Nested @@ -135,7 +133,7 @@ void shouldDelete() { var instanceId = UUID.randomUUID().toString(); when(serverService.delete(any())).thenReturn(ServiceResult.success()); - var result = service.delete(instanceId); + var result = service().delete(instanceId); assertThat(result).isSucceeded(); verify(serverService).delete(instanceId); @@ -146,21 +144,23 @@ void shouldFail_whenNotFound() { var instanceId = UUID.randomUUID().toString(); when(serverService.delete(any())).thenReturn(ServiceResult.notFound("not found")); - var result = service.delete(instanceId); + var result = service().delete(instanceId); assertThat(result).isFailed().extracting(ServiceFailure::getReason).isEqualTo(NOT_FOUND); } + } @Nested class FindById { + @Test void shouldReturnInstanceById() { var instanceId = UUID.randomUUID().toString(); var instance = DataPlaneInstance.Builder.newInstance().url("http://any").build(); when(serverService.findById(any())).thenReturn(ServiceResult.success(instance)); - var result = service.findById(instanceId); + var result = service().findById(instanceId); assertThat(result).isSucceeded().usingRecursiveComparison() .ignoringFields(FIELDS_TO_BE_IGNORED) @@ -172,15 +172,15 @@ void shouldReturnNotFound_whenInstanceDoesNotExist() { var instanceId = UUID.randomUUID().toString(); when(serverService.findById(any())).thenReturn(ServiceResult.notFound("not found")); - var result = service.findById(instanceId); + var result = service().findById(instanceId); assertThat(result).isFailed().extracting(ServiceFailure::getReason).isEqualTo(NOT_FOUND); } + } - @Override - protected Object controller() { - return new DataplaneSelectorControlApiController(validator, typeTransformerRegistry, serverService, Clock.systemUTC()); + private DataPlaneSelectorService service() { + return client.getService(DataPlaneSelectorService.class); } private DataPlaneInstance createInstance(String id) { diff --git a/extensions/data-plane-selector/data-plane-selector-control-api/src/main/java/org/eclipse/edc/connector/dataplane/selector/control/api/DataplaneSelectorControlApiExtension.java b/extensions/data-plane-selector/data-plane-selector-control-api/src/main/java/org/eclipse/edc/connector/dataplane/selector/control/api/DataplaneSelectorControlApiExtension.java index fa0c2bbd059..7c86cc90b55 100644 --- a/extensions/data-plane-selector/data-plane-selector-control-api/src/main/java/org/eclipse/edc/connector/dataplane/selector/control/api/DataplaneSelectorControlApiExtension.java +++ b/extensions/data-plane-selector/data-plane-selector-control-api/src/main/java/org/eclipse/edc/connector/dataplane/selector/control/api/DataplaneSelectorControlApiExtension.java @@ -15,6 +15,7 @@ package org.eclipse.edc.connector.dataplane.selector.control.api; +import org.eclipse.edc.connector.dataplane.selector.control.api.transformer.JsonObjectToSelectionRequestTransformer; import org.eclipse.edc.connector.dataplane.selector.spi.DataPlaneSelectorService; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; @@ -23,7 +24,9 @@ import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.edc.transform.transformer.edc.from.JsonObjectFromDataPlaneInstanceTransformer; +import org.eclipse.edc.transform.transformer.edc.to.JsonObjectToDataAddressTransformer; import org.eclipse.edc.transform.transformer.edc.to.JsonObjectToDataPlaneInstanceTransformer; +import org.eclipse.edc.transform.transformer.edc.to.JsonValueToGenericTypeTransformer; import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry; import org.eclipse.edc.web.spi.WebService; import org.eclipse.edc.web.spi.configuration.ApiContext; @@ -67,9 +70,13 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { validatorRegistry.register(DATAPLANE_INSTANCE_TYPE, DataPlaneInstanceValidator.instance()); + var objectMapper = typeManager.getMapper(JSON_LD); typeTransformerRegistry.register(new JsonObjectToDataPlaneInstanceTransformer()); - typeTransformerRegistry.register(new JsonObjectFromDataPlaneInstanceTransformer(createBuilderFactory(Map.of()), typeManager.getMapper(JSON_LD))); + typeTransformerRegistry.register(new JsonObjectToSelectionRequestTransformer()); + typeTransformerRegistry.register(new JsonObjectToDataAddressTransformer()); + typeTransformerRegistry.register(new JsonValueToGenericTypeTransformer(objectMapper)); + typeTransformerRegistry.register(new JsonObjectFromDataPlaneInstanceTransformer(createBuilderFactory(Map.of()), objectMapper)); var controller = new DataplaneSelectorControlApiController(validatorRegistry, typeTransformerRegistry, dataPlaneSelectorService, clock); webService.registerResource(ApiContext.CONTROL, controller); diff --git a/extensions/data-plane-selector/data-plane-selector-control-api/src/main/java/org/eclipse/edc/connector/dataplane/selector/control/api/model/SelectionRequest.java b/extensions/data-plane-selector/data-plane-selector-control-api/src/main/java/org/eclipse/edc/connector/dataplane/selector/control/api/model/SelectionRequest.java index c0ebf5612dd..74b2c235291 100644 --- a/extensions/data-plane-selector/data-plane-selector-control-api/src/main/java/org/eclipse/edc/connector/dataplane/selector/control/api/model/SelectionRequest.java +++ b/extensions/data-plane-selector/data-plane-selector-control-api/src/main/java/org/eclipse/edc/connector/dataplane/selector/control/api/model/SelectionRequest.java @@ -29,6 +29,7 @@ public class SelectionRequest { public static final String TRANSFER_TYPE = EDC_NAMESPACE + "transferType"; public static final String STRATEGY = EDC_NAMESPACE + "strategy"; private DataAddress source; + @Deprecated(since = "0.8.1") private DataAddress destination; private String strategy = "random"; private String transferType; @@ -40,6 +41,7 @@ public DataAddress getSource() { return source; } + @Deprecated(since = "0.8.1") public DataAddress getDestination() { return destination; } diff --git a/system-tests/e2e-dataplane-tests/tests/build.gradle.kts b/system-tests/e2e-dataplane-tests/tests/build.gradle.kts index 8f19ec48599..6a8ab2566e4 100644 --- a/system-tests/e2e-dataplane-tests/tests/build.gradle.kts +++ b/system-tests/e2e-dataplane-tests/tests/build.gradle.kts @@ -9,7 +9,6 @@ * * Contributors: * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * */ @@ -23,7 +22,6 @@ dependencies { testImplementation(project(":extensions:data-plane:data-plane-signaling:data-plane-signaling-transform")) testImplementation(testFixtures(project(":extensions:control-plane:api:management-api:management-api-test-fixtures"))) - testImplementation(project(":core:common:connector-core")) testImplementation(project(":core:common:junit")) testImplementation(project(":core:common:lib:keys-lib")) testImplementation(project(":extensions:common:json-ld")) diff --git a/system-tests/e2e-dataplane-tests/tests/src/test/java/org/eclipse/edc/test/e2e/DataPlaneSelectorEndToEndTest.java b/system-tests/e2e-dataplane-tests/tests/src/test/java/org/eclipse/edc/test/e2e/DataPlaneSelectorEndToEndTest.java index 86aafdcc2d5..2f4f0ad088b 100644 --- a/system-tests/e2e-dataplane-tests/tests/src/test/java/org/eclipse/edc/test/e2e/DataPlaneSelectorEndToEndTest.java +++ b/system-tests/e2e-dataplane-tests/tests/src/test/java/org/eclipse/edc/test/e2e/DataPlaneSelectorEndToEndTest.java @@ -54,6 +54,7 @@ public class DataPlaneSelectorEndToEndTest { "edc.data.plane.selector.state-machine.check.period", "1", "edc.core.retry.retries.max", "0" ), + ":core:common:connector-core", ":core:control-plane:control-plane-core", ":core:data-plane-selector:data-plane-selector-core", ":extensions:control-plane:transfer:transfer-data-plane-signaling", diff --git a/system-tests/e2e-dataplane-tests/tests/src/test/java/org/eclipse/edc/test/e2e/DataplaneSelectorControlApiEndToEndTest.java b/system-tests/e2e-dataplane-tests/tests/src/test/java/org/eclipse/edc/test/e2e/DataplaneSelectorControlApiEndToEndTest.java index bd5de15b382..9f7e232066b 100644 --- a/system-tests/e2e-dataplane-tests/tests/src/test/java/org/eclipse/edc/test/e2e/DataplaneSelectorControlApiEndToEndTest.java +++ b/system-tests/e2e-dataplane-tests/tests/src/test/java/org/eclipse/edc/test/e2e/DataplaneSelectorControlApiEndToEndTest.java @@ -15,52 +15,63 @@ package org.eclipse.edc.test.e2e; import io.restassured.http.ContentType; +import jakarta.json.Json; import jakarta.json.JsonArray; import org.eclipse.edc.junit.annotations.EndToEndTest; import org.eclipse.edc.junit.extensions.EmbeddedRuntime; import org.eclipse.edc.junit.extensions.RuntimeExtension; import org.eclipse.edc.junit.extensions.RuntimePerMethodExtension; import org.eclipse.edc.spi.protocol.ProtocolWebhook; +import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import java.util.Map; +import java.util.UUID; import static io.restassured.RestAssured.given; import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.CONTEXT; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VOCAB; +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; import static org.eclipse.edc.util.io.Ports.getFreePort; +import static org.hamcrest.CoreMatchers.is; import static org.mockito.Mockito.mock; @EndToEndTest public class DataplaneSelectorControlApiEndToEndTest { - private final int controlPlaneControlPort = getFreePort(); + private final int controlPort = getFreePort(); + private static final String DATA_PLANE_ID = UUID.randomUUID().toString(); @RegisterExtension - private final RuntimeExtension controlPlane = new RuntimePerMethodExtension(new EmbeddedRuntime( - "control-plane", + @Order(1) + private final RuntimeExtension dataPlaneSelector = new RuntimePerMethodExtension(new EmbeddedRuntime( + "data-plane-selector", Map.of( - "web.http.control.port", String.valueOf(controlPlaneControlPort), + "web.http.control.port", String.valueOf(controlPort), "web.http.control.path", "/control" ), - ":core:control-plane:control-plane-core", + ":core:common:connector-core", ":core:data-plane-selector:data-plane-selector-core", - ":extensions:control-plane:transfer:transfer-data-plane-signaling", - ":extensions:common:iam:iam-mock", ":extensions:common:http", ":extensions:common:api:control-api-configuration", + ":extensions:data-plane:data-plane-signaling:data-plane-signaling-client", ":extensions:data-plane-selector:data-plane-selector-control-api" )).registerServiceMock(ProtocolWebhook.class, mock()); @RegisterExtension + @Order(2) private final RuntimeExtension dataPlane = new RuntimePerMethodExtension(new EmbeddedRuntime( "data-plane", Map.of( + "edc.runtime.id", DATA_PLANE_ID, "web.http.port", String.valueOf(getFreePort()), "web.http.path", "/api", "web.http.control.port", String.valueOf(getFreePort()), "web.http.control.path", "/control", - "edc.dpf.selector.url", String.format("http://localhost:%d/control/v1/dataplanes", controlPlaneControlPort), + "edc.dpf.selector.url", String.format("http://localhost:%d/control/v1/dataplanes", controlPort), "edc.transfer.proxy.token.verifier.publickey.alias", "alias", "edc.transfer.proxy.token.signer.privatekey.alias", "alias" ), @@ -72,7 +83,8 @@ public class DataplaneSelectorControlApiEndToEndTest { @Test void shouldReturnSelfRegisteredDataplane() { var result = given() - .baseUri("http://localhost:" + controlPlaneControlPort + "/control") + .basePath("/control") + .port(controlPort) .when() .get("/v1/dataplanes") .then() @@ -82,4 +94,28 @@ void shouldReturnSelfRegisteredDataplane() { assertThat(result).hasSize(1); } + + @Test + void shouldSelectDataPlane() { + var requestBody = Json.createObjectBuilder() + .add(CONTEXT, Json.createObjectBuilder().add(VOCAB, EDC_NAMESPACE)) + .add("source", Json.createObjectBuilder() + .add("type", "HttpData")) + .add("transferType", "HttpData-PUSH") + .build(); + + await().untilAsserted(() -> { + given() + .basePath("/control") + .port(controlPort) + .when() + .contentType(ContentType.JSON) + .body(requestBody) + .post("/v1/dataplanes/select") + .then() + .statusCode(200) + .contentType(ContentType.JSON) + .body("@id", is(DATA_PLANE_ID)); + }); + } }