use of org.eclipse.dataspaceconnector.spi.policy.store.PolicyArchive in project DataSpaceConnector by eclipse-dataspaceconnector.
the class TransferProcessManagerImplTest method deprovisioning_shouldTransitionToDeprovisioned.
@Test
void deprovisioning_shouldTransitionToDeprovisioned() throws InterruptedException {
var manifest = ResourceManifest.Builder.newInstance().definitions(List.of(new TestResourceDefinition())).build();
var resourceSet = ProvisionedResourceSet.Builder.newInstance().resources(List.of(new TokenTestProvisionResource("test", PROVISIONED_RESOURCE_ID))).build();
var process = createTransferProcess(DEPROVISIONING).toBuilder().resourceManifest(manifest).provisionedResourceSet(resourceSet).build();
var deprovisionResult = StatusResult.success(DeprovisionedResource.Builder.newInstance().provisionedResourceId(PROVISIONED_RESOURCE_ID).build());
when(policyArchive.findPolicyForContract(anyString())).thenReturn(Policy.Builder.newInstance().build());
when(vault.deleteSecret(any())).thenReturn(Result.success());
when(provisionManager.deprovision(any(), isA(Policy.class))).thenReturn(completedFuture(List.of(deprovisionResult)));
when(transferProcessStore.nextForState(eq(DEPROVISIONING.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() == DEPROVISIONED.code()));
verify(vault).deleteSecret(any());
}
use of org.eclipse.dataspaceconnector.spi.policy.store.PolicyArchive in project DataSpaceConnector by eclipse-dataspaceconnector.
the class TransferProcessManagerImplTest method provisioning_shouldContinueOnRetryProvisionError.
@Test
void provisioning_shouldContinueOnRetryProvisionError() throws InterruptedException {
var process = createTransferProcess(PROVISIONING).toBuilder().resourceManifest(ResourceManifest.Builder.newInstance().definitions(List.of(new TestResourceDefinition())).build()).build();
var provisionResult = StatusResult.<ProvisionResponse>failure(ResponseStatus.ERROR_RETRY, "test error");
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() == PROVISIONING.code()));
}
use of org.eclipse.dataspaceconnector.spi.policy.store.PolicyArchive in project DataSpaceConnector by eclipse-dataspaceconnector.
the class TransferProcessManagerImplTest method initial_shouldTransitionToProvisioning.
@Test
void initial_shouldTransitionToProvisioning() throws InterruptedException {
var process = createTransferProcess(INITIAL);
when(policyArchive.findPolicyForContract(anyString())).thenReturn(Policy.Builder.newInstance().build());
when(transferProcessStore.nextForState(eq(INITIAL.code()), anyInt())).thenReturn(List.of(process)).thenReturn(emptyList());
var resourceManifest = ResourceManifest.Builder.newInstance().definitions(List.of(new TestResourceDefinition())).build();
when(manifestGenerator.generateConsumerResourceManifest(any(DataRequest.class), any(Policy.class))).thenReturn(resourceManifest);
var latch = countDownOnUpdateLatch();
manager.start();
assertThat(latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue();
verify(policyArchive, atLeastOnce()).findPolicyForContract(anyString());
verifyNoInteractions(provisionManager);
verify(transferProcessStore).update(argThat(p -> p.getState() == PROVISIONING.code()));
}
use of org.eclipse.dataspaceconnector.spi.policy.store.PolicyArchive in project DataSpaceConnector by eclipse-dataspaceconnector.
the class TransferProcessManagerImplTest method deprovisioning_shouldTransitionToErrorOnDeprovisionException.
@Test
void deprovisioning_shouldTransitionToErrorOnDeprovisionException() throws InterruptedException {
var process = createTransferProcess(DEPROVISIONING).toBuilder().resourceManifest(ResourceManifest.Builder.newInstance().definitions(List.of(new TestResourceDefinition())).build()).build();
when(policyArchive.findPolicyForContract(anyString())).thenReturn(Policy.Builder.newInstance().build());
when(provisionManager.deprovision(any(), isA(Policy.class))).thenReturn(failedFuture(new EdcException("provision failed")));
when(transferProcessStore.nextForState(eq(DEPROVISIONING.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() == ERROR.code()));
}
use of org.eclipse.dataspaceconnector.spi.policy.store.PolicyArchive in project DataSpaceConnector by eclipse-dataspaceconnector.
the class TransferProcessManagerImplTest method deprovisioning_shouldTransitionToErrorOnFatalDeprovisionError.
@Test
void deprovisioning_shouldTransitionToErrorOnFatalDeprovisionError() throws InterruptedException {
var manifest = ResourceManifest.Builder.newInstance().definitions(List.of(new TestResourceDefinition())).build();
var resourceSet = ProvisionedResourceSet.Builder.newInstance().resources(List.of(new TestProvisionedDataDestinationResource("test", PROVISIONED_RESOURCE_ID))).build();
var process = createTransferProcess(DEPROVISIONING).toBuilder().resourceManifest(manifest).provisionedResourceSet(resourceSet).build();
var deprovisionResult = StatusResult.<DeprovisionedResource>failure(ResponseStatus.FATAL_ERROR, "test error");
when(policyArchive.findPolicyForContract(anyString())).thenReturn(Policy.Builder.newInstance().build());
when(provisionManager.deprovision(any(), isA(Policy.class))).thenReturn(completedFuture(List.of(deprovisionResult)));
when(transferProcessStore.nextForState(eq(DEPROVISIONING.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() == ERROR.code()));
}
Aggregations