From 7cd7b53f733b20c427f2f402dd7ddef2ac895b57 Mon Sep 17 00:00:00 2001 From: andrea bertagnolli Date: Thu, 23 Jan 2025 10:07:46 +0100 Subject: [PATCH] build: fix compilation (#133) --- .../cloud/fixtures/HuaweiParticipant.java | 38 ++++++++-------- .../cloud/tests/ObsTransferEndToEndTest.java | 10 ++--- .../cloud/tests/OtcTransferEndToEndTest.java | 38 +++++++--------- .../huawei/cloud/obs/ObsCoreExtension.java | 6 +-- .../provision/obs/ObsProvisionExtension.java | 2 +- .../GaussDbContractNegotiationStoreTest.java | 11 ----- .../GaussDbDataPlaneInstanceStoreTest.java | 44 ++++--------------- 7 files changed, 51 insertions(+), 98 deletions(-) diff --git a/e2e-tests/src/test/java/com/huawei/cloud/fixtures/HuaweiParticipant.java b/e2e-tests/src/test/java/com/huawei/cloud/fixtures/HuaweiParticipant.java index df50a0c..b569345 100644 --- a/e2e-tests/src/test/java/com/huawei/cloud/fixtures/HuaweiParticipant.java +++ b/e2e-tests/src/test/java/com/huawei/cloud/fixtures/HuaweiParticipant.java @@ -15,10 +15,12 @@ package com.huawei.cloud.fixtures; import com.fasterxml.jackson.annotation.JsonCreator; +import org.eclipse.edc.connector.controlplane.test.system.utils.LazySupplier; import org.eclipse.edc.connector.controlplane.test.system.utils.Participant; +import org.eclipse.edc.spi.system.configuration.Config; +import org.eclipse.edc.spi.system.configuration.ConfigFactory; import java.net.URI; -import java.time.Duration; import java.util.HashMap; import java.util.Map; @@ -30,30 +32,29 @@ public class HuaweiParticipant extends Participant { private static final String IAM_OTC_CLOUD_URL = "https://iam.eu-de.otc.t-systems.com"; - private static final Duration TIMEOUT = Duration.ofMillis(10000); - private Endpoint controlEndpoint; private String apiKey; + private final LazySupplier controlEndpoint = new LazySupplier<>(() -> URI.create("http://localhost:" + getFreePort() + "/control")); - public Endpoint getControlEndpoint() { - return controlEndpoint; + public URI getControlEndpoint() { + return controlEndpoint.get(); } - public Map controlPlaneConfiguration() { - return new HashMap<>() { + public Config controlPlaneConfig() { + var settings = (Map) new HashMap() { { put(PARTICIPANT_ID, id); put("edc.api.auth.key", apiKey); put("web.http.port", String.valueOf(getFreePort())); put("web.http.path", "/api"); - put("web.http.protocol.port", String.valueOf(protocolEndpoint.getUrl().getPort())); - put("web.http.protocol.path", protocolEndpoint.getUrl().getPath()); - put("web.http.management.port", String.valueOf(managementEndpoint.getUrl().getPort())); - put("web.http.management.path", managementEndpoint.getUrl().getPath()); - put("web.http.control.port", String.valueOf(controlEndpoint.getUrl().getPort())); - put("web.http.control.path", controlEndpoint.getUrl().getPath()); + put("web.http.protocol.port", String.valueOf(controlPlaneProtocol.get().getPort())); + put("web.http.protocol.path", controlPlaneProtocol.get().getPath()); + put("web.http.management.port", String.valueOf(controlPlaneManagement.get().getPort())); + put("web.http.management.path", controlPlaneManagement.get().getPath()); + put("web.http.control.port", String.valueOf(controlEndpoint.get().getPort())); + put("web.http.control.path", controlEndpoint.get().getPath()); put("web.http.public.path", "/public"); put("web.http.public.port", String.valueOf(getFreePort())); - put("edc.dsp.callback.address", protocolEndpoint.getUrl().toString()); + put("edc.dsp.callback.address", controlPlaneProtocol.get().toString()); put("edc.connector.name", name); put("edc.component.id", "connector-test"); put("edc.dataplane.token.validation.endpoint", "http://token-validation.com"); @@ -63,6 +64,8 @@ public Map controlPlaneConfiguration() { put("edc.transfer.proxy.token.signer.privatekey.alias", "privatekey"); } }; + + return ConfigFactory.fromMap(settings); } public static final class Builder extends Participant.Builder { @@ -83,11 +86,8 @@ public Builder apiKey(String apiKey) { @Override public HuaweiParticipant build() { - super.managementEndpoint(new Endpoint(URI.create("http://localhost:" + getFreePort() + "/api/management"), Map.of("X-Api-Key", participant.apiKey))); - super.protocolEndpoint(new Endpoint(URI.create("http://localhost:" + getFreePort() + "/protocol"))); - super.build(); - participant.controlEndpoint = new Endpoint(URI.create("http://localhost:" + getFreePort() + "/control"), Map.of()); - return participant; + participant.enrichManagementRequest = request -> request.header("X-Api-Key", participant.apiKey); + return super.build(); } } } diff --git a/e2e-tests/src/test/java/com/huawei/cloud/tests/ObsTransferEndToEndTest.java b/e2e-tests/src/test/java/com/huawei/cloud/tests/ObsTransferEndToEndTest.java index 2d40f97..7333b67 100644 --- a/e2e-tests/src/test/java/com/huawei/cloud/tests/ObsTransferEndToEndTest.java +++ b/e2e-tests/src/test/java/com/huawei/cloud/tests/ObsTransferEndToEndTest.java @@ -83,16 +83,14 @@ public class ObsTransferEndToEndTest { @RegisterExtension static RuntimeExtension consumer = new RuntimePerClassExtension(new EmbeddedRuntime( "consumer", - CONSUMER.controlPlaneConfiguration(), ":launchers:e2e-test" - )); + ).configurationProvider(CONSUMER::controlPlaneConfig)); @RegisterExtension static RuntimeExtension provider = new RuntimePerClassExtension(new EmbeddedRuntime( "provider", - PROVIDER.controlPlaneConfiguration(), ":launchers:e2e-test" - )); + ).configurationProvider(PROVIDER::controlPlaneConfig)); @Container private final GenericContainer providerContainer = new GenericContainer<>(MINIO_DOCKER_IMAGE) @@ -142,7 +140,7 @@ void transfer_singleFile() throws IOException { consumerClient.createBucket(destBucket); var flowRequest = createFlowRequest(destBucket, consumerEndpoint, srcBucket, TESTFILE_NAME, providerEndpoint).build(); - var url = PROVIDER.getControlEndpoint().getUrl().toString() + "/v1/dataflows"; + var url = PROVIDER.getControlEndpoint() + "/v1/dataflows"; var startMessage = registry.transform(flowRequest, JsonObject.class).orElseThrow(failTest()); @@ -178,7 +176,7 @@ void transfer_multipleFilesWithPrefix() throws IOException { consumerClient.createBucket(destBucket); var flowRequest = createFlowRequest(destBucket, consumerEndpoint, srcBucket, "file", providerEndpoint).build(); - var url = PROVIDER.getControlEndpoint().getUrl().toString() + "/v1/dataflows"; + var url = PROVIDER.getControlEndpoint() + "/v1/dataflows"; var startMessage = registry.transform(flowRequest, JsonObject.class).orElseThrow(failTest()); diff --git a/e2e-tests/src/test/java/com/huawei/cloud/tests/OtcTransferEndToEndTest.java b/e2e-tests/src/test/java/com/huawei/cloud/tests/OtcTransferEndToEndTest.java index 2fd1c18..d35bcf6 100644 --- a/e2e-tests/src/test/java/com/huawei/cloud/tests/OtcTransferEndToEndTest.java +++ b/e2e-tests/src/test/java/com/huawei/cloud/tests/OtcTransferEndToEndTest.java @@ -20,7 +20,6 @@ import com.huawei.cloud.obs.ObsClientProviderImpl; import com.huawei.cloud.obs.OtcTest; import com.obs.services.ObsClient; -import com.obs.services.model.ObsObject; import jakarta.json.Json; import jakarta.json.JsonObject; import jakarta.json.JsonValue; @@ -28,15 +27,15 @@ import org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcessStates; import org.eclipse.edc.connector.dataplane.spi.Endpoint; import org.eclipse.edc.connector.dataplane.spi.iam.PublicEndpointGeneratorService; -import org.eclipse.edc.junit.extensions.EdcClassRuntimesExtension; -import org.eclipse.edc.junit.extensions.EdcRuntimeExtension; +import org.eclipse.edc.junit.extensions.EmbeddedRuntime; +import org.eclipse.edc.junit.extensions.RuntimeExtension; +import org.eclipse.edc.junit.extensions.RuntimePerClassExtension; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import java.time.Duration; -import java.util.List; import java.util.Map; import java.util.UUID; @@ -68,23 +67,16 @@ public class OtcTransferEndToEndTest { private static final String OBS_OTC_CLOUD_URL = "https://obs.eu-de.otc.t-systems.com"; - static EdcRuntimeExtension providerRuntime = new EdcRuntimeExtension( - ":launchers:e2e-test", - "consumer", - CONSUMER.controlPlaneConfiguration() - ); + static EmbeddedRuntime providerRuntime = new EmbeddedRuntime("consumer", ":launchers:e2e-test") + .configurationProvider(CONSUMER::controlPlaneConfig); - static EdcRuntimeExtension consumerRuntime = new EdcRuntimeExtension( - ":launchers:e2e-test", - "provider", - PROVIDER.controlPlaneConfiguration() - ); + static EmbeddedRuntime consumerRuntime = new EmbeddedRuntime("provider", ":launchers:e2e-test") + .configurationProvider(PROVIDER::controlPlaneConfig); @RegisterExtension - static EdcClassRuntimesExtension runtimes = new EdcClassRuntimesExtension( - providerRuntime, - consumerRuntime - ); + static RuntimeExtension provider = new RuntimePerClassExtension(providerRuntime); + @RegisterExtension + static RuntimeExtension consumer = new RuntimePerClassExtension(consumerRuntime); private String id; private String sourceBucket; @@ -105,8 +97,8 @@ void setup() { var consumerClientProviderImp = (ObsClientProviderImpl) consumerRuntime.getService(ObsClientProvider.class); consumerClientProviderImp.getVault().storeSecret("publickey", PUBLIC_KEY); consumerClientProviderImp.getVault().storeSecret("privatekey", PRIVATE_KEY); - var providerEndpointGeneratorService = (PublicEndpointGeneratorService) providerRuntime.getService(PublicEndpointGeneratorService.class); - var consumerEndpointGeneratorService = (PublicEndpointGeneratorService) consumerRuntime.getService(PublicEndpointGeneratorService.class); + var providerEndpointGeneratorService = providerRuntime.getService(PublicEndpointGeneratorService.class); + var consumerEndpointGeneratorService = consumerRuntime.getService(PublicEndpointGeneratorService.class); var endpoint = new Endpoint("endpoint", "obs"); providerEndpointGeneratorService.addGeneratorFunction("HttpData", dataAddress1 -> endpoint); consumerEndpointGeneratorService.addGeneratorFunction("HttpData", dataAddress1 -> endpoint); @@ -132,7 +124,7 @@ void obsToObsTransfer() { assertThat(TransferProcessStates.valueOf(state).code()).isGreaterThanOrEqualTo(COMPLETED.code()); }); - List consumerObsObjectList = consumerClient.listObjects(destBucket).getObjects(); + var consumerObsObjectList = consumerClient.listObjects(destBucket).getObjects(); if (!consumerObsObjectList.isEmpty()) { assertThat(consumerObsObjectList) .allSatisfy(obsObject -> assertThat(obsObject.getObjectKey()).isEqualTo(TESTFILE_NAME)); @@ -146,8 +138,8 @@ void cleanup() { } private JsonObject getOfferForAsset(Participant provider, String assetId) { - JsonObject dataset = CONSUMER.getDatasetForAsset(provider, assetId); - JsonObject policy = ((JsonValue) dataset.getJsonArray("http://www.w3.org/ns/odrl/2/hasPolicy").get(0)).asJsonObject(); + var dataset = CONSUMER.getDatasetForAsset(provider, assetId); + var policy = dataset.getJsonArray("http://www.w3.org/ns/odrl/2/hasPolicy").get(0).asJsonObject(); return Json.createObjectBuilder(policy).add("http://www.w3.org/ns/odrl/2/assigner", Json.createObjectBuilder().add("@id", provider.getId())).add("http://www.w3.org/ns/odrl/2/target", Json.createObjectBuilder().add("@id", (JsonValue) dataset.get("@id"))).build(); } diff --git a/extensions/common/obs/obs-core/src/main/java/com/huawei/cloud/obs/ObsCoreExtension.java b/extensions/common/obs/obs-core/src/main/java/com/huawei/cloud/obs/ObsCoreExtension.java index 802e19a..9b58ce0 100644 --- a/extensions/common/obs/obs-core/src/main/java/com/huawei/cloud/obs/ObsCoreExtension.java +++ b/extensions/common/obs/obs-core/src/main/java/com/huawei/cloud/obs/ObsCoreExtension.java @@ -34,11 +34,11 @@ @Provides(ObsClientProvider.class) public class ObsCoreExtension implements ServiceExtension { - @Setting(value = "The key of the secret where the AWS Access Key Id is stored") + @Setting(description = "The key of the secret where the AWS Access Key Id is stored") public static final String HUAWEI_ACCESS_KEY = "edc.huawei.obs.alias.ak"; - @Setting(value = "The key of the secret where the AWS Secret Access Key is stored") + @Setting(description = "The key of the secret where the AWS Secret Access Key is stored") public static final String HUAWEI_SECRET_KEY = "edc.huawei.obs.alias.sk"; - @Setting(value = "If valued, the AWS clients will point to the specified endpoint") + @Setting(description = "If valued, the AWS clients will point to the specified endpoint") public static final String HUAWEI_IAM_ENDPOINT = "edc.huawei.iam.endpoint"; protected static final String NAME = "OBS Core"; private ObsClientProvider clientProvider; diff --git a/extensions/control-plane/provision-obs/src/main/java/com/huawei/cloud/provision/obs/ObsProvisionExtension.java b/extensions/control-plane/provision-obs/src/main/java/com/huawei/cloud/provision/obs/ObsProvisionExtension.java index 5a839aa..1f788b4 100644 --- a/extensions/control-plane/provision-obs/src/main/java/com/huawei/cloud/provision/obs/ObsProvisionExtension.java +++ b/extensions/control-plane/provision-obs/src/main/java/com/huawei/cloud/provision/obs/ObsProvisionExtension.java @@ -32,7 +32,7 @@ public class ObsProvisionExtension implements ServiceExtension { public static final String NAME = "OBS Provision"; - @Setting(value = "Duration in seconds of the temporary token", defaultValue = "" + ObsProvisionExtension.PROVISIONER_DEFAULT_TOKEN_DURATION) + @Setting(description = "Duration in seconds of the temporary token", defaultValue = "" + ObsProvisionExtension.PROVISIONER_DEFAULT_TOKEN_DURATION) private static final String PROVISION_TOKEN_DURATION = "edc.obs.provision.token.duration"; private static final int PROVISIONER_DEFAULT_TOKEN_DURATION = 60 * 30; diff --git a/extensions/control-plane/store/contract-negotiation-store-gaussdb/src/test/java/com/huawei/cloud/store/gaussdb/contractnegotiationstore/GaussDbContractNegotiationStoreTest.java b/extensions/control-plane/store/contract-negotiation-store-gaussdb/src/test/java/com/huawei/cloud/store/gaussdb/contractnegotiationstore/GaussDbContractNegotiationStoreTest.java index f711e70..5e44109 100644 --- a/extensions/control-plane/store/contract-negotiation-store-gaussdb/src/test/java/com/huawei/cloud/store/gaussdb/contractnegotiationstore/GaussDbContractNegotiationStoreTest.java +++ b/extensions/control-plane/store/contract-negotiation-store-gaussdb/src/test/java/com/huawei/cloud/store/gaussdb/contractnegotiationstore/GaussDbContractNegotiationStoreTest.java @@ -145,17 +145,6 @@ void findById_notExist() { assertThat(getContractNegotiationStore().findById("not-exist")).isNull(); } - @Test - @DisplayName("Find entity by its correlation ID") - void findForCorrelationId() { - var negotiation = createNegotiation("test-cn1"); - getContractNegotiationStore().save(negotiation); - - assertThat(getContractNegotiationStore().findForCorrelationId(negotiation.getCorrelationId())) - .usingRecursiveComparison() - .isEqualTo(negotiation); - } - @Test @DisplayName("Find ContractAgreement by contract ID") void findContractAgreement() { diff --git a/extensions/control-plane/store/data-plane-instance-store-gaussdb/src/test/java/com/huawei/cloud/store/gaussdb/assetindex/GaussDbDataPlaneInstanceStoreTest.java b/extensions/control-plane/store/data-plane-instance-store-gaussdb/src/test/java/com/huawei/cloud/store/gaussdb/assetindex/GaussDbDataPlaneInstanceStoreTest.java index 46ef038..c723d16 100644 --- a/extensions/control-plane/store/data-plane-instance-store-gaussdb/src/test/java/com/huawei/cloud/store/gaussdb/assetindex/GaussDbDataPlaneInstanceStoreTest.java +++ b/extensions/control-plane/store/data-plane-instance-store-gaussdb/src/test/java/com/huawei/cloud/store/gaussdb/assetindex/GaussDbDataPlaneInstanceStoreTest.java @@ -22,7 +22,6 @@ import org.eclipse.edc.connector.dataplane.selector.store.sql.SqlDataPlaneInstanceStore; import org.eclipse.edc.connector.dataplane.selector.store.sql.schema.DataPlaneInstanceStatements; import org.eclipse.edc.connector.dataplane.selector.store.sql.schema.postgres.PostgresDataPlaneInstanceStatements; -import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.sql.QueryExecutor; import org.eclipse.edc.transaction.datasource.spi.DataSourceRegistry; import org.eclipse.edc.transaction.spi.TransactionContext; @@ -39,7 +38,6 @@ import static com.huawei.cloud.gaussdb.testfixtures.GaussDbTestExtension.DEFAULT_DATASOURCE_NAME; import static org.assertj.core.api.Assertions.assertThat; -import static org.eclipse.edc.spi.result.StoreFailure.Reason.ALREADY_EXISTS; @GaussDbTest @ExtendWith(GaussDbTestExtension.class) @@ -59,7 +57,7 @@ static void deleteTable(GaussDbTestExtension.SqlHelper runner) { @BeforeEach void setup(GaussDbTestExtension.SqlHelper runner, TransactionContext transactionContext, QueryExecutor queryExecutor, DataSourceRegistry reg, Clock clock) { - String lease = "lease"; + var lease = "lease"; dataPlaneInstanceStore = new SqlDataPlaneInstanceStore(reg, DEFAULT_DATASOURCE_NAME, transactionContext, SQL_STATEMENTS, new ObjectMapper(), queryExecutor, clock, lease); runner.truncateTable("edc_data_plane_instance"); @@ -68,32 +66,14 @@ void setup(GaussDbTestExtension.SqlHelper runner, TransactionContext transaction @Test void save() { var inst = TestFunctions.createInstance("test-id"); - getStore().create(inst); + getStore().save(inst); assertThat(getStore().getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly(inst); } - @Test - void save_whenExists_shouldNotUpsert() { - var inst = TestFunctions.createInstance("test-id"); - getStore().create(inst); - - var inst2 = DataPlaneInstance.Builder.newInstance() - .id("test-id") - .url("http://somewhere.other:9876/api/v2") //different URL - .build(); - - var result = getStore().create(inst2); - - assertThat(result.failed()).isTrue(); - assertThat(result.getFailure().getReason()).isEqualTo(ALREADY_EXISTS); - - assertThat(getStore().getAll()).hasSize(1).usingRecursiveFieldByFieldElementComparator().containsExactly(inst); - } - @Test void update_whenExists_shouldUpdate() { var inst = TestFunctions.createInstance("test-id"); - getStore().create(inst); + getStore().save(inst); var inst2 = DataPlaneInstance.Builder.newInstance() @@ -101,9 +81,7 @@ void update_whenExists_shouldUpdate() { .url("http://somewhere.other:9876/api/v2") //different URL .build(); - var result = getStore().update(inst2); - - assertThat(result.succeeded()).isTrue(); + getStore().save(inst2); assertThat(getStore().getAll()).hasSize(1).usingRecursiveFieldByFieldElementComparator().containsExactly(inst2); } @@ -112,7 +90,7 @@ void update_whenExists_shouldUpdate() { void save_shouldReturnCustomInstance() { var custom = TestFunctions.createCustomInstance("test-id", "name"); - getStore().create(custom); + getStore().save(custom); var customInstance = getStore().findById(custom.getId()); @@ -126,7 +104,7 @@ void save_shouldReturnCustomInstance() { @Test void findById() { var inst = TestFunctions.createInstance("test-id"); - getStore().create(inst); + getStore().save(inst); assertThat(getStore().findById("test-id")).usingRecursiveComparison().isEqualTo(inst); } @@ -143,8 +121,8 @@ void getAll() { var store = getStore(); - store.create(doc1); - store.create(doc2); + store.save(doc1); + store.save(doc2); var foundItems = store.getAll(); @@ -159,10 +137,6 @@ public class TestFunctions { TestFunctions() { } - public static DataAddress createAddress(String type) { - return DataAddress.Builder.newInstance().type("test-type").keyName(type).property("someprop", "someval").build(); - } - public static DataPlaneInstance createInstance(String id) { return org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.Builder.newInstance().id(id).url("http://somewhere.com:1234/api/v1").build(); } @@ -172,4 +146,4 @@ public static DataPlaneInstance createCustomInstance(String id, String name) { } } -} \ No newline at end of file +}