-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce separate test module for edr-v2
- Loading branch information
1 parent
c3e50ed
commit 5d968ef
Showing
13 changed files
with
767 additions
and
74 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
57 changes: 0 additions & 57 deletions
57
...e-tests/src/test/java/org/eclipse/tractusx/edc/lifecycle/SignalingParticipantRuntime.java
This file was deleted.
Oops, something went wrong.
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,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) | ||
} |
76 changes: 76 additions & 0 deletions
76
...lplane/edr-tests/src/test/java/org/eclipse/tractusx/edc/tests/CatalogHelperFunctions.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,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()); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...edr-tests/src/test/java/org/eclipse/tractusx/edc/tests/EdrNegotiationHelperFunctions.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,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(); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...ts/edc-controlplane/edr-tests/src/test/java/org/eclipse/tractusx/edc/tests/Functions.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,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); | ||
} | ||
} | ||
} |
Oops, something went wrong.