From f2f8a653cd100b74d76691f7e8dbbd10a2ef780c Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Tue, 19 Sep 2023 12:59:59 +0200 Subject: [PATCH] chore: improve code quality --- .../edc/client/AssetApiServiceTest.java | 6 +- .../model/utils/CustomDeserializer.java | 100 ------------------ .../AssetCreatorOrganizationNameJsonLd.java | 24 ----- ...MapperUtils.java => EdcPropertyUtils.java} | 9 +- .../common/mappers/utils/UiAssetMapper.java | 4 +- .../api/common/mappers/AssetMapperTest.java | 4 +- ...ilsTest.java => EdcPropertyUtilsTest.java} | 7 +- .../WrapperExtensionContextBuilder.java | 10 +- .../services/TransferRequestBuilder.java | 7 +- .../api/usecase/services/OfferingService.java | 4 +- .../usecase/services/OfferingServiceTest.java | 4 +- .../edc/ext/wrapper/utils/MapUtilsTest.java | 40 +++++++ .../de/sovity/edc/e2e/UiApiWrapperTest.java | 35 +++++- 13 files changed, 104 insertions(+), 150 deletions(-) delete mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/utils/CustomDeserializer.java delete mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetCreatorOrganizationNameJsonLd.java rename extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/{EdcPropertyMapperUtils.java => EdcPropertyUtils.java} (92%) rename extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/{EdcPropertyMapperUtilsTest.java => EdcPropertyUtilsTest.java} (86%) create mode 100644 extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/utils/MapUtilsTest.java diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java index a2db9a5fb..d568ea527 100644 --- a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java +++ b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java @@ -16,7 +16,7 @@ import de.sovity.edc.client.gen.model.UiAsset; import de.sovity.edc.client.gen.model.UiAssetCreateRequest; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyUtils; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.FailedMappingException; import de.sovity.edc.utils.jsonld.vocab.Prop; import lombok.SneakyThrows; @@ -41,12 +41,12 @@ public class AssetApiServiceTest { public static final String DATA_SINK = "http://my-data-sink/api/stuff"; - EdcPropertyMapperUtils edcPropertyUtils; + EdcPropertyUtils edcPropertyUtils; @BeforeEach void setUp(EdcExtension extension) { TestUtils.setupExtension(extension); - edcPropertyUtils = new EdcPropertyMapperUtils(); + edcPropertyUtils = new EdcPropertyUtils(); } @Test diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/utils/CustomDeserializer.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/utils/CustomDeserializer.java deleted file mode 100644 index faaf12e51..000000000 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/utils/CustomDeserializer.java +++ /dev/null @@ -1,100 +0,0 @@ -package de.sovity.edc.ext.wrapper.api.common.model.utils; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.BeanProperty; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.deser.ContextualDeserializer; -import lombok.AllArgsConstructor; -import lombok.NoArgsConstructor; -import lombok.SneakyThrows; - -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; - -@NoArgsConstructor -@AllArgsConstructor -public class CustomDeserializer extends JsonDeserializer implements ContextualDeserializer { - - private JavaType type; - - @Override - public JsonDeserializer createContextual(DeserializationContext deserializationContext, BeanProperty beanProperty) throws JsonMappingException { - JavaType type = deserializationContext.getContextualType() != null - ? deserializationContext.getContextualType() - : beanProperty.getMember().getType(); - return new CustomDeserializer(type); - } - - @SneakyThrows - @Override - public Object deserialize(JsonParser p, DeserializationContext deserializationContext) { - if (type.isTypeOrSubTypeOf(String.class)) { - return parseString(p); - } else if (type.isTypeOrSubTypeOf(Boolean.class)) { - return parseBoolean(p); - } else if (type.isTypeOrSubTypeOf(List.class)) { - return parseList(p); - } - return p.readValueAs(Object.class); - } - - @SneakyThrows - private String parseString(JsonParser p) { - if (p.isExpectedStartArrayToken()) { - return getFirstValueFromList(p.readValueAs(List.class)); - } else if (p.isExpectedStartObjectToken()) { - return extractValueFromMap(p.readValueAs(LinkedHashMap.class)); - } - return p.getText(); - } - - @SneakyThrows - private Boolean parseBoolean(JsonParser p) { - String valueAsString = p.isExpectedStartArrayToken() ? getFirstValueFromList(p.readValueAs(List.class)) : p.getText(); - if ("true".equalsIgnoreCase(valueAsString)) { - return true; - } else if ("false".equalsIgnoreCase(valueAsString)) { - return false; - } - return null; - } - - @SneakyThrows - private List parseList(JsonParser p) { - if (p.isExpectedStartArrayToken()) { - return p.readValueAs(List.class); - } - return Collections.singletonList(p.getText()); - } - - private String getFirstValueFromList(List list) { - if (list.isEmpty()) { - return null; - } - Object firstItem = list.get(0); - if (firstItem instanceof List) { - return getFirstValueFromList((List) firstItem); - } else if (firstItem instanceof LinkedHashMap) { - return extractValueFromMap((LinkedHashMap) firstItem); - } - return firstItem.toString(); - } - - @SneakyThrows - private String extractValueFromMap(LinkedHashMap map) { - Object valueObject = map.get("@value"); - - if (valueObject instanceof List) { - return getFirstValueFromList((List) valueObject); - - } else if (valueObject instanceof LinkedHashMap) { - return extractValueFromMap((LinkedHashMap) valueObject); - } - - return valueObject.toString(); - } -} diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetCreatorOrganizationNameJsonLd.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetCreatorOrganizationNameJsonLd.java deleted file mode 100644 index afdfa20d0..000000000 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetCreatorOrganizationNameJsonLd.java +++ /dev/null @@ -1,24 +0,0 @@ -package de.sovity.edc.ext.wrapper.api.common.mappers.utils; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; -import lombok.ToString; - - -@Getter -@Setter -@ToString -@AllArgsConstructor -@Builder(toBuilder = true) -@RequiredArgsConstructor -public class AssetCreatorOrganizationNameJsonLd { - @JsonProperty("@type") - private String type; - - @JsonProperty("http://xmlns.com/foaf/0.1/name") - private String name; -} diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyMapperUtils.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyUtils.java similarity index 92% rename from extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyMapperUtils.java rename to extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyUtils.java index 3096d8db5..5af531863 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyMapperUtils.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyUtils.java @@ -20,7 +20,7 @@ import java.util.Map; @RequiredArgsConstructor -public class EdcPropertyMapperUtils { +public class EdcPropertyUtils { /** * Converts a {@code Map} to {@code Map}. @@ -34,6 +34,10 @@ public class EdcPropertyMapperUtils { public Map truncateToMapOfString(Map map) { Map result = new HashMap<>(); + if (map == null) { + return result; + } + for (Map.Entry entry : map.entrySet()) { Object value = entry.getValue(); @@ -57,6 +61,9 @@ public Map truncateToMapOfString(Map map) { @SuppressWarnings({"unchecked", "rawtypes", "java:S1905"}) public Map toMapOfObject(Map map) { + if (map == null) { + return Map.of(); + } return new HashMap<>((Map) (Map) map); } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetMapper.java index f12760252..4ed2139b8 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetMapper.java @@ -21,7 +21,7 @@ @RequiredArgsConstructor public class UiAssetMapper { - private final EdcPropertyMapperUtils edcPropertyMapperUtils; + private final EdcPropertyUtils edcPropertyUtils; private final JsonLd jsonLd; public UiAsset buildUiAsset(JsonObject assetJsonLd) { @@ -122,7 +122,7 @@ private String trueIfTrue(Map dataAddressProperties, String key) } private JsonObjectBuilder getDataAddress(UiAssetCreateRequest uiAssetCreateRequest) { - var props = edcPropertyMapperUtils.toMapOfObject(uiAssetCreateRequest.getDataAddressProperties()); + var props = edcPropertyUtils.toMapOfObject(uiAssetCreateRequest.getDataAddressProperties()); return Json.createObjectBuilder() .add(Prop.TYPE, Prop.Edc.TYPE_DATA_ADDRESS) .add(Prop.Edc.PROPERTIES, Json.createObjectBuilder(props)); diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java index f4cd357eb..a3e97226f 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java @@ -1,6 +1,6 @@ package de.sovity.edc.ext.wrapper.api.common.mappers; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyUtils; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.UiAssetMapper; import de.sovity.edc.utils.JsonUtils; import de.sovity.edc.utils.jsonld.vocab.Prop; @@ -27,7 +27,7 @@ class AssetMapperTest { void setup() { var jsonLd = new TitaniumJsonLd(mock(Monitor.class)); var typeTransformerRegistry = mock(TypeTransformerRegistry.class); - var uiAssetBuilder = new UiAssetMapper(new EdcPropertyMapperUtils(), jsonLd); + var uiAssetBuilder = new UiAssetMapper(new EdcPropertyUtils(), jsonLd); assetMapper = new AssetMapper(typeTransformerRegistry, uiAssetBuilder, jsonLd); } diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyMapperUtilsTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyUtilsTest.java similarity index 86% rename from extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyMapperUtilsTest.java rename to extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyUtilsTest.java index a72d91b24..d95246d45 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyMapperUtilsTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyUtilsTest.java @@ -14,7 +14,6 @@ package de.sovity.edc.ext.wrapper.api.common.mappers.utils; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -23,12 +22,12 @@ import static org.assertj.core.api.Assertions.assertThat; -class EdcPropertyMapperUtilsTest { - EdcPropertyMapperUtils edcPropertyUtils; +class EdcPropertyUtilsTest { + EdcPropertyUtils edcPropertyUtils; @BeforeEach void setup() { - edcPropertyUtils = new EdcPropertyMapperUtils(); + edcPropertyUtils = new EdcPropertyUtils(); } @Test diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java index b4e7960dc..d58598873 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java @@ -20,7 +20,7 @@ import de.sovity.edc.ext.wrapper.api.common.mappers.PolicyMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.AtomicConstraintMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.ConstraintExtractor; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyUtils; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.LiteralMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.PolicyValidator; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.UiAssetMapper; @@ -119,8 +119,8 @@ public static WrapperExtensionContext buildContext( constraintExtractor, atomicConstraintMapper, typeTransformerRegistry); - var edcPropertyMapperUtils = new EdcPropertyMapperUtils(); - var assetBuilder = new UiAssetMapper(edcPropertyMapperUtils, jsonLd); + var edcPropertyUtils = new EdcPropertyUtils(); + var assetBuilder = new UiAssetMapper(edcPropertyUtils, jsonLd); var assetMapper = new AssetMapper(typeTransformerRegistry, assetBuilder, jsonLd); var transferProcessStateService = new TransferProcessStateService(); var contractAgreementPageCardBuilder = new ContractAgreementPageCardBuilder( @@ -159,7 +159,7 @@ public static WrapperExtensionContext buildContext( objectMapper, contractAgreementUtils, contractNegotiationUtils, - edcPropertyMapperUtils, + edcPropertyUtils, serviceExtensionContext.getConnectorId() ); var contractAgreementTransferApiService = new ContractAgreementTransferApiService( @@ -203,7 +203,7 @@ public static WrapperExtensionContext buildContext( policyDefinitionStore, contractDefinitionStore, policyMappingService, - edcPropertyMapperUtils); + edcPropertyUtils); var useCaseResource = new UseCaseResource( kpiApiService, supportedPolicyApiService, diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/TransferRequestBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/TransferRequestBuilder.java index 7db69b67e..ea093aa91 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/TransferRequestBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/TransferRequestBuilder.java @@ -15,7 +15,7 @@ package de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services; import com.fasterxml.jackson.databind.ObjectMapper; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyUtils; import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementTransferRequest; import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementTransferRequestParams; import lombok.RequiredArgsConstructor; @@ -24,7 +24,6 @@ import org.eclipse.edc.protocol.dsp.spi.types.HttpMessageProtocol; import java.util.List; -import java.util.Map; import java.util.Objects; import java.util.UUID; @@ -34,7 +33,7 @@ public class TransferRequestBuilder { private final ObjectMapper objectMapper; private final ContractAgreementUtils contractAgreementUtils; private final ContractNegotiationUtils contractNegotiationUtils; - private final EdcPropertyMapperUtils edcPropertyUtils; + private final EdcPropertyUtils edcPropertyUtils; private final String connectorId; public TransferRequest buildTransferRequest( @@ -63,7 +62,7 @@ private TransferRequest buildTransferRequest( .contractId(contractId) .assetId(agreement.getAssetId()) .dataDestination(address) - .privateProperties(edcPropertyUtils.toMapOfObject(params.getTransferProcessProperties() == null ? Map.of() : params.getTransferProcessProperties())) + .privateProperties(edcPropertyUtils.toMapOfObject(params.getTransferProcessProperties())) .callbackAddresses(List.of()) .build(); } diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingService.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingService.java index 0354ce64b..ad2f96c22 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingService.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingService.java @@ -1,6 +1,6 @@ package de.sovity.edc.ext.wrapper.api.usecase.services; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyUtils; import de.sovity.edc.ext.wrapper.api.usecase.model.AssetEntryDto; import de.sovity.edc.ext.wrapper.api.usecase.model.ContractDefinitionRequestDto; import de.sovity.edc.ext.wrapper.api.usecase.model.CreateOfferingDto; @@ -31,7 +31,7 @@ public class OfferingService { private final PolicyDefinitionStore policyDefinitionStore; private final ContractDefinitionStore contractDefinitionStore; private final PolicyMappingService policyMappingService; - private final EdcPropertyMapperUtils edcPropertyUtils; + private final EdcPropertyUtils edcPropertyUtils; /** * Creates the asset, policy and contract definition in the connector. First, transforms the diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingServiceTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingServiceTest.java index 90fe91948..8bd1dbbfc 100644 --- a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingServiceTest.java +++ b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingServiceTest.java @@ -1,6 +1,6 @@ package de.sovity.edc.ext.wrapper.api.usecase.services; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyUtils; import de.sovity.edc.ext.wrapper.api.common.model.PermissionDto; import de.sovity.edc.ext.wrapper.api.common.model.PolicyDto; import de.sovity.edc.ext.wrapper.api.usecase.model.AssetEntryDto; @@ -60,7 +60,7 @@ void setUp() { policyDefinitionStore, contractDefinitionStore, policyMappingService, - new EdcPropertyMapperUtils()); + new EdcPropertyUtils()); this.assetEntryDto = assetDto(); this.asset = asset(); diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/utils/MapUtilsTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/utils/MapUtilsTest.java new file mode 100644 index 000000000..cf8b53fd8 --- /dev/null +++ b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/utils/MapUtilsTest.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 sovity GmbH + * + * 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: + * sovity GmbH - initial API and implementation + * + */ + +package de.sovity.edc.ext.wrapper.utils; + +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +class MapUtilsTest { + + @Test + void mapValues() { + assertThat(MapUtils.mapValues(Map.of(1, "a"), String::toUpperCase)).isEqualTo(Map.of(1, "A")); + } + + @Test + void associateBy() { + assertThat(MapUtils.associateBy(List.of("a"), String::toUpperCase)).isEqualTo(Map.of("A", "a")); + } + + @Test + void reverse() { + assertThat(MapUtils.reverse(Map.of("a", 1))).isEqualTo(Map.of(1, "a")); + } +} diff --git a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java index 7d2ffdc84..d3ec020fb 100644 --- a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java +++ b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java @@ -108,10 +108,26 @@ void provide_consume_assetMapping_policyMapping() { var assetId = providerClient.uiApi().createAsset(UiAssetCreateRequest.builder() .id("asset-1") .name("AssetName") + .description("AssetDescription") + .licenseUrl("https://license-url") + .version("1.0.0") + .language("en") + .mediaType("application/json") + .dataCategory("dataCategory") + .dataSubcategory("dataSubcategory") + .dataModel("dataModel") + .geoReferenceMethod("geoReferenceMethod") + .transportMode("transportMode") .keywords(List.of("keyword1", "keyword2")) + .creatorOrganizationName("creatorOrganizationName") + .publisherHomepage("publisherHomepage") .dataAddressProperties(Map.of( Prop.Edc.TYPE, "HttpData", - Prop.Edc.BASE_URL, dataAddress.getDataSourceUrl(data) + Prop.Edc.BASE_URL, dataAddress.getDataSourceUrl(data), + Prop.Edc.PROXY_METHOD, "true", + Prop.Edc.PROXY_PATH, "true", + Prop.Edc.PROXY_QUERY_PARAMS, "true", + Prop.Edc.PROXY_BODY, "true" )) .build()).getId(); @@ -145,6 +161,23 @@ void provide_consume_assetMapping_policyMapping() { assertThat(dataOffer.getAsset().getAssetId()).isEqualTo(assetId); assertThat(dataOffer.getAsset().getKeywords()).isEqualTo(List.of("keyword1", "keyword2")); assertThat(dataOffer.getAsset().getName()).isEqualTo("AssetName"); + assertThat(dataOffer.getAsset().getDescription()).isEqualTo("AssetDescription"); + assertThat(dataOffer.getAsset().getVersion()).isEqualTo("1.0.0"); + assertThat(dataOffer.getAsset().getLanguage()).isEqualTo("en"); + assertThat(dataOffer.getAsset().getMediaType()).isEqualTo("application/json"); + assertThat(dataOffer.getAsset().getDataCategory()).isEqualTo("dataCategory"); + assertThat(dataOffer.getAsset().getDataSubcategory()).isEqualTo("dataSubcategory"); + assertThat(dataOffer.getAsset().getDataModel()).isEqualTo("dataModel"); + assertThat(dataOffer.getAsset().getGeoReferenceMethod()).isEqualTo("geoReferenceMethod"); + assertThat(dataOffer.getAsset().getTransportMode()).isEqualTo("transportMode"); + assertThat(dataOffer.getAsset().getLicenseUrl()).isEqualTo("https://license-url"); + assertThat(dataOffer.getAsset().getKeywords()).isEqualTo(List.of("keyword1", "keyword2")); + assertThat(dataOffer.getAsset().getCreatorOrganizationName()).isEqualTo("creatorOrganizationName"); + assertThat(dataOffer.getAsset().getPublisherHomepage()).isEqualTo("publisherHomepage"); + assertThat(dataOffer.getAsset().getHttpDatasourceHintsProxyMethod()).isTrue(); + assertThat(dataOffer.getAsset().getHttpDatasourceHintsProxyPath()).isTrue(); + assertThat(dataOffer.getAsset().getHttpDatasourceHintsProxyQueryParams()).isTrue(); + assertThat(dataOffer.getAsset().getHttpDatasourceHintsProxyBody()).isTrue(); validateDataTransferred(dataAddress.getDataSinkSpyUrl(), data); }