Skip to content

Commit

Permalink
fix: state of negotiation in E2E.
Browse files Browse the repository at this point in the history
  • Loading branch information
majadlymhmd committed Jan 19, 2024
1 parent e62036a commit a6fdfef
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 119 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,23 @@

package org.eclipse.edc.samples.policy;

import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import org.apache.http.HttpStatus;
import org.eclipse.edc.junit.annotations.EndToEndTest;
import org.eclipse.edc.junit.extensions.EdcRuntimeExtension;
import org.eclipse.edc.junit.testfixtures.TestUtils;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.io.File;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import static org.eclipse.edc.samples.policy.BasicPolicySampleTestCommon.getFileFromRelativePath;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.Matchers.equalTo;

@EndToEndTest
public class Policy01BasicFinalizedTest {
Expand All @@ -48,11 +57,49 @@ public class Policy01BasicFinalizedTest {
)
);

final BasicPolicySampleTestCommon testUtils = new BasicPolicySampleTestCommon();
String contractNegotiationId;

@Test
void runSampleSteps() {
testUtils.initiateContractNegotiation(CONTRACT_OFFER_FILE_PATH);
testUtils.lookUpContractAgreementFinalized();
initiateContractNegotiation(CONTRACT_OFFER_FILE_PATH);
lookUpContractAgreementFinalized();
}

@NotNull
public static File getFileFromRelativePath(String relativePath) {
return new File(TestUtils.findBuildRoot(), relativePath);
}

void initiateContractNegotiation(String contractOfferFilePath) {
Response response = RestAssured
.given()
.headers("X-Api-Key", "password")
.contentType(ContentType.JSON)
.body(new File(TestUtils.findBuildRoot(), contractOfferFilePath))
.post("http://localhost:9192/management/v2/contractnegotiations")
.then()
.statusCode(HttpStatus.SC_OK)
.extract()
.response();

String negotiationId = response.jsonPath().getString("@id");
if (negotiationId == null || negotiationId.isEmpty()) {
throw new IllegalStateException("Failed to get a valid contract negotiation ID from the response");
}

contractNegotiationId = negotiationId;
}

void lookUpContractAgreementFinalized() {
await().atMost(120, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).untilAsserted(() ->
RestAssured
.given()
.headers("X-Api-Key", "password")
.when()
.get("http://localhost:9192/management/v2/contractnegotiations/{id}", contractNegotiationId)
.then()
.statusCode(HttpStatus.SC_OK)
.body("state", equalTo("FINALIZED"))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,23 @@

package org.eclipse.edc.samples.policy;

import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import org.apache.http.HttpStatus;
import org.eclipse.edc.junit.annotations.EndToEndTest;
import org.eclipse.edc.junit.extensions.EdcRuntimeExtension;
import org.eclipse.edc.junit.testfixtures.TestUtils;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.io.File;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import static org.eclipse.edc.samples.policy.BasicPolicySampleTestCommon.getFileFromRelativePath;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.core.IsEqual.equalTo;

@EndToEndTest
public class Policy01BasicTerminatedTest {
Expand All @@ -48,11 +57,49 @@ public class Policy01BasicTerminatedTest {
)
);

final BasicPolicySampleTestCommon testUtils = new BasicPolicySampleTestCommon();
String contractNegotiationId;

@Test
void runSampleSteps() {
testUtils.initiateContractNegotiation(CONTRACT_OFFER_FILE_PATH);
testUtils.lookUpContractAgreementTerminated();
initiateContractNegotiation(CONTRACT_OFFER_FILE_PATH);
lookUpContractAgreementTerminated();
}

@NotNull
public static File getFileFromRelativePath(String relativePath) {
return new File(TestUtils.findBuildRoot(), relativePath);
}

void initiateContractNegotiation(String contractOfferFilePath) {
Response response = RestAssured
.given()
.headers("X-Api-Key", "password")
.contentType(ContentType.JSON)
.body(new File(TestUtils.findBuildRoot(), contractOfferFilePath))
.post("http://localhost:9192/management/v2/contractnegotiations")
.then()
.statusCode(HttpStatus.SC_OK)
.extract()
.response();

String negotiationId = response.jsonPath().getString("@id");
if (negotiationId == null || negotiationId.isEmpty()) {
throw new IllegalStateException("Failed to get a valid contract negotiation ID from the response");
}

contractNegotiationId = negotiationId;
}

void lookUpContractAgreementTerminated() {
await().atMost(120, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).untilAsserted(() ->
RestAssured
.given()
.headers("X-Api-Key", "password")
.when()
.get("http://localhost:9192/management/v2/contractnegotiations/{id}", contractNegotiationId)
.then()
.statusCode(HttpStatus.SC_OK)
.body("state", equalTo("TERMINATED"))
);
}
}

0 comments on commit a6fdfef

Please sign in to comment.