use of org.eclipse.dataspaceconnector.assetindex.azure.model.AssetDocument 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.assetindex.azure.model.AssetDocument in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosAssetIndexIntegrationTest method queryAssets_operatorIn_syntaxError_throwsException.
@Test
void queryAssets_operatorIn_syntaxError_throwsException() {
Asset asset1 = createAsset("123", "hello", "world");
Asset asset2 = createAsset("456", "foo", "bar");
container.createItem(new AssetDocument(asset1, TEST_PARTITION_KEY, dataAddress));
container.createItem(new AssetDocument(asset2, TEST_PARTITION_KEY, dataAddress));
var inExpr = format("('%s' ; '%s')", asset1.getId(), asset2.getId());
var selector = AssetSelectorExpression.Builder.newInstance().constraint(Asset.PROPERTY_ID, "IN foobar", List.of(asset1.getId(), asset2.getId())).build();
// collecting is necessary, otherwise the cosmos query is not executed
assertThatThrownBy(() -> assetIndex.queryAssets(selector).collect(Collectors.toList())).isInstanceOf(IllegalArgumentException.class).hasMessage("Cannot build WHERE clause, reason: unsupported operator IN foobar");
}
use of org.eclipse.dataspaceconnector.assetindex.azure.model.AssetDocument in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosAssetIndexIntegrationTest method findAll_noQuerySpec.
@Test
void findAll_noQuerySpec() {
Asset asset1 = createAsset("123", "test", "world");
container.createItem(new AssetDocument(asset1, TEST_PARTITION_KEY, dataAddress));
var all = assetIndex.queryAssets(QuerySpec.none());
assertThat(all).hasSize(1).extracting(Asset::getId).containsExactly(asset1.getId());
}
use of org.eclipse.dataspaceconnector.assetindex.azure.model.AssetDocument in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosAssetIndexTest method findAll_withFiltering.
@Test
void findAll_withFiltering() {
AssetDocument document = createDocument(TEST_ID);
var expectedQuery = "SELECT * FROM AssetDocument WHERE AssetDocument.wrappedInstance.someField = @someField OFFSET 5 LIMIT 100";
when(api.queryItems(argThat(queryMatches(expectedQuery)))).thenReturn(Stream.of(document));
List<Asset> assets = assetIndex.queryAssets(QuerySpec.Builder.newInstance().offset(5).limit(100).filter("someField=randomValue").build()).collect(Collectors.toList());
assertThat(assets).hasSize(1).extracting(Asset::getId).containsExactly(document.getWrappedAsset().getId());
assertThat(assets).extracting(Asset::getProperties).allSatisfy(m -> assertThat(m).containsAllEntriesOf(document.getWrappedAsset().getProperties()));
verify(api).queryItems(any(SqlQuerySpec.class));
}
use of org.eclipse.dataspaceconnector.assetindex.azure.model.AssetDocument in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosAssetIndexTest method findById.
@Test
void findById() {
AssetDocument document = createDocument(TEST_ID);
when(api.queryItemById(TEST_ID)).thenReturn(document);
Asset actualAsset = assetIndex.findById(TEST_ID);
assertThat(actualAsset.getProperties()).isEqualTo(document.getWrappedAsset().getProperties());
verify(api).queryItemById(TEST_ID);
}
Aggregations