From 9ba52d1d27422a9cd9bfa0609f78149d8df21d28 Mon Sep 17 00:00:00 2001 From: ndr_brt Date: Mon, 20 Jan 2025 10:16:25 +0100 Subject: [PATCH] fix tests --- .../basic/Basic01basicConnectorTest.java | 2 - .../basic/Basic02healthEndpointTest.java | 2 - .../basic/Basic03configurationTest.java | 10 +--- .../common/FederatedCatalogCommon.java | 22 ++++---- .../samples/common/PrerequisitesCommon.java | 18 +++---- .../edc/samples/policy/Policy01BasicTest.java | 9 ++-- .../Transfer05fileTransferCloudTest.java | 27 +++++----- .../streaming/Streaming01httpToHttpTest.java | 30 ++++------- .../streaming/Streaming02KafkaToHttpTest.java | 29 ++++------ .../Streaming03KafkaToKafkaTest.java | 27 +++------- .../streaming/StreamingParticipant.java | 31 ++++++----- .../samples/util/ConfigPropertiesLoader.java | 53 +++++++++++++++++++ 12 files changed, 134 insertions(+), 126 deletions(-) create mode 100644 system-tests/src/test/java/org/eclipse/edc/samples/util/ConfigPropertiesLoader.java diff --git a/system-tests/src/test/java/org/eclipse/edc/samples/basic/Basic01basicConnectorTest.java b/system-tests/src/test/java/org/eclipse/edc/samples/basic/Basic01basicConnectorTest.java index 57600e75..b2da9fda 100644 --- a/system-tests/src/test/java/org/eclipse/edc/samples/basic/Basic01basicConnectorTest.java +++ b/system-tests/src/test/java/org/eclipse/edc/samples/basic/Basic01basicConnectorTest.java @@ -23,7 +23,6 @@ import java.time.Clock; -import static java.util.Collections.emptyMap; import static org.assertj.core.api.Assertions.assertThat; @EndToEndTest @@ -32,7 +31,6 @@ class Basic01basicConnectorTest { @RegisterExtension static RuntimeExtension connector = new RuntimePerClassExtension(new EmbeddedRuntime( "connector", - emptyMap(), ":basic:basic-01-basic-connector" )); diff --git a/system-tests/src/test/java/org/eclipse/edc/samples/basic/Basic02healthEndpointTest.java b/system-tests/src/test/java/org/eclipse/edc/samples/basic/Basic02healthEndpointTest.java index 545e3ffe..54c02ceb 100644 --- a/system-tests/src/test/java/org/eclipse/edc/samples/basic/Basic02healthEndpointTest.java +++ b/system-tests/src/test/java/org/eclipse/edc/samples/basic/Basic02healthEndpointTest.java @@ -22,7 +22,6 @@ import org.junit.jupiter.api.extension.RegisterExtension; import static io.restassured.RestAssured.given; -import static java.util.Collections.emptyMap; import static org.hamcrest.CoreMatchers.containsString; @EndToEndTest @@ -31,7 +30,6 @@ class Basic02healthEndpointTest { @RegisterExtension static RuntimeExtension controlPlane = new RuntimePerClassExtension(new EmbeddedRuntime( "connector", - emptyMap(), ":basic:basic-02-health-endpoint" )); diff --git a/system-tests/src/test/java/org/eclipse/edc/samples/basic/Basic03configurationTest.java b/system-tests/src/test/java/org/eclipse/edc/samples/basic/Basic03configurationTest.java index 1710f0b4..50172996 100644 --- a/system-tests/src/test/java/org/eclipse/edc/samples/basic/Basic03configurationTest.java +++ b/system-tests/src/test/java/org/eclipse/edc/samples/basic/Basic03configurationTest.java @@ -21,11 +21,8 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; -import java.io.File; -import java.util.Map; - import static io.restassured.RestAssured.given; -import static org.eclipse.edc.junit.testfixtures.TestUtils.findBuildRoot; +import static org.eclipse.edc.samples.util.ConfigPropertiesLoader.fromPropertiesFile; import static org.hamcrest.CoreMatchers.containsString; @EndToEndTest @@ -34,11 +31,8 @@ class Basic03configurationTest { @RegisterExtension static RuntimeExtension controlPlane = new RuntimePerClassExtension(new EmbeddedRuntime( "connector", - Map.of( - "edc.fs.config", new File(findBuildRoot(), "basic/basic-03-configuration/config.properties").getAbsolutePath() - ), ":basic:basic-03-configuration" - )); + ).configurationProvider(fromPropertiesFile("basic/basic-03-configuration/config.properties"))); @Test void shouldStartConnector() { diff --git a/system-tests/src/test/java/org/eclipse/edc/samples/common/FederatedCatalogCommon.java b/system-tests/src/test/java/org/eclipse/edc/samples/common/FederatedCatalogCommon.java index 2272e9e9..1e67b731 100644 --- a/system-tests/src/test/java/org/eclipse/edc/samples/common/FederatedCatalogCommon.java +++ b/system-tests/src/test/java/org/eclipse/edc/samples/common/FederatedCatalogCommon.java @@ -19,6 +19,7 @@ import org.eclipse.edc.junit.extensions.EmbeddedRuntime; import org.eclipse.edc.junit.extensions.RuntimeExtension; import org.eclipse.edc.junit.extensions.RuntimePerClassExtension; +import org.eclipse.edc.spi.system.configuration.ConfigFactory; import java.util.Map; @@ -27,6 +28,7 @@ import static org.eclipse.edc.samples.common.FileTransferCommon.getFileFromRelativePath; import static org.eclipse.edc.samples.common.PrerequisitesCommon.API_KEY_HEADER_KEY; import static org.eclipse.edc.samples.common.PrerequisitesCommon.API_KEY_HEADER_VALUE; +import static org.eclipse.edc.samples.util.ConfigPropertiesLoader.fromPropertiesFile; import static org.eclipse.edc.samples.util.TransferUtil.post; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; @@ -74,17 +76,15 @@ private static RuntimeExtension getRuntime( String moduleName, String configPropertiesFilePath ) { - return new RuntimePerClassExtension(new EmbeddedRuntime( - moduleName, - Map.of( - EDC_KEYSTORE, getFileFromRelativePath(CERT_PFX_FILE_PATH).getAbsolutePath(), - EDC_KEYSTORE_PASSWORD, KEYSTORE_PASSWORD, - EDC_FS_CONFIG, getFileFromRelativePath(configPropertiesFilePath).getAbsolutePath(), - CRAWLER_EXECUTION_DELAY, Integer.toString(CRAWLER_EXECUTION_DELAY_VALUE), - CRAWLER_EXECUTION_PERIOD, Integer.toString(CRAWLER_EXECUTION_PERIOD_VALUE) - ), - modulePath - )); + return new RuntimePerClassExtension(new EmbeddedRuntime(moduleName, modulePath) + .configurationProvider(fromPropertiesFile(configPropertiesFilePath)) + .configurationProvider(() -> ConfigFactory.fromMap(Map.of( + EDC_KEYSTORE, getFileFromRelativePath(CERT_PFX_FILE_PATH).getAbsolutePath(), + EDC_KEYSTORE_PASSWORD, KEYSTORE_PASSWORD, + CRAWLER_EXECUTION_DELAY, Integer.toString(CRAWLER_EXECUTION_DELAY_VALUE), + CRAWLER_EXECUTION_PERIOD, Integer.toString(CRAWLER_EXECUTION_PERIOD_VALUE))) + ) + ); } public static String createAsset() { diff --git a/system-tests/src/test/java/org/eclipse/edc/samples/common/PrerequisitesCommon.java b/system-tests/src/test/java/org/eclipse/edc/samples/common/PrerequisitesCommon.java index 15517fe6..143a02bd 100644 --- a/system-tests/src/test/java/org/eclipse/edc/samples/common/PrerequisitesCommon.java +++ b/system-tests/src/test/java/org/eclipse/edc/samples/common/PrerequisitesCommon.java @@ -17,6 +17,8 @@ import org.eclipse.edc.junit.extensions.EmbeddedRuntime; import org.eclipse.edc.junit.extensions.RuntimeExtension; import org.eclipse.edc.junit.extensions.RuntimePerClassExtension; +import org.eclipse.edc.samples.util.ConfigPropertiesLoader; +import org.eclipse.edc.spi.system.configuration.ConfigFactory; import java.util.Map; @@ -57,14 +59,12 @@ private static RuntimeExtension getConnector( String moduleName, String configPropertiesFilePath ) { - return new RuntimePerClassExtension(new EmbeddedRuntime( - moduleName, - Map.of( - EDC_KEYSTORE, getFileFromRelativePath(CERT_PFX_FILE_PATH).getAbsolutePath(), - EDC_KEYSTORE_PASSWORD, KEYSTORE_PASSWORD, - EDC_FS_CONFIG, getFileFromRelativePath(configPropertiesFilePath).getAbsolutePath() - ), - modulePath - )); + return new RuntimePerClassExtension(new EmbeddedRuntime(moduleName, modulePath) + .configurationProvider(ConfigPropertiesLoader.fromPropertiesFile(configPropertiesFilePath)) + .configurationProvider(() -> ConfigFactory.fromMap(Map.of( + EDC_KEYSTORE, getFileFromRelativePath(CERT_PFX_FILE_PATH).getAbsolutePath(), + EDC_KEYSTORE_PASSWORD, KEYSTORE_PASSWORD)) + ) + ); } } diff --git a/system-tests/src/test/java/org/eclipse/edc/samples/policy/Policy01BasicTest.java b/system-tests/src/test/java/org/eclipse/edc/samples/policy/Policy01BasicTest.java index 9d1f2710..5272b193 100644 --- a/system-tests/src/test/java/org/eclipse/edc/samples/policy/Policy01BasicTest.java +++ b/system-tests/src/test/java/org/eclipse/edc/samples/policy/Policy01BasicTest.java @@ -24,15 +24,14 @@ import org.junit.jupiter.api.extension.RegisterExtension; import java.time.Duration; -import java.util.Map; import static org.awaitility.Awaitility.await; -import static org.eclipse.edc.samples.common.FileTransferCommon.getFileFromRelativePath; import static org.eclipse.edc.samples.common.NegotiationCommon.getContractNegotiationState; import static org.eclipse.edc.samples.common.NegotiationCommon.negotiateContract; import static org.eclipse.edc.samples.common.PolicyCommon.createAsset; import static org.eclipse.edc.samples.common.PolicyCommon.createContractDefinition; import static org.eclipse.edc.samples.common.PolicyCommon.createPolicy; +import static org.eclipse.edc.samples.util.ConfigPropertiesLoader.fromPropertiesFile; import static org.eclipse.edc.samples.util.TransferUtil.POLL_INTERVAL; @EndToEndTest @@ -93,17 +92,15 @@ void runSampleSteps() { private static RuntimeExtension provider() { return new RuntimePerClassExtension(new EmbeddedRuntime( "provider", - Map.of("edc.fs.config", getFileFromRelativePath(SAMPLE_FOLDER + "/policy-enforcement-provider/config.properties").getAbsolutePath()), ":policy:policy-01-policy-enforcement:policy-enforcement-provider" - )); + ).configurationProvider(fromPropertiesFile(SAMPLE_FOLDER + "/policy-enforcement-provider/config.properties"))); } private static RuntimeExtension consumer(String configurationFilePath) { return new RuntimePerClassExtension(new EmbeddedRuntime( "consumer", - Map.of("edc.fs.config", getFileFromRelativePath(configurationFilePath).getAbsolutePath()), ":policy:policy-01-policy-enforcement:policy-enforcement-consumer" - )); + ).configurationProvider(fromPropertiesFile(configurationFilePath))); } } diff --git a/system-tests/src/test/java/org/eclipse/edc/samples/transfer/Transfer05fileTransferCloudTest.java b/system-tests/src/test/java/org/eclipse/edc/samples/transfer/Transfer05fileTransferCloudTest.java index 3023f68f..65f56630 100644 --- a/system-tests/src/test/java/org/eclipse/edc/samples/transfer/Transfer05fileTransferCloudTest.java +++ b/system-tests/src/test/java/org/eclipse/edc/samples/transfer/Transfer05fileTransferCloudTest.java @@ -24,6 +24,7 @@ import org.eclipse.edc.junit.extensions.EmbeddedRuntime; import org.eclipse.edc.junit.extensions.RuntimeExtension; import org.eclipse.edc.junit.extensions.RuntimePerClassExtension; +import org.eclipse.edc.spi.system.configuration.ConfigFactory; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.testcontainers.containers.GenericContainer; @@ -43,7 +44,7 @@ import static org.assertj.core.api.Fail.fail; import static org.eclipse.edc.samples.common.FileTransferCloudCommon.runNegotiation; import static org.eclipse.edc.samples.common.FileTransferCommon.getFileContentFromRelativePath; -import static org.eclipse.edc.samples.common.FileTransferCommon.getFileFromRelativePath; +import static org.eclipse.edc.samples.util.ConfigPropertiesLoader.fromPropertiesFile; import static org.eclipse.edc.samples.util.TransferUtil.checkTransferStatus; import static org.eclipse.edc.samples.util.TransferUtil.startTransfer; @@ -105,18 +106,15 @@ public class Transfer05fileTransferCloudTest { .withLogConsumer(frame -> System.out.print(frame.getUtf8String())); @RegisterExtension - protected static RuntimeExtension consumer = new RuntimePerClassExtension(new EmbeddedRuntime( - CONSUMER, - Map.of( - EDC_FS_CONFIG, getFileFromRelativePath(CLOUD_CONSUMER_CONFIG_PROPERTIES_FILE_PATH).getAbsolutePath() - ), - CONSUMER_MODULE_PATH - )); + protected static RuntimeExtension consumer = new RuntimePerClassExtension( + new EmbeddedRuntime(CONSUMER, CONSUMER_MODULE_PATH) + .configurationProvider(fromPropertiesFile(CLOUD_CONSUMER_CONFIG_PROPERTIES_FILE_PATH)) + ); @RegisterExtension - protected static RuntimeExtension provider = new RuntimePerClassExtension(new EmbeddedRuntime( - PROVIDER, - Map.ofEntries( + protected static RuntimeExtension provider = new RuntimePerClassExtension( + new EmbeddedRuntime(PROVIDER, PROVIDER_MODULE_PATH) + .configurationProvider(() -> ConfigFactory.fromMap(Map.ofEntries( entry("edc.participant.id", "provider"), entry("edc.dsp.callback.address", "http://localhost:19194/protocol"), entry("web.http.port", "19191"), @@ -140,10 +138,9 @@ EDC_FS_CONFIG, getFileFromRelativePath(CLOUD_CONSUMER_CONFIG_PROPERTIES_FILE_PAT entry("edc.vault.hashicorp.health.check.enabled", "false"), entry("edc.blobstore.endpoint.template", "http://127.0.0.1:" + getAzuritePort() + "/%s"), entry("edc.aws.access.key", "accessKeyId"), - entry("edc.aws.secret.access.key", "secretAccessKey") - ), - PROVIDER_MODULE_PATH - )); + entry("edc.aws.secret.access.key", "secretAccessKey"))) + ) + ); @Test void pushFile() throws Exception { diff --git a/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/Streaming01httpToHttpTest.java b/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/Streaming01httpToHttpTest.java index 58cc538f..7662de1f 100644 --- a/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/Streaming01httpToHttpTest.java +++ b/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/Streaming01httpToHttpTest.java @@ -15,6 +15,7 @@ package org.eclipse.edc.samples.transfer.streaming; import okhttp3.mockwebserver.MockWebServer; +import org.eclipse.edc.connector.controlplane.test.system.utils.LazySupplier; import org.eclipse.edc.junit.annotations.EndToEndTest; import org.eclipse.edc.junit.extensions.EmbeddedRuntime; import org.eclipse.edc.junit.extensions.RuntimeExtension; @@ -29,7 +30,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.time.Duration; -import java.util.Map; import java.util.UUID; import static java.util.concurrent.Executors.newScheduledThreadPool; @@ -38,7 +38,7 @@ import static org.awaitility.Awaitility.await; import static org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcessStates.STARTED; import static org.eclipse.edc.samples.common.FileTransferCommon.getFileContentFromRelativePath; -import static org.eclipse.edc.samples.common.FileTransferCommon.getFileFromRelativePath; +import static org.eclipse.edc.samples.util.ConfigPropertiesLoader.fromPropertiesFile; @EndToEndTest public class Streaming01httpToHttpTest { @@ -49,36 +49,26 @@ public class Streaming01httpToHttpTest { private static final StreamingParticipant PROVIDER = StreamingParticipant.Builder.newStreamingInstance() .name("provider") .id("provider") - .managementEndpoint(new StreamingParticipant.Endpoint(URI.create("http://localhost:18181/management"))) - .protocolEndpoint(new StreamingParticipant.Endpoint(URI.create("http://localhost:18182/protocol"))) - .controlEndpoint(new StreamingParticipant.Endpoint(URI.create("http://localhost:18183/control"))) + .controlPlaneManagement(new LazySupplier<>(() -> URI.create("http://localhost:18181/management"))) + .controlPlaneProtocol(new LazySupplier<>(() -> URI.create("http://localhost:18182/protocol"))) .build(); private static final StreamingParticipant CONSUMER = StreamingParticipant.Builder.newStreamingInstance() .name("consumer") .id("consumer") - .managementEndpoint(new StreamingParticipant.Endpoint(URI.create("http://localhost:28181/management"))) - .protocolEndpoint(new StreamingParticipant.Endpoint(URI.create("http://localhost:28182/protocol"))) - .controlEndpoint(new StreamingParticipant.Endpoint(URI.create("http://localhost:28183/control"))) + .controlPlaneManagement(new LazySupplier<>(() -> URI.create("http://localhost:28181/management"))) + .controlPlaneProtocol(new LazySupplier<>(() -> URI.create("http://localhost:28182/protocol"))) .build(); @RegisterExtension static RuntimeExtension providerConnector = new RuntimePerClassExtension(new EmbeddedRuntime( - "provider", - Map.of( - "edc.fs.config", getFileFromRelativePath(SAMPLE_FOLDER + "/streaming-01-runtime/provider.properties").getAbsolutePath() - ), - ":transfer:streaming:streaming-01-http-to-http:streaming-01-runtime" - )); + "provider", ":transfer:streaming:streaming-01-http-to-http:streaming-01-runtime" + ).configurationProvider(fromPropertiesFile(SAMPLE_FOLDER + "/streaming-01-runtime/provider.properties"))); @RegisterExtension static RuntimeExtension consumerConnector = new RuntimePerClassExtension(new EmbeddedRuntime( - "consumer", - Map.of( - "edc.fs.config", getFileFromRelativePath(SAMPLE_FOLDER + "/streaming-01-runtime/consumer.properties").getAbsolutePath() - ), - ":transfer:streaming:streaming-01-http-to-http:streaming-01-runtime" - )); + "consumer", ":transfer:streaming:streaming-01-http-to-http:streaming-01-runtime" + ).configurationProvider(fromPropertiesFile(SAMPLE_FOLDER + "/streaming-01-runtime/consumer.properties"))); private final int httpReceiverPort = Ports.getFreePort(); private final MockWebServer consumerReceiverServer = new MockWebServer(); diff --git a/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/Streaming02KafkaToHttpTest.java b/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/Streaming02KafkaToHttpTest.java index edee3901..5e29ffd6 100644 --- a/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/Streaming02KafkaToHttpTest.java +++ b/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/Streaming02KafkaToHttpTest.java @@ -21,6 +21,7 @@ import org.apache.kafka.clients.producer.ProducerConfig; import org.apache.kafka.clients.producer.ProducerRecord; import org.apache.kafka.common.serialization.StringSerializer; +import org.eclipse.edc.connector.controlplane.test.system.utils.LazySupplier; import org.eclipse.edc.junit.annotations.EndToEndTest; import org.eclipse.edc.junit.extensions.EmbeddedRuntime; import org.eclipse.edc.junit.extensions.RuntimeExtension; @@ -37,7 +38,6 @@ import java.io.IOException; import java.net.URI; import java.time.Duration; -import java.util.Map; import java.util.Properties; import java.util.concurrent.Executors; @@ -46,7 +46,7 @@ import static org.awaitility.Awaitility.await; import static org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcessStates.STARTED; import static org.eclipse.edc.samples.common.FileTransferCommon.getFileContentFromRelativePath; -import static org.eclipse.edc.samples.common.FileTransferCommon.getFileFromRelativePath; +import static org.eclipse.edc.samples.util.ConfigPropertiesLoader.fromPropertiesFile; @Testcontainers @EndToEndTest @@ -60,16 +60,14 @@ public class Streaming02KafkaToHttpTest { private static final StreamingParticipant PROVIDER = StreamingParticipant.Builder.newStreamingInstance() .name("provider") .id("provider") - .managementEndpoint(new StreamingParticipant.Endpoint(URI.create("http://localhost:18181/management"))) - .protocolEndpoint(new StreamingParticipant.Endpoint(URI.create("http://localhost:18182/protocol"))) - .controlEndpoint(new StreamingParticipant.Endpoint(URI.create("http://localhost:18183/control"))) + .controlPlaneManagement(new LazySupplier<>(() -> URI.create("http://localhost:18181/management"))) + .controlPlaneProtocol(new LazySupplier<>(() -> URI.create("http://localhost:18182/protocol"))) .build(); private static final StreamingParticipant CONSUMER = StreamingParticipant.Builder.newStreamingInstance() .name("consumer") .id("consumer") - .managementEndpoint(new StreamingParticipant.Endpoint(URI.create("http://localhost:28181/management"))) - .protocolEndpoint(new StreamingParticipant.Endpoint(URI.create("http://localhost:28182/protocol"))) - .controlEndpoint(new StreamingParticipant.Endpoint(URI.create("http://localhost:28183/control"))) + .controlPlaneManagement(new LazySupplier<>(() -> URI.create("http://localhost:28181/management"))) + .controlPlaneProtocol(new LazySupplier<>(() -> URI.create("http://localhost:28182/protocol"))) .build(); @Container @@ -81,24 +79,15 @@ public class Streaming02KafkaToHttpTest { @RegisterExtension static RuntimeExtension providerConnector = new RuntimePerClassExtension(new EmbeddedRuntime( "provider", - Map.of( - "edc.fs.config", - getFileFromRelativePath(SAMPLE_FOLDER + "/streaming-02-runtime/provider.properties") - .getAbsolutePath() - ), ":transfer:streaming:streaming-02-kafka-to-http:streaming-02-runtime" - )); + ).configurationProvider(fromPropertiesFile(SAMPLE_FOLDER + "/streaming-02-runtime/provider.properties"))); @RegisterExtension static RuntimeExtension consumerConnector = new RuntimePerClassExtension(new EmbeddedRuntime( "consumer", - Map.of( - "edc.fs.config", - getFileFromRelativePath(SAMPLE_FOLDER + "/streaming-02-runtime/consumer.properties") - .getAbsolutePath() - ), ":transfer:streaming:streaming-02-kafka-to-http:streaming-02-runtime" - )); + ).configurationProvider(fromPropertiesFile(SAMPLE_FOLDER + "/streaming-02-runtime/consumer.properties"))); + private final int httpReceiverPort = Ports.getFreePort(); private final MockWebServer consumerReceiverServer = new MockWebServer(); diff --git a/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/Streaming03KafkaToKafkaTest.java b/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/Streaming03KafkaToKafkaTest.java index e783b3c4..fedfa992 100644 --- a/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/Streaming03KafkaToKafkaTest.java +++ b/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/Streaming03KafkaToKafkaTest.java @@ -38,6 +38,7 @@ import org.apache.kafka.common.resource.ResourceType; import org.apache.kafka.common.serialization.StringDeserializer; import org.apache.kafka.common.serialization.StringSerializer; +import org.eclipse.edc.connector.controlplane.test.system.utils.LazySupplier; import org.eclipse.edc.junit.annotations.EndToEndTest; import org.eclipse.edc.junit.extensions.EmbeddedRuntime; import org.eclipse.edc.junit.extensions.RuntimeExtension; @@ -60,7 +61,6 @@ import java.time.Duration; import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.Properties; import java.util.UUID; import java.util.concurrent.ExecutionException; @@ -74,6 +74,7 @@ import static org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcessStates.STARTED; import static org.eclipse.edc.samples.common.FileTransferCommon.getFileContentFromRelativePath; import static org.eclipse.edc.samples.common.FileTransferCommon.getFileFromRelativePath; +import static org.eclipse.edc.samples.util.ConfigPropertiesLoader.fromPropertiesFile; import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; @Testcontainers @@ -89,16 +90,14 @@ public class Streaming03KafkaToKafkaTest { private static final StreamingParticipant PROVIDER = StreamingParticipant.Builder.newStreamingInstance() .name("provider") .id("provider") - .managementEndpoint(new StreamingParticipant.Endpoint(URI.create("http://localhost:18181/management"))) - .protocolEndpoint(new StreamingParticipant.Endpoint(URI.create("http://localhost:18182/protocol"))) - .controlEndpoint(new StreamingParticipant.Endpoint(URI.create("http://localhost:18183/control"))) + .controlPlaneManagement(new LazySupplier<>(() -> URI.create("http://localhost:18181/management"))) + .controlPlaneProtocol(new LazySupplier<>(() -> URI.create("http://localhost:18182/protocol"))) .build(); private static final StreamingParticipant CONSUMER = StreamingParticipant.Builder.newStreamingInstance() .name("consumer") .id("consumer") - .managementEndpoint(new StreamingParticipant.Endpoint(URI.create("http://localhost:28181/management"))) - .protocolEndpoint(new StreamingParticipant.Endpoint(URI.create("http://localhost:28182/protocol"))) - .controlEndpoint(new StreamingParticipant.Endpoint(URI.create("http://localhost:28183/control"))) + .controlPlaneManagement(new LazySupplier<>(() -> URI.create("http://localhost:28181/management"))) + .controlPlaneProtocol(new LazySupplier<>(() -> URI.create("http://localhost:28182/protocol"))) .build(); private static final String GROUP_ID = "group_id"; @@ -109,24 +108,14 @@ public class Streaming03KafkaToKafkaTest { @RegisterExtension static RuntimeExtension providerConnector = new RuntimePerClassExtension(new EmbeddedRuntime( "provider", - Map.of( - "edc.fs.config", - getFileFromRelativePath(RUNTIME_PATH.resolve("provider.properties").toString()) - .getAbsolutePath() - ), ":transfer:streaming:%s:%s".formatted(SAMPLE_NAME, RUNTIME_NAME) - )); + ).configurationProvider(fromPropertiesFile(RUNTIME_PATH.resolve("provider.properties").toString()))); @RegisterExtension static RuntimeExtension consumerConnector = new RuntimePerClassExtension(new EmbeddedRuntime( "consumer", - Map.of( - "edc.fs.config", - getFileFromRelativePath(RUNTIME_PATH.resolve("consumer.properties").toString()) - .getAbsolutePath() - ), ":transfer:streaming:%s:%s".formatted(SAMPLE_NAME, RUNTIME_NAME) - )); + ).configurationProvider(fromPropertiesFile(RUNTIME_PATH.resolve("consumer.properties").toString()))); private final int httpReceiverPort = Ports.getFreePort(); private final MockWebServer edrReceiverServer = new MockWebServer(); diff --git a/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/StreamingParticipant.java b/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/StreamingParticipant.java index c1f8718a..15ff34a9 100644 --- a/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/StreamingParticipant.java +++ b/system-tests/src/test/java/org/eclipse/edc/samples/transfer/streaming/StreamingParticipant.java @@ -14,8 +14,11 @@ package org.eclipse.edc.samples.transfer.streaming; +import org.eclipse.edc.connector.controlplane.test.system.utils.LazySupplier; import org.eclipse.edc.connector.controlplane.test.system.utils.Participant; +import java.net.URI; + import static io.restassured.http.ContentType.JSON; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; @@ -24,8 +27,6 @@ */ public class StreamingParticipant extends Participant { - protected Endpoint controlEndpoint; - protected StreamingParticipant() { } @@ -34,7 +35,7 @@ public String getName() { } public String createAsset(String requestBody) { - return managementEndpoint.baseRequest() + return baseManagementRequest() .contentType(JSON) .body(requestBody) .when() @@ -48,7 +49,7 @@ public String createAsset(String requestBody) { } public String createPolicyDefinition(String requestBody) { - return managementEndpoint.baseRequest() + return baseManagementRequest() .contentType(JSON) .body(requestBody) .when() @@ -60,7 +61,7 @@ public String createPolicyDefinition(String requestBody) { } public String createContractDefinition(String requestBody) { - return managementEndpoint.baseRequest() + return baseManagementRequest() .contentType(JSON) .body(requestBody) .when() @@ -71,7 +72,7 @@ public String createContractDefinition(String requestBody) { } public String fetchDatasetFromCatalog(String requestBody) { - return managementEndpoint.baseRequest() + return baseManagementRequest() .contentType(JSON) .body(requestBody) .when() @@ -83,7 +84,7 @@ public String fetchDatasetFromCatalog(String requestBody) { } public String negotiateContract(String requestBody) { - return managementEndpoint.baseRequest() + return baseManagementRequest() .contentType(JSON) .body(requestBody) .when() @@ -95,7 +96,7 @@ public String negotiateContract(String requestBody) { } public String getContractAgreementId(String contractNegotiationId) { - return managementEndpoint.baseRequest() + return baseManagementRequest() .contentType(JSON) .when() .get("/v3/contractnegotiations/" + contractNegotiationId) @@ -106,7 +107,7 @@ public String getContractAgreementId(String contractNegotiationId) { } public String startTransfer(String requestBody) { - return managementEndpoint.baseRequest() + return baseManagementRequest() .contentType(JSON) .body(requestBody) .when() @@ -127,14 +128,16 @@ public static > Builder(new StreamingParticipant()); } - public B controlEndpoint(Endpoint controlEndpoint) { - participant.controlEndpoint = controlEndpoint; + public B controlPlaneManagement(LazySupplier controlPlaneManagement) { + participant.controlPlaneManagement = controlPlaneManagement; return self(); } - @Override - public StreamingParticipant build() { - return (StreamingParticipant) super.build(); + public B controlPlaneProtocol(LazySupplier controlPlaneProtocol) { + participant.controlPlaneProtocol = controlPlaneProtocol; + return self(); } + } + } diff --git a/system-tests/src/test/java/org/eclipse/edc/samples/util/ConfigPropertiesLoader.java b/system-tests/src/test/java/org/eclipse/edc/samples/util/ConfigPropertiesLoader.java new file mode 100644 index 00000000..747ebd45 --- /dev/null +++ b/system-tests/src/test/java/org/eclipse/edc/samples/util/ConfigPropertiesLoader.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * 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: + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation + * + */ + +package org.eclipse.edc.samples.util; + +import org.eclipse.edc.spi.EdcException; +import org.eclipse.edc.spi.system.configuration.Config; +import org.eclipse.edc.spi.system.configuration.ConfigFactory; + +import java.io.IOException; +import java.util.Properties; +import java.util.function.Supplier; + +import static org.eclipse.edc.samples.common.FileTransferCommon.getFileFromRelativePath; + +/** + * Load config from properties file + */ +public class ConfigPropertiesLoader implements Supplier { + + private final String path; + + public static ConfigPropertiesLoader fromPropertiesFile(String path) { + return new ConfigPropertiesLoader(path); + } + + public ConfigPropertiesLoader(String path) { + this.path = path; + } + + @Override + public Config get() { + var properties = new Properties(); + var filePath = getFileFromRelativePath(path).toURI(); + try (var stream = filePath.toURL().openStream()) { + properties.load(stream); + } catch (IOException e) { + throw new EdcException("Cannot load properties file " + filePath, e); + } + return ConfigFactory.fromProperties(properties); + } +}