Search in sources :

Example 1 with AssetDocument

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

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");
}
Also used : Asset(org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset) AssetDocument(org.eclipse.dataspaceconnector.assetindex.azure.model.AssetDocument) AzureCosmosDbIntegrationTest(org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with AssetDocument

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());
}
Also used : Asset(org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset) AssetDocument(org.eclipse.dataspaceconnector.assetindex.azure.model.AssetDocument) AzureCosmosDbIntegrationTest(org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with AssetDocument

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));
}
Also used : SqlQuerySpec(com.azure.cosmos.models.SqlQuerySpec) Asset(org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset) AssetDocument(org.eclipse.dataspaceconnector.assetindex.azure.model.AssetDocument) Test(org.junit.jupiter.api.Test)

Example 5 with AssetDocument

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);
}
Also used : Asset(org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset) AssetDocument(org.eclipse.dataspaceconnector.assetindex.azure.model.AssetDocument) Test(org.junit.jupiter.api.Test)

Aggregations

AssetDocument (org.eclipse.dataspaceconnector.assetindex.azure.model.AssetDocument)18 Test (org.junit.jupiter.api.Test)17 Asset (org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset)16 AzureCosmosDbIntegrationTest (org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest)9 SqlQuerySpec (com.azure.cosmos.models.SqlQuerySpec)5 AssetSelectorExpression (org.eclipse.dataspaceconnector.spi.asset.AssetSelectorExpression)4 CosmosContainer (com.azure.cosmos.CosmosContainer)2 CosmosDatabase (com.azure.cosmos.CosmosDatabase)2 CosmosDatabaseResponse (com.azure.cosmos.models.CosmosDatabaseResponse)2 PartitionKey (com.azure.cosmos.models.PartitionKey)2 String.format (java.lang.String.format)2 List (java.util.List)2 UUID (java.util.UUID)2 Collectors (java.util.stream.Collectors)2 IntStream (java.util.stream.IntStream)2 RetryPolicy (net.jodah.failsafe.RetryPolicy)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 CosmosDbApiImpl (org.eclipse.dataspaceconnector.azure.cosmos.CosmosDbApiImpl)2 CosmosTestClient (org.eclipse.dataspaceconnector.azure.testfixtures.CosmosTestClient)2