Changesets · Branches · Tags · Compare
| Changeset | f28dc1f7ad58413e547eb449ca25b386974ff08ffb0a31c17c99e69602e6c01f |
|---|---|
| Author | Enrico Risa <enrico.risa@gmail.com> · 2024-07-12 12:34 +02:00 |
| Committer | GitHub <noreply@github.com> · 2024-07-12 12:34 +02:00 |
| Parents | fcd94f559e2a |
3 files changed
modified spi/control-plane/catalog-spi/build.gradle.kts +3 −0
| @@ -20,6 +20,9 @@ | ||
| 20 | 20 | dependencies { |
| 21 | 21 | api(project(":spi:common:core-spi")) |
| 22 | 22 | api(project(":spi:control-plane:asset-spi")) |
| 23 | + | |
| 24 | + testImplementation(project(":core:common:lib:json-lib")) | |
| 25 | + | |
| 23 | 26 | } |
| 24 | 27 | |
| 25 | 28 |
modified spi/control-plane/catalog-spi/src/main/java/org/eclipse/edc/connector/controlplane/catalog/spi/Dataset.java +5 −0
| @@ -99,6 +99,11 @@ | ||
| 99 | 99 | return self(); |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | + public B offers(Map<String, Policy> offers) { | |
| 103 | + dataset.offers.putAll(offers); | |
| 104 | + return self(); | |
| 105 | + } | |
| 106 | + | |
| 102 | 107 | public B distribution(Distribution distribution) { |
| 103 | 108 | if (dataset.distributions == null) { |
| 104 | 109 | dataset.distributions = new ArrayList<>(); |
added spi/control-plane/catalog-spi/src/test/java/org/eclipse/edc/connector/controlplane/catalog/spi/CatalogSerializationTest.java +62 −0
| @@ -0,0 +1,62 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2022 Microsoft Corporation | |
| 3 | + * | |
| 4 | + * This program and the accompanying materials are made available under the | |
| 5 | + * terms of the Apache License, Version 2.0 which is available at | |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | + * | |
| 8 | + * SPDX-License-Identifier: Apache-2.0 | |
| 9 | + * | |
| 10 | + * Contributors: | |
| 11 | + * Microsoft Corporation - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.connector.controlplane.catalog.spi; | |
| 16 | + | |
| 17 | +import org.eclipse.edc.json.JacksonTypeManager; | |
| 18 | +import org.eclipse.edc.policy.model.Policy; | |
| 19 | +import org.eclipse.edc.spi.types.TypeManager; | |
| 20 | +import org.junit.jupiter.api.Test; | |
| 21 | + | |
| 22 | +import java.util.List; | |
| 23 | +import java.util.Map; | |
| 24 | + | |
| 25 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 26 | + | |
| 27 | +class CatalogSerializationTest { | |
| 28 | + | |
| 29 | + private final TypeManager typeManager = new JacksonTypeManager(); | |
| 30 | + | |
| 31 | + @Test | |
| 32 | + void verifySerialization() { | |
| 33 | + var catalog = createCatalog(); | |
| 34 | + | |
| 35 | + var json = typeManager.writeValueAsString(catalog); | |
| 36 | + | |
| 37 | + var deserialized = typeManager.readValue(json, Catalog.class); | |
| 38 | + assertThat(deserialized).usingRecursiveComparison().isEqualTo(catalog); | |
| 39 | + } | |
| 40 | + | |
| 41 | + | |
| 42 | + @SuppressWarnings("unchecked") | |
| 43 | + private Catalog createCatalog() { | |
| 44 | + var dataService = DataService.Builder.newInstance().endpointUrl("http://endpoint").build(); | |
| 45 | + | |
| 46 | + var distribution = Distribution.Builder.newInstance().dataService(dataService).format("test-format").build(); | |
| 47 | + var dataset = Dataset.Builder.newInstance() | |
| 48 | + .id("assetId") | |
| 49 | + .properties(Map.of("key", "val")) | |
| 50 | + .offer("offer", Policy.Builder.newInstance().assignee("assignee").assigner("assigner").build()) | |
| 51 | + .distributions(List.of(distribution)) | |
| 52 | + .build(); | |
| 53 | + | |
| 54 | + return Catalog.Builder.newInstance() | |
| 55 | + .id("id") | |
| 56 | + .dataServices(List.of(dataService)) | |
| 57 | + .datasets(List.of(dataset)) | |
| 58 | + .property("prop", "propValue") | |
| 59 | + .build(); | |
| 60 | + } | |
| 61 | + | |
| 62 | +} |