Skip to content

Commit

Permalink
feat: introduce TxParticipant + E2E tests fix (#968)
Browse files Browse the repository at this point in the history
* feat: introduce TxParticipant + E2E tests fix

* chore: cleanup stub url

* chore: dependencies file

* chore: javadocs

* pr suggestions
  • Loading branch information
wolf4ood authored Jan 3, 2024
1 parent dfb083b commit c8475e3
Show file tree
Hide file tree
Showing 63 changed files with 1,404 additions and 1,661 deletions.
446 changes: 200 additions & 246 deletions DEPENDENCIES

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ private StatusResult<Void> fireTransferProcess(EndpointDataReferenceEntry entry)

var transferRequest = TransferRequest.Builder.newInstance()
.assetId(dataRequest.getAssetId())
.connectorId(dataRequest.getConnectorId())
.contractId(dataRequest.getContractId())
.protocol(dataRequest.getProtocol())
.counterPartyAddress(dataRequest.getConnectorAddress())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -43,7 +42,7 @@ class VaultSeedExtensionTest {

@BeforeEach
void setup(ServiceExtensionContext context, ObjectFactory factory) {
this.context = spy(context);
this.context = context;
monitor = mock(Monitor.class);
context.registerService(Monitor.class, monitor);
context.registerService(Vault.class, new InMemoryVault(monitor));
Expand All @@ -56,7 +55,7 @@ void name() {
}

@ParameterizedTest
@ValueSource(strings = {"key1:", "key1:value1", "key1:value1;", ";key1:value1", ";sdf;key1:value1"})
@ValueSource(strings = { "key1:", "key1:value1", "key1:value1;", ";key1:value1", ";sdf;key1:value1" })
void createInMemVault_validString(String secret) {
when(context.getSetting(eq(VaultSeedExtension.VAULT_MEMORY_SECRETS_PROPERTY), eq(null))).thenReturn(secret);
extension.createInMemVault(context);
Expand Down
3 changes: 2 additions & 1 deletion edc-dataplane/edc-dataplane-base/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ dependencies {
runtimeOnly(libs.edc.dpf.core)
runtimeOnly(libs.edc.controlplane.apiclient)

runtimeOnly(libs.edc.dpf.api)
runtimeOnly(libs.edc.dpf.api.control)
runtimeOnly(libs.edc.dpf.api.public)
runtimeOnly(libs.edc.core.connector)
runtimeOnly(libs.edc.boot)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.startsWith;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand All @@ -49,7 +48,7 @@ class TxEncryptorExtensionTest {
@BeforeEach
void setup(ObjectFactory factory, ServiceExtensionContext c) {
c.registerService(Monitor.class, monitor);
context = spy(c);
context = c;
when(context.getSetting(ENCRYPTION_KEY_ALIAS, null)).thenReturn("test-key");
extension = factory.constructInstance(TxEncryptorExtension.class);
}
Expand All @@ -76,7 +75,7 @@ void createEncryptor_withPropertyEqualsAes() {
}

@ParameterizedTest
@ValueSource(strings = {CACHING_ENABLED, CACHING_SECONDS})
@ValueSource(strings = { CACHING_ENABLED, CACHING_SECONDS })
void verifyDeprecationWarnings(String deprecatedSetting) {
when(context.getSetting(eq(deprecatedSetting), any())).thenReturn("doesn't matter");
extension.createEncryptor(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import static org.eclipse.tractusx.edc.edr.store.sql.SqlEndpointDataReferenceCacheExtension.DEFAULT_DATASOURCE_NAME;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand All @@ -42,7 +41,7 @@ public class SqlEndpointDataReferenceCacheExtensionTest {

@BeforeEach
void setUp(ObjectFactory factory, ServiceExtensionContext context) {
this.context = spy(context);
this.context = context;
context.registerService(TypeManager.class, new TypeManager());
context.registerService(DataSourceRegistry.class, mock(DataSourceRegistry.class));
extension = factory.constructInstance(SqlEndpointDataReferenceCacheExtension.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ private Result<Void> initiateTransfer(ContractNegotiationFinalized negotiationFi
.id(UUID.randomUUID().toString())
.assetId(negotiationFinalized.getContractAgreement().getAssetId())
.contractId(negotiationFinalized.getContractAgreement().getId())
.connectorId(negotiationFinalized.getCounterPartyId())
.counterPartyAddress(negotiationFinalized.getCounterPartyAddress())
.protocol(negotiationFinalized.getProtocol())
.dataDestination(DATA_DESTINATION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ private Result<Void> storeEdr(EndpointDataReference edr) {
if (contractNegotiation != null) {
contractNegotiationId = contractNegotiation.getId();
} else {
monitor.warning(format("Contract negotiation for agreement with id: %s is missing.", transferProcess.getContractId()));
var msg = format("Contract negotiation for agreement with id: %s is missing.", transferProcess.getContractId());
monitor.warning(msg);
return Result.failure(msg);
}
var expirationTime = extractExpirationTime(edr);

Expand All @@ -106,7 +108,7 @@ private Result<Void> storeEdr(EndpointDataReference edr) {
.transferProcessId(transferProcess.getId())
.assetId(transferProcess.getDataRequest().getAssetId())
.agreementId(transferProcess.getDataRequest().getContractId())
.providerId(transferProcess.getDataRequest().getConnectorId())
.providerId(contractNegotiation.getCounterPartyId())
.state(EndpointDataReferenceEntryStates.NEGOTIATED.code())
.expirationTimestamp(expirationTime.getContent())
.contractNegotiationId(contractNegotiationId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ public class ContractNegotiationCallbackTest {

ContractNegotiationCallback callback;

private static <T extends ContractNegotiationEvent, B extends ContractNegotiationEvent.Builder<T, B>> B baseBuilder(B builder) {
var callbacks = List.of(CallbackAddress.Builder.newInstance().uri("http://local").events(Set.of("test")).build());
return builder
.contractNegotiationId("id")
.protocol("test")
.callbackAddresses(callbacks)
.counterPartyAddress("addr")
.counterPartyId("provider");
}

@BeforeEach
void setup() {
callback = new ContractNegotiationCallback(transferProcessService, monitor);
Expand Down Expand Up @@ -92,7 +102,6 @@ void invoke_shouldStartTransferProcess() {
assertThat(tp.getContractId()).isEqualTo(event.getContractAgreement().getId());
assertThat(tp.getAssetId()).isEqualTo(event.getContractAgreement().getAssetId());
assertThat(tp.getCounterPartyAddress()).isEqualTo(event.getCounterPartyAddress());
assertThat(tp.getConnectorId()).isEqualTo(event.getCounterPartyId());
assertThat(tp.getProtocol()).isEqualTo(event.getProtocol());
assertThat(tp.getDataDestination()).usingRecursiveComparison().isEqualTo(DATA_DESTINATION);
});
Expand Down Expand Up @@ -140,16 +149,6 @@ void invoke_whenFinalized() {
verify(transferProcessService).initiateTransfer(any(TransferRequest.class));
}

private static <T extends ContractNegotiationEvent, B extends ContractNegotiationEvent.Builder<T, B>> B baseBuilder(B builder) {
var callbacks = List.of(CallbackAddress.Builder.newInstance().uri("http://local").events(Set.of("test")).build());
return builder
.contractNegotiationId("id")
.protocol("test")
.callbackAddresses(callbacks)
.counterPartyAddress("addr")
.counterPartyId("provider");
}

private static class EventInstances implements ArgumentsProvider {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package org.eclipse.tractusx.edc.callback;

import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation;
import org.eclipse.edc.connector.spi.contractagreement.ContractAgreementService;
import org.eclipse.edc.connector.transfer.spi.event.TransferProcessCompleted;
import org.eclipse.edc.connector.transfer.spi.event.TransferProcessDeprovisioned;
Expand Down Expand Up @@ -108,11 +109,20 @@ void invoke_shouldStoreTheEdrInCache_whenDataAddressIsPresent() {
var edrEntry = EndpointDataReferenceEntry.Builder.newInstance()
.agreementId(contractId)
.transferProcessId(transferProcessId)
.assetId(assetId).build();
.assetId(assetId)
.build();

var negotiation = ContractNegotiation.Builder.newInstance()
.id(contractId)
.counterPartyId("providerId")
.counterPartyAddress("http://test")
.protocol("protocol")
.build();

when(transformerRegistry.transform(any(DataAddress.class), eq(EndpointDataReference.class))).thenReturn(Result.success(edr));
when(transferProcessStore.findForCorrelationId(edr.getId())).thenReturn(transferProcess);
when(transferProcessStore.findById(transferProcessId)).thenReturn(transferProcess);
when(agreementService.findNegotiation(contractId)).thenReturn(negotiation);
when(edrCache.queryForEntries(any())).thenReturn(Stream.of(edrEntry));


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.edc.spi.persistence.EdcPersistenceException;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.sql.DriverManagerConnectionFactory;
import org.eclipse.edc.sql.datasource.ConnectionFactoryDataSource;
import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.MigrationVersion;
Expand All @@ -32,7 +33,7 @@
import java.util.Properties;

abstract class AbstractPostgresqlMigrationExtension implements ServiceExtension {

private static final String EDC_DATASOURCE_PREFIX = "edc.datasource";
private static final String MIGRATION_LOCATION_BASE =
String.format("classpath:%s", AbstractPostgresqlMigrationExtension.class.getPackageName().replace(".", "/"));
Expand All @@ -50,12 +51,10 @@ public String name() {
return "Postgresql schema migration for subsystem " + getSubsystemName();
}

protected abstract String getSubsystemName();

@Override
public void initialize(final ServiceExtensionContext context) {
var config = context.getConfig();

var subSystemName = Objects.requireNonNull(getSubsystemName());
var enabled = config.getBoolean(MIGRATION_ENABLED_TEMPLATE.formatted(subSystemName), Boolean.valueOf(DEFAULT_MIGRATION_ENABLED_TEMPLATE));

Expand All @@ -77,8 +76,8 @@ public void initialize(final ServiceExtensionContext context) {
var jdbcProperties = new Properties();
jdbcProperties.putAll(datasourceConfig.getRelativeEntries());

var driverManagerConnectionFactory = new DriverManagerConnectionFactory(jdbcUrl, jdbcProperties);
var dataSource = new ConnectionFactoryDataSource(driverManagerConnectionFactory);
var driverManagerConnectionFactory = new DriverManagerConnectionFactory();
var dataSource = new ConnectionFactoryDataSource(driverManagerConnectionFactory, jdbcUrl, jdbcProperties);

var flyway =
Flyway.configure()
Expand All @@ -102,4 +101,6 @@ public void initialize(final ServiceExtensionContext context) {
}
}

protected abstract String getSubsystemName();

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--
-- Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
--
-- This program and the accompanying materials are made available under the
-- terms of the Apache License, Version 2.0 which is available at
-- https://www.apache.org/licenses/LICENSE-2.0
--
-- SPDX-License-Identifier: Apache-2.0
--
-- Contributors:
-- Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
--

-- add columns
ALTER TABLE edc_policydefinitions ADD COLUMN private_properties JSON;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--
-- Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
--
-- This program and the accompanying materials are made available under the
-- terms of the Apache License, Version 2.0 which is available at
-- https://www.apache.org/licenses/LICENSE-2.0
--
-- SPDX-License-Identifier: Apache-2.0
--
-- Contributors:
-- Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
--

-- add column
ALTER TABLE edc_transfer_process ADD COLUMN transfer_type VARCHAR;
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.edc.spi.iam.IdentityService;
import org.eclipse.edc.spi.iam.TokenParameters;
import org.eclipse.edc.spi.iam.TokenRepresentation;
import org.eclipse.edc.spi.iam.VerificationContext;
import org.eclipse.edc.spi.result.Result;
import org.eclipse.tractusx.edc.iam.ssi.spi.SsiCredentialClient;

Expand All @@ -39,7 +40,7 @@ public Result<TokenRepresentation> obtainClientCredentials(TokenParameters param
}

@Override
public Result<ClaimToken> verifyJwtToken(TokenRepresentation tokenRepresentation, String audience) {
public Result<ClaimToken> verifyJwtToken(TokenRepresentation tokenRepresentation, VerificationContext verificationContext) {
return tokenValidationService.validate(tokenRepresentation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.tractusx.edc.iam.ssi.identity.SsiIdentityServiceExtension.ENDPOINT_AUDIENCE;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand All @@ -41,7 +40,7 @@ public class SsiIdentityServiceExtensionTest {

@BeforeEach
void setup(ObjectFactory factory, ServiceExtensionContext context) {
this.context = spy(context);
this.context = context;
context.registerService(SsiCredentialClient.class, mock(SsiCredentialClient.class));
extension = factory.constructInstance(SsiIdentityServiceExtension.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand All @@ -44,7 +43,7 @@ public class SsiMiwConfigurationExtensionTest {

@BeforeEach
void setup(ObjectFactory factory, ServiceExtensionContext context) {
this.context = spy(context);
this.context = context;
extension = factory.constructInstance(SsiMiwConfigurationExtension.class);
}

Expand Down
Loading

0 comments on commit c8475e3

Please sign in to comment.