diff --git a/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/lifecycle/DimParticipant.java b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/lifecycle/DimParticipant.java index 29ff7540c..348398439 100644 --- a/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/lifecycle/DimParticipant.java +++ b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/lifecycle/DimParticipant.java @@ -19,7 +19,7 @@ package org.eclipse.tractusx.edc.lifecycle; -import org.eclipse.tractusx.edc.tests.TractusxIatpParticipantBase; +import org.eclipse.tractusx.edc.tests.participant.TractusxIatpParticipantBase; import java.net.URI; import java.util.HashMap; @@ -42,7 +42,7 @@ public Map iatpConfiguration(TractusxIatpParticipantBase... othe } public static class Builder extends TractusxIatpParticipantBase.Builder { - + protected Builder() { super(new DimParticipant()); } diff --git a/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/lifecycle/MiwParticipant.java b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/lifecycle/MiwParticipant.java index 1db4c37a5..b20aa6e08 100644 --- a/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/lifecycle/MiwParticipant.java +++ b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/lifecycle/MiwParticipant.java @@ -19,7 +19,7 @@ package org.eclipse.tractusx.edc.lifecycle; -import org.eclipse.tractusx.edc.tests.TractusxParticipantBase; +import org.eclipse.tractusx.edc.tests.participant.TractusxParticipantBase; import java.util.HashMap; import java.util.Map; @@ -29,7 +29,7 @@ * Extension of {@link TractusxParticipantBase} with MIW specific configuration */ public class MiwParticipant extends TractusxParticipantBase { - + protected String miwUri; protected String oauth2Uri; diff --git a/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/DimCatalogTest.java b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/DimCatalogIntegrationTest.java similarity index 98% rename from edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/DimCatalogTest.java rename to edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/DimCatalogIntegrationTest.java index 1d0cb3edd..4e59c58cc 100644 --- a/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/DimCatalogTest.java +++ b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/DimCatalogIntegrationTest.java @@ -41,7 +41,7 @@ @DimIntegrationTest @Disabled -public class DimCatalogTest { +public class DimCatalogIntegrationTest { protected static final DimParticipant SOKRATES = configureParticipant(SOKRATES_NAME); protected static final DimParticipant PLATO = configureParticipant(PLATO_NAME); diff --git a/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/DimHttpPullTransferTest.java b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/DimHttpPullTransferIntegrationTest.java similarity index 89% rename from edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/DimHttpPullTransferTest.java rename to edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/DimHttpPullTransferIntegrationTest.java index e70bc2697..2c9c80ef8 100644 --- a/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/DimHttpPullTransferTest.java +++ b/edc-tests/e2e-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/DimHttpPullTransferIntegrationTest.java @@ -22,7 +22,7 @@ import org.eclipse.tractusx.edc.lifecycle.DimParticipant; import org.eclipse.tractusx.edc.lifecycle.ParticipantRuntime; import org.eclipse.tractusx.edc.tag.DimIntegrationTest; -import org.eclipse.tractusx.edc.tests.TractusxParticipantBase; +import org.eclipse.tractusx.edc.tests.participant.TractusxParticipantBase; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.extension.RegisterExtension; @@ -33,7 +33,7 @@ @DimIntegrationTest @Disabled -public class DimHttpPullTransferTest extends HttpConsumerPullBaseTest { +public class DimHttpPullTransferIntegrationTest extends HttpConsumerPullBaseTest { protected static final DimParticipant SOKRATES = configureParticipant(SOKRATES_NAME); protected static final DimParticipant PLATO = configureParticipant(PLATO_NAME); @@ -45,12 +45,12 @@ public class DimHttpPullTransferTest extends HttpConsumerPullBaseTest { protected static final ParticipantRuntime SOKRATES_RUNTIME = dimRuntime(SOKRATES.getName(), SOKRATES.iatpConfiguration(PLATO)); @Override - protected TractusxParticipantBase plato() { + public TractusxParticipantBase plato() { return PLATO; } @Override - protected TractusxParticipantBase sokrates() { + public TractusxParticipantBase sokrates() { return SOKRATES; } } diff --git a/edc-tests/edc-controlplane/catalog-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/AbstractCatalogTest.java b/edc-tests/edc-controlplane/catalog-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/AbstractCatalogTest.java deleted file mode 100644 index 063c16439..000000000 --- a/edc-tests/edc-controlplane/catalog-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/AbstractCatalogTest.java +++ /dev/null @@ -1,205 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * 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. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.edc.tests.catalog; - - -import org.eclipse.edc.policy.model.Operator; -import org.eclipse.tractusx.edc.tests.TxParticipant; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; - -import java.util.Map; - -import static java.util.stream.IntStream.range; -import static org.assertj.core.api.Assertions.assertThat; -import static org.eclipse.edc.test.system.utils.PolicyFixtures.noConstraintPolicy; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_BPN; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_NAME; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_BPN; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_NAME; -import static org.eclipse.tractusx.edc.tests.helpers.CatalogHelperFunctions.getDatasetAssetId; -import static org.eclipse.tractusx.edc.tests.helpers.CatalogHelperFunctions.getDatasetPolicies; -import static org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions.BUSINESS_PARTNER_LEGACY_EVALUATION_KEY; -import static org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions.bnpPolicy; -import static org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions.bpnGroupPolicy; -import static org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions.frameworkPolicy; -import static org.eclipse.tractusx.edc.tests.helpers.QueryHelperFunctions.createQuery; - -public abstract class AbstractCatalogTest { - - - protected static final TxParticipant SOKRATES = TxParticipant.Builder.newInstance() - .name(SOKRATES_NAME) - .id(SOKRATES_BPN) - .build(); - - - protected static final TxParticipant PLATO = TxParticipant.Builder.newInstance() - .name(PLATO_NAME) - .id(PLATO_BPN) - .build(); - - - @Test - @DisplayName("Plato gets catalog from Sokrates. No constraints.") - void requestCatalog_fulfillsPolicy_shouldReturnOffer() { - // arrange - SOKRATES.createAsset("test-asset"); - var ap = SOKRATES.createPolicyDefinition(noConstraintPolicy()); - var cp = SOKRATES.createPolicyDefinition(noConstraintPolicy()); - SOKRATES.createContractDefinition("test-asset", "test-def", ap, cp); - - // act - var catalog = PLATO.getCatalogDatasets(SOKRATES); - - // assert - assertThat(catalog).isNotEmpty() - .hasSize(1) - .allSatisfy(co -> { - assertThat(getDatasetAssetId(co)).isEqualTo("test-asset"); - }); - - } - - @Test - @DisplayName("Verify that Plato receives only the offers he is permitted to (using the legacy BPN validation)") - void requestCatalog_filteredByBpnLegacy_shouldReject() { - var onlyPlatoPolicy = bnpPolicy("BPN1", "BPN2", PLATO.getBpn()); - var onlyDiogenesPolicy = bnpPolicy("ARISTOTELES-BPN"); - - var onlyPlatoId = SOKRATES.createPolicyDefinition(onlyPlatoPolicy); - var onlyDiogenesId = SOKRATES.createPolicyDefinition(onlyDiogenesPolicy); - var noConstraintPolicyId = SOKRATES.createPolicyDefinition(noConstraintPolicy()); - - SOKRATES.createAsset("test-asset1"); - SOKRATES.createAsset("test-asset2"); - SOKRATES.createAsset("test-asset3"); - - SOKRATES.createContractDefinition("test-asset1", "def1", noConstraintPolicyId, noConstraintPolicyId); - SOKRATES.createContractDefinition("test-asset2", "def2", onlyPlatoId, noConstraintPolicyId); - SOKRATES.createContractDefinition("test-asset3", "def3", onlyDiogenesId, noConstraintPolicyId); - - - // act - var catalog = PLATO.getCatalogDatasets(SOKRATES); - assertThat(catalog).hasSize(2); - } - - - @Test - @DisplayName("Verify that Plato receives only the offers he is permitted to (using the legacy BPN validation)") - void requestCatalog_filteredByBpnLegacy_WithNamespace_shouldReject() { - - var onlyPlatoPolicy = bnpPolicy("BPN1", "BPN2", PLATO.getBpn()); - var onlyDiogenesPolicy = frameworkPolicy(Map.of(BUSINESS_PARTNER_LEGACY_EVALUATION_KEY, "ARISTOTELES-BPN")); - - var onlyPlatoId = SOKRATES.createPolicyDefinition(onlyPlatoPolicy); - var onlyDiogenesId = SOKRATES.createPolicyDefinition(onlyDiogenesPolicy); - var noConstraintPolicyId = SOKRATES.createPolicyDefinition(noConstraintPolicy()); - - SOKRATES.createAsset("test-asset1"); - SOKRATES.createAsset("test-asset2"); - SOKRATES.createAsset("test-asset3"); - - SOKRATES.createContractDefinition("test-asset1", "def1", noConstraintPolicyId, noConstraintPolicyId); - SOKRATES.createContractDefinition("test-asset2", "def2", onlyPlatoId, noConstraintPolicyId); - SOKRATES.createContractDefinition("test-asset3", "def3", onlyDiogenesId, noConstraintPolicyId); - - - // act - var catalog = PLATO.getCatalogDatasets(SOKRATES); - assertThat(catalog).hasSize(2); - } - - @Test - @DisplayName("Verify that Plato receives only the offers he is permitted to (using the new BPN validation)") - void requestCatalog_filteredByBpn_shouldReject() { - - var mustBeGreekPhilosopher = bpnGroupPolicy(Operator.IS_ANY_OF, "greek_customer", "philosopher"); - var mustBeGreekMathematician = bpnGroupPolicy(Operator.IS_ALL_OF, "greek_customer", "mathematician"); - - - SOKRATES.storeBusinessPartner(PLATO.getBpn(), "greek_customer", "philosopher"); - var philosopherId = SOKRATES.createPolicyDefinition(mustBeGreekPhilosopher); - var mathId = SOKRATES.createPolicyDefinition(mustBeGreekMathematician); - var noConstraintPolicyId = SOKRATES.createPolicyDefinition(noConstraintPolicy()); - - SOKRATES.createAsset("test-asset1"); - SOKRATES.createAsset("test-asset2"); - SOKRATES.createAsset("test-asset3"); - - SOKRATES.createContractDefinition("test-asset1", "def1", noConstraintPolicyId, noConstraintPolicyId); - SOKRATES.createContractDefinition("test-asset2", "def2", philosopherId, noConstraintPolicyId); - SOKRATES.createContractDefinition("test-asset3", "def3", mathId, noConstraintPolicyId); - - - // act - var catalog = PLATO.getCatalogDatasets(SOKRATES); - assertThat(catalog).hasSize(2); - } - - @Test - @DisplayName("Multiple ContractDefinitions exist for one Asset") - void requestCatalog_multipleOffersForAsset() { - SOKRATES.storeBusinessPartner(PLATO.getBpn(), "test-group"); - SOKRATES.createAsset("asset-1"); - var noConstraintId = SOKRATES.createPolicyDefinition(noConstraintPolicy()); - var groupConstraintId = SOKRATES.createPolicyDefinition(bpnGroupPolicy(Operator.IS_ANY_OF, "test-group")); - - SOKRATES.createContractDefinition("asset-1", "def1", noConstraintId, noConstraintId); - SOKRATES.createContractDefinition("asset-1", "def2", groupConstraintId, noConstraintId); - - var catalog = PLATO.getCatalogDatasets(SOKRATES); - assertThat(catalog).hasSize(1) - .allSatisfy(cd -> { - assertThat(getDatasetAssetId(cd)).isEqualTo("asset-1"); - assertThat(getDatasetPolicies(cd)).hasSize(2); - }); - } - - @Test - @DisplayName("Catalog with 1000 offers") - void requestCatalog_of1000Assets_shouldContainAll() { - var policy = bpnGroupPolicy(Operator.IS_NONE_OF, "test-group1", "test-group2"); - var policyId = SOKRATES.createPolicyDefinition(policy); - var noConstraintId = SOKRATES.createPolicyDefinition(noConstraintPolicy()); - SOKRATES.storeBusinessPartner(PLATO.getBpn(), "test-group-3"); - - range(0, 1000) - .forEach(i -> { - var assetId = "asset-" + i; - SOKRATES.createAsset(assetId); - SOKRATES.createContractDefinition(assetId, "def-" + i, policyId, noConstraintId); - }); - - // request all at once - var dataset = PLATO.getCatalogDatasets(SOKRATES, createQuery(1000, 0)); - assertThat(dataset).hasSize(1000); - - // request in chunks - var o2 = PLATO.getCatalogDatasets(SOKRATES, createQuery(500, 0)); - var o3 = PLATO.getCatalogDatasets(SOKRATES, createQuery(500, 500)); - assertThat(o2).doesNotContainAnyElementsOf(o3); - - } - - -} - diff --git a/edc-tests/edc-controlplane/catalog-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/CatalogInMemoryTest.java b/edc-tests/edc-controlplane/catalog-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/CatalogInMemoryTest.java deleted file mode 100644 index 17e3496cd..000000000 --- a/edc-tests/edc-controlplane/catalog-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/CatalogInMemoryTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * 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. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.edc.tests.catalog; - -import org.eclipse.edc.junit.annotations.EndToEndTest; -import org.eclipse.tractusx.edc.tests.runtimes.ParticipantRuntime; -import org.junit.jupiter.api.extension.RegisterExtension; - -@EndToEndTest -public class CatalogInMemoryTest extends AbstractCatalogTest { - - @RegisterExtension - protected static final ParticipantRuntime SOKRATES_RUNTIME = new ParticipantRuntime( - ":edc-tests:runtime:runtime-memory", - SOKRATES.getName(), - SOKRATES.getBpn(), - SOKRATES.getConfiguration() - ); - - @RegisterExtension - protected static final ParticipantRuntime PLATO_RUNTIME = new ParticipantRuntime( - ":edc-tests:runtime:runtime-memory", - PLATO.getName(), - PLATO.getBpn(), - PLATO.getConfiguration() - ); -} diff --git a/edc-tests/edc-controlplane/catalog-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/CatalogPostgresqlTest.java b/edc-tests/edc-controlplane/catalog-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/CatalogPostgresqlTest.java deleted file mode 100644 index a7a8cb0bf..000000000 --- a/edc-tests/edc-controlplane/catalog-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/CatalogPostgresqlTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * 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. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.edc.tests.catalog; - -import org.eclipse.edc.junit.annotations.PostgresqlIntegrationTest; -import org.eclipse.tractusx.edc.tests.runtimes.PgParticipantRuntime; -import org.junit.jupiter.api.extension.RegisterExtension; - -@PostgresqlIntegrationTest -public class CatalogPostgresqlTest extends AbstractCatalogTest { - - @RegisterExtension - protected static final PgParticipantRuntime SOKRATES_RUNTIME = new PgParticipantRuntime( - ":edc-tests:runtime:runtime-postgresql", - SOKRATES.getName(), - SOKRATES.getBpn(), - SOKRATES.getConfiguration() - ); - @RegisterExtension - protected static final PgParticipantRuntime PLATO_RUNTIME = new PgParticipantRuntime( - ":edc-tests:runtime:runtime-postgresql", - PLATO.getName(), - PLATO.getBpn(), - PLATO.getConfiguration() - ); -} diff --git a/edc-tests/edc-controlplane/catalog-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/CatalogTest.java b/edc-tests/edc-controlplane/catalog-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/CatalogTest.java new file mode 100644 index 000000000..f2a835960 --- /dev/null +++ b/edc-tests/edc-controlplane/catalog-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/CatalogTest.java @@ -0,0 +1,235 @@ +/******************************************************************************** + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * 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. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.edc.tests.catalog; + +import org.eclipse.edc.junit.annotations.EndToEndTest; +import org.eclipse.edc.junit.annotations.PostgresqlIntegrationTest; +import org.eclipse.edc.policy.model.Operator; +import org.eclipse.tractusx.edc.tests.participant.TransferParticipant; +import org.eclipse.tractusx.edc.tests.runtimes.ParticipantRuntime; +import org.eclipse.tractusx.edc.tests.runtimes.PgParticipantRuntime; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import java.util.Map; + +import static java.util.stream.IntStream.range; +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.test.system.utils.PolicyFixtures.noConstraintPolicy; +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_BPN; +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_NAME; +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_BPN; +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_NAME; +import static org.eclipse.tractusx.edc.tests.helpers.CatalogHelperFunctions.getDatasetAssetId; +import static org.eclipse.tractusx.edc.tests.helpers.CatalogHelperFunctions.getDatasetPolicies; +import static org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions.BUSINESS_PARTNER_LEGACY_EVALUATION_KEY; +import static org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions.bnpPolicy; +import static org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions.bpnGroupPolicy; +import static org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions.frameworkPolicy; +import static org.eclipse.tractusx.edc.tests.helpers.QueryHelperFunctions.createQuery; +import static org.eclipse.tractusx.edc.tests.runtimes.Runtimes.memoryRuntime; +import static org.eclipse.tractusx.edc.tests.runtimes.Runtimes.pgRuntime; + +public class CatalogTest { + + protected static final TransferParticipant SOKRATES = TransferParticipant.Builder.newInstance() + .name(SOKRATES_NAME) + .id(SOKRATES_BPN) + .build(); + + + protected static final TransferParticipant PLATO = TransferParticipant.Builder.newInstance() + .name(PLATO_NAME) + .id(PLATO_BPN) + .build(); + + + abstract static class Tests { + @Test + @DisplayName("Plato gets catalog from Sokrates. No constraints.") + void requestCatalog_fulfillsPolicy_shouldReturnOffer() { + // arrange + SOKRATES.createAsset("test-asset"); + var ap = SOKRATES.createPolicyDefinition(noConstraintPolicy()); + var cp = SOKRATES.createPolicyDefinition(noConstraintPolicy()); + SOKRATES.createContractDefinition("test-asset", "test-def", ap, cp); + + // act + var catalog = PLATO.getCatalogDatasets(SOKRATES); + + // assert + assertThat(catalog).isNotEmpty() + .hasSize(1) + .allSatisfy(co -> { + assertThat(getDatasetAssetId(co)).isEqualTo("test-asset"); + }); + + } + + @Test + @DisplayName("Verify that Plato receives only the offers he is permitted to (using the legacy BPN validation)") + void requestCatalog_filteredByBpnLegacy_shouldReject() { + var onlyPlatoPolicy = bnpPolicy("BPN1", "BPN2", PLATO.getBpn()); + var onlyDiogenesPolicy = bnpPolicy("ARISTOTELES-BPN"); + + var onlyPlatoId = SOKRATES.createPolicyDefinition(onlyPlatoPolicy); + var onlyDiogenesId = SOKRATES.createPolicyDefinition(onlyDiogenesPolicy); + var noConstraintPolicyId = SOKRATES.createPolicyDefinition(noConstraintPolicy()); + + SOKRATES.createAsset("test-asset1"); + SOKRATES.createAsset("test-asset2"); + SOKRATES.createAsset("test-asset3"); + + SOKRATES.createContractDefinition("test-asset1", "def1", noConstraintPolicyId, noConstraintPolicyId); + SOKRATES.createContractDefinition("test-asset2", "def2", onlyPlatoId, noConstraintPolicyId); + SOKRATES.createContractDefinition("test-asset3", "def3", onlyDiogenesId, noConstraintPolicyId); + + + // act + var catalog = PLATO.getCatalogDatasets(SOKRATES); + assertThat(catalog).hasSize(2); + } + + + @Test + @DisplayName("Verify that Plato receives only the offers he is permitted to (using the legacy BPN validation)") + void requestCatalog_filteredByBpnLegacy_WithNamespace_shouldReject() { + + var onlyPlatoPolicy = bnpPolicy("BPN1", "BPN2", PLATO.getBpn()); + var onlyDiogenesPolicy = frameworkPolicy(Map.of(BUSINESS_PARTNER_LEGACY_EVALUATION_KEY, "ARISTOTELES-BPN")); + + var onlyPlatoId = SOKRATES.createPolicyDefinition(onlyPlatoPolicy); + var onlyDiogenesId = SOKRATES.createPolicyDefinition(onlyDiogenesPolicy); + var noConstraintPolicyId = SOKRATES.createPolicyDefinition(noConstraintPolicy()); + + SOKRATES.createAsset("test-asset1"); + SOKRATES.createAsset("test-asset2"); + SOKRATES.createAsset("test-asset3"); + + SOKRATES.createContractDefinition("test-asset1", "def1", noConstraintPolicyId, noConstraintPolicyId); + SOKRATES.createContractDefinition("test-asset2", "def2", onlyPlatoId, noConstraintPolicyId); + SOKRATES.createContractDefinition("test-asset3", "def3", onlyDiogenesId, noConstraintPolicyId); + + + // act + var catalog = PLATO.getCatalogDatasets(SOKRATES); + assertThat(catalog).hasSize(2); + } + + @Test + @DisplayName("Verify that Plato receives only the offers he is permitted to (using the new BPN validation)") + void requestCatalog_filteredByBpn_shouldReject() { + + var mustBeGreekPhilosopher = bpnGroupPolicy(Operator.IS_ANY_OF, "greek_customer", "philosopher"); + var mustBeGreekMathematician = bpnGroupPolicy(Operator.IS_ALL_OF, "greek_customer", "mathematician"); + + + SOKRATES.storeBusinessPartner(PLATO.getBpn(), "greek_customer", "philosopher"); + var philosopherId = SOKRATES.createPolicyDefinition(mustBeGreekPhilosopher); + var mathId = SOKRATES.createPolicyDefinition(mustBeGreekMathematician); + var noConstraintPolicyId = SOKRATES.createPolicyDefinition(noConstraintPolicy()); + + SOKRATES.createAsset("test-asset1"); + SOKRATES.createAsset("test-asset2"); + SOKRATES.createAsset("test-asset3"); + + SOKRATES.createContractDefinition("test-asset1", "def1", noConstraintPolicyId, noConstraintPolicyId); + SOKRATES.createContractDefinition("test-asset2", "def2", philosopherId, noConstraintPolicyId); + SOKRATES.createContractDefinition("test-asset3", "def3", mathId, noConstraintPolicyId); + + + // act + var catalog = PLATO.getCatalogDatasets(SOKRATES); + assertThat(catalog).hasSize(2); + } + + @Test + @DisplayName("Multiple ContractDefinitions exist for one Asset") + void requestCatalog_multipleOffersForAsset() { + SOKRATES.storeBusinessPartner(PLATO.getBpn(), "test-group"); + SOKRATES.createAsset("asset-1"); + var noConstraintId = SOKRATES.createPolicyDefinition(noConstraintPolicy()); + var groupConstraintId = SOKRATES.createPolicyDefinition(bpnGroupPolicy(Operator.IS_ANY_OF, "test-group")); + + SOKRATES.createContractDefinition("asset-1", "def1", noConstraintId, noConstraintId); + SOKRATES.createContractDefinition("asset-1", "def2", groupConstraintId, noConstraintId); + + var catalog = PLATO.getCatalogDatasets(SOKRATES); + assertThat(catalog).hasSize(1) + .allSatisfy(cd -> { + assertThat(getDatasetAssetId(cd)).isEqualTo("asset-1"); + assertThat(getDatasetPolicies(cd)).hasSize(2); + }); + } + + @Test + @DisplayName("Catalog with 1000 offers") + void requestCatalog_of1000Assets_shouldContainAll() { + var policy = bpnGroupPolicy(Operator.IS_NONE_OF, "test-group1", "test-group2"); + var policyId = SOKRATES.createPolicyDefinition(policy); + var noConstraintId = SOKRATES.createPolicyDefinition(noConstraintPolicy()); + SOKRATES.storeBusinessPartner(PLATO.getBpn(), "test-group-3"); + + range(0, 1000) + .forEach(i -> { + var assetId = "asset-" + i; + SOKRATES.createAsset(assetId); + SOKRATES.createContractDefinition(assetId, "def-" + i, policyId, noConstraintId); + }); + + // request all at once + var dataset = PLATO.getCatalogDatasets(SOKRATES, createQuery(1000, 0)); + assertThat(dataset).hasSize(1000); + + // request in chunks + var o2 = PLATO.getCatalogDatasets(SOKRATES, createQuery(500, 0)); + var o3 = PLATO.getCatalogDatasets(SOKRATES, createQuery(500, 500)); + assertThat(o2).doesNotContainAnyElementsOf(o3); + + } + } + + @Nested + @EndToEndTest + class InMemory extends Tests { + + @RegisterExtension + protected static final ParticipantRuntime SOKRATES_RUNTIME = memoryRuntime(SOKRATES.getName(), SOKRATES.getBpn(), SOKRATES.getConfiguration()); + + @RegisterExtension + protected static final ParticipantRuntime PLATO_RUNTIME = memoryRuntime(PLATO.getName(), PLATO.getBpn(), PLATO.getConfiguration()); + + } + + @Nested + @PostgresqlIntegrationTest + class Postgres extends Tests { + + @RegisterExtension + protected static final PgParticipantRuntime SOKRATES_RUNTIME = pgRuntime(SOKRATES.getName(), SOKRATES.getBpn(), SOKRATES.getConfiguration()); + + @RegisterExtension + protected static final PgParticipantRuntime PLATO_RUNTIME = pgRuntime(PLATO.getName(), PLATO.getBpn(), PLATO.getConfiguration()); + + } + +} diff --git a/edc-tests/edc-controlplane/edr-api-tests/src/test/java/org/eclipse/tractusx/edc/tests/edrv2/AbstractNegotiateEdrTest.java b/edc-tests/edc-controlplane/edr-api-tests/src/test/java/org/eclipse/tractusx/edc/tests/edrv2/AbstractNegotiateEdrTest.java index 824c2f891..6e355b2ba 100644 --- a/edc-tests/edc-controlplane/edr-api-tests/src/test/java/org/eclipse/tractusx/edc/tests/edrv2/AbstractNegotiateEdrTest.java +++ b/edc-tests/edc-controlplane/edr-api-tests/src/test/java/org/eclipse/tractusx/edc/tests/edrv2/AbstractNegotiateEdrTest.java @@ -33,9 +33,9 @@ import org.eclipse.edc.connector.transfer.spi.event.TransferProcessStarted; import org.eclipse.edc.policy.model.Operator; import org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration; -import org.eclipse.tractusx.edc.tests.TxParticipant; import org.eclipse.tractusx.edc.tests.helpers.EdrNegotiationHelperFunctions; import org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions; +import org.eclipse.tractusx.edc.tests.participant.TransferParticipant; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -49,19 +49,19 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; -import static org.eclipse.tractusx.edc.tests.TxParticipant.ASYNC_POLL_INTERVAL; -import static org.eclipse.tractusx.edc.tests.TxParticipant.ASYNC_TIMEOUT; import static org.eclipse.tractusx.edc.tests.helpers.EdrNegotiationHelperFunctions.createEvent; import static org.eclipse.tractusx.edc.tests.helpers.Functions.waitForEvent; +import static org.eclipse.tractusx.edc.tests.participant.TractusxParticipantBase.ASYNC_POLL_INTERVAL; +import static org.eclipse.tractusx.edc.tests.participant.TractusxParticipantBase.ASYNC_TIMEOUT; public abstract class AbstractNegotiateEdrTest { - protected static final TxParticipant SOKRATES = TxParticipant.Builder.newInstance() + protected static final TransferParticipant SOKRATES = TransferParticipant.Builder.newInstance() .name(TestRuntimeConfiguration.SOKRATES_NAME) .id(TestRuntimeConfiguration.SOKRATES_BPN) .build(); - protected static final TxParticipant PLATO = TxParticipant.Builder.newInstance() + protected static final TransferParticipant PLATO = TransferParticipant.Builder.newInstance() .name(TestRuntimeConfiguration.PLATO_NAME) .id(TestRuntimeConfiguration.PLATO_BPN) .build(); diff --git a/edc-tests/edc-controlplane/edr-api-tests/src/test/java/org/eclipse/tractusx/edc/tests/edrv2/EdrCacheApiEndToEndTest.java b/edc-tests/edc-controlplane/edr-api-tests/src/test/java/org/eclipse/tractusx/edc/tests/edrv2/EdrCacheApiEndToEndTest.java index 74486302e..b9a760e17 100644 --- a/edc-tests/edc-controlplane/edr-api-tests/src/test/java/org/eclipse/tractusx/edc/tests/edrv2/EdrCacheApiEndToEndTest.java +++ b/edc-tests/edc-controlplane/edr-api-tests/src/test/java/org/eclipse/tractusx/edc/tests/edrv2/EdrCacheApiEndToEndTest.java @@ -37,7 +37,7 @@ import org.eclipse.edc.junit.annotations.EndToEndTest; import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.tractusx.edc.spi.tokenrefresh.dataplane.model.TokenResponse; -import org.eclipse.tractusx.edc.tests.TxParticipant; +import org.eclipse.tractusx.edc.tests.participant.TransferParticipant; import org.eclipse.tractusx.edc.tests.runtimes.ParticipantRuntime; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -73,7 +73,7 @@ */ @EndToEndTest public class EdrCacheApiEndToEndTest { - protected static final TxParticipant SOKRATES = TxParticipant.Builder.newInstance() + protected static final TransferParticipant SOKRATES = TransferParticipant.Builder.newInstance() .name("sokrates") .id("BPN00001") .build(); diff --git a/edc-tests/edc-controlplane/edr-api-tests/src/test/java/org/eclipse/tractusx/edc/tests/edrv2/NegotiateEdrInMemoryTest.java b/edc-tests/edc-controlplane/edr-api-tests/src/test/java/org/eclipse/tractusx/edc/tests/edrv2/NegotiateEdrInMemoryTest.java index 974969b0f..dd25e45e1 100644 --- a/edc-tests/edc-controlplane/edr-api-tests/src/test/java/org/eclipse/tractusx/edc/tests/edrv2/NegotiateEdrInMemoryTest.java +++ b/edc-tests/edc-controlplane/edr-api-tests/src/test/java/org/eclipse/tractusx/edc/tests/edrv2/NegotiateEdrInMemoryTest.java @@ -20,15 +20,10 @@ package org.eclipse.tractusx.edc.tests.edrv2; -import com.nimbusds.jose.util.Base64; import org.eclipse.edc.junit.annotations.EndToEndTest; -import org.eclipse.edc.spi.security.Vault; import org.eclipse.tractusx.edc.tests.runtimes.ParticipantRuntime; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.extension.RegisterExtension; -import java.security.SecureRandom; - @EndToEndTest public class NegotiateEdrInMemoryTest extends AbstractNegotiateEdrTest { @@ -48,16 +43,4 @@ public class NegotiateEdrInMemoryTest extends AbstractNegotiateEdrTest { PLATO.getConfiguration() ); - @BeforeAll - static void prepare() { - var bytes = new byte[32]; - - new SecureRandom().nextBytes(bytes); - var value = Base64.encode(bytes).toString(); - var vault = SOKRATES_RUNTIME.getContext().getService(Vault.class); - vault.storeSecret("test-alias", value); - vault = PLATO_RUNTIME.getContext().getService(Vault.class); - vault.storeSecret("test-alias", value); - - } } diff --git a/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/ParticipantAwareTest.java b/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/ParticipantAwareTest.java new file mode 100644 index 000000000..26cddc343 --- /dev/null +++ b/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/ParticipantAwareTest.java @@ -0,0 +1,29 @@ +/******************************************************************************** + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * 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. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.edc.tests; + +import org.eclipse.tractusx.edc.tests.participant.TractusxParticipantBase; + +public interface ParticipantAwareTest { + + TractusxParticipantBase plato(); + + TractusxParticipantBase sokrates(); +} diff --git a/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/ParticipantEdrApi.java b/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/ParticipantEdrApi.java index 443dd8967..fccc1bb0d 100644 --- a/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/ParticipantEdrApi.java +++ b/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/ParticipantEdrApi.java @@ -25,6 +25,7 @@ import jakarta.json.JsonArray; import jakarta.json.JsonObject; import org.eclipse.edc.test.system.utils.Participant; +import org.eclipse.tractusx.edc.tests.participant.TransferParticipant; import static io.restassured.http.ContentType.JSON; import static jakarta.json.Json.createObjectBuilder; @@ -109,7 +110,7 @@ public ValidatableResponse refreshEdr(String transferProcessId) { * @param callbacks The callbacks * @return The contract negotiation id */ - public String negotiateEdr(TxParticipant other, String assetId, JsonArray callbacks) { + public String negotiateEdr(TransferParticipant other, String assetId, JsonArray callbacks) { var dataset = participant.getDatasetForAsset(other, assetId); assertThat(dataset).withFailMessage("Catalog received from " + other.getName() + " was empty!").isNotEmpty(); diff --git a/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/TxParticipant.java b/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/TxParticipant.java deleted file mode 100644 index b17fb24ac..000000000 --- a/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/TxParticipant.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * 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. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.eclipse.tractusx.edc.tests; - -import com.fasterxml.jackson.annotation.JsonCreator; -import jakarta.json.Json; -import org.eclipse.edc.test.system.utils.Participant; -import org.jetbrains.annotations.NotNull; - -import java.net.URI; -import java.time.Duration; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -import static io.restassured.http.ContentType.JSON; -import static jakarta.json.Json.createObjectBuilder; -import static java.time.Duration.ofSeconds; -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; -import static org.eclipse.edc.util.io.Ports.getFreePort; -import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.TX_NAMESPACE; - -public class TxParticipant extends IdentityParticipant { - public static final String API_KEY = "testkey"; - public static final Duration ASYNC_TIMEOUT = ofSeconds(60); - public static final Duration ASYNC_POLL_INTERVAL = ofSeconds(1); - - private final URI controlPlaneDefault = URI.create("http://localhost:" + getFreePort()); - private final URI controlPlaneControl = URI.create("http://localhost:" + getFreePort() + "/control"); - private final URI backendProviderProxy = URI.create("http://localhost:" + getFreePort() + "/events"); - private final URI dataPlaneProxy = URI.create("http://localhost:" + getFreePort()); - private final URI dataPlanePublic = URI.create("http://localhost:" + getFreePort() + "/public"); - - private ParticipantEdrApi edrs; - private ParticipantDataApi data; - - public void createAsset(String id) { - createAsset(id, new HashMap<>(), Map.of("type", "test-type")); - } - - public String getBpn() { - return getId(); - } - - /** - * Returns the base configuration - */ - public Map getConfiguration() { - return new HashMap<>() { - { - put("edc.connector.name", name); - put("edc.participant.id", id); - put("web.http.port", String.valueOf(controlPlaneDefault.getPort())); - 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(controlPlaneControl.getPort())); - put("web.http.control.path", controlPlaneControl.getPath()); - put("edc.dsp.callback.address", protocolEndpoint.getUrl().toString()); - put("edc.api.auth.key", "testkey"); - put("web.http.public.path", "/api/public"); - put("web.http.public.port", String.valueOf(dataPlanePublic.getPort())); - put("edc.transfer.proxy.token.signer.privatekey.alias", getPrivateKeyAlias()); - put("edc.transfer.proxy.token.verifier.publickey.alias", getFullKeyId()); - put("edc.transfer.send.retry.limit", "1"); - put("edc.transfer.send.retry.base-delay.ms", "100"); - put("tx.dpf.consumer.proxy.port", String.valueOf(dataPlaneProxy.getPort())); - put("edc.dataplane.token.validation.endpoint", controlPlaneControl + "/token"); - put("edc.dataplane.selector.httpplane.url", controlPlaneControl.toString()); - put("edc.dataplane.selector.httpplane.sourcetypes", "HttpData"); - put("edc.dataplane.selector.httpplane.destinationtypes", "HttpProxy"); - put("edc.dataplane.selector.httpplane.transfertypes", "HttpProxy-PULL"); - put("edc.dataplane.selector.httpplane.properties", "{\"publicApiUrl\":\"http://localhost:" + dataPlanePublic.getPort() + "/api/public/v2\"}"); - put("edc.receiver.http.dynamic.endpoint", "http://localhost:" + controlPlaneDefault.getPort() + "/api/consumer/datareference"); - put("tractusx.businesspartnervalidation.log.agreement.validation", "true"); - put("edc.agent.identity.key", "BusinessPartnerNumber"); - put("edc.data.encryption.keys.alias", "test-alias"); - put("tx.dpf.proxy.gateway.aas.proxied.path", backendProviderProxy.toString()); - put("tx.dpf.proxy.gateway.aas.authorization.type", "none"); - put("edc.iam.issuer.id", getDid()); - put("edc.dataplane.api.public.baseurl", "http://localhost:%d/api/public/v2/data".formatted(dataPlanePublic.getPort())); - } - }; - } - - public ParticipantEdrApi edrs() { - return edrs; - } - - /** - * Returns the client API for fetching data - */ - public ParticipantDataApi data() { - return data; - } - - /** - * Stores BPN groups - */ - public void storeBusinessPartner(String bpn, String... groups) { - var body = createObjectBuilder() - .add(ID, bpn) - .add(TX_NAMESPACE + "groups", Json.createArrayBuilder(Arrays.asList(groups))) - .build(); - managementEndpoint.baseRequest() - .contentType(JSON) - .body(body) - .when() - .post("/business-partner-groups") - .then() - .statusCode(204); - } - - @Override - public String getFullKeyId() { - return getDid() + "#" + getKeyId(); - } - - @NotNull - private String getDid() { - return "did:web:" + name.toLowerCase(); - } - - public static final class Builder extends Participant.Builder { - - private Builder() { - super(new TxParticipant()); - } - - @JsonCreator - public static Builder newInstance() { - return new Builder(); - } - - @Override - public TxParticipant build() { - super.managementEndpoint(new Endpoint(URI.create("http://localhost:" + getFreePort() + "/api/management"), Map.of("x-api-key", API_KEY))); - super.protocolEndpoint(new Endpoint(URI.create("http://localhost:" + getFreePort() + "/protocol"))); - super.timeout(ASYNC_TIMEOUT); - super.build(); - - this.participant.edrs = new ParticipantEdrApi(participant); - this.participant.data = new ParticipantDataApi(); - return participant; - } - } -} diff --git a/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/TransferProcessHelperFunctions.java b/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/helpers/TransferProcessHelperFunctions.java similarity index 77% rename from edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/TransferProcessHelperFunctions.java rename to edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/helpers/TransferProcessHelperFunctions.java index da83d3143..73d1a44c7 100644 --- a/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/TransferProcessHelperFunctions.java +++ b/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/helpers/TransferProcessHelperFunctions.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. @@ -17,11 +17,12 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package org.eclipse.tractusx.edc.tests.transfer; +package org.eclipse.tractusx.edc.tests.helpers; import jakarta.json.Json; import jakarta.json.JsonObject; +import static jakarta.json.Json.createObjectBuilder; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; @@ -43,12 +44,21 @@ public static JsonObject createTransferRequest(String dataRequestId, String coun } - public static JsonObject createProxyRequest() { return Json.createObjectBuilder() .add(TYPE, EDC_NAMESPACE + "DataAddress") - .add(EDC_NAMESPACE + "type", "HttpProxy-PULL") + .add(EDC_NAMESPACE + "type", "HttpProxy") .build(); } + + public static JsonObject httpDataAddress(String baseUrl) { + return createObjectBuilder() + .add(TYPE, EDC_NAMESPACE + "DataAddress") + .add(EDC_NAMESPACE + "type", "HttpData") + .add(EDC_NAMESPACE + "properties", createObjectBuilder() + .add(EDC_NAMESPACE + "baseUrl", baseUrl) + .build()) + .build(); + } } diff --git a/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/TractusxIatpParticipantBase.java b/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/participant/TractusxIatpParticipantBase.java similarity index 97% rename from edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/TractusxIatpParticipantBase.java rename to edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/participant/TractusxIatpParticipantBase.java index fada1c3de..175a8fa2a 100644 --- a/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/TractusxIatpParticipantBase.java +++ b/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/participant/TractusxIatpParticipantBase.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package org.eclipse.tractusx.edc.tests; +package org.eclipse.tractusx.edc.tests.participant; import java.net.URI; import java.util.Arrays; @@ -86,7 +86,7 @@ public B trustedIssuer(String trustedIssuer) { participant.trustedIssuer = trustedIssuer; return self(); } - + @Override public TractusxIatpParticipantBase build() { super.build(); diff --git a/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/TractusxParticipantBase.java b/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/participant/TractusxParticipantBase.java similarity index 93% rename from edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/TractusxParticipantBase.java rename to edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/participant/TractusxParticipantBase.java index cd8d8fe78..c8e3baae9 100644 --- a/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/TractusxParticipantBase.java +++ b/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/participant/TractusxParticipantBase.java @@ -1,5 +1,5 @@ -/* - * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft +/******************************************************************************** + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. @@ -15,12 +15,15 @@ * under the License. * * SPDX-License-Identifier: Apache-2.0 - */ + ********************************************************************************/ -package org.eclipse.tractusx.edc.tests; +package org.eclipse.tractusx.edc.tests.participant; import jakarta.json.Json; import org.eclipse.edc.test.system.utils.Participant; +import org.eclipse.tractusx.edc.tests.IdentityParticipant; +import org.eclipse.tractusx.edc.tests.ParticipantDataApi; +import org.eclipse.tractusx.edc.tests.ParticipantEdrApi; import org.jetbrains.annotations.NotNull; import java.net.URI; @@ -37,12 +40,13 @@ import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.TX_NAMESPACE; /** - * Base class for doing E2E tests with participants. It will replace {@link TxParticipant} + * Base class for doing E2E tests with participants. */ public abstract class TractusxParticipantBase extends IdentityParticipant { public static final String API_KEY = "testkey"; public static final Duration ASYNC_TIMEOUT = ofSeconds(60); + public static final Duration ASYNC_POLL_INTERVAL = ofSeconds(1); private final URI controlPlaneDefault = URI.create("http://localhost:" + getFreePort()); private final URI controlPlaneControl = URI.create("http://localhost:" + getFreePort() + "/control"); private final URI backendProviderProxy = URI.create("http://localhost:" + getFreePort() + "/events"); @@ -95,7 +99,6 @@ public Map getConfiguration() { put("edc.receiver.http.dynamic.endpoint", "http://localhost:" + controlPlaneDefault.getPort() + "/api/consumer/datareference"); put("tractusx.businesspartnervalidation.log.agreement.validation", "true"); put("edc.agent.identity.key", "BusinessPartnerNumber"); - put("edc.data.encryption.keys.alias", "test-alias"); put("tx.dpf.proxy.gateway.aas.proxied.path", backendProviderProxy.toString()); put("tx.dpf.proxy.gateway.aas.authorization.type", "none"); put("edc.iam.issuer.id", getDid()); @@ -144,7 +147,7 @@ public String getFullKeyId() { public String getDid() { return did; } - + public static class Builder

> extends Participant.Builder { protected Builder(P participant) { diff --git a/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/participant/TransferParticipant.java b/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/participant/TransferParticipant.java new file mode 100644 index 000000000..725d018f1 --- /dev/null +++ b/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/participant/TransferParticipant.java @@ -0,0 +1,43 @@ +/******************************************************************************** + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * 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. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.edc.tests.participant; + +/** + * Extension of {@link TractusxParticipantBase} with Transfer specific configuration + */ +public class TransferParticipant extends TractusxParticipantBase { + + public static class Builder extends TractusxParticipantBase.Builder { + + protected Builder() { + super(new TransferParticipant()); + } + + public static Builder newInstance() { + return new Builder(); + } + + @Override + public TransferParticipant build() { + super.build(); + return participant; + } + } +} diff --git a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/IatpDimParticipant.java b/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/runtimes/Runtimes.java similarity index 57% rename from edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/IatpDimParticipant.java rename to edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/runtimes/Runtimes.java index 28bebf2ec..79aaf0057 100644 --- a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/IatpDimParticipant.java +++ b/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/runtimes/Runtimes.java @@ -17,30 +17,17 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -package org.eclipse.tractusx.edc.tests.transfer.iatp; +package org.eclipse.tractusx.edc.tests.runtimes; - -import org.eclipse.tractusx.edc.tests.TxParticipant; - -import java.net.URI; -import java.util.HashMap; import java.util.Map; -/** - * Extension of {@link IatpParticipant} with DIM specific configuration - */ -public class IatpDimParticipant extends IatpParticipant { - private final URI dimUri; +public interface Runtimes { - public IatpDimParticipant(TxParticipant participant, URI stsUri, URI dimUri) { - super(participant, stsUri); - this.dimUri = dimUri; + static ParticipantRuntime memoryRuntime(String runtimeName, String bpn, Map properties) { + return new ParticipantRuntime(":edc-tests:runtime:runtime-memory", runtimeName, bpn, properties); } - @Override - public Map iatpConfiguration(TxParticipant... others) { - var config = new HashMap<>(super.iatpConfiguration(others)); - config.put("edc.iam.sts.dim.url", dimUri.toString()); - return config; + static PgParticipantRuntime pgRuntime(String runtimeName, String bpn, Map properties) { + return new PgParticipantRuntime(":edc-tests:runtime:runtime-postgresql", runtimeName, bpn, properties); } } diff --git a/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/transfer/HttpConsumerPullBaseTest.java b/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/transfer/HttpConsumerPullBaseTest.java index ea6383b23..c32af6cb9 100644 --- a/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/transfer/HttpConsumerPullBaseTest.java +++ b/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/transfer/HttpConsumerPullBaseTest.java @@ -21,55 +21,52 @@ import jakarta.json.Json; import jakarta.json.JsonObject; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; import org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates; -import org.eclipse.tractusx.edc.tests.TractusxParticipantBase; +import org.eclipse.tractusx.edc.tests.ParticipantAwareTest; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockserver.integration.ClientAndServer; +import org.mockserver.verify.VerificationTimes; -import java.io.IOException; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; import static org.assertj.core.api.Assertions.assertThat; import static org.awaitility.Awaitility.await; import static org.awaitility.pollinterval.FibonacciPollInterval.fibonacci; -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; -import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; -import static org.eclipse.tractusx.edc.tests.TxParticipant.ASYNC_TIMEOUT; +import static org.eclipse.edc.util.io.Ports.getFreePort; import static org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions.bnpPolicy; +import static org.eclipse.tractusx.edc.tests.helpers.TransferProcessHelperFunctions.createProxyRequest; +import static org.eclipse.tractusx.edc.tests.participant.TractusxParticipantBase.ASYNC_TIMEOUT; +import static org.mockserver.model.HttpRequest.request; +import static org.mockserver.model.HttpResponse.response; /** * Base tests for Http PULL scenario */ -public abstract class HttpConsumerPullBaseTest { +public abstract class HttpConsumerPullBaseTest implements ParticipantAwareTest { - protected MockWebServer server; + public static final String MOCK_BACKEND_REMOTE_HOST = "localhost"; + public static final String MOCK_BACKEND_PATH = "/mock/api"; + protected ClientAndServer server; - public static JsonObject createProxyRequest() { - return Json.createObjectBuilder() - .add(TYPE, EDC_NAMESPACE + "DataAddress") - .add(EDC_NAMESPACE + "type", "HttpProxy-PULL") - .build(); + private String privateBackendUrl; - } @BeforeEach void setup() { - server = new MockWebServer(); + server = ClientAndServer.startClientAndServer(MOCK_BACKEND_REMOTE_HOST, getFreePort()); + privateBackendUrl = "http://%s:%d%s".formatted(MOCK_BACKEND_REMOTE_HOST, server.getPort(), MOCK_BACKEND_PATH); } @Test - void transferData_privateBackend() throws IOException, InterruptedException { + void transferData_privateBackend() { var assetId = "api-asset-1"; - var url = server.url("/mock/api"); - server.start(); Map dataAddress = Map.of( - "baseUrl", url.toString(), + "baseUrl", privateBackendUrl, "type", "HttpData", "contentType", "application/json" ); @@ -79,9 +76,8 @@ void transferData_privateBackend() throws IOException, InterruptedException { var accessPolicyId = plato().createPolicyDefinition(createAccessPolicy(sokrates().getBpn())); var contractPolicyId = plato().createPolicyDefinition(createContractPolicy(sokrates().getBpn())); plato().createContractDefinition(assetId, "def-1", accessPolicyId, contractPolicyId); - var transferProcessId = sokrates().requestAsset(plato(), assetId, Json.createObjectBuilder().build(), createProxyRequest()); + var transferProcessId = sokrates().requestAsset(plato(), assetId, Json.createObjectBuilder().build(), createProxyRequest(), "HttpData-PULL"); - var contractAgreementId = new AtomicReference(); var edr = new AtomicReference(); // wait until transfer process completes @@ -93,7 +89,7 @@ void transferData_privateBackend() throws IOException, InterruptedException { }); // wait until EDC is available on the consumer side - server.enqueue(new MockResponse().setBody("test response").setResponseCode(200)); + server.when(request().withMethod("GET").withPath(MOCK_BACKEND_PATH)).respond(response().withStatusCode(200).withBody("test response")); await().pollInterval(fibonacci()) .atMost(ASYNC_TIMEOUT) .untilAsserted(() -> { @@ -104,21 +100,20 @@ void transferData_privateBackend() throws IOException, InterruptedException { // pull data out of provider's backend service: // Prov-DP -> Prov-backend assertThat(sokrates().data().pullData(edr.get(), Map.of())).isEqualTo("test response"); - var rq = server.takeRequest(); - assertThat(rq.getHeader("Edc-Contract-Agreement-Id")).isNotNull(); - assertThat(rq.getHeader("Edc-Bpn")).isEqualTo(sokrates().getBpn()); - assertThat(rq.getMethod()).isEqualToIgnoringCase("GET"); + + server.verify(request() + .withPath(MOCK_BACKEND_PATH) + .withHeader("Edc-Contract-Agreement-Id") + .withHeader("Edc-Bpn", sokrates().getBpn()) + .withMethod("GET"), VerificationTimes.exactly(1)); + } @AfterEach - void teardown() throws IOException { - server.shutdown(); + void teardown() { + server.stop(); } - protected abstract TractusxParticipantBase plato(); - - protected abstract TractusxParticipantBase sokrates(); - protected JsonObject createAccessPolicy(String bpn) { return bnpPolicy(bpn); } diff --git a/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/AbstractHttpProviderPushTest.java b/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/transfer/ProviderPushBaseTest.java similarity index 68% rename from edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/AbstractHttpProviderPushTest.java rename to edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/transfer/ProviderPushBaseTest.java index bb6e51c46..90b2b41fc 100644 --- a/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/AbstractHttpProviderPushTest.java +++ b/edc-tests/edc-controlplane/fixtures/src/testFixtures/java/org/eclipse/tractusx/edc/tests/transfer/ProviderPushBaseTest.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. @@ -20,7 +20,7 @@ package org.eclipse.tractusx.edc.tests.transfer; import jakarta.json.JsonObject; -import org.eclipse.tractusx.edc.tests.TxParticipant; +import org.eclipse.tractusx.edc.tests.ParticipantAwareTest; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,39 +37,30 @@ import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; import static org.eclipse.edc.util.io.Ports.getFreePort; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_BPN; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_NAME; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_BPN; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_NAME; -import static org.eclipse.tractusx.edc.tests.TxParticipant.ASYNC_TIMEOUT; import static org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions.bnpPolicy; +import static org.eclipse.tractusx.edc.tests.participant.TractusxParticipantBase.ASYNC_TIMEOUT; import static org.mockserver.model.HttpRequest.request; -public abstract class AbstractHttpProviderPushTest { - public static final String MOCK_BACKEND_REMOTEHOST = "localhost"; - protected static final TxParticipant SOKRATES = TxParticipant.Builder.newInstance() - .name(SOKRATES_NAME) - .id(SOKRATES_BPN) - .build(); +/** + * Base tests for Provider PUSH scenario + */ +public abstract class ProviderPushBaseTest implements ParticipantAwareTest { - protected static final TxParticipant PLATO = TxParticipant.Builder.newInstance() - .name(PLATO_NAME) - .id(PLATO_BPN) - .build(); + public static final String MOCK_BACKEND_REMOTE_HOST = "localhost"; private ClientAndServer server; @BeforeEach void setup() { - server = ClientAndServer.startClientAndServer(MOCK_BACKEND_REMOTEHOST, getFreePort()); + server = ClientAndServer.startClientAndServer(MOCK_BACKEND_REMOTE_HOST, getFreePort()); } @Test void httpPushDataTransfer() { var assetId = UUID.randomUUID().toString(); - var providerUrl = "http://%s:%d%s".formatted(MOCK_BACKEND_REMOTEHOST, server.getPort(), "/mock/api/provider"); - var consumerUrl = "http://%s:%d%s".formatted(MOCK_BACKEND_REMOTEHOST, server.getPort(), "/mock/api/consumer"); + var providerUrl = "http://%s:%d%s".formatted(MOCK_BACKEND_REMOTE_HOST, server.getPort(), "/mock/api/provider"); + var consumerUrl = "http://%s:%d%s".formatted(MOCK_BACKEND_REMOTE_HOST, server.getPort(), "/mock/api/consumer"); server.when(request().withPath("/mock/api/provider")) .respond(HttpResponse.response().withStatusCode(200)); @@ -83,15 +74,15 @@ void httpPushDataTransfer() { "contentType", "application/json" ); - PLATO.createAsset(assetId, Map.of(), dataAddress); - var policyId = PLATO.createPolicyDefinition(bnpPolicy(SOKRATES.getBpn())); - PLATO.createContractDefinition(assetId, "def-1", policyId, policyId); + plato().createAsset(assetId, Map.of(), dataAddress); + var policyId = plato().createPolicyDefinition(bnpPolicy(sokrates().getBpn())); + plato().createContractDefinition(assetId, "def-1", policyId, policyId); var destination = httpDataAddress(consumerUrl); - var transferProcessId = SOKRATES.requestAsset(PLATO, assetId, createObjectBuilder().build(), destination, "HttpData-PUSH"); + var transferProcessId = sokrates().requestAsset(plato(), assetId, createObjectBuilder().build(), destination, "HttpData-PUSH"); await().atMost(ASYNC_TIMEOUT).untilAsserted(() -> { - var state = SOKRATES.getTransferProcessState(transferProcessId); + var state = sokrates().getTransferProcessState(transferProcessId); assertThat(state).isEqualTo(COMPLETED.name()); }); } diff --git a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/AbstractHttpConsumerPullWithProxyTest.java b/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/AbstractHttpConsumerPullWithProxyTest.java deleted file mode 100644 index d6e53441d..000000000 --- a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/AbstractHttpConsumerPullWithProxyTest.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * 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. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.edc.tests.transfer; - -import jakarta.json.Json; -import jakarta.json.JsonObject; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates; -import org.eclipse.tractusx.edc.tests.TxParticipant; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.atomic.AtomicReference; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.awaitility.Awaitility.await; -import static org.awaitility.pollinterval.FibonacciPollInterval.fibonacci; -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; -import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_BPN; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_NAME; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_BPN; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_NAME; -import static org.eclipse.tractusx.edc.tests.TxParticipant.ASYNC_TIMEOUT; -import static org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions.bnpPolicy; - -public abstract class AbstractHttpConsumerPullWithProxyTest { - - protected static final TxParticipant SOKRATES = TxParticipant.Builder.newInstance() - .name(SOKRATES_NAME) - .id(SOKRATES_BPN) - .build(); - - protected static final TxParticipant PLATO = TxParticipant.Builder.newInstance() - .name(PLATO_NAME) - .id(PLATO_BPN) - .build(); - - protected MockWebServer server; - - public static JsonObject createProxyRequest() { - return Json.createObjectBuilder() - .add(TYPE, EDC_NAMESPACE + "DataAddress") - .add(EDC_NAMESPACE + "type", "HttpProxy-PULL") - .build(); - - } - - @BeforeEach - void setup() throws IOException { - server = new MockWebServer(); - } - - @Test - void transferData_privateBackend() throws IOException, InterruptedException { - var assetId = "api-asset-1"; - var url = server.url("/mock/api"); - server.start(); - - - Map dataAddress = Map.of( - "baseUrl", url.toString(), - "type", "HttpData", - "contentType", "application/json" - ); - - PLATO.createAsset(assetId, Map.of(), dataAddress); - - var accessPolicyId = PLATO.createPolicyDefinition(createAccessPolicy(SOKRATES.getBpn())); - var contractPolicyId = PLATO.createPolicyDefinition(createContractPolicy(SOKRATES.getBpn())); - PLATO.createContractDefinition(assetId, "def-1", accessPolicyId, contractPolicyId); - var transferProcessId = SOKRATES.requestAsset(PLATO, assetId, Json.createObjectBuilder().build(), createProxyRequest()); - - var contractAgreementId = new AtomicReference(); - var edr = new AtomicReference(); - - // wait until transfer process completes - await().pollInterval(fibonacci()) - .atMost(ASYNC_TIMEOUT) - .untilAsserted(() -> { - var tpState = SOKRATES.getTransferProcessState(transferProcessId); - assertThat(tpState).isNotNull().isEqualTo(TransferProcessStates.STARTED.toString()); - }); - - // wait until EDC is available on the consumer side - server.enqueue(new MockResponse().setBody("test response").setResponseCode(200)); - await().pollInterval(fibonacci()) - .atMost(ASYNC_TIMEOUT) - .untilAsserted(() -> { - edr.set(SOKRATES.edrs().getEdr(transferProcessId)); - assertThat(edr).isNotNull(); - }); - - // pull data out of provider's backend service: - // Prov-DP -> Prov-backend - assertThat(SOKRATES.data().pullData(edr.get(), Map.of())).isEqualTo("test response"); - var rq = server.takeRequest(); - assertThat(rq.getHeader("Edc-Contract-Agreement-Id")).isNotNull(); - assertThat(rq.getHeader("Edc-Bpn")).isEqualTo(SOKRATES.getBpn()); - assertThat(rq.getMethod()).isEqualToIgnoringCase("GET"); - } - - @AfterEach - void teardown() throws IOException { - server.shutdown(); - } - - protected JsonObject createAccessPolicy(String bpn) { - return bnpPolicy(bpn); - } - - protected JsonObject createContractPolicy(String bpn) { - return bnpPolicy(bpn); - } -} diff --git a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/AbstractIatpConsumerPullTest.java b/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/AbstractIatpConsumerPullTest.java new file mode 100644 index 000000000..df4b53d5a --- /dev/null +++ b/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/AbstractIatpConsumerPullTest.java @@ -0,0 +1,88 @@ +/******************************************************************************** + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * 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. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.edc.tests.transfer; + +import jakarta.json.JsonObject; +import org.eclipse.tractusx.edc.tests.participant.TractusxParticipantBase; +import org.eclipse.tractusx.edc.tests.transfer.iatp.harness.DataspaceIssuer; +import org.eclipse.tractusx.edc.tests.transfer.iatp.harness.IatpParticipant; +import org.eclipse.tractusx.edc.tests.transfer.iatp.harness.StsParticipant; + +import java.net.URI; +import java.util.Map; + +import static org.eclipse.edc.util.io.Ports.getFreePort; +import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.CX_POLICY_NS; +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_BPN; +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_NAME; +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_BPN; +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_NAME; +import static org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions.frameworkPolicy; + +public abstract class AbstractIatpConsumerPullTest extends HttpConsumerPullBaseTest { + + protected static final URI DIM_URI = URI.create("http://localhost:" + getFreePort()); + protected static final DataspaceIssuer DATASPACE_ISSUER_PARTICIPANT = new DataspaceIssuer(); + protected static final StsParticipant STS = StsParticipant.Builder.newInstance() + .id("STS") + .name("STS") + .build(); + protected static final IatpParticipant SOKRATES = IatpParticipant.Builder.newInstance() + .name(SOKRATES_NAME) + .id(SOKRATES_BPN) + .stsUri(STS.stsUri()) + .stsClientId(SOKRATES_BPN) + .stsClientSecret("client_secret") + .trustedIssuer(DATASPACE_ISSUER_PARTICIPANT.didUrl()) + .dimUri(DIM_URI) + .did(did(SOKRATES_NAME)) + .build(); + protected static final IatpParticipant PLATO = IatpParticipant.Builder.newInstance() + .name(PLATO_NAME) + .id(PLATO_BPN) + .stsUri(STS.stsUri()) + .stsClientId(PLATO_BPN) + .stsClientSecret("client_secret") + .trustedIssuer(DATASPACE_ISSUER_PARTICIPANT.didUrl()) + .dimUri(DIM_URI) + .did(did(PLATO_NAME)) + .build(); + + private static String did(String name) { + return "did:example:" + name.toLowerCase(); + } + + + @Override + public TractusxParticipantBase plato() { + return PLATO; + } + + @Override + public TractusxParticipantBase sokrates() { + return SOKRATES; + } + + @Override + protected JsonObject createContractPolicy(String bpn) { + return frameworkPolicy(Map.of(CX_POLICY_NS + "Membership", "active")); + } + +} diff --git a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/DimHttpConsumerPullWithProxyInMemoryTest.java b/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/DimHttpConsumerPullTest.java similarity index 57% rename from edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/DimHttpConsumerPullWithProxyInMemoryTest.java rename to edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/DimHttpConsumerPullTest.java index 68f20aa3e..90b9c2e4d 100644 --- a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/DimHttpConsumerPullWithProxyInMemoryTest.java +++ b/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/DimHttpConsumerPullTest.java @@ -19,60 +19,39 @@ package org.eclipse.tractusx.edc.tests.transfer; -import jakarta.json.JsonObject; import okhttp3.mockwebserver.MockWebServer; import org.eclipse.edc.iam.did.spi.document.DidDocument; import org.eclipse.edc.iam.identitytrust.sts.embedded.EmbeddedSecureTokenService; import org.eclipse.edc.junit.annotations.EndToEndTest; import org.eclipse.edc.token.JwtGenerationService; import org.eclipse.edc.token.spi.TokenGenerationService; -import org.eclipse.tractusx.edc.tests.transfer.iatp.IatpDimParticipant; import org.eclipse.tractusx.edc.tests.transfer.iatp.dispatchers.DimDispatcher; import org.eclipse.tractusx.edc.tests.transfer.iatp.dispatchers.KeycloakDispatcher; -import org.eclipse.tractusx.edc.tests.transfer.iatp.harness.DataspaceIssuer; -import org.eclipse.tractusx.edc.tests.transfer.iatp.harness.SecureTokenService; +import org.eclipse.tractusx.edc.tests.transfer.iatp.harness.IatpParticipant; import org.eclipse.tractusx.edc.tests.transfer.iatp.runtime.IatpParticipantRuntime; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.extension.RegisterExtension; import java.io.IOException; -import java.net.URI; import java.security.PrivateKey; import java.time.Clock; import java.util.HashMap; import java.util.Map; import java.util.function.Supplier; -import static org.eclipse.edc.util.io.Ports.getFreePort; -import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.CX_CREDENTIAL_NS; -import static org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions.frameworkPolicy; import static org.eclipse.tractusx.edc.tests.transfer.iatp.harness.IatpHelperFunctions.configureParticipant; +import static org.eclipse.tractusx.edc.tests.transfer.iatp.runtime.Runtimes.dimRuntime; @EndToEndTest -public class DimHttpConsumerPullWithProxyInMemoryTest extends AbstractHttpConsumerPullWithProxyTest { +public class DimHttpConsumerPullTest extends AbstractIatpConsumerPullTest { - protected static final URI DIM_URI = URI.create("http://localhost:" + getFreePort()); - protected static final DataspaceIssuer DATASPACE_ISSUER_PARTICIPANT = new DataspaceIssuer(); - protected static final SecureTokenService STS_PARTICIPANT = new SecureTokenService(); - protected static final IatpDimParticipant PLATO_IATP = new IatpDimParticipant(PLATO, STS_PARTICIPANT.stsUri(), DIM_URI); @RegisterExtension - protected static final IatpParticipantRuntime PLATO_RUNTIME = new IatpParticipantRuntime( - ":edc-tests:runtime:iatp:runtime-memory-iatp-dim-ih", - PLATO.getName(), - PLATO_IATP.iatpConfiguration(SOKRATES), - PLATO_IATP.getKeyPair() - ); - protected static final IatpDimParticipant SOKRATES_IATP = new IatpDimParticipant(SOKRATES, STS_PARTICIPANT.stsUri(), DIM_URI); + protected static final IatpParticipantRuntime SOKRATES_RUNTIME = dimRuntime(SOKRATES.getName(), SOKRATES.iatpConfiguration(PLATO), SOKRATES.getKeyPair()); @RegisterExtension - protected static final IatpParticipantRuntime SOKRATES_RUNTIME = new IatpParticipantRuntime( - ":edc-tests:runtime:iatp:runtime-memory-iatp-dim-ih", - SOKRATES.getName(), - SOKRATES_IATP.iatpConfiguration(PLATO), - SOKRATES_IATP.getKeyPair() - ); + protected static final IatpParticipantRuntime PLATO_RUNTIME = dimRuntime(PLATO.getName(), PLATO.iatpConfiguration(SOKRATES), PLATO.getKeyPair()); private static MockWebServer oauthServer; private static MockWebServer dimDispatcher; @@ -82,12 +61,12 @@ static void prepare() throws IOException { var tokenGeneration = new JwtGenerationService(); var generatorServices = Map.of( - SOKRATES_IATP.didUrl(), tokenServiceFor(tokenGeneration, SOKRATES_IATP), - PLATO_IATP.didUrl(), tokenServiceFor(tokenGeneration, PLATO_IATP)); + SOKRATES.getDid(), tokenServiceFor(tokenGeneration, SOKRATES), + PLATO.getDid(), tokenServiceFor(tokenGeneration, PLATO)); oauthServer = new MockWebServer(); - oauthServer.start(STS_PARTICIPANT.stsUri().getPort()); - oauthServer.setDispatcher(new KeycloakDispatcher(STS_PARTICIPANT.stsUri().getPath() + "/token")); + oauthServer.start(STS.stsUri().getPort()); + oauthServer.setDispatcher(new KeycloakDispatcher(STS.stsUri().getPath() + "/token")); dimDispatcher = new MockWebServer(); dimDispatcher.start(DIM_URI.getPort()); @@ -96,11 +75,11 @@ static void prepare() throws IOException { // create the DIDs cache var dids = new HashMap(); dids.put(DATASPACE_ISSUER_PARTICIPANT.didUrl(), DATASPACE_ISSUER_PARTICIPANT.didDocument()); - dids.put(SOKRATES_IATP.didUrl(), SOKRATES_IATP.didDocument()); - dids.put(PLATO_IATP.didUrl(), PLATO_IATP.didDocument()); + dids.put(SOKRATES.getDid(), SOKRATES.getDidDocument()); + dids.put(PLATO.getDid(), PLATO.getDidDocument()); - configureParticipant(DATASPACE_ISSUER_PARTICIPANT, SOKRATES_IATP, SOKRATES_RUNTIME, dids, null); - configureParticipant(DATASPACE_ISSUER_PARTICIPANT, PLATO_IATP, PLATO_RUNTIME, dids, null); + configureParticipant(DATASPACE_ISSUER_PARTICIPANT, SOKRATES, SOKRATES_RUNTIME, dids, null); + configureParticipant(DATASPACE_ISSUER_PARTICIPANT, PLATO, PLATO_RUNTIME, dids, null); } @@ -110,22 +89,17 @@ static void unwind() throws IOException { dimDispatcher.shutdown(); } - private static EmbeddedSecureTokenService tokenServiceFor(TokenGenerationService tokenGenerationService, IatpDimParticipant iatpDimParticipant) { + private static EmbeddedSecureTokenService tokenServiceFor(TokenGenerationService tokenGenerationService, IatpParticipant iatpDimParticipant) { return new EmbeddedSecureTokenService(tokenGenerationService, privateKeySupplier(iatpDimParticipant), publicIdSupplier(iatpDimParticipant), Clock.systemUTC(), 60 * 60); } - private static Supplier privateKeySupplier(IatpDimParticipant participant) { + private static Supplier privateKeySupplier(IatpParticipant participant) { return () -> participant.getKeyPair().getPrivate(); } - private static Supplier publicIdSupplier(IatpDimParticipant participant) { + private static Supplier publicIdSupplier(IatpParticipant participant) { return participant::verificationId; } - @Override - protected JsonObject createContractPolicy(String bpn) { - return frameworkPolicy(Map.of(CX_CREDENTIAL_NS + "Membership", "active")); - } - } diff --git a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/IatpHttpConsumerPullWithProxyInMemoryTest.java b/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/IatpHttpConsumerPullWithProxyInMemoryTest.java deleted file mode 100644 index 73b2993ec..000000000 --- a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/IatpHttpConsumerPullWithProxyInMemoryTest.java +++ /dev/null @@ -1,223 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * 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. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.edc.tests.transfer; - -import jakarta.json.Json; -import jakarta.json.JsonObject; -import okhttp3.mockwebserver.MockResponse; -import org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates; -import org.eclipse.edc.iam.did.spi.document.DidDocument; -import org.eclipse.edc.junit.annotations.EndToEndTest; -import org.eclipse.edc.policy.model.Operator; -import org.eclipse.tractusx.edc.tests.transfer.iatp.IatpParticipant; -import org.eclipse.tractusx.edc.tests.transfer.iatp.harness.DataspaceIssuer; -import org.eclipse.tractusx.edc.tests.transfer.iatp.harness.SecureTokenService; -import org.eclipse.tractusx.edc.tests.transfer.iatp.runtime.IatpParticipantRuntime; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.api.extension.RegisterExtension; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.ArgumentsProvider; -import org.junit.jupiter.params.provider.ArgumentsSource; - -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicReference; -import java.util.stream.Stream; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.awaitility.Awaitility.await; -import static org.awaitility.pollinterval.FibonacciPollInterval.fibonacci; -import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.CX_CREDENTIAL_NS; -import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.CX_POLICY_NS; -import static org.eclipse.tractusx.edc.tests.TxParticipant.ASYNC_TIMEOUT; -import static org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions.frameworkPolicy; -import static org.eclipse.tractusx.edc.tests.transfer.iatp.harness.IatpHelperFunctions.configureParticipant; - -@EndToEndTest -public class IatpHttpConsumerPullWithProxyInMemoryTest extends AbstractHttpConsumerPullWithProxyTest { - - protected static final DataspaceIssuer DATASPACE_ISSUER_PARTICIPANT = new DataspaceIssuer(); - protected static final SecureTokenService STS_PARTICIPANT = new SecureTokenService(); - protected static final IatpParticipant PLATO_IATP = new IatpParticipant(PLATO, STS_PARTICIPANT.stsUri()); - @RegisterExtension - protected static final IatpParticipantRuntime PLATO_RUNTIME = new IatpParticipantRuntime( - ":edc-tests:runtime:iatp:runtime-memory-iatp-ih", - PLATO.getName(), - PLATO_IATP.iatpConfiguration(SOKRATES), - PLATO_IATP.getKeyPair()); - protected static final IatpParticipant SOKRATES_IATP = new IatpParticipant(SOKRATES, STS_PARTICIPANT.stsUri()); - @RegisterExtension - protected static final IatpParticipantRuntime SOKRATES_RUNTIME = new IatpParticipantRuntime( - ":edc-tests:runtime:iatp:runtime-memory-iatp-ih", - SOKRATES.getName(), - SOKRATES_IATP.iatpConfiguration(PLATO), - SOKRATES_IATP.getKeyPair()); - - @RegisterExtension - protected static final IatpParticipantRuntime STS_RUNTIME = new IatpParticipantRuntime( - ":edc-tests:runtime:iatp:runtime-memory-sts", - STS_PARTICIPANT.getName(), - STS_PARTICIPANT.stsConfiguration(SOKRATES_IATP, PLATO_IATP), - STS_PARTICIPANT.getKeyPair()); - - @BeforeAll - static void prepare() { - - // create the DIDs cache - var dids = new HashMap(); - dids.put(DATASPACE_ISSUER_PARTICIPANT.didUrl(), DATASPACE_ISSUER_PARTICIPANT.didDocument()); - dids.put(SOKRATES_IATP.didUrl(), SOKRATES_IATP.didDocument()); - dids.put(PLATO_IATP.didUrl(), PLATO_IATP.didDocument()); - - configureParticipant(DATASPACE_ISSUER_PARTICIPANT, SOKRATES_IATP, SOKRATES_RUNTIME, dids, STS_RUNTIME); - configureParticipant(DATASPACE_ISSUER_PARTICIPANT, PLATO_IATP, PLATO_RUNTIME, dids, STS_RUNTIME); - - } - - @DisplayName("Contract policy is fulfilled") - @ParameterizedTest(name = "{1}") - @ArgumentsSource(ValidContractPolicyProvider.class) - void transferData_whenContractPolicyFulfilled(JsonObject contractPolicy, String description) throws IOException, InterruptedException { - var assetId = "api-asset-1"; - var url = server.url("/mock/api"); - server.start(); - - var authCodeHeaderName = "test-authkey"; - var authCode = "test-authcode"; - - Map dataAddress = Map.of( - "baseUrl", url.toString(), - "type", "HttpData", - "contentType", "application/json", - "authKey", authCodeHeaderName, - "authCode", authCode - ); - - PLATO.createAsset(assetId, Map.of(), dataAddress); - - var accessPolicyId = PLATO.createPolicyDefinition(createAccessPolicy(SOKRATES.getBpn())); - var contractPolicyId = PLATO.createPolicyDefinition(contractPolicy); - PLATO.createContractDefinition(assetId, "def-1", accessPolicyId, contractPolicyId); - var transferProcessId = SOKRATES.requestAsset(PLATO, assetId, Json.createObjectBuilder().build(), createProxyRequest()); - - var edr = new AtomicReference(); - - // wait until transfer process completes - await().pollInterval(fibonacci()) - .atMost(ASYNC_TIMEOUT) - .untilAsserted(() -> { - var tpState = SOKRATES.getTransferProcessState(transferProcessId); - assertThat(tpState).isNotNull().isEqualTo(TransferProcessStates.STARTED.toString()); - }); - - // wait until EDC is available on the consumer side - server.enqueue(new MockResponse().setBody("test response").setResponseCode(200)); - await().pollInterval(fibonacci()) - .atMost(ASYNC_TIMEOUT) - .untilAsserted(() -> { - edr.set(SOKRATES.edrs().getEdr(transferProcessId)); - assertThat(edr).isNotNull(); - }); - - // pull data out of provider's backend service: - // Cons-DP -> Prov-DP -> Prov-backend - assertThat(SOKRATES.data().pullData(edr.get(), Map.of())).isEqualTo("test response"); - var rq = server.takeRequest(); - assertThat(rq.getHeader(authCodeHeaderName)).isEqualTo(authCode); - assertThat(rq.getHeader("Edc-Contract-Agreement-Id")).isNotNull(); - assertThat(rq.getHeader("Edc-Bpn")).isEqualTo(SOKRATES.getBpn()); - assertThat(rq.getMethod()).isEqualToIgnoringCase("GET"); - } - - @DisplayName("Contract policy is NOT fulfilled") - @ParameterizedTest(name = "{1}") - @ArgumentsSource(InvalidContractPolicyProvider.class) - void transferData_whenContractPolicyNotFulfilled(JsonObject contractPolicy, String description) throws IOException { - var assetId = "api-asset-1"; - var url = server.url("/mock/api"); - server.start(); - - var authCodeHeaderName = "test-authkey"; - var authCode = "test-authcode"; - - Map dataAddress = Map.of( - "baseUrl", url.toString(), - "type", "HttpData", - "contentType", "application/json", - "authKey", authCodeHeaderName, - "authCode", authCode - ); - - PLATO.createAsset(assetId, Map.of(), dataAddress); - - var accessPolicyId = PLATO.createPolicyDefinition(createAccessPolicy(SOKRATES.getBpn())); - var contractPolicyId = PLATO.createPolicyDefinition(contractPolicy); - PLATO.createContractDefinition(assetId, "def-1", accessPolicyId, contractPolicyId); - var negotiationId = SOKRATES.initContractNegotiation(PLATO, assetId); - - await().pollInterval(fibonacci()) - .atMost(ASYNC_TIMEOUT) - .untilAsserted(() -> { - var contractNegotiationState = SOKRATES.getContractNegotiationState(negotiationId); - assertThat(contractNegotiationState).isEqualTo("TERMINATED"); - }); - } - - @Override - protected JsonObject createContractPolicy(String bpn) { - return frameworkPolicy(Map.of(CX_CREDENTIAL_NS + "Membership", "active")); - } - - private static class ValidContractPolicyProvider implements ArgumentsProvider { - @Override - public Stream provideArguments(ExtensionContext extensionContext) { - return Stream.of( - Arguments.of(frameworkPolicy(Map.of(CX_POLICY_NS + "Membership", "active")), "MembershipCredential"), - Arguments.of(frameworkPolicy(Map.of(CX_POLICY_NS + "FrameworkAgreement.pcf", "active")), "PCF Use Case (legacy notation)"), - Arguments.of(frameworkPolicy(Map.of(CX_POLICY_NS + "FrameworkAgreement", "pcf")), "PCF Use Case (new notation)"), - Arguments.of(frameworkPolicy(Map.of(CX_POLICY_NS + "Dismantler", "active")), "Dismantler Credential"), - Arguments.of(frameworkPolicy(Map.of(CX_POLICY_NS + "Dismantler.activityType", "vehicleDismantle")), "Dismantler Cred (activity type)"), - Arguments.of(frameworkPolicy(CX_POLICY_NS + "Dismantler.allowedBrands", Operator.IS_ANY_OF, List.of("Moskvich", "Tatra")), "Dismantler allowedBrands (IS_ANY_OF, one intersects)"), - Arguments.of(frameworkPolicy(CX_POLICY_NS + "Dismantler.allowedBrands", Operator.EQ, List.of("Moskvich", "Lada")), "Dismantler allowedBrands (EQ, exact match)"), - Arguments.of(frameworkPolicy(CX_POLICY_NS + "Dismantler.allowedBrands", Operator.IS_NONE_OF, List.of("Yugo", "Tatra")), "Dismantler allowedBrands (IS_NONE_OF, no intersect)"), - Arguments.of(frameworkPolicy(CX_POLICY_NS + "Dismantler.allowedBrands", Operator.IN, List.of("Moskvich", "Tatra", "Yugo", "Lada")), "Dismantler allowedBrands (IN, fully contained)") - ); - } - } - - private static class InvalidContractPolicyProvider implements ArgumentsProvider { - @Override - public Stream provideArguments(ExtensionContext extensionContext) { - return Stream.of( - Arguments.of(frameworkPolicy(Map.of(CX_POLICY_NS + "FrameworkAgreement.sustainability", "active")), "Sustainability Use Case (legacy notation)"), - Arguments.of(frameworkPolicy(Map.of(CX_POLICY_NS + "FrameworkAgreement", "traceability")), "Traceability Use Case (new notation)"), - Arguments.of(frameworkPolicy(Map.of(CX_POLICY_NS + "Dismantler.activityType", "vehicleScrap")), "Dismantler activityType does not match"), - Arguments.of(frameworkPolicy(CX_POLICY_NS + "Dismantler.allowedBrands", Operator.NEQ, List.of("Moskvich", "Lada")), "Dismantler allowedBrands (NEQ, but is equal)"), - Arguments.of(frameworkPolicy(CX_POLICY_NS + "Dismantler.allowedBrands", Operator.IS_NONE_OF, List.of("Yugo", "Lada")), "Dismantler allowedBrands (IS_NONE_OF, but is one contains)"), - Arguments.of(frameworkPolicy(CX_POLICY_NS + "Dismantler.allowedBrands", Operator.IN, List.of("Moskvich", "Tatra", "Yugo")), "Dismantler allowedBrands (IN, but not subset)") - ); - } - } -} diff --git a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/StsHttpConsumerPullTest.java b/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/StsHttpConsumerPullTest.java new file mode 100644 index 000000000..4ec46af14 --- /dev/null +++ b/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/StsHttpConsumerPullTest.java @@ -0,0 +1,61 @@ +/******************************************************************************** + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * 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. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.edc.tests.transfer; + +import org.eclipse.edc.iam.did.spi.document.DidDocument; +import org.eclipse.edc.junit.annotations.EndToEndTest; +import org.eclipse.tractusx.edc.tests.transfer.iatp.runtime.IatpParticipantRuntime; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.extension.RegisterExtension; + +import java.util.HashMap; + +import static org.eclipse.tractusx.edc.tests.transfer.iatp.harness.IatpHelperFunctions.configureParticipant; +import static org.eclipse.tractusx.edc.tests.transfer.iatp.runtime.Runtimes.iatpRuntime; +import static org.eclipse.tractusx.edc.tests.transfer.iatp.runtime.Runtimes.stsRuntime; + +@EndToEndTest +public class StsHttpConsumerPullTest extends AbstractIatpConsumerPullTest { + + + @RegisterExtension + protected static final IatpParticipantRuntime SOKRATES_RUNTIME = iatpRuntime(SOKRATES.getName(), SOKRATES.iatpConfiguration(PLATO), SOKRATES.getKeyPair()); + + @RegisterExtension + protected static final IatpParticipantRuntime PLATO_RUNTIME = iatpRuntime(PLATO.getName(), PLATO.iatpConfiguration(SOKRATES), PLATO.getKeyPair()); + + @RegisterExtension + protected static final IatpParticipantRuntime STS_RUNTIME = stsRuntime(STS.getName(), STS.stsConfiguration(SOKRATES, PLATO), STS.getKeyPair()); + + @BeforeAll + static void prepare() { + + // create the DIDs cache + var dids = new HashMap(); + dids.put(DATASPACE_ISSUER_PARTICIPANT.didUrl(), DATASPACE_ISSUER_PARTICIPANT.didDocument()); + dids.put(SOKRATES.getDid(), SOKRATES.getDidDocument()); + dids.put(PLATO.getDid(), PLATO.getDidDocument()); + + configureParticipant(DATASPACE_ISSUER_PARTICIPANT, SOKRATES, SOKRATES_RUNTIME, dids, STS_RUNTIME); + configureParticipant(DATASPACE_ISSUER_PARTICIPANT, PLATO, PLATO_RUNTIME, dids, STS_RUNTIME); + + } + +} diff --git a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/IatpParticipant.java b/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/IatpParticipant.java deleted file mode 100644 index f0a205c1b..000000000 --- a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/IatpParticipant.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * 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. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.eclipse.tractusx.edc.tests.transfer.iatp; - -import org.eclipse.edc.iam.did.spi.document.DidDocument; -import org.eclipse.edc.iam.did.spi.document.Service; -import org.eclipse.edc.iam.did.spi.document.VerificationMethod; -import org.eclipse.tractusx.edc.tests.IdentityParticipant; -import org.eclipse.tractusx.edc.tests.TxParticipant; - -import java.net.URI; -import java.util.Arrays; -import java.util.Base64; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Stream; - -import static org.eclipse.edc.util.io.Ports.getFreePort; -import static org.eclipse.tractusx.edc.tests.transfer.iatp.harness.DataspaceIssuer.DATASPACE_ISSUER; - -/** - * Wrapper of {@link TxParticipant} with IATP specific configurations - */ -public class IatpParticipant extends IdentityParticipant { - - public static final String DID_EXAMPLE = "did:example:"; - protected final URI csService = URI.create("http://localhost:" + getFreePort() + "/api/resolution"); - private final TxParticipant participant; - private final URI stsUri; - private final DidDocument didDocument; - - public IatpParticipant(TxParticipant participant, URI stsUri) { - this.participant = participant; - this.stsUri = stsUri; - this.didDocument = generateDidDocument(); - } - - public String getBpn() { - return participant.getBpn(); - } - - public String getName() { - return participant.getName(); - } - - public Map iatpConfiguration(TxParticipant... others) { - var did = DID_EXAMPLE + participant.getName().toLowerCase(); - var iatpConfiguration = new HashMap<>(participant.getConfiguration()) { - { - - put("edc.iam.sts.oauth.token.url", stsUri + "/token"); - put("edc.iam.sts.oauth.client.id", getBpn()); - put("edc.iam.sts.oauth.client.secret.alias", "client_secret_alias"); - put("edc.iam.issuer.id", did); - put("edc.ih.iam.id", participant.getBpn()); - put("tx.vault.seed.secrets", "client_secret_alias:client_secret"); - put("edc.ih.iam.publickey.alias", getFullKeyId()); - put("web.http.resolution.port", String.valueOf(csService.getPort())); - put("web.http.resolution.path", csService.getPath()); - put("edc.agent.identity.key", "client_id"); - put("edc.iam.trusted-issuer.issuer.id", DATASPACE_ISSUER); - - put("edc.transfer.proxy.token.signer.privatekey.alias", getPrivateKeyAlias()); - put("edc.transfer.proxy.token.verifier.publickey.alias", getFullKeyId()); - } - }; - - Stream.concat(Stream.of(participant), Arrays.stream(others)).forEach(p -> { - var prefix = "tx.iam.iatp.audiences.%s".formatted(p.getName().toLowerCase()); - var participantDid = DID_EXAMPLE + p.getName().toLowerCase(); - iatpConfiguration.put("%s_endpoint.from".formatted(prefix), p.getProtocolEndpoint().getUrl().toString()); - iatpConfiguration.put("%s_endpoint.to".formatted(prefix), participantDid); - iatpConfiguration.put("%s_id.from".formatted(prefix), p.getBpn()); - iatpConfiguration.put("%s_id.to".formatted(prefix), participantDid); - }); - return iatpConfiguration; - } - - public String didUrl() { - return DID_EXAMPLE + participant.getName().toLowerCase(); - } - - public String verificationId() { - return didUrl() + "#" + getKeyId(); - } - - public DidDocument didDocument() { - return didDocument; - } - - @Override - public String getFullKeyId() { - return verificationId(); - } - - - private DidDocument generateDidDocument() { - var service = new Service(); - service.setId("#credential-service"); - service.setType("CredentialService"); - service.setServiceEndpoint(csService + "/v1/participants/" + toBase64(didUrl())); - - var ecKey = getKeyPairAsJwk(); - - var verificationMethod = VerificationMethod.Builder.newInstance() - .id(verificationId()) - .controller(didUrl()) - .type("JsonWebKey2020") - .publicKeyJwk(ecKey.toPublicJWK().toJSONObject()) - .build(); - - return DidDocument.Builder.newInstance() - .id(didUrl()) - .service(List.of(service)) - .authentication(List.of("#key1")) - .verificationMethod(List.of(verificationMethod)) - .build(); - } - - private String toBase64(String s) { - return Base64.getUrlEncoder().encodeToString(s.getBytes()); - } -} diff --git a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/harness/DataspaceIssuer.java b/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/harness/DataspaceIssuer.java index 56fa04427..89d61968a 100644 --- a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/harness/DataspaceIssuer.java +++ b/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/harness/DataspaceIssuer.java @@ -1,5 +1,5 @@ -/* - * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft +/******************************************************************************** + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. @@ -15,7 +15,7 @@ * under the License. * * SPDX-License-Identifier: Apache-2.0 - */ + ********************************************************************************/ package org.eclipse.tractusx.edc.tests.transfer.iatp.harness; @@ -37,7 +37,6 @@ import org.eclipse.edc.security.signature.jws2020.JwsSignature2020Suite; import org.eclipse.edc.verifiablecredentials.linkeddata.LdpIssuer; import org.eclipse.tractusx.edc.tests.IdentityParticipant; -import org.eclipse.tractusx.edc.tests.transfer.iatp.IatpParticipant; import java.net.URI; import java.time.Instant; @@ -78,7 +77,7 @@ public String verificationId() { return DATASPACE_ISSUER + "#" + getKeyId(); } - public VerifiableCredentialResource issueCredential(IatpParticipant participant, JsonLd jsonLd, String type, Supplier credentialSubjectSupplier, Supplier subjectSupplier) { + public VerifiableCredentialResource issueCredential(String did, String bpn, JsonLd jsonLd, String type, Supplier credentialSubjectSupplier, Supplier subjectSupplier) { var credential = VerifiableCredential.Builder.newInstance() .type(type) .credentialSubject(credentialSubjectSupplier.get()) @@ -89,40 +88,40 @@ public VerifiableCredentialResource issueCredential(IatpParticipant participant, var rawVc = createLdpVc(jsonLd, type, subjectSupplier); return VerifiableCredentialResource.Builder.newInstance() .issuerId(didUrl()) - .participantId(participant.didUrl()) - .holderId(participant.getBpn()) + .participantId(did) + .holderId(bpn) .credential(new VerifiableCredentialContainer(rawVc, CredentialFormat.JSON_LD, credential)) .build(); } - public VerifiableCredentialResource issueMembershipCredential(IatpParticipant participant, JsonLd jsonLd) { - return issueCredential(participant, jsonLd, "MembershipCredential", () -> CredentialSubject.Builder.newInstance() - .claim("holderIdentifier", participant.getBpn()) + public VerifiableCredentialResource issueMembershipCredential(String did, String bpn, JsonLd jsonLd) { + return issueCredential(did, bpn, jsonLd, "MembershipCredential", () -> CredentialSubject.Builder.newInstance() + .claim("holderIdentifier", bpn) .build(), - () -> membershipSubject(participant.didUrl(), participant.getBpn())); + () -> membershipSubject(did, bpn)); } - public VerifiableCredentialResource issueDismantlerCredential(IatpParticipant participant, JsonLd jsonLd) { - return issueCredential(participant, jsonLd, "DismantlerCredential", () -> CredentialSubject.Builder.newInstance() - .claim("holderIdentifier", participant.didUrl()) + public VerifiableCredentialResource issueDismantlerCredential(String did, String bpn, JsonLd jsonLd) { + return issueCredential(did, bpn, jsonLd, "DismantlerCredential", () -> CredentialSubject.Builder.newInstance() + .claim("holderIdentifier", bpn) .claim("activityType", "vehicleDismantle") .claim("allowedVehicleBrands", List.of("Moskvich", "Lada")) .build(), () -> Json.createObjectBuilder() - .add("type", "MembershipCredential") - .add("holderIdentifier", participant.didUrl()) + .add("type", "DismantlerCredential") + .add("holderIdentifier", bpn) .add("activityType", "vehicleDismantle") .add("allowedVehicleBrands", Json.createArrayBuilder().add("Moskvich").add("Lada").build()) - .add("id", participant.didUrl()) + .add("id", did) .build()); } - public VerifiableCredentialResource issueFrameworkCredential(IatpParticipant participant, JsonLd jsonLd, String credentialType) { - return issueCredential(participant, jsonLd, credentialType, () -> CredentialSubject.Builder.newInstance() - .claim("holderIdentifier", participant.getBpn()) + public VerifiableCredentialResource issueFrameworkCredential(String did, String bpn, JsonLd jsonLd, String credentialType) { + return issueCredential(did, bpn, jsonLd, credentialType, () -> CredentialSubject.Builder.newInstance() + .claim("holderIdentifier", bpn) .build(), - () -> frameworkAgreementSubject(participant.didUrl(), participant.getBpn(), credentialType)); + () -> frameworkAgreementSubject(did, bpn, credentialType)); } diff --git a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/harness/DidExampleResolver.java b/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/harness/DidExampleResolver.java index eee98794e..c9297a456 100644 --- a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/harness/DidExampleResolver.java +++ b/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/harness/DidExampleResolver.java @@ -1,5 +1,5 @@ -/* - * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft +/******************************************************************************** + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. @@ -15,7 +15,7 @@ * under the License. * * SPDX-License-Identifier: Apache-2.0 - */ + ********************************************************************************/ package org.eclipse.tractusx.edc.tests.transfer.iatp.harness; diff --git a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/harness/IatpHelperFunctions.java b/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/harness/IatpHelperFunctions.java index f16e88153..36485819d 100644 --- a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/harness/IatpHelperFunctions.java +++ b/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/harness/IatpHelperFunctions.java @@ -1,5 +1,5 @@ -/* - * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft +/******************************************************************************** + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. @@ -15,7 +15,7 @@ * under the License. * * SPDX-License-Identifier: Apache-2.0 - */ + ********************************************************************************/ package org.eclipse.tractusx.edc.tests.transfer.iatp.harness; @@ -32,7 +32,6 @@ import org.eclipse.edc.jsonld.spi.JsonLd; import org.eclipse.edc.junit.extensions.EdcExtension; import org.eclipse.edc.spi.security.Vault; -import org.eclipse.tractusx.edc.tests.transfer.iatp.IatpParticipant; import java.time.Instant; import java.util.List; @@ -105,8 +104,8 @@ public static void configureParticipant(DataspaceIssuer issuer, IatpParticipant .build(); var participantManifest = ParticipantManifest.Builder.newInstance() - .participantId(participant.didUrl()) - .did(participant.didUrl()) + .participantId(participant.getDid()) + .did(participant.getDid()) .key(key) .build(); @@ -124,9 +123,9 @@ private static void storeCredentials(DataspaceIssuer issuer, IatpParticipant par private static List issueCredentials(DataspaceIssuer issuer, IatpParticipant participant, JsonLd jsonLd) { return List.of( - issuer.issueMembershipCredential(participant, jsonLd), - issuer.issueDismantlerCredential(participant, jsonLd), - issuer.issueFrameworkCredential(participant, jsonLd, "PcfCredential")); + issuer.issueMembershipCredential(participant.getDid(), participant.getBpn(), jsonLd), + issuer.issueDismantlerCredential(participant.getDid(), participant.getBpn(), jsonLd), + issuer.issueFrameworkCredential(participant.getDid(), participant.getBpn(), jsonLd, "PcfCredential")); } } diff --git a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/harness/IatpParticipant.java b/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/harness/IatpParticipant.java new file mode 100644 index 000000000..b4edf7502 --- /dev/null +++ b/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/harness/IatpParticipant.java @@ -0,0 +1,112 @@ +/******************************************************************************** + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * 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. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.edc.tests.transfer.iatp.harness; + +import org.eclipse.edc.iam.did.spi.document.DidDocument; +import org.eclipse.edc.iam.did.spi.document.Service; +import org.eclipse.edc.iam.did.spi.document.VerificationMethod; +import org.eclipse.tractusx.edc.tests.participant.TractusxIatpParticipantBase; + +import java.net.URI; +import java.util.Base64; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.eclipse.edc.util.io.Ports.getFreePort; + +public class IatpParticipant extends TractusxIatpParticipantBase { + + protected final URI csService = URI.create("http://localhost:" + getFreePort() + "/api/resolution"); + protected URI dimUri; + + private DidDocument didDocument; + + public DidDocument getDidDocument() { + return didDocument; + } + + public String verificationId() { + return did + "#" + getKeyId(); + } + + @Override + public Map getConfiguration() { + var cfg = new HashMap<>(super.getConfiguration()); + cfg.put("web.http.resolution.port", String.valueOf(csService.getPort())); + cfg.put("web.http.resolution.path", csService.getPath()); + if (dimUri != null) { + cfg.put("edc.iam.sts.dim.url", dimUri.toString()); + } + return cfg; + } + + public static class Builder extends TractusxIatpParticipantBase.Builder { + + protected Builder() { + super(new IatpParticipant()); + } + + public static Builder newInstance() { + return new Builder(); + } + + @Override + public IatpParticipant build() { + super.build(); + participant.didDocument = generateDidDocument(); + return participant; + } + + public Builder dimUri(URI dimUri) { + participant.dimUri = dimUri; + return self(); + } + + private DidDocument generateDidDocument() { + var service = new Service(); + service.setId("#credential-service"); + service.setType("CredentialService"); + service.setServiceEndpoint(participant.csService + "/v1/participants/" + toBase64(participant.did)); + + var ecKey = participant.getKeyPairAsJwk(); + + var verificationMethod = VerificationMethod.Builder.newInstance() + .id(participant.verificationId()) + .controller(participant.did) + .type("JsonWebKey2020") + .publicKeyJwk(ecKey.toPublicJWK().toJSONObject()) + .build(); + + return DidDocument.Builder.newInstance() + .id(participant.did) + .service(List.of(service)) + .authentication(List.of("#key1")) + .verificationMethod(List.of(verificationMethod)) + .build(); + } + + + private String toBase64(String s) { + return Base64.getUrlEncoder().encodeToString(s.getBytes()); + } + + } +} diff --git a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/harness/SecureTokenService.java b/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/harness/StsParticipant.java similarity index 63% rename from edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/harness/SecureTokenService.java rename to edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/harness/StsParticipant.java index 190a74742..3671cb60e 100644 --- a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/harness/SecureTokenService.java +++ b/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/harness/StsParticipant.java @@ -1,5 +1,5 @@ -/* - * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft +/******************************************************************************** + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. @@ -15,14 +15,12 @@ * under the License. * * SPDX-License-Identifier: Apache-2.0 - */ + ********************************************************************************/ package org.eclipse.tractusx.edc.tests.transfer.iatp.harness; -import org.eclipse.tractusx.edc.tests.IdentityParticipant; -import org.eclipse.tractusx.edc.tests.TxParticipant; -import org.eclipse.tractusx.edc.tests.transfer.iatp.IatpParticipant; +import org.eclipse.tractusx.edc.tests.participant.TractusxParticipantBase; import java.net.URI; import java.util.Arrays; @@ -36,54 +34,60 @@ /** * STS configurations */ -public class SecureTokenService extends IdentityParticipant { +public class StsParticipant extends TractusxParticipantBase { protected final URI stsUri = URI.create("http://localhost:" + getFreePort() + "/api/v1/sts"); - protected final TxParticipant stsParticipant = TxParticipant.Builder.newInstance() - .name("STS") - .id("STS") - .build(); + + private StsParticipant() { + } public Map stsConfiguration(IatpParticipant... participants) { - var stsConfiguration = new HashMap() { - { - put("web.http.sts.port", String.valueOf(stsUri.getPort())); - put("web.http.sts.path", stsUri.getPath()); - put("edc.dataplane.token.validation.endpoint", ""); - put("tx.vault.seed.secrets", "client_secret_alias:client_secret"); - } - }; + var stsConfiguration = new HashMap<>(super.getConfiguration()); + + stsConfiguration.put("web.http.sts.port", String.valueOf(stsUri.getPort())); + stsConfiguration.put("web.http.sts.path", stsUri.getPath()); + stsConfiguration.put("edc.dataplane.token.validation.endpoint", ""); + stsConfiguration.put("tx.vault.seed.secrets", "client_secret_alias:client_secret"); Arrays.stream(participants).forEach(participant -> { var prefix = format("edc.iam.sts.clients.%s", participant.getName().toLowerCase()); stsConfiguration.put(prefix + ".name", participant.getName()); stsConfiguration.put(prefix + ".id", UUID.randomUUID().toString()); stsConfiguration.put(prefix + ".client_id", participant.getBpn()); - stsConfiguration.put(prefix + ".did", participant.didUrl()); + stsConfiguration.put(prefix + ".did", participant.getDid()); stsConfiguration.put(prefix + ".secret.alias", "client_secret_alias"); stsConfiguration.put(prefix + ".private-key.alias", participant.verificationId()); stsConfiguration.put(prefix + ".public-key.reference", participant.verificationId()); }); - var baseConfiguration = stsParticipant.getConfiguration(); - stsConfiguration.putAll(baseConfiguration); return stsConfiguration; } - public String getBpn() { - return stsParticipant.getBpn(); - } - public String getName() { - return stsParticipant.getName(); + @Override + public String getFullKeyId() { + return "sts-" + getKeyId(); } + public URI stsUri() { return stsUri; } - @Override - public String getFullKeyId() { - return "sts-" + getKeyId(); + public static class Builder extends TractusxParticipantBase.Builder { + + protected Builder() { + super(new StsParticipant()); + } + + public static Builder newInstance() { + return new Builder(); + } + + @Override + public StsParticipant build() { + super.build(); + return participant; + } } } diff --git a/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/runtime/Runtimes.java b/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/runtime/Runtimes.java new file mode 100644 index 000000000..8dcce0fdc --- /dev/null +++ b/edc-tests/edc-controlplane/iatp-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/iatp/runtime/Runtimes.java @@ -0,0 +1,49 @@ +/******************************************************************************** + * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * 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. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.edc.tests.transfer.iatp.runtime; + +import java.security.KeyPair; +import java.util.Map; + +public interface Runtimes { + + static IatpParticipantRuntime dimRuntime(String name, Map properties, KeyPair keyPair) { + return new IatpParticipantRuntime(":edc-tests:runtime:iatp:runtime-memory-iatp-dim-ih", + name, + properties, + keyPair); + } + + static IatpParticipantRuntime iatpRuntime(String name, Map properties, KeyPair keyPair) { + return new IatpParticipantRuntime(":edc-tests:runtime:iatp:runtime-memory-iatp-ih", + name, + properties, + keyPair); + } + + static IatpParticipantRuntime stsRuntime(String name, Map properties, KeyPair keyPair) { + return new IatpParticipantRuntime( + ":edc-tests:runtime:iatp:runtime-memory-sts", + name, + properties, + keyPair); + } + +} diff --git a/edc-tests/edc-controlplane/policy-tests/src/test/java/org/eclipse/tractusx/edc/tests/policy/AbstractPolicyMonitorTest.java b/edc-tests/edc-controlplane/policy-tests/src/test/java/org/eclipse/tractusx/edc/tests/policy/AbstractPolicyMonitorTest.java deleted file mode 100644 index e4dcc0b01..000000000 --- a/edc-tests/edc-controlplane/policy-tests/src/test/java/org/eclipse/tractusx/edc/tests/policy/AbstractPolicyMonitorTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * 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. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.edc.tests.policy; - -import jakarta.json.Json; -import jakarta.json.JsonObject; -import okhttp3.mockwebserver.Dispatcher; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import okhttp3.mockwebserver.RecordedRequest; -import org.eclipse.tractusx.edc.tests.TxParticipant; -import org.jetbrains.annotations.NotNull; -import org.junit.jupiter.api.Test; - -import java.io.IOException; -import java.util.Map; -import java.util.UUID; - -import static jakarta.json.Json.createObjectBuilder; -import static org.assertj.core.api.Assertions.assertThat; -import static org.awaitility.Awaitility.await; -import static org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates.STARTED; -import static org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates.TERMINATED; -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; -import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; -import static org.eclipse.edc.test.system.utils.PolicyFixtures.inForceDatePolicy; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_BPN; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_NAME; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_BPN; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_NAME; -import static org.eclipse.tractusx.edc.tests.TxParticipant.ASYNC_TIMEOUT; - -public abstract class AbstractPolicyMonitorTest { - - protected static final TxParticipant SOKRATES = TxParticipant.Builder.newInstance() - .name(SOKRATES_NAME) - .id(SOKRATES_BPN) - .build(); - - - protected static final TxParticipant PLATO = TxParticipant.Builder.newInstance() - .name(PLATO_NAME) - .id(PLATO_BPN) - .build(); - private final MockWebServer server = new MockWebServer(); - - @Test - void shouldTerminateTransfer_whenPolicyExpires() throws IOException { - var assetId = UUID.randomUUID().toString(); - - Map dataAddress = Map.of( - "name", "transfer-test", - "baseUrl", "http://localhost:" + server.getPort(), - "type", "HttpData", - "contentType", "application/json", - "proxyQueryParams", "true" - ); - PLATO.createAsset(assetId, Map.of(), dataAddress); - startHttpServerProvider(); - - var policy = inForceDatePolicy("gteq", "contractAgreement+0s", "lteq", "contractAgreement+10s"); - var policyId = PLATO.createPolicyDefinition(policy); - PLATO.createContractDefinition(assetId, UUID.randomUUID().toString(), policyId, policyId); - - var consumerUrl = server.url("/mock/api/consumer"); - var destination = httpDataAddress(consumerUrl.toString()); - - var transferProcessId = SOKRATES.requestAsset(PLATO, assetId, Json.createObjectBuilder().build(), destination, "HttpData-PULL"); - await().atMost(ASYNC_TIMEOUT).untilAsserted(() -> { - var state = SOKRATES.getTransferProcessState(transferProcessId); - assertThat(state).isEqualTo(STARTED.name()); - }); - - await().atMost(ASYNC_TIMEOUT).untilAsserted(() -> { - var state = SOKRATES.getTransferProcessState(transferProcessId); - assertThat(state).isEqualTo(TERMINATED.name()); - }); - } - - private JsonObject httpDataAddress(String baseUrl) { - return createObjectBuilder() - .add(TYPE, EDC_NAMESPACE + "DataAddress") - .add(EDC_NAMESPACE + "type", "HttpData") - .add(EDC_NAMESPACE + "properties", createObjectBuilder() - .add(EDC_NAMESPACE + "baseUrl", baseUrl) - .build()) - .build(); - } - - private void startHttpServerProvider() throws IOException { - server.setDispatcher(new Dispatcher() { - @NotNull - @Override - public MockResponse dispatch(@NotNull RecordedRequest recordedRequest) { - if ("/mock/api/provider".equals(recordedRequest.getPath().split("\\?")[0])) { - return new MockResponse().setResponseCode(200); - } - return new MockResponse().setResponseCode(404); - } - }); - server.start(); - } -} diff --git a/edc-tests/edc-controlplane/policy-tests/src/test/java/org/eclipse/tractusx/edc/tests/policy/PolicyMonitorEndToEndTest.java b/edc-tests/edc-controlplane/policy-tests/src/test/java/org/eclipse/tractusx/edc/tests/policy/PolicyMonitorEndToEndTest.java new file mode 100644 index 000000000..793226960 --- /dev/null +++ b/edc-tests/edc-controlplane/policy-tests/src/test/java/org/eclipse/tractusx/edc/tests/policy/PolicyMonitorEndToEndTest.java @@ -0,0 +1,119 @@ +/******************************************************************************** + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * 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. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.edc.tests.policy; + +import jakarta.json.Json; +import org.eclipse.edc.junit.annotations.EndToEndTest; +import org.eclipse.edc.junit.annotations.PostgresqlIntegrationTest; +import org.eclipse.tractusx.edc.tests.participant.TransferParticipant; +import org.eclipse.tractusx.edc.tests.runtimes.ParticipantRuntime; +import org.eclipse.tractusx.edc.tests.runtimes.PgParticipantRuntime; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import java.util.Map; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; +import static org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates.STARTED; +import static org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates.TERMINATED; +import static org.eclipse.edc.test.system.utils.PolicyFixtures.inForceDatePolicy; +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_BPN; +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_NAME; +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_BPN; +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_NAME; +import static org.eclipse.tractusx.edc.tests.helpers.TransferProcessHelperFunctions.createProxyRequest; +import static org.eclipse.tractusx.edc.tests.participant.TractusxParticipantBase.ASYNC_TIMEOUT; +import static org.eclipse.tractusx.edc.tests.runtimes.Runtimes.memoryRuntime; +import static org.eclipse.tractusx.edc.tests.runtimes.Runtimes.pgRuntime; + +public class PolicyMonitorEndToEndTest { + + protected static final TransferParticipant SOKRATES = TransferParticipant.Builder.newInstance() + .name(SOKRATES_NAME) + .id(SOKRATES_BPN) + .build(); + + + protected static final TransferParticipant PLATO = TransferParticipant.Builder.newInstance() + .name(PLATO_NAME) + .id(PLATO_BPN) + .build(); + + abstract static class Tests { + + @Test + void shouldTerminateTransfer_whenPolicyExpires() { + var assetId = UUID.randomUUID().toString(); + + Map dataAddress = Map.of( + "name", "transfer-test", + "baseUrl", "http://localhost:8080", + "type", "HttpData", + "contentType", "application/json", + "proxyQueryParams", "true" + ); + PLATO.createAsset(assetId, Map.of(), dataAddress); + + var policy = inForceDatePolicy("gteq", "contractAgreement+0s", "lteq", "contractAgreement+10s"); + var policyId = PLATO.createPolicyDefinition(policy); + PLATO.createContractDefinition(assetId, UUID.randomUUID().toString(), policyId, policyId); + + + var transferProcessId = SOKRATES.requestAsset(PLATO, assetId, Json.createObjectBuilder().build(), createProxyRequest(), "HttpData-PULL"); + await().atMost(ASYNC_TIMEOUT).untilAsserted(() -> { + var state = SOKRATES.getTransferProcessState(transferProcessId); + assertThat(state).isEqualTo(STARTED.name()); + }); + + await().atMost(ASYNC_TIMEOUT).untilAsserted(() -> { + var state = SOKRATES.getTransferProcessState(transferProcessId); + assertThat(state).isEqualTo(TERMINATED.name()); + }); + } + + } + + @Nested + @EndToEndTest + class InMemory extends Tests { + + @RegisterExtension + protected static final ParticipantRuntime SOKRATES_RUNTIME = memoryRuntime(SOKRATES.getName(), SOKRATES.getBpn(), SOKRATES.getConfiguration()); + + @RegisterExtension + protected static final ParticipantRuntime PLATO_RUNTIME = memoryRuntime(PLATO.getName(), PLATO.getBpn(), PLATO.getConfiguration()); + + } + + @Nested + @PostgresqlIntegrationTest + class Postgres extends Tests { + + @RegisterExtension + protected static final PgParticipantRuntime SOKRATES_RUNTIME = pgRuntime(SOKRATES.getName(), SOKRATES.getBpn(), SOKRATES.getConfiguration()); + + @RegisterExtension + protected static final PgParticipantRuntime PLATO_RUNTIME = pgRuntime(PLATO.getName(), PLATO.getBpn(), PLATO.getConfiguration()); + + } +} diff --git a/edc-tests/edc-controlplane/policy-tests/src/test/java/org/eclipse/tractusx/edc/tests/policy/PolicyMonitorInMemoryTest.java b/edc-tests/edc-controlplane/policy-tests/src/test/java/org/eclipse/tractusx/edc/tests/policy/PolicyMonitorInMemoryTest.java deleted file mode 100644 index 198e4d494..000000000 --- a/edc-tests/edc-controlplane/policy-tests/src/test/java/org/eclipse/tractusx/edc/tests/policy/PolicyMonitorInMemoryTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * 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. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.edc.tests.policy; - -import com.nimbusds.jose.util.Base64; -import org.eclipse.edc.junit.annotations.EndToEndTest; -import org.eclipse.edc.spi.security.Vault; -import org.eclipse.tractusx.edc.tests.runtimes.ParticipantRuntime; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.extension.RegisterExtension; - -import java.security.SecureRandom; - -@EndToEndTest -public class PolicyMonitorInMemoryTest extends AbstractPolicyMonitorTest { - - @RegisterExtension - protected static final ParticipantRuntime SOKRATES_RUNTIME = new ParticipantRuntime( - ":edc-tests:runtime:runtime-memory", - SOKRATES.getName(), - SOKRATES.getBpn(), - SOKRATES.getConfiguration() - ); - - @RegisterExtension - protected static final ParticipantRuntime PLATO_RUNTIME = new ParticipantRuntime( - ":edc-tests:runtime:runtime-memory", - PLATO.getName(), - PLATO.getBpn(), - PLATO.getConfiguration() - ); - - @BeforeAll - static void prepare() { - var bytes = new byte[32]; - - new SecureRandom().nextBytes(bytes); - var value = Base64.encode(bytes).toString(); - SOKRATES_RUNTIME.getContext().getService(Vault.class).storeSecret("test-alias", value); - PLATO_RUNTIME.getContext().getService(Vault.class).storeSecret("test-alias", value); - } -} diff --git a/edc-tests/edc-controlplane/policy-tests/src/test/java/org/eclipse/tractusx/edc/tests/policy/PolicyMonitorPostgresqlTest.java b/edc-tests/edc-controlplane/policy-tests/src/test/java/org/eclipse/tractusx/edc/tests/policy/PolicyMonitorPostgresqlTest.java deleted file mode 100644 index b8ab7ed2b..000000000 --- a/edc-tests/edc-controlplane/policy-tests/src/test/java/org/eclipse/tractusx/edc/tests/policy/PolicyMonitorPostgresqlTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * 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. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.edc.tests.policy; - -import org.eclipse.edc.junit.annotations.PostgresqlIntegrationTest; -import org.eclipse.tractusx.edc.tests.runtimes.PgParticipantRuntime; -import org.junit.jupiter.api.extension.RegisterExtension; - -@PostgresqlIntegrationTest -public class PolicyMonitorPostgresqlTest extends AbstractPolicyMonitorTest { - - @RegisterExtension - protected static final PgParticipantRuntime SOKRATES_RUNTIME = new PgParticipantRuntime( - ":edc-tests:runtime:runtime-postgresql", - SOKRATES.getName(), - SOKRATES.getBpn(), - SOKRATES.getConfiguration() - ); - @RegisterExtension - protected static final PgParticipantRuntime PLATO_RUNTIME = new PgParticipantRuntime( - ":edc-tests:runtime:runtime-postgresql", - PLATO.getName(), - PLATO.getBpn(), - PLATO.getConfiguration() - ); -} diff --git a/edc-tests/edc-controlplane/ssi-summarycred-tests/src/test/java/org/eclipse/tractusx/edc/tests/SsiParticipant.java b/edc-tests/edc-controlplane/ssi-summarycred-tests/src/test/java/org/eclipse/tractusx/edc/tests/MiwParticipant.java similarity index 72% rename from edc-tests/edc-controlplane/ssi-summarycred-tests/src/test/java/org/eclipse/tractusx/edc/tests/SsiParticipant.java rename to edc-tests/edc-controlplane/ssi-summarycred-tests/src/test/java/org/eclipse/tractusx/edc/tests/MiwParticipant.java index 38faa7f1c..ebe238996 100644 --- a/edc-tests/edc-controlplane/ssi-summarycred-tests/src/test/java/org/eclipse/tractusx/edc/tests/SsiParticipant.java +++ b/edc-tests/edc-controlplane/ssi-summarycred-tests/src/test/java/org/eclipse/tractusx/edc/tests/MiwParticipant.java @@ -19,13 +19,15 @@ package org.eclipse.tractusx.edc.tests; +import org.eclipse.tractusx.edc.tests.participant.TractusxParticipantBase; + import java.net.URI; import java.util.HashMap; import java.util.Map; import static org.eclipse.edc.util.io.Ports.getFreePort; -public class SsiParticipant { +public class MiwParticipant extends TractusxParticipantBase { private final URI miwUri = URI.create("http://localhost:" + getFreePort()); private final URI oauthTokenUri = URI.create("http://localhost:" + getFreePort()); @@ -33,8 +35,8 @@ public class SsiParticipant { /** * Returns the SSI configuration */ - public Map ssiConfiguration(TxParticipant forParticipant) { - var ssiConfiguration = new HashMap() { + public Map getConfiguration() { + return new HashMap<>(super.getConfiguration()) { { put("tx.ssi.miw.url", miwUri.toString()); put("tx.ssi.oauth.token.url", oauthTokenUri.toString()); @@ -43,12 +45,9 @@ public Map ssiConfiguration(TxParticipant forParticipant) { put("tx.ssi.miw.authority.id", "authorityId"); put("tx.ssi.miw.authority.issuer", "did:web:example.com"); put("tx.vault.seed.secrets", "client_secret_alias:client_secret"); - put("tx.ssi.endpoint.audience", forParticipant.getProtocolEndpoint().getUrl().toString()); + put("tx.ssi.endpoint.audience", getProtocolEndpoint().getUrl().toString()); } }; - var baseConfiguration = forParticipant.getConfiguration(); - ssiConfiguration.putAll(baseConfiguration); - return ssiConfiguration; } /** @@ -64,4 +63,21 @@ public URI miwEndpoint() { public URI authTokenEndpoint() { return oauthTokenUri; } + + public static class Builder extends TractusxParticipantBase.Builder { + + protected Builder() { + super(new MiwParticipant()); + } + + public static Builder newInstance() { + return new Builder(); + } + + @Override + public MiwParticipant build() { + super.build(); + return participant; + } + } } \ No newline at end of file diff --git a/edc-tests/edc-controlplane/ssi-summarycred-tests/src/test/java/org/eclipse/tractusx/edc/tests/negotiation/AbstractContractNegotiateTest.java b/edc-tests/edc-controlplane/ssi-summarycred-tests/src/test/java/org/eclipse/tractusx/edc/tests/negotiation/AbstractContractNegotiateTest.java index 59a17559b..2ea74e8f9 100644 --- a/edc-tests/edc-controlplane/ssi-summarycred-tests/src/test/java/org/eclipse/tractusx/edc/tests/negotiation/AbstractContractNegotiateTest.java +++ b/edc-tests/edc-controlplane/ssi-summarycred-tests/src/test/java/org/eclipse/tractusx/edc/tests/negotiation/AbstractContractNegotiateTest.java @@ -21,8 +21,7 @@ import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates; import org.eclipse.edc.policy.model.Operator; -import org.eclipse.tractusx.edc.tests.SsiParticipant; -import org.eclipse.tractusx.edc.tests.TxParticipant; +import org.eclipse.tractusx.edc.tests.MiwParticipant; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -35,24 +34,22 @@ import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_NAME; import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_BPN; import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_NAME; -import static org.eclipse.tractusx.edc.tests.TxParticipant.ASYNC_POLL_INTERVAL; -import static org.eclipse.tractusx.edc.tests.TxParticipant.ASYNC_TIMEOUT; import static org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions.bpnGroupPolicy; import static org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions.frameworkPolicy; +import static org.eclipse.tractusx.edc.tests.participant.TractusxParticipantBase.ASYNC_POLL_INTERVAL; +import static org.eclipse.tractusx.edc.tests.participant.TractusxParticipantBase.ASYNC_TIMEOUT; public abstract class AbstractContractNegotiateTest { - protected static final TxParticipant SOKRATES = TxParticipant.Builder.newInstance() + protected static final MiwParticipant SOKRATES = MiwParticipant.Builder.newInstance() .name(SOKRATES_NAME) .id(SOKRATES_BPN) .build(); - protected static final TxParticipant PLATO = TxParticipant.Builder.newInstance() + protected static final MiwParticipant PLATO = MiwParticipant.Builder.newInstance() .name(PLATO_NAME) .id(PLATO_BPN) .build(); - protected static final SsiParticipant PLATO_SSI = new SsiParticipant(); - protected static final SsiParticipant SOKRATES_SSI = new SsiParticipant(); @Test diff --git a/edc-tests/edc-controlplane/ssi-summarycred-tests/src/test/java/org/eclipse/tractusx/edc/tests/negotiation/SsiContractNegotiationInMemoryTest.java b/edc-tests/edc-controlplane/ssi-summarycred-tests/src/test/java/org/eclipse/tractusx/edc/tests/negotiation/SsiContractNegotiationInMemoryTest.java index f28900b7c..baf01089d 100644 --- a/edc-tests/edc-controlplane/ssi-summarycred-tests/src/test/java/org/eclipse/tractusx/edc/tests/negotiation/SsiContractNegotiationInMemoryTest.java +++ b/edc-tests/edc-controlplane/ssi-summarycred-tests/src/test/java/org/eclipse/tractusx/edc/tests/negotiation/SsiContractNegotiationInMemoryTest.java @@ -43,7 +43,7 @@ public class SsiContractNegotiationInMemoryTest extends AbstractContractNegotiat ":edc-tests:runtime:runtime-memory-ssi", PLATO.getName(), PLATO.getBpn(), - PLATO_SSI.ssiConfiguration(PLATO) + PLATO.getConfiguration() ); @RegisterExtension @@ -51,7 +51,7 @@ public class SsiContractNegotiationInMemoryTest extends AbstractContractNegotiat ":edc-tests:runtime:runtime-memory-ssi", SOKRATES.getName(), SOKRATES.getBpn(), - SOKRATES_SSI.ssiConfiguration(SOKRATES) + SOKRATES.getConfiguration() ); private static MockWebServer miwSokratesServer; private static MockWebServer miwPlatoServer; @@ -69,16 +69,16 @@ static void setup() throws IOException { var credentialSubjectId = "did:web:example.com"; - miwSokratesServer.start(SOKRATES_SSI.miwEndpoint().getPort()); + miwSokratesServer.start(SOKRATES.miwEndpoint().getPort()); miwSokratesServer.setDispatcher(new MiwDispatcher(SOKRATES_BPN, SUMMARY_VC_TEMPLATE, credentialSubjectId, PLATO.getProtocolEndpoint().getUrl().toString())); - miwPlatoServer.start(PLATO_SSI.miwEndpoint().getPort()); + miwPlatoServer.start(PLATO.miwEndpoint().getPort()); miwPlatoServer.setDispatcher(new MiwDispatcher(PLATO_BPN, SUMMARY_VC_TEMPLATE, credentialSubjectId, SOKRATES.getProtocolEndpoint().getUrl().toString())); - sokratesOauthServer.start(SOKRATES_SSI.authTokenEndpoint().getPort()); + sokratesOauthServer.start(SOKRATES.authTokenEndpoint().getPort()); sokratesOauthServer.setDispatcher(new KeycloakDispatcher()); - platoOauthServer.start(PLATO_SSI.authTokenEndpoint().getPort()); + platoOauthServer.start(PLATO.authTokenEndpoint().getPort()); platoOauthServer.setDispatcher(new KeycloakDispatcher()); } diff --git a/edc-tests/edc-controlplane/ssi-summarycred-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/AbstractHttpConsumerPullWithProxyTest.java b/edc-tests/edc-controlplane/ssi-summarycred-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/AbstractHttpConsumerPullWithProxyTest.java deleted file mode 100644 index 7c77cc296..000000000 --- a/edc-tests/edc-controlplane/ssi-summarycred-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/AbstractHttpConsumerPullWithProxyTest.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * 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. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.edc.tests.transfer; - -import jakarta.json.Json; -import jakarta.json.JsonObject; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates; -import org.eclipse.tractusx.edc.tests.SsiParticipant; -import org.eclipse.tractusx.edc.tests.TxParticipant; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.atomic.AtomicReference; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.awaitility.Awaitility.await; -import static org.awaitility.pollinterval.FibonacciPollInterval.fibonacci; -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; -import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_BPN; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_NAME; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_BPN; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_NAME; -import static org.eclipse.tractusx.edc.tests.TxParticipant.ASYNC_TIMEOUT; -import static org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions.bnpPolicy; - -public abstract class AbstractHttpConsumerPullWithProxyTest { - - protected static final TxParticipant SOKRATES = (TxParticipant.Builder.newInstance() - .name(SOKRATES_NAME) - .id(SOKRATES_BPN) - .build()); - - protected static final TxParticipant PLATO = (TxParticipant.Builder.newInstance() - .name(PLATO_NAME) - .id(PLATO_BPN) - .build()); - - protected static final SsiParticipant PLATO_SSI = new SsiParticipant(); - protected static final SsiParticipant SOKRATES_SSI = new SsiParticipant(); - - protected MockWebServer server; - - @BeforeEach - void setup() throws IOException { - server = new MockWebServer(); - } - - @Test - void transferData_privateBackend() throws IOException, InterruptedException { - var assetId = "api-asset-1"; - var url = server.url("/mock/api"); - server.start(); - - var authCodeHeaderName = "test-authkey"; - var authCode = "test-authcode"; - - Map dataAddress = Map.of( - "baseUrl", url.toString(), - "type", "HttpData", - "contentType", "application/json", - "authKey", authCodeHeaderName, - "authCode", authCode - ); - - PLATO.createAsset(assetId, Map.of(), dataAddress); - - var accessPolicyId = PLATO.createPolicyDefinition(createAccessPolicy(SOKRATES.getBpn())); - var contractPolicyId = PLATO.createPolicyDefinition(createContractPolicy(SOKRATES.getBpn())); - PLATO.createContractDefinition(assetId, "def-1", accessPolicyId, contractPolicyId); - var transferProcessId = SOKRATES.requestAsset(PLATO, assetId, Json.createObjectBuilder().build(), createProxyRequest(), "HttpData-PULL"); - - var contractAgreementId = new AtomicReference(); - var edr = new AtomicReference(); - - // wait until transfer process completes - await().pollInterval(fibonacci()) - .atMost(ASYNC_TIMEOUT) - .untilAsserted(() -> { - var tpState = SOKRATES.getTransferProcessState(transferProcessId); - assertThat(tpState).isNotNull().isEqualTo(TransferProcessStates.STARTED.toString()); - }); - - // wait until EDC is available on the consumer side - server.enqueue(new MockResponse().setBody("test response").setResponseCode(200)); - await().pollInterval(fibonacci()) - .atMost(ASYNC_TIMEOUT) - .untilAsserted(() -> { - edr.set(SOKRATES.edrs().getEdr(transferProcessId)); - assertThat(edr).isNotNull(); - }); - - // pull data out of provider's backend service: - // Cons-DP -> Prov-DP -> Prov-backend - assertThat(SOKRATES.data().pullData(edr.get(), Map.of())).isEqualTo("test response"); - var rq = server.takeRequest(); - assertThat(rq.getHeader(authCodeHeaderName)).isEqualTo(authCode); - assertThat(rq.getHeader("Edc-Contract-Agreement-Id")).isNotNull(); - assertThat(rq.getHeader("Edc-Bpn")).isEqualTo(SOKRATES.getBpn()); - assertThat(rq.getMethod()).isEqualToIgnoringCase("GET"); - } - - @AfterEach - void teardown() throws IOException { - server.shutdown(); - } - - protected JsonObject createAccessPolicy(String bpn) { - return bnpPolicy(bpn); - } - - protected JsonObject createContractPolicy(String bpn) { - return bnpPolicy(bpn); - } - - private JsonObject createProxyRequest() { - return Json.createObjectBuilder() - .add(TYPE, EDC_NAMESPACE + "DataAddress") - .add(EDC_NAMESPACE + "type", "HttpProxy") - .build(); - - } -} diff --git a/edc-tests/edc-controlplane/ssi-summarycred-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/SsiHttpConsumerPullWithProxyInMemoryTest.java b/edc-tests/edc-controlplane/ssi-summarycred-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/SsiHttpConsumerPullWithProxyInMemoryTest.java index db071c67a..4335630a2 100644 --- a/edc-tests/edc-controlplane/ssi-summarycred-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/SsiHttpConsumerPullWithProxyInMemoryTest.java +++ b/edc-tests/edc-controlplane/ssi-summarycred-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/SsiHttpConsumerPullWithProxyInMemoryTest.java @@ -24,6 +24,8 @@ import org.eclipse.edc.junit.annotations.EndToEndTest; import org.eclipse.tractusx.edc.tests.KeycloakDispatcher; import org.eclipse.tractusx.edc.tests.MiwDispatcher; +import org.eclipse.tractusx.edc.tests.MiwParticipant; +import org.eclipse.tractusx.edc.tests.participant.TractusxParticipantBase; import org.eclipse.tractusx.edc.tests.runtimes.ParticipantRuntime; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -34,27 +36,37 @@ import static org.eclipse.tractusx.edc.edr.spi.CoreConstants.TX_NAMESPACE; import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_BPN; +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_NAME; import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_BPN; +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_NAME; import static org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions.frameworkPolicy; @EndToEndTest -public class SsiHttpConsumerPullWithProxyInMemoryTest extends AbstractHttpConsumerPullWithProxyTest { +public class SsiHttpConsumerPullWithProxyInMemoryTest extends HttpConsumerPullBaseTest { public static final String SUMMARY_VC_TEMPLATE = "summary-vc.json"; + protected static final MiwParticipant SOKRATES = MiwParticipant.Builder.newInstance() + .name(SOKRATES_NAME) + .id(SOKRATES_BPN) + .build(); + protected static final MiwParticipant PLATO = MiwParticipant.Builder.newInstance() + .name(PLATO_NAME) + .id(PLATO_BPN) + .build(); @RegisterExtension protected static final ParticipantRuntime SOKRATES_RUNTIME = new ParticipantRuntime( ":edc-tests:runtime:runtime-memory-ssi", SOKRATES.getName(), SOKRATES.getBpn(), - SOKRATES_SSI.ssiConfiguration(SOKRATES) + SOKRATES.getConfiguration() ); @RegisterExtension protected static final ParticipantRuntime PLATO_RUNTIME = new ParticipantRuntime( ":edc-tests:runtime:runtime-memory-ssi", PLATO.getName(), PLATO.getBpn(), - PLATO_SSI.ssiConfiguration(PLATO) + PLATO.getConfiguration() ); private static MockWebServer sokratesOauthServer; @@ -71,16 +83,16 @@ static void prepare() throws IOException { var credentialSubjectId = "did:web:example.com"; - miwSokratesServer.start(SOKRATES_SSI.miwEndpoint().getPort()); + miwSokratesServer.start(SOKRATES.miwEndpoint().getPort()); miwSokratesServer.setDispatcher(new MiwDispatcher(SOKRATES_BPN, SUMMARY_VC_TEMPLATE, credentialSubjectId, PLATO.getProtocolEndpoint().getUrl().toString())); - miwPlatoServer.start(PLATO_SSI.miwEndpoint().getPort()); + miwPlatoServer.start(PLATO.miwEndpoint().getPort()); miwPlatoServer.setDispatcher(new MiwDispatcher(PLATO_BPN, SUMMARY_VC_TEMPLATE, credentialSubjectId, SOKRATES.getProtocolEndpoint().getUrl().toString())); - sokratesOauthServer.start(SOKRATES_SSI.authTokenEndpoint().getPort()); + sokratesOauthServer.start(SOKRATES.authTokenEndpoint().getPort()); sokratesOauthServer.setDispatcher(new KeycloakDispatcher()); - platoOauthServer.start(PLATO_SSI.authTokenEndpoint().getPort()); + platoOauthServer.start(PLATO.authTokenEndpoint().getPort()); platoOauthServer.setDispatcher(new KeycloakDispatcher()); } @@ -92,6 +104,16 @@ static void unwind() throws IOException { platoOauthServer.shutdown(); } + @Override + public TractusxParticipantBase plato() { + return PLATO; + } + + @Override + public TractusxParticipantBase sokrates() { + return SOKRATES; + } + @Override protected JsonObject createAccessPolicy(String bpn) { return frameworkPolicy(Map.of(TX_NAMESPACE + "Dismantler", "active")); diff --git a/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/AbstractHttpConsumerPullWithProxyTest.java b/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/AbstractHttpConsumerPullWithProxyTest.java deleted file mode 100644 index 8e41f23df..000000000 --- a/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/AbstractHttpConsumerPullWithProxyTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * 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. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.edc.tests.transfer; - -import jakarta.json.Json; -import jakarta.json.JsonObject; -import org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates; -import org.eclipse.tractusx.edc.tests.TxParticipant; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockserver.integration.ClientAndServer; -import org.mockserver.verify.VerificationTimes; - -import java.util.Map; -import java.util.concurrent.atomic.AtomicReference; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.awaitility.Awaitility.await; -import static org.awaitility.pollinterval.FibonacciPollInterval.fibonacci; -import static org.eclipse.edc.util.io.Ports.getFreePort; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_BPN; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_NAME; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_BPN; -import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_NAME; -import static org.eclipse.tractusx.edc.tests.TxParticipant.ASYNC_TIMEOUT; -import static org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions.bnpPolicy; -import static org.eclipse.tractusx.edc.tests.transfer.TransferProcessHelperFunctions.createProxyRequest; -import static org.mockserver.model.HttpRequest.request; -import static org.mockserver.model.HttpResponse.response; - -public abstract class AbstractHttpConsumerPullWithProxyTest { - - public static final String MOCK_BACKEND_REMOTEHOST = "localhost"; - public static final String MOCK_BACKEND_PATH = "/mock/api"; - protected static final TxParticipant SOKRATES = TxParticipant.Builder.newInstance() - .name(SOKRATES_NAME) - .id(SOKRATES_BPN) - .build(); - protected static final TxParticipant PLATO = TxParticipant.Builder.newInstance() - .name(PLATO_NAME) - .id(PLATO_BPN) - .build(); - protected ClientAndServer server; - private String privateBackendUrl; - - @BeforeEach - void setup() { - server = ClientAndServer.startClientAndServer(MOCK_BACKEND_REMOTEHOST, getFreePort()); - privateBackendUrl = "http://%s:%d%s".formatted(MOCK_BACKEND_REMOTEHOST, server.getPort(), MOCK_BACKEND_PATH); - } - - @Test - void transferData_privateBackend() { - var assetId = "api-asset-1"; - - - Map dataAddress = Map.of( - "baseUrl", privateBackendUrl, - "type", "HttpData", - "contentType", "application/json" - ); - - PLATO.createAsset(assetId, Map.of(), dataAddress); - - var accessPolicyId = PLATO.createPolicyDefinition(createAccessPolicy(SOKRATES.getBpn())); - var contractPolicyId = PLATO.createPolicyDefinition(createContractPolicy(SOKRATES.getBpn())); - PLATO.createContractDefinition(assetId, "def-1", accessPolicyId, contractPolicyId); - var transferProcessId = SOKRATES.requestAsset(PLATO, assetId, Json.createObjectBuilder().build(), createProxyRequest()); - - var edr = new AtomicReference(); - - // wait until transfer process completes - await().pollInterval(fibonacci()) - .atMost(ASYNC_TIMEOUT) - .untilAsserted(() -> { - var tpState = SOKRATES.getTransferProcessState(transferProcessId); - assertThat(tpState).isNotNull().isEqualTo(TransferProcessStates.STARTED.toString()); - }); - - // wait until EDC is available on the consumer side - server.when(request().withMethod("GET").withPath(MOCK_BACKEND_PATH)).respond(response().withStatusCode(200).withBody("test response")); - await().pollInterval(fibonacci()) - .atMost(ASYNC_TIMEOUT) - .untilAsserted(() -> { - edr.set(SOKRATES.edrs().getEdr(transferProcessId)); - assertThat(edr).isNotNull(); - }); - - // pull data out of provider's backend service: - // Prov-DP -> Prov-backend - assertThat(SOKRATES.data().pullData(edr.get(), Map.of())).isEqualTo("test response"); - - server.verify(request() - .withPath(MOCK_BACKEND_PATH) - .withHeader("Edc-Contract-Agreement-Id") - .withHeader("Edc-Bpn", SOKRATES_BPN) - .withMethod("GET"), VerificationTimes.exactly(1)); - - } - - @AfterEach - void teardown() { - server.stop(); - } - - protected JsonObject createAccessPolicy(String bpn) { - return bnpPolicy(bpn); - } - - protected JsonObject createContractPolicy(String bpn) { - return bnpPolicy(bpn); - } -} diff --git a/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/HttpConsumerPullWithProxyInMemoryTest.java b/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/HttpConsumerPullWithProxyInMemoryTest.java deleted file mode 100644 index e86b25f23..000000000 --- a/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/HttpConsumerPullWithProxyInMemoryTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * 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. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.edc.tests.transfer; - -import com.nimbusds.jose.util.Base64; -import org.eclipse.edc.junit.annotations.EndToEndTest; -import org.eclipse.edc.spi.security.Vault; -import org.eclipse.tractusx.edc.tests.runtimes.ParticipantRuntime; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.extension.RegisterExtension; - -import java.security.SecureRandom; - -@EndToEndTest -public class HttpConsumerPullWithProxyInMemoryTest extends AbstractHttpConsumerPullWithProxyTest { - - @RegisterExtension - protected static final ParticipantRuntime SOKRATES_RUNTIME = new ParticipantRuntime( - ":edc-tests:runtime:runtime-memory", - SOKRATES.getName(), - SOKRATES.getBpn(), - SOKRATES.getConfiguration() - ); - - @RegisterExtension - protected static final ParticipantRuntime PLATO_RUNTIME = new ParticipantRuntime( - ":edc-tests:runtime:runtime-memory", - PLATO.getName(), - PLATO.getBpn(), - PLATO.getConfiguration() - ); - - @BeforeAll - static void prepare() { - var bytes = new byte[32]; - - new SecureRandom().nextBytes(bytes); - var value = Base64.encode(bytes).toString(); - var vault = SOKRATES_RUNTIME.getContext().getService(Vault.class); - vault.storeSecret("test-alias", value); - vault = PLATO_RUNTIME.getContext().getService(Vault.class); - vault.storeSecret("test-alias", value); - - } -} diff --git a/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/HttpConsumerPullWithProxyPostgresqlTest.java b/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/HttpConsumerPullWithProxyPostgresqlTest.java deleted file mode 100644 index d1002cbd8..000000000 --- a/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/HttpConsumerPullWithProxyPostgresqlTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * 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. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.edc.tests.transfer; - -import org.eclipse.edc.junit.annotations.PostgresqlIntegrationTest; -import org.eclipse.tractusx.edc.tests.runtimes.PgParticipantRuntime; -import org.junit.jupiter.api.extension.RegisterExtension; - -@PostgresqlIntegrationTest -public class HttpConsumerPullWithProxyPostgresqlTest extends AbstractHttpConsumerPullWithProxyTest { - - - @RegisterExtension - protected static final PgParticipantRuntime SOKRATES_RUNTIME = new PgParticipantRuntime( - ":edc-tests:runtime:runtime-postgresql", - SOKRATES.getName(), - SOKRATES.getBpn(), - SOKRATES.getConfiguration() - ); - @RegisterExtension - protected static final PgParticipantRuntime PLATO_RUNTIME = new PgParticipantRuntime( - ":edc-tests:runtime:runtime-postgresql", - PLATO.getName(), - PLATO.getBpn(), - PLATO.getConfiguration() - ); - -} diff --git a/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/HttpProviderPushInMemoryTest.java b/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/HttpProviderPushInMemoryTest.java deleted file mode 100644 index dd481bd53..000000000 --- a/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/HttpProviderPushInMemoryTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * 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. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.edc.tests.transfer; - -import org.eclipse.edc.junit.annotations.EndToEndTest; -import org.eclipse.tractusx.edc.tests.runtimes.ParticipantRuntime; -import org.junit.jupiter.api.extension.RegisterExtension; - -@EndToEndTest -public class HttpProviderPushInMemoryTest extends AbstractHttpProviderPushTest { - - @RegisterExtension - protected static final ParticipantRuntime SOKRATES_RUNTIME = new ParticipantRuntime( - ":edc-tests:runtime:runtime-memory", - SOKRATES.getName(), - SOKRATES.getBpn(), - SOKRATES.getConfiguration() - ); - - @RegisterExtension - protected static final ParticipantRuntime PLATO_RUNTIME = new ParticipantRuntime( - ":edc-tests:runtime:runtime-memory", - PLATO.getName(), - PLATO.getBpn(), - PLATO.getConfiguration() - ); -} diff --git a/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/HttpProviderPushInPostgresqlTest.java b/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/HttpProviderPushInPostgresqlTest.java deleted file mode 100644 index 79bd34a2d..000000000 --- a/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/HttpProviderPushInPostgresqlTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * 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. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -package org.eclipse.tractusx.edc.tests.transfer; - -import org.eclipse.edc.junit.annotations.PostgresqlIntegrationTest; -import org.eclipse.tractusx.edc.tests.runtimes.PgParticipantRuntime; -import org.junit.jupiter.api.extension.RegisterExtension; - -@PostgresqlIntegrationTest -public class HttpProviderPushInPostgresqlTest extends AbstractHttpProviderPushTest { - - @RegisterExtension - protected static final PgParticipantRuntime SOKRATES_RUNTIME = new PgParticipantRuntime( - ":edc-tests:runtime:runtime-postgresql", - SOKRATES.getName(), - SOKRATES.getBpn(), - SOKRATES.getConfiguration() - ); - @RegisterExtension - protected static final PgParticipantRuntime PLATO_RUNTIME = new PgParticipantRuntime( - ":edc-tests:runtime:runtime-postgresql", - PLATO.getName(), - PLATO.getBpn(), - PLATO.getConfiguration() - ); -} diff --git a/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/TransferPullEndToEndTest.java b/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/TransferPullEndToEndTest.java new file mode 100644 index 000000000..ddd2a983f --- /dev/null +++ b/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/TransferPullEndToEndTest.java @@ -0,0 +1,86 @@ +/******************************************************************************** + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * 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. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.edc.tests.transfer; + +import org.eclipse.edc.junit.annotations.EndToEndTest; +import org.eclipse.edc.junit.annotations.PostgresqlIntegrationTest; +import org.eclipse.tractusx.edc.tests.participant.TractusxParticipantBase; +import org.eclipse.tractusx.edc.tests.participant.TransferParticipant; +import org.eclipse.tractusx.edc.tests.runtimes.ParticipantRuntime; +import org.eclipse.tractusx.edc.tests.runtimes.PgParticipantRuntime; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.extension.RegisterExtension; + +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_BPN; +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_NAME; +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_BPN; +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_NAME; +import static org.eclipse.tractusx.edc.tests.runtimes.Runtimes.memoryRuntime; +import static org.eclipse.tractusx.edc.tests.runtimes.Runtimes.pgRuntime; + +public class TransferPullEndToEndTest { + + abstract static class Tests extends HttpConsumerPullBaseTest { + + protected static final TransferParticipant SOKRATES = TransferParticipant.Builder.newInstance() + .name(SOKRATES_NAME) + .id(SOKRATES_BPN) + .build(); + protected static final TransferParticipant PLATO = TransferParticipant.Builder.newInstance() + .name(PLATO_NAME) + .id(PLATO_BPN) + .build(); + + @Override + public TractusxParticipantBase plato() { + return PLATO; + } + + @Override + public TractusxParticipantBase sokrates() { + return SOKRATES; + } + + } + + @Nested + @EndToEndTest + class InMemory extends Tests { + + @RegisterExtension + protected static final ParticipantRuntime SOKRATES_RUNTIME = memoryRuntime(SOKRATES.getName(), SOKRATES.getBpn(), SOKRATES.getConfiguration()); + + @RegisterExtension + protected static final ParticipantRuntime PLATO_RUNTIME = memoryRuntime(PLATO.getName(), PLATO.getBpn(), PLATO.getConfiguration()); + + } + + @Nested + @PostgresqlIntegrationTest + class Postgres extends Tests { + + @RegisterExtension + protected static final PgParticipantRuntime SOKRATES_RUNTIME = pgRuntime(SOKRATES.getName(), SOKRATES.getBpn(), SOKRATES.getConfiguration()); + + @RegisterExtension + protected static final PgParticipantRuntime PLATO_RUNTIME = pgRuntime(PLATO.getName(), PLATO.getBpn(), PLATO.getConfiguration()); + + } +} \ No newline at end of file diff --git a/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/TransferPushEndToEndTest.java b/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/TransferPushEndToEndTest.java new file mode 100644 index 000000000..ad9d34e71 --- /dev/null +++ b/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/TransferPushEndToEndTest.java @@ -0,0 +1,86 @@ +/******************************************************************************** + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * 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. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +package org.eclipse.tractusx.edc.tests.transfer; + +import org.eclipse.edc.junit.annotations.EndToEndTest; +import org.eclipse.edc.junit.annotations.PostgresqlIntegrationTest; +import org.eclipse.tractusx.edc.tests.participant.TractusxParticipantBase; +import org.eclipse.tractusx.edc.tests.participant.TransferParticipant; +import org.eclipse.tractusx.edc.tests.runtimes.ParticipantRuntime; +import org.eclipse.tractusx.edc.tests.runtimes.PgParticipantRuntime; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.extension.RegisterExtension; + +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_BPN; +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_NAME; +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_BPN; +import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_NAME; +import static org.eclipse.tractusx.edc.tests.runtimes.Runtimes.memoryRuntime; +import static org.eclipse.tractusx.edc.tests.runtimes.Runtimes.pgRuntime; + +public class TransferPushEndToEndTest { + + abstract static class Tests extends ProviderPushBaseTest { + + protected static final TransferParticipant SOKRATES = TransferParticipant.Builder.newInstance() + .name(SOKRATES_NAME) + .id(SOKRATES_BPN) + .build(); + protected static final TransferParticipant PLATO = TransferParticipant.Builder.newInstance() + .name(PLATO_NAME) + .id(PLATO_BPN) + .build(); + + @Override + public TractusxParticipantBase plato() { + return PLATO; + } + + @Override + public TractusxParticipantBase sokrates() { + return SOKRATES; + } + + } + + @Nested + @EndToEndTest + class InMemory extends Tests { + + @RegisterExtension + protected static final ParticipantRuntime SOKRATES_RUNTIME = memoryRuntime(SOKRATES.getName(), SOKRATES.getBpn(), SOKRATES.getConfiguration()); + + @RegisterExtension + protected static final ParticipantRuntime PLATO_RUNTIME = memoryRuntime(PLATO.getName(), PLATO.getBpn(), PLATO.getConfiguration()); + + } + + @Nested + @PostgresqlIntegrationTest + class Postgres extends Tests { + + @RegisterExtension + protected static final PgParticipantRuntime SOKRATES_RUNTIME = pgRuntime(SOKRATES.getName(), SOKRATES.getBpn(), SOKRATES.getConfiguration()); + + @RegisterExtension + protected static final PgParticipantRuntime PLATO_RUNTIME = pgRuntime(PLATO.getName(), PLATO.getBpn(), PLATO.getConfiguration()); + + } +} \ No newline at end of file diff --git a/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/TransferWithTokenRefreshTest.java b/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/TransferWithTokenRefreshTest.java index 2134525c5..d82e6edce 100644 --- a/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/TransferWithTokenRefreshTest.java +++ b/edc-tests/edc-controlplane/transfer-tests/src/test/java/org/eclipse/tractusx/edc/tests/transfer/TransferWithTokenRefreshTest.java @@ -19,23 +19,19 @@ package org.eclipse.tractusx.edc.tests.transfer; -import com.nimbusds.jose.util.Base64; import jakarta.json.Json; import jakarta.json.JsonObject; import org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates; import org.eclipse.edc.junit.annotations.EndToEndTest; -import org.eclipse.edc.spi.security.Vault; -import org.eclipse.tractusx.edc.tests.TxParticipant; +import org.eclipse.tractusx.edc.tests.participant.TransferParticipant; import org.eclipse.tractusx.edc.tests.runtimes.ParticipantRuntime; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.mockserver.integration.ClientAndServer; import org.mockserver.verify.VerificationTimes; -import java.security.SecureRandom; import java.time.Duration; import java.util.HashMap; import java.util.Map; @@ -50,9 +46,10 @@ import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_NAME; import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_BPN; import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_NAME; -import static org.eclipse.tractusx.edc.tests.TxParticipant.ASYNC_TIMEOUT; import static org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions.bnpPolicy; -import static org.eclipse.tractusx.edc.tests.transfer.TransferProcessHelperFunctions.createProxyRequest; +import static org.eclipse.tractusx.edc.tests.helpers.TransferProcessHelperFunctions.createProxyRequest; +import static org.eclipse.tractusx.edc.tests.participant.TractusxParticipantBase.ASYNC_TIMEOUT; +import static org.eclipse.tractusx.edc.tests.runtimes.Runtimes.memoryRuntime; import static org.mockserver.model.HttpRequest.request; import static org.mockserver.model.HttpResponse.response; @@ -64,46 +61,26 @@ @EndToEndTest public class TransferWithTokenRefreshTest { - public static final String MOCK_BACKEND_REMOTEHOST = "localhost"; + public static final String MOCK_BACKEND_REMOTE_HOST = "localhost"; public static final String MOCK_BACKEND_PATH = "/mock/api"; - protected static final TxParticipant SOKRATES = TxParticipant.Builder.newInstance() + protected static final TransferParticipant SOKRATES = TransferParticipant.Builder.newInstance() .name(SOKRATES_NAME) .id(SOKRATES_BPN) .build(); - protected static final TxParticipant PLATO = TxParticipant.Builder.newInstance() + protected static final TransferParticipant PLATO = TransferParticipant.Builder.newInstance() .name(PLATO_NAME) .id(PLATO_BPN) .build(); + @RegisterExtension - protected static final ParticipantRuntime SOKRATES_RUNTIME = new ParticipantRuntime( - ":edc-tests:runtime:runtime-memory", - SOKRATES.getName(), - SOKRATES.getBpn(), - SOKRATES.getConfiguration() - ); + protected static final ParticipantRuntime SOKRATES_RUNTIME = memoryRuntime(SOKRATES.getName(), SOKRATES.getBpn(), SOKRATES.getConfiguration()); private static final Long VERY_SHORT_TOKEN_EXPIRY = 3L; + @RegisterExtension - protected static final ParticipantRuntime PLATO_RUNTIME = new ParticipantRuntime( - ":edc-tests:runtime:runtime-memory", - PLATO.getName(), - PLATO.getBpn(), - forConfig(PLATO.getConfiguration()) - ); + protected static final ParticipantRuntime PLATO_RUNTIME = memoryRuntime(PLATO.getName(), PLATO.getBpn(), forConfig(PLATO.getConfiguration())); protected ClientAndServer server; private String privateBackendUrl; - @BeforeAll - static void prepare() { - var bytes = new byte[32]; - - new SecureRandom().nextBytes(bytes); - var value = Base64.encode(bytes).toString(); - var vault = SOKRATES_RUNTIME.getContext().getService(Vault.class); - vault.storeSecret("test-alias", value); - vault = PLATO_RUNTIME.getContext().getService(Vault.class); - vault.storeSecret("test-alias", value); - - } private static Map forConfig(Map originalConfig) { var newConfig = new HashMap<>(originalConfig); @@ -114,8 +91,8 @@ private static Map forConfig(Map originalConfig) @BeforeEach void setup() { - server = ClientAndServer.startClientAndServer(MOCK_BACKEND_REMOTEHOST, getFreePort()); - privateBackendUrl = "http://%s:%d%s".formatted(MOCK_BACKEND_REMOTEHOST, server.getPort(), MOCK_BACKEND_PATH); + server = ClientAndServer.startClientAndServer(MOCK_BACKEND_REMOTE_HOST, getFreePort()); + privateBackendUrl = "http://%s:%d%s".formatted(MOCK_BACKEND_REMOTE_HOST, server.getPort(), MOCK_BACKEND_PATH); } @Test @@ -133,7 +110,7 @@ void transferData_withExpiredEdr_shouldReturn4xx() { var accessPolicyId = PLATO.createPolicyDefinition(createAccessPolicy(SOKRATES.getBpn())); var contractPolicyId = PLATO.createPolicyDefinition(createContractPolicy(SOKRATES.getBpn())); PLATO.createContractDefinition(assetId, "def-1", accessPolicyId, contractPolicyId); - var transferProcessId = SOKRATES.requestAsset(PLATO, assetId, Json.createObjectBuilder().build(), createProxyRequest()); + var transferProcessId = SOKRATES.requestAsset(PLATO, assetId, Json.createObjectBuilder().build(), createProxyRequest(), "HttpData-PULL"); var edr = new AtomicReference(); @@ -202,7 +179,7 @@ void transferData_withAutomaticRefresh() { var accessPolicyId = PLATO.createPolicyDefinition(createAccessPolicy(SOKRATES.getBpn())); var contractPolicyId = PLATO.createPolicyDefinition(createContractPolicy(SOKRATES.getBpn())); PLATO.createContractDefinition(assetId, "def-1", accessPolicyId, contractPolicyId); - var transferProcessId = SOKRATES.requestAsset(PLATO, assetId, Json.createObjectBuilder().build(), createProxyRequest()); + var transferProcessId = SOKRATES.requestAsset(PLATO, assetId, Json.createObjectBuilder().build(), createProxyRequest(), "HttpData-PULL"); var edr = new AtomicReference();