Skip to content

Commit

Permalink
move tests to use the JUnit runner
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger committed Dec 28, 2023
1 parent eb295f3 commit caa15fe
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 186 deletions.
17 changes: 3 additions & 14 deletions .github/workflows/verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
- name: Component Tests
uses: ./.github/actions/run-tests
with:
command: ./gradlew test jacocoTestReport -DincludeTags="ComponentTest"
command: ./gradlew test jacocoTestReport -DincludeTags="ComponentTest" -PverboseTest=true

End-To-End-Tests:
runs-on: ubuntu-latest
Expand All @@ -83,23 +83,12 @@ jobs:

- name: 'Build Launchers'
run: |
./gradlew -p system-tests/end2end-test clean shadowJar
- name: 'Install docker compose plugin'
run: |
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.17.3/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
- name: 'Start FCC Runtime in Docker'
run: docker compose -f system-tests/end2end-test/docker-compose.yml up --build --wait
timeout-minutes: 10
./gradlew compileJava compileTestJava
- name: 'End to End Integration Tests'
uses: ./.github/actions/run-tests
with:
command: ./gradlew system-tests:end2end-test:e2e-junit:test -DincludeTags="EndToEndTest"
command: ./gradlew test jacocoTestReport -DincludeTags="EndToEndTest" -PverboseTest=true

API-Tests:
env:
Expand Down
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,11 @@ allprojects {
configDirectory.set(rootProject.file("resources"))
}

// EdcRuntimeExtension uses this to determine the runtime classpath of the module to run.
tasks.register("printClasspath") {
doLast {
println(sourceSets["main"].runtimeClasspath.asPath)
}
}

}
Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

