Search in sources :

Example 1 with AssetSelectorExpression

use of org.eclipse.dataspaceconnector.spi.asset.AssetSelectorExpression in project DataSpaceConnector by eclipse-dataspaceconnector.

the class CosmosAssetIndexIntegrationTest method queryAssets_filterOnProperty.

@Test
void queryAssets_filterOnProperty() {
    Asset asset1 = createAsset("123", "test", "world");
    Asset asset2 = createAsset("456", "test", "bar");
    container.createItem(new AssetDocument(asset1, TEST_PARTITION_KEY, dataAddress));
    container.createItem(new AssetDocument(asset2, TEST_PARTITION_KEY, dataAddress));
    AssetSelectorExpression expression = AssetSelectorExpression.Builder.newInstance().whenEquals(Asset.PROPERTY_ID, "456").build();
    List<Asset> assets = assetIndex.queryAssets(expression).collect(Collectors.toList());
    assertThat(assets).hasSize(1).allSatisfy(asset -> assertThat(asset.getId()).isEqualTo("456"));
}
Also used : Asset(org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset) AssetDocument(org.eclipse.dataspaceconnector.assetindex.azure.model.AssetDocument) AssetSelectorExpression(org.eclipse.dataspaceconnector.spi.asset.AssetSelectorExpression) AzureCosmosDbIntegrationTest(org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with AssetSelectorExpression

use of org.eclipse.dataspaceconnector.spi.asset.AssetSelectorExpression in project DataSpaceConnector by eclipse-dataspaceconnector.

the class CosmosAssetQueryBuilderTest method queryWithFilerOnProperty.

@Test
void queryWithFilerOnProperty() {
    AssetSelectorExpression expression = AssetSelectorExpression.Builder.newInstance().whenEquals("id", "'id-test'").whenEquals("name", "'name-test'").build();
    SqlQuerySpec query = builder.from(expression.getCriteria());
    assertThat(query.getQueryText()).isEqualTo("SELECT * FROM AssetDocument WHERE AssetDocument.wrappedInstance.id = @id AND AssetDocument.wrappedInstance.name = @name");
    assertThat(query.getParameters()).hasSize(2).extracting(SqlParameter::getName).containsExactlyInAnyOrder("@id", "@name");
}
Also used : SqlQuerySpec(com.azure.cosmos.models.SqlQuerySpec) AssetSelectorExpression(org.eclipse.dataspaceconnector.spi.asset.AssetSelectorExpression) Test(org.junit.jupiter.api.Test)

Example 3 with AssetSelectorExpression

use of org.eclipse.dataspaceconnector.spi.asset.AssetSelectorExpression in project DataSpaceConnector by eclipse-dataspaceconnector.

the class CosmosAssetQueryBuilderTest method queryWithFilerOnPropertyWithIllegalArgs.

@Test
void queryWithFilerOnPropertyWithIllegalArgs() {
    AssetSelectorExpression expression = AssetSelectorExpression.Builder.newInstance().whenEquals("test:id", "'id-test'").whenEquals("test:name", "'name-test'").build();
    SqlQuerySpec query = builder.from(expression.getCriteria());
    assertThat(query.getQueryText()).isEqualTo("SELECT * FROM AssetDocument WHERE AssetDocument.wrappedInstance.test_id = @test_id AND AssetDocument.wrappedInstance.test_name = @test_name");
    assertThat(query.getParameters()).hasSize(2).extracting(SqlParameter::getName).containsExactlyInAnyOrder("@test_id", "@test_name");
}
Also used : SqlQuerySpec(com.azure.cosmos.models.SqlQuerySpec) AssetSelectorExpression(org.eclipse.dataspaceconnector.spi.asset.AssetSelectorExpression) Test(org.junit.jupiter.api.Test)

Example 4 with AssetSelectorExpression

use of org.eclipse.dataspaceconnector.spi.asset.AssetSelectorExpression in project DataSpaceConnector by eclipse-dataspaceconnector.

the class CosmosAssetIndexIntegrationTest method queryAssets_filterOnPropertyContainingIllegalArgs.

@Test
void queryAssets_filterOnPropertyContainingIllegalArgs() {
    Asset asset1 = createAsset("123", "test:value", "world");
    Asset asset2 = createAsset("456", "test:value", "bar");
    container.createItem(new AssetDocument(asset1, TEST_PARTITION_KEY, dataAddress));
    container.createItem(new AssetDocument(asset2, TEST_PARTITION_KEY, dataAddress));
    AssetSelectorExpression expression = AssetSelectorExpression.Builder.newInstance().whenEquals("test:value", "bar").build();
    List<Asset> assets = assetIndex.queryAssets(expression).collect(Collectors.toList());
    assertThat(assets).hasSize(1).allSatisfy(asset -> assertThat(asset.getId()).isEqualTo("456"));
}
Also used : Asset(org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset) AssetDocument(org.eclipse.dataspaceconnector.assetindex.azure.model.AssetDocument) AssetSelectorExpression(org.eclipse.dataspaceconnector.spi.asset.AssetSelectorExpression) AzureCosmosDbIntegrationTest(org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with AssetSelectorExpression

use of org.eclipse.dataspaceconnector.spi.asset.AssetSelectorExpression in project DataSpaceConnector by eclipse-dataspaceconnector.

the class CosmosAssetQueryBuilderTest method throwEdcExceptionIfCriterionOperationNotHandled.

@Test
void throwEdcExceptionIfCriterionOperationNotHandled() {
    AssetSelectorExpression expression = AssetSelectorExpression.Builder.newInstance().whenEquals("id", "id-test").constraint("name", "in", "name-test").build();
    assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> builder.from(expression.getCriteria())).withMessage("Cannot build WHERE clause, reason: The \"in\" operator requires the right-hand operand to be of type interface java.lang.Iterable but was actually class java.lang.String");
}
Also used : AssetSelectorExpression(org.eclipse.dataspaceconnector.spi.asset.AssetSelectorExpression) Test(org.junit.jupiter.api.Test)

Aggregations

AssetSelectorExpression (org.eclipse.dataspaceconnector.spi.asset.AssetSelectorExpression)5 Test (org.junit.jupiter.api.Test)5 SqlQuerySpec (com.azure.cosmos.models.SqlQuerySpec)2 AssetDocument (org.eclipse.dataspaceconnector.assetindex.azure.model.AssetDocument)2 AzureCosmosDbIntegrationTest (org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest)2 Asset (org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset)2