Skip to content

Commit

Permalink
Fix tests after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
ununhexium committed Oct 24, 2024
1 parent 85a2130 commit ffd0a12
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import jakarta.ws.rs.container.ContainerRequestContext;
import jakarta.ws.rs.container.ContainerResponseContext;
import jakarta.ws.rs.container.ContainerResponseFilter;
import org.eclipse.edc.protocol.dsp.api.configuration.DspApiConfiguration;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.web.spi.WebService;
import org.eclipse.edc.web.spi.configuration.ApiContext;

import static jakarta.ws.rs.HttpMethod.GET;
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE;
Expand All @@ -37,16 +37,12 @@

public class DatasetFixExtension implements ServiceExtension {


@Inject
private DspApiConfiguration apiConfiguration;

@Inject
private WebService webService;

@Override
public void initialize(ServiceExtensionContext context) {
webService.registerResource(apiConfiguration.getContextAlias(), new DatasetFilter());
webService.registerResource(ApiContext.PROTOCOL, new DatasetFilter());
}

private static class DatasetFilter implements ContainerResponseFilter {
Expand Down
114 changes: 58 additions & 56 deletions tests/src/test/java/de/sovity/edc/e2e/DatasetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,116 +14,118 @@

package de.sovity.edc.e2e;

import de.sovity.edc.extension.e2e.connector.ConnectorRemote;
import de.sovity.edc.extension.e2e.connector.config.ConnectorConfig;
import de.sovity.edc.extension.e2e.extension.Consumer;
import de.sovity.edc.extension.e2e.extension.E2eTestExtension;
import de.sovity.edc.extension.e2e.extension.Provider;
import de.sovity.edc.extension.e2e.connector.remotes.management_api.ManagementApiConnectorRemote;
import de.sovity.edc.extension.e2e.junit.CeE2eTestExtension;
import de.sovity.edc.extension.e2e.junit.utils.Consumer;
import de.sovity.edc.extension.e2e.junit.utils.Provider;
import io.restassured.response.Response;
import org.eclipse.edc.spi.system.configuration.Config;
import org.eclipse.edc.web.spi.configuration.ApiContext;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.util.Map;
import java.util.UUID;

import static de.sovity.edc.extension.e2e.extension.Helpers.defaultE2eTestExtension;
import static io.restassured.http.ContentType.JSON;
import static jakarta.json.Json.createObjectBuilder;
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.CONTEXT;
import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE;
import static org.eclipse.edc.spi.CoreConstants.EDC_PREFIX;
import static org.eclipse.edc.spi.constants.CoreConstants.EDC_NAMESPACE;
import static org.eclipse.edc.spi.constants.CoreConstants.EDC_PREFIX;
import static org.hamcrest.Matchers.equalTo;

class DatasetTest {

@RegisterExtension
private static E2eTestExtension e2eTestExtension = defaultE2eTestExtension();
private static CeE2eTestExtension e2eTestExtension = CeE2eTestExtension.builder()
.additionalModule(":launchers:utils:vanilla-control-plane")
.build();

@Test
void canRetrieveOfferedDataset(
@Consumer ConnectorRemote consumerConnector,
@Provider ConnectorConfig providerConfig,
@Provider ConnectorRemote providerConnector) {
@Consumer ManagementApiConnectorRemote consumerConnector,
@Provider Config providerConfig,
@Provider ManagementApiConnectorRemote providerConnector) {
// arrange
var assetId = UUID.randomUUID().toString();
providerConnector.createDataOffer(assetId, "http://example.com");

// act & assert
prepareDatasetApiCall(
consumerConnector,
providerConfig.getProtocolApiUrl(),
assetId)
.then()
.statusCode(200)
.body("'edc:description'", equalTo("description"));
consumerConnector,
ApiContext.PROTOCOL,
assetId)
.then()
.statusCode(200)
.body("'edc:description'", equalTo("description"));
}

@Test
void canNotRetrieveNotOfferedDataset(
@Consumer ConnectorRemote consumerConnector,
@Provider ConnectorConfig providerConfig,
@Provider ConnectorRemote providerConnector) {
@Consumer ManagementApiConnectorRemote consumerConnector,
@Provider Config providerConfig,
@Provider ManagementApiConnectorRemote providerConnector) {
// arrange
Map<String, Object> dataSource = Map.of(
EDC_NAMESPACE + "type", "HttpData",
EDC_NAMESPACE + "baseUrl", "http://localhost");
EDC_NAMESPACE + "type", "HttpData",
EDC_NAMESPACE + "baseUrl", "http://localhost");
var assetId = UUID.randomUUID().toString();
providerConnector.createAsset(assetId, dataSource);

// act & assert
prepareDatasetApiCall(
consumerConnector,
providerConfig.getProtocolApiUrl(),
assetId)
.then()
.statusCode(502);
consumerConnector,
ApiContext.PROTOCOL,
assetId)
.then()
.statusCode(502);
}

