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(refactoring):962 refactored e2e-test. #1062

Merged
merged 8 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
42 changes: 13 additions & 29 deletions .github/workflows/pull-request_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,6 @@ env:
BACKEND_IMAGE_DOCKER_HUB: traceability-foss

jobs:
Check-Changelog-update:
runs-on: ubuntu-latest
if: startsWith(github.head_ref, 'chore') || startsWith(github.head_ref, 'feature')
steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
- name: Check if CHANGELOG is updated
id: updated-changelog
uses: tj-actions/changed-files@v44
with:
# Avoid using single or double quotes for multiline patterns
files: |
CHANGELOG.md
- name: request changes
uses: ntsd/auto-request-changes-action@v3
if: steps.updated-changelog.outputs.any_changed == 'false'
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
review-message: "Please add a short description of the feature/fix to the Changelog.md."
Check-Pom-for-snapshot-versions:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -98,7 +77,7 @@ jobs:
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: "/home/runner/work/tx-traceability-foss/tx-traceability-foss/tx-backend/target/failsafe-reports/TEST-*.xml"
files: "${{ github.workspace }}/tx-backend/target/failsafe-reports/TEST-*.xml"
check_name: "Integration Test Results"

- name: Publish unit test results
Expand All @@ -108,20 +87,25 @@ jobs:
files: "**/surefire-reports/TEST-*.xml"
check_name: "Unit Test Results"

- name: Clean working directories
run: |
rm -rf .scannerwork
rm -rf .sonar

- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

# - name: Verify Sonar Scan
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_BACKEND }}
# SONAR_ORGANIZATION: ${{ vars.SONAR_ORGANIZATION }}
# SONAR_PROJECT_KEY: ${{ vars.SONAR_PROJECT_KEY_BACKEND }}
# run: mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn --batch-mode sonar:sonar -Dsonar.coverage.jacoco.xmlReportPaths=/home/runner/work/traceability-foss/tx-traceability-foss/tx-coverage/target/site/jacoco-aggregate/jacoco.xml -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY_BACKEND }} -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }}
- name: Verify Sonar Scan
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_BACKEND }}
SONAR_ORGANIZATION: ${{ vars.SONAR_ORGANIZATION }}
SONAR_PROJECT_KEY: ${{ vars.SONAR_PROJECT_KEY_BACKEND }}
run: mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn --batch-mode sonar:sonar -Dsonar.coverage.jacoco.xmlReportPaths=${{ github.workspace }}/tx-coverage/target/site/jacoco-aggregate/jacoco.xml -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY_BACKEND }} -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }}

