Skip to content

Commit

Permalink
Add tests for federated catalog samples 01 and 02
Browse files Browse the repository at this point in the history
  • Loading branch information
farhin23 committed Nov 29, 2024
1 parent 9d86244 commit e410e57
Show file tree
Hide file tree
Showing 4 changed files with 244 additions and 0 deletions.
4 changes: 4 additions & 0 deletions system-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* Contributors:
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation
* Fraunhofer-Gesellschaft - dependencies for Federated Catalog Tests
*
*/

Expand Down Expand Up @@ -55,6 +56,9 @@ dependencies {
testCompileOnly(project(":transfer:transfer-05-file-transfer-cloud:cloud-transfer-provider"))
testCompileOnly(project(":transfer:transfer-05-file-transfer-cloud:cloud-transfer-consumer"))
testCompileOnly(project(":transfer:transfer-05-file-transfer-cloud:transfer-file-cloud"))

testCompileOnly(project(":federated-catalog:fc-01-embedded:fc-connector"))
testCompileOnly(project(":federated-catalog:fc-02-standalone:standalone-fc"))
}

tasks.compileJava {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright (c) 2024 Fraunhofer-Gesellschaft
*
* 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:
* Fraunhofer-Gesellschaft - initial API and implementation
*
*/

package org.eclipse.edc.samples.common;

import com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.HttpStatus;
import io.restassured.http.ContentType;
import org.eclipse.edc.junit.extensions.EmbeddedRuntime;
import org.eclipse.edc.junit.extensions.RuntimeExtension;
import org.eclipse.edc.junit.extensions.RuntimePerClassExtension;

import java.util.Map;

import static io.restassured.RestAssured.given;
import static org.eclipse.edc.samples.common.FileTransferCommon.getFileContentFromRelativePath;
import static org.eclipse.edc.samples.common.FileTransferCommon.getFileFromRelativePath;
import static org.eclipse.edc.samples.common.PrerequisitesCommon.API_KEY_HEADER_KEY;
import static org.eclipse.edc.samples.common.PrerequisitesCommon.API_KEY_HEADER_VALUE;
import static org.eclipse.edc.samples.util.TransferUtil.post;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.Matchers.emptyString;

public class FederatedCatalogCommon {
private static final String CREATE_ASSET_FILE_PATH = "transfer/transfer-01-negotiation/resources/create-asset.json";
private static final String V3_ASSETS_PATH = "/v3/assets";
private static final String ASSET_ID = "@id";

private static final String STANDALONE_FC_MODULE_PATH = ":federated-catalog:fc-02-standalone:standalone-fc";
private static final String FC_CONNECTOR_MODULE_PATH = ":federated-catalog:fc-01-embedded:fc-connector";
private static final String STANDALONE_FC = "standalone-fc";
private static final String CONSUMER = "consumer";

private static final String EDC_KEYSTORE = "edc.keystore";
private static final String EDC_KEYSTORE_PASSWORD = "edc.keystore.password";
private static final String EDC_FS_CONFIG = "edc.fs.config";
private static final String CERT_PFX_FILE_PATH = "transfer/transfer-00-prerequisites/resources/certs/cert.pfx";
private static final String KEYSTORE_PASSWORD = "123456";

private static final String STANDALONE_FC_CONFIG_PROPERTIES_FILE_PATH = "federated-catalog/fc-02-standalone/standalone-fc/config.properties";
private static final String FC_CONNECTOR_CONFIG_PROPERTIES_FILE_PATH = "federated-catalog/fc-01-embedded/fc-connector/config.properties";

private static final String CRAWLER_EXECUTION_DELAY = "edc.catalog.cache.execution.delay.seconds";
public static final int CRAWLER_EXECUTION_DELAY_VALUE = 5;
private static final String CRAWLER_EXECUTION_PERIOD = "edc.catalog.cache.execution.period.seconds";
public static final int CRAWLER_EXECUTION_PERIOD_VALUE = 5;
public static final int TIMEOUT = 5 * CRAWLER_EXECUTION_PERIOD_VALUE;

public static final String EMBEDDED_FC_CATALOG_API_ENDPOINT = "http://localhost:29195/api/catalog/v1alpha/catalog/query";
public static final String STANDALONE_FC_CATALOG_API_ENDPOINT = "http://localhost:39195/api/catalog/v1alpha/catalog/query";
public static final String EMPTY_QUERY_FILE_PATH = "federated-catalog/fc-01-embedded/resources/empty-query.json";
public static final String TYPE = "[0].@type";
public static final String CATALOG = "dcat:Catalog";
public static final String DATASET_ASSET_ID = "[0].'dcat:dataset'.@id";

public static RuntimeExtension getFcEmbeddedConnector() {
return getRuntime(FC_CONNECTOR_MODULE_PATH, CONSUMER,FC_CONNECTOR_CONFIG_PROPERTIES_FILE_PATH);
}

public static RuntimeExtension getStandaloneFc() {
return getRuntime(STANDALONE_FC_MODULE_PATH, STANDALONE_FC,STANDALONE_FC_CONFIG_PROPERTIES_FILE_PATH);
}

private static RuntimeExtension getRuntime(
String modulePath,
String moduleName,
String configPropertiesFilePath
) {
return new RuntimePerClassExtension(new EmbeddedRuntime(
moduleName,
Map.of(
EDC_KEYSTORE, getFileFromRelativePath(CERT_PFX_FILE_PATH).getAbsolutePath(),
EDC_KEYSTORE_PASSWORD, KEYSTORE_PASSWORD,
EDC_FS_CONFIG, getFileFromRelativePath(configPropertiesFilePath).getAbsolutePath(),
CRAWLER_EXECUTION_DELAY, Integer.toString(CRAWLER_EXECUTION_DELAY_VALUE),
CRAWLER_EXECUTION_PERIOD, Integer.toString(CRAWLER_EXECUTION_PERIOD_VALUE)
),
modulePath
));
}

public static String createAsset() {
return post(PrerequisitesCommon.PROVIDER_MANAGEMENT_URL + V3_ASSETS_PATH,
getFileContentFromRelativePath(CREATE_ASSET_FILE_PATH),
ASSET_ID);
}

public static String postAndAssertType(String url, String requestBody, String jsonPath) {
return given()
.headers(API_KEY_HEADER_KEY, API_KEY_HEADER_VALUE)
.contentType(ContentType.JSON)
.body(requestBody)
.when()
.post(url)
.then()
.log().ifError()
.statusCode(HttpStatus.SC_OK)
.body(TYPE, not(emptyString()))
.body(TYPE, is(CATALOG))
.extract()
.jsonPath()
.get(jsonPath);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2024 Fraunhofer-Gesellschaft
*
* 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:
* Fraunhofer-Gesellschaft - initial API and implementation
*
*/

package org.eclipse.edc.samples.federatedCatalog;

import org.assertj.core.api.Assertions;
import org.eclipse.edc.junit.annotations.EndToEndTest;
import org.eclipse.edc.junit.extensions.RuntimeExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.time.Clock;
import java.time.Duration;

import static org.awaitility.Awaitility.await;
import static org.eclipse.edc.samples.common.FederatedCatalogCommon.*;
import static org.eclipse.edc.samples.common.FileTransferCommon.getFileContentFromRelativePath;
import static org.eclipse.edc.samples.common.NegotiationCommon.createContractDefinition;
import static org.eclipse.edc.samples.common.NegotiationCommon.createPolicy;
import static org.eclipse.edc.samples.common.PrerequisitesCommon.*;

//@EndToEndTest
public class FederatedCatalog01embeddedTest {

@RegisterExtension
static RuntimeExtension participantConnector = getProvider();

@RegisterExtension
static RuntimeExtension fcConnector = getFcEmbeddedConnector();

@Test
void shouldStartConnector() {
Assertions.assertThat(participantConnector.getService(Clock.class)).isNotNull();
Assertions.assertThat(fcConnector.getService(Clock.class)).isNotNull();
}

@Test
void runSampleSteps() {
String assetId = createAsset();
createPolicy();
createContractDefinition();

await()
.atMost(Duration.ofSeconds(TIMEOUT))
.pollDelay(Duration.ofSeconds(CRAWLER_EXECUTION_DELAY_VALUE))
.pollInterval(Duration.ofSeconds(CRAWLER_EXECUTION_PERIOD_VALUE))
.ignoreExceptions()
.until(() -> postAndAssertType(EMBEDDED_FC_CATALOG_API_ENDPOINT, getFileContentFromRelativePath(EMPTY_QUERY_FILE_PATH), DATASET_ASSET_ID),
id -> id.equals(assetId));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2024 Fraunhofer-Gesellschaft
*
* 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:
* Fraunhofer-Gesellschaft - initial API and implementation
*
*/

package org.eclipse.edc.samples.federatedCatalog;

import org.assertj.core.api.Assertions;
import org.eclipse.edc.junit.annotations.EndToEndTest;
import org.eclipse.edc.junit.extensions.RuntimeExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.time.Clock;
import java.time.Duration;

import static org.awaitility.Awaitility.await;
import static org.eclipse.edc.samples.common.FederatedCatalogCommon.*;
import static org.eclipse.edc.samples.common.FileTransferCommon.getFileContentFromRelativePath;
import static org.eclipse.edc.samples.common.NegotiationCommon.createContractDefinition;
import static org.eclipse.edc.samples.common.NegotiationCommon.createPolicy;
import static org.eclipse.edc.samples.common.PrerequisitesCommon.*;

@EndToEndTest
public class FederatedCatalog02standaloneTest {
@RegisterExtension
static RuntimeExtension participantConnector = getProvider();

@RegisterExtension
static RuntimeExtension standaloneFcRuntime = getStandaloneFc();

@Test
void shouldStartRuntimes() {
Assertions.assertThat(participantConnector.getService(Clock.class)).isNotNull();
Assertions.assertThat(standaloneFcRuntime.getService(Clock.class)).isNotNull();
}

@Test
void runSampleSteps() {
String assetId = createAsset();
createPolicy();
createContractDefinition();

await()
.atMost(Duration.ofSeconds(TIMEOUT))
.pollDelay(Duration.ofSeconds(CRAWLER_EXECUTION_DELAY_VALUE))
.pollInterval(Duration.ofSeconds(CRAWLER_EXECUTION_PERIOD_VALUE))
.ignoreExceptions()
.until(() -> postAndAssertType(STANDALONE_FC_CATALOG_API_ENDPOINT, getFileContentFromRelativePath(EMPTY_QUERY_FILE_PATH), DATASET_ASSET_ID),
id -> id.equals(assetId));
}

}

0 comments on commit e410e57

Please sign in to comment.