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

Spike/626/36 integration testing #3

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f097532
Add docker file for sample 04
cpeeyush Jan 27, 2022
22263ff
Update Dockerfile
cpeeyush Jan 27, 2022
a4c387d
Add integration test project for samples
cpeeyush Jan 28, 2022
70aac69
Add first integration test for sample 04
cpeeyush Jan 28, 2022
24a8c2b
Update FileTransferSystemTest
cpeeyush Jan 28, 2022
c9f54b8
Update sample04 system test
cpeeyush Jan 29, 2022
89b1d5d
Update sample 04 test with initiate a file transfer
cpeeyush Jan 31, 2022
367c51b
Updated Sample04 file transfer test
cpeeyush Jan 31, 2022
e64d92c
Remove unused docker files
cpeeyush Feb 1, 2022
04abb7e
Use Enum for Test
cpeeyush Feb 2, 2022
3c24ace
Move integration test module to sample04
cpeeyush Feb 2, 2022
2096831
Update sample 4 integration test with error message and java doc
cpeeyush Feb 2, 2022
b4042d2
Added endpoint to verify transfer complete
algattik Feb 2, 2022
da4213f
Merge branch 'feature/4-integration-test-sample04-tmp' of github.com:…
algattik Feb 2, 2022
767d2e3
Update sample 04 integration tests
cpeeyush Feb 2, 2022
3e2da26
Update Sample04 Test
cpeeyush Feb 2, 2022
875ceef
Update sample04 test to use test containers
cpeeyush Feb 2, 2022
7f47112
Update sample04 test
cpeeyush Feb 2, 2022
025c780
Update sample04 test to use test containers for consumer container
cpeeyush Feb 3, 2022
f19dac3
Show STDOUT
algattik Feb 3, 2022
3a8ea24
Create SeparateClassloaderSystemTest.java
algattik Feb 3, 2022
e35fafe
Update SeparateClassloaderSystemTest.java
algattik Feb 3, 2022
65001f2
Update SeparateClassloaderSystemTest.java
algattik Feb 3, 2022
0008b9d
Merge branch 'feature/4-integration-test-sample04-tmp' of github.com:…
algattik Feb 3, 2022
9d5d5cf
Isolate jar extension
algattik Feb 3, 2022
d2f2759
Make JAR file configurable
algattik Feb 3, 2022
6d78b29
Alternative classpath based implementation
algattik Feb 3, 2022
68b0556
Update GradleModuleRuntimeExtension.java
algattik Feb 3, 2022
bf48a69
Add docker-compose approach for sample04 test
cpeeyush Feb 3, 2022
c920ed9
Merge branch 'main' into feature/4-integration-test-sample04-tmp
algattik Feb 3, 2022
eaeea42
Update GradleModuleRuntimeExtension.java
algattik Feb 3, 2022
0219dbf
Create 2022-02-03-integration-testing.md
algattik Feb 3, 2022
67ee693
ADR
algattik Feb 3, 2022
8c6e42c
linting
algattik Feb 4, 2022
9f7ef01
Update Sample04 Integration Test ADR
cpeeyush Feb 4, 2022
2665b61
Remove Testcontainers based test
cpeeyush Feb 4, 2022
409cfd8
Delete old Dockerfile
cpeeyush Feb 4, 2022
48f4ca8
Update Integration Testing ADR
cpeeyush Feb 4, 2022
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
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ allprojects {
}
}


tasks.register("printClasspath") {
doLast {
println("${sourceSets["main"].runtimeClasspath.asPath}");
}
}

