Skip to content

Commit

Permalink
update dataset resolver + test
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger committed Jun 24, 2024
1 parent edc3ff4 commit 5019ebf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public Dataset getById(ParticipantAgent agent, String id) {
private Dataset toDataset(List<ContractDefinition> contractDefinitions, Asset asset) {

var distributions = distributionResolver.getDistributions(asset);
var datasetBuilder = asset.isCatalog() ? Catalog.Builder.newInstance() : Dataset.Builder.newInstance()
var datasetBuilder = asset.isCatalog() ? Catalog.Builder.newInstance() : Dataset.Builder.newInstance();
datasetBuilder
.id(asset.getId())
.distributions(distributions)
.properties(asset.getProperties());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.assertj.core.api.iterable.ThrowingExtractor;
import org.eclipse.edc.connector.controlplane.asset.spi.domain.Asset;
import org.eclipse.edc.connector.controlplane.asset.spi.index.AssetIndex;
import org.eclipse.edc.connector.controlplane.catalog.spi.Catalog;
import org.eclipse.edc.connector.controlplane.catalog.spi.DataService;
import org.eclipse.edc.connector.controlplane.catalog.spi.Dataset;
import org.eclipse.edc.connector.controlplane.catalog.spi.DatasetResolver;
Expand All @@ -28,6 +29,7 @@
import org.eclipse.edc.connector.controlplane.contract.spi.types.offer.ContractDefinition;
import org.eclipse.edc.connector.controlplane.policy.spi.PolicyDefinition;
import org.eclipse.edc.connector.controlplane.policy.spi.store.PolicyDefinitionStore;
import org.eclipse.edc.dataaddress.httpdata.spi.HttpDataAddressSchema;
import org.eclipse.edc.policy.model.Policy;
import org.eclipse.edc.query.CriterionOperatorRegistryImpl;
import org.eclipse.edc.spi.agent.ParticipantAgent;
Expand Down Expand Up @@ -219,6 +221,34 @@ void query_shouldLimitDataset_whenMultipleDefinitionsWithSameAssets() {
.map(getId()).containsExactly("6", "7");
}

@Test
void query_shouldReturnCatalogWithinCatalog_whenAssetIsCatalogAsset() {
var contractDefinition = contractDefinitionBuilder("definitionId").contractPolicyId("contractPolicyId").build();
var contractPolicy = Policy.Builder.newInstance().build();
var distribution = Distribution.Builder.newInstance().dataService(DataService.Builder.newInstance()
.endpointDescription("test-asset-desc")
.endpointUrl("https://foo.bar/baz")
.build())
.format(HttpDataAddressSchema.HTTP_DATA_TYPE).build();

when(contractDefinitionResolver.definitionsFor(any())).thenReturn(Stream.of(contractDefinition));
when(assetIndex.queryAssets(isA(QuerySpec.class))).thenReturn(Stream.of(createAsset("assetId").property(Asset.PROPERTY_IS_CATALOG, true).build()));
when(policyStore.findById("contractPolicyId")).thenReturn(PolicyDefinition.Builder.newInstance().policy(contractPolicy).build());
when(distributionResolver.getDistributions(isA(Asset.class))).thenReturn(List.of(distribution));

var datasets = datasetResolver.query(createParticipantAgent(), QuerySpec.none());

assertThat(datasets).isNotNull().hasSize(1).first().satisfies(dataset -> {
assertThat(dataset).isInstanceOf(Catalog.class);
assertThat(dataset.getId()).isEqualTo("assetId");
assertThat(dataset.getOffers()).hasSize(1).allSatisfy((id, policy) -> {
assertThat(ContractOfferId.parseId(id)).isSucceeded().extracting(ContractOfferId::definitionPart).asString().isEqualTo("definitionId");
assertThat(policy.getType()).isEqualTo(OFFER);
assertThat(policy.getTarget()).isEqualTo(null);
});
});
}

@Test
void getById_shouldReturnDataset() {
var policy1 = Policy.Builder.newInstance().inheritsFrom("inherits1").build();
Expand Down

0 comments on commit 5019ebf

Please sign in to comment.