Skip to content

Commit

Permalink
feat(impl):[#370] merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-ext-kmassalski committed Feb 2, 2024
2 parents 5c5d5c8 + 2be68b5 commit 7b4ad06
Show file tree
Hide file tree
Showing 32 changed files with 2,715 additions and 309 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added helper script for building documentation locally.
- Added new job parameter flag "auditContractNegotiation" which toggles setting contractAgreementId in Shells and Submodels
- Added "contractAgreementId" field to Submodel model
- Added Integration Tests for the entire IRS flow using stubbed responses of Discovery Service, Semantic Hub, EDC, Digital Twin Registry and BPDM Pool

### Changed
- Updated license header to "Copyright (c) 2021,2024 Contributors to the Eclipse Foundation"
Expand Down
10 changes: 5 additions & 5 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,11 @@ maven/mavencentral/org.eclipse.jetty/jetty-xml/11.0.17, EPL-2.0 OR Apache-2.0, a
maven/mavencentral/org.eclipse.jetty/jetty-xml/11.0.19, EPL-2.0 OR Apache-2.0, approved, rt.jetty
maven/mavencentral/org.eclipse.tractusx.irs/irs-api/0.0.2-SNAPSHOT, Apache-2.0, approved, automotive.tractusx
maven/mavencentral/org.eclipse.tractusx.irs/irs-common/0.0.2-SNAPSHOT, Apache-2.0, approved, automotive.tractusx
maven/mavencentral/org.eclipse.tractusx.irs/irs-edc-client/1.5.1-SNAPSHOT, Apache-2.0, approved, automotive.tractusx
maven/mavencentral/org.eclipse.tractusx.irs/irs-models/1.5.1-SNAPSHOT, Apache-2.0, approved, automotive.tractusx
maven/mavencentral/org.eclipse.tractusx.irs/irs-edc-client/1.5.2-SNAPSHOT, Apache-2.0, approved, automotive.tractusx
maven/mavencentral/org.eclipse.tractusx.irs/irs-models/1.5.2-SNAPSHOT, Apache-2.0, approved, automotive.tractusx
maven/mavencentral/org.eclipse.tractusx.irs/irs-policy-store/0.0.2-SNAPSHOT, Apache-2.0, approved, automotive.tractusx
maven/mavencentral/org.eclipse.tractusx.irs/irs-registry-client/1.5.1-SNAPSHOT, Apache-2.0, approved, automotive.tractusx
maven/mavencentral/org.eclipse.tractusx.irs/irs-testing/1.5.1-SNAPSHOT, Apache-2.0, approved, automotive.tractusx
maven/mavencentral/org.eclipse.tractusx.irs/irs-registry-client/1.5.2-SNAPSHOT, Apache-2.0, approved, automotive.tractusx
maven/mavencentral/org.eclipse.tractusx.irs/irs-testing/1.5.2-SNAPSHOT, Apache-2.0, approved, automotive.tractusx
maven/mavencentral/org.glassfish.hk2.external/aopalliance-repackaged/3.0.4, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.glassfish
maven/mavencentral/org.glassfish.hk2.external/aopalliance-repackaged/3.0.5, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.glassfish
maven/mavencentral/org.glassfish.hk2/hk2-api/3.0.4, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.glassfish
Expand Down Expand Up @@ -473,7 +473,7 @@ maven/mavencentral/org.testcontainers/testcontainers/1.19.1, Apache-2.0 AND MIT,
maven/mavencentral/org.typelevel/spire-macros_2.13/0.17.0, MIT, approved, clearlydefined
maven/mavencentral/org.unbescape/unbescape/1.1.6.RELEASE, Apache-2.0, approved, CQ18904
maven/mavencentral/org.webjars/swagger-ui/5.2.0, Apache-2.0, approved, #10221
maven/mavencentral/org.wiremock/wiremock-standalone/3.2.0, MIT AND Apache-2.0, approved, #10919
maven/mavencentral/org.wiremock/wiremock-standalone/3.3.1, MIT AND Apache-2.0, approved, #12941
maven/mavencentral/org.xerial.snappy/snappy-java/1.1.10.5, Apache-2.0 AND (Apache-2.0 AND BSD-3-Clause), approved, #9098
maven/mavencentral/org.xmlunit/xmlunit-core/2.9.1, Apache-2.0, approved, #6272
maven/mavencentral/org.yaml/snakeyaml/1.33, Apache-2.0, approved, clearlydefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
Expand All @@ -66,6 +67,7 @@
@Configuration
@RequiredArgsConstructor
@SuppressWarnings("PMD.ExcessiveImports")
@Profile("!integrationtest")
public class RestTemplateConfig {

public static final String DTR_REST_TEMPLATE = "dtrRestTemplate";
Expand Down

Large diffs are not rendered by default.

100 changes: 100 additions & 0 deletions irs-api/src/test/java/org/eclipse/tractusx/irs/WireMockTestConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/********************************************************************************
* Copyright (c) 2022,2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* Copyright (c) 2021,2024 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.irs;

import static org.eclipse.tractusx.irs.configuration.RestTemplateConfig.BPDM_REST_TEMPLATE;
import static org.eclipse.tractusx.irs.configuration.RestTemplateConfig.DISCOVERY_REST_TEMPLATE;
import static org.eclipse.tractusx.irs.configuration.RestTemplateConfig.DTR_REST_TEMPLATE;
import static org.eclipse.tractusx.irs.configuration.RestTemplateConfig.EDC_REST_TEMPLATE;
import static org.eclipse.tractusx.irs.configuration.RestTemplateConfig.NO_ERROR_REST_TEMPLATE;
import static org.eclipse.tractusx.irs.configuration.RestTemplateConfig.SEMHUB_REST_TEMPLATE;
import static org.eclipse.tractusx.irs.testing.wiremock.WireMockConfig.restTemplateProxy;

import java.util.List;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.eclipse.edc.policy.model.PolicyRegistrationTypes;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;

@TestConfiguration
public class WireMockTestConfig {
public static final int HTTP_PORT = 8085;
private static final String PROXY_SERVER_HOST = "127.0.0.1";

@Primary
@Profile("integrationtest")
@Bean(DTR_REST_TEMPLATE)
RestTemplate dtrRestTemplate() {
return restTemplateProxy(PROXY_SERVER_HOST, HTTP_PORT);
}

@Primary
@Profile("integrationtest")
@Bean(EDC_REST_TEMPLATE)
RestTemplate edcRestTemplate() {
final RestTemplate edcRestTemplate = restTemplateProxy(PROXY_SERVER_HOST, HTTP_PORT);
final List<HttpMessageConverter<?>> messageConverters = edcRestTemplate.getMessageConverters();
for (final HttpMessageConverter<?> converter : messageConverters) {
if (converter instanceof final MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter) {
final ObjectMapper mappingJackson2HttpMessageConverterObjectMapper = mappingJackson2HttpMessageConverter.getObjectMapper();
PolicyRegistrationTypes.TYPES.forEach(
mappingJackson2HttpMessageConverterObjectMapper::registerSubtypes);
}
}
return edcRestTemplate;
}

@Primary
@Profile("integrationtest")
@Bean(NO_ERROR_REST_TEMPLATE)
RestTemplate noErrorRestTemplate() {
return restTemplateProxy(PROXY_SERVER_HOST, HTTP_PORT);
}

@Primary
@Profile("integrationtest")
@Bean(DISCOVERY_REST_TEMPLATE)
RestTemplate discoveryRestTemplate() {
return restTemplateProxy(PROXY_SERVER_HOST, HTTP_PORT);
}

@Primary
@Profile("integrationtest")
@Bean(BPDM_REST_TEMPLATE)
RestTemplate bpdmRestTemplate() {
return restTemplateProxy(PROXY_SERVER_HOST, HTTP_PORT);
}

@Primary
@Profile("integrationtest")
@Bean(SEMHUB_REST_TEMPLATE)
@Qualifier(SEMHUB_REST_TEMPLATE)
RestTemplate semanticHubRestTemplate() {
return restTemplateProxy(PROXY_SERVER_HOST, HTTP_PORT);
}

}
142 changes: 142 additions & 0 deletions irs-api/src/test/java/org/eclipse/tractusx/irs/WiremockSupport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/********************************************************************************
* Copyright (c) 2022,2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
* Copyright (c) 2021,2024 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.irs;

import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
import static org.apache.commons.codec.binary.Base64.encodeBase64String;
import static org.eclipse.tractusx.irs.semanticshub.SemanticHubWireMockSupport.semanticHubWillReturnAllModels;
import static org.eclipse.tractusx.irs.testing.wiremock.DtrWiremockSupport.DATAPLANE_PUBLIC_URL;
import static org.eclipse.tractusx.irs.testing.wiremock.DtrWiremockSupport.submodelDescriptor;
import static org.eclipse.tractusx.irs.testing.wiremock.WireMockConfig.responseWithStatus;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference;
import org.eclipse.tractusx.irs.component.PartChainIdentificationKey;
import org.eclipse.tractusx.irs.component.RegisterJob;
import org.eclipse.tractusx.irs.component.enums.Direction;
import org.eclipse.tractusx.irs.data.StringMapper;
import org.eclipse.tractusx.irs.edc.client.configuration.JsonLdConfiguration;
import org.eclipse.tractusx.irs.edc.client.model.EDRAuthCode;
import org.eclipse.tractusx.irs.semanticshub.SemanticHubWireMockSupport;
import org.eclipse.tractusx.irs.testing.wiremock.DiscoveryServiceWiremockSupport;
import org.eclipse.tractusx.irs.testing.wiremock.DtrWiremockSupport;
import org.eclipse.tractusx.irs.testing.wiremock.SubmodelFacadeWiremockSupport;

public class WiremockSupport {
public static EndpointDataReference createEndpointDataReference(final String contractAgreementId) {
final EDRAuthCode edrAuthCode = EDRAuthCode.builder()
.cid(contractAgreementId)
.dad("test")
.exp(9999999999L)
.build();
final String b64EncodedAuthCode = Base64.getUrlEncoder()
.encodeToString(StringMapper.mapToString(edrAuthCode)
.getBytes(StandardCharsets.UTF_8));
final String jwtToken = "eyJhbGciOiJSUzI1NiJ9." + b64EncodedAuthCode + ".test";
return EndpointDataReference.Builder.newInstance()
.authKey("testkey")
.authCode(jwtToken)
.properties(
Map.of(JsonLdConfiguration.NAMESPACE_EDC_CID, contractAgreementId))
.endpoint(SubmodelFacadeWiremockSupport.DATAPLANE_HOST
+ SubmodelFacadeWiremockSupport.PATH_DATAPLANE_PUBLIC)
.build();
}

static void successfulSemanticModelRequest() {
semanticHubWillReturnAllModels("semantichub/all-models-page-IT.json");
}

static RegisterJob jobRequest(final String globalAssetId, final String bpn, final int depth) {
return RegisterJob.builder()
.key(PartChainIdentificationKey.builder().bpn(bpn).globalAssetId(globalAssetId).build())
.depth(depth)
.aspects(List.of("Batch", "SingleLevelBomAsBuilt"))
.collectAspects(true)
.lookupBPNs(true)
.direction(Direction.DOWNWARD)
.build();
}

static void successfulDiscovery() {
stubFor(DiscoveryServiceWiremockSupport.postDiscoveryFinder200());
stubFor(DiscoveryServiceWiremockSupport.postEdcDiscovery200());
}

static String encodedId(final String shellId) {
return encodeBase64String(shellId.getBytes(StandardCharsets.UTF_8));
}

static void verifyDiscoveryCalls(final int times) {
verify(times, postRequestedFor(urlPathEqualTo(DiscoveryServiceWiremockSupport.DISCOVERY_FINDER_PATH)));
verify(times, postRequestedFor(urlPathEqualTo(DiscoveryServiceWiremockSupport.EDC_DISCOVERY_PATH)));
}

static void verifyNegotiationCalls(final int times) {
verify(times, postRequestedFor(urlPathEqualTo(SubmodelFacadeWiremockSupport.PATH_NEGOTIATE)));
verify(times, postRequestedFor(urlPathEqualTo(SubmodelFacadeWiremockSupport.PATH_CATALOG)));
verify(times * 2, getRequestedFor(urlPathMatching(SubmodelFacadeWiremockSupport.PATH_NEGOTIATE + "/.*")));
verify(times, getRequestedFor(urlPathMatching(
SubmodelFacadeWiremockSupport.PATH_NEGOTIATE + "/.*" + SubmodelFacadeWiremockSupport.PATH_STATE)));
verify(times, postRequestedFor(urlPathEqualTo(SubmodelFacadeWiremockSupport.PATH_TRANSFER)));
verify(times * 2, getRequestedFor(urlPathMatching(SubmodelFacadeWiremockSupport.PATH_TRANSFER + "/.*")));
verify(times, getRequestedFor(urlPathMatching(
SubmodelFacadeWiremockSupport.PATH_TRANSFER + "/.*" + SubmodelFacadeWiremockSupport.PATH_STATE)));
}

static void successfulDataRequests(final String assetId, final String fileName) {
stubFor(get(urlPathMatching(DtrWiremockSupport.DATAPLANE_PUBLIC_PATH + "/" + assetId)).willReturn(
responseWithStatus(200).withBodyFile(fileName)));
}

static void successfulSemanticHubRequests() {
SemanticHubWireMockSupport.semanticHubWillReturnBatchSchema();
SemanticHubWireMockSupport.semanticHubWillReturnSingleLevelBomAsBuiltSchema();
}

static String randomUUIDwithPrefix() {
final String uuidPrefix = "urn:uuid:";
return uuidPrefix + randomUUID();
}

static String randomUUID() {
return UUID.randomUUID().toString();
}

static String submodelRequest(final String edcAssetId, final String SingleLevelBomAsBuilt, final String semanticId,
final String sbomFileName) {
final String sbomId = randomUUIDwithPrefix();
final String submoodel = submodelDescriptor(DATAPLANE_PUBLIC_URL, edcAssetId,
DiscoveryServiceWiremockSupport.CONTROLPLANE_PUBLIC_URL, SingleLevelBomAsBuilt, sbomId, semanticId);
successfulDataRequests(sbomId, sbomFileName);
return submoodel;
}
}
Loading

0 comments on commit 7b4ad06

Please sign in to comment.