44 changes: 0 additions & 44 deletions system-tests/end2end-test/docker-compose.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ plugins {

dependencies {
testImplementation(project(":spi:federated-catalog-spi"))
testImplementation(project(":core:federated-catalog-core"))
testImplementation(libs.awaitility)
testImplementation(libs.edc.api.management)
testImplementation(libs.edc.core.transform)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.eclipse.edc.end2end;

public record Endpoint(String path, String port) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import jakarta.json.Json;
import jakarta.json.JsonBuilderFactory;
import org.eclipse.edc.catalog.directory.InMemoryNodeDirectory;
import org.eclipse.edc.catalog.spi.CatalogConstants;
import org.eclipse.edc.core.transform.TypeTransformerRegistryImpl;
import org.eclipse.edc.core.transform.transformer.from.JsonObjectFromCatalogTransformer;
import org.eclipse.edc.core.transform.transformer.from.JsonObjectFromDataServiceTransformer;
Expand All @@ -29,18 +31,24 @@
import org.eclipse.edc.core.transform.transformer.to.JsonObjectToDatasetTransformer;
import org.eclipse.edc.core.transform.transformer.to.JsonObjectToDistributionTransformer;
import org.eclipse.edc.core.transform.transformer.to.JsonValueToGenericTypeTransformer;
import org.eclipse.edc.crawler.spi.TargetNode;
import org.eclipse.edc.crawler.spi.TargetNodeDirectory;
import org.eclipse.edc.jsonld.TitaniumJsonLd;
import org.eclipse.edc.jsonld.util.JacksonJsonLd;
import org.eclipse.edc.junit.annotations.EndToEndTest;
import org.eclipse.edc.junit.extensions.EdcRuntimeExtension;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.result.Result;
import org.eclipse.edc.transform.spi.TypeTransformerRegistry;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.time.Duration;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

Expand All @@ -57,9 +65,43 @@
class FederatedCatalogTest {

public static final Duration TIMEOUT = ofSeconds(60);
private static final Endpoint CONNECTOR_MANAGEMENT = new Endpoint("/management", "8081");
private static final Endpoint CONNECTOR_PROTOCOL = new Endpoint("/api/v1/dsp", "8082");
private static final Endpoint CONNECTOR_DEFAULT = new Endpoint("/api/v1/", "8080");

private static final Endpoint CATALOG_MANAGEMENT = new Endpoint("/management", "8091");
private static final Endpoint CATALOG_PROTOCOL = new Endpoint("/api/v1/dsp", "8092");
private static final Endpoint CATALOG_DEFAULT = new Endpoint("/api/v1/", "8090");

@RegisterExtension
static EdcRuntimeExtension connector = new EdcRuntimeExtension(":system-tests:end2end-test:connector-runtime", "connector",
configOf("edc.connector.name", "connector1",
"edc.web.rest.cors.enabled", "true",
"web.http.port", CONNECTOR_DEFAULT.port(),
"web.http.path", CONNECTOR_DEFAULT.path(),
"web.http.protocol.port", CONNECTOR_PROTOCOL.port(),
"web.http.protocol.path", CONNECTOR_PROTOCOL.path(),
"web.http.management.port", CONNECTOR_MANAGEMENT.port(),
"web.http.management.path", CONNECTOR_MANAGEMENT.path(),
"edc.web.rest.cors.headers", "origin,content-type,accept,authorization,x-api-key",
"edc.dsp.callback.address", "http://localhost:%s%s".formatted(CONNECTOR_PROTOCOL.port(), CONNECTOR_PROTOCOL.path())));

@RegisterExtension
static EdcRuntimeExtension catalog = new EdcRuntimeExtension(":system-tests:end2end-test:catalog-runtime", "catalog",
configOf("edc.catalog.cache.execution.delay.seconds", "0",
"edc.catalog.cache.execution.period.seconds", "2",
"edc.catalog.cache.partition.num.crawlers", "5",
"edc.web.rest.cors.enabled", "true",
"web.http.port", CATALOG_DEFAULT.port(),
"web.http.path", CATALOG_DEFAULT.path(),
"web.http.protocol.port", CATALOG_PROTOCOL.port(),
"web.http.protocol.path", CATALOG_PROTOCOL.path(),
"web.http.management.port", CATALOG_MANAGEMENT.port(),
"web.http.management.path", CATALOG_MANAGEMENT.path(),
"edc.web.rest.cors.headers", "origin,content-type,accept,authorization,x-api-key"));
private final TypeTransformerRegistry typeTransformerRegistry = new TypeTransformerRegistryImpl();
private final ObjectMapper mapper = JacksonJsonLd.createObjectMapper();
private final ManagementApiClient apiClient = new ManagementApiClient(mapper, new TitaniumJsonLd(mock(Monitor.class)), typeTransformerRegistry);
private final ManagementApiClient apiClient = new ManagementApiClient(CATALOG_MANAGEMENT, CONNECTOR_MANAGEMENT, mapper, new TitaniumJsonLd(mock(Monitor.class)), typeTransformerRegistry);

@BeforeEach
void setUp() {
Expand All @@ -77,6 +119,10 @@ void setUp() {
jsonObjectToOdrlTransformers().forEach(typeTransformerRegistry::register);
typeTransformerRegistry.register(new JsonObjectToDistributionTransformer());
typeTransformerRegistry.register(new JsonValueToGenericTypeTransformer(mapper));

var directory = new InMemoryNodeDirectory();
directory.insert(new TargetNode("connector", "http://localhost:%s%s".formatted(CONNECTOR_PROTOCOL.port(), CONNECTOR_PROTOCOL.path()), List.of(CatalogConstants.DATASPACE_PROTOCOL)));
catalog.registerServiceMock(TargetNodeDirectory.class, directory);
}

@Test
Expand Down Expand Up @@ -121,6 +167,18 @@ void crawl_whenOfferAvailable_shouldContainOffer(TestInfo testInfo) {
});
}

private static Map<String, String> configOf(String... keyValuePairs) {
if (keyValuePairs.length % 2 != 0) {
throw new IllegalArgumentException("Must have an even number of key value pairs, was " + keyValuePairs.length);
}

var map = new HashMap<String, String>();
for (int i = 0; i < keyValuePairs.length - 1; i += 2) {
map.put(keyValuePairs[i], keyValuePairs[i + 1]);
}
return map;
}

private String getError(Result<String> r) {
return ofNullable(r.getFailureDetail()).orElse("No error");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,23 @@
import static java.lang.String.format;

class ManagementApiClient {
private static final String MANAGEMENT_BASE_URL = "http://localhost:9192/management";
private static final String CATALOG_BASE_URL = "http://localhost:8181/api";
private static final TypeReference<List<Map<String, Object>>> LIST_TYPE_REFERENCE = new TypeReference<>() {
};
private static final MediaType JSON = MediaType.parse("application/json");
private final String MANAGEMENT_BASE_URL;
private final String CATALOG_BASE_URL;
private final ObjectMapper mapper;
private final JsonLd jsonLdService;
private final TypeTransformerRegistry typeTransformerRegistry;

ManagementApiClient(ObjectMapper mapper, JsonLd jsonLdService, TypeTransformerRegistry typeTransformerRegistry) {
ManagementApiClient(Endpoint catalogManagement, Endpoint connectorManagement,
ObjectMapper mapper, JsonLd jsonLdService,
TypeTransformerRegistry typeTransformerRegistry) {
this.mapper = mapper;
this.jsonLdService = jsonLdService;
this.typeTransformerRegistry = typeTransformerRegistry;
MANAGEMENT_BASE_URL = "http://localhost:%s%s".formatted(connectorManagement.port(), connectorManagement.path());
CATALOG_BASE_URL = "http://localhost:%s%s".formatted(catalogManagement.port(), catalogManagement.path());
}

Result<String> postAsset(JsonObject entry) {
Expand Down Expand Up @@ -84,7 +88,7 @@ List<Catalog> getContractOffers() {
}
}

private static String catalog(String path) {
private String catalog(String path) {
return CATALOG_BASE_URL + path;
}

Expand Down
9 changes: 0 additions & 9 deletions system-tests/end2end-test/resources/nodes-dc.json

This file was deleted.

0 comments on commit caa15fe

Please sign in to comment.