-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/sovity/edc-extensions into …
…461-add-contract-definition-page-to-the-api-wrapper # Conflicts: # extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java # extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java
- Loading branch information
Showing
9 changed files
with
481 additions
and
8 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
...pper/client/src/test/java/de/sovity/edc/client/GetTransferProcessAssetApiServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* 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 - initial API and implementation | ||
* | ||
*/ | ||
|
||
package de.sovity.edc.client; | ||
|
||
import org.eclipse.edc.connector.contract.spi.negotiation.store.ContractNegotiationStore; | ||
import org.eclipse.edc.connector.spi.asset.AssetService; | ||
import org.eclipse.edc.connector.transfer.spi.store.TransferProcessStore; | ||
import org.eclipse.edc.junit.annotations.ApiTest; | ||
import org.eclipse.edc.junit.extensions.EdcExtension; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import java.text.ParseException; | ||
import java.util.Map; | ||
|
||
import static de.sovity.edc.client.TransferProcessTestUtils.createConsumingTransferProcesses; | ||
import static de.sovity.edc.client.TransferProcessTestUtils.createProvidingTransferProcesses; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@ApiTest | ||
@ExtendWith(EdcExtension.class) | ||
class GetTransferProcessAssetApiServiceTest { | ||
|
||
@BeforeEach | ||
void setUp(EdcExtension extension) { | ||
extension.setConfiguration(TestUtils.createConfiguration(Map.of())); | ||
} | ||
|
||
@Test | ||
void testProviderTransferProcess(ContractNegotiationStore negotiationStore, | ||
TransferProcessStore transferProcessStore, | ||
AssetService assetStore) throws ParseException { | ||
|
||
var client = TestUtils.edcClient(); | ||
|
||
//arrange data | ||
createProvidingTransferProcesses(negotiationStore, transferProcessStore, assetStore); | ||
|
||
//act | ||
var providerAssetResult = client.uiApi().getTransferProcessAsset(TransferProcessTestUtils.PROVIDING_TRANSFER_PROCESS_ID); | ||
|
||
//assert | ||
assertThat(providerAssetResult.getAssetId()).isEqualTo(TransferProcessTestUtils.VALID_ASSET_ID); | ||
assertThat(providerAssetResult.getProperties().get("asset:prop:name")).isEqualTo(TransferProcessTestUtils.ASSET_NAME); | ||
} | ||
|
||
@Test | ||
void testConsumerTransferProcess(ContractNegotiationStore negotiationStore, | ||
TransferProcessStore transferProcessStore) throws ParseException { | ||
|
||
var client = TestUtils.edcClient(); | ||
|
||
//arrange data | ||
createConsumingTransferProcesses(negotiationStore, transferProcessStore); | ||
|
||
//act | ||
var consumerAssetResult = client.uiApi().getTransferProcessAsset(TransferProcessTestUtils.CONSUMING_TRANSFER_PROCESS_ID); | ||
|
||
//assert | ||
assertThat(consumerAssetResult.getAssetId()).isEqualTo(TransferProcessTestUtils.UNKNOWN_ASSET_ID); | ||
assertThat(consumerAssetResult.getProperties().get("asset:prop:name")).isNull(); | ||
} | ||
|
||
} |
87 changes: 87 additions & 0 deletions
87
.../wrapper/client/src/test/java/de/sovity/edc/client/TransferHistoryPageApiServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* 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 - initial API and implementation | ||
* | ||
*/ | ||
|
||
package de.sovity.edc.client; | ||
|
||
import org.eclipse.edc.connector.contract.spi.negotiation.store.ContractNegotiationStore; | ||
import org.eclipse.edc.connector.spi.asset.AssetService; | ||
import org.eclipse.edc.connector.transfer.spi.store.TransferProcessStore; | ||
import org.eclipse.edc.junit.annotations.ApiTest; | ||
import org.eclipse.edc.junit.extensions.EdcExtension; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import java.text.ParseException; | ||
import java.util.Map; | ||
|
||
import static de.sovity.edc.client.TransferProcessTestUtils.createConsumingTransferProcesses; | ||
import static de.sovity.edc.client.TransferProcessTestUtils.createProvidingTransferProcesses; | ||
import static de.sovity.edc.client.gen.model.TransferHistoryEntry.DirectionEnum.CONSUMING; | ||
import static de.sovity.edc.client.gen.model.TransferHistoryEntry.DirectionEnum.PROVIDING; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@ApiTest | ||
@ExtendWith(EdcExtension.class) | ||
class TransferHistoryPageApiServiceTest { | ||
|
||
@BeforeEach | ||
void setUp(EdcExtension extension) { | ||
extension.setConfiguration(TestUtils.createConfiguration(Map.of())); | ||
} | ||
|
||
@Test | ||
void startTransferProcessForAgreement( | ||
ContractNegotiationStore negotiationStore, | ||
TransferProcessStore transferProcessStore, | ||
AssetService assetStore | ||
) throws ParseException { | ||
var client = TestUtils.edcClient(); | ||
|
||
// arrange | ||
createProvidingTransferProcesses(negotiationStore, transferProcessStore, assetStore); | ||
createConsumingTransferProcesses(negotiationStore, transferProcessStore); | ||
|
||
// act | ||
var result = client.uiApi().transferHistoryPageEndpoint(); | ||
|
||
// get | ||
var transferProcess = result.getTransferEntries(); | ||
|
||
// assert for the order of entries | ||
assertThat(transferProcess.get(1).getTransferProcessId()).isEqualTo(TransferProcessTestUtils.PROVIDING_TRANSFER_PROCESS_ID); | ||
|
||
// assert for consuming request entry | ||
var consumingProcess = transferProcess.get(0); | ||
assertThat(consumingProcess.getTransferProcessId()).isEqualTo(TransferProcessTestUtils.CONSUMING_TRANSFER_PROCESS_ID); | ||
assertThat(consumingProcess.getAssetId()).isEqualTo(TransferProcessTestUtils.UNKNOWN_ASSET_ID); | ||
assertThat(consumingProcess.getCounterPartyConnectorEndpoint()).isEqualTo(TransferProcessTestUtils.COUNTER_PARTY_ADDRESS); | ||
assertThat(consumingProcess.getContractAgreementId()).isEqualTo(TransferProcessTestUtils.CONSUMING_CONTRACT_ID); | ||
assertThat(consumingProcess.getDirection()).isEqualTo(CONSUMING); | ||
assertThat(consumingProcess.getState().getCode()).isEqualTo(800); | ||
assertThat(consumingProcess.getAssetName()).isEqualTo(TransferProcessTestUtils.UNKNOWN_ASSET_ID); | ||
assertThat(consumingProcess.getErrorMessage()).isEqualTo(""); | ||
|
||
// assert for providing request entry | ||
var providingProcess = transferProcess.get(1); | ||
assertThat(providingProcess.getTransferProcessId()).isEqualTo(TransferProcessTestUtils.PROVIDING_TRANSFER_PROCESS_ID); | ||
assertThat(providingProcess.getAssetId()).isEqualTo(TransferProcessTestUtils.VALID_ASSET_ID); | ||
assertThat(providingProcess.getCounterPartyConnectorEndpoint()).isEqualTo(TransferProcessTestUtils.COUNTER_PARTY_ADDRESS); | ||
assertThat(providingProcess.getContractAgreementId()).isEqualTo(TransferProcessTestUtils.PROVIDING_CONTRACT_ID); | ||
assertThat(providingProcess.getDirection()).isEqualTo(PROVIDING); | ||
assertThat(providingProcess.getState().getCode()).isEqualTo(800); | ||
assertThat(providingProcess.getAssetName()).isEqualTo(TransferProcessTestUtils.ASSET_NAME); | ||
assertThat(providingProcess.getErrorMessage()).isEqualTo("TransferProcessManager: attempt #8 failed to send transfer"); | ||
} | ||
} |
142 changes: 142 additions & 0 deletions
142
extensions/wrapper/client/src/test/java/de/sovity/edc/client/TransferProcessTestUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package de.sovity.edc.client; | ||
|
||
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; | ||
import org.eclipse.edc.connector.spi.asset.AssetService; | ||
import org.eclipse.edc.connector.transfer.spi.store.TransferProcessStore; | ||
import org.eclipse.edc.connector.transfer.spi.types.DataRequest; | ||
import org.eclipse.edc.connector.transfer.spi.types.TransferProcess; | ||
import org.eclipse.edc.policy.model.Policy; | ||
import org.eclipse.edc.spi.types.domain.DataAddress; | ||
import org.eclipse.edc.spi.types.domain.asset.Asset; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.UUID; | ||
|
||
public class TransferProcessTestUtils { | ||
public static final String DATA_SINK = "http://my-data-sink/api/stuff"; | ||
public static final String COUNTER_PARTY_ADDRESS = "http://some-other-connector/api/v1/ids/data"; | ||
public static final String PROVIDING_CONTRACT_ID = "provider-contract:eb934d1f-6582-4bab-85e6-af19a76f7e2b"; | ||
public static final String CONSUMING_CONTRACT_ID = "consumer-contract:f52a5d30-6356-4a55-a75a-3c45d7a88c3e"; | ||
public static final String VALID_ASSET_ID = "urn:artifact:asset"; | ||
public static final String UNKNOWN_ASSET_ID = "urn:junk"; | ||
public static final String ASSET_NAME = "Test asset"; | ||
public static final String PROVIDING_TRANSFER_PROCESS_ID = "81cdf4cf-8427-480f-9662-8a29d66ddd3b"; | ||
public static final String CONSUMING_TRANSFER_PROCESS_ID = "be0cac12-bb43-420e-aa29-d66bb3d0e0ac"; | ||
|
||
@NotNull | ||
public static void createProvidingTransferProcesses(ContractNegotiationStore store, TransferProcessStore transferProcessStore, AssetService assetStore) throws ParseException { | ||
DataAddress dataAddress = getDataAddress(); | ||
createAsset(assetStore, dataAddress, VALID_ASSET_ID, ASSET_NAME); | ||
|
||
// preparing providing transfer process | ||
var providerAgreement = createContractAgreement(PROVIDING_CONTRACT_ID, VALID_ASSET_ID); | ||
createContractNegotiation(store, COUNTER_PARTY_ADDRESS, providerAgreement, ContractNegotiation.Type.PROVIDER); | ||
createTransferProcess(VALID_ASSET_ID, | ||
PROVIDING_CONTRACT_ID, | ||
dataAddress, | ||
TransferProcess.Type.PROVIDER, | ||
PROVIDING_TRANSFER_PROCESS_ID, | ||
"2023-07-08", | ||
"TransferProcessManager: attempt #8 failed to send transfer", | ||
transferProcessStore); | ||
} | ||
|
||
@NotNull | ||
public static void createConsumingTransferProcesses(ContractNegotiationStore store, TransferProcessStore transferProcessStore) throws ParseException { | ||
DataAddress dataAddress = getDataAddress(); | ||
|
||
// preparing consuming transfer process | ||
var consumerAgreement = createContractAgreement(CONSUMING_CONTRACT_ID, UNKNOWN_ASSET_ID); | ||
createContractNegotiation(store, COUNTER_PARTY_ADDRESS, consumerAgreement, ContractNegotiation.Type.CONSUMER); | ||
createTransferProcess(UNKNOWN_ASSET_ID, | ||
CONSUMING_CONTRACT_ID, | ||
dataAddress, | ||
TransferProcess.Type.CONSUMER, | ||
CONSUMING_TRANSFER_PROCESS_ID, | ||
"2023-07-10", | ||
"", | ||
transferProcessStore); | ||
} | ||
|
||
private static DataAddress getDataAddress() { | ||
var dataAddress = DataAddress.Builder.newInstance() | ||
.type("HttpData") | ||
.property("baseUrl", DATA_SINK) | ||
.build(); | ||
return dataAddress; | ||
} | ||
|
||
private static void createAsset(AssetService assetStore, DataAddress dataAddress, String assetId, String assetName) throws ParseException { | ||
var asset = Asset.Builder.newInstance() | ||
.id(assetId) | ||
.property("asset:prop:name", assetName) | ||
.createdAt(dateFormatterToLong("2023-06-01")) | ||
.build(); | ||
|
||
assetStore.create(asset, dataAddress); | ||
} | ||
|
||
private static ContractAgreement createContractAgreement( | ||
String agreementId, | ||
String assetId | ||
) { | ||
var agreement = ContractAgreement.Builder.newInstance() | ||
.id(agreementId) | ||
.providerAgentId(UUID.randomUUID().toString()) | ||
.consumerAgentId(UUID.randomUUID().toString()) | ||
.assetId(assetId) | ||
.policy(Policy.Builder.newInstance().build()) | ||
.build(); | ||
|
||
return agreement; | ||
} | ||
|
||
private static void createContractNegotiation( | ||
ContractNegotiationStore store, | ||
String counterPartyAddress, | ||
ContractAgreement agreement, | ||
ContractNegotiation.Type type | ||
) { | ||
var negotiation = ContractNegotiation.Builder.newInstance() | ||
.id(UUID.randomUUID().toString()) | ||
.counterPartyId(UUID.randomUUID().toString()) | ||
.counterPartyAddress(counterPartyAddress) | ||
.protocol("protocol") | ||
.contractAgreement(agreement) | ||
.type(type) | ||
.correlationId(UUID.randomUUID().toString()) | ||
.build(); | ||
|
||
store.save(negotiation); | ||
} | ||
|
||
private static void createTransferProcess(String assetId, String contractId, DataAddress dataAddress, TransferProcess.Type type, String transferProcessId, String lastUpdateDateForTransferProcess, String errorMessage, TransferProcessStore transferProcessStore) throws ParseException { | ||
|
||
var dataRequestForTransfer = DataRequest.Builder.newInstance() | ||
.assetId(assetId) | ||
.contractId(contractId) | ||
.dataDestination(dataAddress) | ||
.build(); | ||
|
||
var transferProcess = TransferProcess.Builder.newInstance() | ||
.id(transferProcessId) | ||
.type(type) | ||
.dataRequest(dataRequestForTransfer) | ||
.createdAt(dateFormatterToLong("2023-07-08")) | ||
.updatedAt(dateFormatterToLong(lastUpdateDateForTransferProcess)) | ||
.state(800) | ||
.errorDetail(errorMessage) | ||
.build(); | ||
|
||
transferProcessStore.save(transferProcess); | ||
} | ||
|
||
private static long dateFormatterToLong(String date) throws ParseException { | ||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); | ||
return formatter.parse(date).getTime(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.