Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: removes MockWebServer #1265

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
maven/mavencentral/com.apicatalog/carbon-did/0.3.0, Apache-2.0, approved, clearlydefined

Check warning on line 1 in DEPENDENCIES

View workflow job for this annotation

GitHub Actions / verify / verify-dependencies / Dash-Verify-Licenses

Restricted Dependencies found

Some dependencies are marked 'restricted' - please review them
maven/mavencentral/com.apicatalog/copper-multibase/0.5.0, Apache-2.0, approved, #14501
maven/mavencentral/com.apicatalog/copper-multicodec/0.1.1, Apache-2.0, approved, #14500
maven/mavencentral/com.apicatalog/iron-ed25519-cryptosuite-2020/0.14.0, Apache-2.0, approved, #14503
Expand Down Expand Up @@ -114,17 +114,11 @@
maven/mavencentral/com.nimbusds/oauth2-oidc-sdk/11.9.1, Apache-2.0, approved, #12667
maven/mavencentral/com.puppycrawl.tools/checkstyle/10.15.0, LGPL-2.1-or-later, restricted, clearlydefined
maven/mavencentral/com.samskivert/jmustache/1.15, BSD-2-Clause, approved, clearlydefined
maven/mavencentral/com.squareup.okhttp3/mockwebserver/5.0.0-alpha.12, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.squareup.okhttp3/mockwebserver3/5.0.0-alpha.12, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.squareup.okhttp3/okhttp-dnsoverhttps/4.12.0, Apache-2.0, approved, #11159
maven/mavencentral/com.squareup.okhttp3/okhttp-jvm/5.0.0-alpha.12, Apache-2.0, approved, #9263
maven/mavencentral/com.squareup.okhttp3/okhttp/4.12.0, Apache-2.0, approved, #11156
maven/mavencentral/com.squareup.okhttp3/okhttp/4.9.3, Apache-2.0 AND MPL-2.0, approved, #3225
maven/mavencentral/com.squareup.okhttp3/okhttp/5.0.0-alpha.12, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.squareup.okio/okio-jvm/3.6.0, Apache-2.0, approved, #11158
maven/mavencentral/com.squareup.okio/okio-jvm/3.7.0, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.squareup.okio/okio/3.6.0, Apache-2.0, approved, #11155
maven/mavencentral/com.squareup.okio/okio/3.7.0, Apache-2.0, approved, clearlydefined
maven/mavencentral/com.sun.activation/jakarta.activation/2.0.0, EPL-2.0 OR BSD-3-Clause OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.jaf
maven/mavencentral/com.sun.activation/jakarta.activation/2.0.1, EPL-2.0 OR BSD-3-Clause OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.jaf
maven/mavencentral/com.sun.mail/mailapi/1.6.2, CDDL-1.1 OR GPL-2.0-only WITH Classpath-exception-2.0, approved, clearlydefined
Expand Down Expand Up @@ -587,15 +581,10 @@
maven/mavencentral/org.javassist/javassist/3.29.2-GA, Apache-2.0 AND LGPL-2.1-or-later AND MPL-1.1, approved, #6023
maven/mavencentral/org.javassist/javassist/3.30.2-GA, Apache-2.0 AND LGPL-2.1-or-later AND MPL-1.1, approved, #12108
maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-common/1.9.10, Apache-2.0, approved, #14186
maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.8.0, Apache-2.0, approved, #8807
maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.8.21, Apache-2.0, approved, #8807
maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.9.10, Apache-2.0, approved, #14193
maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.8.0, Apache-2.0, approved, #8919
maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.8.21, Apache-2.0, approved, #8919
maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.9.10, Apache-2.0, approved, #14191
maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib/1.8.21, Apache-2.0, approved, #8865
maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib/1.9.10, Apache-2.0, approved, #11827
maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib/1.9.21, Apache-2.0, approved, #11827
maven/mavencentral/org.jetbrains/annotations/13.0, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.jetbrains/annotations/17.0.0, Apache-2.0, approved, clearlydefined
maven/mavencentral/org.jetbrains/annotations/24.1.0, Apache-2.0, approved, clearlydefined
Expand Down
1 change: 0 additions & 1 deletion edc-tests/e2e-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ plugins {
}

