Skip to content

Commit

Permalink
Add autocleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ununhexium committed Oct 25, 2024
1 parent d21233e commit 0b4e74c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 38 deletions.
26 changes: 11 additions & 15 deletions tests/src/test/java/de/sovity/edc/e2e/AssetApiServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void testAssetCreation(EdcClient client, AssetService assetService, Janitor jani
}

@Test
void testeditAsset(EdcClient client, AssetService assetService) {
void testeditAsset(EdcClient client, AssetService assetService, Janitor janitor) {
// arrange
var dataSource = UiDataSource.builder()
.type(DataSourceType.HTTP_DATA)
Expand All @@ -241,7 +241,7 @@ void testeditAsset(EdcClient client, AssetService assetService) {
.customProperties(Map.of("oauth2:tokenUrl", "https://token-url"))
.build();
var createRequest = UiAssetCreateRequest.builder()
.id("asset-41")
.id("asset-1")
.title("AssetTitle")
.description("AssetDescription")
.licenseUrl("https://license-url")
Expand Down Expand Up @@ -277,7 +277,8 @@ void testeditAsset(EdcClient client, AssetService assetService) {
""")
.build();

client.uiApi().createAsset(createRequest);
janitor.withClient(client).createAsset(createRequest);

var dataAddressBeforeEdit = assetService.query(QuerySpec.max())
.orElseThrow(FailedMappingException::ofFailure).toList().get(0)
.getDataAddress()
Expand Down Expand Up @@ -319,15 +320,15 @@ void testeditAsset(EdcClient client, AssetService assetService) {
.build();

// act
var response = client.uiApi().editAsset("asset-41", editRequest);
var response = client.uiApi().editAsset("asset-1", editRequest);

// assert
assertThat(response.getId()).isEqualTo("asset-41");
assertThat(response.getId()).isEqualTo("asset-1");

var assets = client.uiApi().getAssetPage().getAssets();
assertThat(assets).hasSize(1);
var asset = assets.get(0);
assertThat(asset.getAssetId()).isEqualTo("asset-41");
assertThat(asset.getAssetId()).isEqualTo("asset-1");
assertThat(asset.getTitle()).isEqualTo("AssetTitle 2");
assertThat(asset.getDescription()).isEqualTo("AssetDescription 2");
assertThat(asset.getVersion()).isEqualTo("2.0.0");
Expand Down Expand Up @@ -368,9 +369,6 @@ void testeditAsset(EdcClient client, AssetService assetService) {
.getDataAddress()
.getProperties();
assertThat(dataAddressAfterEdit).isEqualTo(dataAddressBeforeEdit);


client.uiApi().deleteAsset("asset-41");
}

@Test
Expand Down Expand Up @@ -403,7 +401,7 @@ void testAssetCreation_noProxying(EdcClient client, Janitor janitor) {
}

@Test
void testAssetCreation_differentDataAddressType(EdcClient client) {
void testAssetCreation_differentDataAddressType(EdcClient client, Janitor janitor) {
// arrange
var dataSource = UiDataSource.builder()
.type(DataSourceType.CUSTOM)
Expand All @@ -412,24 +410,22 @@ void testAssetCreation_differentDataAddressType(EdcClient client) {
))
.build();
var uiAssetRequest = UiAssetCreateRequest.builder()
.id("asset-61")
.id("asset-1")
.dataSource(dataSource)
.build();

// act
var response = client.uiApi().createAsset(uiAssetRequest);
var response = janitor.withClient(client).createAsset(uiAssetRequest);

// assert
assertThat(response.getId()).isEqualTo("asset-61");
assertThat(response.getId()).isEqualTo("asset-1");
var assets = client.uiApi().getAssetPage().getAssets();
assertThat(assets).hasSize(1);
var asset = assets.get(0);
assertThat(asset.getHttpDatasourceHintsProxyMethod()).isNull();
assertThat(asset.getHttpDatasourceHintsProxyPath()).isNull();
assertThat(asset.getHttpDatasourceHintsProxyQueryParams()).isNull();
assertThat(asset.getHttpDatasourceHintsProxyBody()).isNull();

client.uiApi().deleteAsset("asset-61");
}

@Test
Expand Down
29 changes: 7 additions & 22 deletions tests/src/test/java/de/sovity/edc/e2e/UseCaseApiWrapper2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ void shouldFetchFilteredDataOffersWithEq(
) {
// arrange
setupAssets(client, janitor);
buildContractDefinition(client, policyId, assetId1, "cd-1");
buildContractDefinition(client, policyId, assetId2, "cd-2");

// act
var catalogQueryParamsEq = criterion(Prop.Edc.ID, CatalogFilterExpressionOperator.EQ, "test-asset-1");
Expand All @@ -82,8 +80,6 @@ void shouldFetchFilteredDataOffersWithEq(
assertThat(dataOffers).hasSize(1);
assertThat(dataOffers.get(0).getAsset().getAssetId()).isEqualTo(assetId1);
assertThat(dataOffers.get(0).getAsset().getTitle()).isEqualTo("Test Asset 1");

cleanup(client);
}

@Test
Expand All @@ -94,8 +90,6 @@ void shouldFetchFilteredDataOffersWithIn(
) {
// arrange
setupAssets(client, janitor);
buildContractDefinition(client, policyId, assetId1, "cd-1");
buildContractDefinition(client, policyId, assetId2, "cd-2");

// act
var catalogQueryParamsEq = criterion(Prop.Edc.ID, CatalogFilterExpressionOperator.IN, List.of("test-asset-1", "test-asset-2"));
Expand All @@ -106,16 +100,6 @@ void shouldFetchFilteredDataOffersWithIn(
assertThat(dataOffers)
.extracting(it -> it.getAsset().getAssetId())
.containsExactlyInAnyOrder(assetId1, assetId2);

cleanup(client);
}

private static void cleanup(EdcClient client) {
client.uiApi().deleteAsset(assetId1);
client.uiApi().deleteAsset(assetId2);
client.uiApi().deleteContractDefinition("cd-1");
client.uiApi().deleteContractDefinition("cd-2");
client.uiApi().deletePolicyDefinition(policyId);
}

@Test
Expand All @@ -126,8 +110,6 @@ void shouldFetchWithoutFilterButWithLimit(
) {
// arrange
setupAssets(client, janitor);
buildContractDefinition(client, policyId, assetId1, "cd-1");
buildContractDefinition(client, policyId, assetId2, "cd-2");

// act
var catalogQueryParamsEq = criterion(1, 0);
Expand All @@ -138,8 +120,6 @@ void shouldFetchWithoutFilterButWithLimit(
assertThat(dataOffers)
.extracting(it -> it.getAsset().getAssetId())
.containsAnyOf(assetId1, assetId2);

cleanup(client);
}

private CatalogQuery criterion(
Expand Down Expand Up @@ -187,8 +167,9 @@ private CatalogQuery criterion(Integer limit, Integer offset) {
.build();
}

private void buildContractDefinition(EdcClient client, String policyId, String assetId1, String cdId) {
client.uiApi().createContractDefinition(ContractDefinitionRequest.builder()
private void buildContractDefinition(Janitor janitor, EdcClient client, String policyId, String assetId1, String cdId) {
janitor.withClient(client)
.createContractDefinition(ContractDefinitionRequest.builder()
.contractDefinitionId(cdId)
.accessPolicyId(policyId)
.contractPolicyId(policyId)
Expand All @@ -213,6 +194,7 @@ private void setupAssets(EdcClient client, Janitor janitor) {

int offset = 0;
int firstIndex = offset + 1;

assetId1 = janitor.withClient(client).createAsset(UiAssetCreateRequest.builder()
.id("test-asset-" + firstIndex)
.title("Test Asset " + firstIndex)
Expand All @@ -234,5 +216,8 @@ private void setupAssets(EdcClient client, Janitor janitor) {
.type(UiPolicyExpressionType.EMPTY)
.build())
.build()).getId();

buildContractDefinition(janitor, client, policyId, assetId1, "cd-1");
buildContractDefinition(janitor, client, policyId, assetId2, "cd-2");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package de.sovity.edc.extension.e2e.junit;

import de.sovity.edc.client.EdcClient;
import de.sovity.edc.client.gen.model.ContractDefinitionRequest;
import de.sovity.edc.client.gen.model.IdResponseDto;
import de.sovity.edc.client.gen.model.PolicyDefinitionCreateDto;
import de.sovity.edc.client.gen.model.UiAssetCreateRequest;
Expand All @@ -35,7 +36,13 @@ public IdResponseDto createAsset(UiAssetCreateRequest uiAssetCreateRequest) {

public IdResponseDto createPolicyDefinitionV2(PolicyDefinitionCreateDto policyDefinition) {
val result = client.uiApi().createPolicyDefinitionV2(policyDefinition);
janitor.afterEach(() -> client.uiApi().deleteAsset(result.getId()));
janitor.afterEach(() -> client.uiApi().deletePolicyDefinition(result.getId()));
return result;
}

public IdResponseDto createContractDefinition(ContractDefinitionRequest contractDefinitionRequest) {
val result = client.uiApi().createContractDefinition(contractDefinitionRequest);
janitor.afterEach(() -> client.uiApi().deleteContractDefinition(result.getId()));
return result;
}
}

0 comments on commit 0b4e74c

Please sign in to comment.