Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#344 integration tests #744

Merged
merged 23 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fe1f7c5
feat(irs-registry-client): Add wiremock tests for decentral registry …
ds-jhartmann Jan 18, 2024
62cc323
feat(irs-api):[#344] Add wiremock test for BpdmFacade
ds-jhartmann Jan 23, 2024
57e09cd
feat(irs-api):[#344] Extract WireMockConfig to irs-testing
ds-jhartmann Jan 23, 2024
302ddd2
feat(irs-api):[#344] Extract WireMockConfig to irs-testing
ds-jhartmann Jan 23, 2024
d819516
feat(edc-client):[#344] Extend SubmodelFacadeWiremockTest
ds-jhartmann Jan 23, 2024
588b7bd
feat(edc-client):[#344] Extend SemanticHubWiremockTest
ds-jhartmann Jan 23, 2024
4125ea9
feat(edc-client):[#344] Add IrsWireMock integration test
ds-jhartmann Jan 23, 2024
0d30613
feat(irs-test):[#344] Create reusable wiremock config
ds-jhartmann Jan 25, 2024
d1fd503
feat(irs-api):[#344] Add Irs WireMock Test simulating one level
ds-jhartmann Jan 26, 2024
a262bab
feat(irs-testing):[#344] Fix code smells
ds-jhartmann Jan 29, 2024
33945ee
Merge branch 'main' into feature/#344-integration-tests
ds-jhartmann Jan 29, 2024
b557774
feat(irs-api):[#344] Fix test execution and added test cases
ds-jhartmann Jan 29, 2024
9d2e294
chore(foss):[#344] Fix license headers
ds-jhartmann Jan 29, 2024
60d7810
chore(foss):[#344] Update DEPENDENCIES
ds-jhartmann Jan 29, 2024
91c4e88
chore(foss):[#344] Update dash license-tool-plugin
ds-jhartmann Jan 29, 2024
44bed78
feat(irs-api):[#344] Add test case for recursive IRS flow
ds-jhartmann Jan 30, 2024
607faa0
chore(docs):[#344] Add changes to CHANGELOG.md
ds-jhartmann Jan 30, 2024
c455751
chore(foss):[#344] Update DEPENDENCIES
ds-jhartmann Jan 30, 2024
2964eec
feat(irs-api):[#344] Delete unused files
ds-jhartmann Jan 30, 2024
505fa27
feat(irs-api):[#344] Add test case for recursive IRS flow
ds-jhartmann Jan 30, 2024
8be2410
feat(testing):[#344] Renaming *WireMockConfig to *WireMockSupport, re…
ds-jhartmann Feb 1, 2024
d323587
feat(testing):[#344] Renaming *WireMockConfig to *WireMockSupport, re…
ds-jhartmann Feb 1, 2024
c7c4aaf
docs(testing):[#344] Add issue id to todos
ds-jhartmann Feb 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Added helper script for building documentation locally.
- 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