Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6397ace

Browse files
committedApr 3, 2023
feat(tests): removes lombok from edc-tests module
1 parent 70ba6bd commit 6397ace

27 files changed

+1919
-1435
lines changed
 

‎edc-tests/cucumber/src/test/java/org/eclipse/tractusx/edc/tests/BackendServiceBackendAPI.java

+244-194
Large diffs are not rendered by default.

‎edc-tests/cucumber/src/test/java/org/eclipse/tractusx/edc/tests/Connector.java

+54-30
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,72 @@
2020

2121
package org.eclipse.tractusx.edc.tests;
2222

23-
import lombok.Getter;
24-
import lombok.NonNull;
25-
import lombok.RequiredArgsConstructor;
23+
2624
import org.eclipse.tractusx.edc.tests.util.DatabaseCleaner;
2725
import org.eclipse.tractusx.edc.tests.util.S3Client;
2826

29-
@RequiredArgsConstructor
27+
3028
public class Connector {
3129

32-
@NonNull @Getter private final String name;
30+
private final String name;
31+
32+
private final Environment environment;
33+
34+
private final DataManagementAPI dataManagementAPI;
35+
36+
private final BackendServiceBackendAPI backendServiceBackendAPI;
37+
38+
private final DatabaseCleaner databaseCleaner;
39+
40+
41+
private final S3Client s3Client;
42+
43+
public Connector(String name, Environment environment) {
44+
this.name = name;
45+
this.environment = environment;
46+
dataManagementAPI = loadDataManagementAPI();
47+
backendServiceBackendAPI = loadBackendServiceBackendAPI();
48+
databaseCleaner = loadDatabaseCleaner();
49+
s3Client = createS3Client();
50+
}
3351

34-
@Getter @NonNull private final Environment environment;
52+
public BackendServiceBackendAPI getBackendServiceBackendAPI() {
53+
return backendServiceBackendAPI;
54+
}
3555

36-
@Getter(lazy = true)
37-
private final DataManagementAPI dataManagementAPI = loadDataManagementAPI();
56+
public DatabaseCleaner getDatabaseCleaner() {
57+
return databaseCleaner;
58+
}
3859

39-
@Getter(lazy = true)
40-
private final BackendServiceBackendAPI backendServiceBackendAPI = loadBackendServiceBackendAPI();
60+
public DataManagementAPI getDataManagementAPI() {
61+
return dataManagementAPI;
62+
}
4163

42-
@Getter(lazy = true)
43-
private final DatabaseCleaner databaseCleaner = loadDatabaseCleaner();
64+
public Environment getEnvironment() {
65+
return environment;
66+
}
4467

45-
@Getter(lazy = true)
46-
private final S3Client s3Client = createS3Client();
68+
public S3Client getS3Client() {
69+
return s3Client;
70+
}
4771

48-
private DataManagementAPI loadDataManagementAPI() {
49-
return new DataManagementAPI(
50-
environment.getDataManagementUrl(), environment.getDataManagementAuthKey());
51-
}
72+
private DataManagementAPI loadDataManagementAPI() {
73+
return new DataManagementAPI(
74+
environment.getDataManagementUrl(), environment.getDataManagementAuthKey());
75+
}
5276

53-
private DatabaseCleaner loadDatabaseCleaner() {
54-
return new DatabaseCleaner(
55-
environment.getDatabaseUrl(),
56-
environment.getDatabaseUser(),
57-
environment.getDatabasePassword());
58-
}
77+
private DatabaseCleaner loadDatabaseCleaner() {
78+
return new DatabaseCleaner(
79+
environment.getDatabaseUrl(),
80+
environment.getDatabaseUser(),
81+
environment.getDatabasePassword());
82+
}
5983

60-
private BackendServiceBackendAPI loadBackendServiceBackendAPI() {
61-
return new BackendServiceBackendAPI(environment.getBackendServiceBackendApiUrl());
62-
}
84+
private BackendServiceBackendAPI loadBackendServiceBackendAPI() {
85+
return new BackendServiceBackendAPI(environment.getBackendServiceBackendApiUrl());
86+
}
6387

64-
private S3Client createS3Client() {
65-
return new S3Client(environment);
66-
}
88+
private S3Client createS3Client() {
89+
return new S3Client(environment);
90+
}
6791
}

‎edc-tests/cucumber/src/test/java/org/eclipse/tractusx/edc/tests/ConnectorFactory.java

+14-13
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,25 @@
2020

2121
package org.eclipse.tractusx.edc.tests;
2222

23-
import java.util.HashMap;
2423
import java.util.Locale;
2524
import java.util.Map;
26-
import lombok.NonNull;
27-
import lombok.experimental.UtilityClass;
25+
import java.util.Objects;
26+
import java.util.concurrent.ConcurrentHashMap;
27+
2828

29-
@UtilityClass
3029
public class ConnectorFactory {
31-
private static final Map<String, Connector> CONNECTOR_CACHE = new HashMap<>();
30+
private static final Map<String, Connector> CONNECTOR_CACHE = new ConcurrentHashMap<>();
3231

33-
public static Connector byName(@NonNull final String name) {
34-
return CONNECTOR_CACHE.computeIfAbsent(
35-
name.toUpperCase(Locale.ROOT), k -> createConnector(name));
36-
}
32+
public static Connector byName(String name) {
33+
Objects.requireNonNull(name);
34+
return CONNECTOR_CACHE.computeIfAbsent(
35+
name.toUpperCase(Locale.ROOT), k -> createConnector(name));
36+
}
3737

38-
private static Connector createConnector(@NonNull final String name) {
39-
final Environment environment = Environment.byName(name);
38+
private static Connector createConnector(String name) {
39+
Objects.requireNonNull(name);
40+
Environment environment = Environment.byName(name);
4041

41-
return new Connector(name, environment);
42-
}
42+
return new Connector(name, environment);
43+
}
4344
}

‎edc-tests/cucumber/src/test/java/org/eclipse/tractusx/edc/tests/Constants.java

+11-14
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,16 @@
2020

2121
package org.eclipse.tractusx.edc.tests;
2222

23-
import lombok.experimental.UtilityClass;
24-
25-
@UtilityClass
2623
public final class Constants {
27-
public static final String DATA_MANAGEMENT_URL = "DATA_MANAGEMENT_URL";
28-
public static final String DATA_MANAGEMENT_API_AUTH_KEY = "DATA_MANAGEMENT_API_AUTH_KEY";
29-
public static final String IDS_URL = "IDS_URL";
30-
public static final String DATA_PLANE_URL = "DATA_PLANE_URL";
31-
public static final String BACKEND_SERVICE_BACKEND_API_URL = "BACKEND_SERVICE_BACKEND_API_URL";
32-
public static final String DATABASE_URL = "DATABASE_URL";
33-
public static final String DATABASE_USER = "DATABASE_USER";
34-
public static final String DATABASE_PASSWORD = "DATABASE_PASSWORD";
35-
public static final String EDC_AWS_ENDPOINT_OVERRIDE = "EDC_AWS_ENDPOINT_OVERRIDE";
36-
public static final String AWS_ACCESS_KEY_ID = "AWS_ACCESS_KEY_ID";
37-
public static final String AWS_SECRET_ACCESS_KEY = "AWS_SECRET_ACCESS_KEY";
24+
public static final String DATA_MANAGEMENT_URL = "DATA_MANAGEMENT_URL";
25+
public static final String DATA_MANAGEMENT_API_AUTH_KEY = "DATA_MANAGEMENT_API_AUTH_KEY";
26+
public static final String IDS_URL = "IDS_URL";
27+
public static final String DATA_PLANE_URL = "DATA_PLANE_URL";
28+
public static final String BACKEND_SERVICE_BACKEND_API_URL = "BACKEND_SERVICE_BACKEND_API_URL";
29+
public static final String DATABASE_URL = "DATABASE_URL";
30+
public static final String DATABASE_USER = "DATABASE_USER";
31+
public static final String DATABASE_PASSWORD = "DATABASE_PASSWORD";
32+
public static final String EDC_AWS_ENDPOINT_OVERRIDE = "EDC_AWS_ENDPOINT_OVERRIDE";
33+
public static final String AWS_ACCESS_KEY_ID = "AWS_ACCESS_KEY_ID";
34+
public static final String AWS_SECRET_ACCESS_KEY = "AWS_SECRET_ACCESS_KEY";
3835
}

‎edc-tests/cucumber/src/test/java/org/eclipse/tractusx/edc/tests/ControlPlaneAdapterSteps.java

+42-40
Original file line numberDiff line numberDiff line change
@@ -22,64 +22,66 @@
2222

2323
import com.google.gson.Gson;
2424
import io.cucumber.datatable.DataTable;
25-
import java.io.IOException;
26-
import java.util.Map;
27-
import lombok.extern.slf4j.Slf4j;
2825
import org.apache.http.client.methods.CloseableHttpResponse;
2926
import org.apache.http.client.methods.HttpGet;
3027
import org.apache.http.impl.client.HttpClientBuilder;
3128
import org.eclipse.edc.spi.system.health.HealthStatus;
3229
import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference;
3330
import org.junit.jupiter.api.Assertions;
31+
import org.slf4j.Logger;
32+
import org.slf4j.LoggerFactory;
33+
34+
import java.io.IOException;
35+
import java.util.Map;
3436

