-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable federated catalog cache SQL variant
Showing
10 changed files
with
279 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...rg/eclipse/tractusx/edc/postgresql/migration/FederatedCatalogCacheMigrationExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2022 Mercedes-Benz Tech Innovation GmbH | ||
* Copyright (c) 2021,2022 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* 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. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
package org.eclipse.tractusx.edc.postgresql.migration; | ||
|
||
public class FederatedCatalogCacheMigrationExtension extends AbstractPostgresqlMigrationExtension { | ||
private static final String NAME_SUBSYSTEM = "federatedcatalog"; | ||
|
||
protected String getSubsystemName() { | ||
Check notice Code scanning / CodeQL Missing Override annotation Note
This method overrides
AbstractPostgresqlMigrationExtension.getSubsystemName Error loading related location Loading |
||
return NAME_SUBSYSTEM; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...tgresql/migration/federatedcatalog/V0_0_1__Init_FederatedCatalogCache_Database_Schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
-- | ||
-- Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
-- | ||
-- 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: | ||
-- Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
-- | ||
|
||
-- | ||
-- table: edc_federated_catalog | ||
-- | ||
|
||
CREATE TABLE IF NOT EXISTS edc_federated_catalog | ||
( | ||
id VARCHAR PRIMARY KEY NOT NULL, | ||
catalog JSON, | ||
marked BOOLEAN DEFAULT FALSE | ||
); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
171 changes: 171 additions & 0 deletions
171
...alog-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/FederatedCatalogTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* 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. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
package org.eclipse.tractusx.edc.tests.catalog; | ||
|
||
import jakarta.json.Json; | ||
import org.eclipse.edc.crawler.spi.TargetNode; | ||
import org.eclipse.edc.crawler.spi.TargetNodeDirectory; | ||
import org.eclipse.edc.junit.annotations.EndToEndTest; | ||
import org.eclipse.edc.junit.annotations.PostgresqlIntegrationTest; | ||
import org.eclipse.edc.junit.extensions.RuntimeExtension; | ||
import org.eclipse.tractusx.edc.tests.participant.TransferParticipant; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
|
||
import static io.restassured.http.ContentType.JSON; | ||
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; | ||
import static org.awaitility.Awaitility.await; | ||
import static org.eclipse.edc.connector.controlplane.test.system.utils.PolicyFixtures.noConstraintPolicy; | ||
import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.CONSUMER_BPN; | ||
import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.CONSUMER_NAME; | ||
import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PROVIDER_BPN; | ||
import static org.eclipse.tractusx.edc.tests.TestRuntimeConfiguration.PROVIDER_NAME; | ||
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.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.is; | ||
|
||
public class FederatedCatalogTest { | ||
|
||
protected static final TransferParticipant CONSUMER = TransferParticipant.Builder.newInstance() | ||
.name(CONSUMER_NAME) | ||
.id(CONSUMER_BPN) | ||
.build(); | ||
|
||
|
||
protected static final TransferParticipant PROVIDER = TransferParticipant.Builder.newInstance() | ||
.name(PROVIDER_NAME) | ||
.id(PROVIDER_BPN) | ||
.build(); | ||
|
||
protected static Map<String, String> withNodeList(Map<String, String> config, TransferParticipant... participants) { | ||
var nodeList = Json.createArrayBuilder(); | ||
for (var participant : participants) { | ||
nodeList.add(Json.createObjectBuilder() | ||
.add("id", participant.getBpn()) | ||
.add("name", participant.getDid()) | ||
.add("url", participant.getProtocolEndpoint().getUrl().toString()) | ||
.add("supportedProtocols", Json.createArrayBuilder().add("dataspace-protocol-http"))); | ||
} | ||
try { | ||
var tempFile = Files.createTempFile("nodelist-", UUID.randomUUID().toString()); | ||
tempFile.toFile().deleteOnExit(); | ||
var stream = new ByteArrayInputStream(nodeList.build().toString().getBytes(StandardCharsets.UTF_8)); | ||
Files.copy(stream, tempFile, REPLACE_EXISTING); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
return config; | ||
} | ||
|
||
abstract static class Tests { | ||
|
||
@Test | ||
@DisplayName("Consumer gets cached catalog with provider entry") | ||
void requestCatalog_fulfillsPolicy_shouldReturnOffer() { | ||
|
||
// arrange | ||
PROVIDER.createAsset("test-asset"); | ||
var ap = PROVIDER.createPolicyDefinition(noConstraintPolicy()); | ||
var cp = PROVIDER.createPolicyDefinition(noConstraintPolicy()); | ||
PROVIDER.createContractDefinition("test-asset", "test-def", ap, cp); | ||
|
||
|
||
await().pollInterval(ASYNC_POLL_INTERVAL) | ||
.atMost(ASYNC_TIMEOUT) | ||
.untilAsserted(() -> { | ||
// act | ||
CONSUMER.getFederatedCatalog() | ||
.log().ifError() | ||
.statusCode(200) | ||
.contentType(JSON) | ||
.body("size()", is(1)) | ||
.body("[0].'http://www.w3.org/ns/dcat#dataset'.'@id'", equalTo("test-asset")); | ||
}); | ||
} | ||
} | ||
|
||
static class TestTargetNodeDirectory implements TargetNodeDirectory { | ||
|
||
private final List<TransferParticipant> participants; | ||
|
||
TestTargetNodeDirectory(List<TransferParticipant> participants) { | ||
this.participants = participants; | ||
} | ||
|
||
@Override | ||
public List<TargetNode> getAll() { | ||
return participants.stream() | ||
.map(p -> new TargetNode(p.getDid(), p.getBpn(), p.getProtocolEndpoint().getUrl().toString(), List.of("dataspace-protocol-http"))) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public void insert(TargetNode node) { | ||
|
||
} | ||
} | ||
|
||
@Nested | ||
@EndToEndTest | ||
class InMemory extends Tests { | ||
|
||
@RegisterExtension | ||
protected static final RuntimeExtension CONSUMER_RUNTIME = memoryRuntime(CONSUMER.getName(), CONSUMER.getBpn(), CONSUMER.getConfiguration()); | ||
|
||
@RegisterExtension | ||
protected static final RuntimeExtension PROVIDER_RUNTIME = memoryRuntime(PROVIDER.getName(), PROVIDER.getBpn(), PROVIDER.getConfiguration()); | ||
|
||
|
||
static { | ||
CONSUMER_RUNTIME.registerServiceMock(TargetNodeDirectory.class, new TestTargetNodeDirectory(List.of(PROVIDER))); | ||
} | ||
} | ||
|
||
@Nested | ||
@PostgresqlIntegrationTest | ||
class Postgres extends Tests { | ||
|
||
@RegisterExtension | ||
protected static final RuntimeExtension CONSUMER_RUNTIME = pgRuntime(CONSUMER.getName(), CONSUMER.getBpn(), CONSUMER.getConfiguration()); | ||
|
||
@RegisterExtension | ||
protected static final RuntimeExtension PROVIDER_RUNTIME = pgRuntime(PROVIDER.getName(), PROVIDER.getBpn(), PROVIDER.getConfiguration()); | ||
|
||
static { | ||
CONSUMER_RUNTIME.registerServiceMock(TargetNodeDirectory.class, new TestTargetNodeDirectory(List.of(PROVIDER))); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.