Changesets · Branches · Tags · Compare
| Changeset | 0822f691d4b1a49e39d1d2bb1f01d5ee71279a3f846dc8b9c418646133dc446c |
|---|---|
| Author | Enrico Risa <enrico.risa@gmail.com> · 2024-09-16 11:33 +02:00 |
| Committer | GitHub <noreply@github.com> · 2024-09-16 11:33 +02:00 |
| Parents | 548b9b363586 |
26 files changed
modified .github/workflows/publish-context.yaml +2 −2
| @@ -26,7 +26,7 @@ | ||
| 26 | 26 | push: |
| 27 | 27 | branches: [ main ] |
| 28 | 28 | paths: |
| 29 | - - 'extensions/common/api/management-api-json-ld-context/src/main/resources/document/**' | |
| 29 | + - 'extensions/common/json-ld/src/main/resources/document/**' | |
| 30 | 30 | |
| 31 | 31 | jobs: |
| 32 | 32 | build: |
| @@ -39,7 +39,7 @@ | ||
| 39 | 39 | - name: copy contexts into public folder |
| 40 | 40 | run: | |
| 41 | 41 | mkdir -p public/context |
| 42 | - cp extensions/common/api/management-api-json-ld-context/src/main/resources/document/management-context-v1.jsonld public/context/ | |
| 42 | + cp extensions/common/json-ld/src/main/resources/document/management-context-v1.jsonld public/context/ | |
| 43 | 43 | - name: deploy to gh-pages |
| 44 | 44 | uses: peaceiris/actions-gh-pages@v4 |
| 45 | 45 | with: |
modified core/common/lib/json-ld-lib/src/main/java/org/eclipse/edc/jsonld/JsonLdConfiguration.java +10 −0
| @@ -18,6 +18,7 @@ | ||
| 18 | 18 | |
| 19 | 19 | private boolean httpEnabled = false; |
| 20 | 20 | private boolean httpsEnabled = false; |
| 21 | + private boolean avoidVocab = false; | |
| 21 | 22 | private boolean checkPrefixes = true; |
| 22 | 23 | |
| 23 | 24 | private JsonLdConfiguration() { |
| @@ -36,6 +37,10 @@ | ||
| 36 | 37 | return checkPrefixes; |
| 37 | 38 | } |
| 38 | 39 | |
| 40 | + public boolean isAvoidVocab() { | |
| 41 | + return avoidVocab; | |
| 42 | + } | |
| 43 | + | |
| 39 | 44 | public static class Builder { |
| 40 | 45 | |
| 41 | 46 | private final JsonLdConfiguration configuration = new JsonLdConfiguration(); |
| @@ -54,6 +59,11 @@ | ||
| 54 | 59 | return this; |
| 55 | 60 | } |
| 56 | 61 | |
| 62 | + public Builder avoidVocab(boolean avoidVocab) { | |
| 63 | + configuration.avoidVocab = avoidVocab; | |
| 64 | + return this; | |
| 65 | + } | |
| 66 | + | |
| 57 | 67 | public Builder checkPrefixes(boolean checkPrefixes) { |
| 58 | 68 | configuration.checkPrefixes = checkPrefixes; |
| 59 | 69 | return this; |
modified core/common/lib/json-ld-lib/src/main/java/org/eclipse/edc/jsonld/TitaniumJsonLd.java +9 −2
| @@ -49,6 +49,7 @@ | ||
| 49 | 49 | import static jakarta.json.Json.createBuilderFactory; |
| 50 | 50 | import static jakarta.json.Json.createObjectBuilder; |
| 51 | 51 | import static java.util.Optional.ofNullable; |
| 52 | +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VOCAB; | |
| 52 | 53 | |
| 53 | 54 | /** |
| 54 | 55 | * Implementation of the {@link JsonLd} interface that uses the Titanium library for all JSON-LD operations. |
| @@ -66,6 +67,7 @@ | ||
| 66 | 67 | private final JsonObjectValidator validator; |
| 67 | 68 | |
| 68 | 69 | private final boolean shouldCheckPrefixes; |
| 70 | + private final boolean isVocabEnabled; | |
| 69 | 71 | |
| 70 | 72 | public TitaniumJsonLd(Monitor monitor) { |
| 71 | 73 | this(monitor, JsonLdConfiguration.Builder.newInstance().build()); |
| @@ -75,6 +77,7 @@ | ||
| 75 | 77 | this.monitor = monitor; |
| 76 | 78 | this.documentLoader = new CachedDocumentLoader(configuration, monitor); |
| 77 | 79 | this.shouldCheckPrefixes = configuration.shouldCheckPrefixes(); |
| 80 | + this.isVocabEnabled = configuration.isAvoidVocab(); | |
| 78 | 81 | this.validator = JsonObjectValidator.newValidator() |
| 79 | 82 | .verify((path) -> new MissingPrefixes(path, this::getAllPrefixes)) |
| 80 | 83 | .build(); |
| @@ -124,6 +127,10 @@ | ||
| 124 | 127 | |
| 125 | 128 | @Override |
| 126 | 129 | public void registerNamespace(String prefix, String contextIri, String scope) { |
| 130 | + // skip the @vocab if it's not enabled | |
| 131 | + if (isVocabEnabled && VOCAB.equals(prefix)) { | |
| 132 | + return; | |
| 133 | + } | |
| 127 | 134 | var namespaces = scopedNamespaces.computeIfAbsent(scope, k -> new LinkedHashMap<>()); |
| 128 | 135 | namespaces.put(prefix, contextIri); |
| 129 | 136 | } |
| @@ -146,9 +153,9 @@ | ||
| 146 | 153 | if (json.get(JsonLdKeywords.CONTEXT) instanceof JsonObject) { |
| 147 | 154 | var contextObject = ofNullable(json.getJsonObject(JsonLdKeywords.CONTEXT)).orElseGet(() -> createObjectBuilder().build()); |
| 148 | 155 | var contextBuilder = createObjectBuilder(contextObject); |
| 149 | - if (!contextObject.containsKey(JsonLdKeywords.VOCAB)) { | |
| 156 | + if (!contextObject.containsKey(VOCAB)) { | |
| 150 | 157 | var newContextObject = contextBuilder |
| 151 | - .add(JsonLdKeywords.VOCAB, CoreConstants.EDC_NAMESPACE) | |
| 158 | + .add(VOCAB, CoreConstants.EDC_NAMESPACE) | |
| 152 | 159 | .build(); |
| 153 | 160 | jsonObjectBuilder.add(JsonLdKeywords.CONTEXT, newContextObject); |
| 154 | 161 | } |
modified core/common/lib/json-ld-lib/src/test/java/org/eclipse/edc/jsonld/TitaniumJsonLdTest.java +30 −0
| @@ -33,7 +33,9 @@ | ||
| 33 | 33 | |
| 34 | 34 | import static jakarta.json.Json.createArrayBuilder; |
| 35 | 35 | import static jakarta.json.Json.createObjectBuilder; |
| 36 | +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VOCAB; | |
| 36 | 37 | import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; |
| 38 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 37 | 39 | import static org.mockito.Mockito.mock; |
| 38 | 40 | |
| 39 | 41 | class TitaniumJsonLdTest { |
| @@ -147,6 +149,34 @@ | ||
| 147 | 149 | }); |
| 148 | 150 | } |
| 149 | 151 | |
| 152 | + @Test | |
| 153 | + void compact_withVocab() { | |
| 154 | + var expanded = Json.createObjectBuilder() | |
| 155 | + .add(EDC_NAMESPACE + "item", "test") | |
| 156 | + .build(); | |
| 157 | + var jsonLd = defaultService(); | |
| 158 | + jsonLd.registerNamespace(VOCAB, EDC_NAMESPACE); | |
| 159 | + var compacted = jsonLd.compact(expanded); | |
| 160 | + | |
| 161 | + assertThat(compacted).isSucceeded().satisfies(c -> { | |
| 162 | + Assertions.assertThat(c.getString("item")).isEqualTo("test"); | |
| 163 | + }); | |
| 164 | + } | |
| 165 | + | |
| 166 | + @Test | |
| 167 | + void compact_withVocabDisabled() { | |
| 168 | + var expanded = Json.createObjectBuilder() | |
| 169 | + .add(EDC_NAMESPACE + "item", "test") | |
| 170 | + .build(); | |
| 171 | + var jsonLd = defaultService(JsonLdConfiguration.Builder.newInstance().avoidVocab(true).build()); | |
| 172 | + jsonLd.registerNamespace(VOCAB, EDC_NAMESPACE); | |
| 173 | + var compacted = jsonLd.compact(expanded); | |
| 174 | + | |
| 175 | + assertThat(compacted).isSucceeded().satisfies(c -> { | |
| 176 | + Assertions.assertThat(c.getString(EDC_NAMESPACE + "item")).isEqualTo("test"); | |
| 177 | + }); | |
| 178 | + } | |
| 179 | + | |
| 150 | 180 | @Test |
| 151 | 181 | void compact_withCustomPrefix() { |
| 152 | 182 | var ns = "https://test.org/schema/"; |
modified data-protocols/dsp/dsp-http-api-configuration/src/main/java/org/eclipse/edc/protocol/dsp/http/api/configuration/DspApiConfigurationExtension.java +6 −0
| @@ -52,6 +52,7 @@ | ||
| 52 | 52 | import java.util.Map; |
| 53 | 53 | |
| 54 | 54 | import static java.lang.String.format; |
| 55 | +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VOCAB; | |
| 55 | 56 | import static org.eclipse.edc.jsonld.spi.Namespaces.DCAT_PREFIX; |
| 56 | 57 | import static org.eclipse.edc.jsonld.spi.Namespaces.DCAT_SCHEMA; |
| 57 | 58 | import static org.eclipse.edc.jsonld.spi.Namespaces.DCT_PREFIX; |
| @@ -61,6 +62,8 @@ | ||
| 61 | 62 | import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_PREFIX; |
| 62 | 63 | import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_SCHEMA; |
| 63 | 64 | import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_SCOPE; |
| 65 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 66 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_PREFIX; | |
| 64 | 67 | import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; |
| 65 | 68 | |
| 66 | 69 | /** |
| @@ -122,6 +125,9 @@ | ||
| 122 | 125 | jsonLd.registerNamespace(DCT_PREFIX, DCT_SCHEMA, DSP_SCOPE); |
| 123 | 126 | jsonLd.registerNamespace(ODRL_PREFIX, ODRL_SCHEMA, DSP_SCOPE); |
| 124 | 127 | jsonLd.registerNamespace(DSPACE_PREFIX, DSPACE_SCHEMA, DSP_SCOPE); |
| 128 | + jsonLd.registerNamespace(VOCAB, EDC_NAMESPACE, DSP_SCOPE); | |
| 129 | + jsonLd.registerNamespace(EDC_PREFIX, EDC_NAMESPACE, DSP_SCOPE); | |
| 130 | + | |
| 125 | 131 | |
| 126 | 132 | webService.registerResource(ApiContext.PROTOCOL, new ObjectMapperProvider(jsonLdMapper)); |
| 127 | 133 | webService.registerResource(ApiContext.PROTOCOL, new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper, DSP_SCOPE)); |
modified data-protocols/dsp/dsp-http-api-configuration/src/test/java/org/eclipse/edc/protocol/dsp/http/api/configuration/DspApiConfigurationExtensionTest.java +26 −0
| @@ -14,6 +14,7 @@ | ||
| 14 | 14 | |
| 15 | 15 | package org.eclipse.edc.protocol.dsp.http.api.configuration; |
| 16 | 16 | |
| 17 | +import org.eclipse.edc.jsonld.spi.JsonLd; | |
| 17 | 18 | import org.eclipse.edc.junit.extensions.DependencyInjectionExtension; |
| 18 | 19 | import org.eclipse.edc.spi.protocol.ProtocolWebhook; |
| 19 | 20 | import org.eclipse.edc.spi.system.Hostname; |
| @@ -36,8 +37,18 @@ | ||
| 36 | 37 | import java.util.Map; |
| 37 | 38 | |
| 38 | 39 | import static org.assertj.core.api.Assertions.assertThat; |
| 40 | +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VOCAB; | |
| 41 | +import static org.eclipse.edc.jsonld.spi.Namespaces.DCAT_PREFIX; | |
| 42 | +import static org.eclipse.edc.jsonld.spi.Namespaces.DCAT_SCHEMA; | |
| 43 | +import static org.eclipse.edc.jsonld.spi.Namespaces.DCT_PREFIX; | |
| 44 | +import static org.eclipse.edc.jsonld.spi.Namespaces.DCT_SCHEMA; | |
| 45 | +import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_PREFIX; | |
| 46 | +import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_SCHEMA; | |
| 39 | 47 | import static org.eclipse.edc.protocol.dsp.http.api.configuration.DspApiConfigurationExtension.DSP_CALLBACK_ADDRESS; |
| 40 | 48 | import static org.eclipse.edc.protocol.dsp.http.api.configuration.DspApiConfigurationExtension.SETTINGS; |
| 49 | +import static org.eclipse.edc.protocol.dsp.spi.type.DspConstants.DSP_SCOPE; | |
| 50 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 51 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_PREFIX; | |
| 41 | 52 | import static org.mockito.ArgumentMatchers.any; |
| 42 | 53 | import static org.mockito.ArgumentMatchers.eq; |
| 43 | 54 | import static org.mockito.ArgumentMatchers.isA; |
| @@ -52,6 +63,8 @@ | ||
| 52 | 63 | private final WebServer webServer = mock(); |
| 53 | 64 | private final WebService webService = mock(); |
| 54 | 65 | private final TypeManager typeManager = mock(); |
| 66 | + private final JsonLd jsonLd = mock(); | |
| 67 | + | |
| 55 | 68 | |
| 56 | 69 | @BeforeEach |
| 57 | 70 | void setUp(ServiceExtensionContext context) { |
| @@ -60,6 +73,7 @@ | ||
| 60 | 73 | context.registerService(WebServiceConfigurer.class, configurer); |
| 61 | 74 | context.registerService(TypeManager.class, typeManager); |
| 62 | 75 | context.registerService(Hostname.class, () -> "hostname"); |
| 76 | + context.registerService(JsonLd.class, jsonLd); | |
| 63 | 77 | TypeTransformerRegistry typeTransformerRegistry = mock(); |
| 64 | 78 | when(typeTransformerRegistry.forContext(any())).thenReturn(mock()); |
| 65 | 79 | context.registerService(TypeTransformerRegistry.class, typeTransformerRegistry); |
| @@ -105,4 +119,16 @@ | ||
| 105 | 119 | verify(webService).registerResource(eq(ApiContext.PROTOCOL), isA(JerseyJsonLdInterceptor.class)); |
| 106 | 120 | } |
| 107 | 121 | |
| 122 | + @Test | |
| 123 | + void initialize_shouldRegisterNamespaces(DspApiConfigurationExtension extension, ServiceExtensionContext context) { | |
| 124 | + extension.initialize(context); | |
| 125 | + | |
| 126 | + verify(jsonLd).registerNamespace(DCAT_PREFIX, DCAT_SCHEMA, DSP_SCOPE); | |
| 127 | + verify(jsonLd).registerNamespace(DCT_PREFIX, DCT_SCHEMA, DSP_SCOPE); | |
| 128 | + verify(jsonLd).registerNamespace(ODRL_PREFIX, ODRL_SCHEMA, DSP_SCOPE); | |
| 129 | + verify(jsonLd).registerNamespace(VOCAB, EDC_NAMESPACE, DSP_SCOPE); | |
| 130 | + verify(jsonLd).registerNamespace(EDC_PREFIX, EDC_NAMESPACE, DSP_SCOPE); | |
| 131 | + verify(jsonLd).registerNamespace(ODRL_PREFIX, ODRL_SCHEMA, DSP_SCOPE); | |
| 132 | + } | |
| 133 | + | |
| 108 | 134 | } |
modified extensions/common/api/control-api-configuration/src/main/java/org/eclipse/edc/connector/api/control/configuration/ControlApiConfigurationExtension.java +6 −4
| @@ -45,10 +45,13 @@ | ||
| 45 | 45 | import java.util.stream.Stream; |
| 46 | 46 | |
| 47 | 47 | import static java.lang.String.format; |
| 48 | +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VOCAB; | |
| 48 | 49 | import static org.eclipse.edc.jsonld.spi.Namespaces.DSPACE_PREFIX; |
| 49 | 50 | import static org.eclipse.edc.jsonld.spi.Namespaces.DSPACE_SCHEMA; |
| 50 | 51 | import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_PREFIX; |
| 51 | 52 | import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_SCHEMA; |
| 53 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 54 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_PREFIX; | |
| 52 | 55 | import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; |
| 53 | 56 | |
| 54 | 57 | /** |
| @@ -63,12 +66,10 @@ | ||
| 63 | 66 | |
| 64 | 67 | @Setting(value = "Configures endpoint for reaching the Control API. If it's missing it defaults to the hostname configuration.") |
| 65 | 68 | public static final String CONTROL_API_ENDPOINT = "edc.control.endpoint"; |
| 66 | - | |
| 69 | + public static final String CONTROL_SCOPE = "CONTROL_API"; | |
| 67 | 70 | private static final String WEB_SERVICE_NAME = "Control API"; |
| 68 | - | |
| 69 | 71 | @SettingContext("Control API context setting key") |
| 70 | 72 | private static final String CONTROL_CONFIG_KEY = "web.http." + ApiContext.CONTROL; |
| 71 | - | |
| 72 | 73 | public static final WebServiceSettings SETTINGS = WebServiceSettings.Builder.newInstance() |
| 73 | 74 | .apiConfigKey(CONTROL_CONFIG_KEY) |
| 74 | 75 | .contextAlias(ApiContext.CONTROL) |
| @@ -77,7 +78,6 @@ | ||
| 77 | 78 | .useDefaultContext(true) |
| 78 | 79 | .name(WEB_SERVICE_NAME) |
| 79 | 80 | .build(); |
| 80 | - private static final String CONTROL_SCOPE = "CONTROL_API"; | |
| 81 | 81 | private static final String API_VERSION_JSON_FILE = "control-api-version.json"; |
| 82 | 82 | |
| 83 | 83 | @Inject |
| @@ -110,6 +110,8 @@ | ||
| 110 | 110 | var jsonLdMapper = typeManager.getMapper(JSON_LD); |
| 111 | 111 | context.registerService(ControlApiUrl.class, controlApiUrl(context, controlApiConfiguration)); |
| 112 | 112 | |
| 113 | + jsonLd.registerNamespace(EDC_PREFIX, EDC_NAMESPACE, CONTROL_SCOPE); | |
| 114 | + jsonLd.registerNamespace(VOCAB, EDC_NAMESPACE, CONTROL_SCOPE); | |
| 113 | 115 | jsonLd.registerNamespace(ODRL_PREFIX, ODRL_SCHEMA, CONTROL_SCOPE); |
| 114 | 116 | jsonLd.registerNamespace(DSPACE_PREFIX, DSPACE_SCHEMA, CONTROL_SCOPE); |
| 115 | 117 |
modified extensions/common/api/control-api-configuration/src/test/java/org/eclipse/edc/connector/api/control/configuration/ControlApiConfigurationExtensionTest.java +21 −0
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | |
| 17 | 17 | import org.eclipse.edc.api.auth.spi.AuthenticationRequestFilter; |
| 18 | 18 | import org.eclipse.edc.json.JacksonTypeManager; |
| 19 | +import org.eclipse.edc.jsonld.spi.JsonLd; | |
| 19 | 20 | import org.eclipse.edc.junit.extensions.DependencyInjectionExtension; |
| 20 | 21 | import org.eclipse.edc.spi.EdcException; |
| 21 | 22 | import org.eclipse.edc.spi.system.Hostname; |
| @@ -33,6 +34,14 @@ | ||
| 33 | 34 | import static org.assertj.core.api.Assertions.assertThat; |
| 34 | 35 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 35 | 36 | import static org.eclipse.edc.connector.api.control.configuration.ControlApiConfigurationExtension.CONTROL_API_ENDPOINT; |
| 37 | +import static org.eclipse.edc.connector.api.control.configuration.ControlApiConfigurationExtension.CONTROL_SCOPE; | |
| 38 | +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VOCAB; | |
| 39 | +import static org.eclipse.edc.jsonld.spi.Namespaces.DSPACE_PREFIX; | |
| 40 | +import static org.eclipse.edc.jsonld.spi.Namespaces.DSPACE_SCHEMA; | |
| 41 | +import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_PREFIX; | |
| 42 | +import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_SCHEMA; | |
| 43 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 44 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_PREFIX; | |
| 36 | 45 | import static org.mockito.ArgumentMatchers.any; |
| 37 | 46 | import static org.mockito.ArgumentMatchers.eq; |
| 38 | 47 | import static org.mockito.ArgumentMatchers.isA; |
| @@ -45,6 +54,7 @@ | ||
| 45 | 54 | |
| 46 | 55 | private final WebServiceConfigurer configurator = mock(); |
| 47 | 56 | private final WebService webService = mock(); |
| 57 | + private final JsonLd jsonLd = mock(); | |
| 48 | 58 | |
| 49 | 59 | private final WebServiceConfiguration webServiceConfiguration = WebServiceConfiguration.Builder.newInstance() |
| 50 | 60 | .path("/path") |
| @@ -57,6 +67,7 @@ | ||
| 57 | 67 | context.registerService(Hostname.class, () -> "hostname"); |
| 58 | 68 | context.registerService(WebService.class, webService); |
| 59 | 69 | context.registerService(TypeManager.class, new JacksonTypeManager()); |
| 70 | + context.registerService(JsonLd.class, jsonLd); | |
| 60 | 71 | |
| 61 | 72 | when(configurator.configure(any(), any(), any())).thenReturn(webServiceConfiguration); |
| 62 | 73 | } |
| @@ -98,4 +109,14 @@ | ||
| 98 | 109 | |
| 99 | 110 | verify(webService).registerResource(any(), isA(AuthenticationRequestFilter.class)); |
| 100 | 111 | } |
| 112 | + | |
| 113 | + @Test | |
| 114 | + void shouldRegisterNamespaces(ControlApiConfigurationExtension extension, ServiceExtensionContext context) { | |
| 115 | + extension.initialize(context); | |
| 116 | + | |
| 117 | + jsonLd.registerNamespace(EDC_PREFIX, EDC_NAMESPACE, CONTROL_SCOPE); | |
| 118 | + jsonLd.registerNamespace(VOCAB, EDC_NAMESPACE, CONTROL_SCOPE); | |
| 119 | + jsonLd.registerNamespace(ODRL_PREFIX, ODRL_SCHEMA, CONTROL_SCOPE); | |
| 120 | + jsonLd.registerNamespace(DSPACE_PREFIX, DSPACE_SCHEMA, CONTROL_SCOPE); | |
| 121 | + } | |
| 101 | 122 | } |
modified extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiConfigurationExtension.java +20 −4
| @@ -61,8 +61,12 @@ | ||
| 61 | 61 | import java.util.stream.Stream; |
| 62 | 62 | |
| 63 | 63 | import static java.lang.String.format; |
| 64 | +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VOCAB; | |
| 64 | 65 | import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_PREFIX; |
| 65 | 66 | import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_SCHEMA; |
| 67 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_CONNECTOR_MANAGEMENT_CONTEXT; | |
| 68 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 69 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_PREFIX; | |
| 66 | 70 | import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; |
| 67 | 71 | |
| 68 | 72 | /** |
| @@ -75,10 +79,10 @@ | ||
| 75 | 79 | public static final String API_VERSION_JSON_FILE = "management-api-version.json"; |
| 76 | 80 | public static final String NAME = "Management API configuration"; |
| 77 | 81 | public static final String WEB_SERVICE_NAME = "Management API"; |
| 82 | + public static final String MANAGEMENT_SCOPE = "MANAGEMENT_API"; | |
| 78 | 83 | |
| 79 | 84 | @SettingContext("Management API context setting key") |
| 80 | 85 | private static final String MANAGEMENT_CONFIG_KEY = "web.http." + ApiContext.MANAGEMENT; |
| 81 | - | |
| 82 | 86 | public static final WebServiceSettings SETTINGS = WebServiceSettings.Builder.newInstance() |
| 83 | 87 | .apiConfigKey(MANAGEMENT_CONFIG_KEY) |
| 84 | 88 | .contextAlias(ApiContext.MANAGEMENT) |
| @@ -87,11 +91,14 @@ | ||
| 87 | 91 | .useDefaultContext(true) |
| 88 | 92 | .name(WEB_SERVICE_NAME) |
| 89 | 93 | .build(); |
| 90 | - private static final String MANAGEMENT_SCOPE = "MANAGEMENT_API"; | |
| 91 | - | |
| 92 | 94 | @Setting(value = "Configures endpoint for reaching the Management API.", defaultValue = "<hostname:management.port/management.path>") |
| 93 | 95 | private static final String MANAGEMENT_API_ENDPOINT = "edc.management.endpoint"; |
| 94 | 96 | |
| 97 | + private static final boolean DEFAULT_MANAGEMENT_API_ENABLE_CONTEXT = false; | |
| 98 | + | |
| 99 | + @Setting(value = "If set enable the usage of management api JSON-LD context.", defaultValue = "" + DEFAULT_MANAGEMENT_API_ENABLE_CONTEXT) | |
| 100 | + private static final String MANAGEMENT_API_ENABLE_CONTEXT = "edc.management.context.enabled"; | |
| 101 | + | |
| 95 | 102 | @Inject |
| 96 | 103 | private WebService webService; |
| 97 | 104 | @Inject |
| @@ -129,7 +136,16 @@ | ||
| 129 | 136 | var authenticationFilter = new AuthenticationRequestFilter(authenticationRegistry, "management-api"); |
| 130 | 137 | webService.registerResource(ApiContext.MANAGEMENT, authenticationFilter); |
| 131 | 138 | |
| 132 | - jsonLd.registerNamespace(ODRL_PREFIX, ODRL_SCHEMA, MANAGEMENT_SCOPE); | |
| 139 | + var isManagementContextEnabled = context.getSetting(MANAGEMENT_API_ENABLE_CONTEXT, DEFAULT_MANAGEMENT_API_ENABLE_CONTEXT); | |
| 140 | + | |
| 141 | + if (isManagementContextEnabled) { | |
| 142 | + jsonLd.registerContext(EDC_CONNECTOR_MANAGEMENT_CONTEXT, MANAGEMENT_SCOPE); | |
| 143 | + } else { | |
| 144 | + jsonLd.registerNamespace(VOCAB, EDC_NAMESPACE, MANAGEMENT_SCOPE); | |
| 145 | + jsonLd.registerNamespace(EDC_PREFIX, EDC_NAMESPACE, MANAGEMENT_SCOPE); | |
| 146 | + jsonLd.registerNamespace(ODRL_PREFIX, ODRL_SCHEMA, MANAGEMENT_SCOPE); | |
| 147 | + } | |
| 148 | + | |
| 133 | 149 | var jsonLdMapper = typeManager.getMapper(JSON_LD); |
| 134 | 150 | webService.registerResource(ApiContext.MANAGEMENT, new ObjectMapperProvider(jsonLdMapper)); |
| 135 | 151 | webService.registerResource(ApiContext.MANAGEMENT, new JerseyJsonLdInterceptor(jsonLd, jsonLdMapper, MANAGEMENT_SCOPE)); |
modified extensions/common/api/management-api-configuration/src/test/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiConfigurationExtensionTest.java +29 −0
| @@ -18,6 +18,7 @@ | ||
| 18 | 18 | import org.eclipse.edc.boot.system.DefaultServiceExtensionContext; |
| 19 | 19 | import org.eclipse.edc.boot.system.injection.ObjectFactory; |
| 20 | 20 | import org.eclipse.edc.json.JacksonTypeManager; |
| 21 | +import org.eclipse.edc.jsonld.spi.JsonLd; | |
| 21 | 22 | import org.eclipse.edc.junit.extensions.DependencyInjectionExtension; |
| 22 | 23 | import org.eclipse.edc.spi.monitor.Monitor; |
| 23 | 24 | import org.eclipse.edc.spi.system.ServiceExtensionContext; |
| @@ -36,11 +37,21 @@ | ||
| 36 | 37 | import org.junit.jupiter.api.Test; |
| 37 | 38 | import org.junit.jupiter.api.extension.ExtendWith; |
| 38 | 39 | |
| 40 | +import java.util.Map; | |
| 41 | + | |
| 42 | +import static org.eclipse.edc.connector.api.management.configuration.ManagementApiConfigurationExtension.MANAGEMENT_SCOPE; | |
| 39 | 43 | import static org.eclipse.edc.connector.api.management.configuration.ManagementApiConfigurationExtension.SETTINGS; |
| 44 | +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VOCAB; | |
| 45 | +import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_PREFIX; | |
| 46 | +import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_SCHEMA; | |
| 47 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_CONNECTOR_MANAGEMENT_CONTEXT; | |
| 48 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 49 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_PREFIX; | |
| 40 | 50 | import static org.mockito.ArgumentMatchers.any; |
| 41 | 51 | import static org.mockito.ArgumentMatchers.eq; |
| 42 | 52 | import static org.mockito.ArgumentMatchers.isA; |
| 43 | 53 | import static org.mockito.Mockito.mock; |
| 54 | +import static org.mockito.Mockito.times; | |
| 44 | 55 | import static org.mockito.Mockito.verify; |
| 45 | 56 | import static org.mockito.Mockito.when; |
| 46 | 57 | |
| @@ -50,6 +61,7 @@ | ||
| 50 | 61 | private final WebServiceConfigurer configurer = mock(); |
| 51 | 62 | private final Monitor monitor = mock(); |
| 52 | 63 | private final WebService webService = mock(); |
| 64 | + private final JsonLd jsonLd = mock(); | |
| 53 | 65 | private ManagementApiConfigurationExtension extension; |
| 54 | 66 | |
| 55 | 67 | @BeforeEach |
| @@ -60,6 +72,7 @@ | ||
| 60 | 72 | context.registerService(WebServiceConfigurer.class, configurer); |
| 61 | 73 | context.registerService(TypeTransformerRegistry.class, typeTransformerRegistry); |
| 62 | 74 | context.registerService(TypeManager.class, new JacksonTypeManager()); |
| 75 | + context.registerService(JsonLd.class, jsonLd); | |
| 63 | 76 | extension = factory.constructInstance(ManagementApiConfigurationExtension.class); |
| 64 | 77 | } |
| 65 | 78 | |
| @@ -75,6 +88,22 @@ | ||
| 75 | 88 | verify(webService).registerResource(eq(ApiContext.MANAGEMENT), isA(AuthenticationRequestFilter.class)); |
| 76 | 89 | verify(webService).registerResource(eq(ApiContext.MANAGEMENT), isA(JerseyJsonLdInterceptor.class)); |
| 77 | 90 | verify(webService).registerResource(eq(ApiContext.MANAGEMENT), isA(ObjectMapperProvider.class)); |
| 91 | + | |
| 92 | + verify(jsonLd).registerNamespace(VOCAB, EDC_NAMESPACE, MANAGEMENT_SCOPE); | |
| 93 | + verify(jsonLd).registerNamespace(EDC_PREFIX, EDC_NAMESPACE, MANAGEMENT_SCOPE); | |
| 94 | + verify(jsonLd).registerNamespace(ODRL_PREFIX, ODRL_SCHEMA, MANAGEMENT_SCOPE); | |
| 95 | + } | |
| 96 | + | |
| 97 | + @Test | |
| 98 | + void initialize_WithContextEnabled() { | |
| 99 | + var context = contextWithConfig(ConfigFactory.fromMap(Map.of("edc.management.context.enabled", "true"))); | |
| 100 | + var configuration = WebServiceConfiguration.Builder.newInstance().path("/path").port(1234).build(); | |
| 101 | + when(configurer.configure(any(), any(), any())).thenReturn(configuration); | |
| 102 | + | |
| 103 | + extension.initialize(context); | |
| 104 | + | |
| 105 | + verify(jsonLd, times(0)).registerNamespace(any(), any(), any()); | |
| 106 | + verify(jsonLd).registerContext(EDC_CONNECTOR_MANAGEMENT_CONTEXT, MANAGEMENT_SCOPE); | |
| 78 | 107 | } |
| 79 | 108 | |
| 80 | 109 | @NotNull |
deleted extensions/common/api/management-api-json-ld-context/build.gradle.kts +0 −48
| @@ -1,48 +0,0 @@ | ||
| 1 | -/* | |
| 2 | - * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 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 | - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | - * | |
| 13 | - */ | |
| 14 | - | |
| 15 | -plugins { | |
| 16 | - `java-library` | |
| 17 | -} | |
| 18 | - | |
| 19 | -dependencies { | |
| 20 | - api(project(":spi:common:json-ld-spi")) | |
| 21 | - | |
| 22 | - implementation(project(":core:common:lib:transform-lib")) | |
| 23 | - implementation(project(":core:control-plane:control-plane-transform")) | |
| 24 | - | |
| 25 | - testImplementation(project(":spi:common:edr-store-spi")) | |
| 26 | - testImplementation(project(":core:common:connector-core")) | |
| 27 | - testImplementation(project(":core:control-plane:control-plane-transform")) | |
| 28 | - testImplementation(project(":core:common:junit")) | |
| 29 | - testImplementation(project(":core:common:lib:json-ld-lib")) | |
| 30 | - testImplementation(project(":extensions:common:json-ld")) | |
| 31 | - testImplementation(project(":extensions:common:http:jetty-core")) | |
| 32 | - testImplementation(project(":extensions:common:http:jersey-core")) | |
| 33 | - testImplementation(project(":extensions:common:api:management-api-configuration")) | |
| 34 | - testImplementation(project(":extensions:control-plane:api:management-api:contract-definition-api")) | |
| 35 | - testImplementation(project(":extensions:control-plane:api:management-api:contract-negotiation-api")) | |
| 36 | - testImplementation(project(":extensions:control-plane:api:management-api:policy-definition-api")) | |
| 37 | - testImplementation(project(":extensions:control-plane:api:management-api:transfer-process-api")) | |
| 38 | - testImplementation(project(":extensions:control-plane:api:management-api:secrets-api")) | |
| 39 | - testImplementation(project(":extensions:control-plane:api:management-api:edr-cache-api")) | |
| 40 | -} | |
| 41 | - | |
| 42 | -edcBuild { | |
| 43 | - swagger { | |
| 44 | - apiGroup.set("management-api") | |
| 45 | - } | |
| 46 | -} | |
| 47 | - | |
| 48 | - |
deleted extensions/common/api/management-api-json-ld-context/src/main/java/org/eclipse/edc/connector/api/management/jsonld/ManagementApiJsonLdContextExtension.java +0 −72
| @@ -1,72 +0,0 @@ | ||
| 1 | -/* | |
| 2 | - * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 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 | - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | - * | |
| 13 | - */ | |
| 14 | - | |
| 15 | -package org.eclipse.edc.connector.api.management.jsonld; | |
| 16 | - | |
| 17 | -import org.eclipse.edc.jsonld.spi.JsonLd; | |
| 18 | -import org.eclipse.edc.runtime.metamodel.annotation.Inject; | |
| 19 | -import org.eclipse.edc.spi.monitor.Monitor; | |
| 20 | -import org.eclipse.edc.spi.result.Result; | |
| 21 | -import org.eclipse.edc.spi.system.ServiceExtension; | |
| 22 | -import org.eclipse.edc.spi.system.ServiceExtensionContext; | |
| 23 | -import org.jetbrains.annotations.NotNull; | |
| 24 | - | |
| 25 | -import java.net.URI; | |
| 26 | -import java.net.URISyntaxException; | |
| 27 | -import java.util.Map; | |
| 28 | - | |
| 29 | -import static java.lang.String.format; | |
| 30 | - | |
| 31 | -public class ManagementApiJsonLdContextExtension implements ServiceExtension { | |
| 32 | - | |
| 33 | - public static final String EDC_CONNECTOR_MANAGEMENT_CONTEXT = "https://w3id.org/edc/connector/management/v0.0.1"; | |
| 34 | - public static final String EDC_CONNECTOR_MANAGEMENT_SCOPE = "MANAGEMENT_API"; | |
| 35 | - | |
| 36 | - private static final String PREFIX = "document/"; | |
| 37 | - private static final Map<String, String> FILES = Map.of( | |
| 38 | - EDC_CONNECTOR_MANAGEMENT_CONTEXT, PREFIX + "management-context-v1.jsonld"); | |
| 39 | - | |
| 40 | - @Inject | |
| 41 | - private JsonLd jsonLdService; | |
| 42 | - | |
| 43 | - @Inject | |
| 44 | - private Monitor monitor; | |
| 45 | - | |
| 46 | - @Override | |
| 47 | - public void initialize(ServiceExtensionContext context) { | |
| 48 | - jsonLdService.registerContext(EDC_CONNECTOR_MANAGEMENT_CONTEXT, EDC_CONNECTOR_MANAGEMENT_SCOPE); | |
| 49 | - FILES.entrySet().stream().map(this::mapToUri) | |
| 50 | - .forEach(result -> result.onSuccess(entry -> jsonLdService.registerCachedDocument(entry.getKey(), entry.getValue())) | |
| 51 | - .onFailure(failure -> monitor.warning("Failed to register cached json-ld document: " + failure.getFailureDetail()))); | |
| 52 | - } | |
| 53 | - | |
| 54 | - private Result<Map.Entry<String, URI>> mapToUri(Map.Entry<String, String> fileEntry) { | |
| 55 | - return getResourceUri(fileEntry.getValue()) | |
| 56 | - .map(file1 -> Map.entry(fileEntry.getKey(), file1)); | |
| 57 | - } | |
| 58 | - | |
| 59 | - @NotNull | |
| 60 | - private Result<URI> getResourceUri(String name) { | |
| 61 | - var uri = getClass().getClassLoader().getResource(name); | |
| 62 | - if (uri == null) { | |
| 63 | - return Result.failure(format("Cannot find resource %s", name)); | |
| 64 | - } | |
| 65 | - | |
| 66 | - try { | |
| 67 | - return Result.success(uri.toURI()); | |
| 68 | - } catch (URISyntaxException e) { | |
| 69 | - return Result.failure(format("Cannot read resource %s: %s", name, e.getMessage())); | |
| 70 | - } | |
| 71 | - } | |
| 72 | -} |
deleted extensions/common/api/management-api-json-ld-context/src/main/resources/META-INF/services/org.eclipse.edc.spi.system.ServiceExtension +0 −15
| @@ -1,15 +0,0 @@ | ||
| 1 | -# | |
| 2 | -# Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 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 | -# Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | -# | |
| 13 | -# | |
| 14 | - | |
| 15 | -org.eclipse.edc.connector.api.management.jsonld.ManagementApiJsonLdContextExtension | |
| No newline at the end of the file |
deleted extensions/common/api/management-api-json-ld-context/src/main/resources/document/management-context-v1.jsonld +0 −181
| @@ -1,181 +0,0 @@ | ||
| 1 | -{ | |
| 2 | - "@context": { | |
| 3 | - "@version": 1.1, | |
| 4 | - "edc": "https://w3id.org/edc/v0.0.1/ns/", | |
| 5 | - "Asset": "edc:Asset", | |
| 6 | - "PolicyDefinition": "edc:PolicyDefinition", | |
| 7 | - "DataAddress": { | |
| 8 | - "@id": "edc:DataAddress", | |
| 9 | - "@context": { | |
| 10 | - "type": "edc:type", | |
| 11 | - "@vocab": "https://w3id.org/edc/v0.0.1/ns/" | |
| 12 | - } | |
| 13 | - }, | |
| 14 | - "ContractDefinition": "edc:ContractDefinition", | |
| 15 | - "Criterion": "edc:Criterion", | |
| 16 | - "ContractRequest": "edc:ContractRequest", | |
| 17 | - "QuerySpec": "edc:QuerySpec", | |
| 18 | - "ContractNegotiation": { | |
| 19 | - "@id": "edc:ContractNegotiation", | |
| 20 | - "@context": { | |
| 21 | - "type": "edc:type" | |
| 22 | - } | |
| 23 | - }, | |
| 24 | - "CallbackAddress": "edc:CallbackAddress", | |
| 25 | - "NegotiationState": "edc:NegotiationState", | |
| 26 | - "TerminateNegotiation": "edc:TerminateNegotiation", | |
| 27 | - "ContractAgreement": "edc:ContractAgreement", | |
| 28 | - "TransferRequest": "edc:TransferRequest", | |
| 29 | - "TransferState": "edc:TransferState", | |
| 30 | - "TransferProcess": { | |
| 31 | - "@id": "edc:TransferProcess", | |
| 32 | - "@context": { | |
| 33 | - "type": "edc:type" | |
| 34 | - } | |
| 35 | - }, | |
| 36 | - "TerminateTransfer": "edc:TerminateTransfer", | |
| 37 | - "SuspendTransfer": "edc:SuspendTransfer", | |
| 38 | - "Secret": "edc:Secret", | |
| 39 | - "EndpointDataReferenceEntry": "edc:EndpointDataReferenceEntry", | |
| 40 | - "PolicyValidationResult": "edc:PolicyValidationResult", | |
| 41 | - "PolicyEvaluationPlanRequest": "edc:PolicyEvaluationPlanRequest", | |
| 42 | - "PolicyEvaluationPlan": "edc:PolicyEvaluationPlan", | |
| 43 | - "PermissionStep": "edc:PermissionStep", | |
| 44 | - "ProhibitionStep": "edc:ProhibitionStep", | |
| 45 | - "DutyStep": "edc:DutyStep", | |
| 46 | - "OrConstraintStep": "edc:OrConstraintStep", | |
| 47 | - "AndConstraintStep": "edc:AndConstraintStep", | |
| 48 | - "XoneConstraintStep": "edc:XoneConstraintStep", | |
| 49 | - "AtomicConstraintStep": "edc:AtomicConstraintStep", | |
| 50 | - "properties": { | |
| 51 | - "@id": "edc:properties", | |
| 52 | - "@context": { | |
| 53 | - "@vocab": "https://w3id.org/edc/v0.0.1/ns/" | |
| 54 | - } | |
| 55 | - }, | |
| 56 | - "privateProperties": { | |
| 57 | - "@id": "edc:privateProperties", | |
| 58 | - "@context": { | |
| 59 | - "@vocab": "https://w3id.org/edc/v0.0.1/ns/" | |
| 60 | - } | |
| 61 | - }, | |
| 62 | - "dataAddress": { | |
| 63 | - "@id": "edc:dataAddress", | |
| 64 | - "@context": { | |
| 65 | - "@vocab": "https://w3id.org/edc/v0.0.1/ns/" | |
| 66 | - } | |
| 67 | - }, | |
| 68 | - "createdAt": "edc:createdAt", | |
| 69 | - "accessPolicyId": "edc:accessPolicyId", | |
| 70 | - "contractPolicyId": "edc:contractPolicyId", | |
| 71 | - "assetsSelector": { | |
| 72 | - "@id": "edc:assetsSelector", | |
| 73 | - "@container": "@set" | |
| 74 | - }, | |
| 75 | - "operandLeft": "edc:operandLeft", | |
| 76 | - "operator": "edc:operator", | |
| 77 | - "operandRight": "edc:operandRight", | |
| 78 | - "limit": "edc:limit", | |
| 79 | - "offset": "edc:offset", | |
| 80 | - "filterExpression": { | |
| 81 | - "@id": "edc:filterExpression", | |
| 82 | - "@container": "@set" | |
| 83 | - }, | |
| 84 | - "sortOrder": "edc:sortOrder", | |
| 85 | - "sortField": "edc:sortField", | |
| 86 | - "counterPartyAddress": "edc:counterPartyAddress", | |
| 87 | - "protocol": "edc:protocol", | |
| 88 | - "callbackAddresses": { | |
| 89 | - "@id": "edc:callbackAddresses", | |
| 90 | - "@container": "@set" | |
| 91 | - }, | |
| 92 | - "providerId": "edc:providerId", | |
| 93 | - "policy": { | |
| 94 | - "@id": "edc:policy", | |
| 95 | - "@context": [ | |
| 96 | - "http://www.w3.org/ns/odrl.jsonld", | |
| 97 | - { | |
| 98 | - "uid": null, | |
| 99 | - "type": null | |
| 100 | - } | |
| 101 | - ] | |
| 102 | - }, | |
| 103 | - "counterPartyId": "edc:counterPartyId", | |
| 104 | - "state": "edc:state", | |
| 105 | - "errorDetail": "edc:errorDetail", | |
| 106 | - "contractAgreementId": "edc:contractAgreementId", | |
| 107 | - "uri": "edc:uri", | |
| 108 | - "transactional": "edc:transactional", | |
| 109 | - "events": { | |
| 110 | - "@id": "edc:events", | |
| 111 | - "@container": "@set" | |
| 112 | - }, | |
| 113 | - "reason": "edc:reason", | |
| 114 | - "assetId": "edc:assetId", | |
| 115 | - "consumerId": "edc:consumerId", | |
| 116 | - "contractSigningDate": "edc:contractSigningDate", | |
| 117 | - "contractId": "edc:contractId", | |
| 118 | - "dataDestination": { | |
| 119 | - "@id": "edc:dataDestination", | |
| 120 | - "@context": { | |
| 121 | - "@vocab": "https://w3id.org/edc/v0.0.1/ns/" | |
| 122 | - } | |
| 123 | - }, | |
| 124 | - "transferType": "edc:transferType", | |
| 125 | - "correlationId": "edc:correlationId", | |
| 126 | - "stateTimestamp": "edc:stateTimestamp", | |
| 127 | - "value": "edc:value", | |
| 128 | - "transferProcessId": "edc:transferProcessId", | |
| 129 | - "contractNegotiationId": "edc:contractNegotiationId", | |
| 130 | - "agreementId": "edc:agreementId", | |
| 131 | - "inForceDate": "edc:inForceDate", | |
| 132 | - "isValid": "edc:isValid", | |
| 133 | - "errors": { | |
| 134 | - "@id": "edc:errors", | |
| 135 | - "@container": "@set" | |
| 136 | - }, | |
| 137 | - "policyScope": "edc:policyScope", | |
| 138 | - "preValidators": { | |
| 139 | - "@id": "edc:preValidators", | |
| 140 | - "@container": "@set" | |
| 141 | - }, | |
| 142 | - "postValidators": { | |
| 143 | - "@id": "edc:postValidators", | |
| 144 | - "@container": "@set" | |
| 145 | - }, | |
| 146 | - "permissionSteps": { | |
| 147 | - "@id": "edc:permissionSteps", | |
| 148 | - "@container": "@set" | |
| 149 | - }, | |
| 150 | - "prohibitionSteps": { | |
| 151 | - "@id": "edc:prohibitionSteps", | |
| 152 | - "@container": "@set" | |
| 153 | - }, | |
| 154 | - "obligationSteps": { | |
| 155 | - "@id": "edc:obligationSteps", | |
| 156 | - "@container": "@set" | |
| 157 | - }, | |
| 158 | - "constraintSteps": { | |
| 159 | - "@id": "edc:constraintSteps", | |
| 160 | - "@container": "@set" | |
| 161 | - }, | |
| 162 | - "filteringReasons": { | |
| 163 | - "@id": "edc:filteringReasons", | |
| 164 | - "@container": "@set" | |
| 165 | - }, | |
| 166 | - "isFiltered": "edc:isFiltered", | |
| 167 | - "functionName": "edc:functionName", | |
| 168 | - "functionParams": { | |
| 169 | - "@id": "edc:functionParams", | |
| 170 | - "@container": "@set" | |
| 171 | - }, | |
| 172 | - "dutySteps": { | |
| 173 | - "@id": "edc:dutySteps", | |
| 174 | - "@container": "@set" | |
| 175 | - }, | |
| 176 | - "ruleFunctions": { | |
| 177 | - "@id": "edc:ruleFunctions", | |
| 178 | - "@container": "@set" | |
| 179 | - } | |
| 180 | - } | |
| 181 | -} | |
| No newline at the end of the file |
deleted extensions/common/api/management-api-json-ld-context/src/test/java/org/eclipse/edc/connector/api/management/jsonld/serde/ManagementApiJsonLdContextExtensionTest.java +0 −46
| @@ -1,46 +0,0 @@ | ||
| 1 | -/* | |
| 2 | - * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 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 | - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | - * | |
| 13 | - */ | |
| 14 | - | |
| 15 | -package org.eclipse.edc.connector.api.management.jsonld.serde; | |
| 16 | - | |
| 17 | -import org.eclipse.edc.connector.api.management.jsonld.ManagementApiJsonLdContextExtension; | |
| 18 | -import org.eclipse.edc.jsonld.spi.JsonLd; | |
| 19 | -import org.eclipse.edc.junit.extensions.DependencyInjectionExtension; | |
| 20 | -import org.eclipse.edc.spi.system.ServiceExtensionContext; | |
| 21 | -import org.junit.jupiter.api.BeforeEach; | |
| 22 | -import org.junit.jupiter.api.Test; | |
| 23 | -import org.junit.jupiter.api.extension.ExtendWith; | |
| 24 | - | |
| 25 | -import static org.eclipse.edc.connector.api.management.jsonld.ManagementApiJsonLdContextExtension.EDC_CONNECTOR_MANAGEMENT_CONTEXT; | |
| 26 | -import static org.eclipse.edc.connector.api.management.jsonld.ManagementApiJsonLdContextExtension.EDC_CONNECTOR_MANAGEMENT_SCOPE; | |
| 27 | -import static org.mockito.Mockito.mock; | |
| 28 | -import static org.mockito.Mockito.verify; | |
| 29 | - | |
| 30 | -@ExtendWith(DependencyInjectionExtension.class) | |
| 31 | -class ManagementApiJsonLdContextExtensionTest { | |
| 32 | - | |
| 33 | - private final JsonLd jsonLd = mock(); | |
| 34 | - private ManagementApiJsonLdContextExtension extension; | |
| 35 | - | |
| 36 | - @BeforeEach | |
| 37 | - void setup(ServiceExtensionContext context) { | |
| 38 | - context.registerService(JsonLd.class, jsonLd); | |
| 39 | - } | |
| 40 | - | |
| 41 | - @Test | |
| 42 | - void initialize(ManagementApiJsonLdContextExtension extension, ServiceExtensionContext context) { | |
| 43 | - extension.initialize(context); | |
| 44 | - verify(jsonLd).registerContext(EDC_CONNECTOR_MANAGEMENT_CONTEXT, EDC_CONNECTOR_MANAGEMENT_SCOPE); | |
| 45 | - } | |
| 46 | -} |
deleted extensions/common/api/management-api-json-ld-context/src/test/java/org/eclipse/edc/connector/api/management/jsonld/serde/SerdeIntegrationTest.java +0 −475
| @@ -1,475 +0,0 @@ | ||
| 1 | -/* | |
| 2 | - * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 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 | - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | - * | |
| 13 | - */ | |
| 14 | - | |
| 15 | -package org.eclipse.edc.connector.api.management.jsonld.serde; | |
| 16 | - | |
| 17 | -import jakarta.json.Json; | |
| 18 | -import jakarta.json.JsonObject; | |
| 19 | -import jakarta.json.JsonString; | |
| 20 | -import jakarta.json.JsonValue; | |
| 21 | -import org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.model.NegotiationState; | |
| 22 | -import org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyEvaluationPlanRequest; | |
| 23 | -import org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyValidationResult; | |
| 24 | -import org.eclipse.edc.connector.controlplane.api.management.transferprocess.model.SuspendTransfer; | |
| 25 | -import org.eclipse.edc.connector.controlplane.api.management.transferprocess.model.TerminateTransfer; | |
| 26 | -import org.eclipse.edc.connector.controlplane.api.management.transferprocess.model.TransferState; | |
| 27 | -import org.eclipse.edc.connector.controlplane.asset.spi.domain.Asset; | |
| 28 | -import org.eclipse.edc.connector.controlplane.contract.spi.types.command.TerminateNegotiationCommand; | |
| 29 | -import org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractRequest; | |
| 30 | -import org.eclipse.edc.connector.controlplane.contract.spi.types.offer.ContractDefinition; | |
| 31 | -import org.eclipse.edc.connector.controlplane.policy.spi.PolicyDefinition; | |
| 32 | -import org.eclipse.edc.connector.controlplane.services.spi.contractdefinition.ContractDefinitionService; | |
| 33 | -import org.eclipse.edc.connector.controlplane.services.spi.contractnegotiation.ContractNegotiationService; | |
| 34 | -import org.eclipse.edc.connector.controlplane.services.spi.policydefinition.PolicyDefinitionService; | |
| 35 | -import org.eclipse.edc.connector.controlplane.services.spi.transferprocess.TransferProcessService; | |
| 36 | -import org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcessStates; | |
| 37 | -import org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferRequest; | |
| 38 | -import org.eclipse.edc.connector.spi.service.SecretService; | |
| 39 | -import org.eclipse.edc.edr.spi.store.EndpointDataReferenceStore; | |
| 40 | -import org.eclipse.edc.jsonld.spi.JsonLd; | |
| 41 | -import org.eclipse.edc.junit.annotations.ComponentTest; | |
| 42 | -import org.eclipse.edc.junit.extensions.RuntimeExtension; | |
| 43 | -import org.eclipse.edc.junit.extensions.RuntimePerClassExtension; | |
| 44 | -import org.eclipse.edc.policy.model.AndConstraint; | |
| 45 | -import org.eclipse.edc.policy.model.AtomicConstraint; | |
| 46 | -import org.eclipse.edc.policy.model.LiteralExpression; | |
| 47 | -import org.eclipse.edc.policy.model.Operator; | |
| 48 | -import org.eclipse.edc.spi.query.QuerySpec; | |
| 49 | -import org.eclipse.edc.spi.types.domain.DataAddress; | |
| 50 | -import org.eclipse.edc.spi.types.domain.secret.Secret; | |
| 51 | -import org.eclipse.edc.transform.spi.TypeTransformerRegistry; | |
| 52 | -import org.junit.jupiter.api.Test; | |
| 53 | -import org.junit.jupiter.api.extension.ExtensionContext; | |
| 54 | -import org.junit.jupiter.api.extension.RegisterExtension; | |
| 55 | -import org.junit.jupiter.params.ParameterizedTest; | |
| 56 | -import org.junit.jupiter.params.provider.Arguments; | |
| 57 | -import org.junit.jupiter.params.provider.ArgumentsProvider; | |
| 58 | -import org.junit.jupiter.params.provider.ArgumentsSource; | |
| 59 | - | |
| 60 | -import java.util.List; | |
| 61 | -import java.util.Map; | |
| 62 | -import java.util.Optional; | |
| 63 | -import java.util.function.BiFunction; | |
| 64 | -import java.util.function.Consumer; | |
| 65 | -import java.util.function.Function; | |
| 66 | -import java.util.stream.Collectors; | |
| 67 | -import java.util.stream.Stream; | |
| 68 | - | |
| 69 | -import static jakarta.json.Json.createObjectBuilder; | |
| 70 | -import static org.assertj.core.api.Assertions.assertThat; | |
| 71 | -import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.MANAGEMENT_API_CONTEXT; | |
| 72 | -import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.MANAGEMENT_API_SCOPE; | |
| 73 | -import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.assetObject; | |
| 74 | -import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.contractDefinitionObject; | |
| 75 | -import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.contractRequestObject; | |
| 76 | -import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.createContractAgreement; | |
| 77 | -import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.createContractNegotiation; | |
| 78 | -import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.createEdrEntry; | |
| 79 | -import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.createPolicyEvaluationPlan; | |
| 80 | -import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.createTransferProcess; | |
| 81 | -import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.dataAddressObject; | |
| 82 | -import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.inForceDatePermission; | |
| 83 | -import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.policyDefinitionObject; | |
| 84 | -import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.policyEvaluationPlanRequest; | |
| 85 | -import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.querySpecObject; | |
| 86 | -import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.secretObject; | |
| 87 | -import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.suspendTransferObject; | |
| 88 | -import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.terminateNegotiationObject; | |
| 89 | -import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.terminateTransferObject; | |
| 90 | -import static org.eclipse.edc.connector.api.management.jsonld.serde.TestFunctions.transferRequestObject; | |
| 91 | -import static org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractNegotiationStates.REQUESTED; | |
| 92 | -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; | |
| 93 | -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; | |
| 94 | -import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; | |
| 95 | -import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 96 | -import static org.eclipse.edc.util.io.Ports.getFreePort; | |
| 97 | -import static org.mockito.Mockito.mock; | |
| 98 | - | |
| 99 | -@ComponentTest | |
| 100 | -public class SerdeIntegrationTest { | |
| 101 | - | |
| 102 | - @RegisterExtension | |
| 103 | - private static final RuntimeExtension RUNTIME; | |
| 104 | - | |
| 105 | - static { | |
| 106 | - RUNTIME = new RuntimePerClassExtension(); | |
| 107 | - RUNTIME.registerServiceMock(ContractDefinitionService.class, mock()); | |
| 108 | - RUNTIME.registerServiceMock(ContractNegotiationService.class, mock()); | |
| 109 | - RUNTIME.registerServiceMock(PolicyDefinitionService.class, mock()); | |
| 110 | - RUNTIME.registerServiceMock(TransferProcessService.class, mock()); | |
| 111 | - RUNTIME.registerServiceMock(SecretService.class, mock()); | |
| 112 | - RUNTIME.registerServiceMock(EndpointDataReferenceStore.class, mock()); | |
| 113 | - RUNTIME.setConfiguration(Map.of( | |
| 114 | - "web.http.port", String.valueOf(getFreePort()), | |
| 115 | - "web.http.path", "/api", | |
| 116 | - "web.http.management.port", String.valueOf(getFreePort()), | |
| 117 | - "web.http.management.path", "/api", | |
| 118 | - "edc.jsonld.vocab.disable", "true" | |
| 119 | - )); | |
| 120 | - } | |
| 121 | - | |
| 122 | - @Test | |
| 123 | - void ser_ContractAgreement() { | |
| 124 | - var agreement = createContractAgreement("test-id"); | |
| 125 | - var compactResult = serialize(agreement); | |
| 126 | - | |
| 127 | - assertThat(compactResult).isNotNull(); | |
| 128 | - assertThat(compactResult.getString(ID)).isEqualTo(agreement.getId()); | |
| 129 | - assertThat(compactResult.getString(TYPE)).isEqualTo("ContractAgreement"); | |
| 130 | - assertThat(compactResult.getString("providerId")).isEqualTo(agreement.getProviderId()); | |
| 131 | - assertThat(compactResult.getString("consumerId")).isEqualTo(agreement.getConsumerId()); | |
| 132 | - assertThat(compactResult.getString("assetId")).isEqualTo(agreement.getAssetId()); | |
| 133 | - assertThat(compactResult.getJsonObject("policy")).isNotNull(); | |
| 134 | - assertThat(compactResult.getJsonNumber("contractSigningDate")).isNotNull(); | |
| 135 | - | |
| 136 | - } | |
| 137 | - | |
| 138 | - @Test | |
| 139 | - void ser_ContractNegotiation() { | |
| 140 | - var negotiation = createContractNegotiation(); | |
| 141 | - var compactResult = serialize(negotiation); | |
| 142 | - | |
| 143 | - assertThat(compactResult).isNotNull(); | |
| 144 | - assertThat(compactResult.getString(ID)).isEqualTo("test-id"); | |
| 145 | - assertThat(compactResult.getString("state")).isEqualTo(REQUESTED.name()); | |
| 146 | - assertThat(compactResult.getString("counterPartyId")).isEqualTo(negotiation.getCounterPartyId()); | |
| 147 | - assertThat(compactResult.getString("counterPartyAddress")).isEqualTo(negotiation.getCounterPartyAddress()); | |
| 148 | - assertThat(compactResult.getString("contractAgreementId")).isEqualTo(negotiation.getContractAgreement().getId()); | |
| 149 | - assertThat(compactResult.getString("errorDetail")).isEqualTo(negotiation.getErrorDetail()); | |
| 150 | - assertThat(compactResult.getString("type")).isEqualTo(negotiation.getType().toString()); | |
| 151 | - assertThat(compactResult.getString("protocol")).isEqualTo(negotiation.getProtocol()); | |
| 152 | - assertThat(compactResult.getJsonArray("callbackAddresses")).isNotEmpty().first().satisfies(callback -> { | |
| 153 | - var firstCallback = negotiation.getCallbackAddresses().get(0); | |
| 154 | - var cb = callback.asJsonObject(); | |
| 155 | - assertThat(cb.getString("uri")).isEqualTo(firstCallback.getUri()); | |
| 156 | - assertThat(cb.getBoolean("transactional")).isEqualTo(firstCallback.isTransactional()); | |
| 157 | - | |
| 158 | - var events = cb.getJsonArray("events").stream().map(event -> ((JsonString) event).getString()).collect(Collectors.toSet()); | |
| 159 | - assertThat(events).containsAll(firstCallback.getEvents()); | |
| 160 | - }); | |
| 161 | - assertThat(compactResult.getJsonNumber("createdAt").longValue()).isEqualTo(1234); | |
| 162 | - | |
| 163 | - } | |
| 164 | - | |
| 165 | - @Test | |
| 166 | - void ser_TransferProcess() { | |
| 167 | - var transferProcess = createTransferProcess(); | |
| 168 | - var compactResult = serialize(transferProcess); | |
| 169 | - | |
| 170 | - assertThat(compactResult).isNotNull(); | |
| 171 | - assertThat(compactResult.getString(ID)).isEqualTo(transferProcess.getId()); | |
| 172 | - assertThat(compactResult.getString(TYPE)).isEqualTo("TransferProcess"); | |
| 173 | - assertThat(compactResult.getString("correlationId")).isEqualTo(transferProcess.getCorrelationId()); | |
| 174 | - assertThat(compactResult.getString("state")).isEqualTo(transferProcess.stateAsString()); | |
| 175 | - assertThat(compactResult.getJsonNumber("stateTimestamp").longValue()).isEqualTo(transferProcess.getStateTimestamp()); | |
| 176 | - assertThat(compactResult.getString("assetId")).isEqualTo(transferProcess.getAssetId()); | |
| 177 | - assertThat(compactResult.getString("contractId")).isEqualTo(transferProcess.getContractId()); | |
| 178 | - assertThat(compactResult.getString("type")).isEqualTo(transferProcess.getType().toString()); | |
| 179 | - assertThat(compactResult.getJsonObject("dataDestination")).isNotNull(); | |
| 180 | - assertThat(compactResult.getJsonArray("callbackAddresses")).hasSize(transferProcess.getCallbackAddresses().size()); | |
| 181 | - assertThat(compactResult.getString("errorDetail")).isEqualTo(transferProcess.getErrorDetail()); | |
| 182 | - } | |
| 183 | - | |
| 184 | - @Test | |
| 185 | - void ser_EndpointDataReferenceEntry() { | |
| 186 | - var transferProcess = createEdrEntry(); | |
| 187 | - var compactResult = serialize(transferProcess); | |
| 188 | - | |
| 189 | - assertThat(compactResult).isNotNull(); | |
| 190 | - assertThat(compactResult.getString(ID)).isEqualTo(transferProcess.getId()); | |
| 191 | - assertThat(compactResult.getString(TYPE)).isEqualTo("EndpointDataReferenceEntry"); | |
| 192 | - assertThat(compactResult.getString("transferProcessId")).isEqualTo(transferProcess.getTransferProcessId()); | |
| 193 | - assertThat(compactResult.getString("contractNegotiationId")).isEqualTo(transferProcess.getContractNegotiationId()); | |
| 194 | - assertThat(compactResult.getString("assetId")).isEqualTo(transferProcess.getAssetId()); | |
| 195 | - assertThat(compactResult.getString("providerId")).isEqualTo(transferProcess.getProviderId()); | |
| 196 | - assertThat(compactResult.getString("agreementId")).isEqualTo(transferProcess.getAgreementId()); | |
| 197 | - } | |
| 198 | - | |
| 199 | - @Test | |
| 200 | - void ser_NegotiationState() { | |
| 201 | - var state = new NegotiationState(TransferProcessStates.REQUESTED.name()); | |
| 202 | - var compactResult = serialize(state); | |
| 203 | - | |
| 204 | - assertThat(compactResult).isNotNull(); | |
| 205 | - assertThat(compactResult.getString(TYPE)).isEqualTo("NegotiationState"); | |
| 206 | - assertThat(compactResult.getString("state")).isEqualTo(TransferProcessStates.REQUESTED.name()); | |
| 207 | - | |
| 208 | - } | |
| 209 | - | |
| 210 | - @Test | |
| 211 | - void ser_TransferState() { | |
| 212 | - var state = new TransferState(REQUESTED.name()); | |
| 213 | - var compactResult = serialize(state); | |
| 214 | - | |
| 215 | - assertThat(compactResult).isNotNull(); | |
| 216 | - assertThat(compactResult.getString(TYPE)).isEqualTo("TransferState"); | |
| 217 | - assertThat(compactResult.getString("state")).isEqualTo(REQUESTED.name()); | |
| 218 | - | |
| 219 | - } | |
| 220 | - | |
| 221 | - @Test | |
| 222 | - void ser_PolicyValidationResult() { | |
| 223 | - var result = new PolicyValidationResult(false, List.of("error1", "error2")); | |
| 224 | - var compactResult = serialize(result); | |
| 225 | - | |
| 226 | - assertThat(compactResult).isNotNull(); | |
| 227 | - assertThat(compactResult.getString(TYPE)).isEqualTo("PolicyValidationResult"); | |
| 228 | - assertThat(compactResult.getBoolean("isValid")).isEqualTo(false); | |
| 229 | - assertThat(compactResult.getJsonArray("errors")).contains(Json.createValue("error1"), Json.createValue("error2")); | |
| 230 | - | |
| 231 | - } | |
| 232 | - | |
| 233 | - @Test | |
| 234 | - void ser_PolicyEvaluationPlan() { | |
| 235 | - var plan = createPolicyEvaluationPlan(); | |
| 236 | - var compactResult = serialize(plan); | |
| 237 | - | |
| 238 | - assertThat(compactResult).isNotNull(); | |
| 239 | - assertThat(compactResult.getString(TYPE)).isEqualTo("PolicyEvaluationPlan"); | |
| 240 | - assertThat(compactResult.getJsonArray("preValidators")).hasSize(1); | |
| 241 | - assertThat(compactResult.getJsonArray("postValidators")).hasSize(1); | |
| 242 | - | |
| 243 | - | |
| 244 | - BiFunction<String, String, Consumer<JsonValue>> ruleAsser = (ruleType, multiplicityType) -> (ruleValue) -> { | |
| 245 | - var rule = ruleValue.asJsonObject(); | |
| 246 | - assertThat(rule.getString(TYPE)).isEqualTo(ruleType); | |
| 247 | - assertThat(rule.getJsonArray("ruleFunctions")).hasSize(0); | |
| 248 | - assertThat(rule.getJsonArray("constraintSteps")).hasSize(1); | |
| 249 | - | |
| 250 | - var constraint = rule.getJsonArray("constraintSteps").get(0).asJsonObject(); | |
| 251 | - assertThat(constraint.getString(TYPE)).isEqualTo(multiplicityType); | |
| 252 | - assertThat(constraint.getJsonArray("constraintSteps")).hasSize(2) | |
| 253 | - .allSatisfy(value -> { | |
| 254 | - var atomicConstraint = value.asJsonObject(); | |
| 255 | - assertThat(atomicConstraint.getString(TYPE)).isEqualTo("AtomicConstraintStep"); | |
| 256 | - assertThat(atomicConstraint.getJsonArray("filteringReasons")).hasSize(1); | |
| 257 | - assertThat(atomicConstraint.getBoolean("isFiltered")).isTrue(); | |
| 258 | - assertThat(atomicConstraint.getString("functionName")).isEqualTo("AtomicConstraintFunction"); | |
| 259 | - assertThat(atomicConstraint.getJsonArray("functionParams")).hasSize(3); | |
| 260 | - }); | |
| 261 | - }; | |
| 262 | - | |
| 263 | - assertThat(compactResult.getJsonArray("permissionSteps")).hasSize(1) | |
| 264 | - .first() | |
| 265 | - .satisfies(ruleAsser.apply("PermissionStep", "OrConstraintStep")); | |
| 266 | - | |
| 267 | - assertThat(compactResult.getJsonArray("prohibitionSteps")).hasSize(1) | |
| 268 | - .first() | |
| 269 | - .satisfies(ruleAsser.apply("ProhibitionStep", "AndConstraintStep")); | |
| 270 | - | |
| 271 | - assertThat(compactResult.getJsonArray("obligationSteps")).hasSize(1) | |
| 272 | - .first() | |
| 273 | - .satisfies(ruleAsser.apply("DutyStep", "XoneConstraintStep")); | |
| 274 | - | |
| 275 | - } | |
| 276 | - | |
| 277 | - @Test | |
| 278 | - void de_ContractRequest() { | |
| 279 | - var inputObject = contractRequestObject(); | |
| 280 | - var request = deserialize(inputObject, ContractRequest.class); | |
| 281 | - | |
| 282 | - assertThat(request).isNotNull(); | |
| 283 | - assertThat(request.getProviderId()).isEqualTo(inputObject.getJsonObject("policy").getString("assigner")); | |
| 284 | - assertThat(request.getCallbackAddresses()).isNotEmpty(); | |
| 285 | - assertThat(request.getProtocol()).isEqualTo("test-protocol"); | |
| 286 | - assertThat(request.getCounterPartyAddress()).isEqualTo("test-address"); | |
| 287 | - assertThat(request.getContractOffer().getPolicy()).isNotNull(); | |
| 288 | - | |
| 289 | - } | |
| 290 | - | |
| 291 | - @Test | |
| 292 | - void de_TransferRequest() { | |
| 293 | - var inputObject = transferRequestObject(); | |
| 294 | - var transferRequest = deserialize(inputObject, TransferRequest.class); | |
| 295 | - | |
| 296 | - assertThat(transferRequest).isNotNull(); | |
| 297 | - assertThat(transferRequest.getId()).isEqualTo(inputObject.getString(ID)); | |
| 298 | - assertThat(transferRequest.getCounterPartyAddress()).isEqualTo(inputObject.getString("counterPartyAddress")); | |
| 299 | - assertThat(transferRequest.getContractId()).isEqualTo(inputObject.getString("contractId")); | |
| 300 | - assertThat(transferRequest.getDataDestination()).extracting(DataAddress::getType).isEqualTo(inputObject.getJsonObject("dataDestination").getString("type")); | |
| 301 | - assertThat(transferRequest.getPrivateProperties()).containsEntry(EDC_NAMESPACE + "fooPrivate", "bar"); | |
| 302 | - assertThat(transferRequest.getProtocol()).isEqualTo(inputObject.getString("protocol")); | |
| 303 | - assertThat(transferRequest.getCallbackAddresses()).hasSize(inputObject.getJsonArray("callbackAddresses").size()); | |
| 304 | - assertThat(transferRequest.getTransferType()).isEqualTo(inputObject.getString("transferType")); | |
| 305 | - } | |
| 306 | - | |
| 307 | - @Test | |
| 308 | - void de_TransferRequest_withoutDataAddressType() { | |
| 309 | - var dataDestination = createObjectBuilder() | |
| 310 | - .add("type", "type").build(); | |
| 311 | - | |
| 312 | - var inputObject = transferRequestObject(dataDestination); | |
| 313 | - var transferRequest = deserialize(inputObject, TransferRequest.class); | |
| 314 | - | |
| 315 | - assertThat(transferRequest).isNotNull(); | |
| 316 | - assertThat(transferRequest.getId()).isEqualTo(inputObject.getString(ID)); | |
| 317 | - assertThat(transferRequest.getCounterPartyAddress()).isEqualTo(inputObject.getString("counterPartyAddress")); | |
| 318 | - assertThat(transferRequest.getContractId()).isEqualTo(inputObject.getString("contractId")); | |
| 319 | - assertThat(transferRequest.getDataDestination()).extracting(DataAddress::getType).isEqualTo(inputObject.getJsonObject("dataDestination").getString("type")); | |
| 320 | - assertThat(transferRequest.getPrivateProperties()).containsEntry(EDC_NAMESPACE + "fooPrivate", "bar"); | |
| 321 | - assertThat(transferRequest.getProtocol()).isEqualTo(inputObject.getString("protocol")); | |
| 322 | - assertThat(transferRequest.getCallbackAddresses()).hasSize(inputObject.getJsonArray("callbackAddresses").size()); | |
| 323 | - assertThat(transferRequest.getTransferType()).isEqualTo(inputObject.getString("transferType")); | |
| 324 | - | |
| 325 | - } | |
| 326 | - | |
| 327 | - | |
| 328 | - @Test | |
| 329 | - void de_TerminateNegotiation() { | |
| 330 | - var inputObject = terminateNegotiationObject(); | |
| 331 | - var terminateNegotiation = deserialize(inputObject, TerminateNegotiationCommand.class); | |
| 332 | - | |
| 333 | - assertThat(terminateNegotiation).isNotNull(); | |
| 334 | - assertThat(terminateNegotiation.getReason()).isEqualTo(inputObject.getString("reason")); | |
| 335 | - } | |
| 336 | - | |
| 337 | - @Test | |
| 338 | - void de_TerminateTransfer() { | |
| 339 | - var inputObject = terminateTransferObject(); | |
| 340 | - var terminateTransfer = deserialize(inputObject, TerminateTransfer.class); | |
| 341 | - | |
| 342 | - assertThat(terminateTransfer).isNotNull(); | |
| 343 | - assertThat(terminateTransfer.reason()).isEqualTo(inputObject.getString("reason")); | |
| 344 | - | |
| 345 | - } | |
| 346 | - | |
| 347 | - @Test | |
| 348 | - void de_SuspendTransfer() { | |
| 349 | - var inputObject = suspendTransferObject(); | |
| 350 | - var terminateTransfer = deserialize(inputObject, SuspendTransfer.class); | |
| 351 | - | |
| 352 | - assertThat(terminateTransfer).isNotNull(); | |
| 353 | - assertThat(terminateTransfer.reason()).isEqualTo(inputObject.getString("reason")); | |
| 354 | - | |
| 355 | - } | |
| 356 | - | |
| 357 | - @Test | |
| 358 | - void de_PolicyDefinition_withInForceDate() { | |
| 359 | - | |
| 360 | - var andConstraint = AndConstraint.Builder.newInstance() | |
| 361 | - .constraint(AtomicConstraint.Builder.newInstance() | |
| 362 | - .leftExpression(new LiteralExpression(EDC_NAMESPACE + "inForceDate")) | |
| 363 | - .operator(Operator.GEQ) | |
| 364 | - .rightExpression(new LiteralExpression("contractAgreement+0s")) | |
| 365 | - .build()) | |
| 366 | - .constraint(AtomicConstraint.Builder.newInstance() | |
| 367 | - .leftExpression(new LiteralExpression(EDC_NAMESPACE + "inForceDate")) | |
| 368 | - .operator(Operator.LEQ) | |
| 369 | - .rightExpression(new LiteralExpression("contractAgreement+10s")) | |
| 370 | - .build()) | |
| 371 | - .build(); | |
| 372 | - | |
| 373 | - var inputObject = policyDefinitionObject(inForceDatePermission("gteq", "contractAgreement+0s", "lteq", "contractAgreement+10s")); | |
| 374 | - | |
| 375 | - var terminateTransfer = deserialize(inputObject, PolicyDefinition.class); | |
| 376 | - | |
| 377 | - assertThat(terminateTransfer).isNotNull(); | |
| 378 | - assertThat(terminateTransfer.getPolicy().getPermissions().get(0).getConstraints()) | |
| 379 | - .usingRecursiveFieldByFieldElementComparator().containsOnly(andConstraint); | |
| 380 | - | |
| 381 | - } | |
| 382 | - | |
| 383 | - @Test | |
| 384 | - void de_PolicyEvaluationPlanRequest() { | |
| 385 | - var inputObject = policyEvaluationPlanRequest(); | |
| 386 | - var terminateTransfer = deserialize(inputObject, PolicyEvaluationPlanRequest.class); | |
| 387 | - | |
| 388 | - assertThat(terminateTransfer).isNotNull(); | |
| 389 | - assertThat(terminateTransfer.policyScope()).isEqualTo(inputObject.getString("policyScope")); | |
| 390 | - | |
| 391 | - } | |
| 392 | - | |
| 393 | - /** | |
| 394 | - * Tests for entities that supports transformation from/to JsonObject | |
| 395 | - */ | |
| 396 | - @ParameterizedTest(name = "{1}") | |
| 397 | - @ArgumentsSource(JsonInputProvider.class) | |
| 398 | - void serde(JsonObject inputObject, Class<?> klass, Function<JsonObject, JsonObject> mapper) { | |
| 399 | - var typeTransformerRegistry = RUNTIME.getService(TypeTransformerRegistry.class); | |
| 400 | - var jsonLd = RUNTIME.getService(JsonLd.class); | |
| 401 | - var registry = typeTransformerRegistry.forContext(MANAGEMENT_API_CONTEXT); | |
| 402 | - | |
| 403 | - // Expand the input | |
| 404 | - var expanded = jsonLd.expand(inputObject).orElseThrow(f -> new AssertionError(f.getFailureDetail())); | |
| 405 | - | |
| 406 | - // transform the expanded into the input klass type | |
| 407 | - var result = registry.transform(expanded, klass).orElseThrow(failure -> new RuntimeException()); | |
| 408 | - // transform the klass type instance into JsonObject | |
| 409 | - var object = registry.transform(result, JsonObject.class).orElseThrow(failure -> new RuntimeException()); | |
| 410 | - | |
| 411 | - // Compact the result | |
| 412 | - var compactResult = jsonLd.compact(object, MANAGEMENT_API_SCOPE); | |
| 413 | - | |
| 414 | - // checks that the compacted == inputObject | |
| 415 | - assertThat(compactResult).isSucceeded().satisfies(compacted -> { | |
| 416 | - var mapped = Optional.ofNullable(mapper).map(m -> m.apply(compacted)).orElse(compacted); | |
| 417 | - assertThat(mapped).isEqualTo(inputObject); | |
| 418 | - }); | |
| 419 | - } | |
| 420 | - | |
| 421 | - private JsonObject serialize(Object object) { | |
| 422 | - var typeTransformerRegistry = RUNTIME.getService(TypeTransformerRegistry.class); | |
| 423 | - var registry = typeTransformerRegistry.forContext(MANAGEMENT_API_CONTEXT); | |
| 424 | - var jsonLd = RUNTIME.getService(JsonLd.class); | |
| 425 | - | |
| 426 | - var result = registry.transform(object, JsonObject.class).orElseThrow(failure -> new RuntimeException()); | |
| 427 | - return jsonLd.compact(result, MANAGEMENT_API_SCOPE).orElseThrow(failure -> new RuntimeException(failure.getFailureDetail())); | |
| 428 | - } | |
| 429 | - | |
| 430 | - private <T> T deserialize(JsonObject inputObject, Class<T> klass) { | |
| 431 | - var typeTransformerRegistry = RUNTIME.getService(TypeTransformerRegistry.class); | |
| 432 | - var registry = typeTransformerRegistry.forContext(MANAGEMENT_API_CONTEXT); | |
| 433 | - var jsonLd = RUNTIME.getService(JsonLd.class); | |
| 434 | - | |
| 435 | - var expanded = jsonLd.expand(inputObject).orElseThrow(f -> new AssertionError(f.getFailureDetail())); | |
| 436 | - | |
| 437 | - | |
| 438 | - // checks that the type is correctly expanded to the EDC namespace | |
| 439 | - assertThat(expanded.getJsonArray(TYPE)).first().satisfies(t -> { | |
| 440 | - assertThat(((JsonString) t).getString()).startsWith(EDC_NAMESPACE); | |
| 441 | - }); | |
| 442 | - | |
| 443 | - return registry.transform(expanded, klass).orElseThrow(failure -> new RuntimeException()); | |
| 444 | - } | |
| 445 | - | |
| 446 | - private static class JsonInputProvider implements ArgumentsProvider { | |
| 447 | - @Override | |
| 448 | - public Stream<? extends Arguments> provideArguments(ExtensionContext context) { | |
| 449 | - | |
| 450 | - Function<JsonObject, JsonObject> mapper = this::policyMapper; | |
| 451 | - | |
| 452 | - return Stream.of( | |
| 453 | - Arguments.of(assetObject(), Asset.class, null), | |
| 454 | - Arguments.of(contractDefinitionObject(), ContractDefinition.class, null), | |
| 455 | - Arguments.of(secretObject(), Secret.class, null), | |
| 456 | - Arguments.of(querySpecObject(), QuerySpec.class, null), | |
| 457 | - Arguments.of(policyDefinitionObject(), PolicyDefinition.class, mapper), | |
| 458 | - Arguments.of(dataAddressObject(), DataAddress.class, null) | |
| 459 | - ); | |
| 460 | - } | |
| 461 | - | |
| 462 | - private JsonObject policyMapper(JsonObject compacted) { | |
| 463 | - var policy = compacted.getJsonObject("policy"); | |
| 464 | - var newPolicy = Json.createObjectBuilder(policy); | |
| 465 | - newPolicy.remove("@id"); | |
| 466 | - var newDefinition = Json.createObjectBuilder(compacted); | |
| 467 | - newDefinition.remove("createdAt"); | |
| 468 | - newDefinition.add("policy", newPolicy); | |
| 469 | - | |
| 470 | - return newDefinition.build(); | |
| 471 | - } | |
| 472 | - } | |
| 473 | - | |
| 474 | - | |
| 475 | -} |
deleted extensions/common/api/management-api-json-ld-context/src/test/java/org/eclipse/edc/connector/api/management/jsonld/serde/TestFunctions.java +0 −401
| @@ -1,401 +0,0 @@ | ||
| 1 | -/* | |
| 2 | - * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 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 | - * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | - * | |
| 13 | - */ | |
| 14 | - | |
| 15 | -package org.eclipse.edc.connector.api.management.jsonld.serde; | |
| 16 | - | |
| 17 | -import jakarta.json.Json; | |
| 18 | -import jakarta.json.JsonArrayBuilder; | |
| 19 | -import jakarta.json.JsonObject; | |
| 20 | -import jakarta.json.JsonObjectBuilder; | |
| 21 | -import org.eclipse.edc.connector.controlplane.contract.spi.types.agreement.ContractAgreement; | |
| 22 | -import org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractNegotiation; | |
| 23 | -import org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcess; | |
| 24 | -import org.eclipse.edc.edr.spi.types.EndpointDataReferenceEntry; | |
| 25 | -import org.eclipse.edc.policy.engine.spi.AtomicConstraintFunction; | |
| 26 | -import org.eclipse.edc.policy.engine.spi.PolicyValidatorFunction; | |
| 27 | -import org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan; | |
| 28 | -import org.eclipse.edc.policy.engine.spi.plan.step.AndConstraintStep; | |
| 29 | -import org.eclipse.edc.policy.engine.spi.plan.step.AtomicConstraintStep; | |
| 30 | -import org.eclipse.edc.policy.engine.spi.plan.step.ConstraintStep; | |
| 31 | -import org.eclipse.edc.policy.engine.spi.plan.step.DutyStep; | |
| 32 | -import org.eclipse.edc.policy.engine.spi.plan.step.OrConstraintStep; | |
| 33 | -import org.eclipse.edc.policy.engine.spi.plan.step.PermissionStep; | |
| 34 | -import org.eclipse.edc.policy.engine.spi.plan.step.ProhibitionStep; | |
| 35 | -import org.eclipse.edc.policy.engine.spi.plan.step.ValidatorStep; | |
| 36 | -import org.eclipse.edc.policy.engine.spi.plan.step.XoneConstraintStep; | |
| 37 | -import org.eclipse.edc.policy.model.AtomicConstraint; | |
| 38 | -import org.eclipse.edc.policy.model.LiteralExpression; | |
| 39 | -import org.eclipse.edc.policy.model.Policy; | |
| 40 | -import org.eclipse.edc.policy.model.Rule; | |
| 41 | -import org.eclipse.edc.spi.types.domain.DataAddress; | |
| 42 | -import org.eclipse.edc.spi.types.domain.callback.CallbackAddress; | |
| 43 | - | |
| 44 | -import java.time.Clock; | |
| 45 | -import java.util.List; | |
| 46 | -import java.util.Map; | |
| 47 | -import java.util.Set; | |
| 48 | - | |
| 49 | -import static jakarta.json.Json.createArrayBuilder; | |
| 50 | -import static jakarta.json.Json.createObjectBuilder; | |
| 51 | -import static java.util.Collections.emptySet; | |
| 52 | -import static org.eclipse.edc.connector.api.management.jsonld.ManagementApiJsonLdContextExtension.EDC_CONNECTOR_MANAGEMENT_CONTEXT; | |
| 53 | -import static org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractNegotiationStates.REQUESTED; | |
| 54 | -import static org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcess.Type.CONSUMER; | |
| 55 | -import static org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcessStates.STARTED; | |
| 56 | -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.CONTEXT; | |
| 57 | -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; | |
| 58 | -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; | |
| 59 | -import static org.eclipse.edc.policy.model.OdrlNamespace.ODRL_SCHEMA; | |
| 60 | -import static org.eclipse.edc.policy.model.Operator.EQ; | |
| 61 | -import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 62 | -import static org.eclipse.edc.spi.types.domain.callback.CallbackAddress.EVENTS; | |
| 63 | -import static org.eclipse.edc.spi.types.domain.callback.CallbackAddress.IS_TRANSACTIONAL; | |
| 64 | -import static org.eclipse.edc.spi.types.domain.callback.CallbackAddress.URI; | |
| 65 | -import static org.mockito.Mockito.mock; | |
| 66 | -import static org.mockito.Mockito.when; | |
| 67 | - | |
| 68 | -public class TestFunctions { | |
| 69 | - | |
| 70 | - public static final String TEST_ASSET_ID = "some-asset-id"; | |
| 71 | - public static final String TEST_ASSET_NAME = "some-asset-name"; | |
| 72 | - public static final String TEST_ASSET_DESCRIPTION = "some description"; | |
| 73 | - public static final String TEST_ASSET_CONTENTTYPE = "application/json"; | |
| 74 | - public static final String TEST_ASSET_VERSION = "0.2.1"; | |
| 75 | - public static final String MANAGEMENT_API_SCOPE = "MANAGEMENT_API"; | |
| 76 | - public static final String MANAGEMENT_API_CONTEXT = "management-api"; | |
| 77 | - private static final String DEFINITION_ID = "some-definition-id"; | |
| 78 | - private static final String POLICY_ID = "some-policy-id"; | |
| 79 | - | |
| 80 | - public static JsonArrayBuilder createContextBuilder() { | |
| 81 | - return createArrayBuilder() | |
| 82 | - .add(EDC_CONNECTOR_MANAGEMENT_CONTEXT) | |
| 83 | - .add(createObjectBuilder() | |
| 84 | - .add("edc", EDC_NAMESPACE) | |
| 85 | - .add("odrl", ODRL_SCHEMA)); | |
| 86 | - } | |
| 87 | - | |
| 88 | - public static JsonObject assetObject() { | |
| 89 | - return createObjectBuilder() | |
| 90 | - .add(CONTEXT, createContextBuilder().build()) | |
| 91 | - .add(TYPE, "Asset") | |
| 92 | - .add(ID, TEST_ASSET_ID) | |
| 93 | - .add("properties", createObjectBuilder() | |
| 94 | - .add("name", TEST_ASSET_NAME) | |
| 95 | - .add("id", TEST_ASSET_ID) | |
| 96 | - .add("description", TEST_ASSET_DESCRIPTION) | |
| 97 | - .add("version", TEST_ASSET_VERSION) | |
| 98 | - .add("contenttype", TEST_ASSET_CONTENTTYPE) | |
| 99 | - .build()) | |
| 100 | - .add("dataAddress", createObjectBuilder().add("@type", "DataAddress").add("type", "address-type")) | |
| 101 | - .build(); | |
| 102 | - } | |
| 103 | - | |
| 104 | - public static JsonObject dataAddressObject() { | |
| 105 | - return createObjectBuilder() | |
| 106 | - .add(CONTEXT, createContextBuilder().build()) | |
| 107 | - .add(TYPE, "DataAddress") | |
| 108 | - .add("type", "address-type") | |
| 109 | - .add("propertyOne", "foo") | |
| 110 | - .add("propertyTwo", "bar") | |
| 111 | - .build(); | |
| 112 | - } | |
| 113 | - | |
| 114 | - public static JsonObject contractDefinitionObject() { | |
| 115 | - var criterion = Json.createObjectBuilder() | |
| 116 | - .add(TYPE, "Criterion") | |
| 117 | - .add("operandLeft", "foo") | |
| 118 | - .add("operator", "=") | |
| 119 | - .add("operandRight", "bar") | |
| 120 | - .build(); | |
| 121 | - | |
| 122 | - var assetsSelectorJson = createArrayBuilder() | |
| 123 | - .add(criterion) | |
| 124 | - .build(); | |
| 125 | - | |
| 126 | - return createObjectBuilder() | |
| 127 | - .add(CONTEXT, createContextBuilder().build()) | |
| 128 | - .add(TYPE, "ContractDefinition") | |
| 129 | - .add(ID, DEFINITION_ID) | |
| 130 | - .add("accessPolicyId", "accessPolicyId") | |
| 131 | - .add("contractPolicyId", "contractPolicyId") | |
| 132 | - .add("assetsSelector", assetsSelectorJson) | |
| 133 | - .build(); | |
| 134 | - | |
| 135 | - } | |
| 136 | - | |
| 137 | - public static JsonObject terminateNegotiationObject() { | |
| 138 | - return Json.createObjectBuilder() | |
| 139 | - .add(CONTEXT, createContextBuilder().build()) | |
| 140 | - .add(TYPE, "TerminateNegotiation") | |
| 141 | - .add("reason", "reason") | |
| 142 | - .build(); | |
| 143 | - } | |
| 144 | - | |
| 145 | - public static JsonObject terminateTransferObject() { | |
| 146 | - return Json.createObjectBuilder() | |
| 147 | - .add(CONTEXT, createContextBuilder().build()) | |
| 148 | - .add(TYPE, "TerminateTransfer") | |
| 149 | - .add("reason", "reason") | |
| 150 | - .build(); | |
| 151 | - } | |
| 152 | - | |
| 153 | - public static JsonObject suspendTransferObject() { | |
| 154 | - return Json.createObjectBuilder() | |
| 155 | - .add(CONTEXT, createContextBuilder().build()) | |
| 156 | - .add(TYPE, "SuspendTransfer") | |
| 157 | - .add("reason", "reason") | |
| 158 | - .build(); | |
| 159 | - } | |
| 160 | - | |
| 161 | - public static JsonObject contractRequestObject() { | |
| 162 | - var policy = policy(atomicConstraint("spatial", "eq", "https://www.wikidata.org/wiki/Q183")) | |
| 163 | - .add(ID, "id") | |
| 164 | - .add("assigner", "provider") | |
| 165 | - .build(); | |
| 166 | - return Json.createObjectBuilder() | |
| 167 | - .add(CONTEXT, createContextBuilder().build()) | |
| 168 | - .add(TYPE, "ContractRequest") | |
| 169 | - .add("counterPartyAddress", "test-address") | |
| 170 | - .add("protocol", "test-protocol") | |
| 171 | - .add("callbackAddresses", createCallbackAddress()) | |
| 172 | - .add("policy", policy) | |
| 173 | - .build(); | |
| 174 | - } | |
| 175 | - | |
| 176 | - public static JsonObject transferRequestObject() { | |
| 177 | - var dataDestination = createObjectBuilder() | |
| 178 | - .add(TYPE, "DataAddress") | |
| 179 | - .add("type", "type").build(); | |
| 180 | - | |
| 181 | - return transferRequestObject(dataDestination); | |
| 182 | - } | |
| 183 | - | |
| 184 | - public static JsonObject transferRequestObject(JsonObject dataDestination) { | |
| 185 | - var propertiesJson = Json.createObjectBuilder().add("foo", "bar").build(); | |
| 186 | - var privatePropertiesJson = Json.createObjectBuilder().add("fooPrivate", "bar").build(); | |
| 187 | - | |
| 188 | - | |
| 189 | - return createObjectBuilder() | |
| 190 | - .add(TYPE, "TransferRequest") | |
| 191 | - .add(CONTEXT, createContextBuilder().build()) | |
| 192 | - .add(ID, "id") | |
| 193 | - .add("counterPartyAddress", "address") | |
| 194 | - .add("contractId", "contractId") | |
| 195 | - .add("dataDestination", dataDestination) | |
| 196 | - .add("properties", propertiesJson) | |
| 197 | - .add("privateProperties", privatePropertiesJson) | |
| 198 | - .add("protocol", "protocol") | |
| 199 | - .add("callbackAddresses", createCallbackAddress()) | |
| 200 | - .add("transferType", "myTransferType") | |
| 201 | - .build(); | |
| 202 | - } | |
| 203 | - | |
| 204 | - public static ContractAgreement createContractAgreement(String id) { | |
| 205 | - return ContractAgreement.Builder.newInstance() | |
| 206 | - .id(id) | |
| 207 | - .providerId("providerId") | |
| 208 | - .consumerId("consumerId") | |
| 209 | - .assetId("assetId") | |
| 210 | - .policy(Policy.Builder.newInstance().build()) | |
| 211 | - .build(); | |
| 212 | - } | |
| 213 | - | |
| 214 | - public static ContractNegotiation createContractNegotiation() { | |
| 215 | - return ContractNegotiation.Builder.newInstance() | |
| 216 | - .id("test-id") | |
| 217 | - .correlationId("correlation-id") | |
| 218 | - .counterPartyId("counter-party-id") | |
| 219 | - .counterPartyAddress("address") | |
| 220 | - .contractAgreement(createContractAgreement("test-agreement")) | |
| 221 | - .state(REQUESTED.code()) | |
| 222 | - .type(ContractNegotiation.Type.PROVIDER) | |
| 223 | - .callbackAddresses(List.of( | |
| 224 | - CallbackAddress.Builder.newInstance() | |
| 225 | - .uri("local://test") | |
| 226 | - .events(Set.of("event")) | |
| 227 | - .build())) | |
| 228 | - .protocol("protocol") | |
| 229 | - .errorDetail("errorDetail") | |
| 230 | - .createdAt(1234) | |
| 231 | - .build(); | |
| 232 | - | |
| 233 | - } | |
| 234 | - | |
| 235 | - public static TransferProcess createTransferProcess() { | |
| 236 | - return TransferProcess.Builder.newInstance() | |
| 237 | - .id("transferProcessId") | |
| 238 | - .state(STARTED.code()) | |
| 239 | - .stateTimestamp(1234L) | |
| 240 | - .privateProperties(Map.of("foo", "bar")) | |
| 241 | - .type(CONSUMER) | |
| 242 | - .correlationId("correlationId") | |
| 243 | - .assetId("assetId") | |
| 244 | - .contractId("contractId") | |
| 245 | - .dataDestination(DataAddress.Builder.newInstance().type("any").properties(Map.of("bar", "foo")).build()) | |
| 246 | - .callbackAddresses(List.of(CallbackAddress.Builder.newInstance().uri("http://any").events(emptySet()).build())) | |
| 247 | - .errorDetail("an error") | |
| 248 | - .build(); | |
| 249 | - } | |
| 250 | - | |
| 251 | - public static EndpointDataReferenceEntry createEdrEntry() { | |
| 252 | - return EndpointDataReferenceEntry.Builder.newInstance() | |
| 253 | - .id("transferProcessId") | |
| 254 | - .transferProcessId("transferProcessId") | |
| 255 | - .agreementId("agreementId") | |
| 256 | - .assetId("assetId") | |
| 257 | - .providerId("providerId") | |
| 258 | - .contractNegotiationId("contractNegotiationId") | |
| 259 | - .createdAt(Clock.systemUTC().millis()) | |
| 260 | - .build(); | |
| 261 | - } | |
| 262 | - | |
| 263 | - public static PolicyEvaluationPlan createPolicyEvaluationPlan() { | |
| 264 | - | |
| 265 | - var firstConstraint = atomicConstraintStep(atomicConstraint("foo", "bar")); | |
| 266 | - var secondConstraint = atomicConstraintStep(atomicConstraint("baz", "bar")); | |
| 267 | - | |
| 268 | - List<ConstraintStep> constraints = List.of(firstConstraint, secondConstraint); | |
| 269 | - | |
| 270 | - var orConstraintStep = new OrConstraintStep(constraints, mock()); | |
| 271 | - var andConstraintStep = new AndConstraintStep(constraints, mock()); | |
| 272 | - var xoneConstraintStep = new XoneConstraintStep(constraints, mock()); | |
| 273 | - | |
| 274 | - var permission = PermissionStep.Builder.newInstance().constraint(orConstraintStep).rule(mock()).build(); | |
| 275 | - var duty = DutyStep.Builder.newInstance().constraint(xoneConstraintStep).rule(mock()).build(); | |
| 276 | - var prohibition = ProhibitionStep.Builder.newInstance().constraint(andConstraintStep).rule(mock()).build(); | |
| 277 | - | |
| 278 | - var validatorFunction = mock(PolicyValidatorFunction.class); | |
| 279 | - when(validatorFunction.name()).thenReturn("FunctionName"); | |
| 280 | - | |
| 281 | - return PolicyEvaluationPlan.Builder.newInstance() | |
| 282 | - .postValidator(new ValidatorStep(validatorFunction)) | |
| 283 | - .prohibition(prohibition) | |
| 284 | - .permission(permission) | |
| 285 | - .duty(duty) | |
| 286 | - .preValidator(new ValidatorStep(validatorFunction)) | |
| 287 | - .build(); | |
| 288 | - } | |
| 289 | - | |
| 290 | - public static JsonObject policyDefinitionObject() { | |
| 291 | - return createObjectBuilder() | |
| 292 | - .add(CONTEXT, createContextBuilder().build()) | |
| 293 | - .add(TYPE, "PolicyDefinition") | |
| 294 | - .add(ID, POLICY_ID) | |
| 295 | - .add("policy", inForceDatePolicy("gteq", "contractAgreement+0s", "lteq", "contractAgreement+10s")) | |
| 296 | - .build(); | |
| 297 | - } | |
| 298 | - | |
| 299 | - public static JsonObject policyDefinitionObject(JsonObject permission) { | |
| 300 | - return createObjectBuilder() | |
| 301 | - .add(CONTEXT, createContextBuilder().build()) | |
| 302 | - .add(TYPE, "PolicyDefinition") | |
| 303 | - .add(ID, POLICY_ID) | |
| 304 | - .add("policy", policy(permission)) | |
| 305 | - .build(); | |
| 306 | - } | |
| 307 | - | |
| 308 | - public static JsonObject secretObject() { | |
| 309 | - return createObjectBuilder() | |
| 310 | - .add(CONTEXT, createContextBuilder().build()) | |
| 311 | - .add(TYPE, "Secret") | |
| 312 | - .add(ID, "secret-id") | |
| 313 | - .add("value", "superSecret") | |
| 314 | - .build(); | |
| 315 | - } | |
| 316 | - | |
| 317 | - private static JsonArrayBuilder createCallbackAddress() { | |
| 318 | - var builder = Json.createArrayBuilder(); | |
| 319 | - return builder.add(Json.createObjectBuilder() | |
| 320 | - .add(IS_TRANSACTIONAL, true) | |
| 321 | - .add(URI, "http://test.local/") | |
| 322 | - .add(EVENTS, Json.createArrayBuilder().build())); | |
| 323 | - } | |
| 324 | - | |
| 325 | - public static JsonObjectBuilder policy(JsonObject permission) { | |
| 326 | - return createObjectBuilder() | |
| 327 | - .add(TYPE, "odrl:Set") | |
| 328 | - .add("obligation", createArrayBuilder().build()) | |
| 329 | - .add("permission", permission) | |
| 330 | - .add("target", "assetId") | |
| 331 | - .add("prohibition", createArrayBuilder().build()); | |
| 332 | - } | |
| 333 | - | |
| 334 | - public static JsonObject querySpecObject() { | |
| 335 | - var criterion = createObjectBuilder() | |
| 336 | - .add(TYPE, "Criterion") | |
| 337 | - .add("operandLeft", "foo") | |
| 338 | - .add("operator", "=") | |
| 339 | - .add("operandRight", "bar") | |
| 340 | - .build(); | |
| 341 | - | |
| 342 | - return createObjectBuilder() | |
| 343 | - .add(CONTEXT, createContextBuilder().build()) | |
| 344 | - .add(TYPE, "QuerySpec") | |
| 345 | - .add("offset", 10) | |
| 346 | - .add("limit", 20) | |
| 347 | - .add("filterExpression", createArrayBuilder().add(criterion).build()) | |
| 348 | - .add("sortOrder", "DESC") | |
| 349 | - .add("sortField", "fieldName") | |
| 350 | - .build(); | |
| 351 | - | |
| 352 | - } | |
| 353 | - | |
| 354 | - public static JsonObject inForceDatePolicy(String operatorStart, Object startDate, String operatorEnd, Object endDate) { | |
| 355 | - return policy(inForceDatePermission(operatorStart, startDate, operatorEnd, endDate)).build(); | |
| 356 | - } | |
| 357 | - | |
| 358 | - public static JsonObject atomicConstraint(String leftOperand, String operator, Object rightOperand) { | |
| 359 | - return createObjectBuilder() | |
| 360 | - .add("leftOperand", leftOperand) | |
| 361 | - .add("operator", operator) | |
| 362 | - .add("rightOperand", rightOperand.toString()) | |
| 363 | - .build(); | |
| 364 | - } | |
| 365 | - | |
| 366 | - public static JsonObject inForceDatePermission(String operatorStart, Object startDate, String operatorEnd, Object endDate) { | |
| 367 | - return createObjectBuilder() | |
| 368 | - .add("action", "use") | |
| 369 | - .add("constraint", createObjectBuilder() | |
| 370 | - .add("and", createArrayBuilder() | |
| 371 | - .add(atomicConstraint("inForceDate", operatorStart, startDate)) | |
| 372 | - .add(atomicConstraint("inForceDate", operatorEnd, endDate)) | |
| 373 | - .build()) | |
| 374 | - .build()) | |
| 375 | - .build(); | |
| 376 | - } | |
| 377 | - | |
| 378 | - public static JsonObject policyEvaluationPlanRequest() { | |
| 379 | - return Json.createObjectBuilder() | |
| 380 | - .add(CONTEXT, createContextBuilder().build()) | |
| 381 | - .add(TYPE, "PolicyEvaluationPlanRequest") | |
| 382 | - .add("policyScope", "catalog") | |
| 383 | - .build(); | |
| 384 | - } | |
| 385 | - | |
| 386 | - private static AtomicConstraintStep atomicConstraintStep(AtomicConstraint atomicConstraint) { | |
| 387 | - AtomicConstraintFunction<Rule> function = mock(); | |
| 388 | - when(function.name()).thenReturn("AtomicConstraintFunction"); | |
| 389 | - return new AtomicConstraintStep(atomicConstraint, List.of("filtered constraint"), mock(), function); | |
| 390 | - } | |
| 391 | - | |
| 392 | - private static AtomicConstraint atomicConstraint(String key, String value) { | |
| 393 | - var left = new LiteralExpression(key); | |
| 394 | - var right = new LiteralExpression(value); | |
| 395 | - return AtomicConstraint.Builder.newInstance() | |
| 396 | - .leftExpression(left) | |
| 397 | - .operator(EQ) | |
| 398 | - .rightExpression(right) | |
| 399 | - .build(); | |
| 400 | - } | |
| 401 | -} |
modified extensions/common/json-ld/src/main/java/org/eclipse/edc/jsonld/JsonLdExtension.java +6 −10
| @@ -15,7 +15,6 @@ | ||
| 15 | 15 | package org.eclipse.edc.jsonld; |
| 16 | 16 | |
| 17 | 17 | import org.eclipse.edc.jsonld.spi.JsonLd; |
| 18 | -import org.eclipse.edc.jsonld.spi.JsonLdKeywords; | |
| 19 | 18 | import org.eclipse.edc.jsonld.spi.transformer.JsonLdTransformer; |
| 20 | 19 | import org.eclipse.edc.jsonld.util.JacksonJsonLd; |
| 21 | 20 | import org.eclipse.edc.runtime.metamodel.annotation.BaseExtension; |
| @@ -36,8 +35,7 @@ | ||
| 36 | 35 | import java.util.stream.Stream; |
| 37 | 36 | |
| 38 | 37 | import static java.lang.String.format; |
| 39 | -import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 40 | -import static org.eclipse.edc.spi.constants.CoreConstants.EDC_PREFIX; | |
| 38 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_CONNECTOR_MANAGEMENT_CONTEXT; | |
| 41 | 39 | import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD; |
| 42 | 40 | |
| 43 | 41 | /** |
| @@ -64,8 +62,8 @@ | ||
| 64 | 62 | private static final String HTTP_ENABLE_SETTING = "edc.jsonld.http.enabled"; |
| 65 | 63 | @Setting(value = "If set enable https json-ld document resolution", type = "boolean", defaultValue = DEFAULT_HTTP_HTTPS_RESOLUTION + "") |
| 66 | 64 | private static final String HTTPS_ENABLE_SETTING = "edc.jsonld.https.enabled"; |
| 67 | - private static final String DEFAULT_AVOID_VOCAB_CONTEXT = "false"; | |
| 68 | - @Setting(value = "If true disable the @vocab context definition. This could be used to avoid api breaking changes", type = "boolean", defaultValue = DEFAULT_AVOID_VOCAB_CONTEXT) | |
| 65 | + private static final boolean DEFAULT_AVOID_VOCAB_CONTEXT = false; | |
| 66 | + @Setting(value = "If true disable the @vocab context definition. This could be used to avoid api breaking changes", type = "boolean", defaultValue = DEFAULT_AVOID_VOCAB_CONTEXT + "") | |
| 69 | 67 | private static final String AVOID_VOCAB_CONTEXT = "edc.jsonld.vocab.disable"; |
| 70 | 68 | private static final boolean DEFAULT_CHECK_PREFIXES = true; |
| 71 | 69 | @Setting(value = "If true a validation on expended object will be made against configured prefixes", type = "boolean", defaultValue = DEFAULT_CHECK_PREFIXES + "") |
| @@ -90,18 +88,16 @@ | ||
| 90 | 88 | var configuration = JsonLdConfiguration.Builder.newInstance() |
| 91 | 89 | .httpEnabled(config.getBoolean(HTTP_ENABLE_SETTING, DEFAULT_HTTP_HTTPS_RESOLUTION)) |
| 92 | 90 | .httpsEnabled(config.getBoolean(HTTPS_ENABLE_SETTING, DEFAULT_HTTP_HTTPS_RESOLUTION)) |
| 91 | + .avoidVocab(config.getBoolean(AVOID_VOCAB_CONTEXT, DEFAULT_AVOID_VOCAB_CONTEXT)) | |
| 93 | 92 | .checkPrefixes(config.getBoolean(CHECK_PREFIXES, DEFAULT_CHECK_PREFIXES)) |
| 94 | 93 | .build(); |
| 95 | 94 | var monitor = context.getMonitor(); |
| 96 | 95 | var service = new TitaniumJsonLd(monitor, configuration); |
| 97 | - if (!config.getBoolean(AVOID_VOCAB_CONTEXT, Boolean.valueOf(DEFAULT_AVOID_VOCAB_CONTEXT))) { | |
| 98 | - service.registerNamespace(JsonLdKeywords.VOCAB, EDC_NAMESPACE); | |
| 99 | - } | |
| 100 | - service.registerNamespace(EDC_PREFIX, EDC_NAMESPACE); | |
| 101 | 96 | |
| 102 | 97 | Stream.of( |
| 103 | 98 | new JsonLdContext("odrl.jsonld", "http://www.w3.org/ns/odrl.jsonld"), |
| 104 | - new JsonLdContext("dspace.jsonld", "https://w3id.org/dspace/2024/1/context.json") | |
| 99 | + new JsonLdContext("dspace.jsonld", "https://w3id.org/dspace/2024/1/context.json"), | |
| 100 | + new JsonLdContext("management-context-v1.jsonld", EDC_CONNECTOR_MANAGEMENT_CONTEXT) | |
| 105 | 101 | ).forEach(jsonLdContext -> getResourceUri("document/" + jsonLdContext.fileName()) |
| 106 | 102 | .onSuccess(uri -> service.registerCachedDocument(jsonLdContext.url(), uri)) |
| 107 | 103 | .onFailure(failure -> monitor.warning("Failed to register cached json-ld document: " + failure.getFailureDetail())) |
added extensions/common/json-ld/src/main/resources/document/management-context-v1.jsonld +181 −0
| @@ -0,0 +1,181 @@ | ||
| 1 | +{ | |
| 2 | + "@context": { | |
| 3 | + "@version": 1.1, | |
| 4 | + "edc": "https://w3id.org/edc/v0.0.1/ns/", | |
| 5 | + "Asset": "edc:Asset", | |
| 6 | + "PolicyDefinition": "edc:PolicyDefinition", | |
| 7 | + "DataAddress": { | |
| 8 | + "@id": "edc:DataAddress", | |
| 9 | + "@context": { | |
| 10 | + "type": "edc:type", | |
| 11 | + "@vocab": "https://w3id.org/edc/v0.0.1/ns/" | |
| 12 | + } | |
| 13 | + }, | |
| 14 | + "ContractDefinition": "edc:ContractDefinition", | |
| 15 | + "Criterion": "edc:Criterion", | |
| 16 | + "ContractRequest": "edc:ContractRequest", | |
| 17 | + "QuerySpec": "edc:QuerySpec", | |
| 18 | + "ContractNegotiation": { | |
| 19 | + "@id": "edc:ContractNegotiation", | |
| 20 | + "@context": { | |
| 21 | + "type": "edc:type" | |
| 22 | + } | |
| 23 | + }, | |
| 24 | + "CallbackAddress": "edc:CallbackAddress", | |
| 25 | + "NegotiationState": "edc:NegotiationState", | |
| 26 | + "TerminateNegotiation": "edc:TerminateNegotiation", | |
| 27 | + "ContractAgreement": "edc:ContractAgreement", | |
| 28 | + "TransferRequest": "edc:TransferRequest", | |
| 29 | + "TransferState": "edc:TransferState", | |
| 30 | + "TransferProcess": { | |
| 31 | + "@id": "edc:TransferProcess", | |
| 32 | + "@context": { | |
| 33 | + "type": "edc:type" | |
| 34 | + } | |
| 35 | + }, | |
| 36 | + "TerminateTransfer": "edc:TerminateTransfer", | |
| 37 | + "SuspendTransfer": "edc:SuspendTransfer", | |
| 38 | + "Secret": "edc:Secret", | |
| 39 | + "EndpointDataReferenceEntry": "edc:EndpointDataReferenceEntry", | |
| 40 | + "PolicyValidationResult": "edc:PolicyValidationResult", | |
| 41 | + "PolicyEvaluationPlanRequest": "edc:PolicyEvaluationPlanRequest", | |
| 42 | + "PolicyEvaluationPlan": "edc:PolicyEvaluationPlan", | |
| 43 | + "PermissionStep": "edc:PermissionStep", | |
| 44 | + "ProhibitionStep": "edc:ProhibitionStep", | |
| 45 | + "DutyStep": "edc:DutyStep", | |
| 46 | + "OrConstraintStep": "edc:OrConstraintStep", | |
| 47 | + "AndConstraintStep": "edc:AndConstraintStep", | |
| 48 | + "XoneConstraintStep": "edc:XoneConstraintStep", | |
| 49 | + "AtomicConstraintStep": "edc:AtomicConstraintStep", | |
| 50 | + "properties": { | |
| 51 | + "@id": "edc:properties", | |
| 52 | + "@context": { | |
| 53 | + "@vocab": "https://w3id.org/edc/v0.0.1/ns/" | |
| 54 | + } | |
| 55 | + }, | |
| 56 | + "privateProperties": { | |
| 57 | + "@id": "edc:privateProperties", | |
| 58 | + "@context": { | |
| 59 | + "@vocab": "https://w3id.org/edc/v0.0.1/ns/" | |
| 60 | + } | |
| 61 | + }, | |
| 62 | + "dataAddress": { | |
| 63 | + "@id": "edc:dataAddress", | |
| 64 | + "@context": { | |
| 65 | + "@vocab": "https://w3id.org/edc/v0.0.1/ns/" | |
| 66 | + } | |
| 67 | + }, | |
| 68 | + "createdAt": "edc:createdAt", | |
| 69 | + "accessPolicyId": "edc:accessPolicyId", | |
| 70 | + "contractPolicyId": "edc:contractPolicyId", | |
| 71 | + "assetsSelector": { | |
| 72 | + "@id": "edc:assetsSelector", | |
| 73 | + "@container": "@set" | |
| 74 | + }, | |
| 75 | + "operandLeft": "edc:operandLeft", | |
| 76 | + "operator": "edc:operator", | |
| 77 | + "operandRight": "edc:operandRight", | |
| 78 | + "limit": "edc:limit", | |
| 79 | + "offset": "edc:offset", | |
| 80 | + "filterExpression": { | |
| 81 | + "@id": "edc:filterExpression", | |
| 82 | + "@container": "@set" | |
| 83 | + }, | |
| 84 | + "sortOrder": "edc:sortOrder", | |
| 85 | + "sortField": "edc:sortField", | |
| 86 | + "counterPartyAddress": "edc:counterPartyAddress", | |
| 87 | + "protocol": "edc:protocol", | |
| 88 | + "callbackAddresses": { | |
| 89 | + "@id": "edc:callbackAddresses", | |
| 90 | + "@container": "@set" | |
| 91 | + }, | |
| 92 | + "providerId": "edc:providerId", | |
| 93 | + "policy": { | |
| 94 | + "@id": "edc:policy", | |
| 95 | + "@context": [ | |
| 96 | + "http://www.w3.org/ns/odrl.jsonld", | |
| 97 | + { | |
| 98 | + "uid": null, | |
| 99 | + "type": null | |
| 100 | + } | |
| 101 | + ] | |
| 102 | + }, | |
| 103 | + "counterPartyId": "edc:counterPartyId", | |
| 104 | + "state": "edc:state", | |
| 105 | + "errorDetail": "edc:errorDetail", | |
| 106 | + "contractAgreementId": "edc:contractAgreementId", | |
| 107 | + "uri": "edc:uri", | |
| 108 | + "transactional": "edc:transactional", | |
| 109 | + "events": { | |
| 110 | + "@id": "edc:events", | |
| 111 | + "@container": "@set" | |
| 112 | + }, | |
| 113 | + "reason": "edc:reason", | |
| 114 | + "assetId": "edc:assetId", | |
| 115 | + "consumerId": "edc:consumerId", | |
| 116 | + "contractSigningDate": "edc:contractSigningDate", | |
| 117 | + "contractId": "edc:contractId", | |
| 118 | + "dataDestination": { | |
| 119 | + "@id": "edc:dataDestination", | |
| 120 | + "@context": { | |
| 121 | + "@vocab": "https://w3id.org/edc/v0.0.1/ns/" | |
| 122 | + } | |
| 123 | + }, | |
| 124 | + "transferType": "edc:transferType", | |
| 125 | + "correlationId": "edc:correlationId", | |
| 126 | + "stateTimestamp": "edc:stateTimestamp", | |
| 127 | + "value": "edc:value", | |
| 128 | + "transferProcessId": "edc:transferProcessId", | |
| 129 | + "contractNegotiationId": "edc:contractNegotiationId", | |
| 130 | + "agreementId": "edc:agreementId", | |
| 131 | + "inForceDate": "edc:inForceDate", | |
| 132 | + "isValid": "edc:isValid", | |
| 133 | + "errors": { | |
| 134 | + "@id": "edc:errors", | |
| 135 | + "@container": "@set" | |
| 136 | + }, | |
| 137 | + "policyScope": "edc:policyScope", | |
| 138 | + "preValidators": { | |
| 139 | + "@id": "edc:preValidators", | |
| 140 | + "@container": "@set" | |
| 141 | + }, | |
| 142 | + "postValidators": { | |
| 143 | + "@id": "edc:postValidators", | |
| 144 | + "@container": "@set" | |
| 145 | + }, | |
| 146 | + "permissionSteps": { | |
| 147 | + "@id": "edc:permissionSteps", | |
| 148 | + "@container": "@set" | |
| 149 | + }, | |
| 150 | + "prohibitionSteps": { | |
| 151 | + "@id": "edc:prohibitionSteps", | |
| 152 | + "@container": "@set" | |
| 153 | + }, | |
| 154 | + "obligationSteps": { | |
| 155 | + "@id": "edc:obligationSteps", | |
| 156 | + "@container": "@set" | |
| 157 | + }, | |
| 158 | + "constraintSteps": { | |
| 159 | + "@id": "edc:constraintSteps", | |
| 160 | + "@container": "@set" | |
| 161 | + }, | |
| 162 | + "filteringReasons": { | |
| 163 | + "@id": "edc:filteringReasons", | |
| 164 | + "@container": "@set" | |
| 165 | + }, | |
| 166 | + "isFiltered": "edc:isFiltered", | |
| 167 | + "functionName": "edc:functionName", | |
| 168 | + "functionParams": { | |
| 169 | + "@id": "edc:functionParams", | |
| 170 | + "@container": "@set" | |
| 171 | + }, | |
| 172 | + "dutySteps": { | |
| 173 | + "@id": "edc:dutySteps", | |
| 174 | + "@container": "@set" | |
| 175 | + }, | |
| 176 | + "ruleFunctions": { | |
| 177 | + "@id": "edc:ruleFunctions", | |
| 178 | + "@container": "@set" | |
| 179 | + } | |
| 180 | + } | |
| 181 | +} | |
| No newline at the end of the file |
modified extensions/data-plane/data-plane-signaling/data-plane-signaling-client/src/main/java/org/eclipse/edc/connector/dataplane/client/DataPlaneSignalingClientExtension.java +2 −2
| @@ -69,10 +69,10 @@ | ||
| 69 | 69 | context.getMonitor().debug(() -> "Using embedded Data Plane client."); |
| 70 | 70 | return instance -> new EmbeddedDataPlaneClient(dataPlaneManager); |
| 71 | 71 | } |
| 72 | - | |
| 72 | + | |
| 73 | 73 | jsonLd.registerNamespace(ODRL_PREFIX, ODRL_SCHEMA, CONTROL_CLIENT_SCOPE); |
| 74 | 74 | jsonLd.registerNamespace(DSPACE_PREFIX, DSPACE_SCHEMA, CONTROL_CLIENT_SCOPE); |
| 75 | - jsonLd.registerNamespace(VOCAB, EDC_NAMESPACE); | |
| 75 | + jsonLd.registerNamespace(VOCAB, EDC_NAMESPACE, CONTROL_CLIENT_SCOPE); | |
| 76 | 76 | |
| 77 | 77 | var mapper = typeManager.getMapper(JSON_LD); |
| 78 | 78 | context.getMonitor().debug(() -> "Using remote Data Plane client."); |
modified extensions/data-plane/data-plane-signaling/data-plane-signaling-client/src/test/java/org/eclipse/edc/connector/dataplane/client/DataPlaneSignalingClientExtensionTest.java +1 −1
| @@ -49,7 +49,7 @@ | ||
| 49 | 49 | assertThat(client).isInstanceOf(DataPlaneSignalingClient.class); |
| 50 | 50 | verify(jsonLd).registerNamespace(ODRL_PREFIX, ODRL_SCHEMA, CONTROL_CLIENT_SCOPE); |
| 51 | 51 | verify(jsonLd).registerNamespace(DSPACE_PREFIX, DSPACE_SCHEMA, CONTROL_CLIENT_SCOPE); |
| 52 | - verify(jsonLd).registerNamespace(VOCAB, EDC_NAMESPACE); | |
| 52 | + verify(jsonLd).registerNamespace(VOCAB, EDC_NAMESPACE, CONTROL_CLIENT_SCOPE); | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | @Test |
modified settings.gradle.kts +0 −1
| @@ -159,7 +159,6 @@ | ||
| 159 | 159 | |
| 160 | 160 | include(":extensions:common:api:control-api-configuration") |
| 161 | 161 | include(":extensions:common:api:management-api-configuration") |
| 162 | -include(":extensions:common:api:management-api-json-ld-context") | |
| 163 | 162 | |
| 164 | 163 | |
| 165 | 164 | include(":extensions:control-plane:api:control-plane-api") |
modified spi/common/core-spi/src/main/java/org/eclipse/edc/spi/constants/CoreConstants.java +1 −0
| @@ -18,4 +18,5 @@ | ||
| 18 | 18 | String JSON_LD = "json-ld"; |
| 19 | 19 | String EDC_PREFIX = "edc"; |
| 20 | 20 | String EDC_NAMESPACE = "https://w3id.org/edc/v0.0.1/ns/"; |
| 21 | + String EDC_CONNECTOR_MANAGEMENT_CONTEXT = "https://w3id.org/edc/connector/management/v0.0.1"; | |
| 21 | 22 | } |
modified system-tests/management-api/management-api-test-runner/build.gradle.kts +8 −0
| @@ -24,6 +24,7 @@ | ||
| 24 | 24 | testImplementation(project(":spi:control-plane:contract-spi")) |
| 25 | 25 | testImplementation(project(":spi:data-plane-selector:data-plane-selector-spi")) |
| 26 | 26 | testImplementation(project(":core:common:connector-core")) |
| 27 | + testImplementation(project(":core:common:edr-store-core")) | |
| 27 | 28 | |
| 28 | 29 | //useful for generic DTOs etc. |
| 29 | 30 | testImplementation(project(":extensions:common:api:api-core")) |
| @@ -42,6 +43,13 @@ | ||
| 42 | 43 | testImplementation(project(":extensions:common:transaction:transaction-local")) |
| 43 | 44 | testImplementation(libs.testcontainers.junit) |
| 44 | 45 | testImplementation(libs.testcontainers.postgres) |
| 46 | + | |
| 47 | + testImplementation(project(":extensions:control-plane:api:management-api:contract-definition-api")) | |
| 48 | + testImplementation(project(":extensions:control-plane:api:management-api:contract-negotiation-api")) | |
| 49 | + testImplementation(project(":extensions:control-plane:api:management-api:policy-definition-api")) | |
| 50 | + testImplementation(project(":extensions:control-plane:api:management-api:transfer-process-api")) | |
| 51 | + testImplementation(project(":extensions:control-plane:api:management-api:secrets-api")) | |
| 52 | + testImplementation(project(":extensions:control-plane:api:management-api:edr-cache-api")) | |
| 45 | 53 | } |
| 46 | 54 | |
| 47 | 55 | edcBuild { |
added system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/SerdeEndToEndTest.java +485 −0
| @@ -0,0 +1,485 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 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 | + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.test.e2e.managementapi; | |
| 16 | + | |
| 17 | +import jakarta.json.Json; | |
| 18 | +import jakarta.json.JsonObject; | |
| 19 | +import jakarta.json.JsonString; | |
| 20 | +import jakarta.json.JsonValue; | |
| 21 | +import org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.model.NegotiationState; | |
| 22 | +import org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyEvaluationPlanRequest; | |
| 23 | +import org.eclipse.edc.connector.controlplane.api.management.policy.model.PolicyValidationResult; | |
| 24 | +import org.eclipse.edc.connector.controlplane.api.management.transferprocess.model.SuspendTransfer; | |
| 25 | +import org.eclipse.edc.connector.controlplane.api.management.transferprocess.model.TerminateTransfer; | |
| 26 | +import org.eclipse.edc.connector.controlplane.api.management.transferprocess.model.TransferState; | |
| 27 | +import org.eclipse.edc.connector.controlplane.asset.spi.domain.Asset; | |
| 28 | +import org.eclipse.edc.connector.controlplane.contract.spi.types.command.TerminateNegotiationCommand; | |
| 29 | +import org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractRequest; | |
| 30 | +import org.eclipse.edc.connector.controlplane.contract.spi.types.offer.ContractDefinition; | |
| 31 | +import org.eclipse.edc.connector.controlplane.policy.spi.PolicyDefinition; | |
| 32 | +import org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcessStates; | |
| 33 | +import org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferRequest; | |
| 34 | +import org.eclipse.edc.jsonld.spi.JsonLd; | |
| 35 | +import org.eclipse.edc.junit.annotations.EndToEndTest; | |
| 36 | +import org.eclipse.edc.junit.extensions.EmbeddedRuntime; | |
| 37 | +import org.eclipse.edc.junit.extensions.RuntimeExtension; | |
| 38 | +import org.eclipse.edc.policy.model.AndConstraint; | |
| 39 | +import org.eclipse.edc.policy.model.AtomicConstraint; | |
| 40 | +import org.eclipse.edc.policy.model.LiteralExpression; | |
| 41 | +import org.eclipse.edc.policy.model.Operator; | |
| 42 | +import org.eclipse.edc.spi.query.QuerySpec; | |
| 43 | +import org.eclipse.edc.spi.types.domain.DataAddress; | |
| 44 | +import org.eclipse.edc.spi.types.domain.secret.Secret; | |
| 45 | +import org.eclipse.edc.transform.spi.TypeTransformerRegistry; | |
| 46 | +import org.junit.jupiter.api.Test; | |
| 47 | +import org.junit.jupiter.api.extension.ExtensionContext; | |
| 48 | +import org.junit.jupiter.api.extension.RegisterExtension; | |
| 49 | +import org.junit.jupiter.params.ParameterizedTest; | |
| 50 | +import org.junit.jupiter.params.provider.Arguments; | |
| 51 | +import org.junit.jupiter.params.provider.ArgumentsProvider; | |
| 52 | +import org.junit.jupiter.params.provider.ArgumentsSource; | |
| 53 | + | |
| 54 | +import java.util.HashMap; | |
| 55 | +import java.util.List; | |
| 56 | +import java.util.Optional; | |
| 57 | +import java.util.function.BiFunction; | |
| 58 | +import java.util.function.Consumer; | |
| 59 | +import java.util.function.Function; | |
| 60 | +import java.util.stream.Collectors; | |
| 61 | +import java.util.stream.Stream; | |
| 62 | + | |
| 63 | +import static jakarta.json.Json.createObjectBuilder; | |
| 64 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 65 | +import static org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractNegotiationStates.REQUESTED; | |
| 66 | +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; | |
| 67 | +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; | |
| 68 | +import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; | |
| 69 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE; | |
| 70 | +import static org.eclipse.edc.test.e2e.managementapi.TestFunctions.MANAGEMENT_API_CONTEXT; | |
| 71 | +import static org.eclipse.edc.test.e2e.managementapi.TestFunctions.MANAGEMENT_API_SCOPE; | |
| 72 | +import static org.eclipse.edc.test.e2e.managementapi.TestFunctions.assetObject; | |
| 73 | +import static org.eclipse.edc.test.e2e.managementapi.TestFunctions.contractDefinitionObject; | |
| 74 | +import static org.eclipse.edc.test.e2e.managementapi.TestFunctions.contractRequestObject; | |
| 75 | +import static org.eclipse.edc.test.e2e.managementapi.TestFunctions.createContractAgreement; | |
| 76 | +import static org.eclipse.edc.test.e2e.managementapi.TestFunctions.createContractNegotiation; | |
| 77 | +import static org.eclipse.edc.test.e2e.managementapi.TestFunctions.createEdrEntry; | |
| 78 | +import static org.eclipse.edc.test.e2e.managementapi.TestFunctions.createPolicyEvaluationPlan; | |
| 79 | +import static org.eclipse.edc.test.e2e.managementapi.TestFunctions.createTransferProcess; | |
| 80 | +import static org.eclipse.edc.test.e2e.managementapi.TestFunctions.dataAddressObject; | |
| 81 | +import static org.eclipse.edc.test.e2e.managementapi.TestFunctions.inForceDatePermission; | |
| 82 | +import static org.eclipse.edc.test.e2e.managementapi.TestFunctions.policyDefinitionObject; | |
| 83 | +import static org.eclipse.edc.test.e2e.managementapi.TestFunctions.policyEvaluationPlanRequest; | |
| 84 | +import static org.eclipse.edc.test.e2e.managementapi.TestFunctions.querySpecObject; | |
| 85 | +import static org.eclipse.edc.test.e2e.managementapi.TestFunctions.secretObject; | |
| 86 | +import static org.eclipse.edc.test.e2e.managementapi.TestFunctions.suspendTransferObject; | |
| 87 | +import static org.eclipse.edc.test.e2e.managementapi.TestFunctions.terminateNegotiationObject; | |
| 88 | +import static org.eclipse.edc.test.e2e.managementapi.TestFunctions.terminateTransferObject; | |
| 89 | +import static org.eclipse.edc.test.e2e.managementapi.TestFunctions.transferRequestObject; | |
| 90 | +import static org.eclipse.edc.util.io.Ports.getFreePort; | |
| 91 | + | |
| 92 | +@EndToEndTest | |
| 93 | +public class SerdeEndToEndTest { | |
| 94 | + | |
| 95 | + @RegisterExtension | |
| 96 | + private static final RuntimeExtension RUNTIME = new SerdeRuntime(); | |
| 97 | + | |
| 98 | + @Test | |
| 99 | + void ser_ContractAgreement() { | |
| 100 | + var agreement = createContractAgreement("test-id"); | |
| 101 | + var compactResult = serialize(agreement); | |
| 102 | + | |
| 103 | + assertThat(compactResult).isNotNull(); | |
| 104 | + assertThat(compactResult.getString(ID)).isEqualTo(agreement.getId()); | |
| 105 | + assertThat(compactResult.getString(TYPE)).isEqualTo("ContractAgreement"); | |
| 106 | + assertThat(compactResult.getString("providerId")).isEqualTo(agreement.getProviderId()); | |
| 107 | + assertThat(compactResult.getString("consumerId")).isEqualTo(agreement.getConsumerId()); | |
| 108 | + assertThat(compactResult.getString("assetId")).isEqualTo(agreement.getAssetId()); | |
| 109 | + assertThat(compactResult.getJsonObject("policy")).isNotNull(); | |
| 110 | + assertThat(compactResult.getJsonNumber("contractSigningDate")).isNotNull(); | |
| 111 | + | |
| 112 | + } | |
| 113 | + | |
| 114 | + @Test | |
| 115 | + void ser_ContractNegotiation() { | |
| 116 | + var negotiation = createContractNegotiation(); | |
| 117 | + var compactResult = serialize(negotiation); | |
| 118 | + | |
| 119 | + assertThat(compactResult).isNotNull(); | |
| 120 | + assertThat(compactResult.getString(ID)).isEqualTo("test-id"); | |
| 121 | + assertThat(compactResult.getString("state")).isEqualTo(REQUESTED.name()); | |
| 122 | + assertThat(compactResult.getString("counterPartyId")).isEqualTo(negotiation.getCounterPartyId()); | |
| 123 | + assertThat(compactResult.getString("counterPartyAddress")).isEqualTo(negotiation.getCounterPartyAddress()); | |
| 124 | + assertThat(compactResult.getString("contractAgreementId")).isEqualTo(negotiation.getContractAgreement().getId()); | |
| 125 | + assertThat(compactResult.getString("errorDetail")).isEqualTo(negotiation.getErrorDetail()); | |
| 126 | + assertThat(compactResult.getString("type")).isEqualTo(negotiation.getType().toString()); | |
| 127 | + assertThat(compactResult.getString("protocol")).isEqualTo(negotiation.getProtocol()); | |
| 128 | + assertThat(compactResult.getJsonArray("callbackAddresses")).isNotEmpty().first().satisfies(callback -> { | |
| 129 | + var firstCallback = negotiation.getCallbackAddresses().get(0); | |
| 130 | + var cb = callback.asJsonObject(); | |
| 131 | + assertThat(cb.getString("uri")).isEqualTo(firstCallback.getUri()); | |
| 132 | + assertThat(cb.getBoolean("transactional")).isEqualTo(firstCallback.isTransactional()); | |
| 133 | + | |
| 134 | + var events = cb.getJsonArray("events").stream().map(event -> ((JsonString) event).getString()).collect(Collectors.toSet()); | |
| 135 | + assertThat(events).containsAll(firstCallback.getEvents()); | |
| 136 | + }); | |
| 137 | + assertThat(compactResult.getJsonNumber("createdAt").longValue()).isEqualTo(1234); | |
| 138 | + | |
| 139 | + } | |
| 140 | + | |
| 141 | + @Test | |
| 142 | + void ser_TransferProcess() { | |
| 143 | + var transferProcess = createTransferProcess(); | |
| 144 | + var compactResult = serialize(transferProcess); | |
| 145 | + | |
| 146 | + assertThat(compactResult).isNotNull(); | |
| 147 | + assertThat(compactResult.getString(ID)).isEqualTo(transferProcess.getId()); | |
| 148 | + assertThat(compactResult.getString(TYPE)).isEqualTo("TransferProcess"); | |
| 149 | + assertThat(compactResult.getString("correlationId")).isEqualTo(transferProcess.getCorrelationId()); | |
| 150 | + assertThat(compactResult.getString("state")).isEqualTo(transferProcess.stateAsString()); | |
| 151 | + assertThat(compactResult.getJsonNumber("stateTimestamp").longValue()).isEqualTo(transferProcess.getStateTimestamp()); | |
| 152 | + assertThat(compactResult.getString("assetId")).isEqualTo(transferProcess.getAssetId()); | |
| 153 | + assertThat(compactResult.getString("contractId")).isEqualTo(transferProcess.getContractId()); | |
| 154 | + assertThat(compactResult.getString("type")).isEqualTo(transferProcess.getType().toString()); | |
| 155 | + assertThat(compactResult.getJsonObject("dataDestination")).isNotNull(); | |
| 156 | + assertThat(compactResult.getJsonArray("callbackAddresses")).hasSize(transferProcess.getCallbackAddresses().size()); | |
| 157 | + assertThat(compactResult.getString("errorDetail")).isEqualTo(transferProcess.getErrorDetail()); | |
| 158 | + } | |
| 159 | + | |
| 160 | + @Test | |
| 161 | + void ser_EndpointDataReferenceEntry() { | |
| 162 | + var transferProcess = createEdrEntry(); | |
| 163 | + var compactResult = serialize(transferProcess); | |
| 164 | + | |
| 165 | + assertThat(compactResult).isNotNull(); | |
| 166 | + assertThat(compactResult.getString(ID)).isEqualTo(transferProcess.getId()); | |
| 167 | + assertThat(compactResult.getString(TYPE)).isEqualTo("EndpointDataReferenceEntry"); | |
| 168 | + assertThat(compactResult.getString("transferProcessId")).isEqualTo(transferProcess.getTransferProcessId()); | |
| 169 | + assertThat(compactResult.getString("contractNegotiationId")).isEqualTo(transferProcess.getContractNegotiationId()); | |
| 170 | + assertThat(compactResult.getString("assetId")).isEqualTo(transferProcess.getAssetId()); | |
| 171 | + assertThat(compactResult.getString("providerId")).isEqualTo(transferProcess.getProviderId()); | |
| 172 | + assertThat(compactResult.getString("agreementId")).isEqualTo(transferProcess.getAgreementId()); | |
| 173 | + } | |
| 174 | + | |
| 175 | + @Test | |
| 176 | + void ser_NegotiationState() { | |
| 177 | + var state = new NegotiationState(TransferProcessStates.REQUESTED.name()); | |
| 178 | + var compactResult = serialize(state); | |
| 179 | + | |
| 180 | + assertThat(compactResult).isNotNull(); | |
| 181 | + assertThat(compactResult.getString(TYPE)).isEqualTo("NegotiationState"); | |
| 182 | + assertThat(compactResult.getString("state")).isEqualTo(TransferProcessStates.REQUESTED.name()); | |
| 183 | + | |
| 184 | + } | |
| 185 | + | |
| 186 | + @Test | |
| 187 | + void ser_TransferState() { | |
| 188 | + var state = new TransferState(REQUESTED.name()); | |
| 189 | + var compactResult = serialize(state); | |
| 190 | + | |
| 191 | + assertThat(compactResult).isNotNull(); | |
| 192 | + assertThat(compactResult.getString(TYPE)).isEqualTo("TransferState"); | |
| 193 | + assertThat(compactResult.getString("state")).isEqualTo(REQUESTED.name()); | |
| 194 | + | |
| 195 | + } | |
| 196 | + | |
| 197 | + @Test | |
| 198 | + void ser_PolicyValidationResult() { | |
| 199 | + var result = new PolicyValidationResult(false, List.of("error1", "error2")); | |
| 200 | + var compactResult = serialize(result); | |
| 201 | + | |
| 202 | + assertThat(compactResult).isNotNull(); | |
| 203 | + assertThat(compactResult.getString(TYPE)).isEqualTo("PolicyValidationResult"); | |
| 204 | + assertThat(compactResult.getBoolean("isValid")).isEqualTo(false); | |
| 205 | + assertThat(compactResult.getJsonArray("errors")).contains(Json.createValue("error1"), Json.createValue("error2")); | |
| 206 | + | |
| 207 | + } | |
| 208 | + | |
| 209 | + @Test | |
| 210 | + void ser_PolicyEvaluationPlan() { | |
| 211 | + var plan = createPolicyEvaluationPlan(); | |
| 212 | + var compactResult = serialize(plan); | |
| 213 | + | |
| 214 | + assertThat(compactResult).isNotNull(); | |
| 215 | + assertThat(compactResult.getString(TYPE)).isEqualTo("PolicyEvaluationPlan"); | |
| 216 | + assertThat(compactResult.getJsonArray("preValidators")).hasSize(1); | |
| 217 | + assertThat(compactResult.getJsonArray("postValidators")).hasSize(1); | |
| 218 | + | |
| 219 | + | |
| 220 | + BiFunction<String, String, Consumer<JsonValue>> ruleAsser = (ruleType, multiplicityType) -> (ruleValue) -> { | |
| 221 | + var rule = ruleValue.asJsonObject(); | |
| 222 | + assertThat(rule.getString(TYPE)).isEqualTo(ruleType); | |
| 223 | + assertThat(rule.getJsonArray("ruleFunctions")).hasSize(0); | |
| 224 | + assertThat(rule.getJsonArray("constraintSteps")).hasSize(1); | |
| 225 | + | |
| 226 | + var constraint = rule.getJsonArray("constraintSteps").get(0).asJsonObject(); | |
| 227 | + assertThat(constraint.getString(TYPE)).isEqualTo(multiplicityType); | |
| 228 | + assertThat(constraint.getJsonArray("constraintSteps")).hasSize(2) | |
| 229 | + .allSatisfy(value -> { | |
| 230 | + var atomicConstraint = value.asJsonObject(); | |
| 231 | + assertThat(atomicConstraint.getString(TYPE)).isEqualTo("AtomicConstraintStep"); | |
| 232 | + assertThat(atomicConstraint.getJsonArray("filteringReasons")).hasSize(1); | |
| 233 | + assertThat(atomicConstraint.getBoolean("isFiltered")).isTrue(); | |
| 234 | + assertThat(atomicConstraint.getString("functionName")).isEqualTo("AtomicConstraintFunction"); | |
| 235 | + assertThat(atomicConstraint.getJsonArray("functionParams")).hasSize(3); | |
| 236 | + }); | |
| 237 | + }; | |
| 238 | + | |
| 239 | + assertThat(compactResult.getJsonArray("permissionSteps")).hasSize(1) | |
| 240 | + .first() | |
| 241 | + .satisfies(ruleAsser.apply("PermissionStep", "OrConstraintStep")); | |
| 242 | + | |
| 243 | + assertThat(compactResult.getJsonArray("prohibitionSteps")).hasSize(1) | |
| 244 | + .first() | |
| 245 | + .satisfies(ruleAsser.apply("ProhibitionStep", "AndConstraintStep")); | |
| 246 | + | |
| 247 | + assertThat(compactResult.getJsonArray("obligationSteps")).hasSize(1) | |
| 248 | + .first() | |
| 249 | + .satisfies(ruleAsser.apply("DutyStep", "XoneConstraintStep")); | |
| 250 | + | |
| 251 | + } | |
| 252 | + | |
| 253 | + @Test | |
| 254 | + void de_ContractRequest() { | |
| 255 | + var inputObject = contractRequestObject(); | |
| 256 | + var request = deserialize(inputObject, ContractRequest.class); | |
| 257 | + | |
| 258 | + assertThat(request).isNotNull(); | |
| 259 | + assertThat(request.getProviderId()).isEqualTo(inputObject.getJsonObject("policy").getString("assigner")); | |
| 260 | + assertThat(request.getCallbackAddresses()).isNotEmpty(); | |
| 261 | + assertThat(request.getProtocol()).isEqualTo("test-protocol"); | |
| 262 | + assertThat(request.getCounterPartyAddress()).isEqualTo("test-address"); | |
| 263 | + assertThat(request.getContractOffer().getPolicy()).isNotNull(); | |
| 264 | + | |
| 265 | + } | |
| 266 | + | |
| 267 | + @Test | |
| 268 | + void de_TransferRequest() { | |
| 269 | + var inputObject = transferRequestObject(); | |
| 270 | + var transferRequest = deserialize(inputObject, TransferRequest.class); | |
| 271 | + | |
| 272 | + assertThat(transferRequest).isNotNull(); | |
| 273 | + assertThat(transferRequest.getId()).isEqualTo(inputObject.getString(ID)); | |
| 274 | + assertThat(transferRequest.getCounterPartyAddress()).isEqualTo(inputObject.getString("counterPartyAddress")); | |
| 275 | + assertThat(transferRequest.getContractId()).isEqualTo(inputObject.getString("contractId")); | |
| 276 | + assertThat(transferRequest.getDataDestination()).extracting(DataAddress::getType).isEqualTo(inputObject.getJsonObject("dataDestination").getString("type")); | |
| 277 | + assertThat(transferRequest.getPrivateProperties()).containsEntry(EDC_NAMESPACE + "fooPrivate", "bar"); | |
| 278 | + assertThat(transferRequest.getProtocol()).isEqualTo(inputObject.getString("protocol")); | |
| 279 | + assertThat(transferRequest.getCallbackAddresses()).hasSize(inputObject.getJsonArray("callbackAddresses").size()); | |
| 280 | + assertThat(transferRequest.getTransferType()).isEqualTo(inputObject.getString("transferType")); | |
| 281 | + } | |
| 282 | + | |
| 283 | + @Test | |
| 284 | + void de_TransferRequest_withoutDataAddressType() { | |
| 285 | + var dataDestination = createObjectBuilder() | |
| 286 | + .add("type", "type").build(); | |
| 287 | + | |
| 288 | + var inputObject = transferRequestObject(dataDestination); | |
| 289 | + var transferRequest = deserialize(inputObject, TransferRequest.class); | |
| 290 | + | |
| 291 | + assertThat(transferRequest).isNotNull(); | |
| 292 | + assertThat(transferRequest.getId()).isEqualTo(inputObject.getString(ID)); | |
| 293 | + assertThat(transferRequest.getCounterPartyAddress()).isEqualTo(inputObject.getString("counterPartyAddress")); | |
| 294 | + assertThat(transferRequest.getContractId()).isEqualTo(inputObject.getString("contractId")); | |
| 295 | + assertThat(transferRequest.getDataDestination()).extracting(DataAddress::getType).isEqualTo(inputObject.getJsonObject("dataDestination").getString("type")); | |
| 296 | + assertThat(transferRequest.getPrivateProperties()).containsEntry(EDC_NAMESPACE + "fooPrivate", "bar"); | |
| 297 | + assertThat(transferRequest.getProtocol()).isEqualTo(inputObject.getString("protocol")); | |
| 298 | + assertThat(transferRequest.getCallbackAddresses()).hasSize(inputObject.getJsonArray("callbackAddresses").size()); | |
| 299 | + assertThat(transferRequest.getTransferType()).isEqualTo(inputObject.getString("transferType")); | |
| 300 | + | |
| 301 | + } | |
| 302 | + | |
| 303 | + | |
| 304 | + @Test | |
| 305 | + void de_TerminateNegotiation() { | |
| 306 | + var inputObject = terminateNegotiationObject(); | |
| 307 | + var terminateNegotiation = deserialize(inputObject, TerminateNegotiationCommand.class); | |
| 308 | + | |
| 309 | + assertThat(terminateNegotiation).isNotNull(); | |
| 310 | + assertThat(terminateNegotiation.getReason()).isEqualTo(inputObject.getString("reason")); | |
| 311 | + } | |
| 312 | + | |
| 313 | + @Test | |
| 314 | + void de_TerminateTransfer() { | |
| 315 | + var inputObject = terminateTransferObject(); | |
| 316 | + var terminateTransfer = deserialize(inputObject, TerminateTransfer.class); | |
| 317 | + | |
| 318 | + assertThat(terminateTransfer).isNotNull(); | |
| 319 | + assertThat(terminateTransfer.reason()).isEqualTo(inputObject.getString("reason")); | |
| 320 | + | |
| 321 | + } | |
| 322 | + | |
| 323 | + @Test | |
| 324 | + void de_SuspendTransfer() { | |
| 325 | + var inputObject = suspendTransferObject(); | |
| 326 | + var terminateTransfer = deserialize(inputObject, SuspendTransfer.class); | |
| 327 | + | |
| 328 | + assertThat(terminateTransfer).isNotNull(); | |
| 329 | + assertThat(terminateTransfer.reason()).isEqualTo(inputObject.getString("reason")); | |
| 330 | + assertThat(terminateTransfer.reason()).isEqualTo(inputObject.getString("reason")); | |
| 331 | + | |
| 332 | + } | |
| 333 | + | |
| 334 | + @Test | |
| 335 | + void de_PolicyDefinition_withInForceDate() { | |
| 336 | + | |
| 337 | + var andConstraint = AndConstraint.Builder.newInstance() | |
| 338 | + .constraint(AtomicConstraint.Builder.newInstance() | |
| 339 | + .leftExpression(new LiteralExpression(EDC_NAMESPACE + "inForceDate")) | |
| 340 | + .operator(Operator.GEQ) | |
| 341 | + .rightExpression(new LiteralExpression("contractAgreement+0s")) | |
| 342 | + .build()) | |
| 343 | + .constraint(AtomicConstraint.Builder.newInstance() | |
| 344 | + .leftExpression(new LiteralExpression(EDC_NAMESPACE + "inForceDate")) | |
| 345 | + .operator(Operator.LEQ) | |
| 346 | + .rightExpression(new LiteralExpression("contractAgreement+10s")) | |
| 347 | + .build()) | |
| 348 | + .build(); | |
| 349 | + | |
| 350 | + var inputObject = policyDefinitionObject(inForceDatePermission("gteq", "contractAgreement+0s", "lteq", "contractAgreement+10s")); | |
| 351 | + | |
| 352 | + var terminateTransfer = deserialize(inputObject, PolicyDefinition.class); | |
| 353 | + | |
| 354 | + assertThat(terminateTransfer).isNotNull(); | |
| 355 | + assertThat(terminateTransfer.getPolicy().getPermissions().get(0).getConstraints()) | |
| 356 | + .usingRecursiveFieldByFieldElementComparator().containsOnly(andConstraint); | |
| 357 | + | |
| 358 | + } | |
| 359 | + | |
| 360 | + @Test | |
| 361 | + void de_PolicyEvaluationPlanRequest() { | |
| 362 | + var inputObject = policyEvaluationPlanRequest(); | |
| 363 | + var terminateTransfer = deserialize(inputObject, PolicyEvaluationPlanRequest.class); | |
| 364 | + | |
| 365 | + assertThat(terminateTransfer).isNotNull(); | |
| 366 | + assertThat(terminateTransfer.policyScope()).isEqualTo(inputObject.getString("policyScope")); | |
| 367 | + | |
| 368 | + } | |
| 369 | + | |
| 370 | + /** | |
| 371 | + * Tests for entities that supports transformation from/to JsonObject | |
| 372 | + */ | |
| 373 | + @ParameterizedTest(name = "{1}") | |
| 374 | + @ArgumentsSource(JsonInputProvider.class) | |
| 375 | + void serde(JsonObject inputObject, Class<?> klass, Function<JsonObject, JsonObject> mapper) { | |
| 376 | + var typeTransformerRegistry = RUNTIME.getService(TypeTransformerRegistry.class); | |
| 377 | + var jsonLd = RUNTIME.getService(JsonLd.class); | |
| 378 | + var registry = typeTransformerRegistry.forContext(MANAGEMENT_API_CONTEXT); | |
| 379 | + | |
| 380 | + // Expand the input | |
| 381 | + var expanded = jsonLd.expand(inputObject).orElseThrow(f -> new AssertionError(f.getFailureDetail())); | |
| 382 | + | |
| 383 | + // transform the expanded into the input klass type | |
| 384 | + var result = registry.transform(expanded, klass).orElseThrow(failure -> new RuntimeException()); | |
| 385 | + // transform the klass type instance into JsonObject | |
| 386 | + var object = registry.transform(result, JsonObject.class).orElseThrow(failure -> new RuntimeException()); | |
| 387 | + | |
| 388 | + // Compact the result | |
| 389 | + var compactResult = jsonLd.compact(object, MANAGEMENT_API_SCOPE); | |
| 390 | + | |
| 391 | + // checks that the compacted == inputObject | |
| 392 | + assertThat(compactResult).isSucceeded().satisfies(compacted -> { | |
| 393 | + var mapped = Optional.ofNullable(mapper).map(m -> m.apply(compacted)).orElse(compacted); | |
| 394 | + assertThat(mapped).isEqualTo(inputObject); | |
| 395 | + }); | |
| 396 | + } | |
| 397 | + | |
| 398 | + private JsonObject serialize(Object object) { | |
| 399 | + var typeTransformerRegistry = RUNTIME.getService(TypeTransformerRegistry.class); | |
| 400 | + var registry = typeTransformerRegistry.forContext(MANAGEMENT_API_CONTEXT); | |
| 401 | + var jsonLd = RUNTIME.getService(JsonLd.class); | |
| 402 | + | |
| 403 | + var result = registry.transform(object, JsonObject.class).orElseThrow(failure -> new RuntimeException()); | |
| 404 | + return jsonLd.compact(result, MANAGEMENT_API_SCOPE).orElseThrow(failure -> new RuntimeException(failure.getFailureDetail())); | |
| 405 | + } | |
| 406 | + | |
| 407 | + private <T> T deserialize(JsonObject inputObject, Class<T> klass) { | |
| 408 | + var typeTransformerRegistry = RUNTIME.getService(TypeTransformerRegistry.class); | |
| 409 | + var registry = typeTransformerRegistry.forContext(MANAGEMENT_API_CONTEXT); | |
| 410 | + var jsonLd = RUNTIME.getService(JsonLd.class); | |
| 411 | + | |
| 412 | + var expanded = jsonLd.expand(inputObject).orElseThrow(f -> new AssertionError(f.getFailureDetail())); | |
| 413 | + | |
| 414 | + | |
| 415 | + // checks that the type is correctly expanded to the EDC namespace | |
| 416 | + assertThat(expanded.getJsonArray(TYPE)).first().satisfies(t -> { | |
| 417 | + assertThat(((JsonString) t).getString()).startsWith(EDC_NAMESPACE); | |
| 418 | + }); | |
| 419 | + | |
| 420 | + return registry.transform(expanded, klass).orElseThrow(failure -> new RuntimeException()); | |
| 421 | + } | |
| 422 | + | |
| 423 | + private static class JsonInputProvider implements ArgumentsProvider { | |
| 424 | + @Override | |
| 425 | + public Stream<? extends Arguments> provideArguments(ExtensionContext context) { | |
| 426 | + | |
| 427 | + Function<JsonObject, JsonObject> mapper = this::policyMapper; | |
| 428 | + | |
| 429 | + return Stream.of( | |
| 430 | + Arguments.of(assetObject(), Asset.class, null), | |
| 431 | + Arguments.of(contractDefinitionObject(), ContractDefinition.class, null), | |
| 432 | + Arguments.of(secretObject(), Secret.class, null), | |
| 433 | + Arguments.of(querySpecObject(), QuerySpec.class, null), | |
| 434 | + Arguments.of(policyDefinitionObject(), PolicyDefinition.class, mapper), | |
| 435 | + Arguments.of(dataAddressObject(), DataAddress.class, null) | |
| 436 | + ); | |
| 437 | + } | |
| 438 | + | |
| 439 | + private JsonObject policyMapper(JsonObject compacted) { | |
| 440 | + var policy = compacted.getJsonObject("policy"); | |
| 441 | + var newPolicy = Json.createObjectBuilder(policy); | |
| 442 | + newPolicy.remove("@id"); | |
| 443 | + var newDefinition = Json.createObjectBuilder(compacted); | |
| 444 | + newDefinition.remove("createdAt"); | |
| 445 | + newDefinition.add("policy", newPolicy); | |
| 446 | + | |
| 447 | + return newDefinition.build(); | |
| 448 | + } | |
| 449 | + } | |
| 450 | + | |
| 451 | + | |
| 452 | + static class SerdeRuntime extends ManagementEndToEndExtension { | |
| 453 | + | |
| 454 | + protected SerdeRuntime() { | |
| 455 | + super(context()); | |
| 456 | + } | |
| 457 | + | |
| 458 | + private static ManagementEndToEndTestContext context() { | |
| 459 | + var managementPort = getFreePort(); | |
| 460 | + var protocolPort = getFreePort(); | |
| 461 | + | |
| 462 | + var runtime = new EmbeddedRuntime( | |
| 463 | + "control-plane", | |
| 464 | + new HashMap<>() { | |
| 465 | + { | |
| 466 | + put("web.http.path", "/"); | |
| 467 | + put("web.http.port", String.valueOf(getFreePort())); | |
| 468 | + put("web.http.protocol.path", "/protocol"); | |
| 469 | + put("web.http.protocol.port", String.valueOf(protocolPort)); | |
| 470 | + put("web.http.control.port", String.valueOf(getFreePort())); | |
| 471 | + put("edc.dsp.callback.address", "http://localhost:" + protocolPort + "/protocol"); | |
| 472 | + put("web.http.management.path", "/management"); | |
| 473 | + put("web.http.management.port", String.valueOf(managementPort)); | |
| 474 | + put("edc.management.context.enabled", "true"); | |
| 475 | + } | |
| 476 | + }, | |
| 477 | + ":system-tests:management-api:management-api-test-runtime" | |
| 478 | + ); | |
| 479 | + | |
| 480 | + return new ManagementEndToEndTestContext(runtime, managementPort, protocolPort); | |
| 481 | + } | |
| 482 | + | |
| 483 | + } | |
| 484 | + | |
| 485 | +} |
added system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/TestFunctions.java +396 −0
| @@ -0,0 +1,396 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | |
| 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 | + * Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | |
| 12 | + * | |
| 13 | + */ | |
| 14 | + | |
| 15 | +package org.eclipse.edc.test.e2e.managementapi; | |
| 16 | + | |
| 17 | +import jakarta.json.Json; | |
| 18 | +import jakarta.json.JsonArrayBuilder; | |
| 19 | +import jakarta.json.JsonObject; | |
| 20 | +import jakarta.json.JsonObjectBuilder; | |
| 21 | +import org.eclipse.edc.connector.controlplane.contract.spi.types.agreement.ContractAgreement; | |
| 22 | +import org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractNegotiation; | |
| 23 | +import org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcess; | |
| 24 | +import org.eclipse.edc.edr.spi.types.EndpointDataReferenceEntry; | |
| 25 | +import org.eclipse.edc.policy.engine.spi.AtomicConstraintFunction; | |
| 26 | +import org.eclipse.edc.policy.engine.spi.PolicyValidatorFunction; | |
| 27 | +import org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan; | |
| 28 | +import org.eclipse.edc.policy.engine.spi.plan.step.AndConstraintStep; | |
| 29 | +import org.eclipse.edc.policy.engine.spi.plan.step.AtomicConstraintStep; | |
| 30 | +import org.eclipse.edc.policy.engine.spi.plan.step.ConstraintStep; | |
| 31 | +import org.eclipse.edc.policy.engine.spi.plan.step.DutyStep; | |
| 32 | +import org.eclipse.edc.policy.engine.spi.plan.step.OrConstraintStep; | |
| 33 | +import org.eclipse.edc.policy.engine.spi.plan.step.PermissionStep; | |
| 34 | +import org.eclipse.edc.policy.engine.spi.plan.step.ProhibitionStep; | |
| 35 | +import org.eclipse.edc.policy.engine.spi.plan.step.ValidatorStep; | |
| 36 | +import org.eclipse.edc.policy.engine.spi.plan.step.XoneConstraintStep; | |
| 37 | +import org.eclipse.edc.policy.model.AtomicConstraint; | |
| 38 | +import org.eclipse.edc.policy.model.LiteralExpression; | |
| 39 | +import org.eclipse.edc.policy.model.Policy; | |
| 40 | +import org.eclipse.edc.policy.model.Rule; | |
| 41 | +import org.eclipse.edc.spi.types.domain.DataAddress; | |
| 42 | +import org.eclipse.edc.spi.types.domain.callback.CallbackAddress; | |
| 43 | + | |
| 44 | +import java.time.Clock; | |
| 45 | +import java.util.List; | |
| 46 | +import java.util.Map; | |
| 47 | +import java.util.Set; | |
| 48 | + | |
| 49 | +import static jakarta.json.Json.createArrayBuilder; | |
| 50 | +import static jakarta.json.Json.createObjectBuilder; | |
| 51 | +import static java.util.Collections.emptySet; | |
| 52 | +import static org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractNegotiationStates.REQUESTED; | |
| 53 | +import static org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcess.Type.CONSUMER; | |
| 54 | +import static org.eclipse.edc.connector.controlplane.transfer.spi.types.TransferProcessStates.STARTED; | |
| 55 | +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.CONTEXT; | |
| 56 | +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; | |
| 57 | +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; | |
| 58 | +import static org.eclipse.edc.policy.model.Operator.EQ; | |
| 59 | +import static org.eclipse.edc.spi.constants.CoreConstants.EDC_CONNECTOR_MANAGEMENT_CONTEXT; | |
| 60 | +import static org.eclipse.edc.spi.types.domain.callback.CallbackAddress.EVENTS; | |
| 61 | +import static org.eclipse.edc.spi.types.domain.callback.CallbackAddress.IS_TRANSACTIONAL; | |
| 62 | +import static org.eclipse.edc.spi.types.domain.callback.CallbackAddress.URI; | |
| 63 | +import static org.mockito.Mockito.mock; | |
| 64 | +import static org.mockito.Mockito.when; | |
| 65 | + | |
| 66 | +public class TestFunctions { | |
| 67 | + | |
| 68 | + public static final String TEST_ASSET_ID = "some-asset-id"; | |
| 69 | + public static final String TEST_ASSET_NAME = "some-asset-name"; | |
| 70 | + public static final String TEST_ASSET_DESCRIPTION = "some description"; | |
| 71 | + public static final String TEST_ASSET_CONTENTTYPE = "application/json"; | |
| 72 | + public static final String TEST_ASSET_VERSION = "0.2.1"; | |
| 73 | + public static final String MANAGEMENT_API_SCOPE = "MANAGEMENT_API"; | |
| 74 | + public static final String MANAGEMENT_API_CONTEXT = "management-api"; | |
| 75 | + private static final String DEFINITION_ID = "some-definition-id"; | |
| 76 | + private static final String POLICY_ID = "some-policy-id"; | |
| 77 | + | |
| 78 | + public static JsonArrayBuilder createContextBuilder() { | |
| 79 | + return createArrayBuilder() | |
| 80 | + .add(EDC_CONNECTOR_MANAGEMENT_CONTEXT); | |
| 81 | + } | |
| 82 | + | |
| 83 | + public static JsonObject assetObject() { | |
| 84 | + return createObjectBuilder() | |
| 85 | + .add(CONTEXT, createContextBuilder().build()) | |
| 86 | + .add(TYPE, "Asset") | |
| 87 | + .add(ID, TEST_ASSET_ID) | |
| 88 | + .add("properties", createObjectBuilder() | |
| 89 | + .add("name", TEST_ASSET_NAME) | |
| 90 | + .add("id", TEST_ASSET_ID) | |
| 91 | + .add("description", TEST_ASSET_DESCRIPTION) | |
| 92 | + .add("version", TEST_ASSET_VERSION) | |
| 93 | + .add("contenttype", TEST_ASSET_CONTENTTYPE) | |
| 94 | + .build()) | |
| 95 | + .add("dataAddress", createObjectBuilder().add("@type", "DataAddress").add("type", "address-type")) | |
| 96 | + .build(); | |
| 97 | + } | |
| 98 | + | |
| 99 | + public static JsonObject dataAddressObject() { | |
| 100 | + return createObjectBuilder() | |
| 101 | + .add(CONTEXT, createContextBuilder().build()) | |
| 102 | + .add(TYPE, "DataAddress") | |
| 103 | + .add("type", "address-type") | |
| 104 | + .add("propertyOne", "foo") | |
| 105 | + .add("propertyTwo", "bar") | |
| 106 | + .build(); | |
| 107 | + } | |
| 108 | + | |
| 109 | + public static JsonObject contractDefinitionObject() { | |
| 110 | + var criterion = Json.createObjectBuilder() | |
| 111 | + .add(TYPE, "Criterion") | |
| 112 | + .add("operandLeft", "foo") | |
| 113 | + .add("operator", "=") | |
| 114 | + .add("operandRight", "bar") | |
| 115 | + .build(); | |
| 116 | + | |
| 117 | + var assetsSelectorJson = createArrayBuilder() | |
| 118 | + .add(criterion) | |
| 119 | + .build(); | |
| 120 | + | |
| 121 | + return createObjectBuilder() | |
| 122 | + .add(CONTEXT, createContextBuilder().build()) | |
| 123 | + .add(TYPE, "ContractDefinition") | |
| 124 | + .add(ID, DEFINITION_ID) | |
| 125 | + .add("accessPolicyId", "accessPolicyId") | |
| 126 | + .add("contractPolicyId", "contractPolicyId") | |
| 127 | + .add("assetsSelector", assetsSelectorJson) | |
| 128 | + .build(); | |
| 129 | + | |
| 130 | + } | |
| 131 | + | |
| 132 | + public static JsonObject terminateNegotiationObject() { | |
| 133 | + return Json.createObjectBuilder() | |
| 134 | + .add(CONTEXT, createContextBuilder().build()) | |
| 135 | + .add(TYPE, "TerminateNegotiation") | |
| 136 | + .add("reason", "reason") | |
| 137 | + .build(); | |
| 138 | + } | |
| 139 | + | |
| 140 | + public static JsonObject terminateTransferObject() { | |
| 141 | + return Json.createObjectBuilder() | |
| 142 | + .add(CONTEXT, createContextBuilder().build()) | |
| 143 | + .add(TYPE, "TerminateTransfer") | |
| 144 | + .add("reason", "reason") | |
| 145 | + .build(); | |
| 146 | + } | |
| 147 | + | |
| 148 | + public static JsonObject suspendTransferObject() { | |
| 149 | + return Json.createObjectBuilder() | |
| 150 | + .add(CONTEXT, createContextBuilder().build()) | |
| 151 | + .add(TYPE, "SuspendTransfer") | |
| 152 | + .add("reason", "reason") | |
| 153 | + .build(); | |
| 154 | + } | |
| 155 | + | |
| 156 | + public static JsonObject contractRequestObject() { | |
| 157 | + var policy = policy(atomicConstraint("spatial", "eq", "https://www.wikidata.org/wiki/Q183")) | |
| 158 | + .add(ID, "id") | |
| 159 | + .add("assigner", "provider") | |
| 160 | + .build(); | |
| 161 | + return Json.createObjectBuilder() | |
| 162 | + .add(CONTEXT, createContextBuilder().build()) | |
| 163 | + .add(TYPE, "ContractRequest") | |
| 164 | + .add("counterPartyAddress", "test-address") | |
| 165 | + .add("protocol", "test-protocol") | |
| 166 | + .add("callbackAddresses", createCallbackAddress()) | |
| 167 | + .add("policy", policy) | |
| 168 | + .build(); | |
| 169 | + } | |
| 170 | + | |
| 171 | + public static JsonObject transferRequestObject() { | |
| 172 | + var dataDestination = createObjectBuilder() | |
| 173 | + .add(TYPE, "DataAddress") | |
| 174 | + .add("type", "type").build(); | |
| 175 | + | |
| 176 | + return transferRequestObject(dataDestination); | |
| 177 | + } | |
| 178 | + | |
| 179 | + public static JsonObject transferRequestObject(JsonObject dataDestination) { | |
| 180 | + var propertiesJson = Json.createObjectBuilder().add("foo", "bar").build(); | |
| 181 | + var privatePropertiesJson = Json.createObjectBuilder().add("fooPrivate", "bar").build(); | |
| 182 | + | |
| 183 | + | |
| 184 | + return createObjectBuilder() | |
| 185 | + .add(TYPE, "TransferRequest") | |
| 186 | + .add(CONTEXT, createContextBuilder().build()) | |
| 187 | + .add(ID, "id") | |
| 188 | + .add("counterPartyAddress", "address") | |
| 189 | + .add("contractId", "contractId") | |
| 190 | + .add("dataDestination", dataDestination) | |
| 191 | + .add("properties", propertiesJson) | |
| 192 | + .add("privateProperties", privatePropertiesJson) | |
| 193 | + .add("protocol", "protocol") | |
| 194 | + .add("callbackAddresses", createCallbackAddress()) | |
| 195 | + .add("transferType", "myTransferType") | |
| 196 | + .build(); | |
| 197 | + } | |
| 198 | + | |
| 199 | + public static ContractAgreement createContractAgreement(String id) { | |
| 200 | + return ContractAgreement.Builder.newInstance() | |
| 201 | + .id(id) | |
| 202 | + .providerId("providerId") | |
| 203 | + .consumerId("consumerId") | |
| 204 | + .assetId("assetId") | |
| 205 | + .policy(Policy.Builder.newInstance().build()) | |
| 206 | + .build(); | |
| 207 | + } | |
| 208 | + | |
| 209 | + public static ContractNegotiation createContractNegotiation() { | |
| 210 | + return ContractNegotiation.Builder.newInstance() | |
| 211 | + .id("test-id") | |
| 212 | + .correlationId("correlation-id") | |
| 213 | + .counterPartyId("counter-party-id") | |
| 214 | + .counterPartyAddress("address") | |
| 215 | + .contractAgreement(createContractAgreement("test-agreement")) | |
| 216 | + .state(REQUESTED.code()) | |
| 217 | + .type(ContractNegotiation.Type.PROVIDER) | |
| 218 | + .callbackAddresses(List.of( | |
| 219 | + CallbackAddress.Builder.newInstance() | |
| 220 | + .uri("local://test") | |
| 221 | + .events(Set.of("event")) | |
| 222 | + .build())) | |
| 223 | + .protocol("protocol") | |
| 224 | + .errorDetail("errorDetail") | |
| 225 | + .createdAt(1234) | |
| 226 | + .build(); | |
| 227 | + | |
| 228 | + } | |
| 229 | + | |
| 230 | + public static TransferProcess createTransferProcess() { | |
| 231 | + return TransferProcess.Builder.newInstance() | |
| 232 | + .id("transferProcessId") | |
| 233 | + .state(STARTED.code()) | |
| 234 | + .stateTimestamp(1234L) | |
| 235 | + .privateProperties(Map.of("foo", "bar")) | |
| 236 | + .type(CONSUMER) | |
| 237 | + .correlationId("correlationId") | |
| 238 | + .assetId("assetId") | |
| 239 | + .contractId("contractId") | |
| 240 | + .dataDestination(DataAddress.Builder.newInstance().type("any").properties(Map.of("bar", "foo")).build()) | |
| 241 | + .callbackAddresses(List.of(CallbackAddress.Builder.newInstance().uri("http://any").events(emptySet()).build())) | |
| 242 | + .errorDetail("an error") | |
| 243 | + .build(); | |
| 244 | + } | |
| 245 | + | |
| 246 | + public static EndpointDataReferenceEntry createEdrEntry() { | |
| 247 | + return EndpointDataReferenceEntry.Builder.newInstance() | |
| 248 | + .id("transferProcessId") | |
| 249 | + .transferProcessId("transferProcessId") | |
| 250 | + .agreementId("agreementId") | |
| 251 | + .assetId("assetId") | |
| 252 | + .providerId("providerId") | |
| 253 | + .contractNegotiationId("contractNegotiationId") | |
| 254 | + .createdAt(Clock.systemUTC().millis()) | |
| 255 | + .build(); | |
| 256 | + } | |
| 257 | + | |
| 258 | + public static PolicyEvaluationPlan createPolicyEvaluationPlan() { | |
| 259 | + | |
| 260 | + var firstConstraint = atomicConstraintStep(atomicConstraint("foo", "bar")); | |
| 261 | + var secondConstraint = atomicConstraintStep(atomicConstraint("baz", "bar")); | |
| 262 | + | |
| 263 | + List<ConstraintStep> constraints = List.of(firstConstraint, secondConstraint); | |
| 264 | + | |
| 265 | + var orConstraintStep = new OrConstraintStep(constraints, mock()); | |
| 266 | + var andConstraintStep = new AndConstraintStep(constraints, mock()); | |
| 267 | + var xoneConstraintStep = new XoneConstraintStep(constraints, mock()); | |
| 268 | + | |
| 269 | + var permission = PermissionStep.Builder.newInstance().constraint(orConstraintStep).rule(mock()).build(); | |
| 270 | + var duty = DutyStep.Builder.newInstance().constraint(xoneConstraintStep).rule(mock()).build(); | |
| 271 | + var prohibition = ProhibitionStep.Builder.newInstance().constraint(andConstraintStep).rule(mock()).build(); | |
| 272 | + | |
| 273 | + var validatorFunction = mock(PolicyValidatorFunction.class); | |
| 274 | + when(validatorFunction.name()).thenReturn("FunctionName"); | |
| 275 | + | |
| 276 | + return PolicyEvaluationPlan.Builder.newInstance() | |
| 277 | + .postValidator(new ValidatorStep(validatorFunction)) | |
| 278 | + .prohibition(prohibition) | |
| 279 | + .permission(permission) | |
| 280 | + .duty(duty) | |
| 281 | + .preValidator(new ValidatorStep(validatorFunction)) | |
| 282 | + .build(); | |
| 283 | + } | |
| 284 | + | |
| 285 | + public static JsonObject policyDefinitionObject() { | |
| 286 | + return createObjectBuilder() | |
| 287 | + .add(CONTEXT, createContextBuilder().build()) | |
| 288 | + .add(TYPE, "PolicyDefinition") | |
| 289 | + .add(ID, POLICY_ID) | |
| 290 | + .add("policy", inForceDatePolicy("gteq", "contractAgreement+0s", "lteq", "contractAgreement+10s")) | |
| 291 | + .build(); | |
| 292 | + } | |
| 293 | + | |
| 294 | + public static JsonObject policyDefinitionObject(JsonObject permission) { | |
| 295 | + return createObjectBuilder() | |
| 296 | + .add(CONTEXT, createContextBuilder().build()) | |
| 297 | + .add(TYPE, "PolicyDefinition") | |
| 298 | + .add(ID, POLICY_ID) | |
| 299 | + .add("policy", policy(permission)) | |
| 300 | + .build(); | |
| 301 | + } | |
| 302 | + | |
| 303 | + public static JsonObject secretObject() { | |
| 304 | + return createObjectBuilder() | |
| 305 | + .add(CONTEXT, createContextBuilder().build()) | |
| 306 | + .add(TYPE, "Secret") | |
| 307 | + .add(ID, "secret-id") | |
| 308 | + .add("value", "superSecret") | |
| 309 | + .build(); | |
| 310 | + } | |
| 311 | + | |
| 312 | + private static JsonArrayBuilder createCallbackAddress() { | |
| 313 | + var builder = Json.createArrayBuilder(); | |
| 314 | + return builder.add(Json.createObjectBuilder() | |
| 315 | + .add(IS_TRANSACTIONAL, true) | |
| 316 | + .add(URI, "http://test.local/") | |
| 317 | + .add(EVENTS, Json.createArrayBuilder().build())); | |
| 318 | + } | |
| 319 | + | |
| 320 | + public static JsonObjectBuilder policy(JsonObject permission) { | |
| 321 | + return createObjectBuilder() | |
| 322 | + .add(TYPE, "http://www.w3.org/ns/odrl/2/Set") | |
| 323 | + .add("obligation", createArrayBuilder().build()) | |
| 324 | + .add("permission", permission) | |
| 325 | + .add("target", "assetId") | |
| 326 | + .add("prohibition", createArrayBuilder().build()); | |
| 327 | + } | |
| 328 | + | |
| 329 | + public static JsonObject querySpecObject() { | |
| 330 | + var criterion = createObjectBuilder() | |
| 331 | + .add(TYPE, "Criterion") | |
| 332 | + .add("operandLeft", "foo") | |
| 333 | + .add("operator", "=") | |
| 334 | + .add("operandRight", "bar") | |
| 335 | + .build(); | |
| 336 | + | |
| 337 | + return createObjectBuilder() | |
| 338 | + .add(CONTEXT, createContextBuilder().build()) | |
| 339 | + .add(TYPE, "QuerySpec") | |
| 340 | + .add("offset", 10) | |
| 341 | + .add("limit", 20) | |
| 342 | + .add("filterExpression", createArrayBuilder().add(criterion).build()) | |
| 343 | + .add("sortOrder", "DESC") | |
| 344 | + .add("sortField", "fieldName") | |
| 345 | + .build(); | |
| 346 | + | |
| 347 | + } | |
| 348 | + | |
| 349 | + public static JsonObject inForceDatePolicy(String operatorStart, Object startDate, String operatorEnd, Object endDate) { | |
| 350 | + return policy(inForceDatePermission(operatorStart, startDate, operatorEnd, endDate)).build(); | |
| 351 | + } | |
| 352 | + | |
| 353 | + public static JsonObject atomicConstraint(String leftOperand, String operator, Object rightOperand) { | |
| 354 | + return createObjectBuilder() | |
| 355 | + .add("leftOperand", leftOperand) | |
| 356 | + .add("operator", operator) | |
| 357 | + .add("rightOperand", rightOperand.toString()) | |
| 358 | + .build(); | |
| 359 | + } | |
| 360 | + | |
| 361 | + public static JsonObject inForceDatePermission(String operatorStart, Object startDate, String operatorEnd, Object endDate) { | |
| 362 | + return createObjectBuilder() | |
| 363 | + .add("action", "use") | |
| 364 | + .add("constraint", createObjectBuilder() | |
| 365 | + .add("and", createArrayBuilder() | |
| 366 | + .add(atomicConstraint("inForceDate", operatorStart, startDate)) | |
| 367 | + .add(atomicConstraint("inForceDate", operatorEnd, endDate)) | |
| 368 | + .build()) | |
| 369 | + .build()) | |
| 370 | + .build(); | |
| 371 | + } | |
| 372 | + | |
| 373 | + public static JsonObject policyEvaluationPlanRequest() { | |
| 374 | + return Json.createObjectBuilder() | |
| 375 | + .add(CONTEXT, createContextBuilder().build()) | |
| 376 | + .add(TYPE, "PolicyEvaluationPlanRequest") | |
| 377 | + .add("policyScope", "catalog") | |
| 378 | + .build(); | |
| 379 | + } | |
| 380 | + | |
| 381 | + private static AtomicConstraintStep atomicConstraintStep(AtomicConstraint atomicConstraint) { | |
| 382 | + AtomicConstraintFunction<Rule> function = mock(); | |
| 383 | + when(function.name()).thenReturn("AtomicConstraintFunction"); | |
| 384 | + return new AtomicConstraintStep(atomicConstraint, List.of("filtered constraint"), mock(), function); | |
| 385 | + } | |
| 386 | + | |
| 387 | + private static AtomicConstraint atomicConstraint(String key, String value) { | |
| 388 | + var left = new LiteralExpression(key); | |
| 389 | + var right = new LiteralExpression(value); | |
| 390 | + return AtomicConstraint.Builder.newInstance() | |
| 391 | + .leftExpression(left) | |
| 392 | + .operator(EQ) | |
| 393 | + .rightExpression(right) | |
| 394 | + .build(); | |
| 395 | + } | |
| 396 | +} |