Skip to content

Commit

Permalink
chore: clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
richardtreier committed Sep 13, 2023
1 parent e7edfdc commit 87aa8a0
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public Policy buildPolicy(JsonObject policyJsonLd) {
* @return {@link Policy}
*/
public Policy buildPolicy(String policyJsonLd) {
return buildPolicy(JsonUtils.parseJson(policyJsonLd));
return buildPolicy(JsonUtils.parseJsonObj(policyJsonLd));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package de.sovity.edc.ext.wrapper.api.common.mappers;

import com.fasterxml.jackson.databind.ObjectMapper;
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.MappingErrors;
import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyConstraint;
import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyCreateRequest;
import jakarta.json.JsonObject;
import lombok.SneakyThrows;
import org.eclipse.edc.policy.model.AtomicConstraint;
import org.eclipse.edc.policy.model.Policy;
import org.eclipse.edc.policy.model.PolicyType;
import org.eclipse.edc.spi.result.Result;
import org.eclipse.edc.transform.spi.TypeTransformerRegistry;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
Expand All @@ -19,6 +21,7 @@

import java.util.List;

import static de.sovity.edc.utils.JsonUtils.parseJsonObj;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
Expand All @@ -31,7 +34,7 @@ class PolicyMapperTest {
PolicyMapper policyMapper;

@Mock
ObjectMapper jsonLdObjectMapper;
TypeTransformerRegistry transformerRegistry;

@Mock
ConstraintExtractor constraintExtractor;
Expand All @@ -53,13 +56,13 @@ void test_buildPolicyDto() {

mappingErrors.when(MappingErrors::root).thenReturn(errors);
when(constraintExtractor.getPermissionConstraints(policy, errors)).thenReturn(constraints);
when(jsonLdObjectMapper.writeValueAsString(policy)).thenReturn("abc");
when(transformerRegistry.transform(policy, JsonObject.class)).thenReturn(Result.success(parseJsonObj("{}")));

// act
var actual = policyMapper.buildUiPolicy(policy);

// assert
assertThat(actual.getPolicyJsonLd()).isEqualTo("abc");
assertThat(actual.getPolicyJsonLd()).isEqualTo("{}");
assertThat(actual.getConstraints()).isEqualTo(constraints);
assertThat(actual.getErrors()).isEqualTo(List.of("error1"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@
import de.sovity.edc.ext.wrapper.api.ui.pages.asset.AssetApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.asset.AssetBuilder;
import de.sovity.edc.ext.wrapper.api.ui.pages.catalog.CatalogApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.ContractAgreementPageApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.ContractAgreementTransferApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions.ContractDefinitionApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions.ContractDefinitionBuilder;
import de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions.CriterionMapper;
import de.sovity.edc.ext.wrapper.api.ui.pages.contract_negotiations.ContractNegotiationApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.contract_negotiations.ContractNegotiationBuilder;
import de.sovity.edc.ext.wrapper.api.ui.pages.contract_negotiations.ContractOfferMapper;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.ContractAgreementPageApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.ContractAgreementTransferApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services.ContractAgreementDataFetcher;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services.ContractAgreementPageCardBuilder;
import de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions.ContractDefinitionBuilder;
import de.sovity.edc.ext.wrapper.api.ui.pages.contract_negotiations.ContractNegotiationBuilder;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services.TransferProcessStateService;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services.TransferRequestBuilder;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services.ContractAgreementUtils;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services.ContractNegotiationUtils;
import de.sovity.edc.ext.wrapper.api.ui.pages.contract_negotiations.ContractOfferMapper;
import de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions.CriterionMapper;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services.TransferProcessStateService;
import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services.TransferRequestBuilder;
import de.sovity.edc.ext.wrapper.api.ui.pages.policy.PolicyDefinitionApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.transferhistory.TransferHistoryPageApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.transferhistory.TransferHistoryPageAssetFetcherService;
Expand All @@ -49,8 +49,8 @@
import de.sovity.edc.ext.wrapper.api.usecase.services.PolicyMappingService;
import de.sovity.edc.ext.wrapper.api.usecase.services.SupportedPolicyApiService;
import de.sovity.edc.ext.wrapper.utils.EdcPropertyUtils;
import de.sovity.edc.utils.catalog.mapper.DspDataOfferBuilder;
import de.sovity.edc.utils.catalog.DspCatalogService;
import de.sovity.edc.utils.catalog.mapper.DspDataOfferBuilder;
import lombok.NoArgsConstructor;
import org.eclipse.edc.connector.contract.spi.negotiation.store.ContractNegotiationStore;
import org.eclipse.edc.connector.contract.spi.offer.store.ContractDefinitionStore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

package de.sovity.edc.ext.wrapper.utils;

import de.sovity.edc.ext.wrapper.utils.EdcPropertyUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -23,7 +22,7 @@

import static org.assertj.core.api.Assertions.assertThat;

class AssetPropertyMapperTest {
class EdcPropertyUtilsTest {
EdcPropertyUtils edcPropertyUtils;

@BeforeEach
Expand Down
5 changes: 5 additions & 0 deletions launchers/connectors/sovity-dev/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ application {
mainClass.set("org.eclipse.edc.boot.system.runtime.BaseRuntime")
}

tasks.withType<Test>().configureEach {
// These E2E Test should run in sequence to avoid conflicts
maxParallelForks = 1
}

tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
mergeServiceFiles()
archiveFileName.set("app.jar")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@
import de.sovity.edc.extension.e2e.db.TestDatabaseFactory;
import org.awaitility.Awaitility;
import org.eclipse.edc.junit.extensions.EdcExtension;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.util.List;
import java.util.UUID;

import static de.sovity.edc.extension.e2e.connector.DataTransferTestUtil.validateDataTransferred;
Expand Down Expand Up @@ -83,7 +81,7 @@ void setup() {
// TODO test policy conversion
// TODO test asset creation, make this test a full circle in data offering and consumption via the UI API
@Test
void testDataTransfer_freshDataOffer__negotiationViaUiApi() {
void testNegotiationViaUiApi() {
// arrange
var providerEndpoint = providerConnector.getConfig().getProtocolEndpoint().getUri().toString();
var data = "expected data 123";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
/*
* Copyright (c) 2023 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 - init
*/

package de.sovity.edc.utils.catalog;

import de.sovity.edc.utils.JsonUtils;
import de.sovity.edc.utils.catalog.mapper.DspDataOfferBuilder;
import de.sovity.edc.utils.catalog.model.DspDataOffer;
import de.sovity.edc.utils.JsonUtils;
import jakarta.json.JsonObject;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
Expand All @@ -25,7 +38,7 @@ public List<DspDataOffer> fetchDataOffers(String endpoint) {
private JsonObject fetchDcatResponse(String connectorEndpoint) {
var raw = fetchDcatRaw(connectorEndpoint);
var string = new String(raw, StandardCharsets.UTF_8);
return JsonUtils.parseJson(string);
return JsonUtils.parseJsonObj(string);
}

@SneakyThrows
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright (c) 2023 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 - init
*/

package de.sovity.edc.utils.catalog.mapper;

import de.sovity.edc.utils.catalog.model.DspContractOffer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright (c) 2023 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 - init
*/

package de.sovity.edc.utils.catalog.model;

import jakarta.json.JsonObject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright (c) 2023 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 - init
*/

package de.sovity.edc.utils.catalog.model;

import jakarta.json.JsonObject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright (c) 2023 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 - init
*/

package de.sovity.edc.utils;

import jakarta.json.Json;
Expand All @@ -12,7 +25,7 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class JsonUtils {

public static JsonObject parseJson(String string) {
public static JsonObject parseJsonObj(String string) {
try (var reader = Json.createReader(new StringReader(string))) {
return reader.readObject();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright (c) 2023 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 - init
*/

package de.sovity.edc.utils.jsonld;

import jakarta.json.JsonNumber;
Expand All @@ -19,10 +32,7 @@ public class JsonLdUtils {
* @return id or null
*/
public static String id(JsonObject json) {
if (json.containsKey("@id") && json.get("@id").getValueType() == JsonValue.ValueType.STRING) {
return json.getString("@id");
}
return null;
return string(json, "@id");
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright (c) 2023 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 - init
*/

package de.sovity.edc.utils.jsonld.vocab;

import lombok.experimental.UtilityClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class ConnectorRemote {
private final ConnectorRemoteConfig config;

private final ObjectMapper objectMapper = JacksonJsonLd.createObjectMapper();
public final Duration timeout = Duration.ofSeconds(60);
public final Duration timeout = Duration.ofSeconds(8);
private final JsonLd jsonLd = new TitaniumJsonLd(new ConsoleMonitor());

public void createAsset(String assetId, Map<String, Object> dataAddressProperties) {
Expand Down

0 comments on commit 87aa8a0

Please sign in to comment.