Skip to content

Commit

Permalink
introduce separate test module for edr-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger committed Mar 18, 2024
1 parent c3e50ed commit 5d968ef
Show file tree
Hide file tree
Showing 13 changed files with 767 additions and 74 deletions.
5 changes: 0 additions & 5 deletions edc-tests/e2e-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ dependencies {
testImplementation(libs.awaitility)
testImplementation(libs.aws.s3)
testImplementation(libs.edc.spi.core)
testImplementation(libs.edc.spi.edrstore)
testImplementation(libs.edc.junit)
testImplementation(libs.edc.spi.policy)
testImplementation(libs.edc.spi.contract)
Expand All @@ -59,13 +58,9 @@ dependencies {
testImplementation(libs.testcontainers.vault)
testImplementation(libs.bouncyCastle.bcpkixJdk18on)
testImplementation(project(":spi:core-spi"))
testImplementation(project(":spi:tokenrefresh-spi"))

testImplementation(libs.netty.mockserver)

testCompileOnly(project(":edc-tests:runtime:extensions"))
testCompileOnly(project(":edc-tests:runtime:runtime-memory"))
testCompileOnly(project(":edc-tests:runtime:runtime-memory-signaling"))
testCompileOnly(project(":edc-tests:runtime:iatp:runtime-memory-sts"))
testCompileOnly(project(":edc-tests:runtime:iatp:runtime-memory-iatp-ih"))
testCompileOnly(project(":edc-tests:runtime:iatp:runtime-memory-iatp-dim-ih"))
Expand Down

This file was deleted.

51 changes: 51 additions & 0 deletions edc-tests/edc-controlplane/edr-tests/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/********************************************************************************
* 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
********************************************************************************/

plugins {
`java-library`
`java-test-fixtures`
}

dependencies {
testImplementation(project(":spi:edr-spi"))
testImplementation(project(":edc-extensions:edr:edr-api"))
testImplementation(project(":spi:core-spi"))
testImplementation(project(":spi:tokenrefresh-spi"))

testImplementation(testFixtures(libs.edc.api.management.test.fixtures))
testImplementation(libs.edc.spi.edrstore)
testImplementation(libs.edc.identity.trust.sts.embedded)
testImplementation(libs.netty.mockserver)
testImplementation(libs.edc.core.token)
testImplementation(libs.edc.junit)
testImplementation(libs.restAssured)

testCompileOnly(project(":edc-tests:runtime:runtime-memory"))

testFixturesImplementation(libs.junit.jupiter.api)
testFixturesImplementation(libs.edc.spi.core)
testFixturesImplementation(libs.edc.junit)
testFixturesImplementation(libs.edc.spi.policy)
testFixturesImplementation(libs.edc.spi.contract)
}

// do not publish
edcBuild {
publish.set(false)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/********************************************************************************
* 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;

import jakarta.json.Json;
import jakarta.json.JsonArray;
import jakarta.json.JsonObject;
import jakarta.json.JsonValue;
import org.eclipse.edc.connector.contract.spi.ContractId;

import static org.eclipse.edc.catalog.spi.CatalogRequest.CATALOG_REQUEST_QUERY_SPEC;
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID;
import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_POLICY_ATTRIBUTE;
import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE;

public class CatalogHelperFunctions {


public static JsonObject createCatalogRequest(JsonObject query, String dspEndpoint) {
var jsonBuilder = Json.createObjectBuilder();
jsonBuilder.add("@type", "CatalogRequest");
jsonBuilder.add(EDC_NAMESPACE + "counterPartyAddress", dspEndpoint);
jsonBuilder.add(EDC_NAMESPACE + "protocol", "dataspace-protocol-http");

if (query != null) {
jsonBuilder.add(CATALOG_REQUEST_QUERY_SPEC, query);
}
return jsonBuilder.build();
}

public static ContractId getDatasetContractId(JsonObject dataset) {
var id = dataset.getJsonArray(ODRL_POLICY_ATTRIBUTE).get(0).asJsonObject().getString(ID);
return ContractId.parseId(id).orElseThrow(f -> new RuntimeException(f.getFailureDetail()));
}

public static String getDatasetAssetId(JsonObject dataset) {
return getDatasetContractId(dataset).assetIdPart();
}

public static String getDatasetAssetId(JsonValue dataset) {
return getDatasetContractId(dataset.asJsonObject()).assetIdPart();
}

public static JsonArray getDatasetPolicies(JsonObject dataset) {
return dataset.getJsonArray(ODRL_POLICY_ATTRIBUTE);
}

public static JsonObject getDatasetFirstPolicy(JsonObject dataset) {
return dataset.getJsonArray(ODRL_POLICY_ATTRIBUTE).stream().findFirst().get().asJsonObject();
}

public static JsonObject getDatasetFirstPolicy(JsonValue dataset) {
return getDatasetFirstPolicy(dataset.asJsonObject());
}

public static JsonArray getDatasetPolicies(JsonValue dataset) {
return getDatasetPolicies(dataset.asJsonObject());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/********************************************************************************
* 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;

import jakarta.json.Json;
import jakarta.json.JsonArray;
import jakarta.json.JsonArrayBuilder;
import jakarta.json.JsonObject;
import org.eclipse.edc.jsonld.TitaniumJsonLd;
import org.eclipse.edc.jsonld.spi.JsonLd;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.tractusx.edc.api.edr.dto.NegotiateEdrRequestDto;

import java.util.Set;

import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE;
import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE;
import static org.mockito.Mockito.mock;

public class EdrNegotiationHelperFunctions {

private static final JsonLd JSON_LD = new TitaniumJsonLd(mock(Monitor.class));

public static JsonObject createEdrNegotiationRequest(String connectorAddress, String providerId, String offerId, String assetId, JsonObject policy, JsonArray callbacks) {
return Json.createObjectBuilder()
.add(TYPE, NegotiateEdrRequestDto.EDR_REQUEST_DTO_TYPE)
.add(EDC_NAMESPACE + "counterPartyId", providerId)
.add(EDC_NAMESPACE + "providerId", providerId)
.add(EDC_NAMESPACE + "counterPartyAddress", connectorAddress)
.add(EDC_NAMESPACE + "protocol", "dataspace-protocol-http")
.add(EDC_NAMESPACE + "offer", Json.createObjectBuilder()
.add(EDC_NAMESPACE + "offerId", offerId)
.add(EDC_NAMESPACE + "assetId", assetId)
.add(EDC_NAMESPACE + "policy", JSON_LD.compact(policy).getContent())
)
.add(EDC_NAMESPACE + "callbackAddresses", callbacks)
.build();
}

public static JsonObject createCallback(String url, boolean transactional, Set<String> events) {
return Json.createObjectBuilder()
.add(TYPE, EDC_NAMESPACE + "CallbackAddress")
.add(EDC_NAMESPACE + "transactional", transactional)
.add(EDC_NAMESPACE + "uri", url)
.add(EDC_NAMESPACE + "events", events
.stream()
.collect(Json::createArrayBuilder, JsonArrayBuilder::add, JsonArrayBuilder::add)
.build())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft
*
* 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;

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.openssl.jcajce.JcaPEMWriter;
import org.eclipse.edc.spi.EdcException;

import java.io.IOException;
import java.io.StringWriter;
import java.security.InvalidAlgorithmParameterException;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.spec.ECGenParameterSpec;

public class Functions {

/**
* Returns the Pem representation of a {@link Key}
*
* @param key The input key
* @return The pem encoded key
*/
public static String toPemEncoded(Key key) {
var writer = new StringWriter();
try (var jcaPEMWriter = new JcaPEMWriter(writer)) {
jcaPEMWriter.writeObject(key);
} catch (IOException e) {
throw new EdcException("Unable to convert private in PEM format ", e);
}
return writer.toString();
}


public static KeyPair generateKeyPair() {
try {
KeyPairGenerator gen = KeyPairGenerator.getInstance("EC", new BouncyCastleProvider());
gen.initialize(new ECGenParameterSpec("secp256r1"));
return gen.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException e) {
throw new RuntimeException(e);
}
}
}
Loading

0 comments on commit 5d968ef

Please sign in to comment.