Skip to content

Commit

Permalink
feat(tests): removes lombok from edc-tests module (eclipse-tractusx#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood authored Apr 14, 2023
1 parent 31d879d commit 4f4474a
Show file tree
Hide file tree
Showing 26 changed files with 1,577 additions and 1,152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,56 @@

package org.eclipse.tractusx.edc.tests;

import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;

import org.eclipse.tractusx.edc.tests.util.DatabaseCleaner;
import org.eclipse.tractusx.edc.tests.util.S3Client;

import static org.mockito.Mockito.mock;

@RequiredArgsConstructor
public class Connector {

@NonNull
@Getter
private final String name;

@Getter
@NonNull
private final Environment environment;

@Getter(lazy = true)
private final DataManagementAPI dataManagementAPI = loadDataManagementAPI();
private final DataManagementAPI dataManagementAPI;

private final DatabaseCleaner databaseCleaner;


private final S3Client s3Client;

public Connector(String name, Environment environment) {
this.name = name;
this.environment = environment;
dataManagementAPI = loadDataManagementAPI();
databaseCleaner = loadDatabaseCleaner();
s3Client = createS3Client();
}

public BackendDataService getBackendServiceBackendAPI() {
return mock(BackendDataService.class);
}

public DatabaseCleaner getDatabaseCleaner() {
return databaseCleaner;
}

@Getter(lazy = true)
private final BackendDataService backendServiceBackendAPI = loadBackendServiceBackendAPI();
public DataManagementAPI getDataManagementAPI() {
return dataManagementAPI;
}

@Getter(lazy = true)
private final DatabaseCleaner databaseCleaner = loadDatabaseCleaner();
public Environment getEnvironment() {
return environment;
}

@Getter(lazy = true)
private final S3Client s3Client = createS3Client();
public S3Client getS3Client() {
return s3Client;
}

public String getName() {
return name;
}

private DataManagementAPI loadDataManagementAPI() {
return new DataManagementAPI(
Expand All @@ -63,9 +83,6 @@ private DatabaseCleaner loadDatabaseCleaner() {
environment.getDatabasePassword());
}

private BackendDataService loadBackendServiceBackendAPI() {
return mock(BackendDataService.class);
}

private S3Client createS3Client() {
return new S3Client(environment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,25 @@

package org.eclipse.tractusx.edc.tests;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import lombok.NonNull;
import lombok.experimental.UtilityClass;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;


@UtilityClass
public class ConnectorFactory {
private static final Map<String, Connector> CONNECTOR_CACHE = new HashMap<>();
private static final Map<String, Connector> CONNECTOR_CACHE = new ConcurrentHashMap<>();

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

private static Connector createConnector(@NonNull final String name) {
final Environment environment = Environment.byName(name);
private static Connector createConnector(String name) {
Objects.requireNonNull(name);
Environment environment = Environment.byName(name);

return new Connector(name, environment);
}
return new Connector(name, environment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,16 @@

package org.eclipse.tractusx.edc.tests;

import lombok.experimental.UtilityClass;

@UtilityClass
public final class Constants {
public static final String DATA_MANAGEMENT_URL = "DATA_MANAGEMENT_URL";
public static final String DATA_MANAGEMENT_API_AUTH_KEY = "DATA_MANAGEMENT_API_AUTH_KEY";
public static final String IDS_URL = "IDS_URL";
public static final String DATA_PLANE_URL = "DATA_PLANE_URL";
public static final String BACKEND_SERVICE_BACKEND_API_URL = "BACKEND_SERVICE_BACKEND_API_URL";
public static final String DATABASE_URL = "DATABASE_URL";
public static final String DATABASE_USER = "DATABASE_USER";
public static final String DATABASE_PASSWORD = "DATABASE_PASSWORD";
public static final String EDC_AWS_ENDPOINT_OVERRIDE = "EDC_AWS_ENDPOINT_OVERRIDE";
public static final String AWS_ACCESS_KEY_ID = "AWS_ACCESS_KEY_ID";
public static final String AWS_SECRET_ACCESS_KEY = "AWS_SECRET_ACCESS_KEY";
public static final String DATA_MANAGEMENT_URL = "DATA_MANAGEMENT_URL";
public static final String DATA_MANAGEMENT_API_AUTH_KEY = "DATA_MANAGEMENT_API_AUTH_KEY";
public static final String IDS_URL = "IDS_URL";
public static final String DATA_PLANE_URL = "DATA_PLANE_URL";
public static final String BACKEND_SERVICE_BACKEND_API_URL = "BACKEND_SERVICE_BACKEND_API_URL";
public static final String DATABASE_URL = "DATABASE_URL";
public static final String DATABASE_USER = "DATABASE_USER";
public static final String DATABASE_PASSWORD = "DATABASE_PASSWORD";
public static final String EDC_AWS_ENDPOINT_OVERRIDE = "EDC_AWS_ENDPOINT_OVERRIDE";
public static final String AWS_ACCESS_KEY_ID = "AWS_ACCESS_KEY_ID";
public static final String AWS_SECRET_ACCESS_KEY = "AWS_SECRET_ACCESS_KEY";
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,64 +22,66 @@

import com.google.gson.Gson;
import io.cucumber.datatable.DataTable;
import java.io.IOException;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.eclipse.edc.spi.system.health.HealthStatus;
import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Map;

@Slf4j
public class ControlPlaneAdapterSteps {

private EndpointDataReference endpointDataReference;
private static final Logger log = LoggerFactory.getLogger(ControlPlaneAdapterSteps.class);
private EndpointDataReference endpointDataReference;

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

// @When("'{connector}' gets a request endpoint from '{connector}'")
public void getEndPointFromGetRequest(Connector consumer, Connector receiver, DataTable table)
throws IOException {
// @When("'{connector}' gets a request endpoint from '{connector}'")
public void getEndPointFromGetRequest(Connector consumer, Connector receiver, DataTable table)
throws IOException {

final DataManagementAPI dataManagementAPI = consumer.getDataManagementAPI();
final String receiverIdsUrl = receiver.getEnvironment().getIdsUrl() + "/data";
DataManagementAPI dataManagementAPI = consumer.getDataManagementAPI();
String receiverIdsUrl = receiver.getEnvironment().getIdsUrl() + "/data";

for (Map<String, String> map : table.asMaps()) {
final String assetId = map.get("asset id");
for (Map<String, String> map : table.asMaps()) {
String assetId = map.get("asset id");

endpointDataReference = dataManagementAPI.getEdcEndpoint(assetId, receiverIdsUrl);
endpointDataReference = dataManagementAPI.getEdcEndpoint(assetId, receiverIdsUrl);

log.debug("endpointDataReference in controlplane" + endpointDataReference.toString());
log.debug("endpointDataReference in controlplane" + endpointDataReference.toString());
}
}
}

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

// @Then("'{connector}' asks for the asset from the endpoint")
public void receiveEndpoint(Connector consumer) throws IOException {
// @Then("'{connector}' asks for the asset from the endpoint")
public void receiveEndpoint(Connector consumer) throws IOException {

var requestUrl = endpointDataReference.getEndpoint();
var key = endpointDataReference.getAuthKey();
var value = endpointDataReference.getAuthCode();
var httpClient = HttpClientBuilder.create().build();
var get = new HttpGet(requestUrl);
get.addHeader(key, value);
final CloseableHttpResponse response = httpClient.execute(get);
var bytes = response.getEntity().getContent().readAllBytes();
var result = new String(bytes);
var resultTransformed = new Gson().fromJson(result, HealthStatus.class);
var requestUrl = endpointDataReference.getEndpoint();
var key = endpointDataReference.getAuthKey();
var value = endpointDataReference.getAuthCode();
var httpClient = HttpClientBuilder.create().build();
var get = new HttpGet(requestUrl);
get.addHeader(key, value);
CloseableHttpResponse response = httpClient.execute(get);
var bytes = response.getEntity().getContent().readAllBytes();
var result = new String(bytes);
var resultTransformed = new Gson().fromJson(result, HealthStatus.class);

Assertions.assertTrue(resultTransformed.isHealthy());
Assertions.assertFalse(resultTransformed.getComponentResults().isEmpty());
}
Assertions.assertTrue(resultTransformed.isHealthy());
Assertions.assertFalse(resultTransformed.getComponentResults().isEmpty());
}
}
Loading

0 comments on commit 4f4474a

Please sign in to comment.