Publish-docker-image:
# needs: [ "Test-and-Sonar" ]
Expand Down
2 changes: 1 addition & 1 deletion docs/api/traceability-foss-backend.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tx-backend/openapi/traceability-foss-backend.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Descriptions extractDescription(IrsSubmodel irsSubmodel) {

@Override
public boolean validMapper(IrsSubmodel irsSubmodel) {
return irsSubmodel.getPayload() instanceof SingleLevelBomAsBuilt300Schema;
return irsSubmodel.getPayload() instanceof SingleLevelUsageAsBuilt300Schema;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@
import org.eclipse.tractusx.traceability.notification.domain.base.model.Notification;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationAffectedPart;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationMessage;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationSeverity;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationSide;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationStatus;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationType;
import org.eclipse.tractusx.traceability.notification.infrastructure.edc.model.EDCNotification;
import org.springframework.stereotype.Component;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;

import static org.apache.commons.collections4.ListUtils.emptyIfNull;
import static org.eclipse.tractusx.traceability.common.date.DateUtil.convertInstantToString;

@RequiredArgsConstructor
@Component
Expand All @@ -44,11 +47,11 @@ public class NotificationMapper {
* Creates an Notification object representing the notification received by the receiver for a given notification.
*
* @param bpn the BPN of the notification
* @param description the description of the notification
* @param edcNotification the edcNotification of the notification
* @param notification the notification associated with the alert or investigation
* @return an Notification object representing the notification received by the receiver
*/
public Notification toNotification(BPN bpn, String description, NotificationMessage notification, NotificationType notificationType) {
public Notification toNotification(BPN bpn, EDCNotification edcNotification, NotificationMessage notification, NotificationType notificationType) {

List<String> assetIds = new ArrayList<>();
emptyIfNull(notification.getAffectedParts()).stream()
Expand All @@ -59,8 +62,10 @@ public Notification toNotification(BPN bpn, String description, NotificationMess
.notificationStatus(NotificationStatus.RECEIVED)
.notificationSide(NotificationSide.RECEIVER)
.notificationType(notificationType)
.description(description)
.description(edcNotification.getInformation())
.createdAt(Instant.now())
.severity(NotificationSeverity.fromString(edcNotification.getSeverity()))
.targetDate(convertInstantToString(edcNotification.getTargetDate()))
.affectedPartIds(assetIds)
.notifications(List.of(notification))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public abstract class AbstractNotificationReceiverService implements Notificatio
public void handleReceive(EDCNotification edcNotification, NotificationType notificationType) {
BPN investigationCreatorBPN = BPN.of(edcNotification.getSenderBPN());
NotificationMessage notification = getNotificationMessageMapper().toNotificationMessage(edcNotification, notificationType);
Notification investigation = getNotificationMapper().toNotification(investigationCreatorBPN, edcNotification.getInformation(), notification, notificationType);
Notification investigation = getNotificationMapper().toNotification(investigationCreatorBPN, edcNotification, notification, notificationType);
NotificationId investigationId = getRepository().saveNotification(investigation);
log.info("Stored received edcNotification in investigation with id {}", investigationId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationSide;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationStatus;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationType;
import org.eclipse.tractusx.traceability.notification.infrastructure.edc.model.EDCNotification;
import org.eclipse.tractusx.traceability.notification.infrastructure.edc.model.EDCNotificationContent;
import org.eclipse.tractusx.traceability.notification.infrastructure.edc.model.EDCNotificationHeader;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.Arrays;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -62,9 +66,27 @@ void testToReceiverInvestigation() {
.build();
NotificationType type = NotificationType.INVESTIGATION;

EDCNotificationHeader header = new EDCNotificationHeader(
"notif-12345",
"BPNL00000001ABC",
"https://sender-address.com",
"BPNL00000002DEF",
"Risk",
"High",
"notif-54321",
"Open",
"2024-07-01T12:00:00Z",
"msg-67890"
);

EDCNotificationContent content = new EDCNotificationContent(
description,
Arrays.asList("Item1", "Item2", "Item3")
);

EDCNotification edcNotification = new EDCNotification(header, content);
// When
Notification result = mapper.toNotification(new BPN(receiver), description, notification, type);
Notification result = mapper.toNotification(new BPN(receiver), edcNotification, notification, type);

// Then
assertEquals(NotificationStatus.RECEIVED, result.getNotificationStatus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void shouldReceiveAlert() {
.build();
Notification notification = Notification.builder().build();
notification.setSeverity(NotificationSeverity.CRITICAL);
notification.setTargetDate(Instant.MAX.toString());
notification.setTargetDate(Instant.now().toString());
EDCNotification edcNotification = EDCNotificationFactory.createEdcNotification(
"it", message, notification);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void shouldReceiveNotification() {
assetsSupport.defaultAssetsStored();

NotificationType notificationType = NotificationType.INVESTIGATION;
Notification notification = Notification.builder().targetDate(Instant.MAX.toString()).severity(NotificationSeverity.CRITICAL).build();
Notification notification = Notification.builder().targetDate(Instant.now().toString()).severity(NotificationSeverity.CRITICAL).build();
NotificationMessage notificationBuild = NotificationMessage.builder()
.id("some-id")
.notificationStatus(NotificationStatus.SENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@

package org.eclipse.tractusx.traceability.notification.domain.service;

import org.eclipse.tractusx.traceability.common.mapper.NotificationMessageMapper;
import org.eclipse.tractusx.traceability.common.mapper.NotificationMapper;
import org.eclipse.tractusx.traceability.common.mapper.NotificationMessageMapper;
import org.eclipse.tractusx.traceability.common.model.BPN;
import org.eclipse.tractusx.traceability.notification.domain.base.model.Notification;
import org.eclipse.tractusx.traceability.notification.domain.notification.repository.NotificationRepository;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationAffectedPart;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationMessage;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationSeverity;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationStatus;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationType;
import org.eclipse.tractusx.traceability.notification.domain.notification.repository.NotificationRepository;
import org.eclipse.tractusx.traceability.notification.domain.notification.service.NotificationReceiverService;
import org.eclipse.tractusx.traceability.notification.infrastructure.edc.model.EDCNotification;
import org.eclipse.tractusx.traceability.notification.infrastructure.edc.model.EDCNotificationFactory;
Expand All @@ -42,12 +41,10 @@
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

import java.time.Instant;
import java.util.List;
import java.util.Optional;

import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.when;


Expand Down Expand Up @@ -92,14 +89,13 @@ void testhandleReceiveValidSentNotification() {
.build();



Notification investigationTestData = InvestigationTestDataFactory.createInvestigationTestData(NotificationStatus.RECEIVED, "recipientBPN");
NotificationMessage notificationTestData = NotificationTestDataFactory.createNotificationTestData();
EDCNotification edcNotification = EDCNotificationFactory.createEdcNotification(
"it", notification, investigationTestData);

when(mockNotificationMessageMapper.toNotificationMessage(edcNotification, notificationType)).thenReturn(notificationTestData);
when(mockNotificationMapper.toNotification(any(BPN.class), anyString(), any(NotificationMessage.class), any(NotificationType.class))).thenReturn(investigationTestData);
when(mockNotificationMapper.toNotification(any(BPN.class), any(), any(NotificationMessage.class), any(NotificationType.class))).thenReturn(investigationTestData);

// When
service.handleReceive(edcNotification, notificationType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@

import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationAffectedPart;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationMessage;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationSeverity;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationStatus;
import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationType;

import java.time.Instant;
import java.util.List;

public class NotificationTestDataFactory {
Expand Down
Loading