35-
@Slf4j
3637
public class ControlPlaneAdapterSteps {
3738

38-
private EndpointDataReference endpointDataReference;
39+
private static final Logger log = LoggerFactory.getLogger(ControlPlaneAdapterSteps.class);
40+
private EndpointDataReference endpointDataReference;
3941

40-
/*
41-
* TODO: see of EndToEndTransfer.feature
42-
* the current Bussinnes test is not running, because of a possible rare condition in the CI pipeline
43-
* regarding the contract validity: see https://github.com/eclipse-edc/Connector/issues/2514
44-
*/
42+
/*
43+
* TODO: see of EndToEndTransfer.feature
44+
* the current Bussinnes test is not running, because of a possible rare condition in the CI pipeline
45+
* regarding the contract validity: see https://github.com/eclipse-edc/Connector/issues/2514
46+
*/
4547

46-
// @When("'{connector}' gets a request endpoint from '{connector}'")
47-
public void getEndPointFromGetRequest(Connector consumer, Connector receiver, DataTable table)
48-
throws IOException {
48+
// @When("'{connector}' gets a request endpoint from '{connector}'")
49+
public void getEndPointFromGetRequest(Connector consumer, Connector receiver, DataTable table)
50+
throws IOException {
4951

50-
final DataManagementAPI dataManagementAPI = consumer.getDataManagementAPI();
51-
final String receiverIdsUrl = receiver.getEnvironment().getIdsUrl() + "/data";
52+
DataManagementAPI dataManagementAPI = consumer.getDataManagementAPI();
53+
String receiverIdsUrl = receiver.getEnvironment().getIdsUrl() + "/data";
5254

53-
for (Map<String, String> map : table.asMaps()) {
54-
final String assetId = map.get("asset id");
55+
for (Map<String, String> map : table.asMaps()) {
56+
String assetId = map.get("asset id");
5557

56-
endpointDataReference = dataManagementAPI.getEdcEndpoint(assetId, receiverIdsUrl);
58+
endpointDataReference = dataManagementAPI.getEdcEndpoint(assetId, receiverIdsUrl);
5759

58-
log.debug("endpointDataReference in controlplane" + endpointDataReference.toString());
60+
log.debug("endpointDataReference in controlplane" + endpointDataReference.toString());
61+
}
5962
}
60-
}
6163

62-
/*
63-
* TODO: see EndToEndTransfer.feature
64-
* the current Bussinnes test is not running, because of a possible rare condition in the CI pipeline
65-
* regarding the contract validity: see https://github.com/eclipse-edc/Connector/issues/2514
66-
*/
64+
/*
65+
* TODO: see EndToEndTransfer.feature
66+
* the current Bussinnes test is not running, because of a possible rare condition in the CI pipeline
67+
* regarding the contract validity: see https://github.com/eclipse-edc/Connector/issues/2514
68+
*/
6769

68-
// @Then("'{connector}' asks for the asset from the endpoint")
69-
public void receiveEndpoint(Connector consumer) throws IOException {
70+
// @Then("'{connector}' asks for the asset from the endpoint")
71+
public void receiveEndpoint(Connector consumer) throws IOException {
7072

71-
var requestUrl = endpointDataReference.getEndpoint();
72-
var key = endpointDataReference.getAuthKey();
73-
var value = endpointDataReference.getAuthCode();
74-
var httpClient = HttpClientBuilder.create().build();
75-
var get = new HttpGet(requestUrl);
76-
get.addHeader(key, value);
77-
final CloseableHttpResponse response = httpClient.execute(get);
78-
var bytes = response.getEntity().getContent().readAllBytes();
79-
var result = new String(bytes);
80-
var resultTransformed = new Gson().fromJson(result, HealthStatus.class);
73+
var requestUrl = endpointDataReference.getEndpoint();
74+
var key = endpointDataReference.getAuthKey();
75+
var value = endpointDataReference.getAuthCode();
76+
var httpClient = HttpClientBuilder.create().build();
77+
var get = new HttpGet(requestUrl);
78+
get.addHeader(key, value);
79+
CloseableHttpResponse response = httpClient.execute(get);
80+
var bytes = response.getEntity().getContent().readAllBytes();
81+
var result = new String(bytes);
82+
var resultTransformed = new Gson().fromJson(result, HealthStatus.class);
8183

82-
Assertions.assertTrue(resultTransformed.isHealthy());
83-
Assertions.assertFalse(resultTransformed.getComponentResults().isEmpty());
84-
}
84+
Assertions.assertTrue(resultTransformed.isHealthy());
85+
Assertions.assertFalse(resultTransformed.getComponentResults().isEmpty());
86+
}
8587
}

‎edc-tests/cucumber/src/test/java/org/eclipse/tractusx/edc/tests/DataManagementAPI.java

+688-621
Large diffs are not rendered by default.

‎edc-tests/cucumber/src/test/java/org/eclipse/tractusx/edc/tests/Environment.java

+163-40
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
package org.eclipse.tractusx.edc.tests;
2222

23+
import java.util.Locale;
24+
import java.util.Objects;
25+
2326
import static org.eclipse.tractusx.edc.tests.Constants.AWS_ACCESS_KEY_ID;
2427
import static org.eclipse.tractusx.edc.tests.Constants.AWS_SECRET_ACCESS_KEY;
2528
import static org.eclipse.tractusx.edc.tests.Constants.BACKEND_SERVICE_BACKEND_API_URL;
@@ -32,45 +35,165 @@
3235
import static org.eclipse.tractusx.edc.tests.Constants.EDC_AWS_ENDPOINT_OVERRIDE;
3336
import static org.eclipse.tractusx.edc.tests.Constants.IDS_URL;
3437

35-
import java.util.Locale;
36-
import lombok.AccessLevel;
37-
import lombok.Builder;
38-
import lombok.Getter;
39-
import lombok.NonNull;
40-
import lombok.ToString;
41-
42-
@Builder(access = AccessLevel.PRIVATE)
43-
@Getter
44-
@ToString
4538
public class Environment {
46-
@NonNull private final String dataManagementAuthKey;
47-
@NonNull private final String dataManagementUrl;
48-
@NonNull private final String idsUrl;
49-
@NonNull private final String dataPlaneUrl;
50-
@NonNull private final String backendServiceBackendApiUrl;
51-
@NonNull private final String databaseUrl;
52-
@NonNull private final String databaseUser;
53-
@NonNull private final String databasePassword;
54-
@NonNull private final String awsEndpointOverride;
55-
@NonNull private final String awsAccessKey;
56-
@NonNull private final String awsSecretAccessKey;
57-
58-
public static Environment byName(String name) {
59-
name = name.toUpperCase(Locale.ROOT);
60-
61-
return Environment.builder()
62-
.dataManagementUrl(System.getenv(String.join("_", name, DATA_MANAGEMENT_URL)))
63-
.dataManagementAuthKey(System.getenv(String.join("_", name, DATA_MANAGEMENT_API_AUTH_KEY)))
64-
.idsUrl(System.getenv(String.join("_", name, IDS_URL)))
65-
.dataPlaneUrl(System.getenv(String.join("_", name, DATA_PLANE_URL)))
66-
.backendServiceBackendApiUrl(
67-
System.getenv(String.join("_", name, BACKEND_SERVICE_BACKEND_API_URL)))
68-
.databaseUrl(System.getenv(String.join("_", name, DATABASE_URL)))
69-
.databaseUser(System.getenv(String.join("_", name, DATABASE_USER)))
70-
.databasePassword(System.getenv(String.join("_", name, DATABASE_PASSWORD)))
71-
.awsEndpointOverride(System.getenv(EDC_AWS_ENDPOINT_OVERRIDE))
72-
.awsAccessKey(System.getenv(String.join("_", name, AWS_ACCESS_KEY_ID)))
73-
.awsSecretAccessKey(System.getenv(String.join("_", name, AWS_SECRET_ACCESS_KEY)))
74-
.build();
75-
}
39+
40+
private String awsEndpointOverride;
41+
private String awsAccessKey;
42+
private String awsSecretAccessKey;
43+
private String dataManagementAuthKey;
44+
private String dataManagementUrl;
45+
private String idsUrl;
46+
private String dataPlaneUrl;
47+
private String backendServiceBackendApiUrl;
48+
private String databaseUrl;
49+
private String databaseUser;
50+
private String databasePassword;
51+
52+
private Environment() {
53+
54+
}
55+
56+
57+
public static Environment byName(String name) {
58+
var upperName = name.toUpperCase(Locale.ROOT);
59+
60+
return Environment.Builder.newInstance()
61+
.dataManagementUrl(System.getenv(String.join("_", upperName, DATA_MANAGEMENT_URL)))
62+
.dataManagementAuthKey(System.getenv(String.join("_", upperName, DATA_MANAGEMENT_API_AUTH_KEY)))
63+
.idsUrl(System.getenv(String.join("_", upperName, IDS_URL)))
64+
.dataPlaneUrl(System.getenv(String.join("_", upperName, DATA_PLANE_URL)))
65+
.backendServiceBackendApiUrl(
66+
System.getenv(String.join("_", upperName, BACKEND_SERVICE_BACKEND_API_URL)))
67+
.databaseUrl(System.getenv(String.join("_", upperName, DATABASE_URL)))
68+
.databaseUser(System.getenv(String.join("_", upperName, DATABASE_USER)))
69+
.databasePassword(System.getenv(String.join("_", upperName, DATABASE_PASSWORD)))
70+
.awsEndpointOverride(System.getenv(EDC_AWS_ENDPOINT_OVERRIDE))
71+
.awsAccessKey(System.getenv(String.join("_", upperName, AWS_ACCESS_KEY_ID)))
72+
.awsSecretAccessKey(System.getenv(String.join("_", upperName, AWS_SECRET_ACCESS_KEY)))
73+
.build();
74+
}
75+
76+
public String getIdsUrl() {
77+
return idsUrl;
78+
}
79+
80+
public String getAwsEndpointOverride() {
81+
return awsEndpointOverride;
82+
}
83+
84+
public String getAwsSecretAccessKey() {
85+
return awsSecretAccessKey;
86+
}
87+
88+
public String getAwsAccessKey() {
89+
return awsAccessKey;
90+
}
91+
92+
public String getBackendServiceBackendApiUrl() {
93+
return backendServiceBackendApiUrl;
94+
}
95+
96+
public String getDatabasePassword() {
97+
return databasePassword;
98+
}
99+
100+
public String getDatabaseUrl() {
101+
return databaseUrl;
102+
}
103+
104+
public String getDatabaseUser() {
105+
return databaseUser;
106+
}
107+
108+
public String getDataManagementAuthKey() {
109+
return dataManagementAuthKey;
110+
}
111+
112+
public String getDataManagementUrl() {
113+
return dataManagementUrl;
114+
}
115+
116+
private static class Builder {
117+
118+
119+
private final Environment environment;
120+
121+
private Builder() {
122+
environment = new Environment();
123+
}
124+
125+
public static Builder newInstance() {
126+
return new Builder();
127+
}
128+
129+
public Builder awsEndpointOverride(String val) {
130+
environment.awsEndpointOverride = val;
131+
return this;
132+
}
133+
134+
public Builder awsAccessKey(String val) {
135+
environment.awsAccessKey = val;
136+
return this;
137+
}
138+
139+
public Builder awsSecretAccessKey(String val) {
140+
environment.awsSecretAccessKey = val;
141+
return this;
142+
}
143+
144+
public Builder dataManagementAuthKey(String val) {
145+
environment.dataManagementAuthKey = val;
146+
return this;
147+
}
148+
149+
public Builder dataManagementUrl(String val) {
150+
environment.dataManagementUrl = val;
151+
return this;
152+
}
153+
154+
public Builder idsUrl(String val) {
155+
environment.idsUrl = val;
156+
return this;
157+
}
158+
159+
public Builder dataPlaneUrl(String val) {
160+
environment.dataPlaneUrl = val;
161+
return this;
162+
}
163+
164+
public Builder backendServiceBackendApiUrl(String val) {
165+
environment.backendServiceBackendApiUrl = val;
166+
return this;
167+
}
168+
169+
public Builder databaseUrl(String val) {
170+
environment.databaseUrl = val;
171+
return this;
172+
}
173+
174+
public Builder databaseUser(String val) {
175+
environment.databaseUser = val;
176+
return this;
177+
}
178+
179+
public Builder databasePassword(String val) {
180+
environment.databasePassword = val;
181+
return this;
182+
}
183+
184+
public Environment build() {
185+
Objects.requireNonNull(environment.awsAccessKey);
186+
Objects.requireNonNull(environment.awsEndpointOverride);
187+
Objects.requireNonNull(environment.awsSecretAccessKey);
188+
Objects.requireNonNull(environment.backendServiceBackendApiUrl);
189+
Objects.requireNonNull(environment.databaseUrl);
190+
Objects.requireNonNull(environment.databasePassword);
191+
Objects.requireNonNull(environment.databaseUser);
192+
Objects.requireNonNull(environment.dataManagementUrl);
193+
Objects.requireNonNull(environment.dataPlaneUrl);
194+
Objects.requireNonNull(environment.dataManagementAuthKey);
195+
Objects.requireNonNull(environment.idsUrl);
196+
return environment;
197+
}
198+
}
76199
}

‎edc-tests/cucumber/src/test/java/org/eclipse/tractusx/edc/tests/HttpProxyTransferSteps.java

+83-80
Original file line numberDiff line numberDiff line change
@@ -4,96 +4,99 @@
44
import io.cucumber.java.en.Given;
55
import io.cucumber.java.en.Then;
66
import io.cucumber.java.en.When;
7+
import org.eclipse.tractusx.edc.tests.data.Asset;
8+
import org.eclipse.tractusx.edc.tests.data.ContractNegotiation;
9+
import org.eclipse.tractusx.edc.tests.data.DataAddress;
10+
import org.eclipse.tractusx.edc.tests.data.HttpProxySinkDataAddress;
11+
import org.eclipse.tractusx.edc.tests.data.HttpProxySourceDataAddress;
12+
import org.eclipse.tractusx.edc.tests.data.Transfer;
13+
import org.junit.jupiter.api.Assertions;
14+
715
import java.io.IOException;
816
import java.time.Duration;
917
import java.util.Arrays;
1018
import java.util.List;
11-
import lombok.extern.slf4j.Slf4j;
12-
import org.awaitility.Awaitility;
13-
import org.eclipse.tractusx.edc.tests.data.*;
14-
import org.junit.jupiter.api.Assertions;
1519

1620
import static org.awaitility.Awaitility.await;
1721

18-
@Slf4j
1922
public class HttpProxyTransferSteps {
2023

21-
private static final String ID = "id";
22-
private static final String DESCRIPTION = "description";
23-
private static final String BASE_URL = "baseUrl";
24-
private static final String ASSET_ID = "asset id";
25-
private static final String RECEIVER_HTTP_ENDPOINT = "receiverHttpEndpoint";
26-
27-
@Given("'{connector}' has a http proxy assets")
28-
public void hasAssets(Connector connector, DataTable table) throws Exception {
29-
final DataManagementAPI api = connector.getDataManagementAPI();
30-
31-
for (var map : table.asMaps()) {
32-
final String id = map.get(ID);
33-
final String description = map.get(DESCRIPTION);
34-
final String baseUrl = map.get(BASE_URL);
35-
36-
var oauth2Provision =
37-
Arrays.stream(Oauth2DataAddressFields.values())
38-
.map(it -> it.text)
39-
.anyMatch(map::containsKey)
40-
? new HttpProxySourceDataAddress.Oauth2Provision(
41-
map.get(Oauth2DataAddressFields.TOKEN_URL.text),
42-
map.get(Oauth2DataAddressFields.CLIENT_ID.text),
43-
map.get(Oauth2DataAddressFields.CLIENT_SECRET.text),
44-
map.get(Oauth2DataAddressFields.SCOPE.text))
45-
: null;
46-
47-
final DataAddress address = new HttpProxySourceDataAddress(baseUrl, oauth2Provision);
48-
final Asset asset = new Asset(id, description, address);
49-
50-
api.createAsset(asset);
24+
private static final String ID = "id";
25+
private static final String DESCRIPTION = "description";
26+
private static final String BASE_URL = "baseUrl";
27+
private static final String ASSET_ID = "asset id";
28+
private static final String RECEIVER_HTTP_ENDPOINT = "receiverHttpEndpoint";
29+
30+
@Given("'{connector}' has a http proxy assets")
31+
public void hasAssets(Connector connector, DataTable table) throws Exception {
32+
DataManagementAPI api = connector.getDataManagementAPI();
33+
34+
for (var map : table.asMaps()) {
35+
String id = map.get(ID);
36+
String description = map.get(DESCRIPTION);
37+
String baseUrl = map.get(BASE_URL);
38+
39+
var oauth2Provision =
40+
Arrays.stream(Oauth2DataAddressFields.values())
41+
.map(it -> it.text)
42+
.anyMatch(map::containsKey)
43+
? new HttpProxySourceDataAddress.Oauth2Provision(
44+
map.get(Oauth2DataAddressFields.TOKEN_URL.text),
45+
map.get(Oauth2DataAddressFields.CLIENT_ID.text),
46+
map.get(Oauth2DataAddressFields.CLIENT_SECRET.text),
47+
map.get(Oauth2DataAddressFields.SCOPE.text))
48+
: null;
49+
50+
DataAddress address = new HttpProxySourceDataAddress(baseUrl, oauth2Provision);
51+
Asset asset = new Asset(id, description, address);
52+
53+
api.createAsset(asset);
54+
}
5155
}
52-
}
53-
54-
@When("'{connector}' initiates HttpProxy transfer from '{connector}'")
55-
public void sokratesInitiateHttpProxyTransferProcessFromPlato(
56-
Connector consumer, Connector provider, DataTable dataTable) throws IOException {
57-
final DataManagementAPI api = consumer.getDataManagementAPI();
58-
final String receiverUrl = provider.getEnvironment().getIdsUrl() + "/data";
59-
60-
final List<ContractNegotiation> negotiation = api.getNegotiations();
61-
final String agreementId = negotiation.get(0).getAgreementId();
62-
final DataAddress dataAddress = new HttpProxySinkDataAddress();
63-
64-
for (var map : dataTable.asMaps()) {
65-
final String assetId = map.get(ASSET_ID);
66-
final String receiverHttpEndpoint = map.get(RECEIVER_HTTP_ENDPOINT);
67-
final Transfer transfer =
68-
api.initiateTransferProcess(
69-
receiverUrl, agreementId, assetId, dataAddress, receiverHttpEndpoint);
70-
71-
transfer.waitUntilComplete(api);
56+
57+
@When("'{connector}' initiates HttpProxy transfer from '{connector}'")
58+
public void sokratesInitiateHttpProxyTransferProcessFromPlato(
59+
Connector consumer, Connector provider, DataTable dataTable) throws IOException {
60+
DataManagementAPI api = consumer.getDataManagementAPI();
61+
String receiverUrl = provider.getEnvironment().getIdsUrl() + "/data";
62+
63+
List<ContractNegotiation> negotiation = api.getNegotiations();
64+
String agreementId = negotiation.get(0).getAgreementId();
65+
DataAddress dataAddress = new HttpProxySinkDataAddress();
66+
67+
for (var map : dataTable.asMaps()) {
68+
String assetId = map.get(ASSET_ID);
69+
String receiverHttpEndpoint = map.get(RECEIVER_HTTP_ENDPOINT);
70+
Transfer transfer =
71+
api.initiateTransferProcess(
72+
receiverUrl, agreementId, assetId, dataAddress, receiverHttpEndpoint);
73+
74+
transfer.waitUntilComplete(api);
75+
}
7276
}
73-
}
74-
75-
@Then("the backend application of '{connector}' has received data")
76-
public void theBackendApplicationOfSocratesHasReceivedData(Connector consumer) {
77-
final BackendServiceBackendAPI api = consumer.getBackendServiceBackendAPI();
78-
await()
79-
.atMost(Duration.ofSeconds(20))
80-
.pollInterval(Duration.ofSeconds(1))
81-
.untilAsserted(() ->{
82-
final List<String> transferredData = api.list("/");
83-
Assertions.assertNotEquals(0, transferredData.size());
84-
});
85-
}
86-
87-
private enum Oauth2DataAddressFields {
88-
TOKEN_URL("oauth2 token url"),
89-
CLIENT_ID("oauth2 client id"),
90-
CLIENT_SECRET("oauth2 client secret"),
91-
SCOPE("oauth2 scope");
92-
93-
private final String text;
94-
95-
Oauth2DataAddressFields(String text) {
96-
this.text = text;
77+
78+
@Then("the backend application of '{connector}' has received data")
79+
public void theBackendApplicationOfSocratesHasReceivedData(Connector consumer) {
80+
BackendServiceBackendAPI api = consumer.getBackendServiceBackendAPI();
81+
await()
82+
.atMost(Duration.ofSeconds(20))
83+
.pollInterval(Duration.ofSeconds(1))
84+
.untilAsserted(() -> {
85+
List<String> transferredData = api.list("/");
86+
Assertions.assertNotEquals(0, transferredData.size());
87+
});
88+
}
89+
90+
private enum Oauth2DataAddressFields {
91+
TOKEN_URL("oauth2 token url"),
92+
CLIENT_ID("oauth2 client id"),
93+
CLIENT_SECRET("oauth2 client secret"),
94+
SCOPE("oauth2 scope");
95+
96+
private final String text;
97+
98+
Oauth2DataAddressFields(String text) {
99+
this.text = text;
100+
}
97101
}
98-
}
99102
}

‎edc-tests/cucumber/src/test/java/org/eclipse/tractusx/edc/tests/NegotiationSteps.java

+45-44
Original file line numberDiff line numberDiff line change
@@ -23,72 +23,73 @@
2323
import io.cucumber.datatable.DataTable;
2424
import io.cucumber.java.en.Then;
2525
import io.cucumber.java.en.When;
26-
import java.io.IOException;
27-
import java.util.ArrayList;
28-
import java.util.List;
29-
import java.util.Map;
30-
import lombok.extern.slf4j.Slf4j;
3126
import org.eclipse.tractusx.edc.tests.data.ContractNegotiation;
3227
import org.eclipse.tractusx.edc.tests.data.ContractNegotiationState;
3328
import org.eclipse.tractusx.edc.tests.data.Negotiation;
3429
import org.eclipse.tractusx.edc.tests.data.Permission;
3530
import org.eclipse.tractusx.edc.tests.data.Policy;
3631
import org.junit.jupiter.api.Assertions;
3732

38-
@Slf4j
33+
import java.io.IOException;
34+
import java.util.ArrayList;
35+
import java.util.List;
36+
import java.util.Map;
37+
38+
3939
public class NegotiationSteps {
4040

41-
private static final String DEFINITION_ID = "definition id";
42-
private static final String ASSET_ID = "asset id";
4341

44-
private ContractNegotiation lastInitiatedNegotiation;
42+
private static final String DEFINITION_ID = "definition id";
43+
private static final String ASSET_ID = "asset id";
4544

46-
@When("'{connector}' sends '{connector}' an offer without constraints")
47-
public void sendAnOfferWithoutConstraints(Connector sender, Connector receiver, DataTable table)
48-
throws IOException {
45+
private ContractNegotiation lastInitiatedNegotiation;
4946

50-
final DataManagementAPI dataManagementAPI = sender.getDataManagementAPI();
51-
final String receiverIdsUrl = receiver.getEnvironment().getIdsUrl() + "/data";
47+
@When("'{connector}' sends '{connector}' an offer without constraints")
48+
public void sendAnOfferWithoutConstraints(Connector sender, Connector receiver, DataTable table)
49+
throws IOException {
5250

53-
for (Map<String, String> map : table.asMaps()) {
54-
final String definitionId = map.get(DEFINITION_ID);
55-
final String assetId = map.get(ASSET_ID);
51+
DataManagementAPI dataManagementAPI = sender.getDataManagementAPI();
52+
String receiverIdsUrl = receiver.getEnvironment().getIdsUrl() + "/data";
5653

57-
final Permission permission = new Permission("USE", null, new ArrayList<>());
58-
final Policy policy = new Policy("foo", List.of(permission));
54+
for (Map<String, String> map : table.asMaps()) {
55+
String definitionId = map.get(DEFINITION_ID);
56+
String assetId = map.get(ASSET_ID);
5957

60-
final Negotiation negotiation =
61-
dataManagementAPI.initiateNegotiation(receiverIdsUrl, definitionId, assetId, policy);
58+
Permission permission = new Permission("USE", new ArrayList<>(), null);
59+
Policy policy = new Policy("foo", List.of(permission));
6260

63-
// wait for negotiation to complete
64-
negotiation.waitUntilComplete(dataManagementAPI);
61+
Negotiation negotiation =
62+
dataManagementAPI.initiateNegotiation(receiverIdsUrl, definitionId, assetId, policy);
6563

66-
lastInitiatedNegotiation = dataManagementAPI.getNegotiation(negotiation.getId());
64+
// wait for negotiation to complete
65+
negotiation.waitUntilComplete(dataManagementAPI);
66+
67+
lastInitiatedNegotiation = dataManagementAPI.getNegotiation(negotiation.getId());
68+
}
6769
}
68-
}
6970

70-
@When("'{connector}' successfully negotiation a contract agreement with '{connector}'")
71-
public void sokratesSuccessfullyNegotiationAContractAgreementPlatoFor(
72-
Connector consumer, Connector provider, DataTable table) throws IOException {
73-
final DataManagementAPI api = consumer.getDataManagementAPI();
71+
@When("'{connector}' successfully negotiation a contract agreement with '{connector}'")
72+
public void sokratesSuccessfullyNegotiationAContractAgreementPlatoFor(
73+
Connector consumer, Connector provider, DataTable table) throws IOException {
74+
DataManagementAPI api = consumer.getDataManagementAPI();
7475

75-
final Map<String, String> map = table.asMap();
76-
final String definitionId = map.get(DEFINITION_ID);
77-
final String assetId = map.get(ASSET_ID);
76+
Map<String, String> map = table.asMap();
77+
String definitionId = map.get(DEFINITION_ID);
78+
String assetId = map.get(ASSET_ID);
7879

79-
// as default always the "allow all" policy is used. So we can assume this here, too.
80-
final Permission permission = new Permission("USE", null, new ArrayList<>());
81-
final Policy policy = new Policy("policy-id", List.of(permission));
80+
// as default always the "allow all" policy is used. So we can assume this here, too.
81+
Permission permission = new Permission("USE", new ArrayList<>(), null);
82+
Policy policy = new Policy("policy-id", List.of(permission));
8283

83-
final String receiverUrl = provider.getEnvironment().getIdsUrl();
84-
final Negotiation negotiation =
85-
api.initiateNegotiation(receiverUrl, assetId, definitionId, policy);
84+
String receiverUrl = provider.getEnvironment().getIdsUrl();
85+
Negotiation negotiation =
86+
api.initiateNegotiation(receiverUrl, assetId, definitionId, policy);
8687

87-
negotiation.waitUntilComplete(api);
88-
}
88+
negotiation.waitUntilComplete(api);
89+
}
8990

90-
@Then("the negotiation is declined")
91-
public void assertLastNegotiationDeclined() {
92-
Assertions.assertEquals(ContractNegotiationState.DECLINED, lastInitiatedNegotiation.getState());
93-
}
91+
@Then("the negotiation is declined")
92+
public void assertLastNegotiationDeclined() {
93+
Assertions.assertEquals(ContractNegotiationState.DECLINED, lastInitiatedNegotiation.getState());
94+
}
9495
}

‎edc-tests/cucumber/src/test/java/org/eclipse/tractusx/edc/tests/PolicyStepDefs.java

+37-28
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,54 @@
2020

2121
package org.eclipse.tractusx.edc.tests;
2222

23-
import static java.util.Arrays.stream;
24-
import static java.util.stream.Collectors.toList;
25-
2623
import io.cucumber.datatable.DataTable;
2724
import io.cucumber.java.en.Given;
25+
import org.eclipse.tractusx.edc.tests.data.BusinessPartnerNumberConstraint;
26+
import org.eclipse.tractusx.edc.tests.data.Constraint;
27+
import org.eclipse.tractusx.edc.tests.data.OrConstraint;
28+
import org.eclipse.tractusx.edc.tests.data.PayMeConstraint;
29+
import org.eclipse.tractusx.edc.tests.data.Permission;
30+
import org.eclipse.tractusx.edc.tests.data.Policy;
31+
2832
import java.util.ArrayList;
2933
import java.util.List;
3034
import java.util.Map;
31-
import org.eclipse.tractusx.edc.tests.data.*;
35+
36+
import static java.util.Arrays.stream;
37+
import static java.util.stream.Collectors.toList;
3238

3339
public class PolicyStepDefs {
3440

35-
@Given("'{connector}' has the following policies")
36-
public void hasPolicies(Connector connector, DataTable table) throws Exception {
37-
var api = connector.getDataManagementAPI();
38-
var policies = table.asMaps().stream().map(this::parseRow).collect(toList());
41+
@Given("'{connector}' has the following policies")
42+
public void hasPolicies(Connector connector, DataTable table) throws Exception {
43+
var api = connector.getDataManagementAPI();
44+
var policies = table.asMaps().stream().map(this::parseRow).collect(toList());
3945

40-
for (var policy : policies) api.createPolicy(policy);
41-
}
46+
for (var policy : policies) {
47+
api.createPolicy(policy);
48+
}
49+
}
4250

43-
private Policy parseRow(Map<String, String> row) {
44-
var id = row.get("id");
45-
var action = row.get("action");
46-
var constraints = new ArrayList<Constraint>();
51+
private Policy parseRow(Map<String, String> row) {
52+
var id = row.get("id");
53+
var action = row.get("action");
54+
var constraints = new ArrayList<Constraint>();
4755

48-
var businessPartnerNumber = row.get("businessPartnerNumber");
49-
if (businessPartnerNumber != null && !businessPartnerNumber.isBlank()) {
50-
var bpnConstraints =
51-
stream(businessPartnerNumber.split(","))
52-
.map(BusinessPartnerNumberConstraint::new)
53-
.collect(toList());
54-
constraints.add(new OrConstraint(bpnConstraints));
55-
}
56+
var businessPartnerNumber = row.get("businessPartnerNumber");
57+
if (businessPartnerNumber != null && !businessPartnerNumber.isBlank()) {
58+
var bpnConstraints =
59+
stream(businessPartnerNumber.split(","))
60+
.map(BusinessPartnerNumberConstraint::new)
61+
.collect(toList());
62+
constraints.add(new OrConstraint(bpnConstraints));
63+
}
5664

57-
var payMe = row.get("payMe");
58-
if (payMe != null && !payMe.isBlank())
59-
constraints.add(new PayMeConstraint(Double.parseDouble(payMe)));
65+
var payMe = row.get("payMe");
66+
if (payMe != null && !payMe.isBlank()) {
67+
constraints.add(new PayMeConstraint(Double.parseDouble(payMe)));
68+
}
6069

61-
var permission = new Permission(action, null, constraints);
62-
return new Policy(id, List.of(permission));
63-
}
70+
var permission = new Permission(action, constraints, null);
71+
return new Policy(id, List.of(permission));
72+
}
6473
}

‎edc-tests/cucumber/src/test/java/org/eclipse/tractusx/edc/tests/S3FileTransferStepsDefs.java

+113-114
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,10 @@
1919

2020
package org.eclipse.tractusx.edc.tests;
2121

22-
import static org.awaitility.Awaitility.await;
23-
import static org.junit.jupiter.api.Assertions.fail;
24-
2522
import io.cucumber.datatable.DataTable;
2623
import io.cucumber.java.AfterAll;
2724
import io.cucumber.java.en.Given;
2825
import io.cucumber.java.en.Then;
29-
import java.io.File;
30-
import java.io.IOException;
31-
import java.nio.file.Files;
32-
import java.time.Duration;
33-
import java.util.ArrayList;
34-
import java.util.List;
35-
import java.util.Map;
36-
import java.util.Set;
3726
import org.eclipse.tractusx.edc.tests.data.Asset;
3827
import org.eclipse.tractusx.edc.tests.data.DataAddress;
3928
import org.eclipse.tractusx.edc.tests.data.Negotiation;
@@ -45,135 +34,145 @@
4534
import org.eclipse.tractusx.edc.tests.util.Timeouts;
4635
import org.junit.jupiter.api.Assertions;
4736

37+
import java.io.File;
38+
import java.io.IOException;
39+
import java.nio.file.Files;
40+
import java.time.Duration;
41+
import java.util.ArrayList;
42+
import java.util.List;
43+
import java.util.Map;
44+
import java.util.Set;
45+
46+
import static org.awaitility.Awaitility.await;
47+
import static org.junit.jupiter.api.Assertions.fail;
48+
4849
public class S3FileTransferStepsDefs {
4950

50-
@Given("'{connector}' has an empty storage bucket called {string}")
51-
public void hasEmptyStorageBucket(Connector connector, String bucketName) {
52-
S3Client s3 = connector.getS3Client();
51+
private static final String COMPLETION_MARKER = ".complete";
52+
private File fileToTransfer;
53+
private String assetId;
54+
private String agreementId;
5355

54-
s3.createBucket(bucketName);
56+
@AfterAll
57+
public static void bucketsCleanup() {
58+
S3Client s3 = new S3Client(Environment.byName("Sokrates"));
59+
s3.deleteAllBuckets();
60+
}
5561

56-
Assertions.assertTrue(s3.listBuckets().contains(bucketName));
57-
Assertions.assertEquals(0, s3.listBucketContent(bucketName).size());
58-
}
62+
@Given("'{connector}' has an empty storage bucket called {string}")
63+
public void hasEmptyStorageBucket(Connector connector, String bucketName) {
64+
S3Client s3 = connector.getS3Client();
5965

60-
private File fileToTransfer;
66+
s3.createBucket(bucketName);
6167

62-
@Given("'{connector}' has a storage bucket called {string} with the file called {string}")
63-
public void hasAStorageBucketWithTheFile(Connector connector, String bucketName, String fileName)
64-
throws IOException {
68+
Assertions.assertTrue(s3.listBuckets().contains(bucketName));
69+
Assertions.assertEquals(0, s3.listBucketContent(bucketName).size());
70+
}
6571

66-
S3Client s3 = connector.getS3Client();
67-
s3.createBucket(bucketName);
68-
fileToTransfer = s3.uploadFile(bucketName, fileName);
72+
@Given("'{connector}' has a storage bucket called {string} with the file called {string}")
73+
public void hasAStorageBucketWithTheFile(Connector connector, String bucketName, String fileName)
74+
throws IOException {
6975

70-
Set<String> bucketContent = s3.listBucketContent(bucketName);
76+
S3Client s3 = connector.getS3Client();
77+
s3.createBucket(bucketName);
78+
fileToTransfer = s3.uploadFile(bucketName, fileName);
7179

72-
Assertions.assertEquals(1, bucketContent.size());
73-
Assertions.assertTrue(bucketContent.contains(fileName));
74-
}
80+
Set<String> bucketContent = s3.listBucketContent(bucketName);
7581

76-
@Given("'{connector}' has the following S3 assets")
77-
public void hasAssets(Connector connector, DataTable table) {
78-
final DataManagementAPI api = connector.getDataManagementAPI();
82+
Assertions.assertEquals(1, bucketContent.size());
83+
Assertions.assertTrue(bucketContent.contains(fileName));
84+
}
7985

80-
parseDataTable(table)
81-
.forEach(
82-
asset -> {
83-
try {
84-
api.createAsset(asset);
85-
} catch (IOException e) {
86-
fail(e.getMessage());
87-
}
88-
});
89-
}
86+
@Given("'{connector}' has the following S3 assets")
87+
public void hasAssets(Connector connector, DataTable table) {
88+
DataManagementAPI api = connector.getDataManagementAPI();
89+
90+
parseDataTable(table)
91+
.forEach(
92+
asset -> {
93+
try {
94+
api.createAsset(asset);
95+
} catch (IOException e) {
96+
fail(e.getMessage());
97+
}
98+
});
99+
}
90100

91-
private String assetId;
92-
private String agreementId;
101+
@Then("'{connector}' negotiates the contract successfully with '{connector}'")
102+
public void negotiateContract(Connector sender, Connector receiver, DataTable dataTable)
103+
throws IOException {
93104

94-
@Then("'{connector}' negotiates the contract successfully with '{connector}'")
95-
public void negotiateContract(Connector sender, Connector receiver, DataTable dataTable)
96-
throws IOException {
105+
String definitionId = dataTable.asMaps().get(0).get("contract offer id");
106+
assetId = dataTable.asMaps().get(0).get("asset id");
107+
String policyId = dataTable.asMaps().get(0).get("policy id");
97108

98-
String definitionId = dataTable.asMaps().get(0).get("contract offer id");
99-
assetId = dataTable.asMaps().get(0).get("asset id");
100-
String policyId = dataTable.asMaps().get(0).get("policy id");
109+
Policy policy =
110+
new Policy(policyId, List.of(new Permission("USE", new ArrayList<>(), null)));
101111

102-
final Policy policy =
103-
new Policy(policyId, List.of(new Permission("USE", null, new ArrayList<>())));
112+
DataManagementAPI dataManagementAPI = sender.getDataManagementAPI();
113+
String receiverIdsUrl = receiver.getEnvironment().getIdsUrl() + "/data";
104114

105-
final DataManagementAPI dataManagementAPI = sender.getDataManagementAPI();
106-
final String receiverIdsUrl = receiver.getEnvironment().getIdsUrl() + "/data";
115+
Negotiation negotiation =
116+
dataManagementAPI.initiateNegotiation(receiverIdsUrl, definitionId, assetId, policy);
117+
negotiation.waitUntilComplete(dataManagementAPI);
107118

108-
final Negotiation negotiation =
109-
dataManagementAPI.initiateNegotiation(receiverIdsUrl, definitionId, assetId, policy);
110-
negotiation.waitUntilComplete(dataManagementAPI);
119+
agreementId = dataManagementAPI.getNegotiation(negotiation.getId()).getAgreementId();
120+
}
111121

112-
agreementId = dataManagementAPI.getNegotiation(negotiation.getId()).getAgreementId();
113-
}
122+
@Then("'{connector}' initiate S3 transfer process from '{connector}'")
123+
public void initiateTransferProcess(Connector sender, Connector receiver, DataTable dataTable)
124+
throws IOException {
125+
DataAddress dataAddress = createDataAddress(dataTable.asMaps().get(0));
114126

115-
@Then("'{connector}' initiate S3 transfer process from '{connector}'")
116-
public void initiateTransferProcess(Connector sender, Connector receiver, DataTable dataTable)
117-
throws IOException {
118-
DataAddress dataAddress = createDataAddress(dataTable.asMaps().get(0));
127+
DataManagementAPI dataManagementAPI = sender.getDataManagementAPI();
128+
String receiverIdsUrl = receiver.getEnvironment().getIdsUrl() + "/data";
119129

120-
final DataManagementAPI dataManagementAPI = sender.getDataManagementAPI();
121-
final String receiverIdsUrl = receiver.getEnvironment().getIdsUrl() + "/data";
130+
Transfer transferProcess =
131+
dataManagementAPI.initiateTransferProcess(
132+
receiverIdsUrl, agreementId, assetId, dataAddress);
133+
transferProcess.waitUntilComplete(dataManagementAPI);
122134

123-
final Transfer transferProcess =
124-
dataManagementAPI.initiateTransferProcess(
125-
receiverIdsUrl, agreementId, assetId, dataAddress);
126-
transferProcess.waitUntilComplete(dataManagementAPI);
135+
Assertions.assertNotNull(transferProcess.getId());
136+
}
127137

128-
Assertions.assertNotNull(transferProcess.getId());
129-
}
138+
@Then("'{connector}' has a storage bucket called {string} with transferred file called {string}")
139+
public void consumerHasAStorageBucketWithFileTransferred(
140+
Connector connector, String bucketName, String fileName) throws IOException {
141+
S3Client s3 = connector.getS3Client();
142+
await()
143+
.pollDelay(Duration.ofMillis(500))
144+
.atMost(Timeouts.FILE_TRANSFER)
145+
.until(() -> isFilePresent(s3, bucketName, fileName + COMPLETION_MARKER));
146+
147+
Set<String> bucketContent = s3.listBucketContent(bucketName);
148+
149+
Assertions.assertEquals(2, bucketContent.size());
150+
Assertions.assertTrue(bucketContent.contains(fileName));
151+
Assertions.assertArrayEquals(
152+
Files.readAllBytes(fileToTransfer.toPath()),
153+
Files.readAllBytes(s3.downloadFile(bucketName, fileName).toPath()));
154+
}
130155

131-
private static final String COMPLETION_MARKER = ".complete";
156+
private boolean isFilePresent(S3Client s3, String bucketName, String fileName) {
157+
return s3.listBucketContent(bucketName).contains(fileName);
158+
}
132159

133-
@Then("'{connector}' has a storage bucket called {string} with transferred file called {string}")
134-
public void consumerHasAStorageBucketWithFileTransferred(
135-
Connector connector, String bucketName, String fileName) throws IOException {
136-
S3Client s3 = connector.getS3Client();
137-
await()
138-
.pollDelay(Duration.ofMillis(500))
139-
.atMost(Timeouts.FILE_TRANSFER)
140-
.until(() -> isFilePresent(s3, bucketName, fileName + COMPLETION_MARKER));
160+
private List<Asset> parseDataTable(DataTable table) {
161+
List<Asset> assetsWithDataAddresses = new ArrayList<>();
141162

142-
Set<String> bucketContent = s3.listBucketContent(bucketName);
163+
for (Map<String, String> map : table.asMaps()) {
164+
String id = map.get("id");
165+
String description = map.get("description");
166+
assetsWithDataAddresses.add(new Asset(id, description, createDataAddress(map)));
167+
}
143168

144-
Assertions.assertEquals(2, bucketContent.size());
145-
Assertions.assertTrue(bucketContent.contains(fileName));
146-
Assertions.assertArrayEquals(
147-
Files.readAllBytes(fileToTransfer.toPath()),
148-
Files.readAllBytes(s3.downloadFile(bucketName, fileName).toPath()));
149-
}
150-
151-
private boolean isFilePresent(S3Client s3, String bucketName, String fileName) {
152-
return s3.listBucketContent(bucketName).contains(fileName);
153-
}
154-
155-
private List<Asset> parseDataTable(DataTable table) {
156-
final List<Asset> assetsWithDataAddresses = new ArrayList<>();
157-
158-
for (Map<String, String> map : table.asMaps()) {
159-
String id = map.get("id");
160-
String description = map.get("description");
161-
assetsWithDataAddresses.add(new Asset(id, description, createDataAddress(map)));
169+
return assetsWithDataAddresses;
162170
}
163171

164-
return assetsWithDataAddresses;
165-
}
166-
167-
private DataAddress createDataAddress(Map<String, String> map) {
168-
final String bucketName = map.get("data_address_s3_bucket_name");
169-
final String region = map.get("data_address_s3_region");
170-
final String keyName = map.get("data_address_s3_key_name");
171-
return new S3DataAddress(bucketName, region, keyName);
172-
}
173-
174-
@AfterAll
175-
public static void bucketsCleanup() {
176-
S3Client s3 = new S3Client(Environment.byName("Sokrates"));
177-
s3.deleteAllBuckets();
178-
}
172+
private DataAddress createDataAddress(Map<String, String> map) {
173+
String bucketName = map.get("data_address_s3_bucket_name");
174+
String region = map.get("data_address_s3_region");
175+
String keyName = map.get("data_address_s3_key_name");
176+
return new S3DataAddress(bucketName, region, keyName);
177+
}
179178
}

‎edc-tests/cucumber/src/test/java/org/eclipse/tractusx/edc/tests/data/Asset.java

+20-6
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,28 @@
1919
*/
2020
package org.eclipse.tractusx.edc.tests.data;
2121

22-
import lombok.NonNull;
23-
import lombok.Value;
22+
import java.util.Objects;
2423

25-
@Value
2624
public class Asset {
27-
@NonNull String Id;
25+
private final String id;
26+
private final String description;
27+
private final DataAddress dataAddress;
2828

29-
@NonNull String description;
29+
public Asset(String id, String description, DataAddress dataAddress) {
30+
this.id = Objects.requireNonNull(id);
31+
this.description = Objects.requireNonNull(description);
32+
this.dataAddress = Objects.requireNonNull(dataAddress);
33+
}
3034

31-
@NonNull DataAddress dataAddress;
35+
public String getId() {
36+
return id;
37+
}
38+
39+
public String getDescription() {
40+
return description;
41+
}
42+
43+
public DataAddress getDataAddress() {
44+
return dataAddress;
45+
}
3246
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
package org.eclipse.tractusx.edc.tests.data;
22

3-
import lombok.NonNull;
4-
import lombok.Value;
3+
import java.util.Objects;
54

6-
@Value
75
public class BusinessPartnerNumberConstraint implements Constraint {
86

9-
@NonNull String businessPartnerNumber;
7+
private final String businessPartnerNumber;
8+
9+
public BusinessPartnerNumberConstraint(String businessPartnerNumber) {
10+
this.businessPartnerNumber = Objects.requireNonNull(businessPartnerNumber);
11+
}
12+
13+
public String getBusinessPartnerNumber() {
14+
return businessPartnerNumber;
15+
}
1016
}

‎edc-tests/cucumber/src/test/java/org/eclipse/tractusx/edc/tests/data/ContractDefinition.java

+33-8
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,42 @@
2020
package org.eclipse.tractusx.edc.tests.data;
2121

2222
import java.util.List;
23-
import lombok.NonNull;
24-
import lombok.Value;
23+
import java.util.Objects;
24+
2525

26-
@Value
2726
public class ContractDefinition {
2827

29-
@NonNull String id;
28+
private final String id;
29+
30+
private final String contractPolicyId;
31+
private final String acccessPolicyId;
32+
33+
private final List<String> assetIds;
34+
private final Long validity;
35+
36+
public ContractDefinition(String id, String contractPolicyId, String acccessPolicyId, List<String> assetIds, Long validity) {
37+
this.id = Objects.requireNonNull(id);
38+
this.contractPolicyId = Objects.requireNonNull(contractPolicyId);
39+
this.acccessPolicyId = Objects.requireNonNull(acccessPolicyId);
40+
this.assetIds = assetIds;
41+
this.validity = validity;
42+
}
43+
44+
public String getId() {
45+
return id;
46+
}
47+
48+
public String getContractPolicyId() {
49+
return contractPolicyId;
50+
}
51+
52+
public String getAcccessPolicyId() {
53+
return acccessPolicyId;
54+
}
55+
56+
public List<String> getAssetIds() {
57+
return assetIds;
58+
}
3059

31-
@NonNull String contractPolicyId;
32-
@NonNull String acccessPolicyId;
3360

34-
List<String> assetIds;
35-
Long validity;
3661
}

‎edc-tests/cucumber/src/test/java/org/eclipse/tractusx/edc/tests/data/ContractNegotiation.java

+23-6
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,29 @@
2020

2121
package org.eclipse.tractusx.edc.tests.data;
2222

23-
import lombok.NonNull;
24-
import lombok.Value;
23+
import java.util.Objects;
2524

26-
@Value
2725
public class ContractNegotiation {
28-
@NonNull String id;
29-
String agreementId;
30-
@NonNull ContractNegotiationState state;
26+
private final String id;
27+
private final ContractNegotiationState state;
28+
private final String agreementId;
29+
30+
31+
public ContractNegotiation(String id, ContractNegotiationState state, String agreementId) {
32+
this.id = Objects.requireNonNull(id);
33+
this.state = Objects.requireNonNull(state);
34+
this.agreementId = agreementId;
35+
}
36+
37+
public String getId() {
38+
return id;
39+
}
40+
41+
public ContractNegotiationState getState() {
42+
return state;
43+
}
44+
45+
public String getAgreementId() {
46+
return agreementId;
47+
}
3148
}

‎edc-tests/cucumber/src/test/java/org/eclipse/tractusx/edc/tests/data/ContractOffer.java

+22-6
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,28 @@
1919
*/
2020
package org.eclipse.tractusx.edc.tests.data;
2121

22-
import lombok.NonNull;
23-
import lombok.Value;
22+
import java.util.Objects;
2423

25-
@Value
2624
public class ContractOffer {
27-
@NonNull String id;
28-
Policy policy;
29-
String assetId;
25+
private final String id;
26+
private final Policy policy;
27+
private final String assetId;
28+
29+
public ContractOffer(String id, Policy policy, String assetId) {
30+
this.id = Objects.requireNonNull(id);
31+
this.policy = policy;
32+
this.assetId = assetId;
33+
}
34+
35+
public String getId() {
36+
return id;
37+
}
38+
39+
public Policy getPolicy() {
40+
return policy;
41+
}
42+
43+
public String getAssetId() {
44+
return assetId;
45+
}
3046
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,52 @@
11
package org.eclipse.tractusx.edc.tests.data;
22

3-
import lombok.NonNull;
4-
import lombok.Value;
3+
import java.util.Objects;
4+
55

6-
@Value
76
public class HttpProxySourceDataAddress implements DataAddress {
8-
@NonNull String baseUrl;
9-
Oauth2Provision oauth2Provision;
10-
11-
@Value
12-
public static class Oauth2Provision {
13-
@NonNull String tokenUrl;
14-
@NonNull String clientId;
15-
@NonNull String clientSecret;
16-
String scope;
17-
}
7+
private final String baseUrl;
8+
private final Oauth2Provision oauth2Provision;
9+
10+
public HttpProxySourceDataAddress(String baseUrl, Oauth2Provision oauth2Provision) {
11+
this.baseUrl = Objects.requireNonNull(baseUrl);
12+
this.oauth2Provision = oauth2Provision;
13+
}
14+
15+
public String getBaseUrl() {
16+
return baseUrl;
17+
}
18+
19+
public Oauth2Provision getOauth2Provision() {
20+
return oauth2Provision;
21+
}
22+
23+
public static class Oauth2Provision {
24+
private final String tokenUrl;
25+
private final String clientId;
26+
private final String clientSecret;
27+
private final String scope;
28+
29+
public Oauth2Provision(String tokenUrl, String clientId, String clientSecret, String scope) {
30+
this.tokenUrl = Objects.requireNonNull(tokenUrl);
31+
this.clientId = Objects.requireNonNull(clientId);
32+
this.clientSecret = Objects.requireNonNull(clientSecret);
33+
this.scope = scope;
34+
}
35+
36+
public String getTokenUrl() {
37+
return tokenUrl;
38+
}
39+
40+
public String getScope() {
41+
return scope;
42+
}
43+
44+
public String getClientId() {
45+
return clientId;
46+
}
47+
48+
public String getClientSecret() {
49+
return clientSecret;
50+
}
51+
}
1852
}
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,43 @@
11
package org.eclipse.tractusx.edc.tests.data;
22

3-
import static org.awaitility.Awaitility.await;
3+
import org.eclipse.tractusx.edc.tests.DataManagementAPI;
4+
import org.eclipse.tractusx.edc.tests.util.Timeouts;
45

5-
import groovyjarjarantlr4.v4.runtime.misc.NotNull;
66
import java.io.IOException;
77
import java.time.Duration;
8+
import java.util.Objects;
89
import java.util.stream.Stream;
9-
import lombok.Value;
10-
import org.eclipse.tractusx.edc.tests.DataManagementAPI;
11-
import org.eclipse.tractusx.edc.tests.util.Timeouts;
1210

13-
@Value
11+
import static org.awaitility.Awaitility.await;
12+
13+
1414
public class Negotiation {
1515

16-
@NotNull String id;
17-
18-
public void waitUntilComplete(DataManagementAPI dataManagementAPI) {
19-
await()
20-
.pollDelay(Duration.ofMillis(2000))
21-
.atMost(Timeouts.CONTRACT_NEGOTIATION)
22-
.until(() -> isComplete(dataManagementAPI));
23-
}
24-
25-
public boolean isComplete(DataManagementAPI dataManagementAPI) throws IOException {
26-
var negotiation = dataManagementAPI.getNegotiation(id);
27-
return negotiation != null
28-
&& Stream.of(
29-
ContractNegotiationState.ERROR,
30-
ContractNegotiationState.CONFIRMED,
31-
ContractNegotiationState.DECLINED)
32-
.anyMatch((l) -> l.equals(negotiation.getState()));
33-
}
16+
17+
private final String id;
18+
19+
public Negotiation(String id) {
20+
this.id = Objects.requireNonNull(id);
21+
}
22+
23+
public void waitUntilComplete(DataManagementAPI dataManagementAPI) {
24+
await()
25+
.pollDelay(Duration.ofMillis(2000))
26+
.atMost(Timeouts.CONTRACT_NEGOTIATION)
27+
.until(() -> isComplete(dataManagementAPI));
28+
}
29+
30+
public boolean isComplete(DataManagementAPI dataManagementAPI) throws IOException {
31+
var negotiation = dataManagementAPI.getNegotiation(id);
32+
return negotiation != null
33+
&& Stream.of(
34+
ContractNegotiationState.ERROR,
35+
ContractNegotiationState.CONFIRMED,
36+
ContractNegotiationState.DECLINED)
37+
.anyMatch((l) -> l.equals(negotiation.getState()));
38+
}
39+
40+
public String getId() {
41+
return id;
42+
}
3443
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
package org.eclipse.tractusx.edc.tests.data;
22

33
import java.util.List;
4-
import lombok.NonNull;
5-
import lombok.Value;
4+
import java.util.Objects;
5+
66

7-
@Value
87
public class OrConstraint implements Constraint {
98

10-
@NonNull List<? extends Constraint> constraints;
9+
private final List<? extends Constraint> constraints;
10+
11+
public OrConstraint(List<? extends Constraint> constraints) {
12+
this.constraints = Objects.requireNonNull(constraints);
13+
}
14+
15+
public List<? extends Constraint> getConstraints() {
16+
return constraints;
17+
}
1118
}

‎edc-tests/cucumber/src/test/java/org/eclipse/tractusx/edc/tests/data/PayMeConstraint.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,19 @@
2020

2121
package org.eclipse.tractusx.edc.tests.data;
2222

23-
import lombok.Value;
24-
2523
/**
2624
* The PayMe constraint should be used when no constraint validation/enforcement in the EDC is
2725
* intended.
2826
*/
29-
@Value
27+
3028
public class PayMeConstraint implements Constraint {
31-
double amount;
29+
private final double amount;
30+
31+
public PayMeConstraint(double amount) {
32+
this.amount = amount;
33+
}
34+
35+
public double getAmount() {
36+
return amount;
37+
}
3238
}

‎edc-tests/cucumber/src/test/java/org/eclipse/tractusx/edc/tests/data/Permission.java

+23-6
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,30 @@
2020
package org.eclipse.tractusx.edc.tests.data;
2121

2222
import java.util.List;
23-
import lombok.NonNull;
24-
import lombok.Value;
23+
import java.util.Objects;
24+
2525

26-
@Value
2726
public class Permission {
28-
@NonNull String action;
29-
String target;
27+
private final String action;
28+
private final List<Constraint> constraints;
29+
private final String target;
30+
31+
32+
public Permission(String action, List<Constraint> constraints, String target) {
33+
this.action = Objects.requireNonNull(action);
34+
this.constraints = Objects.requireNonNull(constraints);
35+
this.target = target;
36+
}
37+
38+
public String getAction() {
39+
return action;
40+
}
41+
42+
public List<Constraint> getConstraints() {
43+
return constraints;
44+
}
3045

31-
@NonNull List<Constraint> constraints;
46+
public String getTarget() {
47+
return target;
48+
}
3249
}

‎edc-tests/cucumber/src/test/java/org/eclipse/tractusx/edc/tests/data/Policy.java

+17-5
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,23 @@
2121
package org.eclipse.tractusx.edc.tests.data;
2222

2323
import java.util.List;
24-
import lombok.NonNull;
25-
import lombok.Value;
24+
import java.util.Objects;
25+
2626

27-
@Value
2827
public class Policy {
29-
String id;
30-
@NonNull List<Permission> Permission;
28+
private final String id;
29+
private final List<Permission> Permission;
30+
31+
public Policy(String id, List<Permission> permission) {
32+
this.id = id;
33+
Permission = Objects.requireNonNull(permission);
34+
}
35+
36+
public String getId() {
37+
return id;
38+
}
39+
40+
public List<Permission> getPermission() {
41+
return Permission;
42+
}
3143
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
package org.eclipse.tractusx.edc.tests.data;
22

3-
import lombok.NonNull;
4-
import lombok.Value;
3+
import java.util.Objects;
54

6-
@Value
75
public class S3DataAddress implements DataAddress {
86

9-
@NonNull String bucketName;
10-
@NonNull String region;
11-
@NonNull String keyName;
7+
private final String bucketName;
8+
private final String region;
9+
private final String keyName;
10+
11+
public S3DataAddress(String bucketName, String region, String keyName) {
12+
this.bucketName = Objects.requireNonNull(bucketName);
13+
this.region = Objects.requireNonNull(region);
14+
this.keyName = Objects.requireNonNull(keyName);
15+
}
16+
17+
public String getBucketName() {
18+
return bucketName;
19+
}
20+
21+
public String getRegion() {
22+
return region;
23+
}
24+
25+
public String getKeyName() {
26+
return keyName;
27+
}
1228
}
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
11
package org.eclipse.tractusx.edc.tests.data;
22

3-
import static org.awaitility.Awaitility.await;
3+
import org.eclipse.tractusx.edc.tests.DataManagementAPI;
4+
import org.eclipse.tractusx.edc.tests.util.Timeouts;
45

56
import java.io.IOException;
67
import java.time.Duration;
7-
import lombok.Value;
8-
import org.eclipse.tractusx.edc.tests.DataManagementAPI;
9-
import org.eclipse.tractusx.edc.tests.util.Timeouts;
108

11-
@Value
9+
import static org.awaitility.Awaitility.await;
10+
11+
1212
public class Transfer {
1313

14-
String id;
14+
private final String id;
15+
16+
public Transfer(String id) {
17+
this.id = id;
18+
}
19+
20+
public void waitUntilComplete(DataManagementAPI dataManagementAPI) {
21+
await()
22+
.pollDelay(Duration.ofMillis(2000))
23+
.atMost(Timeouts.FILE_TRANSFER)
24+
.until(() -> isComplete(dataManagementAPI));
25+
}
1526

16-
public void waitUntilComplete(DataManagementAPI dataManagementAPI) {
17-
await()
18-
.pollDelay(Duration.ofMillis(2000))
19-
.atMost(Timeouts.FILE_TRANSFER)
20-
.until(() -> isComplete(dataManagementAPI));
21-
}
27+
public boolean isComplete(DataManagementAPI dataManagementAPI) throws IOException {
28+
var transferProcess = dataManagementAPI.getTransferProcess(id);
29+
if (transferProcess == null) {
30+
return false;
31+
}
2232

23-
public boolean isComplete(DataManagementAPI dataManagementAPI) throws IOException {
24-
var transferProcess = dataManagementAPI.getTransferProcess(id);
25-
if (transferProcess == null) return false;
33+
var state = transferProcess.getState();
2634

27-
var state = transferProcess.getState();
35+
return state == TransferProcessState.COMPLETED || state == TransferProcessState.ERROR;
36+
}
2837

29-
return state == TransferProcessState.COMPLETED || state == TransferProcessState.ERROR;
30-
}
38+
public String getId() {
39+
return id;
40+
}
3141
}

‎edc-tests/cucumber/src/test/java/org/eclipse/tractusx/edc/tests/data/TransferProcess.java

+16-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,22 @@
1919

2020
package org.eclipse.tractusx.edc.tests.data;
2121

22-
import lombok.NonNull;
23-
import lombok.Value;
22+
import java.util.Objects;
2423

25-
@Value
2624
public class TransferProcess {
27-
@NonNull String id;
28-
@NonNull TransferProcessState state;
25+
private final String id;
26+
private final TransferProcessState state;
27+
28+
public TransferProcess(String id, TransferProcessState state) {
29+
this.id = Objects.requireNonNull(id);
30+
this.state = Objects.requireNonNull(state);
31+
}
32+
33+
public String getId() {
34+
return id;
35+
}
36+
37+
public TransferProcessState getState() {
38+
return state;
39+
}
2940
}

‎edc-tests/cucumber/src/test/java/org/eclipse/tractusx/edc/tests/util/DatabaseCleaner.java

+25-20
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,33 @@
2424
import java.sql.DriverManager;
2525
import java.sql.SQLException;
2626
import java.sql.Statement;
27-
import lombok.RequiredArgsConstructor;
2827

29-
@RequiredArgsConstructor
28+
3029
public class DatabaseCleaner {
3130

32-
private static final String SQL =
33-
"DELETE FROM edc_contract_negotiation;\n"
34-
+ "DELETE FROM edc_contract_agreement;\n"
35-
+ "DELETE FROM edc_transfer_process;\n"
36-
+ "DELETE FROM edc_contract_definitions;\n"
37-
+ "DELETE FROM edc_policydefinitions;\n"
38-
+ "DELETE FROM edc_asset;\n"
39-
+ "DELETE FROM edc_lease;";
40-
41-
private final String url;
42-
private final String user;
43-
private final String password;
44-
45-
public void run() throws SQLException {
46-
try (Connection con = DriverManager.getConnection(url, user, password)) {
47-
Statement st = con.createStatement();
48-
st.executeUpdate(SQL);
31+
private static final String SQL =
32+
"DELETE FROM edc_contract_negotiation;\n"
33+
+ "DELETE FROM edc_contract_agreement;\n"
34+
+ "DELETE FROM edc_transfer_process;\n"
35+
+ "DELETE FROM edc_contract_definitions;\n"
36+
+ "DELETE FROM edc_policydefinitions;\n"
37+
+ "DELETE FROM edc_asset;\n"
38+
+ "DELETE FROM edc_lease;";
39+
40+
private final String url;
41+
private final String user;
42+
private final String password;
43+
44+
public DatabaseCleaner(String url, String user, String password) {
45+
this.url = url;
46+
this.user = user;
47+
this.password = password;
48+
}
49+
50+
public void run() throws SQLException {
51+
try (Connection con = DriverManager.getConnection(url, user, password)) {
52+
Statement st = con.createStatement();
53+
st.executeUpdate(SQL);
54+
}
4955
}
50-
}
5156
}

‎edc-tests/cucumber/src/test/java/org/eclipse/tractusx/edc/tests/util/S3Client.java

+85-82
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,10 @@
1919

2020
package org.eclipse.tractusx.edc.tests.util;
2121

22-
import java.io.File;
23-
import java.io.IOException;
24-
import java.net.URI;
25-
import java.nio.charset.StandardCharsets;
26-
import java.nio.file.Files;
27-
import java.util.List;
28-
import java.util.Set;
29-
import java.util.stream.Collectors;
30-
import lombok.extern.slf4j.Slf4j;
22+
import org.eclipse.tractusx.edc.tests.BackendServiceBackendAPI;
3123
import org.eclipse.tractusx.edc.tests.Environment;
24+
import org.slf4j.Logger;
25+
import org.slf4j.LoggerFactory;
3226
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
3327
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
3428
import software.amazon.awssdk.core.ResponseBytes;
@@ -45,80 +39,89 @@
4539
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
4640
import software.amazon.awssdk.services.s3.model.S3Object;
4741

48-
@Slf4j
42+
import java.io.File;
43+
import java.io.IOException;
44+
import java.net.URI;
45+
import java.nio.charset.StandardCharsets;
46+
import java.nio.file.Files;
47+
import java.util.List;
48+
import java.util.Set;
49+
import java.util.stream.Collectors;
50+
51+
4952
public class S3Client {
53+
private static final Logger log = LoggerFactory.getLogger(BackendServiceBackendAPI.class);
54+
private final software.amazon.awssdk.services.s3.S3Client s3;
55+
56+
public S3Client(Environment environment) {
57+
58+
s3 =
59+
software.amazon.awssdk.services.s3.S3Client.builder()
60+
.region(Region.US_EAST_1)
61+
.forcePathStyle(true)
62+
.endpointOverride(URI.create(environment.getAwsEndpointOverride()))
63+
.credentialsProvider(
64+
StaticCredentialsProvider.create(
65+
AwsBasicCredentials.create(
66+
environment.getAwsAccessKey(), environment.getAwsSecretAccessKey())))
67+
.build();
68+
}
69+
70+
public void createBucket(String bucketName) {
71+
try {
72+
s3.createBucket(CreateBucketRequest.builder().bucket(bucketName).build());
73+
} catch (BucketAlreadyOwnedByYouException e) {
74+
log.info("'{}' bucket already owned - skipped bucket creation", bucketName);
75+
}
76+
}
77+
78+
public File uploadFile(String bucketName, String fileName) throws IOException {
79+
File tempFile = File.createTempFile(fileName, null);
80+
Files.write(
81+
tempFile.toPath(), "Will fail if the file has no content".getBytes(StandardCharsets.UTF_8));
82+
83+
s3.putObject(
84+
PutObjectRequest.builder().bucket(bucketName).key(fileName).build(),
85+
RequestBody.fromFile(tempFile));
86+
87+
return tempFile;
88+
}
89+
90+
public List<String> listBuckets() {
91+
return s3.listBuckets().buckets().stream().map(Bucket::name).collect(Collectors.toList());
92+
}
93+
94+
public Set<String> listBucketContent(String bucketName) {
95+
return s3
96+
.listObjects(ListObjectsRequest.builder().bucket(bucketName).build())
97+
.contents()
98+
.stream()
99+
.map(S3Object::key)
100+
.collect(Collectors.toSet());
101+
}
102+
103+
public File downloadFile(String bucketName, String fileName) throws IOException {
104+
ResponseBytes<GetObjectResponse> objectAsBytes =
105+
s3.getObjectAsBytes(GetObjectRequest.builder().bucket(bucketName).key(fileName).build());
106+
107+
return Files.write(File.createTempFile(fileName, null).toPath(), objectAsBytes.asByteArray())
108+
.toFile();
109+
}
110+
111+
public void deleteAllBuckets() {
112+
List<Bucket> buckets = s3.listBuckets().buckets();
113+
buckets.forEach(this::clearBucket);
114+
buckets.forEach(
115+
bucket -> s3.deleteBucket(DeleteBucketRequest.builder().bucket(bucket.name()).build()));
116+
}
50117

51-
private final software.amazon.awssdk.services.s3.S3Client s3;
52-
53-
public S3Client(Environment environment) {
54-
55-
s3 =
56-
software.amazon.awssdk.services.s3.S3Client.builder()
57-
.region(Region.US_EAST_1)
58-
.forcePathStyle(true)
59-
.endpointOverride(URI.create(environment.getAwsEndpointOverride()))
60-
.credentialsProvider(
61-
StaticCredentialsProvider.create(
62-
AwsBasicCredentials.create(
63-
environment.getAwsAccessKey(), environment.getAwsSecretAccessKey())))
64-
.build();
65-
}
66-
67-
public void createBucket(String bucketName) {
68-
try {
69-
s3.createBucket(CreateBucketRequest.builder().bucket(bucketName).build());
70-
} catch (BucketAlreadyOwnedByYouException e) {
71-
log.info("'{}' bucket already owned - skipped bucket creation", bucketName);
118+
private void clearBucket(Bucket bucket) {
119+
String bucketName = bucket.name();
120+
s3.listObjects(ListObjectsRequest.builder().bucket(bucketName).build())
121+
.contents()
122+
.forEach(
123+
s3Object ->
124+
s3.deleteObject(
125+
DeleteObjectRequest.builder().bucket(bucketName).key(s3Object.key()).build()));
72126
}
73-
}
74-
75-
public File uploadFile(String bucketName, String fileName) throws IOException {
76-
File tempFile = File.createTempFile(fileName, null);
77-
Files.write(
78-
tempFile.toPath(), "Will fail if the file has no content".getBytes(StandardCharsets.UTF_8));
79-
80-
s3.putObject(
81-
PutObjectRequest.builder().bucket(bucketName).key(fileName).build(),
82-
RequestBody.fromFile(tempFile));
83-
84-
return tempFile;
85-
}
86-
87-
public List<String> listBuckets() {
88-
return s3.listBuckets().buckets().stream().map(Bucket::name).collect(Collectors.toList());
89-
}
90-
91-
public Set<String> listBucketContent(String bucketName) {
92-
return s3
93-
.listObjects(ListObjectsRequest.builder().bucket(bucketName).build())
94-
.contents()
95-
.stream()
96-
.map(S3Object::key)
97-
.collect(Collectors.toSet());
98-
}
99-
100-
public File downloadFile(String bucketName, String fileName) throws IOException {
101-
ResponseBytes<GetObjectResponse> objectAsBytes =
102-
s3.getObjectAsBytes(GetObjectRequest.builder().bucket(bucketName).key(fileName).build());
103-
104-
return Files.write(File.createTempFile(fileName, null).toPath(), objectAsBytes.asByteArray())
105-
.toFile();
106-
}
107-
108-
public void deleteAllBuckets() {
109-
List<Bucket> buckets = s3.listBuckets().buckets();
110-
buckets.forEach(this::clearBucket);
111-
buckets.forEach(
112-
bucket -> s3.deleteBucket(DeleteBucketRequest.builder().bucket(bucket.name()).build()));
113-
}
114-
115-
private void clearBucket(Bucket bucket) {
116-
String bucketName = bucket.name();
117-
s3.listObjects(ListObjectsRequest.builder().bucket(bucketName).build())
118-
.contents()
119-
.forEach(
120-
s3Object ->
121-
s3.deleteObject(
122-
DeleteObjectRequest.builder().bucket(bucketName).key(s3Object.key()).build()));
123-
}
124127
}

0 commit comments

Comments
 (0)
Please sign in to comment.