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 f53450af5bb..fa0c2bbd059 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 @@ -9,6 +9,7 @@ * * Contributors: * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation + * Fraunhofer Institute for Software and Systems Engineering - register missing transformer * */ @@ -19,16 +20,21 @@ 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 org.eclipse.edc.transform.spi.TypeTransformerRegistry; +import org.eclipse.edc.transform.transformer.edc.from.JsonObjectFromDataPlaneInstanceTransformer; import org.eclipse.edc.transform.transformer.edc.to.JsonObjectToDataPlaneInstanceTransformer; import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry; import org.eclipse.edc.web.spi.WebService; import org.eclipse.edc.web.spi.configuration.ApiContext; import java.time.Clock; +import java.util.Map; +import static jakarta.json.Json.createBuilderFactory; import static org.eclipse.edc.connector.dataplane.selector.control.api.DataplaneSelectorControlApiExtension.NAME; import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.DATAPLANE_INSTANCE_TYPE; +import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; @Extension(NAME) public class DataplaneSelectorControlApiExtension implements ServiceExtension { @@ -41,6 +47,9 @@ public class DataplaneSelectorControlApiExtension implements ServiceExtension { @Inject private JsonObjectValidatorRegistry validatorRegistry; + @Inject + private TypeManager typeManager; + @Inject private TypeTransformerRegistry typeTransformerRegistry; @@ -60,6 +69,7 @@ public void initialize(ServiceExtensionContext context) { validatorRegistry.register(DATAPLANE_INSTANCE_TYPE, DataPlaneInstanceValidator.instance()); typeTransformerRegistry.register(new JsonObjectToDataPlaneInstanceTransformer()); + typeTransformerRegistry.register(new JsonObjectFromDataPlaneInstanceTransformer(createBuilderFactory(Map.of()), typeManager.getMapper(JSON_LD))); 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/test/java/org/eclipse/edc/connector/dataplane/selector/control/api/DataplaneSelectorControlApiExtensionTest.java b/extensions/data-plane-selector/data-plane-selector-control-api/src/test/java/org/eclipse/edc/connector/dataplane/selector/control/api/DataplaneSelectorControlApiExtensionTest.java index 40c60ac2604..47c74e6d88d 100644 --- a/extensions/data-plane-selector/data-plane-selector-control-api/src/test/java/org/eclipse/edc/connector/dataplane/selector/control/api/DataplaneSelectorControlApiExtensionTest.java +++ b/extensions/data-plane-selector/data-plane-selector-control-api/src/test/java/org/eclipse/edc/connector/dataplane/selector/control/api/DataplaneSelectorControlApiExtensionTest.java @@ -9,6 +9,7 @@ * * Contributors: * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation + * Fraunhofer Institute for Software and Systems Engineering - register missing transformer * */ @@ -18,6 +19,7 @@ import org.eclipse.edc.junit.extensions.DependencyInjectionExtension; import org.eclipse.edc.spi.system.ServiceExtensionContext; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; +import org.eclipse.edc.transform.transformer.edc.from.JsonObjectFromDataPlaneInstanceTransformer; import org.eclipse.edc.transform.transformer.edc.to.JsonObjectToDataPlaneInstanceTransformer; import org.eclipse.edc.validator.jsonobject.JsonObjectValidator; import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry; @@ -65,5 +67,6 @@ void shouldRegisterTransformers(DataplaneSelectorControlApiExtension extension, extension.initialize(context); verify(typeTransformerRegistry).register(isA(JsonObjectToDataPlaneInstanceTransformer.class)); + verify(typeTransformerRegistry).register(isA(JsonObjectFromDataPlaneInstanceTransformer.class)); } } 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 new file mode 100644 index 00000000000..8cae2eac227 --- /dev/null +++ b/system-tests/e2e-dataplane-tests/tests/src/test/java/org/eclipse/edc/test/e2e/DataplaneSelectorControlApiEndToEndTest.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2024 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 implementation + * + */ + +package org.eclipse.edc.test.e2e; + +import io.restassured.http.ContentType; +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.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import java.util.Map; + +import static io.restassured.RestAssured.given; +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.util.io.Ports.getFreePort; +import static org.mockito.Mockito.mock; + +@EndToEndTest +public class DataplaneSelectorControlApiEndToEndTest { + + private final int controlPlaneControlPort = getFreePort(); + + @RegisterExtension + private final RuntimeExtension controlPlane = new RuntimePerMethodExtension(new EmbeddedRuntime( + "control-plane", + Map.of( + "web.http.control.port", String.valueOf(controlPlaneControlPort), + "web.http.control.path", "/control" + ), + ":core:control-plane:control-plane-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-selector:data-plane-selector-control-api" + )).registerServiceMock(ProtocolWebhook.class, mock()); + + @RegisterExtension + private final RuntimeExtension dataPlane = new RuntimePerMethodExtension(new EmbeddedRuntime( + "data-plane", + Map.of( + "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) + ), + ":system-tests:e2e-dataplane-tests:runtimes:data-plane", + ":extensions:data-plane:data-plane-self-registration", + ":extensions:data-plane-selector:data-plane-selector-client" + )); + + @Test + void shouldReturnSelfRegisteredDataplane() { + var result = given() + .baseUri("http://localhost:" + controlPlaneControlPort + "/control") + .when() + .get("/v1/dataplanes") + .then() + .statusCode(200) + .contentType(ContentType.JSON) + .extract().body().as(JsonArray.class); + + assertThat(result).hasSize(1); + } +}