@Test
void canNotRetrieveNotOfferedDatasetIfValidOfferAvailable(
@Consumer ConnectorRemote consumerConnector,
@Provider ConnectorConfig providerConfig,
@Provider ConnectorRemote providerConnector) {
@Consumer ManagementApiConnectorRemote consumerConnector,
@Provider Config providerConfig,
@Provider ManagementApiConnectorRemote providerConnector) {
// arrange
Map<String, Object> dataSource = Map.of(
EDC_NAMESPACE + "type", "HttpData",
EDC_NAMESPACE + "baseUrl", "http://localhost");
EDC_NAMESPACE + "type", "HttpData",
EDC_NAMESPACE + "baseUrl", "http://localhost");
var notOfferedAssetId = UUID.randomUUID().toString();
var offeredAssetId = UUID.randomUUID().toString();
providerConnector.createAsset(notOfferedAssetId, dataSource);
providerConnector.createDataOffer(offeredAssetId, "http://localhost");

// act & assert
prepareDatasetApiCall(
consumerConnector,
providerConfig.getProtocolApiUrl(),
notOfferedAssetId)
.then()
.statusCode(502);
consumerConnector,
ApiContext.PROTOCOL,
notOfferedAssetId)
.then()
.statusCode(502);

prepareDatasetApiCall(
consumerConnector,
providerConfig.getProtocolApiUrl(),
offeredAssetId)
.then()
.statusCode(200)
.body("'edc:description'", equalTo("description"));
consumerConnector,
ApiContext.PROTOCOL,
offeredAssetId)
.then()
.statusCode(200)
.body("'edc:description'", equalTo("description"));
}

private static Response prepareDatasetApiCall(
ConnectorRemote consumerConnector,
String providerProtocolUrl,
String assetId) {
ManagementApiConnectorRemote consumerConnector,
String providerProtocolUrl,
String assetId) {
var requestBody = createObjectBuilder()
.add(CONTEXT, createObjectBuilder().add(EDC_PREFIX, EDC_NAMESPACE))
.add(EDC_NAMESPACE + "counterPartyAddress", providerProtocolUrl)
.add(EDC_NAMESPACE + "protocol", "dataspace-protocol-http")
.add("@id", assetId)
.build();
.add(CONTEXT, createObjectBuilder().add(EDC_PREFIX, EDC_NAMESPACE))
.add(EDC_NAMESPACE + "counterPartyAddress", providerProtocolUrl)
.add(EDC_NAMESPACE + "protocol", "dataspace-protocol-http")
.add("@id", assetId)
.build();
return consumerConnector.prepareManagementApiCall()
.contentType(JSON)
.body(requestBody)
.when()
.post("/v2/catalog/dataset/request");
.contentType(JSON)
.body(requestBody)
.when()
.post("/v2/catalog/dataset/request");
}
}

0 comments on commit ffd0a12

Please sign in to comment.