Search in sources :

Example 1 with Policy

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");
}
Also used : Policy(org.eclipse.dataspaceconnector.policy.model.Policy) TestResourceDefinition(org.eclipse.dataspaceconnector.transfer.core.TestResourceDefinition) BeforeEach(org.junit.jupiter.api.BeforeEach) Policy(org.eclipse.dataspaceconnector.policy.model.Policy) TestProvisionedDataDestinationResource(org.eclipse.dataspaceconnector.transfer.core.TestProvisionedDataDestinationResource) ProvisionedResource(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedResource) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EdcException(org.eclipse.dataspaceconnector.spi.EdcException) Mockito.when(org.mockito.Mockito.when) StatusResult(org.eclipse.dataspaceconnector.spi.response.StatusResult) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) DeprovisionedResource(org.eclipse.dataspaceconnector.spi.types.domain.transfer.DeprovisionedResource) CompletableFuture.failedFuture(java.util.concurrent.CompletableFuture.failedFuture) Provisioner(org.eclipse.dataspaceconnector.spi.transfer.provision.Provisioner) List(java.util.List) ProvisionResponse(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionResponse) ProvisionedDataDestinationResource(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedDataDestinationResource) Monitor(org.eclipse.dataspaceconnector.spi.monitor.Monitor) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) Mockito.mock(org.mockito.Mockito.mock) TestProvisionedDataDestinationResource(org.eclipse.dataspaceconnector.transfer.core.TestProvisionedDataDestinationResource) ProvisionedDataDestinationResource(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedDataDestinationResource) StatusResult(org.eclipse.dataspaceconnector.spi.response.StatusResult) TestResourceDefinition(org.eclipse.dataspaceconnector.transfer.core.TestResourceDefinition) TestProvisionedDataDestinationResource(org.eclipse.dataspaceconnector.transfer.core.TestProvisionedDataDestinationResource) Test(org.junit.jupiter.api.Test)

Example 2 with Policy

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());
}
Also used : Policy(org.eclipse.dataspaceconnector.policy.model.Policy) ComponentTest(org.eclipse.dataspaceconnector.common.annotations.ComponentTest) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with Policy

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());
}
Also used : Interceptor(okhttp3.Interceptor) BeforeEach(org.junit.jupiter.api.BeforeEach) Policy(org.eclipse.dataspaceconnector.policy.model.Policy) HTTP_1_1(okhttp3.Protocol.HTTP_1_1) FATAL_ERROR(org.eclipse.dataspaceconnector.spi.response.ResponseStatus.FATAL_ERROR) TypeManager(org.eclipse.dataspaceconnector.spi.types.TypeManager) DataRequest(org.eclipse.dataspaceconnector.spi.types.domain.transfer.DataRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UUID(java.util.UUID) DataAddress(org.eclipse.dataspaceconnector.spi.types.domain.DataAddress) Test(org.junit.jupiter.api.Test) OkHttpClient(okhttp3.OkHttpClient) Response(okhttp3.Response) ERROR_RETRY(org.eclipse.dataspaceconnector.spi.response.ResponseStatus.ERROR_RETRY) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TestUtils.testOkHttpClient(org.eclipse.dataspaceconnector.common.testfixtures.TestUtils.testOkHttpClient) MediaType(okhttp3.MediaType) ResponseBody(okhttp3.ResponseBody) Monitor(org.eclipse.dataspaceconnector.spi.monitor.Monitor) Mockito.mock(org.mockito.Mockito.mock) Interceptor(okhttp3.Interceptor) Test(org.junit.jupiter.api.Test)

Example 4 with Policy

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);
}
Also used : Policy(org.eclipse.dataspaceconnector.policy.model.Policy) Test(org.junit.jupiter.api.Test)

Example 5 with 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);
    });
}
Also used : BlobStoreApi(org.eclipse.dataspaceconnector.azure.blob.core.api.BlobStoreApi) Policy(org.eclipse.dataspaceconnector.policy.model.Policy) ProvisionedResource(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedResource) Failsafe.with(net.jodah.failsafe.Failsafe.with) ResourceDefinition(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ResourceDefinition) RetryPolicy(net.jodah.failsafe.RetryPolicy) CompletableFuture(java.util.concurrent.CompletableFuture) StatusResult(org.eclipse.dataspaceconnector.spi.response.StatusResult) DeprovisionedResource(org.eclipse.dataspaceconnector.spi.types.domain.transfer.DeprovisionedResource) Provisioner(org.eclipse.dataspaceconnector.spi.transfer.provision.Provisioner) OffsetDateTime(java.time.OffsetDateTime) AzureSasToken(org.eclipse.dataspaceconnector.azure.blob.core.AzureSasToken) ProvisionResponse(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionResponse) NotNull(org.jetbrains.annotations.NotNull) Monitor(org.eclipse.dataspaceconnector.spi.monitor.Monitor) OffsetDateTime(java.time.OffsetDateTime) AzureSasToken(org.eclipse.dataspaceconnector.azure.blob.core.AzureSasToken)

Aggregations

Policy (org.eclipse.dataspaceconnector.policy.model.Policy)27 Test (org.junit.jupiter.api.Test)23 Monitor (org.eclipse.dataspaceconnector.spi.monitor.Monitor)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 ParticipantAgent (org.eclipse.dataspaceconnector.spi.agent.ParticipantAgent)4 DataAddress (org.eclipse.dataspaceconnector.spi.types.domain.DataAddress)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Mockito.mock (org.mockito.Mockito.mock)4 UUID (java.util.UUID)3 Interceptor (okhttp3.Interceptor)3 MediaType (okhttp3.MediaType)3 OkHttpClient (okhttp3.OkHttpClient)3 HTTP_1_1 (okhttp3.Protocol.HTTP_1_1)3 Response (okhttp3.Response)3 ResponseBody (okhttp3.ResponseBody)3 TestUtils.testOkHttpClient (org.eclipse.dataspaceconnector.common.testfixtures.TestUtils.testOkHttpClient)3 PolicyEvaluator (org.eclipse.dataspaceconnector.policy.engine.PolicyEvaluator)3 PolicyTestFunctions.createLiteralAtomicConstraint (org.eclipse.dataspaceconnector.policy.engine.model.PolicyTestFunctions.createLiteralAtomicConstraint)3 AndConstraint (org.eclipse.dataspaceconnector.policy.model.AndConstraint)3 AtomicConstraint (org.eclipse.dataspaceconnector.policy.model.AtomicConstraint)3