use of org.eclipse.dataspaceconnector.policy.model.Policy 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.policy.model.Policy in project DataSpaceConnector by eclipse-dataspaceconnector.
the class SqlPolicyStoreTest method save_alreadyExists.
@Test
@DisplayName("Save (update) a single policy that already exists")
void save_alreadyExists() {
var id = getRandomId();
Policy policy1 = Policy.Builder.newInstance().id(id).target("Target1").build();
Policy policy2 = Policy.Builder.newInstance().id(id).target("Target2").build();
var spec = QuerySpec.Builder.newInstance().build();
sqlPolicyStore.save(policy1);
sqlPolicyStore.save(policy2);
var policyFromDb = sqlPolicyStore.findAll(spec).collect(Collectors.toList());
assertThat(1).isEqualTo(policyFromDb.size());
assertThat("Target2").isEqualTo(policyFromDb.get(0).getTarget());
}
use of org.eclipse.dataspaceconnector.policy.model.Policy in project DataSpaceConnector by eclipse-dataspaceconnector.
the class HttpDataFlowControllerTest method verifyRetryErrorResponse.
@Test
void verifyRetryErrorResponse() {
Interceptor delegate = chain -> new Response.Builder().request(chain.request()).protocol(HTTP_1_1).code(500).body(ResponseBody.create("", MediaType.get("application/json"))).message("ok").build();
httpClient = testOkHttpClient().newBuilder().addInterceptor(delegate).build();
var dataRequest = createDataRequest();
var contentAddress = DataAddress.Builder.newInstance().type("test").build();
var policy = Policy.Builder.newInstance().build();
assertEquals(ERROR_RETRY, flowController.initiateFlow(dataRequest, contentAddress, policy).getFailure().status());
}
use of org.eclipse.dataspaceconnector.policy.model.Policy in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CachedAssetTest method getPolicy.
@Test
void getPolicy() {
Policy policy = Policy.Builder.newInstance().build();
var ca = CachedAsset.Builder.newInstance().policy(policy).id("testAsset1").name("test-asset").build();
assertThat(ca.getPolicy()).isEqualTo(policy);
}
use of org.eclipse.dataspaceconnector.policy.model.Policy in project DataSpaceConnector by eclipse-dataspaceconnector.
the class ObjectStorageProvisioner method provision.
@Override
public CompletableFuture<StatusResult<ProvisionResponse>> provision(ObjectStorageResourceDefinition resourceDefinition, Policy policy) {
String containerName = resourceDefinition.getContainerName();
String accountName = resourceDefinition.getAccountName();
monitor.info("Azure Storage Container request submitted: " + containerName);
OffsetDateTime expiryTime = OffsetDateTime.now().plusHours(1);
return with(retryPolicy).getAsync(() -> blobStoreApi.exists(accountName, containerName)).thenCompose(exists -> {
if (exists) {
return reusingExistingContainer(containerName);
} else {
return createContainer(containerName, accountName);
}
}).thenCompose(empty -> createContainerSasToken(containerName, accountName, expiryTime)).thenApply(writeOnlySas -> {
// Ensure resource name is unique to avoid key collisions in local and remote vaults
String resourceName = resourceDefinition.getId() + "-container";
var resource = ObjectContainerProvisionedResource.Builder.newInstance().id(containerName).accountName(accountName).containerName(containerName).resourceDefinitionId(resourceDefinition.getId()).transferProcessId(resourceDefinition.getTransferProcessId()).resourceName(resourceName).hasToken(true).build();
var secretToken = new AzureSasToken("?" + writeOnlySas, expiryTime.toInstant().toEpochMilli());
var response = ProvisionResponse.Builder.newInstance().resource(resource).secretToken(secretToken).build();
return StatusResult.success(response);
});
}
Aggregations