pluginManager.withPlugin("java-library") {
group = groupId
version = edcVersion
Expand Down
301 changes: 301 additions & 0 deletions docs/developer/decision-records/2022-02-03-integration-testing.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ public boolean canHandle(DataRequest dataRequest) {
var destinationType = dataRequest.getDestinationType();
monitor.info(format("Copying data from %s to %s", source.getType(), destinationType));

var destSecretName = dataRequest.getDataDestination().getKeyName();
if (destSecretName == null) {
monitor.severe(format("No credentials found for %s, will not copy!", destinationType));
return DataFlowInitiateResult.failure(ERROR_RETRY, "Did not find credentials for data destination.");
}

var secret = vault.resolveSecret(destSecretName);

// first look for a streamer
DataStreamPublisher streamer = dataOperatorRegistry.getStreamPublisher(dataRequest);
if (streamer != null) {
Expand All @@ -71,6 +63,13 @@ public boolean canHandle(DataRequest dataRequest) {
return DataFlowInitiateResult.failure(ERROR_RETRY, "Failed to copy data from source to destination: " + copyResult.getFailure().getMessages());
}
} else {
var destSecretName = dataRequest.getDataDestination().getKeyName();
if (destSecretName == null) {
monitor.severe(format("No credentials found for %s, will not copy!", destinationType));
return DataFlowInitiateResult.failure(ERROR_RETRY, "Did not find credentials for data destination.");
}

var secret = vault.resolveSecret(destSecretName);
// if no copier found for this source/destination pair, then use inline read and write
var reader = dataOperatorRegistry.getReader(source.getType());
var writer = dataOperatorRegistry.getWriter(destinationType);
Expand Down
27 changes: 27 additions & 0 deletions samples/04.0-file-transfer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM openjdk:11-jre-slim AS runtime

WORKDIR /build

COPY ./consumer/build/libs/consumer.jar /build/consumer/
RUN echo "web.http.port=9191\n" \
"edc.api.control.auth.apikey.value=password\n" \
"ids.webhook.address=http://sample04-connector-consumer:9191\n" > /build/consumer/config.properties

COPY ./provider/build/libs/provider.jar /build/provider/
RUN echo "edc.samples.04.asset.path=/tmp/provider/test-document.txt\n" \
"ids.webhook.address=http://sample04-connector-provider:8181\n" > /build/provider/config.properties


FROM runtime AS sample04-connector-provider

WORKDIR /app
COPY --from=runtime /build/provider/* /app/

ENTRYPOINT ["java", "-Dedc.fs.config=config.properties", "-jar", "provider.jar"]

FROM runtime AS sample04-connector-consumer

WORKDIR /app
COPY --from=runtime /build/consumer/* /app/

ENTRYPOINT ["java", "-Dedc.fs.config=config.properties", "-jar", "consumer.jar"]
4 changes: 2 additions & 2 deletions samples/04.0-file-transfer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ addition to just confirming or declining an offer.

In order to trigger the negotiation, we use the endpoint previously created in the `api` extension. We specify the
address of the provider connector as a query parameter and set our contract offer in the request body. The contract
offer is prepared in [contractoffer.json](contractoffer.json)
offer is prepared in [contractoffer.json](integration-tests/src/test/resources/contractoffer.json)
and can be used as is. In a real scenario, a potential consumer would first need to request a description of the
provider's offers in order to get the provider's contract offer.

```bash
curl -X POST -H "Content-Type: application/json" -d @samples/04.0-file-transfer/contractoffer.json "http://localhost:9191/api/negotiation?connectorAddress=http://localhost:8181/api/ids/multipart"
curl -X POST -H "Content-Type: application/json" -d @samples/04.0-file-transfer/integration-tests/src/test/resources/contractoffer.json "http://localhost:9191/api/negotiation?connectorAddress=http://localhost:8181/api/ids/multipart"
```

In the response we'll get a UUID that we can use to get the contract agreement negotiated between provider and consumer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.dataspaceconnector.spi.system.ServiceExtension;
import org.eclipse.dataspaceconnector.spi.system.ServiceExtensionContext;
import org.eclipse.dataspaceconnector.spi.transfer.TransferProcessManager;
import org.eclipse.dataspaceconnector.spi.transfer.store.TransferProcessStore;

public class ApiEndpointExtension implements ServiceExtension {

Expand All @@ -32,6 +33,7 @@ public void initialize(ServiceExtensionContext context) {
var webService = context.getService(WebService.class);
var processManager = context.getService(TransferProcessManager.class);
var negotiationManager = context.getService(ConsumerContractNegotiationManager.class);
webService.registerController(new ConsumerApiController(context.getMonitor(), processManager, negotiationManager));
var transferProcessStore = context.getService(TransferProcessStore.class);
webService.registerController(new ConsumerApiController(context.getMonitor(), processManager, negotiationManager, transferProcessStore));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@
import org.eclipse.dataspaceconnector.spi.contract.negotiation.response.NegotiationResult;
import org.eclipse.dataspaceconnector.spi.monitor.Monitor;
import org.eclipse.dataspaceconnector.spi.transfer.TransferProcessManager;
import org.eclipse.dataspaceconnector.spi.transfer.store.TransferProcessStore;
import org.eclipse.dataspaceconnector.spi.types.domain.DataAddress;
import org.eclipse.dataspaceconnector.spi.types.domain.contract.negotiation.ContractOfferRequest;
import org.eclipse.dataspaceconnector.spi.types.domain.contract.offer.ContractOffer;
import org.eclipse.dataspaceconnector.spi.types.domain.transfer.DataRequest;

import java.util.Objects;
import java.util.Optional;
import java.util.UUID;

import static jakarta.ws.rs.core.Response.Status.NOT_ACCEPTABLE;
import static java.lang.String.format;

@Consumes({MediaType.APPLICATION_JSON})
Expand All @@ -45,12 +48,14 @@ public class ConsumerApiController {
private final Monitor monitor;
private final TransferProcessManager processManager;
private final ConsumerContractNegotiationManager consumerNegotiationManager;
private final TransferProcessStore transferProcessStore;

public ConsumerApiController(Monitor monitor, TransferProcessManager processManager,
ConsumerContractNegotiationManager consumerNegotiationManager) {
ConsumerContractNegotiationManager consumerNegotiationManager, TransferProcessStore transferProcessStore) {
this.monitor = monitor;
this.processManager = processManager;
this.consumerNegotiationManager = consumerNegotiationManager;
this.transferProcessStore = transferProcessStore;
}

@GET
Expand Down Expand Up @@ -114,5 +119,16 @@ public Response initiateTransfer(@PathParam("filename") String filename, @QueryP

return result.failed() ? Response.status(400).build() : Response.ok(result.getContent()).build();
}

@GET
@Path("transfer/{id}")
public Response getTransferById(@PathParam("id") String id) {
return Optional.ofNullable(transferProcessStore.find(id))
.map(
v -> Response.ok(v).build()
).orElse(
Response.status(NOT_ACCEPTABLE).build()
);
}
}

24 changes: 24 additions & 0 deletions samples/04.0-file-transfer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3.8'

services:
sample04-connector-provider:
container_name: sample04-connector-provider
build:
context: .
target: sample04-connector-provider
ports:
- "8181:8181"
volumes:
- /tmp/provider:/tmp/provider
- /tmp/consumer:/tmp/consumer

sample04-connector-consumer:
container_name: sample04-connector-consumer
build:
context: .
target: sample04-connector-consumer
ports:
- "9191:9191"
volumes:
- /tmp/provider:/tmp/provider
- /tmp/consumer:/tmp/consumer
43 changes: 43 additions & 0 deletions samples/04.0-file-transfer/integration-tests/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2022 Microsoft Corporation
*
* 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:
* Microsoft Corporation - initial API and implementation
*
*/

plugins {
java
}

repositories {
mavenCentral()
}

dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.2")
testImplementation("io.rest-assured:rest-assured:4.5.0")
testImplementation("org.assertj:assertj-core:3.22.0")
testImplementation("org.awaitility:awaitility:4.1.1")
testImplementation("net.javacrumbs.json-unit:json-unit-assertj:2.28.0")

testImplementation(testFixtures(project(":common:util")))
testImplementation(testFixtures(project(":launchers:junit")))

implementation(project(":samples:04.0-file-transfer:provider"))
}

tasks.getByName<Test>("test") {
useJUnitPlatform()
testLogging {
showStandardStreams = true
events("skipped", "failed")
}
}
Loading