dependencies {
testImplementation(libs.okhttp.mockwebserver)
testImplementation(libs.restAssured)
testImplementation(libs.nimbus.jwt)
testImplementation(libs.awaitility)
Expand Down
1 change: 0 additions & 1 deletion edc-tests/edc-controlplane/catalog-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ dependencies {
testImplementation(libs.edc.junit)
testImplementation(libs.restAssured)
testImplementation(libs.awaitility)
testImplementation(libs.okhttp.mockwebserver)
}

// do not publish
Expand Down
1 change: 0 additions & 1 deletion edc-tests/edc-controlplane/edr-api-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ dependencies {
testImplementation(libs.edc.junit)
testImplementation(libs.restAssured)
testImplementation(libs.awaitility)
testImplementation(libs.okhttp.mockwebserver)
}

// do not publish
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
package org.eclipse.tractusx.edc.tests.edrv2;

import jakarta.json.Json;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import org.eclipse.edc.connector.controlplane.contract.spi.event.contractnegotiation.ContractNegotiationAgreed;
import org.eclipse.edc.connector.controlplane.contract.spi.event.contractnegotiation.ContractNegotiationFinalized;
import org.eclipse.edc.connector.controlplane.contract.spi.event.contractnegotiation.ContractNegotiationInitiated;
Expand All @@ -36,6 +34,7 @@
import org.eclipse.edc.policy.model.Operator;
import org.eclipse.tractusx.edc.tests.helpers.EdrNegotiationHelperFunctions;
import org.eclipse.tractusx.edc.tests.helpers.PolicyHelperFunctions;
import org.eclipse.tractusx.edc.tests.helpers.ReceivedEvent;
import org.eclipse.tractusx.edc.tests.participant.TransferParticipant;
import org.eclipse.tractusx.edc.tests.runtimes.ParticipantRuntime;
import org.eclipse.tractusx.edc.tests.runtimes.PgParticipantRuntime;
Expand All @@ -45,25 +44,29 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockserver.integration.ClientAndServer;
import org.mockserver.model.HttpResponse;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.eclipse.edc.util.io.Ports.getFreePort;
import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_BPN;
import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PLATO_NAME;
import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_BPN;
import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.SOKRATES_NAME;
import static org.eclipse.tractusx.edc.tests.helpers.EdrNegotiationHelperFunctions.createEvent;
import static org.eclipse.tractusx.edc.tests.helpers.Functions.waitForEvent;
import static org.eclipse.tractusx.edc.tests.helpers.Functions.readEvent;
import static org.eclipse.tractusx.edc.tests.participant.TractusxParticipantBase.ASYNC_POLL_INTERVAL;
import static org.eclipse.tractusx.edc.tests.participant.TractusxParticipantBase.ASYNC_TIMEOUT;
import static org.eclipse.tractusx.edc.tests.runtimes.Runtimes.memoryRuntime;
import static org.eclipse.tractusx.edc.tests.runtimes.Runtimes.pgRuntime;
import static org.mockserver.model.HttpRequest.request;

public class NegotiateEdrTest {

Expand All @@ -80,11 +83,11 @@ public class NegotiateEdrTest {

abstract static class Tests {

MockWebServer server;
ClientAndServer server;

@BeforeEach
void setup() {
server = new MockWebServer();
server = ClientAndServer.startClientAndServer("localhost", getFreePort());
}

@Test
Expand All @@ -102,15 +105,15 @@ void negotiateEdr_shouldInvokeCallbacks() throws IOException {
createEvent(TransferProcessRequested.class),
createEvent(TransferProcessStarted.class));

var url = "http://%s:%d%s".formatted("localhost", server.getPort(), "/mock/api");

var assetId = "api-asset-1";
var url = server.url("/mock/api");
server.start();

var authCodeHeaderName = "test-authkey";
var authCode = "test-authcode";
Map<String, Object> dataAddress = Map.of(
"name", "transfer-test",
"baseUrl", url.toString(),
"baseUrl", url,
"type", "HttpData",
"contentType", "application/json",
"authKey", authCodeHeaderName,
Expand All @@ -125,28 +128,33 @@ void negotiateEdr_shouldInvokeCallbacks() throws IOException {
PLATO.createContractDefinition(assetId, "def-1", accessPolicy, contractPolicy);


expectedEvents.forEach(event -> server.enqueue(new MockResponse()));
var events = new ArrayList<ReceivedEvent>();
server.when(request().withPath("/mock/api"))
.respond(request -> {
var event = readEvent(request);
events.add(event);
return HttpResponse.response().withStatusCode(200);
});


var callbacks = Json.createArrayBuilder()
.add(EdrNegotiationHelperFunctions.createCallback(url.toString(), true, Set.of("contract.negotiation", "transfer.process")))
.add(EdrNegotiationHelperFunctions.createCallback(url, true, Set.of("contract.negotiation", "transfer.process")))
.build();

var contractNegotiationId = SOKRATES.edrs().negotiateEdr(PLATO, assetId, callbacks);

var events = expectedEvents.stream()
.map(receivedEvent -> waitForEvent(server))
.collect(Collectors.toList());


await().pollInterval(ASYNC_POLL_INTERVAL)
.atMost(ASYNC_TIMEOUT)
.untilAsserted(() -> {
assertThat(expectedEvents).usingRecursiveFieldByFieldElementComparator().containsAll(events);
});
await().pollInterval(ASYNC_POLL_INTERVAL)
.atMost(ASYNC_TIMEOUT)
.untilAsserted(() -> {
var edrCaches = SOKRATES.edrs().getEdrEntriesByAssetId(assetId);
assertThat(edrCaches).hasSize(1);
});

assertThat(expectedEvents).usingRecursiveFieldByFieldElementComparator().containsAll(events);

var edrCaches = SOKRATES.edrs().getEdrEntriesByAssetId(assetId);

assertThat(edrCaches).hasSize(1);
Expand Down Expand Up @@ -174,7 +182,7 @@ void negotiateEdr_shouldInvokeCallbacks() throws IOException {

@AfterEach
void teardown() throws IOException {
server.shutdown();
server.stop();
}
}

Expand Down
1 change: 0 additions & 1 deletion edc-tests/edc-controlplane/fixtures/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ dependencies {
testFixturesImplementation(libs.edc.core.token)
testFixturesImplementation(libs.edc.spi.identity.did)
testFixturesImplementation(testFixtures(libs.edc.sql.core))
testFixturesImplementation(libs.okhttp.mockwebserver)
testFixturesImplementation(libs.testcontainers.postgres)

testCompileOnly(project(":edc-tests:runtime:runtime-memory"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,24 @@
package org.eclipse.tractusx.edc.tests.helpers;

import com.fasterxml.jackson.databind.ObjectMapper;
import okhttp3.mockwebserver.MockWebServer;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.mockserver.model.HttpRequest;

import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.spec.ECGenParameterSpec;
import java.util.concurrent.TimeUnit;

public class Functions {

private static final ObjectMapper MAPPER = new ObjectMapper();

public static ReceivedEvent waitForEvent(MockWebServer server) {
public static ReceivedEvent readEvent(HttpRequest request) {
try {
var request = server.takeRequest(60, TimeUnit.SECONDS);
if (request != null) {
return MAPPER.readValue(request.getBody().inputStream(), ReceivedEvent.class);
} else {
throw new RuntimeException("Timeout exceeded waiting for events");
}
} catch (Exception e) {
return MAPPER.readValue(request.getBody().getRawBytes(), ReceivedEvent.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ void transferData_privateBackend() {
.withHeader("Edc-Contract-Agreement-Id")
.withHeader("Edc-Bpn", sokrates().getBpn())
.withMethod("GET"), VerificationTimes.exactly(1));

}

}

@Test
void transferData_privateBackend_withConsumerDataPlane() {
Expand Down Expand Up @@ -158,8 +157,7 @@ void transferData_privateBackend_withConsumerDataPlane() {
.withHeader("Edc-Bpn", sokrates().getBpn())
.withMethod("GET"), VerificationTimes.exactly(1));
}



@AfterEach
void teardown() {
server.stop();
Expand Down
1 change: 0 additions & 1 deletion edc-tests/edc-controlplane/iatp-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ dependencies {
testImplementation(libs.netty.mockserver)
testImplementation(libs.restAssured)
testImplementation(libs.awaitility)
testImplementation(libs.okhttp.mockwebserver)
testImplementation(libs.bouncyCastle.bcpkixJdk18on)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@

package org.eclipse.tractusx.edc.tests.transfer;

import okhttp3.mockwebserver.MockWebServer;
import org.eclipse.edc.iam.did.spi.document.DidDocument;
import org.eclipse.edc.iam.identitytrust.sts.embedded.EmbeddedSecureTokenService;
import org.eclipse.edc.json.JacksonTypeManager;
import org.eclipse.edc.junit.annotations.EndToEndTest;
import org.eclipse.edc.spi.types.TypeManager;
import org.eclipse.edc.token.JwtGenerationService;
import org.eclipse.edc.token.spi.TokenGenerationService;
import org.eclipse.tractusx.edc.tests.transfer.iatp.dispatchers.DimDispatcher;
import org.eclipse.tractusx.edc.tests.transfer.iatp.dispatchers.KeycloakDispatcher;
import org.eclipse.tractusx.edc.tests.transfer.iatp.harness.IatpParticipant;
import org.eclipse.tractusx.edc.tests.transfer.iatp.runtime.IatpParticipantRuntime;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockserver.integration.ClientAndServer;
import org.mockserver.model.HttpResponse;

import java.io.IOException;
import java.security.PrivateKey;
Expand All @@ -42,35 +44,35 @@

import static org.eclipse.tractusx.edc.tests.transfer.iatp.harness.IatpHelperFunctions.configureParticipant;
import static org.eclipse.tractusx.edc.tests.transfer.iatp.runtime.Runtimes.dimRuntime;
import static org.mockserver.model.HttpRequest.request;

@EndToEndTest
public class DimHttpConsumerPullTest extends AbstractIatpConsumerPullTest {


@RegisterExtension
protected static final IatpParticipantRuntime SOKRATES_RUNTIME = dimRuntime(SOKRATES.getName(), SOKRATES.iatpConfiguration(PLATO), SOKRATES.getKeyPair());

@RegisterExtension
protected static final IatpParticipantRuntime PLATO_RUNTIME = dimRuntime(PLATO.getName(), PLATO.iatpConfiguration(SOKRATES), PLATO.getKeyPair());
private static MockWebServer oauthServer;
private static MockWebServer dimDispatcher;
private static final TypeManager MAPPER = new JacksonTypeManager();
private static ClientAndServer oauthServer;
private static ClientAndServer dimServer;

@BeforeAll
static void prepare() throws IOException {
static void prepare() {

var tokenGeneration = new JwtGenerationService();

var generatorServices = Map.of(
SOKRATES.getDid(), tokenServiceFor(tokenGeneration, SOKRATES),
PLATO.getDid(), tokenServiceFor(tokenGeneration, PLATO));

oauthServer = new MockWebServer();
oauthServer.start(STS.stsUri().getPort());
oauthServer.setDispatcher(new KeycloakDispatcher(STS.stsUri().getPath() + "/token"));
oauthServer = ClientAndServer.startClientAndServer(STS.stsUri().getPort());

oauthServer.when(request().withMethod("POST").withPath(STS.stsUri().getPath() + "/token"))
.respond(HttpResponse.response(MAPPER.writeValueAsString(Map.of("access_token", "token"))));

dimDispatcher = new MockWebServer();
dimDispatcher.start(DIM_URI.getPort());
dimDispatcher.setDispatcher(new DimDispatcher(generatorServices));
dimServer = ClientAndServer.startClientAndServer(DIM_URI.getPort());
dimServer.when(request().withMethod("POST")).respond(new DimDispatcher(generatorServices));

// create the DIDs cache
var dids = new HashMap<String, DidDocument>();
Expand All @@ -85,8 +87,8 @@ static void prepare() throws IOException {

@AfterAll
static void unwind() throws IOException {
oauthServer.shutdown();
dimDispatcher.shutdown();
oauthServer.stop();
dimServer.stop();
}

private static EmbeddedSecureTokenService tokenServiceFor(TokenGenerationService tokenGenerationService, IatpParticipant iatpDimParticipant) {
Expand Down
Loading
Loading