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"));
}
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");
}
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");
}
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"));
}
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");
}
Aggregations