use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedDataDestinationResource in project DataSpaceConnector by eclipse-dataspaceconnector.
the class ProvisionManagerImplTest method deprovision_should_deprovision_all_the_transfer_process_provisioned_resources.
@Test
void deprovision_should_deprovision_all_the_transfer_process_provisioned_resources() {
var deprovisionResponse = DeprovisionResponse.Builder.newInstance().resource(new TestProvisionedDataDestinationResource("test-resource")).build();
when(provisioner.canDeprovision(isA(ProvisionedResource.class))).thenReturn(true);
when(provisioner.deprovision(isA(TestProvisionedResource.class))).thenReturn(completedFuture(deprovisionResponse));
TransferProcess transferProcess = TransferProcess.Builder.newInstance().id("id").state(TransferProcessStates.REQUESTED.code()).provisionedResourceSet(ProvisionedResourceSet.Builder.newInstance().resources(List.of(new TestProvisionedResource())).build()).build();
var result = provisionManager.deprovision(transferProcess);
assertThat(result).succeedsWithin(1, SECONDS).extracting(responses -> responses.get(0)).extracting(DeprovisionResponse::getResource).extracting(ProvisionedDataDestinationResource.class::cast).extracting(ProvisionedDataDestinationResource::getResourceName).isEqualTo("test-resource");
}
use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedDataDestinationResource in project DataSpaceConnector by eclipse-dataspaceconnector.
the class ProvisionManagerImplTest method provision_should_provision_all_the_transfer_process_definitions.
@Test
void provision_should_provision_all_the_transfer_process_definitions() {
when(provisioner.canProvision(isA(TestResourceDefinition.class))).thenReturn(true);
var provisionResult = StatusResult.success(ProvisionResponse.Builder.newInstance().resource(new TestProvisionedDataDestinationResource("test-resource", "1")).build());
when(provisioner.provision(isA(TestResourceDefinition.class), isA(Policy.class))).thenReturn(completedFuture(provisionResult));
var result = provisionManager.provision(List.of(new TestResourceDefinition()), policy);
assertThat(result).succeedsWithin(1, SECONDS).extracting(responses -> responses.get(0)).extracting(StatusResult::getContent).extracting(ProvisionResponse::getResource).extracting(ProvisionedDataDestinationResource.class::cast).extracting(ProvisionedDataDestinationResource::getResourceName).isEqualTo("test-resource");
}
use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedDataDestinationResource in project DataSpaceConnector by eclipse-dataspaceconnector.
the class TransferProcessManagerImplTest method verifyCompleted_noCheckerForSomeResources.
@Test
@DisplayName("checkComplete: should automatically transition process with no managed resources if no checker")
void verifyCompleted_noCheckerForSomeResources() throws InterruptedException {
var process = createTransferProcess(IN_PROGRESS, new TransferType(), false);
process.getProvisionedResourceSet().addResource(provisionedDataDestinationResource());
process.getProvisionedResourceSet().addResource(provisionedDataDestinationResource());
var latch = countDownOnUpdateLatch();
when(transferProcessStore.nextForState(eq(IN_PROGRESS.code()), anyInt())).thenReturn(List.of(process)).thenReturn(emptyList());
when(statusCheckerRegistry.resolve(anyString())).thenReturn(null);
manager.start();
assertThat(latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue();
verify(statusCheckerRegistry, atLeastOnce()).resolve(any());
verify(transferProcessStore).update(argThat(p -> p.getState() == COMPLETED.code()));
}
use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedDataDestinationResource in project DataSpaceConnector by eclipse-dataspaceconnector.
the class TransferProcessManagerImplTest method verifyCompletedNonManagedResources.
@Test
@DisplayName("checkComplete: should transition process with no managed resources if checker returns completed")
void verifyCompletedNonManagedResources() throws InterruptedException {
TransferProcess process = createTransferProcess(REQUESTED, new TransferType(), false);
process.getProvisionedResourceSet().addResource(provisionedDataDestinationResource());
process.getProvisionedResourceSet().addResource(provisionedDataDestinationResource());
when(transferProcessStore.nextForState(eq(IN_PROGRESS.code()), anyInt())).thenReturn(List.of(process)).thenReturn(emptyList());
when(statusCheckerRegistry.resolve(anyString())).thenReturn((tp, resources) -> true);
var latch = countDownOnUpdateLatch();
manager.start();
assertThat(latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue();
verify(statusCheckerRegistry, atLeastOnce()).resolve(any());
verify(transferProcessStore).update(argThat(p -> p.getState() == COMPLETED.code()));
}
use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedDataDestinationResource in project DataSpaceConnector by eclipse-dataspaceconnector.
the class TransferProcessManagerImplTest method provisioning_shouldTransitionToProvisionedOnDataDestination.
@Test
void provisioning_shouldTransitionToProvisionedOnDataDestination() throws InterruptedException {
var process = createTransferProcess(PROVISIONING).toBuilder().resourceManifest(ResourceManifest.Builder.newInstance().definitions(List.of(new TestResourceDefinition())).build()).build();
var provisionResult = StatusResult.success(ProvisionResponse.Builder.newInstance().resource(provisionedDataDestinationResource()).build());
when(policyArchive.findPolicyForContract(anyString())).thenReturn(Policy.Builder.newInstance().build());
when(provisionManager.provision(any(), isA(Policy.class))).thenReturn(completedFuture(List.of(provisionResult)));
when(transferProcessStore.nextForState(eq(PROVISIONING.code()), anyInt())).thenReturn(List.of(process)).thenReturn(emptyList());
when(transferProcessStore.find(process.getId())).thenReturn(process);
var latch = countDownOnUpdateLatch();
manager.start();
assertThat(latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue();
verify(policyArchive, atLeastOnce()).findPolicyForContract(anyString());
verify(transferProcessStore).update(argThat(p -> p.getState() == PROVISIONED.code()));
}
Aggregations