Skip to content

Commit

Permalink
feat: add transfer process endpoints schema examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt committed Jul 14, 2023
1 parent 578fb6c commit 2bfb4c3
Show file tree
Hide file tree
Showing 59 changed files with 1,265 additions and 2,121 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private ServiceResult<TransferProcess> onMessageDo(TransferRemoteMessage message
}

private boolean validateCounterParty(ClaimToken claimToken, TransferProcess transferProcess) {
return Optional.ofNullable(negotiationStore.findContractAgreement(transferProcess.getDataRequest().getContractId()))
return Optional.ofNullable(negotiationStore.findContractAgreement(transferProcess.getContractId()))
.map(agreement -> contractValidationService.validateRequest(claimToken, agreement))
.filter(Result::succeeded)
.isPresent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public ServiceResult<Stream<TransferProcess>> query(QuerySpec query) {

@Override
public @NotNull ServiceResult<TransferProcess> initiateTransfer(TransferRequest request) {
var validDestination = dataAddressValidator.validate(request.getDataRequest().getDataDestination());
var validDestination = dataAddressValidator.validate(request.getDataDestination());
if (validDestination.failed()) {
return ServiceResult.badRequest(validDestination.getFailureMessages().toArray(new String[]{}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.eclipse.edc.connector.transfer.spi.event.TransferProcessTerminated;
import org.eclipse.edc.connector.transfer.spi.retry.TransferWaitStrategy;
import org.eclipse.edc.connector.transfer.spi.status.StatusCheckerRegistry;
import org.eclipse.edc.connector.transfer.spi.types.DataRequest;
import org.eclipse.edc.connector.transfer.spi.types.StatusChecker;
import org.eclipse.edc.connector.transfer.spi.types.TransferRequest;
import org.eclipse.edc.connector.transfer.spi.types.protocol.TransferStartMessage;
Expand All @@ -55,7 +54,6 @@

import java.util.Map;

import static java.util.UUID.randomUUID;
import static java.util.concurrent.CompletableFuture.completedFuture;
import static java.util.concurrent.Executors.newSingleThreadExecutor;
import static org.awaitility.Awaitility.await;
Expand Down Expand Up @@ -105,19 +103,7 @@ void shouldDispatchEventsOnTransferProcessStateChanges(TransferProcessService se

statusCheckerRegistry.register("any", statusCheck);
when(statusCheck.isComplete(any(), any())).thenReturn(false);

var dataRequest = DataRequest.Builder.newInstance()
.id("dataRequestId")
.assetId("assetId")
.destinationType("any")
.protocol("test")
.connectorAddress("http://an/address")
.contractId("contractId")
.build();

var transferRequest = TransferRequest.Builder.newInstance()
.dataRequest(dataRequest)
.build();
var transferRequest = createTransferRequest();

var initiateResult = service.initiateTransfer(transferRequest);

Expand Down Expand Up @@ -166,19 +152,7 @@ void shouldDispatchEventsOnTransferProcessStateChanges(TransferProcessService se
void shouldTerminateOnInvalidPolicy(TransferProcessService service, EventRouter eventRouter, RemoteMessageDispatcherRegistry dispatcherRegistry) {
dispatcherRegistry.register(getTestDispatcher());
eventRouter.register(TransferProcessEvent.class, eventSubscriber);

var dataRequest = DataRequest.Builder.newInstance()
.id("dataRequestId")
.assetId("assetId")
.destinationType("any")
.protocol("test")
.connectorAddress("http://an/address")
.contractId("contractId")
.build();

var transferRequest = TransferRequest.Builder.newInstance()
.dataRequest(dataRequest)
.build();
var transferRequest = createTransferRequest();

service.initiateTransfer(transferRequest);

Expand All @@ -192,18 +166,7 @@ void shouldTerminateOnInvalidPolicy(TransferProcessService service, EventRouter
void shouldDispatchEventOnTransferProcessTerminated(TransferProcessService service, EventRouter eventRouter, RemoteMessageDispatcherRegistry dispatcherRegistry) {
dispatcherRegistry.register(getTestDispatcher());
eventRouter.register(TransferProcessEvent.class, eventSubscriber);

var dataRequest = DataRequest.Builder.newInstance()
.id(randomUUID().toString())
.assetId("assetId")
.destinationType("any")
.protocol("test")
.connectorAddress("http://an/address")
.build();

var transferRequest = TransferRequest.Builder.newInstance()
.dataRequest(dataRequest)
.build();
var transferRequest = createTransferRequest();

var initiateResult = service.initiateTransfer(transferRequest);

Expand All @@ -216,22 +179,22 @@ void shouldDispatchEventOnTransferProcessTerminated(TransferProcessService servi
void shouldDispatchEventOnTransferProcessFailure(TransferProcessService service, EventRouter eventRouter, RemoteMessageDispatcherRegistry dispatcherRegistry) {
dispatcherRegistry.register(getTestDispatcher());
eventRouter.register(TransferProcessEvent.class, eventSubscriber);
var transferRequest = createTransferRequest();

service.initiateTransfer(transferRequest);

var dataRequest = DataRequest.Builder.newInstance()
.id(String.valueOf(randomUUID()))
await().untilAsserted(() -> verify(eventSubscriber).on(argThat(isEnvelopeOf(TransferProcessTerminated.class))));
}

private TransferRequest createTransferRequest() {
return TransferRequest.Builder.newInstance()
.id("dataRequestId")
.assetId("assetId")
.destinationType("any")
.dataDestination(DataAddress.Builder.newInstance().type("any").build())
.protocol("test")
.connectorAddress("http://an/address")
.contractId("contractId")
.build();

var transferRequest = TransferRequest.Builder.newInstance()
.dataRequest(dataRequest)
.build();

service.initiateTransfer(transferRequest);

await().untilAsserted(() -> verify(eventSubscriber).on(argThat(isEnvelopeOf(TransferProcessTerminated.class))));
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ void notifyRequested_validAgreement_shouldInitiateTransfer() {

assertThat(result).isSucceeded().satisfies(tp -> {
assertThat(tp.getCorrelationId()).isEqualTo("transferProcessId");
assertThat(tp.getDataRequest().getConnectorAddress()).isEqualTo("http://any");
assertThat(tp.getDataRequest().getAssetId()).isEqualTo("assetId");
assertThat(tp.getConnectorAddress()).isEqualTo("http://any");
assertThat(tp.getAssetId()).isEqualTo("assetId");
});
verify(listener).preCreated(any());
verify(store).updateOrCreate(argThat(t -> t.getState() == INITIAL.code()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.eclipse.edc.connector.spi.transferprocess.TransferProcessService;
import org.eclipse.edc.connector.transfer.spi.TransferProcessManager;
import org.eclipse.edc.connector.transfer.spi.store.TransferProcessStore;
import org.eclipse.edc.connector.transfer.spi.types.DataRequest;
import org.eclipse.edc.connector.transfer.spi.types.TransferProcess;
import org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates;
import org.eclipse.edc.connector.transfer.spi.types.TransferRequest;
Expand All @@ -30,6 +29,7 @@
import org.eclipse.edc.spi.query.QuerySpec;
import org.eclipse.edc.spi.response.StatusResult;
import org.eclipse.edc.spi.result.Result;
import org.eclipse.edc.spi.types.domain.DataAddress;
import org.eclipse.edc.transaction.spi.NoopTransactionContext;
import org.eclipse.edc.transaction.spi.TransactionContext;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -222,15 +222,9 @@ private TransferProcess transferProcess(TransferProcessStates state, String id)
.build();
}

private DataRequest dataRequest() {
return DataRequest.Builder.newInstance()
.destinationType("type")
.build();
}

private TransferRequest transferRequest() {
return TransferRequest.Builder.newInstance()
.dataRequest(dataRequest())
.dataDestination(DataAddress.Builder.newInstance().type("type").build())
.build();
}

Expand Down
Loading

0 comments on commit 2bfb4c3

Please sign in to comment.