From 3448defebabb252ac348d972aacdcb386c412efc Mon Sep 17 00:00:00 2001 From: ndr_brt Date: Thu, 13 Jul 2023 17:16:40 +0200 Subject: [PATCH] feat: add agreement endpoints schema examples --- .../build.gradle.kts | 3 + .../ManagementApiConfigurationExtension.java | 10 +- .../configuration/ManagementApiSchema.java | 63 ++++++ ...bjectFromContractAgreementTransformer.java | 16 +- .../ManagementApiSchemaTest.java | 60 ++++++ ...tFromContractAgreementTransformerTest.java | 2 +- .../ContractAgreementApi.java | 10 +- .../ContractAgreementApiController.java | 7 +- .../ContractAgreementApiExtension.java | 7 - .../model/ContractAgreementDto.java | 110 ---------- ...mentToContractAgreementDtoTransformer.java | 47 ---- ...ctFromContractAgreementDtoTransformer.java | 54 ----- .../ContractAgreementApiControllerTest.java | 37 +--- .../model/ContractAgreementDtoTest.java | 46 ---- ...ToContractAgreementDtoTransformerTest.java | 58 ----- ...omContractAgreementDtoTransformerTest.java | 65 ------ .../ContractNegotiationApi.java | 40 +--- .../ContractNegotiationApiExtension.java | 2 - .../ContractNegotiationApiTest.java | 23 -- resources/openapi/openapi.yaml | 34 +-- .../contract-agreement-api.yaml | 202 ++++-------------- .../spi/types/domain/asset/AssetEntry.java | 1 + .../AssetApiDeprecatedEndToEndTest.java | 49 +---- .../managementapi/AssetApiEndToEndTest.java | 57 ++--- .../BaseManagementApiEndToEndTest.java | 10 + .../managementapi/CatalogApiEndToEndTest.java | 21 +- .../ContractAgreementApiEndToEndTest.java | 29 +-- .../ContractDefinitionApiEndToEndTest.java | 19 +- .../ContractNegotiationApiEndToEndTest.java | 23 +- .../PolicyDefinitionApiEndToEndTest.java | 26 +-- .../TransferProcessApiEndToEndTest.java | 22 +- 31 files changed, 297 insertions(+), 856 deletions(-) create mode 100644 extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiSchema.java rename extensions/{control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation => common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration}/transform/JsonObjectFromContractAgreementTransformer.java (80%) create mode 100644 extensions/common/api/management-api-configuration/src/test/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiSchemaTest.java rename extensions/{control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation => common/api/management-api-configuration/src/test/java/org/eclipse/edc/connector/api/management/configuration}/transform/JsonObjectFromContractAgreementTransformerTest.java (97%) delete mode 100644 extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/model/ContractAgreementDto.java delete mode 100644 extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/transform/ContractAgreementToContractAgreementDtoTransformer.java delete mode 100644 extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/transform/JsonObjectFromContractAgreementDtoTransformer.java delete mode 100644 extensions/control-plane/api/management-api/contract-agreement-api/src/test/java/org/eclipse/edc/connector/api/management/contractagreement/model/ContractAgreementDtoTest.java delete mode 100644 extensions/control-plane/api/management-api/contract-agreement-api/src/test/java/org/eclipse/edc/connector/api/management/contractagreement/transform/ContractAgreementToContractAgreementDtoTransformerTest.java delete mode 100644 extensions/control-plane/api/management-api/contract-agreement-api/src/test/java/org/eclipse/edc/connector/api/management/contractagreement/transform/JsonObjectFromContractAgreementDtoTransformerTest.java diff --git a/extensions/common/api/management-api-configuration/build.gradle.kts b/extensions/common/api/management-api-configuration/build.gradle.kts index cd58d12b7c2..884a0a826b7 100644 --- a/extensions/common/api/management-api-configuration/build.gradle.kts +++ b/extensions/common/api/management-api-configuration/build.gradle.kts @@ -24,7 +24,10 @@ dependencies { implementation(project(":core:common:transform-core")) implementation(project(":extensions:common:api:api-core")) + implementation(libs.swagger.annotations.jakarta) + testImplementation(project(":core:common:junit")) + testImplementation(project(":extensions:common:json-ld")) } edcBuild { diff --git a/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiConfigurationExtension.java b/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiConfigurationExtension.java index 89d2a1175fb..fdf0ddb3784 100644 --- a/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiConfigurationExtension.java +++ b/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiConfigurationExtension.java @@ -14,8 +14,10 @@ package org.eclipse.edc.connector.api.management.configuration; +import jakarta.json.Json; import org.eclipse.edc.api.auth.spi.AuthenticationRequestFilter; import org.eclipse.edc.api.auth.spi.AuthenticationService; +import org.eclipse.edc.connector.api.management.configuration.transform.JsonObjectFromContractAgreementTransformer; import org.eclipse.edc.connector.api.management.configuration.transform.ManagementApiTypeTransformerRegistry; import org.eclipse.edc.connector.api.management.configuration.transform.ManagementApiTypeTransformerRegistryImpl; import org.eclipse.edc.jsonld.spi.JsonLd; @@ -34,6 +36,8 @@ import org.eclipse.edc.web.spi.configuration.WebServiceConfigurer; import org.eclipse.edc.web.spi.configuration.WebServiceSettings; +import java.util.Map; + import static org.eclipse.edc.spi.CoreConstants.JSON_LD; /** @@ -101,6 +105,10 @@ public void initialize(ServiceExtensionContext context) { @Provider public ManagementApiTypeTransformerRegistry managementApiTypeTransformerRegistry() { - return new ManagementApiTypeTransformerRegistryImpl(this.transformerRegistry); + var factory = Json.createBuilderFactory(Map.of()); + + var registry = new ManagementApiTypeTransformerRegistryImpl(this.transformerRegistry); + registry.register(new JsonObjectFromContractAgreementTransformer(factory)); + return registry; } } diff --git a/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiSchema.java b/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiSchema.java new file mode 100644 index 00000000000..9a880e98412 --- /dev/null +++ b/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiSchema.java @@ -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" + }] + } + } + """; + } + +} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractAgreementTransformer.java b/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/transform/JsonObjectFromContractAgreementTransformer.java similarity index 80% rename from extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractAgreementTransformer.java rename to extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/transform/JsonObjectFromContractAgreementTransformer.java index 0e7b3118f3f..e9fa70a7bad 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractAgreementTransformer.java +++ b/extensions/common/api/management-api-configuration/src/main/java/org/eclipse/edc/connector/api/management/configuration/transform/JsonObjectFromContractAgreementTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.connector.api.management.contractnegotiation.transform; +package org.eclipse.edc.connector.api.management.configuration.transform; import jakarta.json.JsonBuilderFactory; import jakarta.json.JsonObject; @@ -40,15 +40,15 @@ public JsonObjectFromContractAgreementTransformer(JsonBuilderFactory jsonFactory } @Override - public @Nullable JsonObject transform(@NotNull ContractAgreement dto, @NotNull TransformerContext context) { + public @Nullable JsonObject transform(@NotNull ContractAgreement agreement, @NotNull TransformerContext context) { return jsonFactory.createObjectBuilder() .add(TYPE, CONTRACT_AGREEMENT_TYPE) - .add(ID, dto.getId()) - .add(CONTRACT_AGREEMENT_ASSET_ID, dto.getAssetId()) - .add(CONTRACT_AGREEMENT_POLICY, context.transform(dto.getPolicy(), JsonObject.class)) - .add(CONTRACT_AGREEMENT_SIGNING_DATE, dto.getContractSigningDate()) - .add(CONTRACT_AGREEMENT_CONSUMER_ID, dto.getConsumerId()) - .add(CONTRACT_AGREEMENT_PROVIDER_ID, dto.getProviderId()) + .add(ID, agreement.getId()) + .add(CONTRACT_AGREEMENT_ASSET_ID, agreement.getAssetId()) + .add(CONTRACT_AGREEMENT_POLICY, context.transform(agreement.getPolicy(), JsonObject.class)) + .add(CONTRACT_AGREEMENT_SIGNING_DATE, agreement.getContractSigningDate()) + .add(CONTRACT_AGREEMENT_CONSUMER_ID, agreement.getConsumerId()) + .add(CONTRACT_AGREEMENT_PROVIDER_ID, agreement.getProviderId()) .build(); } } diff --git a/extensions/common/api/management-api-configuration/src/test/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiSchemaTest.java b/extensions/common/api/management-api-configuration/src/test/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiSchemaTest.java new file mode 100644 index 00000000000..e123fa4b85c --- /dev/null +++ b/extensions/common/api/management-api-configuration/src/test/java/org/eclipse/edc/connector/api/management/configuration/ManagementApiSchemaTest.java @@ -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(); + }); + } + +} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractAgreementTransformerTest.java b/extensions/common/api/management-api-configuration/src/test/java/org/eclipse/edc/connector/api/management/configuration/transform/JsonObjectFromContractAgreementTransformerTest.java similarity index 97% rename from extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractAgreementTransformerTest.java rename to extensions/common/api/management-api-configuration/src/test/java/org/eclipse/edc/connector/api/management/configuration/transform/JsonObjectFromContractAgreementTransformerTest.java index 1611f67bb5e..5f6eb845d0a 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromContractAgreementTransformerTest.java +++ b/extensions/common/api/management-api-configuration/src/test/java/org/eclipse/edc/connector/api/management/configuration/transform/JsonObjectFromContractAgreementTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.connector.api.management.contractnegotiation.transform; +package org.eclipse.edc.connector.api.management.configuration.transform; import jakarta.json.Json; import jakarta.json.JsonObject; diff --git a/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/ContractAgreementApi.java b/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/ContractAgreementApi.java index 4d2a7e1a6c8..115777d33d4 100644 --- a/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/ContractAgreementApi.java +++ b/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/ContractAgreementApi.java @@ -24,8 +24,8 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.json.JsonArray; import jakarta.json.JsonObject; -import org.eclipse.edc.api.model.QuerySpecDto; -import org.eclipse.edc.connector.api.management.contractagreement.model.ContractAgreementDto; +import org.eclipse.edc.api.model.ApiCoreSchema; +import org.eclipse.edc.connector.api.management.configuration.ManagementApiSchema; import org.eclipse.edc.web.spi.ApiErrorDetail; @OpenAPIDefinition @@ -33,10 +33,10 @@ public interface ContractAgreementApi { @Operation(description = "Gets all contract agreements according to a particular query", - requestBody = @RequestBody(content = @Content(schema = @Schema(implementation = QuerySpecDto.class))), + requestBody = @RequestBody(content = @Content(schema = @Schema(implementation = ApiCoreSchema.QuerySpecSchema.class))), responses = { @ApiResponse(responseCode = "200", description = "The contract agreements matching the query", - content = @Content(array = @ArraySchema(schema = @Schema(implementation = ContractAgreementDto.class)))), + content = @Content(array = @ArraySchema(schema = @Schema(implementation = ManagementApiSchema.ContractAgreementSchema.class)))), @ApiResponse(responseCode = "400", description = "Request body was malformed", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ApiErrorDetail.class)))) } @@ -46,7 +46,7 @@ public interface ContractAgreementApi { @Operation(description = "Gets an contract agreement with the given ID", responses = { @ApiResponse(responseCode = "200", description = "The contract agreement", - content = @Content(schema = @Schema(implementation = ContractAgreementDto.class))), + content = @Content(schema = @Schema(implementation = ManagementApiSchema.ContractAgreementSchema.class))), @ApiResponse(responseCode = "400", description = "Request was malformed, e.g. id was null", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ApiErrorDetail.class)))), @ApiResponse(responseCode = "404", description = "An contract agreement with the given ID does not exist", diff --git a/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/ContractAgreementApiController.java b/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/ContractAgreementApiController.java index fdae070184f..0e0145e120f 100644 --- a/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/ContractAgreementApiController.java +++ b/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/ContractAgreementApiController.java @@ -23,7 +23,6 @@ import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; import org.eclipse.edc.api.model.QuerySpecDto; -import org.eclipse.edc.connector.api.management.contractagreement.model.ContractAgreementDto; import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; import org.eclipse.edc.connector.contract.spi.types.offer.ContractDefinition; import org.eclipse.edc.connector.spi.contractagreement.ContractAgreementService; @@ -76,8 +75,7 @@ public JsonArray queryAllAgreements(JsonObject querySpecDto) { try (var stream = service.query(querySpec).orElseThrow(exceptionMapper(ContractDefinition.class, null))) { return stream - .map(it -> transformerRegistry.transform(it, ContractAgreementDto.class) - .compose(dto -> transformerRegistry.transform(dto, JsonObject.class))) + .map(it -> transformerRegistry.transform(it, JsonObject.class)) .peek(r -> r.onFailure(f -> monitor.warning(f.getFailureDetail()))) .filter(Result::succeeded) .map(Result::getContent) @@ -91,8 +89,7 @@ public JsonArray queryAllAgreements(JsonObject querySpecDto) { public JsonObject getAgreementById(@PathParam("id") String id) { return Optional.of(id) .map(service::findById) - .map(it -> transformerRegistry.transform(it, ContractAgreementDto.class) - .compose(dto -> transformerRegistry.transform(dto, JsonObject.class)) + .map(it -> transformerRegistry.transform(it, JsonObject.class) .orElseThrow(failure -> new EdcException(failure.getFailureDetail()))) .orElseThrow(() -> new ObjectNotFoundException(ContractAgreement.class, id)); } diff --git a/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/ContractAgreementApiExtension.java b/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/ContractAgreementApiExtension.java index dede652cffe..4aa1d50cd59 100644 --- a/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/ContractAgreementApiExtension.java +++ b/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/ContractAgreementApiExtension.java @@ -15,11 +15,8 @@ package org.eclipse.edc.connector.api.management.contractagreement; -import jakarta.json.Json; import org.eclipse.edc.connector.api.management.configuration.ManagementApiConfiguration; import org.eclipse.edc.connector.api.management.configuration.transform.ManagementApiTypeTransformerRegistry; -import org.eclipse.edc.connector.api.management.contractagreement.transform.ContractAgreementToContractAgreementDtoTransformer; -import org.eclipse.edc.connector.api.management.contractagreement.transform.JsonObjectFromContractAgreementDtoTransformer; import org.eclipse.edc.connector.spi.contractagreement.ContractAgreementService; import org.eclipse.edc.runtime.metamodel.annotation.Extension; import org.eclipse.edc.runtime.metamodel.annotation.Inject; @@ -28,8 +25,6 @@ import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry; import org.eclipse.edc.web.spi.WebService; -import java.util.Map; - @Extension(value = ContractAgreementApiExtension.NAME) public class ContractAgreementApiExtension implements ServiceExtension { @@ -56,8 +51,6 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { - transformerRegistry.register(new ContractAgreementToContractAgreementDtoTransformer()); - transformerRegistry.register(new JsonObjectFromContractAgreementDtoTransformer(Json.createBuilderFactory(Map.of()))); var monitor = context.getMonitor(); var controller = new ContractAgreementApiController(service, transformerRegistry, monitor, validatorRegistry); diff --git a/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/model/ContractAgreementDto.java b/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/model/ContractAgreementDto.java deleted file mode 100644 index 546f5a53986..00000000000 --- a/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/model/ContractAgreementDto.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2020 - 2022 Microsoft Corporation - * - * 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: - * Microsoft Corporation - initial API and implementation - * - */ - -package org.eclipse.edc.connector.api.management.contractagreement.model; - -import com.fasterxml.jackson.annotation.JsonProperty; -import org.eclipse.edc.api.model.BaseDto; -import org.eclipse.edc.policy.model.Policy; - -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; -import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; - -public class ContractAgreementDto extends BaseDto { - - public static final String TYPE = EDC_NAMESPACE + "ContractAgreementDto"; - public static final String CONTRACT_AGREEMENT_ASSETID = EDC_NAMESPACE + "assetId"; - public static final String CONTRACT_AGREEMENT_PROVIDER_ID = EDC_NAMESPACE + "providerId"; - public static final String CONTRACT_AGREEMENT_CONSUMER_ID = EDC_NAMESPACE + "consumerId"; - public static final String CONTRACT_AGREEMENT_SIGNING_DATE = EDC_NAMESPACE + "contractSigningDate"; - public static final String CONTRACT_AGREEMENT_POLICY = EDC_NAMESPACE + "policy"; - - @JsonProperty(value = ID) - private String id; - private String providerId; - private String consumerId; - private long contractSigningDate; - private String assetId; - private Policy policy; - - public String getId() { - return id; - } - - public String getProviderId() { - return providerId; - } - - public String getConsumerId() { - return consumerId; - } - - public long getContractSigningDate() { - return contractSigningDate; - } - - public String getAssetId() { - return assetId; - } - - public Policy getPolicy() { - return policy; - } - - public static final class Builder { - private final ContractAgreementDto agreement; - - private Builder() { - agreement = new ContractAgreementDto(); - } - - public static Builder newInstance() { - return new Builder(); - } - - public Builder id(String id) { - agreement.id = id; - return this; - } - - public Builder providerId(String providerId) { - agreement.providerId = providerId; - return this; - } - - public Builder consumerId(String consumerId) { - agreement.consumerId = consumerId; - return this; - } - - public Builder contractSigningDate(long contractSigningDate) { - agreement.contractSigningDate = contractSigningDate; - return this; - } - - public Builder assetId(String assetId) { - agreement.assetId = assetId; - return this; - } - - public Builder policy(Policy policy) { - agreement.policy = policy; - return this; - } - - public ContractAgreementDto build() { - return agreement; - } - } -} diff --git a/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/transform/ContractAgreementToContractAgreementDtoTransformer.java b/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/transform/ContractAgreementToContractAgreementDtoTransformer.java deleted file mode 100644 index 56e04f8ec5a..00000000000 --- a/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/transform/ContractAgreementToContractAgreementDtoTransformer.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2022 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.contractagreement.transform; - -import org.eclipse.edc.api.transformer.DtoTransformer; -import org.eclipse.edc.connector.api.management.contractagreement.model.ContractAgreementDto; -import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; -import org.eclipse.edc.transform.spi.TransformerContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class ContractAgreementToContractAgreementDtoTransformer implements DtoTransformer { - - @Override - public Class getInputType() { - return ContractAgreement.class; - } - - @Override - public Class getOutputType() { - return ContractAgreementDto.class; - } - - @Override - public @Nullable ContractAgreementDto transform(@NotNull ContractAgreement object, @NotNull TransformerContext context) { - return ContractAgreementDto.Builder.newInstance() - .id(object.getId()) - .assetId(object.getAssetId()) - .policy(object.getPolicy()) - .consumerId(object.getConsumerId()) - .providerId(object.getProviderId()) - .contractSigningDate(object.getContractSigningDate()) - .build(); - } -} diff --git a/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/transform/JsonObjectFromContractAgreementDtoTransformer.java b/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/transform/JsonObjectFromContractAgreementDtoTransformer.java deleted file mode 100644 index 033cdf5ef3f..00000000000 --- a/extensions/control-plane/api/management-api/contract-agreement-api/src/main/java/org/eclipse/edc/connector/api/management/contractagreement/transform/JsonObjectFromContractAgreementDtoTransformer.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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.contractagreement.transform; - -import jakarta.json.JsonBuilderFactory; -import jakarta.json.JsonObject; -import org.eclipse.edc.connector.api.management.contractagreement.model.ContractAgreementDto; -import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; -import org.eclipse.edc.transform.spi.TransformerContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import static org.eclipse.edc.connector.api.management.contractagreement.model.ContractAgreementDto.CONTRACT_AGREEMENT_ASSETID; -import static org.eclipse.edc.connector.api.management.contractagreement.model.ContractAgreementDto.CONTRACT_AGREEMENT_CONSUMER_ID; -import static org.eclipse.edc.connector.api.management.contractagreement.model.ContractAgreementDto.CONTRACT_AGREEMENT_POLICY; -import static org.eclipse.edc.connector.api.management.contractagreement.model.ContractAgreementDto.CONTRACT_AGREEMENT_PROVIDER_ID; -import static org.eclipse.edc.connector.api.management.contractagreement.model.ContractAgreementDto.CONTRACT_AGREEMENT_SIGNING_DATE; -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; - -public class JsonObjectFromContractAgreementDtoTransformer extends AbstractJsonLdTransformer { - private final JsonBuilderFactory jsonFactory; - - public JsonObjectFromContractAgreementDtoTransformer(JsonBuilderFactory jsonFactory) { - super(ContractAgreementDto.class, JsonObject.class); - this.jsonFactory = jsonFactory; - } - - @Override - public @Nullable JsonObject transform(@NotNull ContractAgreementDto dto, @NotNull TransformerContext context) { - var builder = jsonFactory.createObjectBuilder() - .add(TYPE, ContractAgreementDto.TYPE) - .add(ID, dto.getId()) - .add(CONTRACT_AGREEMENT_ASSETID, dto.getAssetId()) - .add(CONTRACT_AGREEMENT_PROVIDER_ID, dto.getProviderId()) - .add(CONTRACT_AGREEMENT_CONSUMER_ID, dto.getConsumerId()) - .add(CONTRACT_AGREEMENT_SIGNING_DATE, dto.getContractSigningDate()) - .add(CONTRACT_AGREEMENT_POLICY, context.transform(dto.getPolicy(), JsonObject.class)); - - return builder.build(); - } -} diff --git a/extensions/control-plane/api/management-api/contract-agreement-api/src/test/java/org/eclipse/edc/connector/api/management/contractagreement/ContractAgreementApiControllerTest.java b/extensions/control-plane/api/management-api/contract-agreement-api/src/test/java/org/eclipse/edc/connector/api/management/contractagreement/ContractAgreementApiControllerTest.java index 5086cbee3c5..421d0e838af 100644 --- a/extensions/control-plane/api/management-api/contract-agreement-api/src/test/java/org/eclipse/edc/connector/api/management/contractagreement/ContractAgreementApiControllerTest.java +++ b/extensions/control-plane/api/management-api/contract-agreement-api/src/test/java/org/eclipse/edc/connector/api/management/contractagreement/ContractAgreementApiControllerTest.java @@ -18,7 +18,6 @@ import jakarta.json.Json; import jakarta.json.JsonObject; import org.eclipse.edc.api.model.QuerySpecDto; -import org.eclipse.edc.connector.api.management.contractagreement.model.ContractAgreementDto; import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; import org.eclipse.edc.connector.spi.contractagreement.ContractAgreementService; import org.eclipse.edc.junit.annotations.ApiTest; @@ -64,8 +63,7 @@ void queryAllAgreements_whenExists() { when(transformerRegistry.transform(any(JsonObject.class), eq(QuerySpecDto.class))).thenReturn(Result.success(QuerySpecDto.Builder.newInstance().build())); when(transformerRegistry.transform(any(QuerySpecDto.class), eq(QuerySpec.class))).thenReturn(Result.success(QuerySpec.none())); when(service.query(any(QuerySpec.class))).thenReturn(ServiceResult.success(Stream.of(createContractAgreement("id1"), createContractAgreement("id2")))); - when(transformerRegistry.transform(any(ContractAgreement.class), eq(ContractAgreementDto.class))).thenReturn(Result.success(createContractAgreementDto(UUID.randomUUID().toString()))); - when(transformerRegistry.transform(any(ContractAgreementDto.class), eq(JsonObject.class))).thenReturn(Result.success(expanded)); + when(transformerRegistry.transform(any(ContractAgreement.class), eq(JsonObject.class))).thenReturn(Result.success(expanded)); baseRequest() .contentType(JSON) @@ -79,8 +77,7 @@ void queryAllAgreements_whenExists() { verify(transformerRegistry).transform(any(JsonObject.class), eq(QuerySpecDto.class)); verify(transformerRegistry).transform(any(QuerySpecDto.class), eq(QuerySpec.class)); verify(service).query(any(QuerySpec.class)); - verify(transformerRegistry, times(2)).transform(any(ContractAgreement.class), eq(ContractAgreementDto.class)); - verify(transformerRegistry, times(2)).transform(any(ContractAgreementDto.class), eq(JsonObject.class)); + verify(transformerRegistry, times(2)).transform(any(ContractAgreement.class), eq(JsonObject.class)); verifyNoMoreInteractions(service, transformerRegistry); } @@ -102,8 +99,7 @@ void queryAllAgreements_whenNoneExists() { verify(transformerRegistry).transform(any(JsonObject.class), eq(QuerySpecDto.class)); verify(transformerRegistry).transform(any(QuerySpecDto.class), eq(QuerySpec.class)); verify(service).query(any(QuerySpec.class)); - verify(transformerRegistry, never()).transform(any(ContractAgreement.class), eq(ContractAgreementDto.class)); - verify(transformerRegistry, never()).transform(any(ContractAgreementDto.class), eq(JsonObject.class)); + verify(transformerRegistry, never()).transform(any(ContractAgreement.class), eq(JsonObject.class)); verifyNoMoreInteractions(service, transformerRegistry); } @@ -127,8 +123,7 @@ void queryAllAgreements_whenTransformationFails() { when(transformerRegistry.transform(any(JsonObject.class), eq(QuerySpecDto.class))).thenReturn(Result.success(QuerySpecDto.Builder.newInstance().build())); when(transformerRegistry.transform(any(QuerySpecDto.class), eq(QuerySpec.class))).thenReturn(Result.success(QuerySpec.none())); when(service.query(any(QuerySpec.class))).thenReturn(ServiceResult.success(Stream.of(createContractAgreement("id1"), createContractAgreement("id2")))); - when(transformerRegistry.transform(any(ContractAgreement.class), eq(ContractAgreementDto.class))).thenReturn(Result.success(createContractAgreementDto(UUID.randomUUID().toString()))); - when(transformerRegistry.transform(any(ContractAgreementDto.class), eq(JsonObject.class))).thenReturn(Result.failure("test-failure")); + when(transformerRegistry.transform(any(ContractAgreement.class), eq(JsonObject.class))).thenReturn(Result.failure("test-failure")); baseRequest() .contentType(JSON) @@ -141,8 +136,7 @@ void queryAllAgreements_whenTransformationFails() { verify(transformerRegistry).transform(any(JsonObject.class), eq(QuerySpecDto.class)); verify(transformerRegistry).transform(any(QuerySpecDto.class), eq(QuerySpec.class)); verify(service).query(any(QuerySpec.class)); - verify(transformerRegistry, times(2)).transform(any(ContractAgreement.class), eq(ContractAgreementDto.class)); - verify(transformerRegistry, times(2)).transform(any(ContractAgreementDto.class), eq(JsonObject.class)); + verify(transformerRegistry, times(2)).transform(any(ContractAgreement.class), eq(JsonObject.class)); verify(monitor, times(2)).warning(eq("test-failure")); verifyNoMoreInteractions(service, transformerRegistry); } @@ -150,8 +144,7 @@ void queryAllAgreements_whenTransformationFails() { @Test void getContractAgreement() { when(service.findById(eq("id1"))).thenReturn(createContractAgreement("id1")); - when(transformerRegistry.transform(any(ContractAgreement.class), eq(ContractAgreementDto.class))).thenReturn(Result.success(createContractAgreementDto("id1"))); - when(transformerRegistry.transform(any(ContractAgreementDto.class), eq(JsonObject.class))).thenReturn(Result.success(Json.createObjectBuilder().build())); + when(transformerRegistry.transform(any(ContractAgreement.class), eq(JsonObject.class))).thenReturn(Result.success(Json.createObjectBuilder().build())); baseRequest() .contentType(JSON) @@ -161,8 +154,7 @@ void getContractAgreement() { .body(notNullValue()); verify(service).findById(eq("id1")); - verify(transformerRegistry).transform(any(ContractAgreement.class), eq(ContractAgreementDto.class)); - verify(transformerRegistry).transform(any(ContractAgreementDto.class), eq(JsonObject.class)); + verify(transformerRegistry).transform(any(ContractAgreement.class), eq(JsonObject.class)); verifyNoMoreInteractions(service, transformerRegistry); } @@ -184,8 +176,7 @@ void getContractAgreement_notFound() { @Test void getContractAgreement_transformationFails() { when(service.findById(eq("id1"))).thenReturn(createContractAgreement("id1")); - when(transformerRegistry.transform(any(ContractAgreement.class), eq(ContractAgreementDto.class))).thenReturn(Result.success(createContractAgreementDto("id1"))); - when(transformerRegistry.transform(any(ContractAgreementDto.class), eq(JsonObject.class))).thenReturn(Result.failure("test-failure")); + when(transformerRegistry.transform(any(ContractAgreement.class), eq(JsonObject.class))).thenReturn(Result.failure("test-failure")); baseRequest() .contentType(JSON) @@ -194,8 +185,7 @@ void getContractAgreement_transformationFails() { .statusCode(500); verify(service).findById(eq("id1")); - verify(transformerRegistry).transform(any(ContractAgreement.class), eq(ContractAgreementDto.class)); - verify(transformerRegistry).transform(any(ContractAgreementDto.class), eq(JsonObject.class)); + verify(transformerRegistry).transform(any(ContractAgreement.class), eq(JsonObject.class)); verifyNoMoreInteractions(service, transformerRegistry); } @@ -221,13 +211,4 @@ private ContractAgreement createContractAgreement(String negotiationId) { .build(); } - private ContractAgreementDto createContractAgreementDto(String negotiationId) { - return ContractAgreementDto.Builder.newInstance() - .id(negotiationId) - .consumerId("test-consumer") - .providerId("test-provider") - .assetId(UUID.randomUUID().toString()) - .policy(Policy.Builder.newInstance().build()) - .build(); - } } diff --git a/extensions/control-plane/api/management-api/contract-agreement-api/src/test/java/org/eclipse/edc/connector/api/management/contractagreement/model/ContractAgreementDtoTest.java b/extensions/control-plane/api/management-api/contract-agreement-api/src/test/java/org/eclipse/edc/connector/api/management/contractagreement/model/ContractAgreementDtoTest.java deleted file mode 100644 index c9d28a6fea4..00000000000 --- a/extensions/control-plane/api/management-api/contract-agreement-api/src/test/java/org/eclipse/edc/connector/api/management/contractagreement/model/ContractAgreementDtoTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2020 - 2022 Microsoft Corporation - * - * 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: - * Microsoft Corporation - initial API and implementation - * - */ - -package org.eclipse.edc.connector.api.management.contractagreement.model; - -import com.fasterxml.jackson.core.JsonProcessingException; -import org.eclipse.edc.policy.model.Policy; -import org.eclipse.edc.spi.types.TypeManager; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -class ContractAgreementDtoTest { - - @Test - void verifySerialization() throws JsonProcessingException { - var om = new TypeManager().getMapper(); - var dto = ContractAgreementDto.Builder.newInstance() - .assetId("test-asset-id") - .id("test-id") - .contractSigningDate(5432L) - .providerId("provider") - .consumerId("consumer") - .policy(Policy.Builder.newInstance().build()) - .build(); - - var json = om.writeValueAsString(dto); - assertThat(json).isNotNull(); - - var deserialized = om.readValue(json, ContractAgreementDto.class); - assertThat(deserialized).usingRecursiveComparison().isEqualTo(dto); - - } - -} diff --git a/extensions/control-plane/api/management-api/contract-agreement-api/src/test/java/org/eclipse/edc/connector/api/management/contractagreement/transform/ContractAgreementToContractAgreementDtoTransformerTest.java b/extensions/control-plane/api/management-api/contract-agreement-api/src/test/java/org/eclipse/edc/connector/api/management/contractagreement/transform/ContractAgreementToContractAgreementDtoTransformerTest.java deleted file mode 100644 index be761523584..00000000000 --- a/extensions/control-plane/api/management-api/contract-agreement-api/src/test/java/org/eclipse/edc/connector/api/management/contractagreement/transform/ContractAgreementToContractAgreementDtoTransformerTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2022 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.contractagreement.transform; - -import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; -import org.eclipse.edc.policy.model.Policy; -import org.eclipse.edc.transform.spi.TransformerContext; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -class ContractAgreementToContractAgreementDtoTransformerTest { - - private final ContractAgreementToContractAgreementDtoTransformer transformer = new ContractAgreementToContractAgreementDtoTransformer(); - - @Test - void inputOutputType() { - assertThat(transformer.getInputType()).isNotNull(); - assertThat(transformer.getOutputType()).isNotNull(); - } - - @Test - void transform() { - var context = mock(TransformerContext.class); - var policy = Policy.Builder.newInstance().build(); - var contractAgreement = ContractAgreement.Builder.newInstance() - .id("agreementId") - .consumerId("consumerId") - .providerId("providerId") - .assetId("assetId") - .policy(policy) - .contractSigningDate(2) - .build(); - - var dto = transformer.transform(contractAgreement, context); - - assertThat(dto.getId()).isEqualTo("agreementId"); - assertThat(dto.getAssetId()).isEqualTo("assetId"); - assertThat(dto.getPolicy()).isEqualTo(policy); - assertThat(dto.getContractSigningDate()).isEqualTo(2); - assertThat(dto.getConsumerId()).isEqualTo("consumerId"); - assertThat(dto.getProviderId()).isEqualTo("providerId"); - } - -} diff --git a/extensions/control-plane/api/management-api/contract-agreement-api/src/test/java/org/eclipse/edc/connector/api/management/contractagreement/transform/JsonObjectFromContractAgreementDtoTransformerTest.java b/extensions/control-plane/api/management-api/contract-agreement-api/src/test/java/org/eclipse/edc/connector/api/management/contractagreement/transform/JsonObjectFromContractAgreementDtoTransformerTest.java deleted file mode 100644 index 2425d5dbea0..00000000000 --- a/extensions/control-plane/api/management-api/contract-agreement-api/src/test/java/org/eclipse/edc/connector/api/management/contractagreement/transform/JsonObjectFromContractAgreementDtoTransformerTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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.contractagreement.transform; - -import jakarta.json.Json; -import jakarta.json.JsonObject; -import jakarta.json.JsonString; -import org.eclipse.edc.connector.api.management.contractagreement.model.ContractAgreementDto; -import org.eclipse.edc.policy.model.Policy; -import org.eclipse.edc.transform.spi.TransformerContext; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.eclipse.edc.connector.api.management.contractagreement.model.ContractAgreementDto.CONTRACT_AGREEMENT_ASSETID; -import static org.eclipse.edc.connector.api.management.contractagreement.model.ContractAgreementDto.CONTRACT_AGREEMENT_CONSUMER_ID; -import static org.eclipse.edc.connector.api.management.contractagreement.model.ContractAgreementDto.CONTRACT_AGREEMENT_POLICY; -import static org.eclipse.edc.connector.api.management.contractagreement.model.ContractAgreementDto.CONTRACT_AGREEMENT_PROVIDER_ID; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -class JsonObjectFromContractAgreementDtoTransformerTest { - private JsonObjectFromContractAgreementDtoTransformer transformer; - - @BeforeEach - void setUp() { - transformer = new JsonObjectFromContractAgreementDtoTransformer(Json.createBuilderFactory(Map.of())); - } - - @Test - void transform() { - var agreement = ContractAgreementDto.Builder.newInstance() - .id("test-id") - .providerId("test-provider") - .consumerId("test-consumer") - .assetId("test-asset") - .policy(Policy.Builder.newInstance().build()) - .build(); - var context = mock(TransformerContext.class); - when(context.transform(any(Policy.class), eq(JsonObject.class))).thenReturn(Json.createObjectBuilder().build()); - - var jobj = transformer.transform(agreement, context); - assertThat(jobj).isNotNull(); - assertThat(jobj.getJsonString(CONTRACT_AGREEMENT_ASSETID)).extracting(JsonString::getString).isEqualTo("test-asset"); - assertThat(jobj.getJsonString(CONTRACT_AGREEMENT_PROVIDER_ID)).extracting(JsonString::getString).isEqualTo("test-provider"); - assertThat(jobj.getJsonString(CONTRACT_AGREEMENT_CONSUMER_ID)).extracting(JsonString::getString).isEqualTo("test-consumer"); - assertThat(jobj.getJsonObject(CONTRACT_AGREEMENT_POLICY)).isNotNull(); - } -} \ No newline at end of file diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApi.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApi.java index eb52ecbcac8..4f9a2b4f40f 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApi.java +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApi.java @@ -27,9 +27,9 @@ import jakarta.json.JsonArray; import jakarta.json.JsonObject; import org.eclipse.edc.api.model.ApiCoreSchema; +import org.eclipse.edc.connector.api.management.configuration.ManagementApiSchema; import org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractOfferDescription; import org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationState; -import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation; import org.eclipse.edc.spi.types.domain.callback.CallbackAddress; import org.eclipse.edc.web.spi.ApiErrorDetail; @@ -84,7 +84,7 @@ public interface ContractNegotiationApi { @Operation(description = "Gets a contract agreement for a contract negotiation with the given ID", responses = { @ApiResponse(responseCode = "200", description = "The contract agreement that is attached to the negotiation, or null", - content = @Content(schema = @Schema(implementation = ContractAgreementSchema.class))), + content = @Content(schema = @Schema(implementation = ManagementApiSchema.ContractAgreementSchema.class))), @ApiResponse(responseCode = "400", description = "Request was malformed, e.g. id was null", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ApiErrorDetail.class)))), @ApiResponse(responseCode = "404", description = "An contract negotiation with the given ID does not exist", @@ -220,42 +220,6 @@ record ContractNegotiationSchema( """; } - @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" - }] - } - } - """; - } - - @Schema(example = NegotiationStateSchema.NEGOTIATION_STATE_EXAMPLE) record NegotiationStateSchema( @Schema(name = TYPE, example = NegotiationState.NEGOTIATION_STATE_TYPE) diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiExtension.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiExtension.java index 8ca23c9fda9..edebccdbb50 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiExtension.java +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiExtension.java @@ -18,7 +18,6 @@ import jakarta.json.Json; import org.eclipse.edc.connector.api.management.configuration.ManagementApiConfiguration; import org.eclipse.edc.connector.api.management.configuration.transform.ManagementApiTypeTransformerRegistry; -import org.eclipse.edc.connector.api.management.contractnegotiation.transform.JsonObjectFromContractAgreementTransformer; import org.eclipse.edc.connector.api.management.contractnegotiation.transform.JsonObjectFromContractNegotiationTransformer; import org.eclipse.edc.connector.api.management.contractnegotiation.transform.JsonObjectFromNegotiationStateTransformer; import org.eclipse.edc.connector.api.management.contractnegotiation.transform.JsonObjectToContractOfferDescriptionTransformer; @@ -64,7 +63,6 @@ public String name() { public void initialize(ServiceExtensionContext context) { var factory = Json.createBuilderFactory(Map.of()); transformerRegistry.register(new JsonObjectFromContractNegotiationTransformer(factory)); - transformerRegistry.register(new JsonObjectFromContractAgreementTransformer(factory)); transformerRegistry.register(new JsonObjectToContractRequestTransformer()); transformerRegistry.register(new JsonObjectFromNegotiationStateTransformer(factory)); transformerRegistry.register(new JsonObjectToContractOfferDescriptionTransformer()); diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiTest.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiTest.java index 6b54f79459b..34b15e23503 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiTest.java +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiTest.java @@ -32,18 +32,11 @@ import org.junit.jupiter.api.Test; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.eclipse.edc.connector.api.management.contractnegotiation.ContractNegotiationApi.ContractAgreementSchema.CONTRACT_AGREEMENT_EXAMPLE; import static org.eclipse.edc.connector.api.management.contractnegotiation.ContractNegotiationApi.ContractNegotiationSchema.CONTRACT_NEGOTIATION_EXAMPLE; import static org.eclipse.edc.connector.api.management.contractnegotiation.ContractNegotiationApi.ContractRequestSchema.CONTRACT_REQUEST_EXAMPLE; import static org.eclipse.edc.connector.api.management.contractnegotiation.ContractNegotiationApi.NegotiationStateSchema.NEGOTIATION_STATE_EXAMPLE; import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationState.NEGOTIATION_STATE_STATE; import static org.eclipse.edc.connector.api.management.contractnegotiation.model.NegotiationState.NEGOTIATION_STATE_TYPE; -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.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_AGREEMENT_ID; import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_CALLBACK_ADDR; import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation.CONTRACT_NEGOTIATION_COUNTERPARTY_ADDR; @@ -111,22 +104,6 @@ void contractNegotiationExample() throws JsonProcessingException { }); } - @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(); - }); - } - @Test void negotiationStateExample() throws JsonProcessingException { var jsonObject = objectMapper.readValue(NEGOTIATION_STATE_EXAMPLE, JsonObject.class); diff --git a/resources/openapi/openapi.yaml b/resources/openapi/openapi.yaml index 7fce4066bef..14f25502f3f 100644 --- a/resources/openapi/openapi.yaml +++ b/resources/openapi/openapi.yaml @@ -589,7 +589,7 @@ paths: content: '*/*': schema: - $ref: '#/components/schemas/QuerySpecDto' + $ref: '#/components/schemas/QuerySpecSchema' responses: "200": description: The contract agreements matching the query @@ -599,7 +599,7 @@ paths: type: array example: null items: - $ref: '#/components/schemas/ContractAgreementDto' + $ref: '#/components/schemas/ContractAgreementSchema' "400": description: Request body was malformed content: @@ -630,7 +630,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ContractAgreementDto' + $ref: '#/components/schemas/ContractAgreementSchema' "400": description: "Request was malformed, e.g. id was null" content: @@ -2080,34 +2080,6 @@ components: example: null discriminator: propertyName: edctype - ContractAgreementDto: - type: object - properties: - '@context': - type: object - example: null - '@id': - type: string - example: null - '@type': - type: string - example: null - assetId: - type: string - example: null - consumerId: - type: string - example: null - contractSigningDate: - type: integer - format: int64 - example: null - policy: - $ref: '#/components/schemas/Policy' - providerId: - type: string - example: null - example: null ContractAgreementSchema: type: object properties: diff --git a/resources/openapi/yaml/management-api/contract-agreement-api.yaml b/resources/openapi/yaml/management-api/contract-agreement-api.yaml index 68f0b49b557..fa07eb80952 100644 --- a/resources/openapi/yaml/management-api/contract-agreement-api.yaml +++ b/resources/openapi/yaml/management-api/contract-agreement-api.yaml @@ -8,7 +8,7 @@ paths: content: '*/*': schema: - $ref: '#/components/schemas/QuerySpecDto' + $ref: '#/components/schemas/QuerySpecSchema' responses: "200": content: @@ -17,7 +17,7 @@ paths: type: array example: null items: - $ref: '#/components/schemas/ContractAgreementDto' + $ref: '#/components/schemas/ContractAgreementSchema' description: The contract agreements matching the query "400": content: @@ -46,7 +46,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ContractAgreementDto' + $ref: '#/components/schemas/ContractAgreementSchema' description: The contract agreement "400": content: @@ -70,18 +70,6 @@ paths: - Contract Agreement components: schemas: - Action: - type: object - example: null - properties: - constraint: - $ref: '#/components/schemas/Constraint' - includedIn: - type: string - example: null - type: - type: string - example: null ApiErrorDetail: type: object example: null @@ -98,30 +86,31 @@ components: type: type: string example: null - Constraint: - type: object - discriminator: - propertyName: edctype - example: null - properties: - edctype: - type: string - example: null - required: - - edctype - ContractAgreementDto: + ContractAgreementSchema: type: object - example: null - properties: + example: '@context': - type: object - example: null + 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 + properties: '@id': type: string example: null '@type': type: string - example: null + example: https://w3id.org/edc/v0.0.1/ns/ContractAgreement assetId: type: string example: null @@ -133,20 +122,24 @@ components: format: int64 example: null policy: - $ref: '#/components/schemas/Policy' + type: object + description: ODRL policy + example: null providerId: type: string example: null - CriterionDto: + CriterionSchema: type: object - example: null - properties: + example: '@context': - type: object - example: null + edc: https://w3id.org/edc/v0.0.1/ns/ + operandLeft: fieldName + operator: = + operandRight: some value + properties: '@type': type: string - example: null + example: https://w3id.org/edc/v0.0.1/ns/CriterionDto operandLeft: type: object example: null @@ -156,30 +149,6 @@ components: operator: type: string example: null - Duty: - type: object - example: null - properties: - action: - $ref: '#/components/schemas/Action' - assignee: - type: string - example: null - assigner: - type: string - example: null - consequence: - $ref: '#/components/schemas/Duty' - constraints: - type: array - example: null - items: - $ref: '#/components/schemas/Constraint' - parentPermission: - $ref: '#/components/schemas/Permission' - target: - type: string - example: null JsonArray: type: array example: null @@ -235,110 +204,25 @@ components: - "FALSE" - "NULL" example: null - Permission: + QuerySpecSchema: type: object - example: null - properties: - action: - $ref: '#/components/schemas/Action' - assignee: - type: string - example: null - assigner: - type: string - example: null - constraints: - type: array - example: null - items: - $ref: '#/components/schemas/Constraint' - duties: - type: array - example: null - items: - $ref: '#/components/schemas/Duty' - target: - type: string - example: null - Policy: - type: object - example: null - properties: - '@type': - type: string - enum: - - SET - - OFFER - - CONTRACT - example: null - assignee: - type: string - example: null - assigner: - type: string - example: null - extensibleProperties: - type: object - additionalProperties: - type: object - example: null - example: null - inheritsFrom: - type: string - example: null - obligations: - type: array - example: null - items: - $ref: '#/components/schemas/Duty' - permissions: - type: array - example: null - items: - $ref: '#/components/schemas/Permission' - prohibitions: - type: array - example: null - items: - $ref: '#/components/schemas/Prohibition' - target: - type: string - example: null - Prohibition: - type: object - example: null - properties: - action: - $ref: '#/components/schemas/Action' - assignee: - type: string - example: null - assigner: - type: string - example: null - constraints: - type: array - example: null - items: - $ref: '#/components/schemas/Constraint' - target: - type: string - example: null - QuerySpecDto: - type: object - example: null - properties: + example: '@context': - type: object - example: null + edc: https://w3id.org/edc/v0.0.1/ns/ + offset: 5 + limit: 10 + sortOrder: DESC + sortField: fieldName + criterion: [] + properties: '@type': type: string - example: null + example: https://w3id.org/edc/v0.0.1/ns/QuerySpecDto filterExpression: type: array example: null items: - $ref: '#/components/schemas/CriterionDto' + $ref: '#/components/schemas/CriterionSchema' limit: type: integer format: int32 diff --git a/spi/common/core-spi/src/main/java/org/eclipse/edc/spi/types/domain/asset/AssetEntry.java b/spi/common/core-spi/src/main/java/org/eclipse/edc/spi/types/domain/asset/AssetEntry.java index 460b40d6fe3..38541ac1071 100644 --- a/spi/common/core-spi/src/main/java/org/eclipse/edc/spi/types/domain/asset/AssetEntry.java +++ b/spi/common/core-spi/src/main/java/org/eclipse/edc/spi/types/domain/asset/AssetEntry.java @@ -18,6 +18,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.eclipse.edc.spi.types.domain.DataAddress; +@Deprecated(since = "0.1.2") public class AssetEntry { private final Asset asset; private final DataAddress dataAddress; diff --git a/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/AssetApiDeprecatedEndToEndTest.java b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/AssetApiDeprecatedEndToEndTest.java index 5846c63edb8..c3086a4a0c8 100644 --- a/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/AssetApiDeprecatedEndToEndTest.java +++ b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/AssetApiDeprecatedEndToEndTest.java @@ -15,7 +15,6 @@ package org.eclipse.edc.test.e2e.managementapi; import io.restassured.http.ContentType; -import io.restassured.specification.RequestSpecification; import jakarta.json.JsonObject; import jakarta.json.JsonObjectBuilder; import org.eclipse.edc.junit.annotations.EndToEndTest; @@ -27,7 +26,6 @@ import java.util.List; -import static io.restassured.RestAssured.given; import static jakarta.json.Json.createArrayBuilder; import static jakarta.json.Json.createObjectBuilder; import static java.util.Collections.emptyList; @@ -50,8 +48,6 @@ @Deprecated(since = "0.1.2") public class AssetApiDeprecatedEndToEndTest extends BaseManagementApiEndToEndTest { - private static final String BASE_PATH = "/management/v2/assets"; - private static final String TEST_ASSET_ID = "test-asset-id"; private static final String TEST_ASSET_CONTENTTYPE = "application/json"; private static final String TEST_ASSET_DESCRIPTION = "test description"; @@ -66,7 +62,7 @@ void getAssetById() { createDataAddress().build())); var body = baseRequest() - .get("/" + TEST_ASSET_ID) + .get("/v2/assets/" + TEST_ASSET_ID) .then() .statusCode(200) .extract().body().jsonPath(); @@ -106,7 +102,7 @@ void createAsset_shouldBeStored() { baseRequest() .contentType(ContentType.JSON) .body(assetNewJson) - .post() + .post("/v2/assets") .then() .log().ifError() .statusCode(200) @@ -135,7 +131,7 @@ void createAsset_shouldFail_whenBodyIsNotValid() { baseRequest() .contentType(ContentType.JSON) .body(assetNewJson) - .post() + .post("/v2/assets") .then() .log().ifError() .statusCode(400); @@ -171,7 +167,7 @@ void createAsset_withoutPrefix_shouldAddEdcNamespace() { baseRequest() .contentType(ContentType.JSON) .body(assetNewJson) - .post() + .post("/v2/assets") .then() .log().ifError() .statusCode(200) @@ -213,7 +209,7 @@ void queryAsset_byContentType() { baseRequest() .contentType(ContentType.JSON) .body(query) - .post("/request") + .post("/v2/assets/request") .then() .log().ifError() .statusCode(200) @@ -236,7 +232,7 @@ void queryAsset_byCustomStringProperty() { baseRequest() .contentType(ContentType.JSON) .body(query) - .post("/request") + .post("/v2/assets/request") .then() .log().ifError() .statusCode(200) @@ -261,7 +257,7 @@ void queryAsset_byCustomComplexProperty_whenJsonPathQuery_expectNoResult() { baseRequest() .contentType(ContentType.JSON) .body(query) - .post("/request") + .post("/v2/assets/request") .then() .log().ifError() .statusCode(200) @@ -286,7 +282,7 @@ void queryAsset_byCustomComplexProperty_whenLikeOperator_expectException() { baseRequest() .contentType(ContentType.JSON) .body(query) - .post("/request") + .post("/v2/assets/request") .then() .log().ifError() .statusCode(500); @@ -309,7 +305,7 @@ void updateAsset() { baseRequest() .contentType(ContentType.JSON) .body(assetJson) - .put() + .put("/v2/assets") .then() .log().all() .statusCode(204) @@ -327,7 +323,7 @@ void getDataAddress() { DataAddress.Builder.newInstance().type("test-type").property(EDC_NAMESPACE + "another-key", "another-value").build())); baseRequest() - .get("/test-asset/dataaddress") + .get("/v2/assets/test-asset/dataaddress") .then() .statusCode(200) .body("'edc:type'", equalTo("test-type")) @@ -371,28 +367,5 @@ private JsonObject createSingleFilterQuery(String leftOperand, String operator, .build(); } - private RequestSpecification baseRequest() { - return given() - .port(PORT) - .basePath(BASE_PATH) - .when(); - } - - private static class TestObject { - private final String description; - private final int number; - - TestObject(String description, int number) { - this.description = description; - this.number = number; - } - - public String getDescription() { - return description; - } - - public int getNumber() { - return number; - } - } + private record TestObject(String description, int number) { } } diff --git a/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/AssetApiEndToEndTest.java b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/AssetApiEndToEndTest.java index b904736a94e..d40cb373e28 100644 --- a/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/AssetApiEndToEndTest.java +++ b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/AssetApiEndToEndTest.java @@ -15,19 +15,16 @@ package org.eclipse.edc.test.e2e.managementapi; import io.restassured.http.ContentType; -import io.restassured.specification.RequestSpecification; import jakarta.json.JsonObject; import jakarta.json.JsonObjectBuilder; import org.eclipse.edc.junit.annotations.EndToEndTest; import org.eclipse.edc.spi.asset.AssetIndex; import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.spi.types.domain.asset.Asset; -import org.eclipse.edc.spi.types.domain.asset.AssetEntry; import org.junit.jupiter.api.Test; import java.util.List; -import static io.restassured.RestAssured.given; import static jakarta.json.Json.createArrayBuilder; import static jakarta.json.Json.createObjectBuilder; import static java.util.Collections.emptyList; @@ -46,8 +43,6 @@ @EndToEndTest public class AssetApiEndToEndTest extends BaseManagementApiEndToEndTest { - private static final String BASE_PATH = "/management/v3/assets"; - private static final String TEST_ASSET_ID = "test-asset-id"; private static final String TEST_ASSET_CONTENTTYPE = "application/json"; private static final String TEST_ASSET_DESCRIPTION = "test description"; @@ -61,7 +56,7 @@ void getAssetById() { .create(createAsset().dataAddress(createDataAddress().type("addressType").build()).build()); var body = baseRequest() - .get("/" + TEST_ASSET_ID) + .get("/v3/assets/" + TEST_ASSET_ID) .then() .statusCode(200) .extract().body().jsonPath(); @@ -94,7 +89,7 @@ void createAsset_shouldBeStored() { baseRequest() .contentType(ContentType.JSON) .body(assetJson) - .post() + .post("/v3/assets") .then() .log().ifError() .statusCode(200) @@ -117,7 +112,7 @@ void createAsset_shouldFail_whenBodyIsNotValid() { baseRequest() .contentType(ContentType.JSON) .body(assetJson) - .post() + .post("/v3/assets") .then() .log().ifError() .statusCode(400); @@ -145,7 +140,7 @@ void createAsset_withoutPrefix_shouldAddEdcNamespace() { baseRequest() .contentType(ContentType.JSON) .body(assetJson) - .post() + .post("/v3/assets") .then() .log().ifError() .statusCode(200) @@ -171,9 +166,9 @@ void createAsset_withoutPrefix_shouldAddEdcNamespace() { @Test void queryAsset_byContentType() { //insert one asset into the index + var asset = Asset.Builder.newInstance().id("test-asset").contentType("application/octet-stream").dataAddress(createDataAddress().build()).build(); controlPlane.getContext().getService(AssetIndex.class) - .create(new AssetEntry(Asset.Builder.newInstance().id("test-asset").contentType("application/octet-stream").build(), - createDataAddress().build())); + .create(asset); var query = createObjectBuilder() .add(CONTEXT, createObjectBuilder().add(EDC_PREFIX, EDC_NAMESPACE)) @@ -187,7 +182,7 @@ void queryAsset_byContentType() { baseRequest() .contentType(ContentType.JSON) .body(query) - .post("/request") + .post("/v3/assets/request") .then() .log().ifError() .statusCode(200) @@ -198,19 +193,19 @@ void queryAsset_byContentType() { void queryAsset_byCustomStringProperty() { //insert one asset into the index var assetIndex = controlPlane.getContext().getService(AssetIndex.class); - assetIndex.create(new AssetEntry(Asset.Builder.newInstance() + assetIndex.create(Asset.Builder.newInstance() .id("test-asset") .contentType("application/octet-stream") .property("myProp", "myVal") - .build(), - createDataAddress().build())); + .dataAddress(createDataAddress().build()) + .build()); var query = createSingleFilterQuery("myProp", "=", "myVal"); baseRequest() .contentType(ContentType.JSON) .body(query) - .post("/request") + .post("/v3/assets/request") .then() .log().ifError() .statusCode(200) @@ -221,13 +216,13 @@ void queryAsset_byCustomStringProperty() { void queryAsset_byCustomComplexProperty_whenJsonPathQuery_expectNoResult() { //insert one asset into the index var assetIndex = controlPlane.getContext().getService(AssetIndex.class); - assetIndex.create(new AssetEntry(Asset.Builder.newInstance() + assetIndex.create(Asset.Builder.newInstance() .id("test-asset") .contentType("application/octet-stream") // use a custom, complex object type .property("myProp", new TestObject("test desc", 42)) - .build(), - createDataAddress().build())); + .dataAddress(createDataAddress().build()) + .build()); var query = createSingleFilterQuery("myProp.description", "=", "test desc"); @@ -235,7 +230,7 @@ void queryAsset_byCustomComplexProperty_whenJsonPathQuery_expectNoResult() { baseRequest() .contentType(ContentType.JSON) .body(query) - .post("/request") + .post("/v3/assets/request") .then() .log().ifError() .statusCode(200) @@ -246,13 +241,13 @@ void queryAsset_byCustomComplexProperty_whenJsonPathQuery_expectNoResult() { void queryAsset_byCustomComplexProperty_whenLikeOperator_expectException() { //insert one asset into the index var assetIndex = controlPlane.getContext().getService(AssetIndex.class); - assetIndex.create(new AssetEntry(Asset.Builder.newInstance() + assetIndex.create(Asset.Builder.newInstance() .id("test-asset") .contentType("application/octet-stream") // use a custom, complex object type .property("myProp", new TestObject("test desc", 42)) - .build(), - createDataAddress().build())); + .dataAddress(createDataAddress().build()) + .build()); var query = createSingleFilterQuery("myProp", "LIKE", "test desc"); @@ -260,7 +255,7 @@ void queryAsset_byCustomComplexProperty_whenLikeOperator_expectException() { baseRequest() .contentType(ContentType.JSON) .body(query) - .post("/request") + .post("/v3/assets/request") .then() .log().ifError() .statusCode(500); @@ -270,7 +265,7 @@ void queryAsset_byCustomComplexProperty_whenLikeOperator_expectException() { void updateAsset() { var asset = createAsset(); var assetIndex = controlPlane.getContext().getService(AssetIndex.class); - assetIndex.create(new AssetEntry(asset.build(), createDataAddress().build())); + assetIndex.create(asset.build()); var assetJson = createObjectBuilder() .add(CONTEXT, createObjectBuilder().add(EDC_PREFIX, EDC_NAMESPACE)) @@ -285,7 +280,7 @@ void updateAsset() { baseRequest() .contentType(ContentType.JSON) .body(assetJson) - .put() + .put("/v3/assets") .then() .log().all() .statusCode(204) @@ -307,7 +302,8 @@ private Asset.Builder createAsset() { .name(TEST_ASSET_NAME) .description(TEST_ASSET_DESCRIPTION) .contentType(TEST_ASSET_CONTENTTYPE) - .version(TEST_ASSET_VERSION); + .version(TEST_ASSET_VERSION) + .dataAddress(createDataAddress().build()); } private JsonObjectBuilder createPropertiesBuilder() { @@ -334,12 +330,5 @@ private JsonObject createSingleFilterQuery(String leftOperand, String operator, .build(); } - private RequestSpecification baseRequest() { - return given() - .port(PORT) - .basePath(BASE_PATH) - .when(); - } - private record TestObject(String description, int number) { } } diff --git a/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/BaseManagementApiEndToEndTest.java b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/BaseManagementApiEndToEndTest.java index a9015d56c49..b63a4efe238 100644 --- a/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/BaseManagementApiEndToEndTest.java +++ b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/BaseManagementApiEndToEndTest.java @@ -14,17 +14,20 @@ package org.eclipse.edc.test.e2e.managementapi; +import io.restassured.specification.RequestSpecification; import org.eclipse.edc.junit.extensions.EdcRuntimeExtension; import org.junit.jupiter.api.extension.RegisterExtension; import java.util.HashMap; +import static io.restassured.RestAssured.given; import static org.eclipse.edc.junit.testfixtures.TestUtils.getFreePort; public abstract class BaseManagementApiEndToEndTest { public static final int PORT = getFreePort(); public static final int PROTOCOL_PORT = getFreePort(); + public static final String BASE_MANAGEMENT_URL = "http://localhost:" + PORT + "/management"; @RegisterExtension static EdcRuntimeExtension controlPlane = new EdcRuntimeExtension( @@ -42,4 +45,11 @@ public abstract class BaseManagementApiEndToEndTest { } } ); + + protected RequestSpecification baseRequest() { + return given() + .port(PORT) + .baseUri(BASE_MANAGEMENT_URL) + .when(); + } } diff --git a/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/CatalogApiEndToEndTest.java b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/CatalogApiEndToEndTest.java index ef008192045..2113214c111 100644 --- a/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/CatalogApiEndToEndTest.java +++ b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/CatalogApiEndToEndTest.java @@ -27,7 +27,6 @@ import java.util.UUID; -import static io.restassured.RestAssured.given; import static io.restassured.http.ContentType.JSON; import static jakarta.json.Json.createArrayBuilder; import static jakarta.json.Json.createObjectBuilder; @@ -52,12 +51,10 @@ void shouldReturnCatalog_withoutQuerySpec() { .add("protocol", "dataspace-protocol-http") .build(); - given() - .port(PORT) + baseRequest() .contentType(JSON) .body(requestBody) - .basePath("/management/v2/catalog") - .post("/request") + .post("/v2/catalog/request") .then() .statusCode(200) .contentType(JSON) @@ -66,8 +63,8 @@ void shouldReturnCatalog_withoutQuerySpec() { @Test void shouldReturnCatalog_withQuerySpec() { - var asset = createAsset("id-1").dataAddress(createDataAddress().build()); - var asset1 = createAsset("id-2").dataAddress(createDataAddress().build()); + var asset = createAsset("id-1").dataAddress(createDataAddress()); + var asset1 = createAsset("id-2").dataAddress(createDataAddress()); var assetIndex = controlPlane.getContext().getService(AssetIndex.class); var policyDefinitionStore = controlPlane.getContext().getService(PolicyDefinitionStore.class); @@ -113,12 +110,10 @@ void shouldReturnCatalog_withQuerySpec() { .add("querySpec", querySpec) .build(); - given() - .port(PORT) + baseRequest() .contentType(JSON) .body(requestBody) - .basePath("/management/v2/catalog") - .post("/request") + .post("/v2/catalog/request") .then() .statusCode(200) .contentType(JSON) @@ -127,8 +122,8 @@ void shouldReturnCatalog_withQuerySpec() { .extract().body().asString(); } - private DataAddress.Builder createDataAddress() { - return DataAddress.Builder.newInstance().type("test-type"); + private DataAddress createDataAddress() { + return DataAddress.Builder.newInstance().type("test-type").build(); } private Asset.Builder createAsset(String id) { diff --git a/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/ContractAgreementApiEndToEndTest.java b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/ContractAgreementApiEndToEndTest.java index 15f9441df41..72b6b1b4e1f 100644 --- a/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/ContractAgreementApiEndToEndTest.java +++ b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/ContractAgreementApiEndToEndTest.java @@ -14,7 +14,6 @@ package org.eclipse.edc.test.e2e.managementapi; -import io.restassured.specification.RequestSpecification; import org.eclipse.edc.connector.contract.spi.negotiation.store.ContractNegotiationStore; import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation; @@ -28,9 +27,9 @@ import java.util.Set; import java.util.UUID; -import static io.restassured.RestAssured.given; import static io.restassured.http.ContentType.JSON; import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationStates.FINALIZED; import static org.hamcrest.Matchers.is; @EndToEndTest @@ -44,7 +43,7 @@ void getAll() { var jsonPath = baseRequest() .contentType(JSON) - .post("/request") + .post("/v2/contractagreements/request") .then() .log().ifError() .statusCode(200) @@ -52,12 +51,10 @@ void getAll() { .body("size()", is(2)) .extract().jsonPath(); - // must use bracket notation when using keys with a colon - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors - assertThat((String) jsonPath.get("[0]['edc:assetId']")).isNotNull(); - assertThat((String) jsonPath.get("[1]['edc:assetId']")).isNotNull(); - assertThat((String) jsonPath.get("[0].@id")).isIn("cn1", "cn2"); - assertThat((String) jsonPath.get("[1].@id")).isIn("cn1", "cn2"); + assertThat(jsonPath.getString("[0]['edc:assetId']")).isNotNull(); + assertThat(jsonPath.getString("[1]['edc:assetId']")).isNotNull(); + assertThat(jsonPath.getString("[0].@id")).isIn("cn1", "cn2"); + assertThat(jsonPath.getString("[1].@id")).isIn("cn1", "cn2"); } @Test @@ -67,22 +64,16 @@ void getById() { var json = baseRequest() .contentType(JSON) - .get("cn1") + .get("/v2/contractagreements/cn1") .then() .statusCode(200) .contentType(JSON) .extract().jsonPath(); - assertThat((String) json.get("@id")).isEqualTo("cn1"); + assertThat(json.getString("@id")).isEqualTo("cn1"); assertThat(json.getString("'edc:assetId'")).isNotNull(); } - private RequestSpecification baseRequest() { - return given() - .baseUri("http://localhost:" + PORT + "/management/v2/contractagreements") - .when(); - } - private ContractNegotiation.Builder createContractNegotiationBuilder(String negotiationId) { return ContractNegotiation.Builder.newInstance() .id(negotiationId) @@ -93,7 +84,8 @@ private ContractNegotiation.Builder createContractNegotiationBuilder(String nego .events(Set.of("test-event1", "test-event2")) .build())) .protocol("dataspace-protocol-http") - .contractOffer(contractOfferBuilder().build()); + .contractOffer(contractOfferBuilder().build()) + .state(FINALIZED.code()); } private ContractOffer.Builder contractOfferBuilder() { @@ -103,7 +95,6 @@ private ContractOffer.Builder contractOfferBuilder() { .policy(Policy.Builder.newInstance().build()); } - private ContractAgreement createContractAgreement(String negotiationId) { return ContractAgreement.Builder.newInstance() .id(negotiationId) diff --git a/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/ContractDefinitionApiEndToEndTest.java b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/ContractDefinitionApiEndToEndTest.java index a33567809e6..bef49db3b5c 100644 --- a/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/ContractDefinitionApiEndToEndTest.java +++ b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/ContractDefinitionApiEndToEndTest.java @@ -14,7 +14,6 @@ package org.eclipse.edc.test.e2e.managementapi; -import io.restassured.specification.RequestSpecification; import jakarta.json.JsonArray; import jakarta.json.JsonObjectBuilder; import org.eclipse.edc.connector.contract.spi.offer.store.ContractDefinitionStore; @@ -23,7 +22,6 @@ import org.eclipse.edc.spi.query.QuerySpec; import org.junit.jupiter.api.Test; -import static io.restassured.RestAssured.given; import static io.restassured.http.ContentType.JSON; import static jakarta.json.Json.createArrayBuilder; import static jakarta.json.Json.createObjectBuilder; @@ -51,7 +49,7 @@ void queryContractDefinitions_noQuerySpec() { var body = baseRequest() .contentType(JSON) - .post("/request") + .post("/v2/contractdefinitions/request") .then() .statusCode(200) .body("size()", greaterThan(0)) @@ -70,7 +68,7 @@ void createContractDef() { baseRequest() .contentType(JSON) .body(requestJson) - .post() + .post("/v2/contractdefinitions") .then() .statusCode(200) .body("@id", equalTo(TEST_ID)); @@ -86,7 +84,7 @@ void delete() { store.save(entity); baseRequest() - .delete(entity.getId()) + .delete("/v2/contractdefinitions/" + entity.getId()) .then() .statusCode(204); @@ -106,7 +104,7 @@ void update_whenExists() { baseRequest() .contentType(JSON) .body(updated) - .put() + .put("/v2/contractdefinitions") .then() .statusCode(204); @@ -127,7 +125,7 @@ void update_whenNotExists() { baseRequest() .contentType(JSON) .body(updated) - .put() + .put("/v2/contractdefinitions") .then() .statusCode(404); @@ -135,13 +133,6 @@ void update_whenNotExists() { assertThat(all).isEmpty(); } - private RequestSpecification baseRequest() { - return given() - .port(PORT) - .basePath("/management/v2/contractdefinitions") - .when(); - } - private JsonObjectBuilder createDefinitionBuilder() { return createObjectBuilder() .add(CONTEXT, createObjectBuilder().add(EDC_PREFIX, EDC_NAMESPACE)) diff --git a/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/ContractNegotiationApiEndToEndTest.java b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/ContractNegotiationApiEndToEndTest.java index 6a116ddf4e9..372283ab84f 100644 --- a/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/ContractNegotiationApiEndToEndTest.java +++ b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/ContractNegotiationApiEndToEndTest.java @@ -14,7 +14,6 @@ package org.eclipse.edc.test.e2e.managementapi; -import io.restassured.specification.RequestSpecification; import jakarta.json.Json; import jakarta.json.JsonArrayBuilder; import jakarta.json.JsonObject; @@ -32,7 +31,6 @@ import java.util.Map; import java.util.Set; -import static io.restassured.RestAssured.given; import static io.restassured.http.ContentType.JSON; import static jakarta.json.Json.createObjectBuilder; import static java.util.UUID.randomUUID; @@ -61,7 +59,7 @@ void getAll() { var jsonPath = baseRequest() .contentType(JSON) - .post("/request") + .post("/v2/contractnegotiations/request") .then() .statusCode(200) .contentType(JSON) @@ -82,7 +80,7 @@ void getById() { var json = baseRequest() .contentType(JSON) - .get("cn1") + .get("/v2/contractnegotiations/cn1") .then() .statusCode(200) .contentType(JSON) @@ -100,7 +98,7 @@ void getState() { baseRequest() .contentType(JSON) - .get("cn1/state") + .get("/v2/contractnegotiations/cn1/state") .then() .statusCode(200) .contentType(JSON) @@ -115,7 +113,7 @@ void getAgreementForNegotiation() { var json = baseRequest() .contentType(JSON) - .get("cn1/agreement") + .get("/v2/contractnegotiations/cn1/agreement") .then() .statusCode(200) .contentType(JSON) @@ -146,7 +144,7 @@ void initiateNegotiation() { var id = baseRequest() .contentType(JSON) .body(requestJson) - .post() + .post("/v2/contractnegotiations") .then() .statusCode(200) .contentType(JSON) @@ -164,7 +162,7 @@ void cancel() { baseRequest() .contentType(JSON) - .post("cn1/cancel") + .post("/v2/contractnegotiations/cn1/cancel") .then() .statusCode(204); } @@ -176,18 +174,11 @@ void decline() { baseRequest() .contentType(JSON) - .post("cn1/decline") + .post("/v2/contractnegotiations/cn1/decline") .then() .statusCode(204); } - private RequestSpecification baseRequest() { - return given() - .port(PORT) - .basePath("/management/v2/contractnegotiations") - .when(); - } - private ContractNegotiation createContractNegotiation(String negotiationId) { return createContractNegotiationBuilder(negotiationId) .build(); diff --git a/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/PolicyDefinitionApiEndToEndTest.java b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/PolicyDefinitionApiEndToEndTest.java index c9e2908b618..9612ecba108 100644 --- a/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/PolicyDefinitionApiEndToEndTest.java +++ b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/PolicyDefinitionApiEndToEndTest.java @@ -14,7 +14,6 @@ package org.eclipse.edc.test.e2e.managementapi; -import io.restassured.specification.RequestSpecification; import jakarta.json.JsonArray; import jakarta.json.JsonObject; import org.eclipse.edc.connector.policy.spi.PolicyDefinition; @@ -24,7 +23,6 @@ import org.eclipse.edc.spi.entity.Entity; import org.junit.jupiter.api.Test; -import static io.restassured.RestAssured.given; import static io.restassured.http.ContentType.JSON; import static jakarta.json.Json.createArrayBuilder; import static jakarta.json.Json.createObjectBuilder; @@ -40,8 +38,6 @@ @EndToEndTest public class PolicyDefinitionApiEndToEndTest extends BaseManagementApiEndToEndTest { - private static final String BASE_PATH = "/management/v2/policydefinitions"; - @Test void shouldStorePolicyDefinition() { var requestBody = createObjectBuilder() @@ -55,7 +51,7 @@ void shouldStorePolicyDefinition() { var id = baseRequest() .body(requestBody) .contentType(JSON) - .post() + .post("/v2/policydefinitions") .then() .contentType(JSON) .extract().jsonPath().getString(ID); @@ -65,7 +61,7 @@ void shouldStorePolicyDefinition() { .extracting(Policy::getPermissions).asList().hasSize(1); baseRequest() - .get("/" + id) + .get("/v2/policydefinitions/" + id) .then() .statusCode(200) .contentType(JSON) @@ -88,14 +84,14 @@ void shouldUpdate() { var id = baseRequest() .body(requestBody) .contentType(JSON) - .post() + .post("/v2/policydefinitions") .then() .statusCode(200) .extract().jsonPath().getString(ID); var createdAt = baseRequest() .contentType(JSON) - .post("/request") + .post("/v2/policydefinitions/request") .then() .statusCode(200) .extract().as(JsonArray.class) @@ -105,7 +101,7 @@ void shouldUpdate() { baseRequest() .contentType(JSON) .body(createObjectBuilder(requestBody).add(ID, id).build()) - .put("/" + id) + .put("/v2/policydefinitions/" + id) .then() .statusCode(204); @@ -128,28 +124,22 @@ void shouldDelete() { var id = baseRequest() .body(requestBody) .contentType(JSON) - .post() + .post("/v2/policydefinitions") .then() .statusCode(200) .extract().jsonPath().getString(ID); baseRequest() - .delete("/" + id) + .delete("/v2/policydefinitions/" + id) .then() .statusCode(204); baseRequest() - .get("/" + id) + .get("/v2/policydefinitions/" + id) .then() .statusCode(404); } - private RequestSpecification baseRequest() { - return given() - .port(PORT) - .basePath(BASE_PATH); - } - private JsonObject sampleOdrlPolicy() { return createObjectBuilder() .add(CONTEXT, "http://www.w3.org/ns/odrl.jsonld") diff --git a/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/TransferProcessApiEndToEndTest.java b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/TransferProcessApiEndToEndTest.java index c925868ac9b..f4ab9170cdf 100644 --- a/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/TransferProcessApiEndToEndTest.java +++ b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/TransferProcessApiEndToEndTest.java @@ -14,7 +14,6 @@ package org.eclipse.edc.test.e2e.managementapi; -import io.restassured.specification.RequestSpecification; import jakarta.json.Json; import jakarta.json.JsonArrayBuilder; import org.eclipse.edc.connector.transfer.spi.store.TransferProcessStore; @@ -28,7 +27,6 @@ import java.util.List; import java.util.UUID; -import static io.restassured.RestAssured.given; import static io.restassured.http.ContentType.JSON; import static jakarta.json.Json.createObjectBuilder; import static java.util.Collections.emptySet; @@ -50,8 +48,6 @@ @EndToEndTest public class TransferProcessApiEndToEndTest extends BaseManagementApiEndToEndTest { - public static final String BASE_PATH = "/management/v2/transferprocesses"; - @Test void getAll() { getStore().updateOrCreate(createTransferProcess("tp1")); @@ -59,7 +55,7 @@ void getAll() { baseRequest() .contentType(JSON) - .post("/request") + .post("/v2/transferprocesses/request") .then() .statusCode(200) .body("size()", is(2)) @@ -73,7 +69,7 @@ void getById() { getStore().updateOrCreate(createTransferProcess("tp2")); baseRequest() - .get("/tp2") + .get("/v2/transferprocesses/tp2") .then() .statusCode(200) .body("@id", is("tp2")) @@ -85,7 +81,7 @@ void getState() { getStore().updateOrCreate(createTransferProcessBuilder("tp2").state(COMPLETED.code()).build()); baseRequest() - .get("/tp2/state") + .get("/v2/transferprocesses/tp2/state") .then() .statusCode(200) .contentType(JSON) @@ -117,7 +113,7 @@ void create() { var id = baseRequest() .contentType(JSON) .body(requestBody) - .post("/") + .post("/v2/transferprocesses/") .then() .log().ifError() .statusCode(200) @@ -133,7 +129,7 @@ void deprovision() { baseRequest() .contentType(JSON) - .post("/" + id + "/deprovision") + .post("/v2/transferprocesses/" + id + "/deprovision") .then() .statusCode(204); } @@ -150,7 +146,7 @@ void terminate() { baseRequest() .contentType(JSON) .body(requestBody) - .post("/" + id + "/terminate") + .post("/v2/transferprocesses/" + id + "/terminate") .then() .log().ifError() .statusCode(204); @@ -186,10 +182,4 @@ private JsonArrayBuilder createCallbackAddress() { .add(EVENTS, Json.createArrayBuilder().build())); } - private RequestSpecification baseRequest() { - return given() - .port(PORT) - .basePath(BASE_PATH) - .when(); - } }