Skip to content

Commit

Permalink
feat: split Junit module between base utils and the integration test …
Browse files Browse the repository at this point in the history
…runtime (#4042)

Split Junit module between base utils and the integration test runtime
  • Loading branch information
jimmarino committed Mar 25, 2024
1 parent fd81ffc commit 73317e3
Show file tree
Hide file tree
Showing 54 changed files with 166 additions and 76 deletions.
3 changes: 2 additions & 1 deletion core/common/junit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ plugins {
}

dependencies {
api(project(":tests:junit-base"))

api(project(":spi:common:core-spi"))
api(project(":core:common:boot"))
api(project(":core:common:util"))
Expand All @@ -36,7 +38,6 @@ dependencies {
implementation(libs.testcontainers.junit)
testImplementation(project(":core:common:connector-core"))


testImplementation(project(":core:common:lib:boot-lib"))
}

Expand Down
2 changes: 2 additions & 0 deletions core/common/lib/http-lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ dependencies {

testImplementation(project(":core:common:util"))

testFixturesImplementation(libs.mockito.core)

testImplementation(libs.mockserver.netty)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
*
*/

package org.eclipse.http.client.testfixtures;

import dev.failsafe.RetryPolicy;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import org.eclipse.edc.spi.http.EdcHttpClient;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.http.client.EdcHttpClientImpl;
import org.mockito.Mockito;

import java.util.concurrent.TimeUnit;

/**
* HTTP-related test utilities.
*/
public class HttpTestUtils {

/**
* Create an {@link OkHttpClient} suitable for using in unit tests. The client configured with long timeouts
* suitable for high-contention scenarios in CI.
*
* @return an {@link OkHttpClient.Builder}.
*/
public static OkHttpClient testOkHttpClient(Interceptor... interceptors) {
var builder = new OkHttpClient.Builder()
.connectTimeout(1, TimeUnit.MINUTES)
.writeTimeout(1, TimeUnit.MINUTES)
.readTimeout(1, TimeUnit.MINUTES);

for (Interceptor interceptor : interceptors) {
builder.addInterceptor(interceptor);
}

return builder.build();
}

/**
* Create an {@link org.eclipse.edc.spi.http.EdcHttpClient} suitable for using in unit tests. The client configured with long timeouts
* suitable for high-contention scenarios in CI.
*
* @return an {@link OkHttpClient.Builder}.
*/
public static EdcHttpClient testHttpClient(Interceptor... interceptors) {
return new EdcHttpClientImpl(testOkHttpClient(interceptors), RetryPolicy.ofDefaults(), Mockito.mock(Monitor.class));
}

private HttpTestUtils() {
}
}
2 changes: 1 addition & 1 deletion core/common/lib/keys-lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies {
implementation(libs.nimbus.jwt)
implementation(libs.tink)

testImplementation(project(":core:common:junit"));
testImplementation(project(":tests:junit-base"));

}

Expand Down
2 changes: 1 addition & 1 deletion core/common/policy-engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies {
api(project(":spi:common:policy-model"))
implementation(project(":core:common:policy-evaluator"))

testImplementation(project(":core:common:junit"))
testImplementation(project(":tests:junit-base"));
}


2 changes: 1 addition & 1 deletion core/common/transform-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ dependencies {

api(libs.jakartaJson)

testImplementation(project(":core:common:junit"))
testImplementation(project(":tests:junit-base"));
testImplementation(project(":extensions:common:json-ld"))
}
3 changes: 2 additions & 1 deletion core/common/validator-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ dependencies {

api(libs.jakartaJson)

testImplementation(project(":core:common:junit"))
testImplementation(project(":tests:junit-base"));

}
3 changes: 2 additions & 1 deletion core/control-plane/catalog-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ dependencies {
api(project(":spi:control-plane:contract-spi"))
api(project(":spi:control-plane:transfer-spi"))

testImplementation(project(":core:common:junit"))
testImplementation(project(":tests:junit-base"));

testImplementation(project(":core:common:connector-core"))
testImplementation(project(":core:control-plane:control-plane-core"))
}
Expand Down
3 changes: 2 additions & 1 deletion core/data-plane/data-plane-util/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ dependencies {

implementation(libs.opentelemetry.instrumentation.annotations)

testImplementation(project(":core:common:junit"))
testImplementation(project(":tests:junit-base"));

}


3 changes: 2 additions & 1 deletion extensions/common/http/jetty-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ dependencies {
api(project(":spi:common:web-spi"))

testImplementation(libs.restAssured)
testImplementation(project(":core:common:junit"))
testImplementation(project(":tests:junit-base"));

}


Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ dependencies {

implementation(libs.bouncyCastle.bcpkixJdk18on)

testImplementation(project(":core:common:junit"))
testImplementation(project(":tests:junit-base"));

}


Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies {
api(project(":spi:common:http-spi"))
api(project(":core:common:util"))

testImplementation(project(":core:common:junit"))
testImplementation(testFixtures(project(":core:common:lib:http-lib")))
}


Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import static okhttp3.Protocol.HTTP_1_1;
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.junit.testfixtures.TestUtils.testHttpClient;
import static org.eclipse.http.client.testfixtures.HttpTestUtils.testHttpClient;
import static org.mockito.Mockito.mock;

class WebDidResolverTest {
Expand Down
4 changes: 2 additions & 2 deletions extensions/common/iam/oauth2/oauth2-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ dependencies {
api(project(":spi:common:http-spi"))
api(project(":spi:common:oauth2-spi"))

testImplementation(project(":core:common:junit"))

testImplementation(project(":core:common:util"))
testImplementation(testFixtures(project(":core:common:lib:http-lib")))
testImplementation(libs.mockserver.netty)
testImplementation(libs.mockserver.client)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import java.util.stream.Collectors;

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.junit.testfixtures.TestUtils.testHttpClient;
import static org.eclipse.edc.util.io.Ports.getFreePort;
import static org.eclipse.http.client.testfixtures.HttpTestUtils.testHttpClient;
import static org.mockserver.integration.ClientAndServer.startClientAndServer;
import static org.mockserver.model.MediaType.APPLICATION_JSON;

Expand Down
1 change: 1 addition & 0 deletions extensions/common/iam/oauth2/oauth2-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies {
implementation(libs.nimbus.jwt)

testImplementation(project(":core:common:junit"))
testImplementation(testFixtures(project(":core:common:lib:http-lib")))

testImplementation(libs.mockserver.netty)
testImplementation(libs.mockserver.client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import static java.util.Collections.emptyMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.eclipse.edc.junit.testfixtures.TestUtils.testHttpClient;
import static org.eclipse.http.client.testfixtures.HttpTestUtils.testHttpClient;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down
3 changes: 2 additions & 1 deletion extensions/common/json-ld/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ dependencies {
api(project(":spi:common:json-ld-spi"))
api(project(":spi:common:transform-spi"))

testImplementation(project(":core:common:junit"))
testImplementation(project(":core:common:junit"));

testImplementation(libs.mockserver.netty)
testImplementation(libs.mockserver.client)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ dependencies {
api(project(":spi:common:transaction-spi"))
implementation(project(":spi:common:transaction-datasource-spi"))

testImplementation(project(":core:common:junit"))
testImplementation(project(":tests:junit-base"));

testImplementation(testFixtures(project(":extensions:common:sql:sql-core")))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {
api(project(":spi:common:validator-spi"))
api(project(":spi:common:data-address:data-address-http-data-spi"))

testImplementation(project(":core:common:junit"))
testImplementation(project(":tests:junit-base"));

}

Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ dependencies {
api(project(":spi:common:validator-spi"))
api(project(":spi:common:data-address:data-address-kafka-spi"))

testImplementation(project(":core:common:junit"))
testImplementation(project(":tests:junit-base"));

}
1 change: 1 addition & 0 deletions extensions/common/vault/vault-hashicorp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {
implementation(project(":core:common:util"))

testImplementation(project(":core:common:connector-core"))
testImplementation(testFixtures(project(":core:common:lib:http-lib")))
testImplementation(project(":core:common:junit"))
testImplementation(libs.jakartaJson)
testImplementation(libs.testcontainers.junit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.json.Json;
import org.eclipse.edc.junit.annotations.ComponentTest;
import org.eclipse.edc.junit.testfixtures.TestUtils;
import org.eclipse.edc.spi.monitor.ConsoleMonitor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -33,6 +32,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat;
import static org.eclipse.http.client.testfixtures.HttpTestUtils.testHttpClient;
import static org.testcontainers.shaded.org.awaitility.Awaitility.await;

@ComponentTest
Expand All @@ -58,7 +58,7 @@ class HashicorpVaultClientIntegrationTest {
void beforeEach() throws IOException, InterruptedException {
assertThat(CREATION_TTL).isGreaterThan(TTL);
client = new HashicorpVaultClient(
TestUtils.testHttpClient(),
testHttpClient(),
OBJECT_MAPPER,
MONITOR,
getSettings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ dependencies {
testImplementation(project(":extensions:common:auth:auth-tokenbased"))
testImplementation(libs.awaitility)

testImplementation(testFixtures(project(":core:common:lib:http-lib")))

}


Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import static okhttp3.Protocol.HTTP_1_1;
import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat;
import static org.eclipse.edc.junit.testfixtures.TestUtils.testHttpClient;
import static org.eclipse.http.client.testfixtures.HttpTestUtils.testHttpClient;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {

testImplementation(libs.mockserver.netty)
testImplementation(libs.mockserver.client)
testImplementation(testFixtures(project(":core:common:lib:http-lib")))
testImplementation(project(":core:common:junit"))

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.connector.callback.dispatcher.http.GenericHttpRemoteDispatcherImpl.CALLBACK_EVENT_HTTP;
import static org.eclipse.edc.junit.testfixtures.TestUtils.testHttpClient;
import static org.eclipse.edc.util.io.Ports.getFreePort;
import static org.eclipse.http.client.testfixtures.HttpTestUtils.testHttpClient;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.atMostOnce;
import static org.mockito.Mockito.mock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies {
testImplementation(project(":core:data-plane-selector:data-plane-selector-core"))
testImplementation(project(":extensions:common:http"))
testImplementation(project(":extensions:common:json-ld"))
testImplementation(testFixtures(project(":core:common:lib:http-lib")))
testImplementation(testFixtures(project(":extensions:common:http:jersey-core")))
testImplementation(libs.restAssured)
testImplementation(libs.awaitility)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.connector.provision.http.HttpProvisionerFixtures.createResponse;
import static org.eclipse.edc.connector.provision.http.config.ProvisionerConfiguration.ProvisionerType.PROVIDER;
import static org.eclipse.edc.junit.testfixtures.TestUtils.testHttpClient;
import static org.eclipse.http.client.testfixtures.HttpTestUtils.testHttpClient;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
import static org.eclipse.edc.connector.provision.http.HttpProvisionerFixtures.createResponse;
import static org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates.PROVISIONING_REQUESTED;
import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat;
import static org.eclipse.edc.junit.testfixtures.TestUtils.testHttpClient;
import static org.eclipse.edc.util.io.Ports.getFreePort;
import static org.eclipse.http.client.testfixtures.HttpTestUtils.testHttpClient;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isA;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ dependencies {
testImplementation(project(":spi:common:data-address:data-address-http-data-spi"))
testImplementation(libs.mockserver.netty)
testImplementation(libs.mockserver.client)
testImplementation(project(":core:common:junit"))

testImplementation(testFixtures(project(":core:common:lib:http-lib")))


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
import static org.eclipse.edc.connector.receiver.http.dynamic.HttpDynamicEndpointDataReferenceReceiver.HTTP_RECEIVER_ENDPOINT;
import static org.eclipse.edc.connector.receiver.http.dynamic.TestFunctions.createTransferProcess;
import static org.eclipse.edc.connector.receiver.http.dynamic.TestFunctions.transferProperties;
import static org.eclipse.edc.junit.testfixtures.TestUtils.testOkHttpClient;
import static org.eclipse.edc.util.io.Ports.getFreePort;
import static org.eclipse.http.client.testfixtures.HttpTestUtils.testOkHttpClient;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.atMostOnce;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ dependencies {

testImplementation(libs.mockserver.netty)
testImplementation(libs.mockserver.client)
testImplementation(project(":core:common:junit"))

testImplementation(testFixtures(project(":core:common:lib:http-lib")))

}


Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import java.util.concurrent.ExecutionException;

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.junit.testfixtures.TestUtils.testHttpClient;
import static org.eclipse.edc.util.io.Ports.getFreePort;
import static org.eclipse.http.client.testfixtures.HttpTestUtils.testHttpClient;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockserver.integration.ClientAndServer.startClientAndServer;
Expand Down

0 comments on commit 73317e3

Please sign in to comment.