-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add agreement endpoints schema examples (#3299)
- Loading branch information
Showing
31 changed files
with
297 additions
and
856 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...main/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiSchema.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.connector.api.management.configuration; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; | ||
|
||
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; | ||
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; | ||
|
||
/** | ||
* Schema records that are shared between multiple management modules | ||
*/ | ||
public interface ManagementApiSchema { | ||
|
||
@Schema(example = ContractAgreementSchema.CONTRACT_AGREEMENT_EXAMPLE) | ||
record ContractAgreementSchema( | ||
@Schema(name = TYPE, example = ContractAgreement.CONTRACT_AGREEMENT_TYPE) | ||
String ldType, | ||
@Schema(name = ID) | ||
String id, | ||
String providerId, | ||
String consumerId, | ||
long contractSigningDate, | ||
String assetId, | ||
@Schema(description = "ODRL policy") | ||
Object policy | ||
) { | ||
public static final String CONTRACT_AGREEMENT_EXAMPLE = """ | ||
{ | ||
"@context": { "edc": "https://w3id.org/edc/v0.0.1/ns/" }, | ||
"@type": "https://w3id.org/edc/v0.0.1/ns/ContractAgreement", | ||
"@id": "negotiation-id", | ||
"providerId": "provider-id", | ||
"consumerId": "consumer-id", | ||
"assetId": "asset-id", | ||
"contractSigningDate": 1688465655, | ||
"policy": { | ||
"@context": "http://www.w3.org/ns/odrl.jsonld", | ||
"@type": "Set", | ||
"@id": "offer-id", | ||
"permission": [{ | ||
"target": "asset-id", | ||
"action": "display" | ||
}] | ||
} | ||
} | ||
"""; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
.../java/org/eclipse/edc/connector/api/management/configuration/ManagementApiSchemaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.connector.api.management.configuration; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import jakarta.json.JsonObject; | ||
import org.eclipse.edc.jsonld.JsonLdExtension; | ||
import org.eclipse.edc.jsonld.spi.JsonLd; | ||
import org.eclipse.edc.jsonld.util.JacksonJsonLd; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.eclipse.edc.connector.api.management.configuration.ManagementApiSchema.ContractAgreementSchema.CONTRACT_AGREEMENT_EXAMPLE; | ||
import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_ASSET_ID; | ||
import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_CONSUMER_ID; | ||
import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_POLICY; | ||
import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_PROVIDER_ID; | ||
import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_SIGNING_DATE; | ||
import static org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement.CONTRACT_AGREEMENT_TYPE; | ||
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; | ||
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; | ||
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.VALUE; | ||
import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat; | ||
import static org.eclipse.edc.junit.extensions.TestServiceExtensionContext.testServiceExtensionContext; | ||
|
||
class ManagementApiSchemaTest { | ||
|
||
private final ObjectMapper objectMapper = JacksonJsonLd.createObjectMapper(); | ||
private final JsonLd jsonLd = new JsonLdExtension().createJsonLdService(testServiceExtensionContext()); | ||
|
||
@Test | ||
void contractAgreementExample() throws JsonProcessingException { | ||
var jsonObject = objectMapper.readValue(CONTRACT_AGREEMENT_EXAMPLE, JsonObject.class); | ||
var expanded = jsonLd.expand(jsonObject); | ||
|
||
assertThat(expanded).isSucceeded().satisfies(content -> { | ||
assertThat(content.getString(ID)).isNotBlank(); | ||
assertThat(content.getJsonArray(TYPE).getString(0)).isEqualTo(CONTRACT_AGREEMENT_TYPE); | ||
assertThat(content.getJsonArray(CONTRACT_AGREEMENT_ASSET_ID).getJsonObject(0).getString(VALUE)).isNotBlank(); | ||
assertThat(content.getJsonArray(CONTRACT_AGREEMENT_PROVIDER_ID).getJsonObject(0).getString(VALUE)).isNotBlank(); | ||
assertThat(content.getJsonArray(CONTRACT_AGREEMENT_CONSUMER_ID).getJsonObject(0).getString(VALUE)).isNotBlank(); | ||
assertThat(content.getJsonArray(CONTRACT_AGREEMENT_SIGNING_DATE).getJsonObject(0).getJsonNumber(VALUE).longValue()).isGreaterThan(0); | ||
assertThat(content.getJsonArray(CONTRACT_AGREEMENT_POLICY).getJsonObject(0)).isNotNull(); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.