Skip to content

Commit

Permalink
feature: xxx add association cucumber test action
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-lcapellino committed Jul 25, 2024
1 parent b39ce3e commit 635cfff
Show file tree
Hide file tree
Showing 19 changed files with 699 additions and 945 deletions.
100 changes: 100 additions & 0 deletions .github/workflows/xray-cucumber-association.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Copyright (c) 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

name: "[BE][TEST][E2E] Cucumber - Association"

on:
workflow_dispatch: # Trigger manually
schedule:
- cron: "0 0 * * *"

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Cache maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Download Feature Files
id: download
env:
JIRA_USERNAME: ${{ secrets.ASSOCIATION_TX_JIRA_USERNAME }}
JIRA_PASSWORD: ${{ secrets.ASSOCIATION_TX_JIRA_PASSWORD }}
# 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")
# Downloads all feature files of cucumber tests inside TRI project
run: |
token=$(curl -H "Content-Type: application/json" -X POST \
--data "{ \"client_id\": \"$JIRA_USERNAME\",\"client_secret\": \"$JIRA_PASSWORD\" }" \
https://xray.cloud.getxray.app/api/v2/authenticate | tr -d '"')
export HTTP_RESULT=$(curl -s --show-error -w "%{http_code}" --header "Authorization: Bearer $token" \
"https://xray.cloud.getxray.app/api/v2/export/cucumber?filter=10005&fz=true" -o features.zip)
[[ $HTTP_RESULT == 200 || $HTTP_RESULT == 400 ]]
echo "::set-output name=http_response::$HTTP_RESULT"
- name: install tx-models
run: mvn install -pl tx-models

# Required step due to fact that jira will name feature files differently with each feature added and that will cause duplicate test runs
- name: Cleanup repository feature files
if: ${{ steps.download.outputs.http_response == '200' }}
#working-directory: tx-cucumber-tests
run: |
rm -r tx-cucumber-tests/src/test/resources/features/*
- name: Build with Maven
if: ${{ steps.download.outputs.http_response == '200' }}
env:
KEYCLOAK_HOST: ${{ secrets.ASSOCIATION_KEYCLOAK_HOST }}
SUPERVISOR_CLIENT_ID: ${{ secrets.ASSOCIATION_SUPERVISOR_CLIENT_ID }}
SUPERVISOR_PASSWORD: ${{ secrets.ASSOCIATION_SUPERVISOR_PASSWORD }}
E2E_TXA_HOST: ${{ secrets.ASSOCIATION_E2E_TXA_HOST }}
E2E_TXB_HOST: ${{ secrets.ASSOCIATION_E2E_TXB_HOST }}
#working-directory: tx-cucumber-tests
run: |
unzip -o tx-cucumber-tests/features.zip -d tx-cucumber-tests/src/test/resources/features
mvn -pl tx-models,tx-cucumber-tests --batch-mode clean install -D"cucumber.filter.tags"="@trace-x-automated" -P association
- name: Submit results to Xray
if: ${{ always() && steps.download.outputs.http_response == '200' }}
env:
JIRA_USERNAME: ${{ secrets.ASSOCIATION_TX_JIRA_USERNAME }}
JIRA_PASSWORD: ${{ secrets.ASSOCIATION_TX_JIRA_PASSWORD }}
run: |
token=$(curl -H "Content-Type: application/json" -X POST \
--data "{ \"client_id\": \"$JIRA_USERNAME\",\"client_secret\": \"$JIRA_PASSWORD\" }" \
https://xray.cloud.getxray.app/api/v2/authenticate | tr -d '"')
curl --request POST \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $token" \
--data-binary '@tx-cucumber-tests/report.json' \
"https://xray.cloud.getxray.app/api/v2/import/execution/cucumber"
41 changes: 41 additions & 0 deletions tx-cucumber-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,47 @@ SPDX-License-Identifier: Apache-2.0
<properties>
<sonar.skip>true</sonar.skip>
</properties>

<profiles>
<profile>
<id>consortia</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<txa.bpn>BPNL00000003CML1</txa.bpn>
<txb.bpn>BPNL00000003CNKC</txb.bpn>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>association</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<txa.bpn>BPNL000000000UKM</txa.bpn>
<txb.bpn>BPNL000000000DWF</txb.bpn>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<dependencyManagement>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@
import static org.eclipse.tractusx.traceability.test.tooling.TraceXEnvironmentEnum.TRACE_X_A;
import static org.eclipse.tractusx.traceability.test.tooling.TraceXEnvironmentEnum.TRACE_X_B;
import static org.eclipse.tractusx.traceability.test.validator.TestUtils.normalize;
import static org.eclipse.tractusx.traceability.test.validator.TestUtils.wrapStringWithTimestamp;
import static org.eclipse.tractusx.traceability.test.validator.TestUtils.wrapStringWithUUID;

@Slf4j
public class TraceabilityTestStepDefinition {

private RestProvider restProvider;
private Long notificationID_TXA = null;
private Long notificationID_TXB = null;
protected static final String BPN_TXA = "BPNL00000003CML1";
protected static final String BPN_TXB = "BPNL00000003CNKC";
protected static final String BPN_TXA = System.getProperty("txa.bpn");
protected static final String BPN_TXB = System.getProperty("txb.bpn");
private String notificationDescription = null;
private List<AssetAsBuiltResponse> requestedAssets;
private List<String> testAssets;
Expand Down Expand Up @@ -96,7 +96,7 @@ public void iCreateQualityNotification(DataTable dataTable) {
throw MissingStepDefinitionException.missingAssetDefinition();
}

notificationDescription = wrapStringWithTimestamp(input.get("description"));
notificationDescription = wrapStringWithUUID(input.get("description"));

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

Expand Down Expand Up @@ -127,7 +127,7 @@ public void iEditQualityNotification(DataTable dataTable) {
throw MissingStepDefinitionException.missingAssetDefinition();
}

notificationDescription = wrapStringWithTimestamp(input.get("description"));
notificationDescription = wrapStringWithUUID(input.get("description"));

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,38 @@

public class EnvVariablesResolver {

public static String getSupervisorClientId() {
return System.getenv("SUPERVISOR_CLIENT_ID");
public static final String ASSOCIATION_SUPERVISOR_TX_A_CLIENT_ID = "ASSOCIATION_SUPERVISOR_TX_A_CLIENT_ID";
public static final String ASSOCIATION_SUPERVISOR_TX_A_PASSWORD = "ASSOCIATION_SUPERVISOR_TX_A_PASSWORD";
public static final String ASSOCIATION_SUPERVISOR_TX_B_CLIENT_ID = "ASSOCIATION_SUPERVISOR_TX_B_CLIENT_ID";
public static final String ASSOCIATION_SUPERVISOR_TX_B_PASSWORD = "ASSOCIATION_SUPERVISOR_TX_B_PASSWORD";

public static String getSupervisorClientIdTracexA() {
return System.getenv(ASSOCIATION_SUPERVISOR_TX_A_CLIENT_ID);
}

public static String getSupervisorPasswordTracexA() {
return System.getenv(ASSOCIATION_SUPERVISOR_TX_A_PASSWORD);
}

public static String getSupervisorClientIdTracexB() {
return System.getenv(ASSOCIATION_SUPERVISOR_TX_B_CLIENT_ID) == null
? System.getenv(ASSOCIATION_SUPERVISOR_TX_A_CLIENT_ID) : System.getenv(ASSOCIATION_SUPERVISOR_TX_B_CLIENT_ID);
}

public static String getSupervisorPassword() {
return System.getenv("SUPERVISOR_PASSWORD");
public static String getAssociationSupervisorTxBPassword() {
return System.getenv(ASSOCIATION_SUPERVISOR_TX_B_PASSWORD) == null
? System.getenv(ASSOCIATION_SUPERVISOR_TX_A_PASSWORD) : System.getenv(ASSOCIATION_SUPERVISOR_TX_B_PASSWORD);
}

public static String getKeycloakHost() {
return System.getenv("KEYCLOAK_HOST");
return System.getenv("ASSOCIATION_KEYCLOAK_HOST");
}

public static String getTX_A_Host() {
return System.getenv("E2E_TXA_HOST");
return System.getenv("ASSOCIATION_E2E_TXA_HOST");
}

public static String getTX_B_Host() {
return System.getenv("E2E_TXB_HOST");
return System.getenv("ASSOCIATION_E2E_TXB_HOST");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,28 @@ public class Authentication {
private String clientSecret;
private String keycloakHost;

Authentication() {
clientId = EnvVariablesResolver.getSupervisorClientId();
clientSecret = EnvVariablesResolver.getSupervisorPassword();
private Authentication() {
clientId = EnvVariablesResolver.getSupervisorClientIdTracexA();
clientSecret = EnvVariablesResolver.getSupervisorPasswordTracexA();
keycloakHost = EnvVariablesResolver.getKeycloakHost();
}

public static Authentication authenticationForTracexA(){
Authentication authentication = new Authentication();
authentication.clientId = EnvVariablesResolver.getSupervisorClientIdTracexA();
authentication.clientSecret = EnvVariablesResolver.getSupervisorPasswordTracexA();
authentication.keycloakHost = EnvVariablesResolver.getKeycloakHost();
return authentication;
}

public static Authentication authenticationForTracexB(){
Authentication authentication = new Authentication();
authentication.clientId = EnvVariablesResolver.getSupervisorClientIdTracexB();
authentication.clientSecret = EnvVariablesResolver.getAssociationSupervisorTxBPassword();
authentication.keycloakHost = EnvVariablesResolver.getKeycloakHost();
return authentication;
}

public String obtainAccessToken() {
final Map<String, String> oauth2Payload = new HashMap<>();
oauth2Payload.put("grant_type", "client_credentials");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ public class RestProvider {
@Getter
private TraceXEnvironmentEnum currentEnv;

private final Authentication authentication;
private Authentication authentication;

public RestProvider() {
host = null;
authentication = new Authentication();

RestAssured.config = RestAssuredConfig.config().objectMapperConfig(new ObjectMapperConfig().jackson2ObjectMapperFactory(
(type, s) -> new ObjectMapper()
Expand All @@ -84,9 +83,11 @@ public RestProvider() {
public void loginToEnvironment(TraceXEnvironmentEnum environment) {
if (environment.equals(TRACE_X_A)) {
host = EnvVariablesResolver.getTX_A_Host();
authentication = Authentication.authenticationForTracexA();
currentEnv = TRACE_X_A;
} else if (environment.equals(TRACE_X_B)) {
host = EnvVariablesResolver.getTX_B_Host();
authentication = Authentication.authenticationForTracexB();
currentEnv = TRACE_X_B;
}
System.out.println(host);
Expand Down Expand Up @@ -249,16 +250,17 @@ public List<NotificationResponse> getReceivedNotifications() {
return given().spec(getRequestSpecification())
.contentType(ContentType.JSON)
.when()
.body("{\n" +
" \"pageAble\": {\n" +
" \"size\": 1000 \n" +
" },\n" +
" \"searchCriteria\": {\n" +
" \"filter\": [\n" +
" \"channel,EQUAL,RECEIVER,AND\"\n" +
" ]\n" +
" }\n" +
"}")
.body("""
{
"pageAble": {
"size": 1000\s
},
"searchCriteria": {
"filter": [
"channel,EQUAL,RECEIVER,AND"
]
}
}""")
.post("/api/notifications/filter")
.then()
.statusCode(HttpStatus.SC_OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

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

import java.time.Instant;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand All @@ -29,9 +31,8 @@ public class TestUtils {

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

public static String wrapStringWithTimestamp(String string) {

return UNIQUE_SEPARATOR + string + UNIQUE_SEPARATOR + Instant.now();
public static String wrapStringWithUUID(String string) {
return UNIQUE_SEPARATOR + string + UNIQUE_SEPARATOR + UUID.randomUUID();
}

public static String unWrapStringWithTimestamp(String string) {
Expand Down
Loading

0 comments on commit 635cfff

Please sign in to comment.