Skip to content

Commit 7cd6d0c

Browse files
authored
Merge pull request #1298 from eclipse-tractusx/feature/xxx-association-cucumber
feature: xxx add association cucumber test action
2 parents b60ea8c + 635cfff commit 7cd6d0c

19 files changed

+699
-945
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Copyright (c) 2024 Contributors to the Eclipse Foundation
2+
#
3+
# See the NOTICE file(s) distributed with this work for additional
4+
# information regarding copyright ownership.
5+
#
6+
# This program and the accompanying materials are made available under the
7+
# terms of the Apache License, Version 2.0 which is available at
8+
# https://www.apache.org/licenses/LICENSE-2.0.
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations
14+
# under the License.
15+
#
16+
# SPDX-License-Identifier: Apache-2.0
17+
18+
name: "[BE][TEST][E2E] Cucumber - Association"
19+
20+
on:
21+
workflow_dispatch: # Trigger manually
22+
schedule:
23+
- cron: "0 0 * * *"
24+
25+
jobs:
26+
build:
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- uses: actions/checkout@v4
31+
32+
- name: Set up JDK 17
33+
uses: actions/setup-java@v4
34+
with:
35+
java-version: '17'
36+
distribution: 'temurin'
37+
38+
- name: Cache maven packages
39+
uses: actions/cache@v4
40+
with:
41+
path: ~/.m2
42+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
43+
restore-keys: ${{ runner.os }}-m2
44+
45+
- name: Download Feature Files
46+
id: download
47+
env:
48+
JIRA_USERNAME: ${{ secrets.ASSOCIATION_TX_JIRA_USERNAME }}
49+
JIRA_PASSWORD: ${{ secrets.ASSOCIATION_TX_JIRA_PASSWORD }}
50+
# JIRA filter 11349: project = "[TR] FOSS - Open Source (Impl.)" AND issuetype = Test AND "Test Type" = Cucumber AND status = Ready AND labels = INTEGRATION_TEST AND (environment ~ DEV OR environment ~ "INT")
51+
# Downloads all feature files of cucumber tests inside TRI project
52+
run: |
53+
token=$(curl -H "Content-Type: application/json" -X POST \
54+
--data "{ \"client_id\": \"$JIRA_USERNAME\",\"client_secret\": \"$JIRA_PASSWORD\" }" \
55+
https://xray.cloud.getxray.app/api/v2/authenticate | tr -d '"')
56+
57+
export HTTP_RESULT=$(curl -s --show-error -w "%{http_code}" --header "Authorization: Bearer $token" \
58+
"https://xray.cloud.getxray.app/api/v2/export/cucumber?filter=10005&fz=true" -o features.zip)
59+
60+
[[ $HTTP_RESULT == 200 || $HTTP_RESULT == 400 ]]
61+
echo "::set-output name=http_response::$HTTP_RESULT"
62+
63+
- name: install tx-models
64+
run: mvn install -pl tx-models
65+
66+
# Required step due to fact that jira will name feature files differently with each feature added and that will cause duplicate test runs
67+
- name: Cleanup repository feature files
68+
if: ${{ steps.download.outputs.http_response == '200' }}
69+
#working-directory: tx-cucumber-tests
70+
run: |
71+
rm -r tx-cucumber-tests/src/test/resources/features/*
72+
73+
- name: Build with Maven
74+
if: ${{ steps.download.outputs.http_response == '200' }}
75+
env:
76+
KEYCLOAK_HOST: ${{ secrets.ASSOCIATION_KEYCLOAK_HOST }}
77+
SUPERVISOR_CLIENT_ID: ${{ secrets.ASSOCIATION_SUPERVISOR_CLIENT_ID }}
78+
SUPERVISOR_PASSWORD: ${{ secrets.ASSOCIATION_SUPERVISOR_PASSWORD }}
79+
E2E_TXA_HOST: ${{ secrets.ASSOCIATION_E2E_TXA_HOST }}
80+
E2E_TXB_HOST: ${{ secrets.ASSOCIATION_E2E_TXB_HOST }}
81+
#working-directory: tx-cucumber-tests
82+
run: |
83+
unzip -o tx-cucumber-tests/features.zip -d tx-cucumber-tests/src/test/resources/features
84+
mvn -pl tx-models,tx-cucumber-tests --batch-mode clean install -D"cucumber.filter.tags"="@trace-x-automated" -P association
85+
86+
- name: Submit results to Xray
87+
if: ${{ always() && steps.download.outputs.http_response == '200' }}
88+
env:
89+
JIRA_USERNAME: ${{ secrets.ASSOCIATION_TX_JIRA_USERNAME }}
90+
JIRA_PASSWORD: ${{ secrets.ASSOCIATION_TX_JIRA_PASSWORD }}
91+
run: |
92+
token=$(curl -H "Content-Type: application/json" -X POST \
93+
--data "{ \"client_id\": \"$JIRA_USERNAME\",\"client_secret\": \"$JIRA_PASSWORD\" }" \
94+
https://xray.cloud.getxray.app/api/v2/authenticate | tr -d '"')
95+
96+
curl --request POST \
97+
--header 'Content-Type: application/json' \
98+
--header "Authorization: Bearer $token" \
99+
--data-binary '@tx-cucumber-tests/report.json' \
100+
"https://xray.cloud.getxray.app/api/v2/import/execution/cucumber"

tx-cucumber-tests/pom.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,47 @@ SPDX-License-Identifier: Apache-2.0
3535
<properties>
3636
<sonar.skip>true</sonar.skip>
3737
</properties>
38+
39+
<profiles>
40+
<profile>
41+
<id>consortia</id>
42+
<activation>
43+
<activeByDefault>true</activeByDefault>
44+
</activation>
45+
<build>
46+
<plugins>
47+
<plugin>
48+
<groupId>org.apache.maven.plugins</groupId>
49+
<artifactId>maven-surefire-plugin</artifactId>
50+
<configuration>
51+
<systemPropertyVariables>
52+
<txa.bpn>BPNL00000003CML1</txa.bpn>
53+
<txb.bpn>BPNL00000003CNKC</txb.bpn>
54+
</systemPropertyVariables>
55+
</configuration>
56+
</plugin>
57+
</plugins>
58+
</build>
59+
</profile>
60+
<profile>
61+
<id>association</id>
62+
<build>
63+
<plugins>
64+
<plugin>
65+
<groupId>org.apache.maven.plugins</groupId>
66+
<artifactId>maven-surefire-plugin</artifactId>
67+
<configuration>
68+
<systemPropertyVariables>
69+
<txa.bpn>BPNL000000000UKM</txa.bpn>
70+
<txb.bpn>BPNL000000000DWF</txb.bpn>
71+
</systemPropertyVariables>
72+
</configuration>
73+
</plugin>
74+
</plugins>
75+
</build>
76+
</profile>
77+
</profiles>
78+
3879
<dependencyManagement>
3980
<dependencies>
4081
<dependency>

tx-cucumber-tests/src/test/java/org/eclipse/tractusx/traceability/test/TraceabilityTestStepDefinition.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@
5353
import static org.eclipse.tractusx.traceability.test.tooling.TraceXEnvironmentEnum.TRACE_X_A;
5454
import static org.eclipse.tractusx.traceability.test.tooling.TraceXEnvironmentEnum.TRACE_X_B;
5555
import static org.eclipse.tractusx.traceability.test.validator.TestUtils.normalize;
56-
import static org.eclipse.tractusx.traceability.test.validator.TestUtils.wrapStringWithTimestamp;
56+
import static org.eclipse.tractusx.traceability.test.validator.TestUtils.wrapStringWithUUID;
5757

5858
@Slf4j
5959
public class TraceabilityTestStepDefinition {
6060

6161
private RestProvider restProvider;
6262
private Long notificationID_TXA = null;
6363
private Long notificationID_TXB = null;
64-
protected static final String BPN_TXA = "BPNL00000003CML1";
65-
protected static final String BPN_TXB = "BPNL00000003CNKC";
64+
protected static final String BPN_TXA = System.getProperty("txa.bpn");
65+
protected static final String BPN_TXB = System.getProperty("txb.bpn");
6666
private String notificationDescription = null;
6767
private List<AssetAsBuiltResponse> requestedAssets;
6868
private List<String> testAssets;
@@ -96,7 +96,7 @@ public void iCreateQualityNotification(DataTable dataTable) {
9696
throw MissingStepDefinitionException.missingAssetDefinition();
9797
}
9898

99-
notificationDescription = wrapStringWithTimestamp(input.get("description"));
99+
notificationDescription = wrapStringWithUUID(input.get("description"));
100100

101101
final Instant targetDate = input.get("targetDate") == null ? null : Instant.parse(input.get("targetDate"));
102102

@@ -127,7 +127,7 @@ public void iEditQualityNotification(DataTable dataTable) {
127127
throw MissingStepDefinitionException.missingAssetDefinition();
128128
}
129129

130-
notificationDescription = wrapStringWithTimestamp(input.get("description"));
130+
notificationDescription = wrapStringWithUUID(input.get("description"));
131131

132132
final Instant targetDate = input.get("targetDate") == null ? null : Instant.parse(input.get("targetDate"));
133133

tx-cucumber-tests/src/test/java/org/eclipse/tractusx/traceability/test/tooling/EnvVariablesResolver.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,38 @@
2121

2222
public class EnvVariablesResolver {
2323

24-
public static String getSupervisorClientId() {
25-
return System.getenv("SUPERVISOR_CLIENT_ID");
24+
public static final String ASSOCIATION_SUPERVISOR_TX_A_CLIENT_ID = "ASSOCIATION_SUPERVISOR_TX_A_CLIENT_ID";
25+
public static final String ASSOCIATION_SUPERVISOR_TX_A_PASSWORD = "ASSOCIATION_SUPERVISOR_TX_A_PASSWORD";
26+
public static final String ASSOCIATION_SUPERVISOR_TX_B_CLIENT_ID = "ASSOCIATION_SUPERVISOR_TX_B_CLIENT_ID";
27+
public static final String ASSOCIATION_SUPERVISOR_TX_B_PASSWORD = "ASSOCIATION_SUPERVISOR_TX_B_PASSWORD";
28+
29+
public static String getSupervisorClientIdTracexA() {
30+
return System.getenv(ASSOCIATION_SUPERVISOR_TX_A_CLIENT_ID);
31+
}
32+
33+
public static String getSupervisorPasswordTracexA() {
34+
return System.getenv(ASSOCIATION_SUPERVISOR_TX_A_PASSWORD);
35+
}
36+
37+
public static String getSupervisorClientIdTracexB() {
38+
return System.getenv(ASSOCIATION_SUPERVISOR_TX_B_CLIENT_ID) == null
39+
? System.getenv(ASSOCIATION_SUPERVISOR_TX_A_CLIENT_ID) : System.getenv(ASSOCIATION_SUPERVISOR_TX_B_CLIENT_ID);
2640
}
2741

28-
public static String getSupervisorPassword() {
29-
return System.getenv("SUPERVISOR_PASSWORD");
42+
public static String getAssociationSupervisorTxBPassword() {
43+
return System.getenv(ASSOCIATION_SUPERVISOR_TX_B_PASSWORD) == null
44+
? System.getenv(ASSOCIATION_SUPERVISOR_TX_A_PASSWORD) : System.getenv(ASSOCIATION_SUPERVISOR_TX_B_PASSWORD);
3045
}
3146

3247
public static String getKeycloakHost() {
33-
return System.getenv("KEYCLOAK_HOST");
48+
return System.getenv("ASSOCIATION_KEYCLOAK_HOST");
3449
}
3550

3651
public static String getTX_A_Host() {
37-
return System.getenv("E2E_TXA_HOST");
52+
return System.getenv("ASSOCIATION_E2E_TXA_HOST");
3853
}
3954

4055
public static String getTX_B_Host() {
41-
return System.getenv("E2E_TXB_HOST");
56+
return System.getenv("ASSOCIATION_E2E_TXB_HOST");
4257
}
4358
}

tx-cucumber-tests/src/test/java/org/eclipse/tractusx/traceability/test/tooling/rest/Authentication.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,28 @@ public class Authentication {
4040
private String clientSecret;
4141
private String keycloakHost;
4242

43-
Authentication() {
44-
clientId = EnvVariablesResolver.getSupervisorClientId();
45-
clientSecret = EnvVariablesResolver.getSupervisorPassword();
43+
private Authentication() {
44+
clientId = EnvVariablesResolver.getSupervisorClientIdTracexA();
45+
clientSecret = EnvVariablesResolver.getSupervisorPasswordTracexA();
4646
keycloakHost = EnvVariablesResolver.getKeycloakHost();
4747
}
4848

49+
public static Authentication authenticationForTracexA(){
50+
Authentication authentication = new Authentication();
51+
authentication.clientId = EnvVariablesResolver.getSupervisorClientIdTracexA();
52+
authentication.clientSecret = EnvVariablesResolver.getSupervisorPasswordTracexA();
53+
authentication.keycloakHost = EnvVariablesResolver.getKeycloakHost();
54+
return authentication;
55+
}
56+
57+
public static Authentication authenticationForTracexB(){
58+
Authentication authentication = new Authentication();
59+
authentication.clientId = EnvVariablesResolver.getSupervisorClientIdTracexB();
60+
authentication.clientSecret = EnvVariablesResolver.getAssociationSupervisorTxBPassword();
61+
authentication.keycloakHost = EnvVariablesResolver.getKeycloakHost();
62+
return authentication;
63+
}
64+
4965
public String obtainAccessToken() {
5066
final Map<String, String> oauth2Payload = new HashMap<>();
5167
oauth2Payload.put("grant_type", "client_credentials");

tx-cucumber-tests/src/test/java/org/eclipse/tractusx/traceability/test/tooling/rest/RestProvider.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ public class RestProvider {
6363
@Getter
6464
private TraceXEnvironmentEnum currentEnv;
6565

66-
private final Authentication authentication;
66+
private Authentication authentication;
6767

6868
public RestProvider() {
6969
host = null;
70-
authentication = new Authentication();
7170

7271
RestAssured.config = RestAssuredConfig.config().objectMapperConfig(new ObjectMapperConfig().jackson2ObjectMapperFactory(
7372
(type, s) -> new ObjectMapper()
@@ -84,9 +83,11 @@ public RestProvider() {
8483
public void loginToEnvironment(TraceXEnvironmentEnum environment) {
8584
if (environment.equals(TRACE_X_A)) {
8685
host = EnvVariablesResolver.getTX_A_Host();
86+
authentication = Authentication.authenticationForTracexA();
8787
currentEnv = TRACE_X_A;
8888
} else if (environment.equals(TRACE_X_B)) {
8989
host = EnvVariablesResolver.getTX_B_Host();
90+
authentication = Authentication.authenticationForTracexB();
9091
currentEnv = TRACE_X_B;
9192
}
9293
System.out.println(host);
@@ -249,16 +250,17 @@ public List<NotificationResponse> getReceivedNotifications() {
249250
return given().spec(getRequestSpecification())
250251
.contentType(ContentType.JSON)
251252
.when()
252-
.body("{\n" +
253-
" \"pageAble\": {\n" +
254-
" \"size\": 1000 \n" +
255-
" },\n" +
256-
" \"searchCriteria\": {\n" +
257-
" \"filter\": [\n" +
258-
" \"channel,EQUAL,RECEIVER,AND\"\n" +
259-
" ]\n" +
260-
" }\n" +
261-
"}")
253+
.body("""
254+
{
255+
"pageAble": {
256+
"size": 1000\s
257+
},
258+
"searchCriteria": {
259+
"filter": [
260+
"channel,EQUAL,RECEIVER,AND"
261+
]
262+
}
263+
}""")
262264
.post("/api/notifications/filter")
263265
.then()
264266
.statusCode(HttpStatus.SC_OK)

tx-cucumber-tests/src/test/java/org/eclipse/tractusx/traceability/test/validator/TestUtils.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919

2020
package org.eclipse.tractusx.traceability.test.validator;
2121

22-
import java.time.Instant;
22+
import lombok.extern.slf4j.Slf4j;
23+
2324
import java.util.Map;
25+
import java.util.UUID;
2426
import java.util.regex.Matcher;
2527
import java.util.regex.Pattern;
2628
import java.util.stream.Collectors;
@@ -29,9 +31,8 @@ public class TestUtils {
2931

3032
private static final String UNIQUE_SEPARATOR = ":-:";
3133

32-
public static String wrapStringWithTimestamp(String string) {
33-
34-
return UNIQUE_SEPARATOR + string + UNIQUE_SEPARATOR + Instant.now();
34+
public static String wrapStringWithUUID(String string) {
35+
return UNIQUE_SEPARATOR + string + UNIQUE_SEPARATOR + UUID.randomUUID();
3536
}
3637

3738
public static String unWrapStringWithTimestamp(String string) {

0 commit comments

Comments
 (0)